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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	X.25 Packet Layer release 002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	This is ALPHA test software. This code may break your machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	randomly fail to work with new releases, misbehave and/or generally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	screw up. It might even work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	This code REQUIRES 2.4 with seq_file support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	History
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *	2002/10/06	Arnaldo Carvalho de Melo  seq_file support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <net/x25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	__acquires(x25_route_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	read_lock_bh(&x25_route_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	return seq_list_start_head(&x25_route_list, *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return seq_list_next(v, &x25_route_list, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static void x25_seq_route_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	__releases(x25_route_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	read_unlock_bh(&x25_route_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int x25_seq_route_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct x25_route *rt = list_entry(v, struct x25_route, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (v == &x25_route_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		seq_puts(seq, "Address          Digits  Device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		goto out;
^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) 	rt = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	seq_printf(seq, "%-15s  %-6d  %-5s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		   rt->address.x25_addr, rt->sigdigits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		   rt->dev ? rt->dev->name : "???");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	__acquires(x25_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	read_lock_bh(&x25_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return seq_hlist_start_head(&x25_list, *pos);
^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 *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return seq_hlist_next(v, &x25_list, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static void x25_seq_socket_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	__releases(x25_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	read_unlock_bh(&x25_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int x25_seq_socket_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct x25_sock *x25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	const char *devname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (v == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		seq_printf(seq, "dest_addr  src_addr   dev   lci st vs vr "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				"va   t  t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	s = sk_entry(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	x25 = x25_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		devname = "???";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		devname = x25->neighbour->dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	seq_printf(seq, "%-10s %-10s %-5s %3.3X  %d  %d  %d  %d %3lu %3lu "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			"%3lu %3lu %3lu %5d %5d %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		   !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		   !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		   devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		   x25->va, x25_display_timer(s) / HZ, x25->t2  / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		   x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		   sk_wmem_alloc_get(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		   sk_rmem_alloc_get(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		   s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void *x25_seq_forward_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	__acquires(x25_forward_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	read_lock_bh(&x25_forward_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return seq_list_start_head(&x25_forward_list, *pos);
^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 *x25_seq_forward_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return seq_list_next(v, &x25_forward_list, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static void x25_seq_forward_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	__releases(x25_forward_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	read_unlock_bh(&x25_forward_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int x25_seq_forward_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct x25_forward *f = list_entry(v, struct x25_forward, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (v == &x25_forward_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		seq_printf(seq, "lci dev1       dev2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		goto out;
^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) 	f = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	seq_printf(seq, "%d %-10s %-10s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			f->lci, f->dev1->name, f->dev2->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static const struct seq_operations x25_seq_route_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	.start  = x25_seq_route_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.next   = x25_seq_route_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.stop   = x25_seq_route_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.show   = x25_seq_route_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static const struct seq_operations x25_seq_socket_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	.start  = x25_seq_socket_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	.next   = x25_seq_socket_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	.stop   = x25_seq_socket_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.show   = x25_seq_socket_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static const struct seq_operations x25_seq_forward_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.start  = x25_seq_forward_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.next   = x25_seq_forward_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	.stop   = x25_seq_forward_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	.show   = x25_seq_forward_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int __init x25_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (!proc_mkdir("x25", init_net.proc_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (!proc_create_seq("x25/route", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			 &x25_seq_route_ops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (!proc_create_seq("x25/socket", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			 &x25_seq_socket_ops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (!proc_create_seq("x25/forward", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			 &x25_seq_forward_ops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	remove_proc_subtree("x25", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) void __exit x25_proc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	remove_proc_subtree("x25", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #else /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int __init x25_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) void __exit x25_proc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #endif /* CONFIG_PROC_FS */