Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  DDP:    An implementation of the AppleTalk DDP protocol for
0004  *      Ethernet 'ELAP'.
0005  *
0006  *      Alan Cox  <alan@lxorguk.ukuu.org.uk>
0007  *
0008  *      With more than a little assistance from
0009  *
0010  *      Wesley Craig <netatalk@umich.edu>
0011  *
0012  *  Fixes:
0013  *      Neil Horman     :   Added missing device ioctls
0014  *      Michael Callahan    :   Made routing work
0015  *      Wesley Craig        :   Fix probing to listen to a
0016  *                      passed node id.
0017  *      Alan Cox        :   Added send/recvmsg support
0018  *      Alan Cox        :   Moved at. to protinfo in
0019  *                      socket.
0020  *      Alan Cox        :   Added firewall hooks.
0021  *      Alan Cox        :   Supports new ARPHRD_LOOPBACK
0022  *      Christer Weinigel   :   Routing and /proc fixes.
0023  *      Bradford Johnson    :   LocalTalk.
0024  *      Tom Dyas        :   Module support.
0025  *      Alan Cox        :   Hooks for PPP (based on the
0026  *                      LocalTalk hook).
0027  *      Alan Cox        :   Posix bits
0028  *      Alan Cox/Mike Freeman   :   Possible fix to NBP problems
0029  *      Bradford Johnson    :   IP-over-DDP (experimental)
0030  *      Jay Schulist        :   Moved IP-over-DDP to its own
0031  *                      driver file. (ipddp.c & ipddp.h)
0032  *      Jay Schulist        :   Made work as module with
0033  *                      AppleTalk drivers, cleaned it.
0034  *      Rob Newberry        :   Added proxy AARP and AARP
0035  *                      procfs, moved probing to AARP
0036  *                      module.
0037  *              Adrian Sun/
0038  *              Michael Zuelsdorff      :       fix for net.0 packets. don't
0039  *                                              allow illegal ether/tokentalk
0040  *                                              port assignment. we lose a
0041  *                                              valid localtalk port as a
0042  *                                              result.
0043  *      Arnaldo C. de Melo  :   Cleanup, in preparation for
0044  *                      shared skb support 8)
0045  *      Arnaldo C. de Melo  :   Move proc stuff to atalk_proc.c,
0046  *                      use seq_file
0047  */
0048 
0049 #include <linux/capability.h>
0050 #include <linux/module.h>
0051 #include <linux/if_arp.h>
0052 #include <linux/termios.h>  /* For TIOCOUTQ/INQ */
0053 #include <linux/compat.h>
0054 #include <linux/slab.h>
0055 #include <net/datalink.h>
0056 #include <net/psnap.h>
0057 #include <net/sock.h>
0058 #include <net/tcp_states.h>
0059 #include <net/route.h>
0060 #include <net/compat.h>
0061 #include <linux/atalk.h>
0062 #include <linux/highmem.h>
0063 
0064 struct datalink_proto *ddp_dl, *aarp_dl;
0065 static const struct proto_ops atalk_dgram_ops;
0066 
0067 /**************************************************************************\
0068 *                                                                          *
0069 * Handlers for the socket list.                                            *
0070 *                                                                          *
0071 \**************************************************************************/
0072 
0073 HLIST_HEAD(atalk_sockets);
0074 DEFINE_RWLOCK(atalk_sockets_lock);
0075 
0076 static inline void __atalk_insert_socket(struct sock *sk)
0077 {
0078     sk_add_node(sk, &atalk_sockets);
0079 }
0080 
0081 static inline void atalk_remove_socket(struct sock *sk)
0082 {
0083     write_lock_bh(&atalk_sockets_lock);
0084     sk_del_node_init(sk);
0085     write_unlock_bh(&atalk_sockets_lock);
0086 }
0087 
0088 static struct sock *atalk_search_socket(struct sockaddr_at *to,
0089                     struct atalk_iface *atif)
0090 {
0091     struct sock *s;
0092 
0093     read_lock_bh(&atalk_sockets_lock);
0094     sk_for_each(s, &atalk_sockets) {
0095         struct atalk_sock *at = at_sk(s);
0096 
0097         if (to->sat_port != at->src_port)
0098             continue;
0099 
0100         if (to->sat_addr.s_net == ATADDR_ANYNET &&
0101             to->sat_addr.s_node == ATADDR_BCAST)
0102             goto found;
0103 
0104         if (to->sat_addr.s_net == at->src_net &&
0105             (to->sat_addr.s_node == at->src_node ||
0106              to->sat_addr.s_node == ATADDR_BCAST ||
0107              to->sat_addr.s_node == ATADDR_ANYNODE))
0108             goto found;
0109 
0110         /* XXXX.0 -- we got a request for this router. make sure
0111          * that the node is appropriately set. */
0112         if (to->sat_addr.s_node == ATADDR_ANYNODE &&
0113             to->sat_addr.s_net != ATADDR_ANYNET &&
0114             atif->address.s_node == at->src_node) {
0115             to->sat_addr.s_node = atif->address.s_node;
0116             goto found;
0117         }
0118     }
0119     s = NULL;
0120 found:
0121     read_unlock_bh(&atalk_sockets_lock);
0122     return s;
0123 }
0124 
0125 /**
0126  * atalk_find_or_insert_socket - Try to find a socket matching ADDR
0127  * @sk: socket to insert in the list if it is not there already
0128  * @sat: address to search for
0129  *
0130  * Try to find a socket matching ADDR in the socket list, if found then return
0131  * it. If not, insert SK into the socket list.
0132  *
0133  * This entire operation must execute atomically.
0134  */
0135 static struct sock *atalk_find_or_insert_socket(struct sock *sk,
0136                         struct sockaddr_at *sat)
0137 {
0138     struct sock *s;
0139     struct atalk_sock *at;
0140 
0141     write_lock_bh(&atalk_sockets_lock);
0142     sk_for_each(s, &atalk_sockets) {
0143         at = at_sk(s);
0144 
0145         if (at->src_net == sat->sat_addr.s_net &&
0146             at->src_node == sat->sat_addr.s_node &&
0147             at->src_port == sat->sat_port)
0148             goto found;
0149     }
0150     s = NULL;
0151     __atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
0152 found:
0153     write_unlock_bh(&atalk_sockets_lock);
0154     return s;
0155 }
0156 
0157 static void atalk_destroy_timer(struct timer_list *t)
0158 {
0159     struct sock *sk = from_timer(sk, t, sk_timer);
0160 
0161     if (sk_has_allocations(sk)) {
0162         sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
0163         add_timer(&sk->sk_timer);
0164     } else
0165         sock_put(sk);
0166 }
0167 
0168 static inline void atalk_destroy_socket(struct sock *sk)
0169 {
0170     atalk_remove_socket(sk);
0171     skb_queue_purge(&sk->sk_receive_queue);
0172 
0173     if (sk_has_allocations(sk)) {
0174         timer_setup(&sk->sk_timer, atalk_destroy_timer, 0);
0175         sk->sk_timer.expires    = jiffies + SOCK_DESTROY_TIME;
0176         add_timer(&sk->sk_timer);
0177     } else
0178         sock_put(sk);
0179 }
0180 
0181 /**************************************************************************\
0182 *                                                                          *
0183 * Routing tables for the AppleTalk socket layer.                           *
0184 *                                                                          *
0185 \**************************************************************************/
0186 
0187 /* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
0188 struct atalk_route *atalk_routes;
0189 DEFINE_RWLOCK(atalk_routes_lock);
0190 
0191 struct atalk_iface *atalk_interfaces;
0192 DEFINE_RWLOCK(atalk_interfaces_lock);
0193 
0194 /* For probing devices or in a routerless network */
0195 struct atalk_route atrtr_default;
0196 
0197 /* AppleTalk interface control */
0198 /*
0199  * Drop a device. Doesn't drop any of its routes - that is the caller's
0200  * problem. Called when we down the interface or delete the address.
0201  */
0202 static void atif_drop_device(struct net_device *dev)
0203 {
0204     struct atalk_iface **iface = &atalk_interfaces;
0205     struct atalk_iface *tmp;
0206 
0207     write_lock_bh(&atalk_interfaces_lock);
0208     while ((tmp = *iface) != NULL) {
0209         if (tmp->dev == dev) {
0210             *iface = tmp->next;
0211             dev_put(dev);
0212             kfree(tmp);
0213             dev->atalk_ptr = NULL;
0214         } else
0215             iface = &tmp->next;
0216     }
0217     write_unlock_bh(&atalk_interfaces_lock);
0218 }
0219 
0220 static struct atalk_iface *atif_add_device(struct net_device *dev,
0221                        struct atalk_addr *sa)
0222 {
0223     struct atalk_iface *iface = kzalloc(sizeof(*iface), GFP_KERNEL);
0224 
0225     if (!iface)
0226         goto out;
0227 
0228     dev_hold(dev);
0229     iface->dev = dev;
0230     dev->atalk_ptr = iface;
0231     iface->address = *sa;
0232     iface->status = 0;
0233 
0234     write_lock_bh(&atalk_interfaces_lock);
0235     iface->next = atalk_interfaces;
0236     atalk_interfaces = iface;
0237     write_unlock_bh(&atalk_interfaces_lock);
0238 out:
0239     return iface;
0240 }
0241 
0242 /* Perform phase 2 AARP probing on our tentative address */
0243 static int atif_probe_device(struct atalk_iface *atif)
0244 {
0245     int netrange = ntohs(atif->nets.nr_lastnet) -
0246             ntohs(atif->nets.nr_firstnet) + 1;
0247     int probe_net = ntohs(atif->address.s_net);
0248     int probe_node = atif->address.s_node;
0249     int netct, nodect;
0250 
0251     /* Offset the network we start probing with */
0252     if (probe_net == ATADDR_ANYNET) {
0253         probe_net = ntohs(atif->nets.nr_firstnet);
0254         if (netrange)
0255             probe_net += jiffies % netrange;
0256     }
0257     if (probe_node == ATADDR_ANYNODE)
0258         probe_node = jiffies & 0xFF;
0259 
0260     /* Scan the networks */
0261     atif->status |= ATIF_PROBE;
0262     for (netct = 0; netct <= netrange; netct++) {
0263         /* Sweep the available nodes from a given start */
0264         atif->address.s_net = htons(probe_net);
0265         for (nodect = 0; nodect < 256; nodect++) {
0266             atif->address.s_node = (nodect + probe_node) & 0xFF;
0267             if (atif->address.s_node > 0 &&
0268                 atif->address.s_node < 254) {
0269                 /* Probe a proposed address */
0270                 aarp_probe_network(atif);
0271 
0272                 if (!(atif->status & ATIF_PROBE_FAIL)) {
0273                     atif->status &= ~ATIF_PROBE;
0274                     return 0;
0275                 }
0276             }
0277             atif->status &= ~ATIF_PROBE_FAIL;
0278         }
0279         probe_net++;
0280         if (probe_net > ntohs(atif->nets.nr_lastnet))
0281             probe_net = ntohs(atif->nets.nr_firstnet);
0282     }
0283     atif->status &= ~ATIF_PROBE;
0284 
0285     return -EADDRINUSE; /* Network is full... */
0286 }
0287 
0288 
0289 /* Perform AARP probing for a proxy address */
0290 static int atif_proxy_probe_device(struct atalk_iface *atif,
0291                    struct atalk_addr *proxy_addr)
0292 {
0293     int netrange = ntohs(atif->nets.nr_lastnet) -
0294             ntohs(atif->nets.nr_firstnet) + 1;
0295     /* we probe the interface's network */
0296     int probe_net = ntohs(atif->address.s_net);
0297     int probe_node = ATADDR_ANYNODE;        /* we'll take anything */
0298     int netct, nodect;
0299 
0300     /* Offset the network we start probing with */
0301     if (probe_net == ATADDR_ANYNET) {
0302         probe_net = ntohs(atif->nets.nr_firstnet);
0303         if (netrange)
0304             probe_net += jiffies % netrange;
0305     }
0306 
0307     if (probe_node == ATADDR_ANYNODE)
0308         probe_node = jiffies & 0xFF;
0309 
0310     /* Scan the networks */
0311     for (netct = 0; netct <= netrange; netct++) {
0312         /* Sweep the available nodes from a given start */
0313         proxy_addr->s_net = htons(probe_net);
0314         for (nodect = 0; nodect < 256; nodect++) {
0315             proxy_addr->s_node = (nodect + probe_node) & 0xFF;
0316             if (proxy_addr->s_node > 0 &&
0317                 proxy_addr->s_node < 254) {
0318                 /* Tell AARP to probe a proposed address */
0319                 int ret = aarp_proxy_probe_network(atif,
0320                                     proxy_addr);
0321 
0322                 if (ret != -EADDRINUSE)
0323                     return ret;
0324             }
0325         }
0326         probe_net++;
0327         if (probe_net > ntohs(atif->nets.nr_lastnet))
0328             probe_net = ntohs(atif->nets.nr_firstnet);
0329     }
0330 
0331     return -EADDRINUSE; /* Network is full... */
0332 }
0333 
0334 
0335 struct atalk_addr *atalk_find_dev_addr(struct net_device *dev)
0336 {
0337     struct atalk_iface *iface = dev->atalk_ptr;
0338     return iface ? &iface->address : NULL;
0339 }
0340 
0341 static struct atalk_addr *atalk_find_primary(void)
0342 {
0343     struct atalk_iface *fiface = NULL;
0344     struct atalk_addr *retval;
0345     struct atalk_iface *iface;
0346 
0347     /*
0348      * Return a point-to-point interface only if
0349      * there is no non-ptp interface available.
0350      */
0351     read_lock_bh(&atalk_interfaces_lock);
0352     for (iface = atalk_interfaces; iface; iface = iface->next) {
0353         if (!fiface && !(iface->dev->flags & IFF_LOOPBACK))
0354             fiface = iface;
0355         if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
0356             retval = &iface->address;
0357             goto out;
0358         }
0359     }
0360 
0361     if (fiface)
0362         retval = &fiface->address;
0363     else if (atalk_interfaces)
0364         retval = &atalk_interfaces->address;
0365     else
0366         retval = NULL;
0367 out:
0368     read_unlock_bh(&atalk_interfaces_lock);
0369     return retval;
0370 }
0371 
0372 /*
0373  * Find a match for 'any network' - ie any of our interfaces with that
0374  * node number will do just nicely.
0375  */
0376 static struct atalk_iface *atalk_find_anynet(int node, struct net_device *dev)
0377 {
0378     struct atalk_iface *iface = dev->atalk_ptr;
0379 
0380     if (!iface || iface->status & ATIF_PROBE)
0381         goto out_err;
0382 
0383     if (node != ATADDR_BCAST &&
0384         iface->address.s_node != node &&
0385         node != ATADDR_ANYNODE)
0386         goto out_err;
0387 out:
0388     return iface;
0389 out_err:
0390     iface = NULL;
0391     goto out;
0392 }
0393 
0394 /* Find a match for a specific network:node pair */
0395 static struct atalk_iface *atalk_find_interface(__be16 net, int node)
0396 {
0397     struct atalk_iface *iface;
0398 
0399     read_lock_bh(&atalk_interfaces_lock);
0400     for (iface = atalk_interfaces; iface; iface = iface->next) {
0401         if ((node == ATADDR_BCAST ||
0402              node == ATADDR_ANYNODE ||
0403              iface->address.s_node == node) &&
0404             iface->address.s_net == net &&
0405             !(iface->status & ATIF_PROBE))
0406             break;
0407 
0408         /* XXXX.0 -- net.0 returns the iface associated with net */
0409         if (node == ATADDR_ANYNODE && net != ATADDR_ANYNET &&
0410             ntohs(iface->nets.nr_firstnet) <= ntohs(net) &&
0411             ntohs(net) <= ntohs(iface->nets.nr_lastnet))
0412             break;
0413     }
0414     read_unlock_bh(&atalk_interfaces_lock);
0415     return iface;
0416 }
0417 
0418 
0419 /*
0420  * Find a route for an AppleTalk packet. This ought to get cached in
0421  * the socket (later on...). We know about host routes and the fact
0422  * that a route must be direct to broadcast.
0423  */
0424 static struct atalk_route *atrtr_find(struct atalk_addr *target)
0425 {
0426     /*
0427      * we must search through all routes unless we find a
0428      * host route, because some host routes might overlap
0429      * network routes
0430      */
0431     struct atalk_route *net_route = NULL;
0432     struct atalk_route *r;
0433 
0434     read_lock_bh(&atalk_routes_lock);
0435     for (r = atalk_routes; r; r = r->next) {
0436         if (!(r->flags & RTF_UP))
0437             continue;
0438 
0439         if (r->target.s_net == target->s_net) {
0440             if (r->flags & RTF_HOST) {
0441                 /*
0442                  * if this host route is for the target,
0443                  * the we're done
0444                  */
0445                 if (r->target.s_node == target->s_node)
0446                     goto out;
0447             } else
0448                 /*
0449                  * this route will work if there isn't a
0450                  * direct host route, so cache it
0451                  */
0452                 net_route = r;
0453         }
0454     }
0455 
0456     /*
0457      * if we found a network route but not a direct host
0458      * route, then return it
0459      */
0460     if (net_route)
0461         r = net_route;
0462     else if (atrtr_default.dev)
0463         r = &atrtr_default;
0464     else /* No route can be found */
0465         r = NULL;
0466 out:
0467     read_unlock_bh(&atalk_routes_lock);
0468     return r;
0469 }
0470 
0471 
0472 /*
0473  * Given an AppleTalk network, find the device to use. This can be
0474  * a simple lookup.
0475  */
0476 struct net_device *atrtr_get_dev(struct atalk_addr *sa)
0477 {
0478     struct atalk_route *atr = atrtr_find(sa);
0479     return atr ? atr->dev : NULL;
0480 }
0481 
0482 /* Set up a default router */
0483 static void atrtr_set_default(struct net_device *dev)
0484 {
0485     atrtr_default.dev        = dev;
0486     atrtr_default.flags      = RTF_UP;
0487     atrtr_default.gateway.s_net  = htons(0);
0488     atrtr_default.gateway.s_node = 0;
0489 }
0490 
0491 /*
0492  * Add a router. Basically make sure it looks valid and stuff the
0493  * entry in the list. While it uses netranges we always set them to one
0494  * entry to work like netatalk.
0495  */
0496 static int atrtr_create(struct rtentry *r, struct net_device *devhint)
0497 {
0498     struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst;
0499     struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway;
0500     struct atalk_route *rt;
0501     struct atalk_iface *iface, *riface;
0502     int retval = -EINVAL;
0503 
0504     /*
0505      * Fixme: Raise/Lower a routing change semaphore for these
0506      * operations.
0507      */
0508 
0509     /* Validate the request */
0510     if (ta->sat_family != AF_APPLETALK ||
0511         (!devhint && ga->sat_family != AF_APPLETALK))
0512         goto out;
0513 
0514     /* Now walk the routing table and make our decisions */
0515     write_lock_bh(&atalk_routes_lock);
0516     for (rt = atalk_routes; rt; rt = rt->next) {
0517         if (r->rt_flags != rt->flags)
0518             continue;
0519 
0520         if (ta->sat_addr.s_net == rt->target.s_net) {
0521             if (!(rt->flags & RTF_HOST))
0522                 break;
0523             if (ta->sat_addr.s_node == rt->target.s_node)
0524                 break;
0525         }
0526     }
0527 
0528     if (!devhint) {
0529         riface = NULL;
0530 
0531         read_lock_bh(&atalk_interfaces_lock);
0532         for (iface = atalk_interfaces; iface; iface = iface->next) {
0533             if (!riface &&
0534                 ntohs(ga->sat_addr.s_net) >=
0535                     ntohs(iface->nets.nr_firstnet) &&
0536                 ntohs(ga->sat_addr.s_net) <=
0537                     ntohs(iface->nets.nr_lastnet))
0538                 riface = iface;
0539 
0540             if (ga->sat_addr.s_net == iface->address.s_net &&
0541                 ga->sat_addr.s_node == iface->address.s_node)
0542                 riface = iface;
0543         }
0544         read_unlock_bh(&atalk_interfaces_lock);
0545 
0546         retval = -ENETUNREACH;
0547         if (!riface)
0548             goto out_unlock;
0549 
0550         devhint = riface->dev;
0551     }
0552 
0553     if (!rt) {
0554         rt = kzalloc(sizeof(*rt), GFP_ATOMIC);
0555 
0556         retval = -ENOBUFS;
0557         if (!rt)
0558             goto out_unlock;
0559 
0560         rt->next = atalk_routes;
0561         atalk_routes = rt;
0562     }
0563 
0564     /* Fill in the routing entry */
0565     rt->target  = ta->sat_addr;
0566     dev_hold(devhint);
0567     rt->dev     = devhint;
0568     rt->flags   = r->rt_flags;
0569     rt->gateway = ga->sat_addr;
0570 
0571     retval = 0;
0572 out_unlock:
0573     write_unlock_bh(&atalk_routes_lock);
0574 out:
0575     return retval;
0576 }
0577 
0578 /* Delete a route. Find it and discard it */
0579 static int atrtr_delete(struct atalk_addr *addr)
0580 {
0581     struct atalk_route **r = &atalk_routes;
0582     int retval = 0;
0583     struct atalk_route *tmp;
0584 
0585     write_lock_bh(&atalk_routes_lock);
0586     while ((tmp = *r) != NULL) {
0587         if (tmp->target.s_net == addr->s_net &&
0588             (!(tmp->flags&RTF_GATEWAY) ||
0589              tmp->target.s_node == addr->s_node)) {
0590             *r = tmp->next;
0591             dev_put(tmp->dev);
0592             kfree(tmp);
0593             goto out;
0594         }
0595         r = &tmp->next;
0596     }
0597     retval = -ENOENT;
0598 out:
0599     write_unlock_bh(&atalk_routes_lock);
0600     return retval;
0601 }
0602 
0603 /*
0604  * Called when a device is downed. Just throw away any routes
0605  * via it.
0606  */
0607 static void atrtr_device_down(struct net_device *dev)
0608 {
0609     struct atalk_route **r = &atalk_routes;
0610     struct atalk_route *tmp;
0611 
0612     write_lock_bh(&atalk_routes_lock);
0613     while ((tmp = *r) != NULL) {
0614         if (tmp->dev == dev) {
0615             *r = tmp->next;
0616             dev_put(dev);
0617             kfree(tmp);
0618         } else
0619             r = &tmp->next;
0620     }
0621     write_unlock_bh(&atalk_routes_lock);
0622 
0623     if (atrtr_default.dev == dev)
0624         atrtr_set_default(NULL);
0625 }
0626 
0627 /* Actually down the interface */
0628 static inline void atalk_dev_down(struct net_device *dev)
0629 {
0630     atrtr_device_down(dev); /* Remove all routes for the device */
0631     aarp_device_down(dev);  /* Remove AARP entries for the device */
0632     atif_drop_device(dev);  /* Remove the device */
0633 }
0634 
0635 /*
0636  * A device event has occurred. Watch for devices going down and
0637  * delete our use of them (iface and route).
0638  */
0639 static int ddp_device_event(struct notifier_block *this, unsigned long event,
0640                 void *ptr)
0641 {
0642     struct net_device *dev = netdev_notifier_info_to_dev(ptr);
0643 
0644     if (!net_eq(dev_net(dev), &init_net))
0645         return NOTIFY_DONE;
0646 
0647     if (event == NETDEV_DOWN)
0648         /* Discard any use of this */
0649         atalk_dev_down(dev);
0650 
0651     return NOTIFY_DONE;
0652 }
0653 
0654 /* ioctl calls. Shouldn't even need touching */
0655 /* Device configuration ioctl calls */
0656 static int atif_ioctl(int cmd, void __user *arg)
0657 {
0658     static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
0659     struct ifreq atreq;
0660     struct atalk_netrange *nr;
0661     struct sockaddr_at *sa;
0662     struct net_device *dev;
0663     struct atalk_iface *atif;
0664     int ct;
0665     int limit;
0666     struct rtentry rtdef;
0667     int add_route;
0668 
0669     if (get_user_ifreq(&atreq, NULL, arg))
0670         return -EFAULT;
0671 
0672     dev = __dev_get_by_name(&init_net, atreq.ifr_name);
0673     if (!dev)
0674         return -ENODEV;
0675 
0676     sa = (struct sockaddr_at *)&atreq.ifr_addr;
0677     atif = atalk_find_dev(dev);
0678 
0679     switch (cmd) {
0680     case SIOCSIFADDR:
0681         if (!capable(CAP_NET_ADMIN))
0682             return -EPERM;
0683         if (sa->sat_family != AF_APPLETALK)
0684             return -EINVAL;
0685         if (dev->type != ARPHRD_ETHER &&
0686             dev->type != ARPHRD_LOOPBACK &&
0687             dev->type != ARPHRD_LOCALTLK &&
0688             dev->type != ARPHRD_PPP)
0689             return -EPROTONOSUPPORT;
0690 
0691         nr = (struct atalk_netrange *)&sa->sat_zero[0];
0692         add_route = 1;
0693 
0694         /*
0695          * if this is a point-to-point iface, and we already
0696          * have an iface for this AppleTalk address, then we
0697          * should not add a route
0698          */
0699         if ((dev->flags & IFF_POINTOPOINT) &&
0700             atalk_find_interface(sa->sat_addr.s_net,
0701                      sa->sat_addr.s_node)) {
0702             printk(KERN_DEBUG "AppleTalk: point-to-point "
0703                    "interface added with "
0704                    "existing address\n");
0705             add_route = 0;
0706         }
0707 
0708         /*
0709          * Phase 1 is fine on LocalTalk but we don't do
0710          * EtherTalk phase 1. Anyone wanting to add it, go ahead.
0711          */
0712         if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
0713             return -EPROTONOSUPPORT;
0714         if (sa->sat_addr.s_node == ATADDR_BCAST ||
0715             sa->sat_addr.s_node == 254)
0716             return -EINVAL;
0717         if (atif) {
0718             /* Already setting address */
0719             if (atif->status & ATIF_PROBE)
0720                 return -EBUSY;
0721 
0722             atif->address.s_net  = sa->sat_addr.s_net;
0723             atif->address.s_node = sa->sat_addr.s_node;
0724             atrtr_device_down(dev); /* Flush old routes */
0725         } else {
0726             atif = atif_add_device(dev, &sa->sat_addr);
0727             if (!atif)
0728                 return -ENOMEM;
0729         }
0730         atif->nets = *nr;
0731 
0732         /*
0733          * Check if the chosen address is used. If so we
0734          * error and atalkd will try another.
0735          */
0736 
0737         if (!(dev->flags & IFF_LOOPBACK) &&
0738             !(dev->flags & IFF_POINTOPOINT) &&
0739             atif_probe_device(atif) < 0) {
0740             atif_drop_device(dev);
0741             return -EADDRINUSE;
0742         }
0743 
0744         /* Hey it worked - add the direct routes */
0745         sa = (struct sockaddr_at *)&rtdef.rt_gateway;
0746         sa->sat_family = AF_APPLETALK;
0747         sa->sat_addr.s_net  = atif->address.s_net;
0748         sa->sat_addr.s_node = atif->address.s_node;
0749         sa = (struct sockaddr_at *)&rtdef.rt_dst;
0750         rtdef.rt_flags = RTF_UP;
0751         sa->sat_family = AF_APPLETALK;
0752         sa->sat_addr.s_node = ATADDR_ANYNODE;
0753         if (dev->flags & IFF_LOOPBACK ||
0754             dev->flags & IFF_POINTOPOINT)
0755             rtdef.rt_flags |= RTF_HOST;
0756 
0757         /* Routerless initial state */
0758         if (nr->nr_firstnet == htons(0) &&
0759             nr->nr_lastnet == htons(0xFFFE)) {
0760             sa->sat_addr.s_net = atif->address.s_net;
0761             atrtr_create(&rtdef, dev);
0762             atrtr_set_default(dev);
0763         } else {
0764             limit = ntohs(nr->nr_lastnet);
0765             if (limit - ntohs(nr->nr_firstnet) > 4096) {
0766                 printk(KERN_WARNING "Too many routes/"
0767                        "iface.\n");
0768                 return -EINVAL;
0769             }
0770             if (add_route)
0771                 for (ct = ntohs(nr->nr_firstnet);
0772                      ct <= limit; ct++) {
0773                     sa->sat_addr.s_net = htons(ct);
0774                     atrtr_create(&rtdef, dev);
0775                 }
0776         }
0777         dev_mc_add_global(dev, aarp_mcast);
0778         return 0;
0779 
0780     case SIOCGIFADDR:
0781         if (!atif)
0782             return -EADDRNOTAVAIL;
0783 
0784         sa->sat_family = AF_APPLETALK;
0785         sa->sat_addr = atif->address;
0786         break;
0787 
0788     case SIOCGIFBRDADDR:
0789         if (!atif)
0790             return -EADDRNOTAVAIL;
0791 
0792         sa->sat_family = AF_APPLETALK;
0793         sa->sat_addr.s_net = atif->address.s_net;
0794         sa->sat_addr.s_node = ATADDR_BCAST;
0795         break;
0796 
0797     case SIOCATALKDIFADDR:
0798     case SIOCDIFADDR:
0799         if (!capable(CAP_NET_ADMIN))
0800             return -EPERM;
0801         if (sa->sat_family != AF_APPLETALK)
0802             return -EINVAL;
0803         atalk_dev_down(dev);
0804         break;
0805 
0806     case SIOCSARP:
0807         if (!capable(CAP_NET_ADMIN))
0808             return -EPERM;
0809         if (sa->sat_family != AF_APPLETALK)
0810             return -EINVAL;
0811         /*
0812          * for now, we only support proxy AARP on ELAP;
0813          * we should be able to do it for LocalTalk, too.
0814          */
0815         if (dev->type != ARPHRD_ETHER)
0816             return -EPROTONOSUPPORT;
0817 
0818         /*
0819          * atif points to the current interface on this network;
0820          * we aren't concerned about its current status (at
0821          * least for now), but it has all the settings about
0822          * the network we're going to probe. Consequently, it
0823          * must exist.
0824          */
0825         if (!atif)
0826             return -EADDRNOTAVAIL;
0827 
0828         nr = (struct atalk_netrange *)&(atif->nets);
0829         /*
0830          * Phase 1 is fine on Localtalk but we don't do
0831          * Ethertalk phase 1. Anyone wanting to add it, go ahead.
0832          */
0833         if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
0834             return -EPROTONOSUPPORT;
0835 
0836         if (sa->sat_addr.s_node == ATADDR_BCAST ||
0837             sa->sat_addr.s_node == 254)
0838             return -EINVAL;
0839 
0840         /*
0841          * Check if the chosen address is used. If so we
0842          * error and ATCP will try another.
0843          */
0844         if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0)
0845             return -EADDRINUSE;
0846 
0847         /*
0848          * We now have an address on the local network, and
0849          * the AARP code will defend it for us until we take it
0850          * down. We don't set up any routes right now, because
0851          * ATCP will install them manually via SIOCADDRT.
0852          */
0853         break;
0854 
0855     case SIOCDARP:
0856         if (!capable(CAP_NET_ADMIN))
0857             return -EPERM;
0858         if (sa->sat_family != AF_APPLETALK)
0859             return -EINVAL;
0860         if (!atif)
0861             return -EADDRNOTAVAIL;
0862 
0863         /* give to aarp module to remove proxy entry */
0864         aarp_proxy_remove(atif->dev, &(sa->sat_addr));
0865         return 0;
0866     }
0867 
0868     return put_user_ifreq(&atreq, arg);
0869 }
0870 
0871 static int atrtr_ioctl_addrt(struct rtentry *rt)
0872 {
0873     struct net_device *dev = NULL;
0874 
0875     if (rt->rt_dev) {
0876         char name[IFNAMSIZ];
0877 
0878         if (copy_from_user(name, rt->rt_dev, IFNAMSIZ-1))
0879             return -EFAULT;
0880         name[IFNAMSIZ-1] = '\0';
0881 
0882         dev = __dev_get_by_name(&init_net, name);
0883         if (!dev)
0884             return -ENODEV;
0885     }
0886     return atrtr_create(rt, dev);
0887 }
0888 
0889 /* Routing ioctl() calls */
0890 static int atrtr_ioctl(unsigned int cmd, void __user *arg)
0891 {
0892     struct rtentry rt;
0893 
0894     if (copy_from_user(&rt, arg, sizeof(rt)))
0895         return -EFAULT;
0896 
0897     switch (cmd) {
0898     case SIOCDELRT:
0899         if (rt.rt_dst.sa_family != AF_APPLETALK)
0900             return -EINVAL;
0901         return atrtr_delete(&((struct sockaddr_at *)
0902                       &rt.rt_dst)->sat_addr);
0903 
0904     case SIOCADDRT:
0905         return atrtr_ioctl_addrt(&rt);
0906     }
0907     return -EINVAL;
0908 }
0909 
0910 /**************************************************************************\
0911 *                                                                          *
0912 * Handling for system calls applied via the various interfaces to an       *
0913 * AppleTalk socket object.                                                 *
0914 *                                                                          *
0915 \**************************************************************************/
0916 
0917 /*
0918  * Checksum: This is 'optional'. It's quite likely also a good
0919  * candidate for assembler hackery 8)
0920  */
0921 static unsigned long atalk_sum_partial(const unsigned char *data,
0922                        int len, unsigned long sum)
0923 {
0924     /* This ought to be unwrapped neatly. I'll trust gcc for now */
0925     while (len--) {
0926         sum += *data++;
0927         sum = rol16(sum, 1);
0928     }
0929     return sum;
0930 }
0931 
0932 /*  Checksum skb data --  similar to skb_checksum  */
0933 static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
0934                    int len, unsigned long sum)
0935 {
0936     int start = skb_headlen(skb);
0937     struct sk_buff *frag_iter;
0938     int i, copy;
0939 
0940     /* checksum stuff in header space */
0941     if ((copy = start - offset) > 0) {
0942         if (copy > len)
0943             copy = len;
0944         sum = atalk_sum_partial(skb->data + offset, copy, sum);
0945         if ((len -= copy) == 0)
0946             return sum;
0947 
0948         offset += copy;
0949     }
0950 
0951     /* checksum stuff in frags */
0952     for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
0953         int end;
0954         const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
0955         WARN_ON(start > offset + len);
0956 
0957         end = start + skb_frag_size(frag);
0958         if ((copy = end - offset) > 0) {
0959             u8 *vaddr;
0960 
0961             if (copy > len)
0962                 copy = len;
0963             vaddr = kmap_atomic(skb_frag_page(frag));
0964             sum = atalk_sum_partial(vaddr + skb_frag_off(frag) +
0965                         offset - start, copy, sum);
0966             kunmap_atomic(vaddr);
0967 
0968             if (!(len -= copy))
0969                 return sum;
0970             offset += copy;
0971         }
0972         start = end;
0973     }
0974 
0975     skb_walk_frags(skb, frag_iter) {
0976         int end;
0977 
0978         WARN_ON(start > offset + len);
0979 
0980         end = start + frag_iter->len;
0981         if ((copy = end - offset) > 0) {
0982             if (copy > len)
0983                 copy = len;
0984             sum = atalk_sum_skb(frag_iter, offset - start,
0985                         copy, sum);
0986             if ((len -= copy) == 0)
0987                 return sum;
0988             offset += copy;
0989         }
0990         start = end;
0991     }
0992 
0993     BUG_ON(len > 0);
0994 
0995     return sum;
0996 }
0997 
0998 static __be16 atalk_checksum(const struct sk_buff *skb, int len)
0999 {
1000     unsigned long sum;
1001 
1002     /* skip header 4 bytes */
1003     sum = atalk_sum_skb(skb, 4, len-4, 0);
1004 
1005     /* Use 0xFFFF for 0. 0 itself means none */
1006     return sum ? htons((unsigned short)sum) : htons(0xFFFF);
1007 }
1008 
1009 static struct proto ddp_proto = {
1010     .name     = "DDP",
1011     .owner    = THIS_MODULE,
1012     .obj_size = sizeof(struct atalk_sock),
1013 };
1014 
1015 /*
1016  * Create a socket. Initialise the socket, blank the addresses
1017  * set the state.
1018  */
1019 static int atalk_create(struct net *net, struct socket *sock, int protocol,
1020             int kern)
1021 {
1022     struct sock *sk;
1023     int rc = -ESOCKTNOSUPPORT;
1024 
1025     if (!net_eq(net, &init_net))
1026         return -EAFNOSUPPORT;
1027 
1028     /*
1029      * We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
1030      * and gives you the full ELAP frame. Should be handy for CAP 8)
1031      */
1032     if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
1033         goto out;
1034 
1035     rc = -EPERM;
1036     if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
1037         goto out;
1038 
1039     rc = -ENOMEM;
1040     sk = sk_alloc(net, PF_APPLETALK, GFP_KERNEL, &ddp_proto, kern);
1041     if (!sk)
1042         goto out;
1043     rc = 0;
1044     sock->ops = &atalk_dgram_ops;
1045     sock_init_data(sock, sk);
1046 
1047     /* Checksums on by default */
1048     sock_set_flag(sk, SOCK_ZAPPED);
1049 out:
1050     return rc;
1051 }
1052 
1053 /* Free a socket. No work needed */
1054 static int atalk_release(struct socket *sock)
1055 {
1056     struct sock *sk = sock->sk;
1057 
1058     if (sk) {
1059         sock_hold(sk);
1060         lock_sock(sk);
1061 
1062         sock_orphan(sk);
1063         sock->sk = NULL;
1064         atalk_destroy_socket(sk);
1065 
1066         release_sock(sk);
1067         sock_put(sk);
1068     }
1069     return 0;
1070 }
1071 
1072 /**
1073  * atalk_pick_and_bind_port - Pick a source port when one is not given
1074  * @sk: socket to insert into the tables
1075  * @sat: address to search for
1076  *
1077  * Pick a source port when one is not given. If we can find a suitable free
1078  * one, we insert the socket into the tables using it.
1079  *
1080  * This whole operation must be atomic.
1081  */
1082 static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
1083 {
1084     int retval;
1085 
1086     write_lock_bh(&atalk_sockets_lock);
1087 
1088     for (sat->sat_port = ATPORT_RESERVED;
1089          sat->sat_port < ATPORT_LAST;
1090          sat->sat_port++) {
1091         struct sock *s;
1092 
1093         sk_for_each(s, &atalk_sockets) {
1094             struct atalk_sock *at = at_sk(s);
1095 
1096             if (at->src_net == sat->sat_addr.s_net &&
1097                 at->src_node == sat->sat_addr.s_node &&
1098                 at->src_port == sat->sat_port)
1099                 goto try_next_port;
1100         }
1101 
1102         /* Wheee, it's free, assign and insert. */
1103         __atalk_insert_socket(sk);
1104         at_sk(sk)->src_port = sat->sat_port;
1105         retval = 0;
1106         goto out;
1107 
1108 try_next_port:;
1109     }
1110 
1111     retval = -EBUSY;
1112 out:
1113     write_unlock_bh(&atalk_sockets_lock);
1114     return retval;
1115 }
1116 
1117 static int atalk_autobind(struct sock *sk)
1118 {
1119     struct atalk_sock *at = at_sk(sk);
1120     struct sockaddr_at sat;
1121     struct atalk_addr *ap = atalk_find_primary();
1122     int n = -EADDRNOTAVAIL;
1123 
1124     if (!ap || ap->s_net == htons(ATADDR_ANYNET))
1125         goto out;
1126 
1127     at->src_net  = sat.sat_addr.s_net  = ap->s_net;
1128     at->src_node = sat.sat_addr.s_node = ap->s_node;
1129 
1130     n = atalk_pick_and_bind_port(sk, &sat);
1131     if (!n)
1132         sock_reset_flag(sk, SOCK_ZAPPED);
1133 out:
1134     return n;
1135 }
1136 
1137 /* Set the address 'our end' of the connection */
1138 static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1139 {
1140     struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
1141     struct sock *sk = sock->sk;
1142     struct atalk_sock *at = at_sk(sk);
1143     int err;
1144 
1145     if (!sock_flag(sk, SOCK_ZAPPED) ||
1146         addr_len != sizeof(struct sockaddr_at))
1147         return -EINVAL;
1148 
1149     if (addr->sat_family != AF_APPLETALK)
1150         return -EAFNOSUPPORT;
1151 
1152     lock_sock(sk);
1153     if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
1154         struct atalk_addr *ap = atalk_find_primary();
1155 
1156         err = -EADDRNOTAVAIL;
1157         if (!ap)
1158             goto out;
1159 
1160         at->src_net  = addr->sat_addr.s_net = ap->s_net;
1161         at->src_node = addr->sat_addr.s_node = ap->s_node;
1162     } else {
1163         err = -EADDRNOTAVAIL;
1164         if (!atalk_find_interface(addr->sat_addr.s_net,
1165                       addr->sat_addr.s_node))
1166             goto out;
1167 
1168         at->src_net  = addr->sat_addr.s_net;
1169         at->src_node = addr->sat_addr.s_node;
1170     }
1171 
1172     if (addr->sat_port == ATADDR_ANYPORT) {
1173         err = atalk_pick_and_bind_port(sk, addr);
1174 
1175         if (err < 0)
1176             goto out;
1177     } else {
1178         at->src_port = addr->sat_port;
1179 
1180         err = -EADDRINUSE;
1181         if (atalk_find_or_insert_socket(sk, addr))
1182             goto out;
1183     }
1184 
1185     sock_reset_flag(sk, SOCK_ZAPPED);
1186     err = 0;
1187 out:
1188     release_sock(sk);
1189     return err;
1190 }
1191 
1192 /* Set the address we talk to */
1193 static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1194              int addr_len, int flags)
1195 {
1196     struct sock *sk = sock->sk;
1197     struct atalk_sock *at = at_sk(sk);
1198     struct sockaddr_at *addr;
1199     int err;
1200 
1201     sk->sk_state   = TCP_CLOSE;
1202     sock->state = SS_UNCONNECTED;
1203 
1204     if (addr_len != sizeof(*addr))
1205         return -EINVAL;
1206 
1207     addr = (struct sockaddr_at *)uaddr;
1208 
1209     if (addr->sat_family != AF_APPLETALK)
1210         return -EAFNOSUPPORT;
1211 
1212     if (addr->sat_addr.s_node == ATADDR_BCAST &&
1213         !sock_flag(sk, SOCK_BROADCAST)) {
1214 #if 1
1215         pr_warn("atalk_connect: %s is broken and did not set SO_BROADCAST.\n",
1216             current->comm);
1217 #else
1218         return -EACCES;
1219 #endif
1220     }
1221 
1222     lock_sock(sk);
1223     err = -EBUSY;
1224     if (sock_flag(sk, SOCK_ZAPPED))
1225         if (atalk_autobind(sk) < 0)
1226             goto out;
1227 
1228     err = -ENETUNREACH;
1229     if (!atrtr_get_dev(&addr->sat_addr))
1230         goto out;
1231 
1232     at->dest_port = addr->sat_port;
1233     at->dest_net  = addr->sat_addr.s_net;
1234     at->dest_node = addr->sat_addr.s_node;
1235 
1236     sock->state  = SS_CONNECTED;
1237     sk->sk_state = TCP_ESTABLISHED;
1238     err = 0;
1239 out:
1240     release_sock(sk);
1241     return err;
1242 }
1243 
1244 /*
1245  * Find the name of an AppleTalk socket. Just copy the right
1246  * fields into the sockaddr.
1247  */
1248 static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1249              int peer)
1250 {
1251     struct sockaddr_at sat;
1252     struct sock *sk = sock->sk;
1253     struct atalk_sock *at = at_sk(sk);
1254     int err;
1255 
1256     lock_sock(sk);
1257     err = -ENOBUFS;
1258     if (sock_flag(sk, SOCK_ZAPPED))
1259         if (atalk_autobind(sk) < 0)
1260             goto out;
1261 
1262     memset(&sat, 0, sizeof(sat));
1263 
1264     if (peer) {
1265         err = -ENOTCONN;
1266         if (sk->sk_state != TCP_ESTABLISHED)
1267             goto out;
1268 
1269         sat.sat_addr.s_net  = at->dest_net;
1270         sat.sat_addr.s_node = at->dest_node;
1271         sat.sat_port        = at->dest_port;
1272     } else {
1273         sat.sat_addr.s_net  = at->src_net;
1274         sat.sat_addr.s_node = at->src_node;
1275         sat.sat_port        = at->src_port;
1276     }
1277 
1278     sat.sat_family = AF_APPLETALK;
1279     memcpy(uaddr, &sat, sizeof(sat));
1280     err = sizeof(struct sockaddr_at);
1281 
1282 out:
1283     release_sock(sk);
1284     return err;
1285 }
1286 
1287 #if IS_ENABLED(CONFIG_IPDDP)
1288 static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
1289 {
1290     return skb->data[12] == 22;
1291 }
1292 
1293 static int handle_ip_over_ddp(struct sk_buff *skb)
1294 {
1295     struct net_device *dev = __dev_get_by_name(&init_net, "ipddp0");
1296     struct net_device_stats *stats;
1297 
1298     /* This needs to be able to handle ipddp"N" devices */
1299     if (!dev) {
1300         kfree_skb(skb);
1301         return NET_RX_DROP;
1302     }
1303 
1304     skb->protocol = htons(ETH_P_IP);
1305     skb_pull(skb, 13);
1306     skb->dev   = dev;
1307     skb_reset_transport_header(skb);
1308 
1309     stats = netdev_priv(dev);
1310     stats->rx_packets++;
1311     stats->rx_bytes += skb->len + 13;
1312     return netif_rx(skb);  /* Send the SKB up to a higher place. */
1313 }
1314 #else
1315 /* make it easy for gcc to optimize this test out, i.e. kill the code */
1316 #define is_ip_over_ddp(skb) 0
1317 #define handle_ip_over_ddp(skb) 0
1318 #endif
1319 
1320 static int atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
1321                   struct ddpehdr *ddp, __u16 len_hops, int origlen)
1322 {
1323     struct atalk_route *rt;
1324     struct atalk_addr ta;
1325 
1326     /*
1327      * Don't route multicast, etc., packets, or packets sent to "this
1328      * network"
1329      */
1330     if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
1331         /*
1332          * FIXME:
1333          *
1334          * Can it ever happen that a packet is from a PPP iface and
1335          * needs to be broadcast onto the default network?
1336          */
1337         if (dev->type == ARPHRD_PPP)
1338             printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
1339                       "packet received from PPP iface\n");
1340         goto free_it;
1341     }
1342 
1343     ta.s_net  = ddp->deh_dnet;
1344     ta.s_node = ddp->deh_dnode;
1345 
1346     /* Route the packet */
1347     rt = atrtr_find(&ta);
1348     /* increment hops count */
1349     len_hops += 1 << 10;
1350     if (!rt || !(len_hops & (15 << 10)))
1351         goto free_it;
1352 
1353     /* FIXME: use skb->cb to be able to use shared skbs */
1354 
1355     /*
1356      * Route goes through another gateway, so set the target to the
1357      * gateway instead.
1358      */
1359 
1360     if (rt->flags & RTF_GATEWAY) {
1361         ta.s_net  = rt->gateway.s_net;
1362         ta.s_node = rt->gateway.s_node;
1363     }
1364 
1365     /* Fix up skb->len field */
1366     skb_trim(skb, min_t(unsigned int, origlen,
1367                 (rt->dev->hard_header_len +
1368                  ddp_dl->header_length + (len_hops & 1023))));
1369 
1370     /* FIXME: use skb->cb to be able to use shared skbs */
1371     ddp->deh_len_hops = htons(len_hops);
1372 
1373     /*
1374      * Send the buffer onwards
1375      *
1376      * Now we must always be careful. If it's come from LocalTalk to
1377      * EtherTalk it might not fit
1378      *
1379      * Order matters here: If a packet has to be copied to make a new
1380      * headroom (rare hopefully) then it won't need unsharing.
1381      *
1382      * Note. ddp-> becomes invalid at the realloc.
1383      */
1384     if (skb_headroom(skb) < 22) {
1385         /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
1386         struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
1387         kfree_skb(skb);
1388         skb = nskb;
1389     } else
1390         skb = skb_unshare(skb, GFP_ATOMIC);
1391 
1392     /*
1393      * If the buffer didn't vanish into the lack of space bitbucket we can
1394      * send it.
1395      */
1396     if (skb == NULL)
1397         goto drop;
1398 
1399     if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP)
1400         return NET_RX_DROP;
1401     return NET_RX_SUCCESS;
1402 free_it:
1403     kfree_skb(skb);
1404 drop:
1405     return NET_RX_DROP;
1406 }
1407 
1408 /**
1409  *  atalk_rcv - Receive a packet (in skb) from device dev
1410  *  @skb: packet received
1411  *  @dev: network device where the packet comes from
1412  *  @pt: packet type
1413  *  @orig_dev: the original receive net device
1414  *
1415  *  Receive a packet (in skb) from device dev. This has come from the SNAP
1416  *  decoder, and on entry skb->transport_header is the DDP header, skb->len
1417  *  is the DDP header, skb->len is the DDP length. The physical headers
1418  *  have been extracted. PPP should probably pass frames marked as for this
1419  *  layer.  [ie ARPHRD_ETHERTALK]
1420  */
1421 static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
1422              struct packet_type *pt, struct net_device *orig_dev)
1423 {
1424     struct ddpehdr *ddp;
1425     struct sock *sock;
1426     struct atalk_iface *atif;
1427     struct sockaddr_at tosat;
1428     int origlen;
1429     __u16 len_hops;
1430 
1431     if (!net_eq(dev_net(dev), &init_net))
1432         goto drop;
1433 
1434     /* Don't mangle buffer if shared */
1435     if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1436         goto out;
1437 
1438     /* Size check and make sure header is contiguous */
1439     if (!pskb_may_pull(skb, sizeof(*ddp)))
1440         goto drop;
1441 
1442     ddp = ddp_hdr(skb);
1443 
1444     len_hops = ntohs(ddp->deh_len_hops);
1445 
1446     /* Trim buffer in case of stray trailing data */
1447     origlen = skb->len;
1448     skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023));
1449 
1450     /*
1451      * Size check to see if ddp->deh_len was crap
1452      * (Otherwise we'll detonate most spectacularly
1453      * in the middle of atalk_checksum() or recvmsg()).
1454      */
1455     if (skb->len < sizeof(*ddp) || skb->len < (len_hops & 1023)) {
1456         pr_debug("AppleTalk: dropping corrupted frame (deh_len=%u, "
1457              "skb->len=%u)\n", len_hops & 1023, skb->len);
1458         goto drop;
1459     }
1460 
1461     /*
1462      * Any checksums. Note we don't do htons() on this == is assumed to be
1463      * valid for net byte orders all over the networking code...
1464      */
1465     if (ddp->deh_sum &&
1466         atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum)
1467         /* Not a valid AppleTalk frame - dustbin time */
1468         goto drop;
1469 
1470     /* Check the packet is aimed at us */
1471     if (!ddp->deh_dnet) /* Net 0 is 'this network' */
1472         atif = atalk_find_anynet(ddp->deh_dnode, dev);
1473     else
1474         atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
1475 
1476     if (!atif) {
1477         /* Not ours, so we route the packet via the correct
1478          * AppleTalk iface
1479          */
1480         return atalk_route_packet(skb, dev, ddp, len_hops, origlen);
1481     }
1482 
1483     /* if IP over DDP is not selected this code will be optimized out */
1484     if (is_ip_over_ddp(skb))
1485         return handle_ip_over_ddp(skb);
1486     /*
1487      * Which socket - atalk_search_socket() looks for a *full match*
1488      * of the <net, node, port> tuple.
1489      */
1490     tosat.sat_addr.s_net  = ddp->deh_dnet;
1491     tosat.sat_addr.s_node = ddp->deh_dnode;
1492     tosat.sat_port        = ddp->deh_dport;
1493 
1494     sock = atalk_search_socket(&tosat, atif);
1495     if (!sock) /* But not one of our sockets */
1496         goto drop;
1497 
1498     /* Queue packet (standard) */
1499     if (sock_queue_rcv_skb(sock, skb) < 0)
1500         goto drop;
1501 
1502     return NET_RX_SUCCESS;
1503 
1504 drop:
1505     kfree_skb(skb);
1506 out:
1507     return NET_RX_DROP;
1508 
1509 }
1510 
1511 /*
1512  * Receive a LocalTalk frame. We make some demands on the caller here.
1513  * Caller must provide enough headroom on the packet to pull the short
1514  * header and append a long one.
1515  */
1516 static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
1517              struct packet_type *pt, struct net_device *orig_dev)
1518 {
1519     if (!net_eq(dev_net(dev), &init_net))
1520         goto freeit;
1521 
1522     /* Expand any short form frames */
1523     if (skb_mac_header(skb)[2] == 1) {
1524         struct ddpehdr *ddp;
1525         /* Find our address */
1526         struct atalk_addr *ap = atalk_find_dev_addr(dev);
1527 
1528         if (!ap || skb->len < sizeof(__be16) || skb->len > 1023)
1529             goto freeit;
1530 
1531         /* Don't mangle buffer if shared */
1532         if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1533             return 0;
1534 
1535         /*
1536          * The push leaves us with a ddephdr not an shdr, and
1537          * handily the port bytes in the right place preset.
1538          */
1539         ddp = skb_push(skb, sizeof(*ddp) - 4);
1540 
1541         /* Now fill in the long header */
1542 
1543         /*
1544          * These two first. The mac overlays the new source/dest
1545          * network information so we MUST copy these before
1546          * we write the network numbers !
1547          */
1548 
1549         ddp->deh_dnode = skb_mac_header(skb)[0];     /* From physical header */
1550         ddp->deh_snode = skb_mac_header(skb)[1];     /* From physical header */
1551 
1552         ddp->deh_dnet  = ap->s_net; /* Network number */
1553         ddp->deh_snet  = ap->s_net;
1554         ddp->deh_sum   = 0;     /* No checksum */
1555         /*
1556          * Not sure about this bit...
1557          */
1558         /* Non routable, so force a drop if we slip up later */
1559         ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
1560     }
1561     skb_reset_transport_header(skb);
1562 
1563     return atalk_rcv(skb, dev, pt, orig_dev);
1564 freeit:
1565     kfree_skb(skb);
1566     return 0;
1567 }
1568 
1569 static int atalk_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
1570 {
1571     struct sock *sk = sock->sk;
1572     struct atalk_sock *at = at_sk(sk);
1573     DECLARE_SOCKADDR(struct sockaddr_at *, usat, msg->msg_name);
1574     int flags = msg->msg_flags;
1575     int loopback = 0;
1576     struct sockaddr_at local_satalk, gsat;
1577     struct sk_buff *skb;
1578     struct net_device *dev;
1579     struct ddpehdr *ddp;
1580     int size, hard_header_len;
1581     struct atalk_route *rt, *rt_lo = NULL;
1582     int err;
1583 
1584     if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
1585         return -EINVAL;
1586 
1587     if (len > DDP_MAXSZ)
1588         return -EMSGSIZE;
1589 
1590     lock_sock(sk);
1591     if (usat) {
1592         err = -EBUSY;
1593         if (sock_flag(sk, SOCK_ZAPPED))
1594             if (atalk_autobind(sk) < 0)
1595                 goto out;
1596 
1597         err = -EINVAL;
1598         if (msg->msg_namelen < sizeof(*usat) ||
1599             usat->sat_family != AF_APPLETALK)
1600             goto out;
1601 
1602         err = -EPERM;
1603         /* netatalk didn't implement this check */
1604         if (usat->sat_addr.s_node == ATADDR_BCAST &&
1605             !sock_flag(sk, SOCK_BROADCAST)) {
1606             goto out;
1607         }
1608     } else {
1609         err = -ENOTCONN;
1610         if (sk->sk_state != TCP_ESTABLISHED)
1611             goto out;
1612         usat = &local_satalk;
1613         usat->sat_family      = AF_APPLETALK;
1614         usat->sat_port        = at->dest_port;
1615         usat->sat_addr.s_node = at->dest_node;
1616         usat->sat_addr.s_net  = at->dest_net;
1617     }
1618 
1619     /* Build a packet */
1620     SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
1621 
1622     /* For headers */
1623     size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
1624 
1625     if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
1626         rt = atrtr_find(&usat->sat_addr);
1627     } else {
1628         struct atalk_addr at_hint;
1629 
1630         at_hint.s_node = 0;
1631         at_hint.s_net  = at->src_net;
1632 
1633         rt = atrtr_find(&at_hint);
1634     }
1635     err = -ENETUNREACH;
1636     if (!rt)
1637         goto out;
1638 
1639     dev = rt->dev;
1640 
1641     SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
1642             sk, size, dev->name);
1643 
1644     hard_header_len = dev->hard_header_len;
1645     /* Leave room for loopback hardware header if necessary */
1646     if (usat->sat_addr.s_node == ATADDR_BCAST &&
1647         (dev->flags & IFF_LOOPBACK || !(rt->flags & RTF_GATEWAY))) {
1648         struct atalk_addr at_lo;
1649 
1650         at_lo.s_node = 0;
1651         at_lo.s_net  = 0;
1652 
1653         rt_lo = atrtr_find(&at_lo);
1654 
1655         if (rt_lo && rt_lo->dev->hard_header_len > hard_header_len)
1656             hard_header_len = rt_lo->dev->hard_header_len;
1657     }
1658 
1659     size += hard_header_len;
1660     release_sock(sk);
1661     skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
1662     lock_sock(sk);
1663     if (!skb)
1664         goto out;
1665 
1666     skb_reserve(skb, ddp_dl->header_length);
1667     skb_reserve(skb, hard_header_len);
1668     skb->dev = dev;
1669 
1670     SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
1671 
1672     ddp = skb_put(skb, sizeof(struct ddpehdr));
1673     ddp->deh_len_hops  = htons(len + sizeof(*ddp));
1674     ddp->deh_dnet  = usat->sat_addr.s_net;
1675     ddp->deh_snet  = at->src_net;
1676     ddp->deh_dnode = usat->sat_addr.s_node;
1677     ddp->deh_snode = at->src_node;
1678     ddp->deh_dport = usat->sat_port;
1679     ddp->deh_sport = at->src_port;
1680 
1681     SOCK_DEBUG(sk, "SK %p: Copy user data (%zd bytes).\n", sk, len);
1682 
1683     err = memcpy_from_msg(skb_put(skb, len), msg, len);
1684     if (err) {
1685         kfree_skb(skb);
1686         err = -EFAULT;
1687         goto out;
1688     }
1689 
1690     if (sk->sk_no_check_tx)
1691         ddp->deh_sum = 0;
1692     else
1693         ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
1694 
1695     /*
1696      * Loopback broadcast packets to non gateway targets (ie routes
1697      * to group we are in)
1698      */
1699     if (ddp->deh_dnode == ATADDR_BCAST &&
1700         !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
1701         struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
1702 
1703         if (skb2) {
1704             loopback = 1;
1705             SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
1706             /*
1707              * If it fails it is queued/sent above in the aarp queue
1708              */
1709             aarp_send_ddp(dev, skb2, &usat->sat_addr, NULL);
1710         }
1711     }
1712 
1713     if (dev->flags & IFF_LOOPBACK || loopback) {
1714         SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
1715         /* loop back */
1716         skb_orphan(skb);
1717         if (ddp->deh_dnode == ATADDR_BCAST) {
1718             if (!rt_lo) {
1719                 kfree_skb(skb);
1720                 err = -ENETUNREACH;
1721                 goto out;
1722             }
1723             dev = rt_lo->dev;
1724             skb->dev = dev;
1725         }
1726         ddp_dl->request(ddp_dl, skb, dev->dev_addr);
1727     } else {
1728         SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
1729         if (rt->flags & RTF_GATEWAY) {
1730             gsat.sat_addr = rt->gateway;
1731             usat = &gsat;
1732         }
1733 
1734         /*
1735          * If it fails it is queued/sent above in the aarp queue
1736          */
1737         aarp_send_ddp(dev, skb, &usat->sat_addr, NULL);
1738     }
1739     SOCK_DEBUG(sk, "SK %p: Done write (%zd).\n", sk, len);
1740 
1741 out:
1742     release_sock(sk);
1743     return err ? : len;
1744 }
1745 
1746 static int atalk_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
1747              int flags)
1748 {
1749     struct sock *sk = sock->sk;
1750     struct ddpehdr *ddp;
1751     int copied = 0;
1752     int offset = 0;
1753     int err = 0;
1754     struct sk_buff *skb;
1755 
1756     skb = skb_recv_datagram(sk, flags, &err);
1757     lock_sock(sk);
1758 
1759     if (!skb)
1760         goto out;
1761 
1762     /* FIXME: use skb->cb to be able to use shared skbs */
1763     ddp = ddp_hdr(skb);
1764     copied = ntohs(ddp->deh_len_hops) & 1023;
1765 
1766     if (sk->sk_type != SOCK_RAW) {
1767         offset = sizeof(*ddp);
1768         copied -= offset;
1769     }
1770 
1771     if (copied > size) {
1772         copied = size;
1773         msg->msg_flags |= MSG_TRUNC;
1774     }
1775     err = skb_copy_datagram_msg(skb, offset, msg, copied);
1776 
1777     if (!err && msg->msg_name) {
1778         DECLARE_SOCKADDR(struct sockaddr_at *, sat, msg->msg_name);
1779         sat->sat_family      = AF_APPLETALK;
1780         sat->sat_port        = ddp->deh_sport;
1781         sat->sat_addr.s_node = ddp->deh_snode;
1782         sat->sat_addr.s_net  = ddp->deh_snet;
1783         msg->msg_namelen     = sizeof(*sat);
1784     }
1785 
1786     skb_free_datagram(sk, skb); /* Free the datagram. */
1787 
1788 out:
1789     release_sock(sk);
1790     return err ? : copied;
1791 }
1792 
1793 
1794 /*
1795  * AppleTalk ioctl calls.
1796  */
1797 static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1798 {
1799     int rc = -ENOIOCTLCMD;
1800     struct sock *sk = sock->sk;
1801     void __user *argp = (void __user *)arg;
1802 
1803     switch (cmd) {
1804     /* Protocol layer */
1805     case TIOCOUTQ: {
1806         long amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
1807 
1808         if (amount < 0)
1809             amount = 0;
1810         rc = put_user(amount, (int __user *)argp);
1811         break;
1812     }
1813     case TIOCINQ: {
1814         /*
1815          * These two are safe on a single CPU system as only
1816          * user tasks fiddle here
1817          */
1818         struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
1819         long amount = 0;
1820 
1821         if (skb)
1822             amount = skb->len - sizeof(struct ddpehdr);
1823         rc = put_user(amount, (int __user *)argp);
1824         break;
1825     }
1826     /* Routing */
1827     case SIOCADDRT:
1828     case SIOCDELRT:
1829         rc = -EPERM;
1830         if (capable(CAP_NET_ADMIN))
1831             rc = atrtr_ioctl(cmd, argp);
1832         break;
1833     /* Interface */
1834     case SIOCGIFADDR:
1835     case SIOCSIFADDR:
1836     case SIOCGIFBRDADDR:
1837     case SIOCATALKDIFADDR:
1838     case SIOCDIFADDR:
1839     case SIOCSARP:      /* proxy AARP */
1840     case SIOCDARP:      /* proxy AARP */
1841         rtnl_lock();
1842         rc = atif_ioctl(cmd, argp);
1843         rtnl_unlock();
1844         break;
1845     }
1846 
1847     return rc;
1848 }
1849 
1850 
1851 #ifdef CONFIG_COMPAT
1852 static int atalk_compat_routing_ioctl(struct sock *sk, unsigned int cmd,
1853         struct compat_rtentry __user *ur)
1854 {
1855     compat_uptr_t rtdev;
1856     struct rtentry rt;
1857 
1858     if (copy_from_user(&rt.rt_dst, &ur->rt_dst,
1859             3 * sizeof(struct sockaddr)) ||
1860         get_user(rt.rt_flags, &ur->rt_flags) ||
1861         get_user(rt.rt_metric, &ur->rt_metric) ||
1862         get_user(rt.rt_mtu, &ur->rt_mtu) ||
1863         get_user(rt.rt_window, &ur->rt_window) ||
1864         get_user(rt.rt_irtt, &ur->rt_irtt) ||
1865         get_user(rtdev, &ur->rt_dev))
1866         return -EFAULT;
1867 
1868     switch (cmd) {
1869     case SIOCDELRT:
1870         if (rt.rt_dst.sa_family != AF_APPLETALK)
1871             return -EINVAL;
1872         return atrtr_delete(&((struct sockaddr_at *)
1873                       &rt.rt_dst)->sat_addr);
1874 
1875     case SIOCADDRT:
1876         rt.rt_dev = compat_ptr(rtdev);
1877         return atrtr_ioctl_addrt(&rt);
1878     default:
1879         return -EINVAL;
1880     }
1881 }
1882 static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1883 {
1884     void __user *argp = compat_ptr(arg);
1885     struct sock *sk = sock->sk;
1886 
1887     switch (cmd) {
1888     case SIOCADDRT:
1889     case SIOCDELRT:
1890         return atalk_compat_routing_ioctl(sk, cmd, argp);
1891     /*
1892      * SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
1893      * cannot handle it in common code. The data we access if ifreq
1894      * here is compatible, so we can simply call the native
1895      * handler.
1896      */
1897     case SIOCATALKDIFADDR:
1898         return atalk_ioctl(sock, cmd, (unsigned long)argp);
1899     default:
1900         return -ENOIOCTLCMD;
1901     }
1902 }
1903 #endif /* CONFIG_COMPAT */
1904 
1905 
1906 static const struct net_proto_family atalk_family_ops = {
1907     .family     = PF_APPLETALK,
1908     .create     = atalk_create,
1909     .owner      = THIS_MODULE,
1910 };
1911 
1912 static const struct proto_ops atalk_dgram_ops = {
1913     .family     = PF_APPLETALK,
1914     .owner      = THIS_MODULE,
1915     .release    = atalk_release,
1916     .bind       = atalk_bind,
1917     .connect    = atalk_connect,
1918     .socketpair = sock_no_socketpair,
1919     .accept     = sock_no_accept,
1920     .getname    = atalk_getname,
1921     .poll       = datagram_poll,
1922     .ioctl      = atalk_ioctl,
1923     .gettstamp  = sock_gettstamp,
1924 #ifdef CONFIG_COMPAT
1925     .compat_ioctl   = atalk_compat_ioctl,
1926 #endif
1927     .listen     = sock_no_listen,
1928     .shutdown   = sock_no_shutdown,
1929     .sendmsg    = atalk_sendmsg,
1930     .recvmsg    = atalk_recvmsg,
1931     .mmap       = sock_no_mmap,
1932     .sendpage   = sock_no_sendpage,
1933 };
1934 
1935 static struct notifier_block ddp_notifier = {
1936     .notifier_call  = ddp_device_event,
1937 };
1938 
1939 static struct packet_type ltalk_packet_type __read_mostly = {
1940     .type       = cpu_to_be16(ETH_P_LOCALTALK),
1941     .func       = ltalk_rcv,
1942 };
1943 
1944 static struct packet_type ppptalk_packet_type __read_mostly = {
1945     .type       = cpu_to_be16(ETH_P_PPPTALK),
1946     .func       = atalk_rcv,
1947 };
1948 
1949 static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
1950 
1951 /* Export symbols for use by drivers when AppleTalk is a module */
1952 EXPORT_SYMBOL(atrtr_get_dev);
1953 EXPORT_SYMBOL(atalk_find_dev_addr);
1954 
1955 /* Called by proto.c on kernel start up */
1956 static int __init atalk_init(void)
1957 {
1958     int rc;
1959 
1960     rc = proto_register(&ddp_proto, 0);
1961     if (rc)
1962         goto out;
1963 
1964     rc = sock_register(&atalk_family_ops);
1965     if (rc)
1966         goto out_proto;
1967 
1968     ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
1969     if (!ddp_dl) {
1970         pr_crit("Unable to register DDP with SNAP.\n");
1971         rc = -ENOMEM;
1972         goto out_sock;
1973     }
1974 
1975     dev_add_pack(&ltalk_packet_type);
1976     dev_add_pack(&ppptalk_packet_type);
1977 
1978     rc = register_netdevice_notifier(&ddp_notifier);
1979     if (rc)
1980         goto out_snap;
1981 
1982     rc = aarp_proto_init();
1983     if (rc)
1984         goto out_dev;
1985 
1986     rc = atalk_proc_init();
1987     if (rc)
1988         goto out_aarp;
1989 
1990     rc = atalk_register_sysctl();
1991     if (rc)
1992         goto out_proc;
1993 out:
1994     return rc;
1995 out_proc:
1996     atalk_proc_exit();
1997 out_aarp:
1998     aarp_cleanup_module();
1999 out_dev:
2000     unregister_netdevice_notifier(&ddp_notifier);
2001 out_snap:
2002     dev_remove_pack(&ppptalk_packet_type);
2003     dev_remove_pack(&ltalk_packet_type);
2004     unregister_snap_client(ddp_dl);
2005 out_sock:
2006     sock_unregister(PF_APPLETALK);
2007 out_proto:
2008     proto_unregister(&ddp_proto);
2009     goto out;
2010 }
2011 module_init(atalk_init);
2012 
2013 /*
2014  * No explicit module reference count manipulation is needed in the
2015  * protocol. Socket layer sets module reference count for us
2016  * and interfaces reference counting is done
2017  * by the network device layer.
2018  *
2019  * Ergo, before the AppleTalk module can be removed, all AppleTalk
2020  * sockets should be closed from user space.
2021  */
2022 static void __exit atalk_exit(void)
2023 {
2024 #ifdef CONFIG_SYSCTL
2025     atalk_unregister_sysctl();
2026 #endif /* CONFIG_SYSCTL */
2027     atalk_proc_exit();
2028     aarp_cleanup_module();  /* General aarp clean-up. */
2029     unregister_netdevice_notifier(&ddp_notifier);
2030     dev_remove_pack(&ltalk_packet_type);
2031     dev_remove_pack(&ppptalk_packet_type);
2032     unregister_snap_client(ddp_dl);
2033     sock_unregister(PF_APPLETALK);
2034     proto_unregister(&ddp_proto);
2035 }
2036 module_exit(atalk_exit);
2037 
2038 MODULE_LICENSE("GPL");
2039 MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
2040 MODULE_DESCRIPTION("AppleTalk 0.20\n");
2041 MODULE_ALIAS_NETPROTO(PF_APPLETALK);