^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) * DDP: An implementation of the AppleTalk DDP protocol for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Ethernet 'ELAP'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Alan Cox <alan@lxorguk.ukuu.org.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * With more than a little assistance from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Wesley Craig <netatalk@umich.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Fixes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Neil Horman : Added missing device ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Michael Callahan : Made routing work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Wesley Craig : Fix probing to listen to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * passed node id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Alan Cox : Added send/recvmsg support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Alan Cox : Moved at. to protinfo in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Alan Cox : Added firewall hooks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Alan Cox : Supports new ARPHRD_LOOPBACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Christer Weinigel : Routing and /proc fixes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Bradford Johnson : LocalTalk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Tom Dyas : Module support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Alan Cox : Hooks for PPP (based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * LocalTalk hook).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Alan Cox : Posix bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Alan Cox/Mike Freeman : Possible fix to NBP problems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Bradford Johnson : IP-over-DDP (experimental)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Jay Schulist : Moved IP-over-DDP to its own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * driver file. (ipddp.c & ipddp.h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Jay Schulist : Made work as module with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * AppleTalk drivers, cleaned it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Rob Newberry : Added proxy AARP and AARP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * procfs, moved probing to AARP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Adrian Sun/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Michael Zuelsdorff : fix for net.0 packets. don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * allow illegal ether/tokentalk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * port assignment. we lose a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * valid localtalk port as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Arnaldo C. de Melo : Cleanup, in preparation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * shared skb support 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Arnaldo C. de Melo : Move proc stuff to atalk_proc.c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * use seq_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/termios.h> /* For TIOCOUTQ/INQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <net/datalink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <net/psnap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <net/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #include <net/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <linux/atalk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct datalink_proto *ddp_dl, *aarp_dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static const struct proto_ops atalk_dgram_ops;
^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) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * Handlers for the socket list. *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) \**************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) HLIST_HEAD(atalk_sockets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) DEFINE_RWLOCK(atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static inline void __atalk_insert_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) sk_add_node(sk, &atalk_sockets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static inline void atalk_remove_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) write_lock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) sk_del_node_init(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) write_unlock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct sock *atalk_search_socket(struct sockaddr_at *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct atalk_iface *atif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) read_lock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sk_for_each(s, &atalk_sockets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct atalk_sock *at = at_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (to->sat_port != at->src_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (to->sat_addr.s_net == ATADDR_ANYNET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) to->sat_addr.s_node == ATADDR_BCAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (to->sat_addr.s_net == at->src_net &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) (to->sat_addr.s_node == at->src_node ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) to->sat_addr.s_node == ATADDR_BCAST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) to->sat_addr.s_node == ATADDR_ANYNODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* XXXX.0 -- we got a request for this router. make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * that the node is appropriately set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (to->sat_addr.s_node == ATADDR_ANYNODE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) to->sat_addr.s_net != ATADDR_ANYNET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) atif->address.s_node == at->src_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) to->sat_addr.s_node = atif->address.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) read_unlock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * atalk_find_or_insert_socket - Try to find a socket matching ADDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * @sk: socket to insert in the list if it is not there already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @sat: address to search for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * Try to find a socket matching ADDR in the socket list, if found then return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * it. If not, insert SK into the socket list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * This entire operation must execute atomically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static struct sock *atalk_find_or_insert_socket(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct sockaddr_at *sat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct atalk_sock *at;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) write_lock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) sk_for_each(s, &atalk_sockets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) at = at_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (at->src_net == sat->sat_addr.s_net &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) at->src_node == sat->sat_addr.s_node &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) at->src_port == sat->sat_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) __atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) write_unlock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static void atalk_destroy_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct sock *sk = from_timer(sk, t, sk_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (sk_has_allocations(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) add_timer(&sk->sk_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static inline void atalk_destroy_socket(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) atalk_remove_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) skb_queue_purge(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (sk_has_allocations(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) timer_setup(&sk->sk_timer, atalk_destroy_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) add_timer(&sk->sk_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /**************************************************************************\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * Routing tables for the AppleTalk socket layer. *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) \**************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct atalk_route *atalk_routes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) DEFINE_RWLOCK(atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct atalk_iface *atalk_interfaces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) DEFINE_RWLOCK(atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* For probing devices or in a routerless network */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct atalk_route atrtr_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* AppleTalk interface control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * Drop a device. Doesn't drop any of its routes - that is the caller's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * problem. Called when we down the interface or delete the address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void atif_drop_device(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct atalk_iface **iface = &atalk_interfaces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct atalk_iface *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) write_lock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) while ((tmp = *iface) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (tmp->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) *iface = tmp->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) dev->atalk_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) iface = &tmp->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) write_unlock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static struct atalk_iface *atif_add_device(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct atalk_addr *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct atalk_iface *iface = kzalloc(sizeof(*iface), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (!iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) iface->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) dev->atalk_ptr = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) iface->address = *sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) iface->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) write_lock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) iface->next = atalk_interfaces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) atalk_interfaces = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) write_unlock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* Perform phase 2 AARP probing on our tentative address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int atif_probe_device(struct atalk_iface *atif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int netrange = ntohs(atif->nets.nr_lastnet) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ntohs(atif->nets.nr_firstnet) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int probe_net = ntohs(atif->address.s_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int probe_node = atif->address.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int netct, nodect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Offset the network we start probing with */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (probe_net == ATADDR_ANYNET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) probe_net = ntohs(atif->nets.nr_firstnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (netrange)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) probe_net += jiffies % netrange;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (probe_node == ATADDR_ANYNODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) probe_node = jiffies & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* Scan the networks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) atif->status |= ATIF_PROBE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) for (netct = 0; netct <= netrange; netct++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* Sweep the available nodes from a given start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) atif->address.s_net = htons(probe_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) for (nodect = 0; nodect < 256; nodect++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) atif->address.s_node = (nodect + probe_node) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (atif->address.s_node > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) atif->address.s_node < 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* Probe a proposed address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) aarp_probe_network(atif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!(atif->status & ATIF_PROBE_FAIL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) atif->status &= ~ATIF_PROBE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) atif->status &= ~ATIF_PROBE_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) probe_net++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (probe_net > ntohs(atif->nets.nr_lastnet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) probe_net = ntohs(atif->nets.nr_firstnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) atif->status &= ~ATIF_PROBE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return -EADDRINUSE; /* Network is full... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* Perform AARP probing for a proxy address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int atif_proxy_probe_device(struct atalk_iface *atif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct atalk_addr *proxy_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int netrange = ntohs(atif->nets.nr_lastnet) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ntohs(atif->nets.nr_firstnet) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* we probe the interface's network */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int probe_net = ntohs(atif->address.s_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int probe_node = ATADDR_ANYNODE; /* we'll take anything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int netct, nodect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* Offset the network we start probing with */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (probe_net == ATADDR_ANYNET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) probe_net = ntohs(atif->nets.nr_firstnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (netrange)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) probe_net += jiffies % netrange;
^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) if (probe_node == ATADDR_ANYNODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) probe_node = jiffies & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* Scan the networks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) for (netct = 0; netct <= netrange; netct++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* Sweep the available nodes from a given start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) proxy_addr->s_net = htons(probe_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) for (nodect = 0; nodect < 256; nodect++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) proxy_addr->s_node = (nodect + probe_node) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (proxy_addr->s_node > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) proxy_addr->s_node < 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* Tell AARP to probe a proposed address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) int ret = aarp_proxy_probe_network(atif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) proxy_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (ret != -EADDRINUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return ret;
^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) probe_net++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (probe_net > ntohs(atif->nets.nr_lastnet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) probe_net = ntohs(atif->nets.nr_firstnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return -EADDRINUSE; /* Network is full... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct atalk_addr *atalk_find_dev_addr(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct atalk_iface *iface = dev->atalk_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return iface ? &iface->address : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static struct atalk_addr *atalk_find_primary(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct atalk_iface *fiface = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct atalk_addr *retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct atalk_iface *iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * Return a point-to-point interface only if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * there is no non-ptp interface available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) read_lock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) for (iface = atalk_interfaces; iface; iface = iface->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (!fiface && !(iface->dev->flags & IFF_LOOPBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) fiface = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) retval = &iface->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (fiface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) retval = &fiface->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) else if (atalk_interfaces)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) retval = &atalk_interfaces->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) retval = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) read_unlock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * Find a match for 'any network' - ie any of our interfaces with that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * node number will do just nicely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static struct atalk_iface *atalk_find_anynet(int node, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct atalk_iface *iface = dev->atalk_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (!iface || iface->status & ATIF_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (node != ATADDR_BCAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) iface->address.s_node != node &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) node != ATADDR_ANYNODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) iface = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* Find a match for a specific network:node pair */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static struct atalk_iface *atalk_find_interface(__be16 net, int node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct atalk_iface *iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) read_lock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) for (iface = atalk_interfaces; iface; iface = iface->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if ((node == ATADDR_BCAST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) node == ATADDR_ANYNODE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) iface->address.s_node == node) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) iface->address.s_net == net &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) !(iface->status & ATIF_PROBE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /* XXXX.0 -- net.0 returns the iface associated with net */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (node == ATADDR_ANYNODE && net != ATADDR_ANYNET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ntohs(iface->nets.nr_firstnet) <= ntohs(net) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ntohs(net) <= ntohs(iface->nets.nr_lastnet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) read_unlock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * Find a route for an AppleTalk packet. This ought to get cached in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * the socket (later on...). We know about host routes and the fact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * that a route must be direct to broadcast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static struct atalk_route *atrtr_find(struct atalk_addr *target)
^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) * we must search through all routes unless we find a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * host route, because some host routes might overlap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * network routes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct atalk_route *net_route = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct atalk_route *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) read_lock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) for (r = atalk_routes; r; r = r->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (!(r->flags & RTF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (r->target.s_net == target->s_net) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (r->flags & RTF_HOST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * if this host route is for the target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * the we're done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (r->target.s_node == target->s_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * this route will work if there isn't a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * direct host route, so cache it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) net_route = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * if we found a network route but not a direct host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * route, then return it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (net_route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) r = net_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) else if (atrtr_default.dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) r = &atrtr_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) else /* No route can be found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) r = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) read_unlock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * Given an AppleTalk network, find the device to use. This can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * a simple lookup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct net_device *atrtr_get_dev(struct atalk_addr *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct atalk_route *atr = atrtr_find(sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return atr ? atr->dev : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* Set up a default router */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static void atrtr_set_default(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) atrtr_default.dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) atrtr_default.flags = RTF_UP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) atrtr_default.gateway.s_net = htons(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) atrtr_default.gateway.s_node = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * Add a router. Basically make sure it looks valid and stuff the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * entry in the list. While it uses netranges we always set them to one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * entry to work like netatalk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static int atrtr_create(struct rtentry *r, struct net_device *devhint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct atalk_route *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct atalk_iface *iface, *riface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * Fixme: Raise/Lower a routing change semaphore for these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* Validate the request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (ta->sat_family != AF_APPLETALK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) (!devhint && ga->sat_family != AF_APPLETALK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* Now walk the routing table and make our decisions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) write_lock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) for (rt = atalk_routes; rt; rt = rt->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (r->rt_flags != rt->flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (ta->sat_addr.s_net == rt->target.s_net) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (!(rt->flags & RTF_HOST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (ta->sat_addr.s_node == rt->target.s_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (!devhint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) riface = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) read_lock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) for (iface = atalk_interfaces; iface; iface = iface->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (!riface &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) ntohs(ga->sat_addr.s_net) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) ntohs(iface->nets.nr_firstnet) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) ntohs(ga->sat_addr.s_net) <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ntohs(iface->nets.nr_lastnet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) riface = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (ga->sat_addr.s_net == iface->address.s_net &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ga->sat_addr.s_node == iface->address.s_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) riface = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) read_unlock_bh(&atalk_interfaces_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) retval = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (!riface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) devhint = riface->dev;
^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) if (!rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) rt = kzalloc(sizeof(*rt), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) retval = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (!rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) rt->next = atalk_routes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) atalk_routes = rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /* Fill in the routing entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) rt->target = ta->sat_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) dev_hold(devhint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) rt->dev = devhint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) rt->flags = r->rt_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) rt->gateway = ga->sat_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) write_unlock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* Delete a route. Find it and discard it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static int atrtr_delete(struct atalk_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct atalk_route **r = &atalk_routes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct atalk_route *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) write_lock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) while ((tmp = *r) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (tmp->target.s_net == addr->s_net &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) (!(tmp->flags&RTF_GATEWAY) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) tmp->target.s_node == addr->s_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) *r = tmp->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) dev_put(tmp->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) r = &tmp->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) retval = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) write_unlock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) * Called when a device is downed. Just throw away any routes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * via it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static void atrtr_device_down(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct atalk_route **r = &atalk_routes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct atalk_route *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) write_lock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) while ((tmp = *r) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (tmp->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) *r = tmp->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) r = &tmp->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) write_unlock_bh(&atalk_routes_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (atrtr_default.dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) atrtr_set_default(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* Actually down the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static inline void atalk_dev_down(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) atrtr_device_down(dev); /* Remove all routes for the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) aarp_device_down(dev); /* Remove AARP entries for the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) atif_drop_device(dev); /* Remove the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * A device event has occurred. Watch for devices going down and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * delete our use of them (iface and route).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) static int ddp_device_event(struct notifier_block *this, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (!net_eq(dev_net(dev), &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (event == NETDEV_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) /* Discard any use of this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) atalk_dev_down(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) return NOTIFY_DONE;
^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) /* ioctl calls. Shouldn't even need touching */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Device configuration ioctl calls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static int atif_ioctl(int cmd, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct ifreq atreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct atalk_netrange *nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) struct sockaddr_at *sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) struct atalk_iface *atif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) int ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) int limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) struct rtentry rtdef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) int add_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (copy_from_user(&atreq, arg, sizeof(atreq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) dev = __dev_get_by_name(&init_net, atreq.ifr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) sa = (struct sockaddr_at *)&atreq.ifr_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) atif = atalk_find_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) case SIOCSIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (sa->sat_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (dev->type != ARPHRD_ETHER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) dev->type != ARPHRD_LOOPBACK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) dev->type != ARPHRD_LOCALTLK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) dev->type != ARPHRD_PPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) nr = (struct atalk_netrange *)&sa->sat_zero[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) add_route = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * if this is a point-to-point iface, and we already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * have an iface for this AppleTalk address, then we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * should not add a route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if ((dev->flags & IFF_POINTOPOINT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) atalk_find_interface(sa->sat_addr.s_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) sa->sat_addr.s_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) printk(KERN_DEBUG "AppleTalk: point-to-point "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) "interface added with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) "existing address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) add_route = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^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) * Phase 1 is fine on LocalTalk but we don't do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * EtherTalk phase 1. Anyone wanting to add it go ahead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (sa->sat_addr.s_node == ATADDR_BCAST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) sa->sat_addr.s_node == 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (atif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) /* Already setting address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (atif->status & ATIF_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) atif->address.s_net = sa->sat_addr.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) atif->address.s_node = sa->sat_addr.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) atrtr_device_down(dev); /* Flush old routes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) atif = atif_add_device(dev, &sa->sat_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (!atif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) atif->nets = *nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * Check if the chosen address is used. If so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * error and atalkd will try another.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) if (!(dev->flags & IFF_LOOPBACK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) !(dev->flags & IFF_POINTOPOINT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) atif_probe_device(atif) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) atif_drop_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* Hey it worked - add the direct routes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) sa = (struct sockaddr_at *)&rtdef.rt_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) sa->sat_family = AF_APPLETALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) sa->sat_addr.s_net = atif->address.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) sa->sat_addr.s_node = atif->address.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) sa = (struct sockaddr_at *)&rtdef.rt_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) rtdef.rt_flags = RTF_UP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) sa->sat_family = AF_APPLETALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) sa->sat_addr.s_node = ATADDR_ANYNODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (dev->flags & IFF_LOOPBACK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) dev->flags & IFF_POINTOPOINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) rtdef.rt_flags |= RTF_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) /* Routerless initial state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (nr->nr_firstnet == htons(0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) nr->nr_lastnet == htons(0xFFFE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) sa->sat_addr.s_net = atif->address.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) atrtr_create(&rtdef, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) atrtr_set_default(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) limit = ntohs(nr->nr_lastnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (limit - ntohs(nr->nr_firstnet) > 4096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) printk(KERN_WARNING "Too many routes/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) "iface.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (add_route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) for (ct = ntohs(nr->nr_firstnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) ct <= limit; ct++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) sa->sat_addr.s_net = htons(ct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) atrtr_create(&rtdef, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) dev_mc_add_global(dev, aarp_mcast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) case SIOCGIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) if (!atif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) sa->sat_family = AF_APPLETALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) sa->sat_addr = atif->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) case SIOCGIFBRDADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (!atif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) sa->sat_family = AF_APPLETALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) sa->sat_addr.s_net = atif->address.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) sa->sat_addr.s_node = ATADDR_BCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) case SIOCATALKDIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) case SIOCDIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (sa->sat_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) atalk_dev_down(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) case SIOCSARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (sa->sat_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * for now, we only support proxy AARP on ELAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * we should be able to do it for LocalTalk, too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (dev->type != ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * atif points to the current interface on this network;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * we aren't concerned about its current status (at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * least for now), but it has all the settings about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * the network we're going to probe. Consequently, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * must exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (!atif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) nr = (struct atalk_netrange *)&(atif->nets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) * Phase 1 is fine on Localtalk but we don't do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) * Ethertalk phase 1. Anyone wanting to add it go ahead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (sa->sat_addr.s_node == ATADDR_BCAST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) sa->sat_addr.s_node == 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * Check if the chosen address is used. If so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * error and ATCP will try another.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) return -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * We now have an address on the local network, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * the AARP code will defend it for us until we take it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * down. We don't set up any routes right now, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * ATCP will install them manually via SIOCADDRT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) case SIOCDARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (sa->sat_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!atif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* give to aarp module to remove proxy entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) aarp_proxy_remove(atif->dev, &(sa->sat_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return copy_to_user(arg, &atreq, sizeof(atreq)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) static int atrtr_ioctl_addrt(struct rtentry *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) struct net_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (rt->rt_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) char name[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (copy_from_user(name, rt->rt_dev, IFNAMSIZ-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) name[IFNAMSIZ-1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) dev = __dev_get_by_name(&init_net, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) return atrtr_create(rt, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* Routing ioctl() calls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) static int atrtr_ioctl(unsigned int cmd, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) struct rtentry rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (copy_from_user(&rt, arg, sizeof(rt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (rt.rt_dst.sa_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) return atrtr_delete(&((struct sockaddr_at *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) &rt.rt_dst)->sat_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return atrtr_ioctl_addrt(&rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) /**************************************************************************\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * Handling for system calls applied via the various interfaces to an *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * AppleTalk socket object. *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) \**************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) * Checksum: This is 'optional'. It's quite likely also a good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) * candidate for assembler hackery 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) static unsigned long atalk_sum_partial(const unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) int len, unsigned long sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) /* This ought to be unwrapped neatly. I'll trust gcc for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) while (len--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) sum += *data++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) sum = rol16(sum, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) /* Checksum skb data -- similar to skb_checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) int len, unsigned long sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) int start = skb_headlen(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct sk_buff *frag_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) int i, copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) /* checksum stuff in header space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if ((copy = start - offset) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (copy > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) copy = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) sum = atalk_sum_partial(skb->data + offset, copy, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if ((len -= copy) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) offset += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) /* checksum stuff in frags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) int end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) WARN_ON(start > offset + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) end = start + skb_frag_size(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) if ((copy = end - offset) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) u8 *vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) if (copy > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) copy = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) vaddr = kmap_atomic(skb_frag_page(frag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) sum = atalk_sum_partial(vaddr + skb_frag_off(frag) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) offset - start, copy, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) kunmap_atomic(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (!(len -= copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) offset += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) start = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) skb_walk_frags(skb, frag_iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) int end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) WARN_ON(start > offset + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) end = start + frag_iter->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if ((copy = end - offset) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (copy > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) copy = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) sum = atalk_sum_skb(frag_iter, offset - start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) copy, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if ((len -= copy) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) offset += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) start = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) BUG_ON(len > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) static __be16 atalk_checksum(const struct sk_buff *skb, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) unsigned long sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) /* skip header 4 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) sum = atalk_sum_skb(skb, 4, len-4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) /* Use 0xFFFF for 0. 0 itself means none */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) return sum ? htons((unsigned short)sum) : htons(0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) static struct proto ddp_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) .name = "DDP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) .obj_size = sizeof(struct atalk_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) * Create a socket. Initialise the socket, blank the addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) * set the state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) static int atalk_create(struct net *net, struct socket *sock, int protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) int kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) int rc = -ESOCKTNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (!net_eq(net, &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) * We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * and gives you the full ELAP frame. Should be handy for CAP 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) rc = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) sk = sk_alloc(net, PF_APPLETALK, GFP_KERNEL, &ddp_proto, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) sock->ops = &atalk_dgram_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) sock_init_data(sock, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) /* Checksums on by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) sock_set_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) /* Free a socket. No work needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) static int atalk_release(struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) if (sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) sock_orphan(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) sock->sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) atalk_destroy_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) return 0;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) * atalk_pick_and_bind_port - Pick a source port when one is not given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) * @sk: socket to insert into the tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) * @sat: address to search for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) * Pick a source port when one is not given. If we can find a suitable free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) * one, we insert the socket into the tables using it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) * This whole operation must be atomic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) write_lock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) for (sat->sat_port = ATPORT_RESERVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) sat->sat_port < ATPORT_LAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) sat->sat_port++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) sk_for_each(s, &atalk_sockets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) struct atalk_sock *at = at_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) if (at->src_net == sat->sat_addr.s_net &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) at->src_node == sat->sat_addr.s_node &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) at->src_port == sat->sat_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) goto try_next_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) /* Wheee, it's free, assign and insert. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) __atalk_insert_socket(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) at_sk(sk)->src_port = sat->sat_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) try_next_port:;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) retval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) write_unlock_bh(&atalk_sockets_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static int atalk_autobind(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) struct atalk_sock *at = at_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct sockaddr_at sat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) struct atalk_addr *ap = atalk_find_primary();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) int n = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (!ap || ap->s_net == htons(ATADDR_ANYNET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) at->src_net = sat.sat_addr.s_net = ap->s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) at->src_node = sat.sat_addr.s_node = ap->s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) n = atalk_pick_and_bind_port(sk, &sat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (!n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) sock_reset_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) /* Set the address 'our end' of the connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) struct atalk_sock *at = at_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (!sock_flag(sk, SOCK_ZAPPED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) addr_len != sizeof(struct sockaddr_at))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (addr->sat_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) struct atalk_addr *ap = atalk_find_primary();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (!ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) at->src_net = addr->sat_addr.s_net = ap->s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) at->src_node = addr->sat_addr.s_node = ap->s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (!atalk_find_interface(addr->sat_addr.s_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) addr->sat_addr.s_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) at->src_net = addr->sat_addr.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) at->src_node = addr->sat_addr.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) if (addr->sat_port == ATADDR_ANYPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) err = atalk_pick_and_bind_port(sk, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) at->src_port = addr->sat_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) err = -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) if (atalk_find_or_insert_socket(sk, addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) sock_reset_flag(sk, SOCK_ZAPPED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) /* Set the address we talk to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) int addr_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) struct atalk_sock *at = at_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) struct sockaddr_at *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) sk->sk_state = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) sock->state = SS_UNCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (addr_len != sizeof(*addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) addr = (struct sockaddr_at *)uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if (addr->sat_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) if (addr->sat_addr.s_node == ATADDR_BCAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) !sock_flag(sk, SOCK_BROADCAST)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) #if 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) pr_warn("atalk_connect: %s is broken and did not set SO_BROADCAST.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (sock_flag(sk, SOCK_ZAPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) if (atalk_autobind(sk) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) if (!atrtr_get_dev(&addr->sat_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) at->dest_port = addr->sat_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) at->dest_net = addr->sat_addr.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) at->dest_node = addr->sat_addr.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) sock->state = SS_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) sk->sk_state = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) return err;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) * Find the name of an AppleTalk socket. Just copy the right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) * fields into the sockaddr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) int peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) struct sockaddr_at sat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) struct atalk_sock *at = at_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) if (sock_flag(sk, SOCK_ZAPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if (atalk_autobind(sk) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) memset(&sat, 0, sizeof(sat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (peer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) err = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) sat.sat_addr.s_net = at->dest_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) sat.sat_addr.s_node = at->dest_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) sat.sat_port = at->dest_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) sat.sat_addr.s_net = at->src_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) sat.sat_addr.s_node = at->src_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) sat.sat_port = at->src_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) sat.sat_family = AF_APPLETALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) memcpy(uaddr, &sat, sizeof(sat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) err = sizeof(struct sockaddr_at);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) #if IS_ENABLED(CONFIG_IPDDP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) return skb->data[12] == 22;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) static int handle_ip_over_ddp(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) struct net_device *dev = __dev_get_by_name(&init_net, "ipddp0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) struct net_device_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) /* This needs to be able to handle ipddp"N" devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) skb->protocol = htons(ETH_P_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) skb_pull(skb, 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) stats = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) stats->rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) stats->rx_bytes += skb->len + 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) return netif_rx(skb); /* Send the SKB up to a higher place. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) /* make it easy for gcc to optimize this test out, i.e. kill the code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) #define is_ip_over_ddp(skb) 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) #define handle_ip_over_ddp(skb) 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) static int atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) struct ddpehdr *ddp, __u16 len_hops, int origlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) struct atalk_route *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) struct atalk_addr ta;
^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) * Don't route multicast, etc., packets, or packets sent to "this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) * network"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) * FIXME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) * Can it ever happen that a packet is from a PPP iface and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) * needs to be broadcast onto the default network?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) if (dev->type == ARPHRD_PPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) "packet received from PPP iface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) goto free_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) ta.s_net = ddp->deh_dnet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) ta.s_node = ddp->deh_dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) /* Route the packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) rt = atrtr_find(&ta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) /* increment hops count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) len_hops += 1 << 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (!rt || !(len_hops & (15 << 10)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) goto free_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) /* FIXME: use skb->cb to be able to use shared skbs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) * Route goes through another gateway, so set the target to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) * gateway instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) if (rt->flags & RTF_GATEWAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) ta.s_net = rt->gateway.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) ta.s_node = rt->gateway.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) /* Fix up skb->len field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) skb_trim(skb, min_t(unsigned int, origlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) (rt->dev->hard_header_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) ddp_dl->header_length + (len_hops & 1023))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) /* FIXME: use skb->cb to be able to use shared skbs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) ddp->deh_len_hops = htons(len_hops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) * Send the buffer onwards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) * Now we must always be careful. If it's come from LocalTalk to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) * EtherTalk it might not fit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) * Order matters here: If a packet has to be copied to make a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) * headroom (rare hopefully) then it won't need unsharing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) * Note. ddp-> becomes invalid at the realloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) if (skb_headroom(skb) < 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) skb = nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) skb = skb_unshare(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) * If the buffer didn't vanish into the lack of space bitbucket we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) * send it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) free_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) * atalk_rcv - Receive a packet (in skb) from device dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) * @skb - packet received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) * @dev - network device where the packet comes from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) * @pt - packet type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) * Receive a packet (in skb) from device dev. This has come from the SNAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) * decoder, and on entry skb->transport_header is the DDP header, skb->len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) * is the DDP header, skb->len is the DDP length. The physical headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) * have been extracted. PPP should probably pass frames marked as for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) * layer. [ie ARPHRD_ETHERTALK]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) struct packet_type *pt, struct net_device *orig_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) struct ddpehdr *ddp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) struct sock *sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) struct atalk_iface *atif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) struct sockaddr_at tosat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) int origlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) __u16 len_hops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) if (!net_eq(dev_net(dev), &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) /* Don't mangle buffer if shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) /* Size check and make sure header is contiguous */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) if (!pskb_may_pull(skb, sizeof(*ddp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) ddp = ddp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) len_hops = ntohs(ddp->deh_len_hops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) /* Trim buffer in case of stray trailing data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) origlen = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) * Size check to see if ddp->deh_len was crap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) * (Otherwise we'll detonate most spectacularly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) * in the middle of atalk_checksum() or recvmsg()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) if (skb->len < sizeof(*ddp) || skb->len < (len_hops & 1023)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) pr_debug("AppleTalk: dropping corrupted frame (deh_len=%u, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) "skb->len=%u)\n", len_hops & 1023, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) * Any checksums. Note we don't do htons() on this == is assumed to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * valid for net byte orders all over the networking code...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) if (ddp->deh_sum &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) /* Not a valid AppleTalk frame - dustbin time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) /* Check the packet is aimed at us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) if (!ddp->deh_dnet) /* Net 0 is 'this network' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) atif = atalk_find_anynet(ddp->deh_dnode, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if (!atif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) /* Not ours, so we route the packet via the correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) * AppleTalk iface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) return atalk_route_packet(skb, dev, ddp, len_hops, origlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) /* if IP over DDP is not selected this code will be optimized out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) if (is_ip_over_ddp(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) return handle_ip_over_ddp(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) * Which socket - atalk_search_socket() looks for a *full match*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) * of the <net, node, port> tuple.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) tosat.sat_addr.s_net = ddp->deh_dnet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) tosat.sat_addr.s_node = ddp->deh_dnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) tosat.sat_port = ddp->deh_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) sock = atalk_search_socket(&tosat, atif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) if (!sock) /* But not one of our sockets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /* Queue packet (standard) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) if (sock_queue_rcv_skb(sock, skb) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) * Receive a LocalTalk frame. We make some demands on the caller here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) * Caller must provide enough headroom on the packet to pull the short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) * header and append a long one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) struct packet_type *pt, struct net_device *orig_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) if (!net_eq(dev_net(dev), &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) goto freeit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) /* Expand any short form frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) if (skb_mac_header(skb)[2] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) struct ddpehdr *ddp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) /* Find our address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) struct atalk_addr *ap = atalk_find_dev_addr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) if (!ap || skb->len < sizeof(__be16) || skb->len > 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) goto freeit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) /* Don't mangle buffer if shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) * The push leaves us with a ddephdr not an shdr, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) * handily the port bytes in the right place preset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) ddp = skb_push(skb, sizeof(*ddp) - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) /* Now fill in the long header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) * These two first. The mac overlays the new source/dest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) * network information so we MUST copy these before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) * we write the network numbers !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) ddp->deh_dnode = skb_mac_header(skb)[0]; /* From physical header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) ddp->deh_snode = skb_mac_header(skb)[1]; /* From physical header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) ddp->deh_dnet = ap->s_net; /* Network number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) ddp->deh_snet = ap->s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) ddp->deh_sum = 0; /* No checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) * Not sure about this bit...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) /* Non routable, so force a drop if we slip up later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) return atalk_rcv(skb, dev, pt, orig_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) freeit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) static int atalk_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) struct atalk_sock *at = at_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) DECLARE_SOCKADDR(struct sockaddr_at *, usat, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) int flags = msg->msg_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) int loopback = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) struct sockaddr_at local_satalk, gsat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) struct ddpehdr *ddp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) int size, hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) struct atalk_route *rt, *rt_lo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) if (len > DDP_MAXSZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (usat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) if (sock_flag(sk, SOCK_ZAPPED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) if (atalk_autobind(sk) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) if (msg->msg_namelen < sizeof(*usat) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) usat->sat_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) /* netatalk didn't implement this check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) if (usat->sat_addr.s_node == ATADDR_BCAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) !sock_flag(sk, SOCK_BROADCAST)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) err = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) usat = &local_satalk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) usat->sat_family = AF_APPLETALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) usat->sat_port = at->dest_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) usat->sat_addr.s_node = at->dest_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) usat->sat_addr.s_net = at->dest_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) /* Build a packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) /* For headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) rt = atrtr_find(&usat->sat_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) struct atalk_addr at_hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) at_hint.s_node = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) at_hint.s_net = at->src_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) rt = atrtr_find(&at_hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) if (!rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) dev = rt->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) sk, size, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) hard_header_len = dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) /* Leave room for loopback hardware header if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) if (usat->sat_addr.s_node == ATADDR_BCAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) (dev->flags & IFF_LOOPBACK || !(rt->flags & RTF_GATEWAY))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) struct atalk_addr at_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) at_lo.s_node = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) at_lo.s_net = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) rt_lo = atrtr_find(&at_lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) if (rt_lo && rt_lo->dev->hard_header_len > hard_header_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) hard_header_len = rt_lo->dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) size += hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) skb_reserve(skb, ddp_dl->header_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) skb_reserve(skb, hard_header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) ddp = skb_put(skb, sizeof(struct ddpehdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) ddp->deh_len_hops = htons(len + sizeof(*ddp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) ddp->deh_dnet = usat->sat_addr.s_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) ddp->deh_snet = at->src_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) ddp->deh_dnode = usat->sat_addr.s_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) ddp->deh_snode = at->src_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) ddp->deh_dport = usat->sat_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) ddp->deh_sport = at->src_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) SOCK_DEBUG(sk, "SK %p: Copy user data (%zd bytes).\n", sk, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) err = memcpy_from_msg(skb_put(skb, len), msg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (sk->sk_no_check_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) ddp->deh_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) * Loopback broadcast packets to non gateway targets (ie routes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) * to group we are in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) if (ddp->deh_dnode == ATADDR_BCAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) if (skb2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) loopback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) * If it fails it is queued/sent above in the aarp queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) aarp_send_ddp(dev, skb2, &usat->sat_addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) if (dev->flags & IFF_LOOPBACK || loopback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) /* loop back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) skb_orphan(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) if (ddp->deh_dnode == ATADDR_BCAST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) if (!rt_lo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) err = -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) dev = rt_lo->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) ddp_dl->request(ddp_dl, skb, dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) if (rt->flags & RTF_GATEWAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) gsat.sat_addr = rt->gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) usat = &gsat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) * If it fails it is queued/sent above in the aarp queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) aarp_send_ddp(dev, skb, &usat->sat_addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) SOCK_DEBUG(sk, "SK %p: Done write (%zd).\n", sk, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) return err ? : len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) static int atalk_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) struct ddpehdr *ddp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) int copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) int offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) flags & MSG_DONTWAIT, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) /* FIXME: use skb->cb to be able to use shared skbs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) ddp = ddp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) copied = ntohs(ddp->deh_len_hops) & 1023;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) if (sk->sk_type != SOCK_RAW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) offset = sizeof(*ddp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) copied -= offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) if (copied > size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) copied = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) msg->msg_flags |= MSG_TRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) err = skb_copy_datagram_msg(skb, offset, msg, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) if (!err && msg->msg_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) DECLARE_SOCKADDR(struct sockaddr_at *, sat, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) sat->sat_family = AF_APPLETALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) sat->sat_port = ddp->deh_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) sat->sat_addr.s_node = ddp->deh_snode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) sat->sat_addr.s_net = ddp->deh_snet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) msg->msg_namelen = sizeof(*sat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) skb_free_datagram(sk, skb); /* Free the datagram. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) return err ? : copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) * AppleTalk ioctl calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) int rc = -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) /* Protocol layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) case TIOCOUTQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) long amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) if (amount < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) amount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) rc = put_user(amount, (int __user *)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) case TIOCINQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) * These two are safe on a single CPU system as only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) * user tasks fiddle here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) long amount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) amount = skb->len - sizeof(struct ddpehdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) rc = put_user(amount, (int __user *)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) /* Routing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) rc = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) if (capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) rc = atrtr_ioctl(cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) /* Interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) case SIOCGIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) case SIOCSIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) case SIOCGIFBRDADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) case SIOCATALKDIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) case SIOCDIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) case SIOCSARP: /* proxy AARP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) case SIOCDARP: /* proxy AARP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) rc = atif_ioctl(cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) static int atalk_compat_routing_ioctl(struct sock *sk, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) struct compat_rtentry __user *ur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) compat_uptr_t rtdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) struct rtentry rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) if (copy_from_user(&rt.rt_dst, &ur->rt_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 3 * sizeof(struct sockaddr)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) get_user(rt.rt_flags, &ur->rt_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) get_user(rt.rt_metric, &ur->rt_metric) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) get_user(rt.rt_mtu, &ur->rt_mtu) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) get_user(rt.rt_window, &ur->rt_window) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) get_user(rt.rt_irtt, &ur->rt_irtt) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) get_user(rtdev, &ur->rt_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) if (rt.rt_dst.sa_family != AF_APPLETALK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) return atrtr_delete(&((struct sockaddr_at *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) &rt.rt_dst)->sat_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) rt.rt_dev = compat_ptr(rtdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) return atrtr_ioctl_addrt(&rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) void __user *argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) case SIOCADDRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) case SIOCDELRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) return atalk_compat_routing_ioctl(sk, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) * SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) * cannot handle it in common code. The data we access if ifreq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) * here is compatible, so we can simply call the native
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) * handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) case SIOCATALKDIFADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) return atalk_ioctl(sock, cmd, (unsigned long)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) #endif /* CONFIG_COMPAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) static const struct net_proto_family atalk_family_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) .family = PF_APPLETALK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) .create = atalk_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) static const struct proto_ops atalk_dgram_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) .family = PF_APPLETALK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) .release = atalk_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) .bind = atalk_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) .connect = atalk_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) .socketpair = sock_no_socketpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) .accept = sock_no_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) .getname = atalk_getname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) .poll = datagram_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) .ioctl = atalk_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) .gettstamp = sock_gettstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) .compat_ioctl = atalk_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) .listen = sock_no_listen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) .shutdown = sock_no_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) .sendmsg = atalk_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) .recvmsg = atalk_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) .mmap = sock_no_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) .sendpage = sock_no_sendpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) static struct notifier_block ddp_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) .notifier_call = ddp_device_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) static struct packet_type ltalk_packet_type __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) .type = cpu_to_be16(ETH_P_LOCALTALK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) .func = ltalk_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) static struct packet_type ppptalk_packet_type __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) .type = cpu_to_be16(ETH_P_PPPTALK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) .func = atalk_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) /* Export symbols for use by drivers when AppleTalk is a module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) EXPORT_SYMBOL(atrtr_get_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) EXPORT_SYMBOL(atalk_find_dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) /* Called by proto.c on kernel start up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) static int __init atalk_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) rc = proto_register(&ddp_proto, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) rc = sock_register(&atalk_family_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) goto out_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) if (!ddp_dl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) pr_crit("Unable to register DDP with SNAP.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) goto out_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) dev_add_pack(<alk_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) dev_add_pack(&ppptalk_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) rc = register_netdevice_notifier(&ddp_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) goto out_snap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) rc = aarp_proto_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) goto out_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) rc = atalk_proc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) goto out_aarp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) rc = atalk_register_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) goto out_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) out_proc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) atalk_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) out_aarp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) aarp_cleanup_module();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) out_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) unregister_netdevice_notifier(&ddp_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) out_snap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) dev_remove_pack(&ppptalk_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) dev_remove_pack(<alk_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) unregister_snap_client(ddp_dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) out_sock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) sock_unregister(PF_APPLETALK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) out_proto:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) proto_unregister(&ddp_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) module_init(atalk_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) * No explicit module reference count manipulation is needed in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) * protocol. Socket layer sets module reference count for us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) * and interfaces reference counting is done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) * by the network device layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) * Ergo, before the AppleTalk module can be removed, all AppleTalk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) * sockets be closed from user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) static void __exit atalk_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) atalk_unregister_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) #endif /* CONFIG_SYSCTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) atalk_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) aarp_cleanup_module(); /* General aarp clean-up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) unregister_netdevice_notifier(&ddp_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) dev_remove_pack(<alk_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) dev_remove_pack(&ppptalk_packet_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) unregister_snap_client(ddp_dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) sock_unregister(PF_APPLETALK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) proto_unregister(&ddp_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) module_exit(atalk_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) MODULE_DESCRIPTION("AppleTalk 0.20\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) MODULE_ALIAS_NETPROTO(PF_APPLETALK);