2 * DDP: An implementation of the AppleTalk DDP protocol for
5 * Alan Cox <alan@lxorguk.ukuu.org.uk>
7 * With more than a little assistance from
9 * Wesley Craig <netatalk@umich.edu>
12 * Neil Horman : Added missing device ioctls
13 * Michael Callahan : Made routing work
14 * Wesley Craig : Fix probing to listen to a
16 * Alan Cox : Added send/recvmsg support
17 * Alan Cox : Moved at. to protinfo in
19 * Alan Cox : Added firewall hooks.
20 * Alan Cox : Supports new ARPHRD_LOOPBACK
21 * Christer Weinigel : Routing and /proc fixes.
22 * Bradford Johnson : LocalTalk.
23 * Tom Dyas : Module support.
24 * Alan Cox : Hooks for PPP (based on the
26 * Alan Cox : Posix bits
27 * Alan Cox/Mike Freeman : Possible fix to NBP problems
28 * Bradford Johnson : IP-over-DDP (experimental)
29 * Jay Schulist : Moved IP-over-DDP to its own
30 * driver file. (ipddp.c & ipddp.h)
31 * Jay Schulist : Made work as module with
32 * AppleTalk drivers, cleaned it.
33 * Rob Newberry : Added proxy AARP and AARP
34 * procfs, moved probing to AARP
37 * Michael Zuelsdorff : fix for net.0 packets. don't
38 * allow illegal ether/tokentalk
39 * port assignment. we lose a
40 * valid localtalk port as a
42 * Arnaldo C. de Melo : Cleanup, in preparation for
43 * shared skb support 8)
44 * Arnaldo C. de Melo : Move proc stuff to atalk_proc.c,
47 * This program is free software; you can redistribute it and/or
48 * modify it under the terms of the GNU General Public License
49 * as published by the Free Software Foundation; either version
50 * 2 of the License, or (at your option) any later version.
54 #include <linux/capability.h>
55 #include <linux/module.h>
56 #include <linux/if_arp.h>
57 #include <linux/termios.h> /* For TIOCOUTQ/INQ */
58 #include <linux/compat.h>
59 #include <linux/slab.h>
60 #include <net/datalink.h>
61 #include <net/psnap.h>
63 #include <net/tcp_states.h>
64 #include <net/route.h>
65 #include <linux/atalk.h>
66 #include <linux/highmem.h>
68 struct datalink_proto *ddp_dl, *aarp_dl;
69 static const struct proto_ops atalk_dgram_ops;
71 /**************************************************************************\
73 * Handlers for the socket list. *
75 \**************************************************************************/
77 HLIST_HEAD(atalk_sockets);
78 DEFINE_RWLOCK(atalk_sockets_lock);
80 static inline void __atalk_insert_socket(struct sock *sk)
82 sk_add_node(sk, &atalk_sockets);
85 static inline void atalk_remove_socket(struct sock *sk)
87 write_lock_bh(&atalk_sockets_lock);
89 write_unlock_bh(&atalk_sockets_lock);
92 static struct sock *atalk_search_socket(struct sockaddr_at *to,
93 struct atalk_iface *atif)
97 read_lock_bh(&atalk_sockets_lock);
98 sk_for_each(s, &atalk_sockets) {
99 struct atalk_sock *at = at_sk(s);
101 if (to->sat_port != at->src_port)
104 if (to->sat_addr.s_net == ATADDR_ANYNET &&
105 to->sat_addr.s_node == ATADDR_BCAST)
108 if (to->sat_addr.s_net == at->src_net &&
109 (to->sat_addr.s_node == at->src_node ||
110 to->sat_addr.s_node == ATADDR_BCAST ||
111 to->sat_addr.s_node == ATADDR_ANYNODE))
114 /* XXXX.0 -- we got a request for this router. make sure
115 * that the node is appropriately set. */
116 if (to->sat_addr.s_node == ATADDR_ANYNODE &&
117 to->sat_addr.s_net != ATADDR_ANYNET &&
118 atif->address.s_node == at->src_node) {
119 to->sat_addr.s_node = atif->address.s_node;
125 read_unlock_bh(&atalk_sockets_lock);
130 * atalk_find_or_insert_socket - Try to find a socket matching ADDR
131 * @sk: socket to insert in the list if it is not there already
132 * @sat: address to search for
134 * Try to find a socket matching ADDR in the socket list, if found then return
135 * it. If not, insert SK into the socket list.
137 * This entire operation must execute atomically.
139 static struct sock *atalk_find_or_insert_socket(struct sock *sk,
140 struct sockaddr_at *sat)
143 struct atalk_sock *at;
145 write_lock_bh(&atalk_sockets_lock);
146 sk_for_each(s, &atalk_sockets) {
149 if (at->src_net == sat->sat_addr.s_net &&
150 at->src_node == sat->sat_addr.s_node &&
151 at->src_port == sat->sat_port)
155 __atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
157 write_unlock_bh(&atalk_sockets_lock);
161 static void atalk_destroy_timer(unsigned long data)
163 struct sock *sk = (struct sock *)data;
165 if (sk_has_allocations(sk)) {
166 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
167 add_timer(&sk->sk_timer);
172 static inline void atalk_destroy_socket(struct sock *sk)
174 atalk_remove_socket(sk);
175 skb_queue_purge(&sk->sk_receive_queue);
177 if (sk_has_allocations(sk)) {
178 setup_timer(&sk->sk_timer, atalk_destroy_timer,
180 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
181 add_timer(&sk->sk_timer);
186 /**************************************************************************\
188 * Routing tables for the AppleTalk socket layer. *
190 \**************************************************************************/
192 /* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
193 struct atalk_route *atalk_routes;
194 DEFINE_RWLOCK(atalk_routes_lock);
196 struct atalk_iface *atalk_interfaces;
197 DEFINE_RWLOCK(atalk_interfaces_lock);
199 /* For probing devices or in a routerless network */
200 struct atalk_route atrtr_default;
202 /* AppleTalk interface control */
204 * Drop a device. Doesn't drop any of its routes - that is the caller's
205 * problem. Called when we down the interface or delete the address.
207 static void atif_drop_device(struct net_device *dev)
209 struct atalk_iface **iface = &atalk_interfaces;
210 struct atalk_iface *tmp;
212 write_lock_bh(&atalk_interfaces_lock);
213 while ((tmp = *iface) != NULL) {
214 if (tmp->dev == dev) {
218 dev->atalk_ptr = NULL;
222 write_unlock_bh(&atalk_interfaces_lock);
225 static struct atalk_iface *atif_add_device(struct net_device *dev,
226 struct atalk_addr *sa)
228 struct atalk_iface *iface = kzalloc(sizeof(*iface), GFP_KERNEL);
235 dev->atalk_ptr = iface;
236 iface->address = *sa;
239 write_lock_bh(&atalk_interfaces_lock);
240 iface->next = atalk_interfaces;
241 atalk_interfaces = iface;
242 write_unlock_bh(&atalk_interfaces_lock);
247 /* Perform phase 2 AARP probing on our tentative address */
248 static int atif_probe_device(struct atalk_iface *atif)
250 int netrange = ntohs(atif->nets.nr_lastnet) -
251 ntohs(atif->nets.nr_firstnet) + 1;
252 int probe_net = ntohs(atif->address.s_net);
253 int probe_node = atif->address.s_node;
256 /* Offset the network we start probing with */
257 if (probe_net == ATADDR_ANYNET) {
258 probe_net = ntohs(atif->nets.nr_firstnet);
260 probe_net += jiffies % netrange;
262 if (probe_node == ATADDR_ANYNODE)
263 probe_node = jiffies & 0xFF;
265 /* Scan the networks */
266 atif->status |= ATIF_PROBE;
267 for (netct = 0; netct <= netrange; netct++) {
268 /* Sweep the available nodes from a given start */
269 atif->address.s_net = htons(probe_net);
270 for (nodect = 0; nodect < 256; nodect++) {
271 atif->address.s_node = (nodect + probe_node) & 0xFF;
272 if (atif->address.s_node > 0 &&
273 atif->address.s_node < 254) {
274 /* Probe a proposed address */
275 aarp_probe_network(atif);
277 if (!(atif->status & ATIF_PROBE_FAIL)) {
278 atif->status &= ~ATIF_PROBE;
282 atif->status &= ~ATIF_PROBE_FAIL;
285 if (probe_net > ntohs(atif->nets.nr_lastnet))
286 probe_net = ntohs(atif->nets.nr_firstnet);
288 atif->status &= ~ATIF_PROBE;
290 return -EADDRINUSE; /* Network is full... */
294 /* Perform AARP probing for a proxy address */
295 static int atif_proxy_probe_device(struct atalk_iface *atif,
296 struct atalk_addr *proxy_addr)
298 int netrange = ntohs(atif->nets.nr_lastnet) -
299 ntohs(atif->nets.nr_firstnet) + 1;
300 /* we probe the interface's network */
301 int probe_net = ntohs(atif->address.s_net);
302 int probe_node = ATADDR_ANYNODE; /* we'll take anything */
305 /* Offset the network we start probing with */
306 if (probe_net == ATADDR_ANYNET) {
307 probe_net = ntohs(atif->nets.nr_firstnet);
309 probe_net += jiffies % netrange;
312 if (probe_node == ATADDR_ANYNODE)
313 probe_node = jiffies & 0xFF;
315 /* Scan the networks */
316 for (netct = 0; netct <= netrange; netct++) {
317 /* Sweep the available nodes from a given start */
318 proxy_addr->s_net = htons(probe_net);
319 for (nodect = 0; nodect < 256; nodect++) {
320 proxy_addr->s_node = (nodect + probe_node) & 0xFF;
321 if (proxy_addr->s_node > 0 &&
322 proxy_addr->s_node < 254) {
323 /* Tell AARP to probe a proposed address */
324 int ret = aarp_proxy_probe_network(atif,
327 if (ret != -EADDRINUSE)
332 if (probe_net > ntohs(atif->nets.nr_lastnet))
333 probe_net = ntohs(atif->nets.nr_firstnet);
336 return -EADDRINUSE; /* Network is full... */
340 struct atalk_addr *atalk_find_dev_addr(struct net_device *dev)
342 struct atalk_iface *iface = dev->atalk_ptr;
343 return iface ? &iface->address : NULL;
346 static struct atalk_addr *atalk_find_primary(void)
348 struct atalk_iface *fiface = NULL;
349 struct atalk_addr *retval;
350 struct atalk_iface *iface;
353 * Return a point-to-point interface only if
354 * there is no non-ptp interface available.
356 read_lock_bh(&atalk_interfaces_lock);
357 for (iface = atalk_interfaces; iface; iface = iface->next) {
358 if (!fiface && !(iface->dev->flags & IFF_LOOPBACK))
360 if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
361 retval = &iface->address;
367 retval = &fiface->address;
368 else if (atalk_interfaces)
369 retval = &atalk_interfaces->address;
373 read_unlock_bh(&atalk_interfaces_lock);
378 * Find a match for 'any network' - ie any of our interfaces with that
379 * node number will do just nicely.
381 static struct atalk_iface *atalk_find_anynet(int node, struct net_device *dev)
383 struct atalk_iface *iface = dev->atalk_ptr;
385 if (!iface || iface->status & ATIF_PROBE)
388 if (node != ATADDR_BCAST &&
389 iface->address.s_node != node &&
390 node != ATADDR_ANYNODE)
399 /* Find a match for a specific network:node pair */
400 static struct atalk_iface *atalk_find_interface(__be16 net, int node)
402 struct atalk_iface *iface;
404 read_lock_bh(&atalk_interfaces_lock);
405 for (iface = atalk_interfaces; iface; iface = iface->next) {
406 if ((node == ATADDR_BCAST ||
407 node == ATADDR_ANYNODE ||
408 iface->address.s_node == node) &&
409 iface->address.s_net == net &&
410 !(iface->status & ATIF_PROBE))
413 /* XXXX.0 -- net.0 returns the iface associated with net */
414 if (node == ATADDR_ANYNODE && net != ATADDR_ANYNET &&
415 ntohs(iface->nets.nr_firstnet) <= ntohs(net) &&
416 ntohs(net) <= ntohs(iface->nets.nr_lastnet))
419 read_unlock_bh(&atalk_interfaces_lock);
425 * Find a route for an AppleTalk packet. This ought to get cached in
426 * the socket (later on...). We know about host routes and the fact
427 * that a route must be direct to broadcast.
429 static struct atalk_route *atrtr_find(struct atalk_addr *target)
432 * we must search through all routes unless we find a
433 * host route, because some host routes might overlap
436 struct atalk_route *net_route = NULL;
437 struct atalk_route *r;
439 read_lock_bh(&atalk_routes_lock);
440 for (r = atalk_routes; r; r = r->next) {
441 if (!(r->flags & RTF_UP))
444 if (r->target.s_net == target->s_net) {
445 if (r->flags & RTF_HOST) {
447 * if this host route is for the target,
450 if (r->target.s_node == target->s_node)
454 * this route will work if there isn't a
455 * direct host route, so cache it
462 * if we found a network route but not a direct host
463 * route, then return it
467 else if (atrtr_default.dev)
469 else /* No route can be found */
472 read_unlock_bh(&atalk_routes_lock);
478 * Given an AppleTalk network, find the device to use. This can be
481 struct net_device *atrtr_get_dev(struct atalk_addr *sa)
483 struct atalk_route *atr = atrtr_find(sa);
484 return atr ? atr->dev : NULL;
487 /* Set up a default router */
488 static void atrtr_set_default(struct net_device *dev)
490 atrtr_default.dev = dev;
491 atrtr_default.flags = RTF_UP;
492 atrtr_default.gateway.s_net = htons(0);
493 atrtr_default.gateway.s_node = 0;
497 * Add a router. Basically make sure it looks valid and stuff the
498 * entry in the list. While it uses netranges we always set them to one
499 * entry to work like netatalk.
501 static int atrtr_create(struct rtentry *r, struct net_device *devhint)
503 struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst;
504 struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway;
505 struct atalk_route *rt;
506 struct atalk_iface *iface, *riface;
507 int retval = -EINVAL;
510 * Fixme: Raise/Lower a routing change semaphore for these
514 /* Validate the request */
515 if (ta->sat_family != AF_APPLETALK ||
516 (!devhint && ga->sat_family != AF_APPLETALK))
519 /* Now walk the routing table and make our decisions */
520 write_lock_bh(&atalk_routes_lock);
521 for (rt = atalk_routes; rt; rt = rt->next) {
522 if (r->rt_flags != rt->flags)
525 if (ta->sat_addr.s_net == rt->target.s_net) {
526 if (!(rt->flags & RTF_HOST))
528 if (ta->sat_addr.s_node == rt->target.s_node)
536 read_lock_bh(&atalk_interfaces_lock);
537 for (iface = atalk_interfaces; iface; iface = iface->next) {
539 ntohs(ga->sat_addr.s_net) >=
540 ntohs(iface->nets.nr_firstnet) &&
541 ntohs(ga->sat_addr.s_net) <=
542 ntohs(iface->nets.nr_lastnet))
545 if (ga->sat_addr.s_net == iface->address.s_net &&
546 ga->sat_addr.s_node == iface->address.s_node)
549 read_unlock_bh(&atalk_interfaces_lock);
551 retval = -ENETUNREACH;
555 devhint = riface->dev;
559 rt = kzalloc(sizeof(*rt), GFP_ATOMIC);
565 rt->next = atalk_routes;
569 /* Fill in the routing entry */
570 rt->target = ta->sat_addr;
573 rt->flags = r->rt_flags;
574 rt->gateway = ga->sat_addr;
578 write_unlock_bh(&atalk_routes_lock);
583 /* Delete a route. Find it and discard it */
584 static int atrtr_delete(struct atalk_addr *addr)
586 struct atalk_route **r = &atalk_routes;
588 struct atalk_route *tmp;
590 write_lock_bh(&atalk_routes_lock);
591 while ((tmp = *r) != NULL) {
592 if (tmp->target.s_net == addr->s_net &&
593 (!(tmp->flags&RTF_GATEWAY) ||
594 tmp->target.s_node == addr->s_node)) {
604 write_unlock_bh(&atalk_routes_lock);
609 * Called when a device is downed. Just throw away any routes
612 static void atrtr_device_down(struct net_device *dev)
614 struct atalk_route **r = &atalk_routes;
615 struct atalk_route *tmp;
617 write_lock_bh(&atalk_routes_lock);
618 while ((tmp = *r) != NULL) {
619 if (tmp->dev == dev) {
626 write_unlock_bh(&atalk_routes_lock);
628 if (atrtr_default.dev == dev)
629 atrtr_set_default(NULL);
632 /* Actually down the interface */
633 static inline void atalk_dev_down(struct net_device *dev)
635 atrtr_device_down(dev); /* Remove all routes for the device */
636 aarp_device_down(dev); /* Remove AARP entries for the device */
637 atif_drop_device(dev); /* Remove the device */
641 * A device event has occurred. Watch for devices going down and
642 * delete our use of them (iface and route).
644 static int ddp_device_event(struct notifier_block *this, unsigned long event,
647 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
649 if (!net_eq(dev_net(dev), &init_net))
652 if (event == NETDEV_DOWN)
653 /* Discard any use of this */
659 /* ioctl calls. Shouldn't even need touching */
660 /* Device configuration ioctl calls */
661 static int atif_ioctl(int cmd, void __user *arg)
663 static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
665 struct atalk_netrange *nr;
666 struct sockaddr_at *sa;
667 struct net_device *dev;
668 struct atalk_iface *atif;
671 struct rtentry rtdef;
674 if (copy_from_user(&atreq, arg, sizeof(atreq)))
677 dev = __dev_get_by_name(&init_net, atreq.ifr_name);
681 sa = (struct sockaddr_at *)&atreq.ifr_addr;
682 atif = atalk_find_dev(dev);
686 if (!capable(CAP_NET_ADMIN))
688 if (sa->sat_family != AF_APPLETALK)
690 if (dev->type != ARPHRD_ETHER &&
691 dev->type != ARPHRD_LOOPBACK &&
692 dev->type != ARPHRD_LOCALTLK &&
693 dev->type != ARPHRD_PPP)
694 return -EPROTONOSUPPORT;
696 nr = (struct atalk_netrange *)&sa->sat_zero[0];
700 * if this is a point-to-point iface, and we already
701 * have an iface for this AppleTalk address, then we
702 * should not add a route
704 if ((dev->flags & IFF_POINTOPOINT) &&
705 atalk_find_interface(sa->sat_addr.s_net,
706 sa->sat_addr.s_node)) {
707 printk(KERN_DEBUG "AppleTalk: point-to-point "
708 "interface added with "
709 "existing address\n");
714 * Phase 1 is fine on LocalTalk but we don't do
715 * EtherTalk phase 1. Anyone wanting to add it go ahead.
717 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
718 return -EPROTONOSUPPORT;
719 if (sa->sat_addr.s_node == ATADDR_BCAST ||
720 sa->sat_addr.s_node == 254)
723 /* Already setting address */
724 if (atif->status & ATIF_PROBE)
727 atif->address.s_net = sa->sat_addr.s_net;
728 atif->address.s_node = sa->sat_addr.s_node;
729 atrtr_device_down(dev); /* Flush old routes */
731 atif = atif_add_device(dev, &sa->sat_addr);
738 * Check if the chosen address is used. If so we
739 * error and atalkd will try another.
742 if (!(dev->flags & IFF_LOOPBACK) &&
743 !(dev->flags & IFF_POINTOPOINT) &&
744 atif_probe_device(atif) < 0) {
745 atif_drop_device(dev);
749 /* Hey it worked - add the direct routes */
750 sa = (struct sockaddr_at *)&rtdef.rt_gateway;
751 sa->sat_family = AF_APPLETALK;
752 sa->sat_addr.s_net = atif->address.s_net;
753 sa->sat_addr.s_node = atif->address.s_node;
754 sa = (struct sockaddr_at *)&rtdef.rt_dst;
755 rtdef.rt_flags = RTF_UP;
756 sa->sat_family = AF_APPLETALK;
757 sa->sat_addr.s_node = ATADDR_ANYNODE;
758 if (dev->flags & IFF_LOOPBACK ||
759 dev->flags & IFF_POINTOPOINT)
760 rtdef.rt_flags |= RTF_HOST;
762 /* Routerless initial state */
763 if (nr->nr_firstnet == htons(0) &&
764 nr->nr_lastnet == htons(0xFFFE)) {
765 sa->sat_addr.s_net = atif->address.s_net;
766 atrtr_create(&rtdef, dev);
767 atrtr_set_default(dev);
769 limit = ntohs(nr->nr_lastnet);
770 if (limit - ntohs(nr->nr_firstnet) > 4096) {
771 printk(KERN_WARNING "Too many routes/"
776 for (ct = ntohs(nr->nr_firstnet);
778 sa->sat_addr.s_net = htons(ct);
779 atrtr_create(&rtdef, dev);
782 dev_mc_add_global(dev, aarp_mcast);
787 return -EADDRNOTAVAIL;
789 sa->sat_family = AF_APPLETALK;
790 sa->sat_addr = atif->address;
795 return -EADDRNOTAVAIL;
797 sa->sat_family = AF_APPLETALK;
798 sa->sat_addr.s_net = atif->address.s_net;
799 sa->sat_addr.s_node = ATADDR_BCAST;
802 case SIOCATALKDIFADDR:
804 if (!capable(CAP_NET_ADMIN))
806 if (sa->sat_family != AF_APPLETALK)
812 if (!capable(CAP_NET_ADMIN))
814 if (sa->sat_family != AF_APPLETALK)
817 * for now, we only support proxy AARP on ELAP;
818 * we should be able to do it for LocalTalk, too.
820 if (dev->type != ARPHRD_ETHER)
821 return -EPROTONOSUPPORT;
824 * atif points to the current interface on this network;
825 * we aren't concerned about its current status (at
826 * least for now), but it has all the settings about
827 * the network we're going to probe. Consequently, it
831 return -EADDRNOTAVAIL;
833 nr = (struct atalk_netrange *)&(atif->nets);
835 * Phase 1 is fine on Localtalk but we don't do
836 * Ethertalk phase 1. Anyone wanting to add it go ahead.
838 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
839 return -EPROTONOSUPPORT;
841 if (sa->sat_addr.s_node == ATADDR_BCAST ||
842 sa->sat_addr.s_node == 254)
846 * Check if the chosen address is used. If so we
847 * error and ATCP will try another.
849 if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0)
853 * We now have an address on the local network, and
854 * the AARP code will defend it for us until we take it
855 * down. We don't set up any routes right now, because
856 * ATCP will install them manually via SIOCADDRT.
861 if (!capable(CAP_NET_ADMIN))
863 if (sa->sat_family != AF_APPLETALK)
866 return -EADDRNOTAVAIL;
868 /* give to aarp module to remove proxy entry */
869 aarp_proxy_remove(atif->dev, &(sa->sat_addr));
873 return copy_to_user(arg, &atreq, sizeof(atreq)) ? -EFAULT : 0;
876 /* Routing ioctl() calls */
877 static int atrtr_ioctl(unsigned int cmd, void __user *arg)
881 if (copy_from_user(&rt, arg, sizeof(rt)))
886 if (rt.rt_dst.sa_family != AF_APPLETALK)
888 return atrtr_delete(&((struct sockaddr_at *)
889 &rt.rt_dst)->sat_addr);
892 struct net_device *dev = NULL;
895 if (copy_from_user(name, rt.rt_dev, IFNAMSIZ-1))
897 name[IFNAMSIZ-1] = '\0';
898 dev = __dev_get_by_name(&init_net, name);
902 return atrtr_create(&rt, dev);
908 /**************************************************************************\
910 * Handling for system calls applied via the various interfaces to an *
911 * AppleTalk socket object. *
913 \**************************************************************************/
916 * Checksum: This is 'optional'. It's quite likely also a good
917 * candidate for assembler hackery 8)
919 static unsigned long atalk_sum_partial(const unsigned char *data,
920 int len, unsigned long sum)
922 /* This ought to be unwrapped neatly. I'll trust gcc for now */
930 /* Checksum skb data -- similar to skb_checksum */
931 static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
932 int len, unsigned long sum)
934 int start = skb_headlen(skb);
935 struct sk_buff *frag_iter;
938 /* checksum stuff in header space */
939 if ((copy = start - offset) > 0) {
942 sum = atalk_sum_partial(skb->data + offset, copy, sum);
943 if ((len -= copy) == 0)
949 /* checksum stuff in frags */
950 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
952 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
953 WARN_ON(start > offset + len);
955 end = start + skb_frag_size(frag);
956 if ((copy = end - offset) > 0) {
961 vaddr = kmap_atomic(skb_frag_page(frag));
962 sum = atalk_sum_partial(vaddr + frag->page_offset +
963 offset - start, copy, sum);
964 kunmap_atomic(vaddr);
973 skb_walk_frags(skb, frag_iter) {
976 WARN_ON(start > offset + len);
978 end = start + frag_iter->len;
979 if ((copy = end - offset) > 0) {
982 sum = atalk_sum_skb(frag_iter, offset - start,
984 if ((len -= copy) == 0)
996 static __be16 atalk_checksum(const struct sk_buff *skb, int len)
1000 /* skip header 4 bytes */
1001 sum = atalk_sum_skb(skb, 4, len-4, 0);
1003 /* Use 0xFFFF for 0. 0 itself means none */
1004 return sum ? htons((unsigned short)sum) : htons(0xFFFF);
1007 static struct proto ddp_proto = {
1009 .owner = THIS_MODULE,
1010 .obj_size = sizeof(struct atalk_sock),
1014 * Create a socket. Initialise the socket, blank the addresses
1017 static int atalk_create(struct net *net, struct socket *sock, int protocol,
1021 int rc = -ESOCKTNOSUPPORT;
1023 if (!net_eq(net, &init_net))
1024 return -EAFNOSUPPORT;
1027 * We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
1028 * and gives you the full ELAP frame. Should be handy for CAP 8)
1030 if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
1033 sk = sk_alloc(net, PF_APPLETALK, GFP_KERNEL, &ddp_proto);
1037 sock->ops = &atalk_dgram_ops;
1038 sock_init_data(sock, sk);
1040 /* Checksums on by default */
1041 sock_set_flag(sk, SOCK_ZAPPED);
1046 /* Free a socket. No work needed */
1047 static int atalk_release(struct socket *sock)
1049 struct sock *sk = sock->sk;
1057 atalk_destroy_socket(sk);
1066 * atalk_pick_and_bind_port - Pick a source port when one is not given
1067 * @sk: socket to insert into the tables
1068 * @sat: address to search for
1070 * Pick a source port when one is not given. If we can find a suitable free
1071 * one, we insert the socket into the tables using it.
1073 * This whole operation must be atomic.
1075 static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
1079 write_lock_bh(&atalk_sockets_lock);
1081 for (sat->sat_port = ATPORT_RESERVED;
1082 sat->sat_port < ATPORT_LAST;
1086 sk_for_each(s, &atalk_sockets) {
1087 struct atalk_sock *at = at_sk(s);
1089 if (at->src_net == sat->sat_addr.s_net &&
1090 at->src_node == sat->sat_addr.s_node &&
1091 at->src_port == sat->sat_port)
1095 /* Wheee, it's free, assign and insert. */
1096 __atalk_insert_socket(sk);
1097 at_sk(sk)->src_port = sat->sat_port;
1106 write_unlock_bh(&atalk_sockets_lock);
1110 static int atalk_autobind(struct sock *sk)
1112 struct atalk_sock *at = at_sk(sk);
1113 struct sockaddr_at sat;
1114 struct atalk_addr *ap = atalk_find_primary();
1115 int n = -EADDRNOTAVAIL;
1117 if (!ap || ap->s_net == htons(ATADDR_ANYNET))
1120 at->src_net = sat.sat_addr.s_net = ap->s_net;
1121 at->src_node = sat.sat_addr.s_node = ap->s_node;
1123 n = atalk_pick_and_bind_port(sk, &sat);
1125 sock_reset_flag(sk, SOCK_ZAPPED);
1130 /* Set the address 'our end' of the connection */
1131 static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1133 struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
1134 struct sock *sk = sock->sk;
1135 struct atalk_sock *at = at_sk(sk);
1138 if (!sock_flag(sk, SOCK_ZAPPED) ||
1139 addr_len != sizeof(struct sockaddr_at))
1142 if (addr->sat_family != AF_APPLETALK)
1143 return -EAFNOSUPPORT;
1146 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
1147 struct atalk_addr *ap = atalk_find_primary();
1149 err = -EADDRNOTAVAIL;
1153 at->src_net = addr->sat_addr.s_net = ap->s_net;
1154 at->src_node = addr->sat_addr.s_node = ap->s_node;
1156 err = -EADDRNOTAVAIL;
1157 if (!atalk_find_interface(addr->sat_addr.s_net,
1158 addr->sat_addr.s_node))
1161 at->src_net = addr->sat_addr.s_net;
1162 at->src_node = addr->sat_addr.s_node;
1165 if (addr->sat_port == ATADDR_ANYPORT) {
1166 err = atalk_pick_and_bind_port(sk, addr);
1171 at->src_port = addr->sat_port;
1174 if (atalk_find_or_insert_socket(sk, addr))
1178 sock_reset_flag(sk, SOCK_ZAPPED);
1185 /* Set the address we talk to */
1186 static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1187 int addr_len, int flags)
1189 struct sock *sk = sock->sk;
1190 struct atalk_sock *at = at_sk(sk);
1191 struct sockaddr_at *addr;
1194 sk->sk_state = TCP_CLOSE;
1195 sock->state = SS_UNCONNECTED;
1197 if (addr_len != sizeof(*addr))
1200 addr = (struct sockaddr_at *)uaddr;
1202 if (addr->sat_family != AF_APPLETALK)
1203 return -EAFNOSUPPORT;
1205 if (addr->sat_addr.s_node == ATADDR_BCAST &&
1206 !sock_flag(sk, SOCK_BROADCAST)) {
1208 pr_warn("atalk_connect: %s is broken and did not set SO_BROADCAST.\n",
1217 if (sock_flag(sk, SOCK_ZAPPED))
1218 if (atalk_autobind(sk) < 0)
1222 if (!atrtr_get_dev(&addr->sat_addr))
1225 at->dest_port = addr->sat_port;
1226 at->dest_net = addr->sat_addr.s_net;
1227 at->dest_node = addr->sat_addr.s_node;
1229 sock->state = SS_CONNECTED;
1230 sk->sk_state = TCP_ESTABLISHED;
1238 * Find the name of an AppleTalk socket. Just copy the right
1239 * fields into the sockaddr.
1241 static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1242 int *uaddr_len, int peer)
1244 struct sockaddr_at sat;
1245 struct sock *sk = sock->sk;
1246 struct atalk_sock *at = at_sk(sk);
1251 if (sock_flag(sk, SOCK_ZAPPED))
1252 if (atalk_autobind(sk) < 0)
1255 *uaddr_len = sizeof(struct sockaddr_at);
1256 memset(&sat, 0, sizeof(sat));
1260 if (sk->sk_state != TCP_ESTABLISHED)
1263 sat.sat_addr.s_net = at->dest_net;
1264 sat.sat_addr.s_node = at->dest_node;
1265 sat.sat_port = at->dest_port;
1267 sat.sat_addr.s_net = at->src_net;
1268 sat.sat_addr.s_node = at->src_node;
1269 sat.sat_port = at->src_port;
1273 sat.sat_family = AF_APPLETALK;
1274 memcpy(uaddr, &sat, sizeof(sat));
1281 #if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
1282 static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
1284 return skb->data[12] == 22;
1287 static int handle_ip_over_ddp(struct sk_buff *skb)
1289 struct net_device *dev = __dev_get_by_name(&init_net, "ipddp0");
1290 struct net_device_stats *stats;
1292 /* This needs to be able to handle ipddp"N" devices */
1298 skb->protocol = htons(ETH_P_IP);
1301 skb_reset_transport_header(skb);
1303 stats = netdev_priv(dev);
1304 stats->rx_packets++;
1305 stats->rx_bytes += skb->len + 13;
1306 return netif_rx(skb); /* Send the SKB up to a higher place. */
1309 /* make it easy for gcc to optimize this test out, i.e. kill the code */
1310 #define is_ip_over_ddp(skb) 0
1311 #define handle_ip_over_ddp(skb) 0
1314 static int atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
1315 struct ddpehdr *ddp, __u16 len_hops, int origlen)
1317 struct atalk_route *rt;
1318 struct atalk_addr ta;
1321 * Don't route multicast, etc., packets, or packets sent to "this
1324 if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
1328 * Can it ever happen that a packet is from a PPP iface and
1329 * needs to be broadcast onto the default network?
1331 if (dev->type == ARPHRD_PPP)
1332 printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
1333 "packet received from PPP iface\n");
1337 ta.s_net = ddp->deh_dnet;
1338 ta.s_node = ddp->deh_dnode;
1340 /* Route the packet */
1341 rt = atrtr_find(&ta);
1342 /* increment hops count */
1343 len_hops += 1 << 10;
1344 if (!rt || !(len_hops & (15 << 10)))
1347 /* FIXME: use skb->cb to be able to use shared skbs */
1350 * Route goes through another gateway, so set the target to the
1354 if (rt->flags & RTF_GATEWAY) {
1355 ta.s_net = rt->gateway.s_net;
1356 ta.s_node = rt->gateway.s_node;
1359 /* Fix up skb->len field */
1360 skb_trim(skb, min_t(unsigned int, origlen,
1361 (rt->dev->hard_header_len +
1362 ddp_dl->header_length + (len_hops & 1023))));
1364 /* FIXME: use skb->cb to be able to use shared skbs */
1365 ddp->deh_len_hops = htons(len_hops);
1368 * Send the buffer onwards
1370 * Now we must always be careful. If it's come from LocalTalk to
1371 * EtherTalk it might not fit
1373 * Order matters here: If a packet has to be copied to make a new
1374 * headroom (rare hopefully) then it won't need unsharing.
1376 * Note. ddp-> becomes invalid at the realloc.
1378 if (skb_headroom(skb) < 22) {
1379 /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
1380 struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
1384 skb = skb_unshare(skb, GFP_ATOMIC);
1387 * If the buffer didn't vanish into the lack of space bitbucket we can
1393 if (aarp_send_ddp(rt->dev, skb, &ta, NULL) == NET_XMIT_DROP)
1395 return NET_RX_SUCCESS;
1403 * atalk_rcv - Receive a packet (in skb) from device dev
1404 * @skb - packet received
1405 * @dev - network device where the packet comes from
1408 * Receive a packet (in skb) from device dev. This has come from the SNAP
1409 * decoder, and on entry skb->transport_header is the DDP header, skb->len
1410 * is the DDP header, skb->len is the DDP length. The physical headers
1411 * have been extracted. PPP should probably pass frames marked as for this
1412 * layer. [ie ARPHRD_ETHERTALK]
1414 static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
1415 struct packet_type *pt, struct net_device *orig_dev)
1417 struct ddpehdr *ddp;
1419 struct atalk_iface *atif;
1420 struct sockaddr_at tosat;
1424 if (!net_eq(dev_net(dev), &init_net))
1427 /* Don't mangle buffer if shared */
1428 if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1431 /* Size check and make sure header is contiguous */
1432 if (!pskb_may_pull(skb, sizeof(*ddp)))
1437 len_hops = ntohs(ddp->deh_len_hops);
1439 /* Trim buffer in case of stray trailing data */
1441 skb_trim(skb, min_t(unsigned int, skb->len, len_hops & 1023));
1444 * Size check to see if ddp->deh_len was crap
1445 * (Otherwise we'll detonate most spectacularly
1446 * in the middle of atalk_checksum() or recvmsg()).
1448 if (skb->len < sizeof(*ddp) || skb->len < (len_hops & 1023)) {
1449 pr_debug("AppleTalk: dropping corrupted frame (deh_len=%u, "
1450 "skb->len=%u)\n", len_hops & 1023, skb->len);
1455 * Any checksums. Note we don't do htons() on this == is assumed to be
1456 * valid for net byte orders all over the networking code...
1459 atalk_checksum(skb, len_hops & 1023) != ddp->deh_sum)
1460 /* Not a valid AppleTalk frame - dustbin time */
1463 /* Check the packet is aimed at us */
1464 if (!ddp->deh_dnet) /* Net 0 is 'this network' */
1465 atif = atalk_find_anynet(ddp->deh_dnode, dev);
1467 atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
1470 /* Not ours, so we route the packet via the correct
1473 return atalk_route_packet(skb, dev, ddp, len_hops, origlen);
1476 /* if IP over DDP is not selected this code will be optimized out */
1477 if (is_ip_over_ddp(skb))
1478 return handle_ip_over_ddp(skb);
1480 * Which socket - atalk_search_socket() looks for a *full match*
1481 * of the <net, node, port> tuple.
1483 tosat.sat_addr.s_net = ddp->deh_dnet;
1484 tosat.sat_addr.s_node = ddp->deh_dnode;
1485 tosat.sat_port = ddp->deh_dport;
1487 sock = atalk_search_socket(&tosat, atif);
1488 if (!sock) /* But not one of our sockets */
1491 /* Queue packet (standard) */
1494 if (sock_queue_rcv_skb(sock, skb) < 0)
1497 return NET_RX_SUCCESS;
1507 * Receive a LocalTalk frame. We make some demands on the caller here.
1508 * Caller must provide enough headroom on the packet to pull the short
1509 * header and append a long one.
1511 static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
1512 struct packet_type *pt, struct net_device *orig_dev)
1514 if (!net_eq(dev_net(dev), &init_net))
1517 /* Expand any short form frames */
1518 if (skb_mac_header(skb)[2] == 1) {
1519 struct ddpehdr *ddp;
1520 /* Find our address */
1521 struct atalk_addr *ap = atalk_find_dev_addr(dev);
1523 if (!ap || skb->len < sizeof(__be16) || skb->len > 1023)
1526 /* Don't mangle buffer if shared */
1527 if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1531 * The push leaves us with a ddephdr not an shdr, and
1532 * handily the port bytes in the right place preset.
1534 ddp = (struct ddpehdr *) skb_push(skb, sizeof(*ddp) - 4);
1536 /* Now fill in the long header */
1539 * These two first. The mac overlays the new source/dest
1540 * network information so we MUST copy these before
1541 * we write the network numbers !
1544 ddp->deh_dnode = skb_mac_header(skb)[0]; /* From physical header */
1545 ddp->deh_snode = skb_mac_header(skb)[1]; /* From physical header */
1547 ddp->deh_dnet = ap->s_net; /* Network number */
1548 ddp->deh_snet = ap->s_net;
1549 ddp->deh_sum = 0; /* No checksum */
1551 * Not sure about this bit...
1553 /* Non routable, so force a drop if we slip up later */
1554 ddp->deh_len_hops = htons(skb->len + (DDP_MAXHOPS << 10));
1556 skb_reset_transport_header(skb);
1558 return atalk_rcv(skb, dev, pt, orig_dev);
1564 static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
1567 struct sock *sk = sock->sk;
1568 struct atalk_sock *at = at_sk(sk);
1569 DECLARE_SOCKADDR(struct sockaddr_at *, usat, msg->msg_name);
1570 int flags = msg->msg_flags;
1572 struct sockaddr_at local_satalk, gsat;
1573 struct sk_buff *skb;
1574 struct net_device *dev;
1575 struct ddpehdr *ddp;
1577 struct atalk_route *rt;
1580 if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
1583 if (len > DDP_MAXSZ)
1589 if (sock_flag(sk, SOCK_ZAPPED))
1590 if (atalk_autobind(sk) < 0)
1594 if (msg->msg_namelen < sizeof(*usat) ||
1595 usat->sat_family != AF_APPLETALK)
1599 /* netatalk didn't implement this check */
1600 if (usat->sat_addr.s_node == ATADDR_BCAST &&
1601 !sock_flag(sk, SOCK_BROADCAST)) {
1606 if (sk->sk_state != TCP_ESTABLISHED)
1608 usat = &local_satalk;
1609 usat->sat_family = AF_APPLETALK;
1610 usat->sat_port = at->dest_port;
1611 usat->sat_addr.s_node = at->dest_node;
1612 usat->sat_addr.s_net = at->dest_net;
1615 /* Build a packet */
1616 SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
1619 size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
1621 if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
1622 rt = atrtr_find(&usat->sat_addr);
1624 struct atalk_addr at_hint;
1627 at_hint.s_net = at->src_net;
1629 rt = atrtr_find(&at_hint);
1637 SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
1638 sk, size, dev->name);
1640 size += dev->hard_header_len;
1642 skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
1648 skb_reserve(skb, ddp_dl->header_length);
1649 skb_reserve(skb, dev->hard_header_len);
1652 SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
1654 ddp = (struct ddpehdr *)skb_put(skb, sizeof(struct ddpehdr));
1655 ddp->deh_len_hops = htons(len + sizeof(*ddp));
1656 ddp->deh_dnet = usat->sat_addr.s_net;
1657 ddp->deh_snet = at->src_net;
1658 ddp->deh_dnode = usat->sat_addr.s_node;
1659 ddp->deh_snode = at->src_node;
1660 ddp->deh_dport = usat->sat_port;
1661 ddp->deh_sport = at->src_port;
1663 SOCK_DEBUG(sk, "SK %p: Copy user data (%Zd bytes).\n", sk, len);
1665 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1672 if (sk->sk_no_check == 1)
1675 ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
1678 * Loopback broadcast packets to non gateway targets (ie routes
1679 * to group we are in)
1681 if (ddp->deh_dnode == ATADDR_BCAST &&
1682 !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
1683 struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
1687 SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
1689 * If it fails it is queued/sent above in the aarp queue
1691 aarp_send_ddp(dev, skb2, &usat->sat_addr, NULL);
1695 if (dev->flags & IFF_LOOPBACK || loopback) {
1696 SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
1699 if (ddp->deh_dnode == ATADDR_BCAST) {
1700 struct atalk_addr at_lo;
1705 rt = atrtr_find(&at_lo);
1714 ddp_dl->request(ddp_dl, skb, dev->dev_addr);
1716 SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
1717 if (rt->flags & RTF_GATEWAY) {
1718 gsat.sat_addr = rt->gateway;
1723 * If it fails it is queued/sent above in the aarp queue
1725 aarp_send_ddp(dev, skb, &usat->sat_addr, NULL);
1727 SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
1734 static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
1735 size_t size, int flags)
1737 struct sock *sk = sock->sk;
1738 struct ddpehdr *ddp;
1742 struct sk_buff *skb;
1744 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1745 flags & MSG_DONTWAIT, &err);
1751 /* FIXME: use skb->cb to be able to use shared skbs */
1753 copied = ntohs(ddp->deh_len_hops) & 1023;
1755 if (sk->sk_type != SOCK_RAW) {
1756 offset = sizeof(*ddp);
1760 if (copied > size) {
1762 msg->msg_flags |= MSG_TRUNC;
1764 err = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, copied);
1766 if (!err && msg->msg_name) {
1767 DECLARE_SOCKADDR(struct sockaddr_at *, sat, msg->msg_name);
1768 sat->sat_family = AF_APPLETALK;
1769 sat->sat_port = ddp->deh_sport;
1770 sat->sat_addr.s_node = ddp->deh_snode;
1771 sat->sat_addr.s_net = ddp->deh_snet;
1772 msg->msg_namelen = sizeof(*sat);
1775 skb_free_datagram(sk, skb); /* Free the datagram. */
1779 return err ? : copied;
1784 * AppleTalk ioctl calls.
1786 static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1788 int rc = -ENOIOCTLCMD;
1789 struct sock *sk = sock->sk;
1790 void __user *argp = (void __user *)arg;
1793 /* Protocol layer */
1795 long amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
1799 rc = put_user(amount, (int __user *)argp);
1804 * These two are safe on a single CPU system as only
1805 * user tasks fiddle here
1807 struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
1811 amount = skb->len - sizeof(struct ddpehdr);
1812 rc = put_user(amount, (int __user *)argp);
1816 rc = sock_get_timestamp(sk, argp);
1819 rc = sock_get_timestampns(sk, argp);
1825 if (capable(CAP_NET_ADMIN))
1826 rc = atrtr_ioctl(cmd, argp);
1831 case SIOCGIFBRDADDR:
1832 case SIOCATALKDIFADDR:
1834 case SIOCSARP: /* proxy AARP */
1835 case SIOCDARP: /* proxy AARP */
1837 rc = atif_ioctl(cmd, argp);
1846 #ifdef CONFIG_COMPAT
1847 static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1850 * SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
1851 * cannot handle it in common code. The data we access if ifreq
1852 * here is compatible, so we can simply call the native
1855 if (cmd == SIOCATALKDIFADDR)
1856 return atalk_ioctl(sock, cmd, (unsigned long)compat_ptr(arg));
1858 return -ENOIOCTLCMD;
1863 static const struct net_proto_family atalk_family_ops = {
1864 .family = PF_APPLETALK,
1865 .create = atalk_create,
1866 .owner = THIS_MODULE,
1869 static const struct proto_ops atalk_dgram_ops = {
1870 .family = PF_APPLETALK,
1871 .owner = THIS_MODULE,
1872 .release = atalk_release,
1874 .connect = atalk_connect,
1875 .socketpair = sock_no_socketpair,
1876 .accept = sock_no_accept,
1877 .getname = atalk_getname,
1878 .poll = datagram_poll,
1879 .ioctl = atalk_ioctl,
1880 #ifdef CONFIG_COMPAT
1881 .compat_ioctl = atalk_compat_ioctl,
1883 .listen = sock_no_listen,
1884 .shutdown = sock_no_shutdown,
1885 .setsockopt = sock_no_setsockopt,
1886 .getsockopt = sock_no_getsockopt,
1887 .sendmsg = atalk_sendmsg,
1888 .recvmsg = atalk_recvmsg,
1889 .mmap = sock_no_mmap,
1890 .sendpage = sock_no_sendpage,
1893 static struct notifier_block ddp_notifier = {
1894 .notifier_call = ddp_device_event,
1897 static struct packet_type ltalk_packet_type __read_mostly = {
1898 .type = cpu_to_be16(ETH_P_LOCALTALK),
1902 static struct packet_type ppptalk_packet_type __read_mostly = {
1903 .type = cpu_to_be16(ETH_P_PPPTALK),
1907 static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
1909 /* Export symbols for use by drivers when AppleTalk is a module */
1910 EXPORT_SYMBOL(atrtr_get_dev);
1911 EXPORT_SYMBOL(atalk_find_dev_addr);
1913 static const char atalk_err_snap[] __initconst =
1914 KERN_CRIT "Unable to register DDP with SNAP.\n";
1916 /* Called by proto.c on kernel start up */
1917 static int __init atalk_init(void)
1919 int rc = proto_register(&ddp_proto, 0);
1924 (void)sock_register(&atalk_family_ops);
1925 ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
1927 printk(atalk_err_snap);
1929 dev_add_pack(<alk_packet_type);
1930 dev_add_pack(&ppptalk_packet_type);
1932 register_netdevice_notifier(&ddp_notifier);
1935 atalk_register_sysctl();
1939 module_init(atalk_init);
1942 * No explicit module reference count manipulation is needed in the
1943 * protocol. Socket layer sets module reference count for us
1944 * and interfaces reference counting is done
1945 * by the network device layer.
1947 * Ergo, before the AppleTalk module can be removed, all AppleTalk
1948 * sockets be closed from user space.
1950 static void __exit atalk_exit(void)
1952 #ifdef CONFIG_SYSCTL
1953 atalk_unregister_sysctl();
1954 #endif /* CONFIG_SYSCTL */
1956 aarp_cleanup_module(); /* General aarp clean-up. */
1957 unregister_netdevice_notifier(&ddp_notifier);
1958 dev_remove_pack(<alk_packet_type);
1959 dev_remove_pack(&ppptalk_packet_type);
1960 unregister_snap_client(ddp_dl);
1961 sock_unregister(PF_APPLETALK);
1962 proto_unregister(&ddp_proto);
1964 module_exit(atalk_exit);
1966 MODULE_LICENSE("GPL");
1967 MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
1968 MODULE_DESCRIPTION("AppleTalk 0.20\n");
1969 MODULE_ALIAS_NETPROTO(PF_APPLETALK);