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)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright Darryl Miles G7LED (dlm@g7led.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/socket.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/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/termios.h>	/* For TIOCINQ/OUTQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <net/netrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) static int nr_ndevs = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) int sysctl_netrom_default_path_quality            = NR_DEFAULT_QUAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) int sysctl_netrom_obsolescence_count_initialiser  = NR_DEFAULT_OBS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) int sysctl_netrom_network_ttl_initialiser         = NR_DEFAULT_TTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) int sysctl_netrom_transport_timeout               = NR_DEFAULT_T1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) int sysctl_netrom_transport_maximum_tries         = NR_DEFAULT_N2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) int sysctl_netrom_transport_acknowledge_delay     = NR_DEFAULT_T2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) int sysctl_netrom_transport_busy_delay            = NR_DEFAULT_T4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) int sysctl_netrom_transport_requested_window_size = NR_DEFAULT_WINDOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) int sysctl_netrom_transport_no_activity_timeout   = NR_DEFAULT_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) int sysctl_netrom_routing_control                 = NR_DEFAULT_ROUTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) int sysctl_netrom_link_fails_count                = NR_DEFAULT_FAILS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) int sysctl_netrom_reset_circuit                   = NR_DEFAULT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static unsigned short circuit = 0x101;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) static HLIST_HEAD(nr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) static DEFINE_SPINLOCK(nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static const struct proto_ops nr_proto_ops;
^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)  * NETROM network devices are virtual network devices encapsulating NETROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  * frames into AX.25 which will be sent through an AX.25 device, so form a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * special "super class" of normal net devices; split their locks off into a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * separate class since they always nest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static struct lock_class_key nr_netdev_xmit_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static struct lock_class_key nr_netdev_addr_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) static void nr_set_lockdep_one(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 			       struct netdev_queue *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 			       void *_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	lockdep_set_class(&txq->_xmit_lock, &nr_netdev_xmit_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) static void nr_set_lockdep_key(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	lockdep_set_class(&dev->addr_list_lock, &nr_netdev_addr_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	netdev_for_each_tx_queue(dev, nr_set_lockdep_one, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  *	Socket removal during an interrupt is now safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) static void nr_remove_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	spin_lock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	sk_del_node_init(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	spin_unlock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  *	Kill all bound sockets on a dropped device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) static void nr_kill_by_device(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	spin_lock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	sk_for_each(s, &nr_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		if (nr_sk(s)->device == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 			nr_disconnect(s, ENETUNREACH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	spin_unlock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) }
^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)  *	Handle device status changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static int nr_device_event(struct notifier_block *this, unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	if (!net_eq(dev_net(dev), &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	if (event != NETDEV_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	nr_kill_by_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	nr_rt_device_down(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	return NOTIFY_DONE;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)  *	Add a socket to the bound sockets list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static void nr_insert_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	spin_lock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	sk_add_node(sk, &nr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	spin_unlock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142)  *	Find a socket that wants to accept the Connect Request we just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143)  *	received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) static struct sock *nr_find_listener(ax25_address *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	spin_lock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	sk_for_each(s, &nr_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		if (!ax25cmp(&nr_sk(s)->source_addr, addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		    s->sk_state == TCP_LISTEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 			sock_hold(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 			goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	spin_unlock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	return s;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  *	Find a connected NET/ROM socket given my circuit IDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static struct sock *nr_find_socket(unsigned char index, unsigned char id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	spin_lock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	sk_for_each(s, &nr_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		struct nr_sock *nr = nr_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		if (nr->my_index == index && nr->my_id == id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 			sock_hold(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 			goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	spin_unlock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)  *	Find a connected NET/ROM socket given their circuit IDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) static struct sock *nr_find_peer(unsigned char index, unsigned char id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	ax25_address *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	spin_lock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	sk_for_each(s, &nr_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		struct nr_sock *nr = nr_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		if (nr->your_index == index && nr->your_id == id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		    !ax25cmp(&nr->dest_addr, dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 			sock_hold(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 			goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	spin_unlock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209)  *	Find next free circuit ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) static unsigned short nr_find_next_circuit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	unsigned short id = circuit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	unsigned char i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		i = id / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		j = id % 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		if (i != 0 && j != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 			if ((sk=nr_find_socket(i, j)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 			sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	return id;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  *	Deferred destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) void nr_destroy_socket(struct sock *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)  *	Handler for deferred kills.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) static void nr_destroy_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	struct sock *sk = from_timer(sk, t, sk_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	nr_destroy_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252)  *	This is called from user mode and the timers. Thus it protects itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)  *	against interrupt users but doesn't worry about being called during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)  *	work. Once it is removed from the queue no interrupt or bottom half
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  *	will touch it and we are (fairly 8-) ) safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) void nr_destroy_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	nr_remove_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	nr_stop_heartbeat(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	nr_stop_t1timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	nr_stop_t2timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	nr_stop_t4timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	nr_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	nr_clear_queues(sk);		/* Flush the queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		if (skb->sk != sk) { /* A pending connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			/* Queue the unaccepted socket for death */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			sock_set_flag(skb->sk, SOCK_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 			nr_start_heartbeat(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 			nr_sk(skb->sk)->state = NR_STATE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	if (sk_has_allocations(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		/* Defer: outstanding buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		sk->sk_timer.function = nr_destroy_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		sk->sk_timer.expires  = jiffies + 2 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		add_timer(&sk->sk_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)  *	Handling for system calls applied via the various interfaces to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)  *	NET/ROM socket object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) static int nr_setsockopt(struct socket *sock, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		sockptr_t optval, unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	unsigned int opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	if (level != SOL_NETROM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	if (optlen < sizeof(unsigned int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (copy_from_sockptr(&opt, optval, sizeof(opt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	switch (optname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	case NETROM_T1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		if (opt < 1 || opt > UINT_MAX / HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		nr->t1 = opt * HZ;
^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) 	case NETROM_T2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		if (opt < 1 || opt > UINT_MAX / HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		nr->t2 = opt * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	case NETROM_N2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		if (opt < 1 || opt > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		nr->n2 = opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	case NETROM_T4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		if (opt < 1 || opt > UINT_MAX / HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		nr->t4 = opt * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	case NETROM_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		if (opt > UINT_MAX / (60 * HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		nr->idle = opt * 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) static int nr_getsockopt(struct socket *sock, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (level != SOL_NETROM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	if (get_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	switch (optname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	case NETROM_T1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		val = nr->t1 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	case NETROM_T2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		val = nr->t2 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	case NETROM_N2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		val = nr->n2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	case NETROM_T4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		val = nr->t4 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	case NETROM_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		val = nr->idle / (60 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	len = min_t(unsigned int, len, sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	return copy_to_user(optval, &val, len) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) static int nr_listen(struct socket *sock, int backlog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	if (sk->sk_state != TCP_LISTEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		memset(&nr_sk(sk)->user_addr, 0, AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		sk->sk_max_ack_backlog = backlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		sk->sk_state           = TCP_LISTEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) static struct proto nr_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	.name	  = "NETROM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	.owner	  = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	.obj_size = sizeof(struct nr_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) static int nr_create(struct net *net, struct socket *sock, int protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		     int kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct nr_sock *nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	if (!net_eq(net, &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	if (sock->type != SOCK_SEQPACKET || protocol != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		return -ESOCKTNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	sk = sk_alloc(net, PF_NETROM, GFP_ATOMIC, &nr_proto, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	if (sk  == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	sock_init_data(sock, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	sock->ops    = &nr_proto_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	sk->sk_protocol = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	skb_queue_head_init(&nr->ack_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	skb_queue_head_init(&nr->reseq_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	skb_queue_head_init(&nr->frag_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	nr_init_timers(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	nr->t1     =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		msecs_to_jiffies(sysctl_netrom_transport_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	nr->t2     =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		msecs_to_jiffies(sysctl_netrom_transport_acknowledge_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	nr->n2     =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		msecs_to_jiffies(sysctl_netrom_transport_maximum_tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	nr->t4     =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		msecs_to_jiffies(sysctl_netrom_transport_busy_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	nr->idle   =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		msecs_to_jiffies(sysctl_netrom_transport_no_activity_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	nr->window = sysctl_netrom_transport_requested_window_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	nr->bpqext = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	nr->state  = NR_STATE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) static struct sock *nr_make_new(struct sock *osk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	struct nr_sock *nr, *onr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	if (osk->sk_type != SOCK_SEQPACKET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	sk = sk_alloc(sock_net(osk), PF_NETROM, GFP_ATOMIC, osk->sk_prot, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	if (sk == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	sock_init_data(NULL, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	sk->sk_type     = osk->sk_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	sk->sk_priority = osk->sk_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	sk->sk_protocol = osk->sk_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	sk->sk_rcvbuf   = osk->sk_rcvbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	sk->sk_sndbuf   = osk->sk_sndbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	sk->sk_state    = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	sock_copy_flags(sk, osk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	skb_queue_head_init(&nr->ack_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	skb_queue_head_init(&nr->reseq_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	skb_queue_head_init(&nr->frag_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	nr_init_timers(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	onr = nr_sk(osk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	nr->t1      = onr->t1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	nr->t2      = onr->t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	nr->n2      = onr->n2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	nr->t4      = onr->t4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	nr->idle    = onr->idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	nr->window  = onr->window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	nr->device  = onr->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	nr->bpqext  = onr->bpqext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) static int nr_release(struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	struct nr_sock *nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	if (sk == NULL) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	sock_orphan(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	switch (nr->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	case NR_STATE_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	case NR_STATE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	case NR_STATE_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		nr_disconnect(sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		nr_destroy_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	case NR_STATE_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		nr_clear_queues(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		nr->n2count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		nr_write_internal(sk, NR_DISCREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		nr_start_t1timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		nr_stop_t2timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		nr_stop_t4timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		nr_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		nr->state    = NR_STATE_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		sk->sk_state    = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		sk->sk_shutdown |= SEND_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		sock_set_flag(sk, SOCK_DESTROY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	sock->sk   = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) static int nr_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	ax25_uid_assoc *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	ax25_address *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	if (!sock_flag(sk, SOCK_ZAPPED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	if (addr_len < sizeof(struct sockaddr_ax25) || addr_len > sizeof(struct full_sockaddr_ax25)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	if (addr_len < (addr->fsa_ax25.sax25_ndigis * sizeof(ax25_address) + sizeof(struct sockaddr_ax25))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	if (addr->fsa_ax25.sax25_family != AF_NETROM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	if ((dev = nr_dev_get(&addr->fsa_ax25.sax25_call)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	 * Only the super user can set an arbitrary user callsign.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	if (addr->fsa_ax25.sax25_ndigis == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		if (!capable(CAP_NET_BIND_SERVICE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		nr->user_addr   = addr->fsa_digipeater[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		nr->source_addr = addr->fsa_ax25.sax25_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		source = &addr->fsa_ax25.sax25_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		user = ax25_findbyuid(current_euid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		if (user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			nr->user_addr   = user->call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 			ax25_uid_put(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 			if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 				release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 				dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 				return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			nr->user_addr   = *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		nr->source_addr = *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	nr->device = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	nr_insert_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	sock_reset_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	int addr_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	struct sockaddr_ax25 *addr = (struct sockaddr_ax25 *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	ax25_address *source = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	ax25_uid_assoc *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		sock->state = SS_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		goto out_release;	/* Connect completed during a ERESTARTSYS event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	if (sk->sk_state == TCP_CLOSE && sock->state == SS_CONNECTING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		sock->state = SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		err = -ECONNREFUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (sk->sk_state == TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		err = -EISCONN;	/* No reconnect on a seqpacket socket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	sk->sk_state   = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	sock->state = SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	if (addr->sax25_family != AF_NETROM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	if (sock_flag(sk, SOCK_ZAPPED)) {	/* Must bind first - autobinding in this may or may not work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		sock_reset_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		if ((dev = nr_dev_first()) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 			err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		source = (ax25_address *)dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		user = ax25_findbyuid(current_euid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		if (user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			nr->user_addr   = user->call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			ax25_uid_put(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			if (ax25_uid_policy && !capable(CAP_NET_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 				dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 				err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 				goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			nr->user_addr   = *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		nr->source_addr = *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		nr->device      = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		nr_insert_socket(sk);		/* Finish the bind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	nr->dest_addr = addr->sax25_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	circuit = nr_find_next_circuit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	nr->my_index = circuit / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	nr->my_id    = circuit % 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	circuit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	/* Move to connecting socket, start sending Connect Requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	sock->state  = SS_CONNECTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	sk->sk_state = TCP_SYN_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	nr_establish_data_link(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	nr->state = NR_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	nr_start_heartbeat(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	/* Now the loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		err = -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	 * A Connect Ack with Choke or timeout or failed routing will go to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	 * closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	if (sk->sk_state == TCP_SYN_SENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 			prepare_to_wait(sk_sleep(sk), &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 					TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			if (sk->sk_state != TCP_SYN_SENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 			if (!signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 				release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 				schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 				lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			err = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	if (sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		sock->state = SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		err = sock_error(sk);	/* Always set at this point */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	sock->state = SS_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) out_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) static int nr_accept(struct socket *sock, struct socket *newsock, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		     bool kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	struct sock *newsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	if ((sk = sock->sk) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	if (sk->sk_type != SOCK_SEQPACKET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	if (sk->sk_state != TCP_LISTEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	 *	The write queue this time is holding sockets ready to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	 *	hooked into the SABM we saved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		skb = skb_dequeue(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		if (flags & O_NONBLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			err = -EWOULDBLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		if (!signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		err = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	newsk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	sock_graft(newsk, newsock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	/* Now attach up the new socket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	sk_acceptq_removed(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) out_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	int peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	struct full_sockaddr_ax25 *sax = (struct full_sockaddr_ax25 *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	int uaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	memset(&sax->fsa_ax25, 0, sizeof(struct sockaddr_ax25));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (peer != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		if (sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		sax->fsa_ax25.sax25_family = AF_NETROM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		sax->fsa_ax25.sax25_ndigis = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		sax->fsa_ax25.sax25_call   = nr->user_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		memset(sax->fsa_digipeater, 0, sizeof(sax->fsa_digipeater));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		sax->fsa_digipeater[0]     = nr->dest_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		uaddr_len = sizeof(struct full_sockaddr_ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		sax->fsa_ax25.sax25_family = AF_NETROM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		sax->fsa_ax25.sax25_ndigis = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		sax->fsa_ax25.sax25_call   = nr->source_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		uaddr_len = sizeof(struct sockaddr_ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return uaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	struct sock *make;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	struct nr_sock *nr_make;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	ax25_address *src, *dest, *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	unsigned short circuit_index, circuit_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	unsigned short peer_circuit_index, peer_circuit_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	unsigned short frametype, flags, window, timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	skb_orphan(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	 *	skb->data points to the netrom frame start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	src  = (ax25_address *)(skb->data + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	dest = (ax25_address *)(skb->data + 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	circuit_index      = skb->data[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	circuit_id         = skb->data[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	peer_circuit_index = skb->data[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	peer_circuit_id    = skb->data[18];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	frametype          = skb->data[19] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	flags              = skb->data[19] & 0xF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	 * Check for an incoming IP over NET/ROM frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	if (frametype == NR_PROTOEXT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	    circuit_index == NR_PROTO_IP && circuit_id == NR_PROTO_IP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		skb_pull(skb, NR_NETWORK_LEN + NR_TRANSPORT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		return nr_rx_ip(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	 * Find an existing socket connection, based on circuit ID, if it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	 * a Connect Request base it on their circuit ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	 * Circuit ID 0/0 is not valid but it could still be a "reset" for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	 * circuit that no longer exists at the other end ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	if (circuit_index == 0 && circuit_id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		if (frametype == NR_CONNACK && flags == NR_CHOKE_FLAG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 			sk = nr_find_peer(peer_circuit_index, peer_circuit_id, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		if (frametype == NR_CONNREQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 			sk = nr_find_peer(circuit_index, circuit_id, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 			sk = nr_find_socket(circuit_index, circuit_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	if (sk != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		if (frametype == NR_CONNACK && skb->len == 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			nr_sk(sk)->bpqext = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 			nr_sk(sk)->bpqext = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		ret = nr_process_rx_frame(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	 * Now it should be a CONNREQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (frametype != NR_CONNREQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		 * Here it would be nice to be able to send a reset but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		 * NET/ROM doesn't have one.  We've tried to extend the protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		 * by sending NR_CONNACK | NR_CHOKE_FLAGS replies but that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		 * apparently kills BPQ boxes... :-(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		 * So now we try to follow the established behaviour of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		 * G8PZT's Xrouter which is sending packets with command type 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		 * as an extension of the protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		if (sysctl_netrom_reset_circuit &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		    (frametype != NR_RESET || flags != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			nr_transmit_reset(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	sk = nr_find_listener(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	user = (ax25_address *)(skb->data + 21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (sk == NULL || sk_acceptq_is_full(sk) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	    (make = nr_make_new(sk)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		nr_transmit_refusal(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		if (sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	window = skb->data[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	sock_hold(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	skb->sk             = make;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	skb->destructor     = sock_efree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	make->sk_state	    = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	/* Fill in his circuit details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	nr_make = nr_sk(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	nr_make->source_addr = *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	nr_make->dest_addr   = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	nr_make->user_addr   = *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	nr_make->your_index  = circuit_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	nr_make->your_id     = circuit_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	circuit = nr_find_next_circuit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	bh_lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	nr_make->my_index    = circuit / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	nr_make->my_id       = circuit % 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	circuit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	/* Window negotiation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	if (window < nr_make->window)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		nr_make->window = window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	/* L4 timeout negotiation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	if (skb->len == 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		timeout = skb->data[36] * 256 + skb->data[35];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		if (timeout * HZ < nr_make->t1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			nr_make->t1 = timeout * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		nr_make->bpqext = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		nr_make->bpqext = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	nr_write_internal(make, NR_CONNACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	nr_make->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	nr_make->vs        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	nr_make->va        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	nr_make->vr        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	nr_make->vl        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	nr_make->state     = NR_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	sk_acceptq_added(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	skb_queue_head(&sk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	if (!sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	nr_insert_socket(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	nr_start_heartbeat(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	nr_start_idletimer(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static int nr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	DECLARE_SOCKADDR(struct sockaddr_ax25 *, usax, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	struct sockaddr_ax25 sax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	unsigned char *asmptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_CMSG_COMPAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	if (sock_flag(sk, SOCK_ZAPPED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (sk->sk_shutdown & SEND_SHUTDOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		send_sig(SIGPIPE, current, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		err = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	if (nr->device == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	if (usax) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		if (msg->msg_namelen < sizeof(sax)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		sax = *usax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		if (ax25cmp(&nr->dest_addr, &sax.sax25_call) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			err = -EISCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		if (sax.sax25_family != AF_NETROM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		if (sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 			err = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		sax.sax25_family = AF_NETROM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		sax.sax25_call   = nr->dest_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	/* Build a packet - the conventional user limit is 236 bytes. We can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	   do ludicrously large NetROM frames but must not overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (len > 65536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	size = len + NR_NETWORK_LEN + NR_TRANSPORT_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	if ((skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	skb_reserve(skb, size - len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	 *	Push down the NET/ROM header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	asmptr = skb_push(skb, NR_TRANSPORT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	/* Build a NET/ROM Transport header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	*asmptr++ = nr->your_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	*asmptr++ = nr->your_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	*asmptr++ = 0;		/* To be filled in later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	*asmptr++ = 0;		/*      Ditto            */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	*asmptr++ = NR_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	 *	Put the data on the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	skb_put(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	/* User data follows immediately after the NET/ROM transport header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	if (memcpy_from_msg(skb_transport_header(skb), msg, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	if (sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		err = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	nr_output(sk, skb);	/* Shove it onto the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	err = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static int nr_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		      int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	DECLARE_SOCKADDR(struct sockaddr_ax25 *, sax, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	size_t copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	int er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	 * This works for seqpacket too. The receiver has ordered the queue for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	 * us! We do one quick check first though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	if (sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	/* Now we can treat all alike */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		return er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	copied     = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	if (copied > size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		copied = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		msg->msg_flags |= MSG_TRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	er = skb_copy_datagram_msg(skb, 0, msg, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	if (er < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		skb_free_datagram(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		return er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	if (sax != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		memset(sax, 0, sizeof(*sax));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		sax->sax25_family = AF_NETROM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		skb_copy_from_linear_data_offset(skb, 7, sax->sax25_call.ax25_call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 			      AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		msg->msg_namelen = sizeof(*sax);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	skb_free_datagram(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	return copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	case TIOCOUTQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		long amount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		if (amount < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 			amount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		return put_user(amount, (int __user *)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	case TIOCINQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		long amount = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		/* These two are safe on a single CPU system as only user tasks fiddle here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			amount = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		return put_user(amount, (int __user *)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	case SIOCGIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	case SIOCSIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	case SIOCGIFDSTADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	case SIOCSIFDSTADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	case SIOCGIFBRDADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	case SIOCSIFBRDADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	case SIOCGIFNETMASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	case SIOCSIFNETMASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	case SIOCGIFMETRIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	case SIOCSIFMETRIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	case SIOCNRDECOBS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 		if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		return nr_rt_ioctl(cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) static void *nr_info_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	__acquires(&nr_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	spin_lock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	return seq_hlist_start_head(&nr_list, *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) static void *nr_info_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	return seq_hlist_next(v, &nr_list, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) static void nr_info_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	__releases(&nr_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	spin_unlock_bh(&nr_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) static int nr_info_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	struct sock *s = sk_entry(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	struct nr_sock *nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	const char *devname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	char buf[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		seq_puts(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) "user_addr dest_node src_node  dev    my  your  st  vs  vr  va    t1     t2     t4      idle   n2  wnd Snd-Q Rcv-Q inode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		bh_lock_sock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		nr = nr_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		if ((dev = nr->device) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 			devname = "???";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 			devname = dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		seq_printf(seq, "%-9s ", ax2asc(buf, &nr->user_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		seq_printf(seq, "%-9s ", ax2asc(buf, &nr->dest_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) "%-9s %-3s  %02X/%02X %02X/%02X %2d %3d %3d %3d %3lu/%03lu %2lu/%02lu %3lu/%03lu %3lu/%03lu %2d/%02d %3d %5d %5d %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 			ax2asc(buf, &nr->source_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 			devname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 			nr->my_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 			nr->my_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			nr->your_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 			nr->your_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 			nr->state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 			nr->vs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 			nr->vr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 			nr->va,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 			ax25_display_timer(&nr->t1timer) / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 			nr->t1 / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			ax25_display_timer(&nr->t2timer) / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 			nr->t2 / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 			ax25_display_timer(&nr->t4timer) / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 			nr->t4 / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 			ax25_display_timer(&nr->idletimer) / (60 * HZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 			nr->idle / (60 * HZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 			nr->n2count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 			nr->n2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			nr->window,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 			sk_wmem_alloc_get(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 			sk_rmem_alloc_get(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 			s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		bh_unlock_sock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) static const struct seq_operations nr_info_seqops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	.start = nr_info_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	.next = nr_info_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	.stop = nr_info_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	.show = nr_info_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) #endif	/* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) static const struct net_proto_family nr_family_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	.family		=	PF_NETROM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	.create		=	nr_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	.owner		=	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) static const struct proto_ops nr_proto_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	.family		=	PF_NETROM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	.owner		=	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	.release	=	nr_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	.bind		=	nr_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	.connect	=	nr_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	.socketpair	=	sock_no_socketpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	.accept		=	nr_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	.getname	=	nr_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	.poll		=	datagram_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	.ioctl		=	nr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	.gettstamp	=	sock_gettstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	.listen		=	nr_listen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	.shutdown	=	sock_no_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	.setsockopt	=	nr_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	.getsockopt	=	nr_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	.sendmsg	=	nr_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	.recvmsg	=	nr_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	.mmap		=	sock_no_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	.sendpage	=	sock_no_sendpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) static struct notifier_block nr_dev_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	.notifier_call	=	nr_device_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static struct net_device **dev_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) static struct ax25_protocol nr_pid = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	.pid	= AX25_P_NETROM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	.func	= nr_route_frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) static struct ax25_linkfail nr_linkfail_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	.func	= nr_link_failed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) static int __init nr_proto_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	int rc = proto_register(&nr_proto, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	if (nr_ndevs > 0x7fffffff/sizeof(struct net_device *)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		pr_err("NET/ROM: %s - nr_ndevs parameter too large\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		       __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		goto unregister_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	dev_nr = kcalloc(nr_ndevs, sizeof(struct net_device *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	if (!dev_nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		pr_err("NET/ROM: %s - unable to allocate device array\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		       __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		goto unregister_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	for (i = 0; i < nr_ndevs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		char name[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		sprintf(name, "nr%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		dev = alloc_netdev(0, name, NET_NAME_UNKNOWN, nr_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		dev->base_addr = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		rc = register_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 			free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		nr_set_lockdep_key(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		dev_nr[i] = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	rc = sock_register(&nr_family_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	rc = register_netdevice_notifier(&nr_dev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		goto out_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	ax25_register_pid(&nr_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	ax25_linkfail_register(&nr_linkfail_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	rc = nr_register_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 		goto out_sysctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	nr_loopback_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	if (!proc_create_seq("nr", 0444, init_net.proc_net, &nr_info_seqops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		goto proc_remove1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	if (!proc_create_seq("nr_neigh", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			     &nr_neigh_seqops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 		goto proc_remove2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	if (!proc_create_seq("nr_nodes", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 			     &nr_node_seqops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		goto proc_remove3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) proc_remove3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	remove_proc_entry("nr_neigh", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) proc_remove2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	remove_proc_entry("nr", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) proc_remove1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	nr_loopback_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	nr_rt_free();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	nr_unregister_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) out_sysctl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	ax25_linkfail_release(&nr_linkfail_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	ax25_protocol_release(AX25_P_NETROM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	unregister_netdevice_notifier(&nr_dev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) out_sock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	sock_unregister(PF_NETROM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	while (--i >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		unregister_netdev(dev_nr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		free_netdev(dev_nr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	kfree(dev_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) unregister_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	proto_unregister(&nr_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) module_init(nr_proto_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) module_param(nr_ndevs, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) MODULE_PARM_DESC(nr_ndevs, "number of NET/ROM devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) MODULE_DESCRIPTION("The amateur radio NET/ROM network and transport layer protocol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) MODULE_ALIAS_NETPROTO(PF_NETROM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) static void __exit nr_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	remove_proc_entry("nr", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	remove_proc_entry("nr_neigh", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	remove_proc_entry("nr_nodes", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	nr_loopback_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	nr_rt_free();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	nr_unregister_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	ax25_linkfail_release(&nr_linkfail_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	ax25_protocol_release(AX25_P_NETROM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	unregister_netdevice_notifier(&nr_dev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	sock_unregister(PF_NETROM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	for (i = 0; i < nr_ndevs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 		struct net_device *dev = dev_nr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 			unregister_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 			free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	kfree(dev_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	proto_unregister(&nr_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) module_exit(nr_exit);