^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 (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/termios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <net/rose.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int rose_ndevs = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int sysctl_rose_restart_request_timeout = ROSE_DEFAULT_T0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int sysctl_rose_call_request_timeout = ROSE_DEFAULT_T1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int sysctl_rose_reset_request_timeout = ROSE_DEFAULT_T2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int sysctl_rose_clear_request_timeout = ROSE_DEFAULT_T3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int sysctl_rose_no_activity_timeout = ROSE_DEFAULT_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int sysctl_rose_ack_hold_back_timeout = ROSE_DEFAULT_HB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int sysctl_rose_routing_control = ROSE_DEFAULT_ROUTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int sysctl_rose_link_fail_timeout = ROSE_DEFAULT_FAIL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int sysctl_rose_maximum_vcs = ROSE_DEFAULT_MAXVC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int sysctl_rose_window_size = ROSE_DEFAULT_WINDOW_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static HLIST_HEAD(rose_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static DEFINE_SPINLOCK(rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static const struct proto_ops rose_proto_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ax25_address rose_callsign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * ROSE network devices are virtual network devices encapsulating ROSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * 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 70) * special "super class" of normal net devices; split their locks off into a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * separate class since they always nest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static struct lock_class_key rose_netdev_xmit_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct lock_class_key rose_netdev_addr_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void rose_set_lockdep_one(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct netdev_queue *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) void *_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) lockdep_set_class(&txq->_xmit_lock, &rose_netdev_xmit_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void rose_set_lockdep_key(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) lockdep_set_class(&dev->addr_list_lock, &rose_netdev_addr_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) netdev_for_each_tx_queue(dev, rose_set_lockdep_one, NULL);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Convert a ROSE address into text.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) char *rose2asc(char *buf, const rose_address *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (addr->rose_addr[0] == 0x00 && addr->rose_addr[1] == 0x00 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) addr->rose_addr[2] == 0x00 && addr->rose_addr[3] == 0x00 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) addr->rose_addr[4] == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) strcpy(buf, "*");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) sprintf(buf, "%02X%02X%02X%02X%02X", addr->rose_addr[0] & 0xFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) addr->rose_addr[1] & 0xFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) addr->rose_addr[2] & 0xFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) addr->rose_addr[3] & 0xFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) addr->rose_addr[4] & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * Compare two ROSE addresses, 0 == equal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int rosecmp(rose_address *addr1, rose_address *addr2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) for (i = 0; i < 5; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (addr1->rose_addr[i] != addr2->rose_addr[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Compare two ROSE addresses for only mask digits, 0 == equal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int rosecmpm(rose_address *addr1, rose_address *addr2, unsigned short mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (mask > 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) for (i = 0; i < mask; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) j = i / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if ((i % 2) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if ((addr1->rose_addr[j] & 0x0F) != (addr2->rose_addr[j] & 0x0F))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if ((addr1->rose_addr[j] & 0xF0) != (addr2->rose_addr[j] & 0xF0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Socket removal during an interrupt is now safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static void rose_remove_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) spin_lock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) sk_del_node_init(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) spin_unlock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Kill all bound sockets on a broken link layer connection to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * particular neighbour.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) void rose_kill_by_neigh(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) spin_lock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) sk_for_each(s, &rose_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct rose_sock *rose = rose_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (rose->neighbour == neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) rose->neighbour = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) spin_unlock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * Kill all bound sockets on a dropped device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static void rose_kill_by_device(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) spin_lock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) sk_for_each(s, &rose_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct rose_sock *rose = rose_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (rose->device == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (rose->neighbour)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) rose->device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) spin_unlock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * Handle device status changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int rose_device_event(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (!net_eq(dev_net(dev), &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (event != NETDEV_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) switch (dev->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) case ARPHRD_ROSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) rose_kill_by_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case ARPHRD_AX25:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) rose_link_device_down(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) rose_rt_device_down(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return NOTIFY_DONE;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Add a socket to the bound sockets list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static void rose_insert_socket(struct sock *sk)
^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) spin_lock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sk_add_node(sk, &rose_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) spin_unlock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^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) * Find a socket that wants to accept the Call Request we just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static struct sock *rose_find_listener(rose_address *addr, ax25_address *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) spin_lock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) sk_for_each(s, &rose_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct rose_sock *rose = rose_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (!rosecmp(&rose->source_addr, addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) !ax25cmp(&rose->source_call, call) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) !rose->source_ndigis && s->sk_state == TCP_LISTEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) sk_for_each(s, &rose_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct rose_sock *rose = rose_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!rosecmp(&rose->source_addr, addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) !ax25cmp(&rose->source_call, &null_ax25_address) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) s->sk_state == TCP_LISTEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) spin_unlock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Find a connected ROSE socket given my LCI and device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct sock *rose_find_socket(unsigned int lci, struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) spin_lock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) sk_for_each(s, &rose_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct rose_sock *rose = rose_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (rose->lci == lci && rose->neighbour == neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) spin_unlock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^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) * Find a unique LCI for a given device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) unsigned int rose_new_lci(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int lci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (neigh->dce_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) for (lci = 1; lci <= sysctl_rose_maximum_vcs; lci++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return lci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) for (lci = sysctl_rose_maximum_vcs; lci > 0; lci--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (rose_find_socket(lci, neigh) == NULL && rose_route_free_lci(lci, neigh) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return lci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * Deferred destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) void rose_destroy_socket(struct sock *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * Handler for deferred kills.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static void rose_destroy_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct sock *sk = from_timer(sk, t, sk_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) rose_destroy_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * This is called from user mode and the timers. Thus it protects itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * against interrupt users but doesn't worry about being called during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * work. Once it is removed from the queue no interrupt or bottom half
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * will touch it and we are (fairly 8-) ) safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) void rose_destroy_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) rose_remove_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) rose_stop_heartbeat(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) rose_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) rose_clear_queues(sk); /* Flush the queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (skb->sk != sk) { /* A pending connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* Queue the unaccepted socket for death */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) sock_set_flag(skb->sk, SOCK_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) rose_start_heartbeat(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) rose_sk(skb->sk)->state = ROSE_STATE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (sk_has_allocations(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /* Defer: outstanding buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) timer_setup(&sk->sk_timer, rose_destroy_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) sk->sk_timer.expires = jiffies + 10 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) add_timer(&sk->sk_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * Handling for system calls applied via the various interfaces to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * ROSE socket object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static int rose_setsockopt(struct socket *sock, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) sockptr_t optval, unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) int opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (level != SOL_ROSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (copy_from_sockptr(&opt, optval, sizeof(int)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) switch (optname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) case ROSE_DEFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) rose->defer = opt ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) case ROSE_T1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (opt < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) rose->t1 = opt * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) case ROSE_T2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (opt < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) rose->t2 = opt * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) case ROSE_T3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (opt < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) rose->t3 = opt * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) case ROSE_HOLDBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (opt < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) rose->hb = opt * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) case ROSE_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (opt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) rose->idle = opt * 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) case ROSE_QBITINCL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) rose->qbitincl = opt ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static int rose_getsockopt(struct socket *sock, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (level != SOL_ROSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (get_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) switch (optname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) case ROSE_DEFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) val = rose->defer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) case ROSE_T1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) val = rose->t1 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) case ROSE_T2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) val = rose->t2 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) case ROSE_T3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) val = rose->t3 / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) case ROSE_HOLDBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) val = rose->hb / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) case ROSE_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) val = rose->idle / (60 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) case ROSE_QBITINCL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) val = rose->qbitincl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) len = min_t(unsigned int, len, sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return copy_to_user(optval, &val, len) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static int rose_listen(struct socket *sock, int backlog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (sk->sk_state != TCP_LISTEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) rose->dest_ndigis = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) memset(&rose->dest_addr, 0, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) memset(&rose->dest_call, 0, AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) memset(rose->dest_digis, 0, AX25_ADDR_LEN * ROSE_MAX_DIGIS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) sk->sk_max_ack_backlog = backlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) sk->sk_state = TCP_LISTEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static struct proto rose_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) .name = "ROSE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) .obj_size = sizeof(struct rose_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static int rose_create(struct net *net, struct socket *sock, int protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) int kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct rose_sock *rose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (!net_eq(net, &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (sock->type != SOCK_SEQPACKET || protocol != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return -ESOCKTNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) sk = sk_alloc(net, PF_ROSE, GFP_ATOMIC, &rose_proto, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (sk == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) sock_init_data(sock, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) skb_queue_head_init(&rose->ack_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) #ifdef M_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) skb_queue_head_init(&rose->frag_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) rose->fraglen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) sock->ops = &rose_proto_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) sk->sk_protocol = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) timer_setup(&rose->timer, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) timer_setup(&rose->idletimer, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) rose->t1 = msecs_to_jiffies(sysctl_rose_call_request_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) rose->t2 = msecs_to_jiffies(sysctl_rose_reset_request_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) rose->t3 = msecs_to_jiffies(sysctl_rose_clear_request_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) rose->hb = msecs_to_jiffies(sysctl_rose_ack_hold_back_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) rose->idle = msecs_to_jiffies(sysctl_rose_no_activity_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) rose->state = ROSE_STATE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static struct sock *rose_make_new(struct sock *osk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct rose_sock *rose, *orose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (osk->sk_type != SOCK_SEQPACKET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) sk = sk_alloc(sock_net(osk), PF_ROSE, GFP_ATOMIC, &rose_proto, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (sk == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) sock_init_data(NULL, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) skb_queue_head_init(&rose->ack_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) #ifdef M_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) skb_queue_head_init(&rose->frag_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) rose->fraglen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) sk->sk_type = osk->sk_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) sk->sk_priority = osk->sk_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) sk->sk_protocol = osk->sk_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) sk->sk_rcvbuf = osk->sk_rcvbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) sk->sk_sndbuf = osk->sk_sndbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) sk->sk_state = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) sock_copy_flags(sk, osk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) timer_setup(&rose->timer, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) timer_setup(&rose->idletimer, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) orose = rose_sk(osk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) rose->t1 = orose->t1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) rose->t2 = orose->t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) rose->t3 = orose->t3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) rose->hb = orose->hb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) rose->idle = orose->idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) rose->defer = orose->defer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) rose->device = orose->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) rose->qbitincl = orose->qbitincl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static int rose_release(struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct rose_sock *rose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (sk == NULL) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) sock_orphan(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) switch (rose->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) case ROSE_STATE_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) rose_disconnect(sk, 0, -1, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) rose_destroy_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) case ROSE_STATE_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) rose_disconnect(sk, 0, -1, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) rose_destroy_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) case ROSE_STATE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) case ROSE_STATE_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) case ROSE_STATE_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) case ROSE_STATE_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) rose_clear_queues(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) rose_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) rose_write_internal(sk, ROSE_CLEAR_REQUEST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) rose_start_t3timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) rose->state = ROSE_STATE_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) sk->sk_state = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) sk->sk_shutdown |= SEND_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) sock_set_flag(sk, SOCK_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) sock_set_flag(sk, SOCK_DESTROY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) break;
^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) sock->sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) static int rose_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) ax25_address *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) ax25_uid_assoc *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (!sock_flag(sk, SOCK_ZAPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (addr->srose_family != AF_ROSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if ((unsigned int) addr->srose_ndigis > ROSE_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if ((dev = rose_dev_get(&addr->srose_addr)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) source = &addr->srose_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) user = ax25_findbyuid(current_euid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) rose->source_call = user->call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) ax25_uid_put(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (ax25_uid_policy && !capable(CAP_NET_BIND_SERVICE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) rose->source_call = *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) rose->source_addr = addr->srose_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) rose->device = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) rose->source_ndigis = addr->srose_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (addr_len == sizeof(struct full_sockaddr_rose)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) for (n = 0 ; n < addr->srose_ndigis ; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) rose->source_digis[n] = full_addr->srose_digis[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (rose->source_ndigis == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) rose->source_digis[0] = addr->srose_digi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) rose_insert_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) sock_reset_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct sockaddr_rose *addr = (struct sockaddr_rose *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) unsigned char cause, diagnostic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) ax25_uid_assoc *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) int n, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (addr_len != sizeof(struct sockaddr_rose) && addr_len != sizeof(struct full_sockaddr_rose))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (addr->srose_family != AF_ROSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if (addr_len == sizeof(struct sockaddr_rose) && addr->srose_ndigis > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if ((unsigned int) addr->srose_ndigis > ROSE_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) /* Source + Destination digis should not exceed ROSE_MAX_DIGIS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if ((rose->source_ndigis + addr->srose_ndigis) > ROSE_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) /* Connect completed during a ERESTARTSYS event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) sock->state = SS_CONNECTED;
^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_CLOSE && sock->state == SS_CONNECTING) {
^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 = -ECONNREFUSED;
^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) if (sk->sk_state == TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) /* No reconnect on a seqpacket socket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) err = -EISCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) sk->sk_state = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) sock->state = SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) rose->neighbour = rose_get_neigh(&addr->srose_addr, &cause,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) &diagnostic, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if (!rose->neighbour) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) rose->lci = rose_new_lci(rose->neighbour);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (!rose->lci) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 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 780) sock_reset_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if ((dev = rose_dev_first()) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) user = ax25_findbyuid(current_euid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (!user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) memcpy(&rose->source_addr, dev->dev_addr, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) rose->source_call = user->call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) rose->device = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) ax25_uid_put(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) rose_insert_socket(sk); /* Finish the bind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) rose->dest_addr = addr->srose_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) rose->dest_call = addr->srose_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) rose->rand = ((long)rose & 0xFFFF) + rose->lci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) rose->dest_ndigis = addr->srose_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (addr_len == sizeof(struct full_sockaddr_rose)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) struct full_sockaddr_rose *full_addr = (struct full_sockaddr_rose *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) for (n = 0 ; n < addr->srose_ndigis ; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) rose->dest_digis[n] = full_addr->srose_digis[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (rose->dest_ndigis == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) rose->dest_digis[0] = addr->srose_digi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) /* Move to connecting socket, start sending Connect Requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) sock->state = SS_CONNECTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) sk->sk_state = TCP_SYN_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) rose->state = ROSE_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) rose->neighbour->use++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) rose_write_internal(sk, ROSE_CALL_REQUEST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) rose_start_heartbeat(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) rose_start_t1timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /* Now the loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) err = -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * A Connect Ack with Choke or timeout or failed routing will go to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) * closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (sk->sk_state == TCP_SYN_SENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) prepare_to_wait(sk_sleep(sk), &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (sk->sk_state != TCP_SYN_SENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (!signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) err = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) sock->state = SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) err = sock_error(sk); /* Always set at this point */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) sock->state = SS_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) out_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) static int rose_accept(struct socket *sock, struct socket *newsock, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) bool kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) struct sock *newsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if ((sk = sock->sk) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (sk->sk_type != SOCK_SEQPACKET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (sk->sk_state != TCP_LISTEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * The write queue this time is holding sockets ready to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) * hooked into the SABM we saved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) skb = skb_dequeue(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) if (flags & O_NONBLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) err = -EWOULDBLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (!signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) err = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) newsk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) sock_graft(newsk, newsock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) /* Now attach up the new socket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) skb->sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) sk_acceptq_removed(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) out_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) static int rose_getname(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) int peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct full_sockaddr_rose *srose = (struct full_sockaddr_rose *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) memset(srose, 0, sizeof(*srose));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (peer != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) srose->srose_family = AF_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) srose->srose_addr = rose->dest_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) srose->srose_call = rose->dest_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) srose->srose_ndigis = rose->dest_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) for (n = 0; n < rose->dest_ndigis; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) srose->srose_digis[n] = rose->dest_digis[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) srose->srose_family = AF_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) srose->srose_addr = rose->source_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) srose->srose_call = rose->source_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) srose->srose_ndigis = rose->source_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) for (n = 0; n < rose->source_ndigis; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) srose->srose_digis[n] = rose->source_digis[n];
^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) return sizeof(struct full_sockaddr_rose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) int rose_rx_call_request(struct sk_buff *skb, struct net_device *dev, struct rose_neigh *neigh, unsigned int lci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) struct sock *make;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) struct rose_sock *make_rose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) struct rose_facilities_struct facilities;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) skb->sk = NULL; /* Initially we don't know who it's for */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) * skb->data points to the rose frame start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) memset(&facilities, 0x00, sizeof(struct rose_facilities_struct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (!rose_parse_facilities(skb->data + ROSE_CALL_REQ_FACILITIES_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) skb->len - ROSE_CALL_REQ_FACILITIES_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) &facilities)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) rose_transmit_clear_request(neigh, lci, ROSE_INVALID_FACILITY, 76);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) sk = rose_find_listener(&facilities.source_addr, &facilities.source_call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) * We can't accept the Call Request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) if (sk == NULL || sk_acceptq_is_full(sk) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) (make = rose_make_new(sk)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) rose_transmit_clear_request(neigh, lci, ROSE_NETWORK_CONGESTION, 120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) skb->sk = make;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) make->sk_state = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) make_rose = rose_sk(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) make_rose->lci = lci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) make_rose->dest_addr = facilities.dest_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) make_rose->dest_call = facilities.dest_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) make_rose->dest_ndigis = facilities.dest_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) for (n = 0 ; n < facilities.dest_ndigis ; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) make_rose->dest_digis[n] = facilities.dest_digis[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) make_rose->source_addr = facilities.source_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) make_rose->source_call = facilities.source_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) make_rose->source_ndigis = facilities.source_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) for (n = 0 ; n < facilities.source_ndigis ; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) make_rose->source_digis[n] = facilities.source_digis[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) make_rose->neighbour = neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) make_rose->device = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) make_rose->facilities = facilities;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) make_rose->neighbour->use++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) if (rose_sk(sk)->defer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) make_rose->state = ROSE_STATE_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) rose_write_internal(make, ROSE_CALL_ACCEPTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) make_rose->state = ROSE_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) rose_start_idletimer(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) make_rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) make_rose->vs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) make_rose->va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) make_rose->vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) make_rose->vl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) sk_acceptq_added(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) rose_insert_socket(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) skb_queue_head(&sk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) rose_start_heartbeat(make);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (!sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) static int rose_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) DECLARE_SOCKADDR(struct sockaddr_rose *, usrose, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) struct full_sockaddr_rose srose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) unsigned char *asmptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) int n, size, qbit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_CMSG_COMPAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (sock_flag(sk, SOCK_ZAPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (sk->sk_shutdown & SEND_SHUTDOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) send_sig(SIGPIPE, current, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (rose->neighbour == NULL || rose->device == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) return -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (usrose != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (msg->msg_namelen != sizeof(struct sockaddr_rose) && msg->msg_namelen != sizeof(struct full_sockaddr_rose))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) memset(&srose, 0, sizeof(struct full_sockaddr_rose));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) memcpy(&srose, usrose, msg->msg_namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (rosecmp(&rose->dest_addr, &srose.srose_addr) != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) ax25cmp(&rose->dest_call, &srose.srose_call) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) return -EISCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (srose.srose_ndigis != rose->dest_ndigis)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) return -EISCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (srose.srose_ndigis == rose->dest_ndigis) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) for (n = 0 ; n < srose.srose_ndigis ; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if (ax25cmp(&rose->dest_digis[n],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) &srose.srose_digis[n]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) return -EISCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) if (srose.srose_family != AF_ROSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) srose.srose_family = AF_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) srose.srose_addr = rose->dest_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) srose.srose_call = rose->dest_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) srose.srose_ndigis = rose->dest_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) for (n = 0 ; n < rose->dest_ndigis ; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) srose.srose_digis[n] = rose->dest_digis[n];
^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) /* Build a packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) /* Sanity check the packet size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (len > 65535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) size = len + AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) if ((skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) * Put the data on the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) skb_put(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) err = memcpy_from_msg(skb_transport_header(skb), msg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) * If the Q BIT Include socket option is in force, the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) * byte of the user data is the logical value of the Q Bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) if (rose->qbitincl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) qbit = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) skb_pull(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) * Push down the ROSE header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) asmptr = skb_push(skb, ROSE_MIN_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) /* Build a ROSE Network header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) asmptr[0] = ((rose->lci >> 8) & 0x0F) | ROSE_GFI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) asmptr[1] = (rose->lci >> 0) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) asmptr[2] = ROSE_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (qbit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) asmptr[0] |= ROSE_Q_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) #ifdef M_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) #define ROSE_PACLEN (256-ROSE_MIN_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (skb->len - ROSE_MIN_LEN > ROSE_PACLEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) unsigned char header[ROSE_MIN_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) struct sk_buff *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) int frontlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) int lg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /* Save a copy of the Header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) skb_copy_from_linear_data(skb, header, ROSE_MIN_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) skb_pull(skb, ROSE_MIN_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) frontlen = skb_headroom(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) while (skb->len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) if ((skbn = sock_alloc_send_skb(sk, frontlen + ROSE_PACLEN, 0, &err)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) skbn->sk = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) skbn->free = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) skbn->arp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) skb_reserve(skbn, frontlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) lg = (ROSE_PACLEN > skb->len) ? skb->len : ROSE_PACLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) /* Copy the user data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) skb_copy_from_linear_data(skb, skb_put(skbn, lg), lg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) skb_pull(skb, lg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) /* Duplicate the Header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) skb_push(skbn, ROSE_MIN_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) skb_copy_to_linear_data(skbn, header, ROSE_MIN_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) if (skb->len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) skbn->data[2] |= M_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) skb_queue_tail(&sk->sk_write_queue, skbn); /* Throw it on the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) skb->free = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) skb_queue_tail(&sk->sk_write_queue, skb); /* Throw it on the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) skb_queue_tail(&sk->sk_write_queue, skb); /* Shove it onto the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) rose_kick(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^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) static int rose_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) size_t copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) unsigned char *asmptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) int n, er, qbit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * This works for seqpacket too. The receiver has ordered the queue for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) * us! We do one quick check first though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) /* Now we can treat all alike */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if ((skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, flags & MSG_DONTWAIT, &er)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) return er;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) qbit = (skb->data[0] & ROSE_Q_BIT) == ROSE_Q_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) skb_pull(skb, ROSE_MIN_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) if (rose->qbitincl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) asmptr = skb_push(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) *asmptr = qbit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) copied = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (copied > size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) copied = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) msg->msg_flags |= MSG_TRUNC;
^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) skb_copy_datagram_msg(skb, 0, msg, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) if (msg->msg_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) struct sockaddr_rose *srose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) DECLARE_SOCKADDR(struct full_sockaddr_rose *, full_srose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) memset(msg->msg_name, 0, sizeof(struct full_sockaddr_rose));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) srose = msg->msg_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) srose->srose_family = AF_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) srose->srose_addr = rose->dest_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) srose->srose_call = rose->dest_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) srose->srose_ndigis = rose->dest_ndigis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) for (n = 0 ; n < rose->dest_ndigis ; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) full_srose->srose_digis[n] = rose->dest_digis[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) msg->msg_namelen = sizeof(struct full_sockaddr_rose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) skb_free_datagram(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) return copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) case TIOCOUTQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) long amount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) if (amount < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) amount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return put_user(amount, (unsigned int __user *) argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) case TIOCINQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) long amount = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) /* These two are safe on a single CPU system as only user tasks fiddle here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) amount = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return put_user(amount, (unsigned int __user *) argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) case SIOCGIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) case SIOCSIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) case SIOCGIFDSTADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) case SIOCSIFDSTADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) case SIOCGIFBRDADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) case SIOCSIFBRDADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) case SIOCGIFNETMASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) case SIOCSIFNETMASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) case SIOCGIFMETRIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) case SIOCSIFMETRIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) case SIOCRSCLRRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) return rose_rt_ioctl(cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) case SIOCRSGCAUSE: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) struct rose_cause_struct rose_cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) rose_cause.cause = rose->cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) rose_cause.diagnostic = rose->diagnostic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) return copy_to_user(argp, &rose_cause, sizeof(struct rose_cause_struct)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) case SIOCRSSCAUSE: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) struct rose_cause_struct rose_cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) if (copy_from_user(&rose_cause, argp, sizeof(struct rose_cause_struct)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) rose->cause = rose_cause.cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) rose->diagnostic = rose_cause.diagnostic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) case SIOCRSSL2CALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) if (!capable(CAP_NET_ADMIN)) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) ax25_listen_release(&rose_callsign, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) if (copy_from_user(&rose_callsign, argp, sizeof(ax25_address)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) return ax25_listen_register(&rose_callsign, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) case SIOCRSGL2CALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) return copy_to_user(argp, &rose_callsign, sizeof(ax25_address)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) case SIOCRSACCEPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) if (rose->state == ROSE_STATE_5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) rose_write_internal(sk, ROSE_CALL_ACCEPTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) rose_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) rose->vs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) rose->va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) rose->vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) rose->vl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) rose->state = ROSE_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) static void *rose_info_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) __acquires(rose_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) spin_lock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) return seq_hlist_start_head(&rose_list, *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) static void *rose_info_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) return seq_hlist_next(v, &rose_list, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) static void rose_info_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) __releases(rose_list_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) spin_unlock_bh(&rose_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) static int rose_info_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) char buf[11], rsbuf[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) seq_puts(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) struct sock *s = sk_entry(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) struct rose_sock *rose = rose_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) const char *devname, *callsign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) const struct net_device *dev = rose->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) devname = "???";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) devname = dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) seq_printf(seq, "%-10s %-9s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) rose2asc(rsbuf, &rose->dest_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) ax2asc(buf, &rose->dest_call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) if (ax25cmp(&rose->source_call, &null_ax25_address) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) callsign = "??????-?";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) callsign = ax2asc(buf, &rose->source_call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) "%-10s %-9s %-5s %3.3X %05d %d %d %d %d %3lu %3lu %3lu %3lu %3lu %3lu/%03lu %5d %5d %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) rose2asc(rsbuf, &rose->source_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) callsign,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) devname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) rose->lci & 0x0FFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) (rose->neighbour) ? rose->neighbour->number : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) rose->state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) rose->vs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) rose->vr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) rose->va,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) ax25_display_timer(&rose->timer) / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) rose->t1 / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) rose->t2 / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) rose->t3 / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) rose->hb / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) ax25_display_timer(&rose->idletimer) / (60 * HZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) rose->idle / (60 * HZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) sk_wmem_alloc_get(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) sk_rmem_alloc_get(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) static const struct seq_operations rose_info_seqops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) .start = rose_info_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) .next = rose_info_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) .stop = rose_info_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) .show = rose_info_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) #endif /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) static const struct net_proto_family rose_family_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) .family = PF_ROSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) .create = rose_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) static const struct proto_ops rose_proto_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) .family = PF_ROSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) .release = rose_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) .bind = rose_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) .connect = rose_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) .socketpair = sock_no_socketpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) .accept = rose_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) .getname = rose_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) .poll = datagram_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) .ioctl = rose_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) .gettstamp = sock_gettstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) .listen = rose_listen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) .shutdown = sock_no_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) .setsockopt = rose_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) .getsockopt = rose_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) .sendmsg = rose_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) .recvmsg = rose_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) .mmap = sock_no_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) .sendpage = sock_no_sendpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) static struct notifier_block rose_dev_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) .notifier_call = rose_device_event,
^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) static struct net_device **dev_rose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) static struct ax25_protocol rose_pid = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) .pid = AX25_P_ROSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) .func = rose_route_frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) static struct ax25_linkfail rose_linkfail_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) .func = rose_link_failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) static int __init rose_proto_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (rose_ndevs > 0x7FFFFFFF/sizeof(struct net_device *)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) printk(KERN_ERR "ROSE: rose_proto_init - rose_ndevs parameter too large\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) rc = proto_register(&rose_proto, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) rose_callsign = null_ax25_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) dev_rose = kcalloc(rose_ndevs, sizeof(struct net_device *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) if (dev_rose == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) goto out_proto_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) for (i = 0; i < rose_ndevs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) char name[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) sprintf(name, "rose%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) dev = alloc_netdev(0, name, NET_NAME_UNKNOWN, rose_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) rc = register_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) printk(KERN_ERR "ROSE: netdevice registration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) rose_set_lockdep_key(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) dev_rose[i] = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) sock_register(&rose_family_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) register_netdevice_notifier(&rose_dev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) ax25_register_pid(&rose_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) ax25_linkfail_register(&rose_linkfail_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) rose_register_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) rose_loopback_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) rose_add_loopback_neigh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) proc_create_seq("rose", 0444, init_net.proc_net, &rose_info_seqops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) proc_create_seq("rose_neigh", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) &rose_neigh_seqops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) proc_create_seq("rose_nodes", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) &rose_node_seqops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) proc_create_seq("rose_routes", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) &rose_route_seqops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) while (--i >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) unregister_netdev(dev_rose[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) free_netdev(dev_rose[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) kfree(dev_rose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) out_proto_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) proto_unregister(&rose_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) module_init(rose_proto_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) module_param(rose_ndevs, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) MODULE_PARM_DESC(rose_ndevs, "number of ROSE devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) MODULE_DESCRIPTION("The amateur radio ROSE network layer protocol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) MODULE_ALIAS_NETPROTO(PF_ROSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) static void __exit rose_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) remove_proc_entry("rose", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) remove_proc_entry("rose_neigh", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) remove_proc_entry("rose_nodes", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) remove_proc_entry("rose_routes", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) rose_loopback_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) rose_rt_free();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) ax25_protocol_release(AX25_P_ROSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) ax25_linkfail_release(&rose_linkfail_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) ax25_listen_release(&rose_callsign, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) rose_unregister_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) unregister_netdevice_notifier(&rose_dev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) sock_unregister(PF_ROSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) for (i = 0; i < rose_ndevs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) struct net_device *dev = dev_rose[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) unregister_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) kfree(dev_rose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) proto_unregister(&rose_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) module_exit(rose_exit);