Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* L2TP subsystem debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2010 Katalix Systems Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/l2tp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <net/inet_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/inet_hashtables.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "l2tp_core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static struct dentry *rootdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) struct l2tp_dfs_seq_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int tunnel_idx;			/* current tunnel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int session_idx;		/* index of session within current tunnel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct l2tp_tunnel *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct l2tp_session *session;	/* NULL means get next tunnel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void l2tp_dfs_next_tunnel(struct l2tp_dfs_seq_data *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* Drop reference taken during previous invocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (pd->tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		l2tp_tunnel_dec_refcount(pd->tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	pd->tunnel = l2tp_tunnel_get_nth(pd->net, pd->tunnel_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	pd->tunnel_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* Drop reference taken during previous invocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (pd->session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		l2tp_session_dec_refcount(pd->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	pd->session_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (!pd->session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		pd->session_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		l2tp_dfs_next_tunnel(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct l2tp_dfs_seq_data *pd = SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	loff_t pos = *offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (!pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (WARN_ON(!m->private)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		pd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	pd = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (!pd->tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		l2tp_dfs_next_tunnel(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		l2tp_dfs_next_session(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	/* NULL tunnel and session indicates end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!pd->tunnel && !pd->session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		pd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static void *l2tp_dfs_seq_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	(*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static void l2tp_dfs_seq_stop(struct seq_file *p, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct l2tp_dfs_seq_data *pd = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (!pd || pd == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* Drop reference taken by last invocation of l2tp_dfs_next_session()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * or l2tp_dfs_next_tunnel().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (pd->session) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		l2tp_session_dec_refcount(pd->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		pd->session = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (pd->tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		l2tp_tunnel_dec_refcount(pd->tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		pd->tunnel = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct l2tp_tunnel *tunnel = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int session_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct hlist_node *walk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct hlist_node *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	read_lock_bh(&tunnel->hlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	for (hash = 0; hash < L2TP_HASH_SIZE; hash++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			struct l2tp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			session = hlist_entry(walk, struct l2tp_session, hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			if (session->session_id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			session_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	read_unlock_bh(&tunnel->hlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	seq_printf(m, "\nTUNNEL %u peer %u", tunnel->tunnel_id, tunnel->peer_tunnel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (tunnel->sock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		struct inet_sock *inet = inet_sk(tunnel->sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (tunnel->sock->sk_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			const struct ipv6_pinfo *np = inet6_sk(tunnel->sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			seq_printf(m, " from %pI6c to %pI6c\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				   &np->saddr, &tunnel->sock->sk_v6_daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (tunnel->sock->sk_family == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			seq_printf(m, " from %pI4 to %pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				   &inet->inet_saddr, &inet->inet_daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (tunnel->encap == L2TP_ENCAPTYPE_UDP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			seq_printf(m, " source port %hu, dest port %hu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				   ntohs(inet->inet_sport), ntohs(inet->inet_dport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	seq_printf(m, " L2TPv%d, %s\n", tunnel->version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		   tunnel->encap == L2TP_ENCAPTYPE_UDP ? "UDP" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		   tunnel->encap == L2TP_ENCAPTYPE_IP ? "IP" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		   "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	seq_printf(m, " %d sessions, refcnt %d/%d\n", session_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		   tunnel->sock ? refcount_read(&tunnel->sock->sk_refcnt) : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		   refcount_read(&tunnel->ref_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	seq_printf(m, " %08x rx %ld/%ld/%ld rx %ld/%ld/%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		   0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		   atomic_long_read(&tunnel->stats.tx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		   atomic_long_read(&tunnel->stats.tx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		   atomic_long_read(&tunnel->stats.tx_errors),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		   atomic_long_read(&tunnel->stats.rx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		   atomic_long_read(&tunnel->stats.rx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		   atomic_long_read(&tunnel->stats.rx_errors));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct l2tp_session *session = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	seq_printf(m, "  SESSION %u, peer %u, %s\n", session->session_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		   session->peer_session_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		   session->pwtype == L2TP_PWTYPE_ETH ? "ETH" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		   session->pwtype == L2TP_PWTYPE_PPP ? "PPP" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		   "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (session->send_seq || session->recv_seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		seq_printf(m, "   nr %hu, ns %hu\n", session->nr, session->ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	seq_printf(m, "   refcnt %d\n", refcount_read(&session->ref_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	seq_printf(m, "   config 0/0/%c/%c/-/%s %08x %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		   session->recv_seq ? 'R' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		   session->send_seq ? 'S' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		   session->lns_mode ? "LNS" : "LAC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		   0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		   jiffies_to_msecs(session->reorder_timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	seq_printf(m, "   offset 0 l2specific %hu/%hu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		   session->l2specific_type, l2tp_get_l2specific_len(session));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (session->cookie_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		seq_printf(m, "   cookie %02x%02x%02x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			   session->cookie[0], session->cookie[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			   session->cookie[2], session->cookie[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (session->cookie_len == 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			seq_printf(m, "%02x%02x%02x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 				   session->cookie[4], session->cookie[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				   session->cookie[6], session->cookie[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		seq_puts(m, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (session->peer_cookie_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		seq_printf(m, "   peer cookie %02x%02x%02x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			   session->peer_cookie[0], session->peer_cookie[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			   session->peer_cookie[2], session->peer_cookie[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (session->peer_cookie_len == 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			seq_printf(m, "%02x%02x%02x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				   session->peer_cookie[4], session->peer_cookie[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				   session->peer_cookie[6], session->peer_cookie[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		seq_puts(m, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	seq_printf(m, "   %hu/%hu tx %ld/%ld/%ld rx %ld/%ld/%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		   session->nr, session->ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		   atomic_long_read(&session->stats.tx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		   atomic_long_read(&session->stats.tx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		   atomic_long_read(&session->stats.tx_errors),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		   atomic_long_read(&session->stats.rx_packets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		   atomic_long_read(&session->stats.rx_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		   atomic_long_read(&session->stats.rx_errors));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (session->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		session->show(m, session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int l2tp_dfs_seq_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct l2tp_dfs_seq_data *pd = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	/* display header on line 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (v == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		seq_puts(m, "TUNNEL ID, peer ID from IP to IP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		seq_puts(m, " L2TPv2/L2TPv3, UDP/IP\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		seq_puts(m, " sessions session-count, refcnt refcnt/sk->refcnt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		seq_puts(m, "  SESSION ID, peer ID, PWTYPE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		seq_puts(m, "   refcnt cnt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		seq_puts(m, "   offset OFFSET l2specific TYPE/LEN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		seq_puts(m, "   [ cookie ]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		seq_puts(m, "   [ peer cookie ]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		seq_puts(m, "   config mtu/mru/rcvseq/sendseq/dataseq/lns debug reorderto\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		seq_puts(m, "   nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (!pd->session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		l2tp_dfs_seq_tunnel_show(m, pd->tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		l2tp_dfs_seq_session_show(m, pd->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static const struct seq_operations l2tp_dfs_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	.start		= l2tp_dfs_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	.next		= l2tp_dfs_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	.stop		= l2tp_dfs_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	.show		= l2tp_dfs_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int l2tp_dfs_seq_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct l2tp_dfs_seq_data *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	int rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	pd = kzalloc(sizeof(*pd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (!pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	/* Derive the network namespace from the pid opening the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 * file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	pd->net = get_net_ns_by_pid(current->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (IS_ERR(pd->net)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		rc = PTR_ERR(pd->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		goto err_free_pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	rc = seq_open(file, &l2tp_dfs_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto err_free_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	seq->private = pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) err_free_net:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	put_net(pd->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) err_free_pd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	kfree(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int l2tp_dfs_seq_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct l2tp_dfs_seq_data *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	pd = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (pd->net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		put_net(pd->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	kfree(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	seq_release(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static const struct file_operations l2tp_dfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	.open		= l2tp_dfs_seq_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	.read		= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	.llseek		= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.release	= l2tp_dfs_seq_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static int __init l2tp_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	rootdir = debugfs_create_dir("l2tp", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	debugfs_create_file("tunnels", 0600, rootdir, NULL, &l2tp_dfs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	pr_info("L2TP debugfs support\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void __exit l2tp_debugfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	debugfs_remove_recursive(rootdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) module_init(l2tp_debugfs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) module_exit(l2tp_debugfs_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) MODULE_DESCRIPTION("L2TP debugfs driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) MODULE_VERSION("1.0");