2 * DDP: An implementation of the AppleTalk DDP protocol for
5 * Alan Cox <Alan.Cox@linux.org>
7 * With more than a little assistance from
9 * Wesley Craig <netatalk@umich.edu>
12 * Michael Callahan : Made routing work
13 * Wesley Craig : Fix probing to listen to a
15 * Alan Cox : Added send/recvmsg support
16 * Alan Cox : Moved at. to protinfo in
18 * Alan Cox : Added firewall hooks.
19 * Alan Cox : Supports new ARPHRD_LOOPBACK
20 * Christer Weinigel : Routing and /proc fixes.
21 * Bradford Johnson : LocalTalk.
22 * Tom Dyas : Module support.
23 * Alan Cox : Hooks for PPP (based on the
25 * Alan Cox : Posix bits
26 * Alan Cox/Mike Freeman : Possible fix to NBP problems
27 * Bradford Johnson : IP-over-DDP (experimental)
28 * Jay Schulist : Moved IP-over-DDP to its own
29 * driver file. (ipddp.c & ipddp.h)
30 * Jay Schulist : Made work as module with
31 * AppleTalk drivers, cleaned it.
32 * Rob Newberry : Added proxy AARP and AARP
33 * procfs, moved probing to AARP
36 * Michael Zuelsdorff : fix for net.0 packets. don't
37 * allow illegal ether/tokentalk
38 * port assignment. we lose a
39 * valid localtalk port as a
41 * Arnaldo C. de Melo : Cleanup, in preparation for
42 * shared skb support 8)
43 * Arnaldo C. de Melo : Move proc stuff to atalk_proc.c,
46 * This program is free software; you can redistribute it and/or
47 * modify it under the terms of the GNU General Public License
48 * as published by the Free Software Foundation; either version
49 * 2 of the License, or (at your option) any later version.
53 #include <linux/config.h>
54 #include <linux/module.h>
55 #include <linux/tcp.h>
56 #include <linux/if_arp.h>
57 #include <linux/termios.h> /* For TIOCOUTQ/INQ */
58 #include <net/datalink.h>
59 #include <net/psnap.h>
61 #include <net/route.h>
62 #include <linux/atalk.h>
64 struct datalink_proto *ddp_dl, *aarp_dl;
65 static struct proto_ops atalk_dgram_ops;
67 /**************************************************************************\
69 * Handlers for the socket list. *
71 \**************************************************************************/
73 HLIST_HEAD(atalk_sockets);
74 rwlock_t atalk_sockets_lock = RW_LOCK_UNLOCKED;
76 static inline void __atalk_insert_socket(struct sock *sk)
78 sk_add_node(sk, &atalk_sockets);
81 static inline void atalk_insert_socket(struct sock *sk)
83 write_lock_bh(&atalk_sockets_lock);
84 __atalk_insert_socket(sk);
85 write_unlock_bh(&atalk_sockets_lock);
88 static inline void atalk_remove_socket(struct sock *sk)
90 write_lock_bh(&atalk_sockets_lock);
92 write_unlock_bh(&atalk_sockets_lock);
95 static struct sock *atalk_search_socket(struct sockaddr_at *to,
96 struct atalk_iface *atif)
99 struct hlist_node *node;
101 read_lock_bh(&atalk_sockets_lock);
102 sk_for_each(s, node, &atalk_sockets) {
103 struct atalk_sock *at = at_sk(s);
105 if (to->sat_port != at->src_port)
108 if (to->sat_addr.s_net == ATADDR_ANYNET &&
109 to->sat_addr.s_node == ATADDR_BCAST &&
110 at->src_net == atif->address.s_net)
113 if (to->sat_addr.s_net == at->src_net &&
114 (to->sat_addr.s_node == at->src_node ||
115 to->sat_addr.s_node == ATADDR_BCAST ||
116 to->sat_addr.s_node == ATADDR_ANYNODE))
119 /* XXXX.0 -- we got a request for this router. make sure
120 * that the node is appropriately set. */
121 if (to->sat_addr.s_node == ATADDR_ANYNODE &&
122 to->sat_addr.s_net != ATADDR_ANYNET &&
123 atif->address.s_node == at->src_node) {
124 to->sat_addr.s_node = atif->address.s_node;
130 read_unlock_bh(&atalk_sockets_lock);
135 * atalk_find_or_insert_socket - Try to find a socket matching ADDR
136 * @sk - socket to insert in the list if it is not there already
137 * @sat - address to search for
139 * Try to find a socket matching ADDR in the socket list, if found then return
140 * it. If not, insert SK into the socket list.
142 * This entire operation must execute atomically.
144 static struct sock *atalk_find_or_insert_socket(struct sock *sk,
145 struct sockaddr_at *sat)
148 struct hlist_node *node;
149 struct atalk_sock *at;
151 write_lock_bh(&atalk_sockets_lock);
152 sk_for_each(s, node, &atalk_sockets) {
155 if (at->src_net == sat->sat_addr.s_net &&
156 at->src_node == sat->sat_addr.s_node &&
157 at->src_port == sat->sat_port)
161 __atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
163 write_unlock_bh(&atalk_sockets_lock);
167 static void atalk_destroy_timer(unsigned long data)
169 struct sock *sk = (struct sock *)data;
171 if (atomic_read(&sk->sk_wmem_alloc) ||
172 atomic_read(&sk->sk_rmem_alloc)) {
173 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
174 add_timer(&sk->sk_timer);
179 static inline void atalk_destroy_socket(struct sock *sk)
181 atalk_remove_socket(sk);
182 skb_queue_purge(&sk->sk_receive_queue);
184 if (atomic_read(&sk->sk_wmem_alloc) ||
185 atomic_read(&sk->sk_rmem_alloc)) {
186 init_timer(&sk->sk_timer);
187 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
188 sk->sk_timer.function = atalk_destroy_timer;
189 sk->sk_timer.data = (unsigned long)sk;
190 add_timer(&sk->sk_timer);
195 /**************************************************************************\
197 * Routing tables for the AppleTalk socket layer. *
199 \**************************************************************************/
201 /* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
202 struct atalk_route *atalk_routes;
203 rwlock_t atalk_routes_lock = RW_LOCK_UNLOCKED;
205 struct atalk_iface *atalk_interfaces;
206 rwlock_t atalk_interfaces_lock = RW_LOCK_UNLOCKED;
208 /* For probing devices or in a routerless network */
209 struct atalk_route atrtr_default;
211 /* AppleTalk interface control */
213 * Drop a device. Doesn't drop any of its routes - that is the caller's
214 * problem. Called when we down the interface or delete the address.
216 static void atif_drop_device(struct net_device *dev)
218 struct atalk_iface **iface = &atalk_interfaces;
219 struct atalk_iface *tmp;
221 write_lock_bh(&atalk_interfaces_lock);
222 while ((tmp = *iface) != NULL) {
223 if (tmp->dev == dev) {
227 dev->atalk_ptr = NULL;
231 write_unlock_bh(&atalk_interfaces_lock);
234 static struct atalk_iface *atif_add_device(struct net_device *dev,
235 struct atalk_addr *sa)
237 struct atalk_iface *iface = kmalloc(sizeof(*iface), GFP_KERNEL);
242 memset(iface, 0, sizeof(*iface));
245 dev->atalk_ptr = iface;
246 iface->address = *sa;
249 write_lock_bh(&atalk_interfaces_lock);
250 iface->next = atalk_interfaces;
251 atalk_interfaces = iface;
252 write_unlock_bh(&atalk_interfaces_lock);
257 /* Perform phase 2 AARP probing on our tentative address */
258 static int atif_probe_device(struct atalk_iface *atif)
260 int netrange = ntohs(atif->nets.nr_lastnet) -
261 ntohs(atif->nets.nr_firstnet) + 1;
262 int probe_net = ntohs(atif->address.s_net);
263 int probe_node = atif->address.s_node;
266 /* Offset the network we start probing with */
267 if (probe_net == ATADDR_ANYNET) {
268 probe_net = ntohs(atif->nets.nr_firstnet);
270 probe_net += jiffies % netrange;
272 if (probe_node == ATADDR_ANYNODE)
273 probe_node = jiffies & 0xFF;
275 /* Scan the networks */
276 atif->status |= ATIF_PROBE;
277 for (netct = 0; netct <= netrange; netct++) {
278 /* Sweep the available nodes from a given start */
279 atif->address.s_net = htons(probe_net);
280 for (nodect = 0; nodect < 256; nodect++) {
281 atif->address.s_node = (nodect + probe_node) & 0xFF;
282 if (atif->address.s_node > 0 &&
283 atif->address.s_node < 254) {
284 /* Probe a proposed address */
285 aarp_probe_network(atif);
287 if (!(atif->status & ATIF_PROBE_FAIL)) {
288 atif->status &= ~ATIF_PROBE;
292 atif->status &= ~ATIF_PROBE_FAIL;
295 if (probe_net > ntohs(atif->nets.nr_lastnet))
296 probe_net = ntohs(atif->nets.nr_firstnet);
298 atif->status &= ~ATIF_PROBE;
300 return -EADDRINUSE; /* Network is full... */
304 /* Perform AARP probing for a proxy address */
305 static int atif_proxy_probe_device(struct atalk_iface *atif,
306 struct atalk_addr* proxy_addr)
308 int netrange = ntohs(atif->nets.nr_lastnet) -
309 ntohs(atif->nets.nr_firstnet) + 1;
310 /* we probe the interface's network */
311 int probe_net = ntohs(atif->address.s_net);
312 int probe_node = ATADDR_ANYNODE; /* we'll take anything */
315 /* Offset the network we start probing with */
316 if (probe_net == ATADDR_ANYNET) {
317 probe_net = ntohs(atif->nets.nr_firstnet);
319 probe_net += jiffies % netrange;
322 if (probe_node == ATADDR_ANYNODE)
323 probe_node = jiffies & 0xFF;
325 /* Scan the networks */
326 for (netct = 0; netct <= netrange; netct++) {
327 /* Sweep the available nodes from a given start */
328 proxy_addr->s_net = htons(probe_net);
329 for (nodect = 0; nodect < 256; nodect++) {
330 proxy_addr->s_node = (nodect + probe_node) & 0xFF;
331 if (proxy_addr->s_node > 0 &&
332 proxy_addr->s_node < 254) {
333 /* Tell AARP to probe a proposed address */
334 int ret = aarp_proxy_probe_network(atif,
337 if (ret != -EADDRINUSE)
342 if (probe_net > ntohs(atif->nets.nr_lastnet))
343 probe_net = ntohs(atif->nets.nr_firstnet);
346 return -EADDRINUSE; /* Network is full... */
350 struct atalk_addr *atalk_find_dev_addr(struct net_device *dev)
352 struct atalk_iface *iface = dev->atalk_ptr;
353 return iface ? &iface->address : NULL;
356 static struct atalk_addr *atalk_find_primary(void)
358 struct atalk_iface *fiface = NULL;
359 struct atalk_addr *retval;
360 struct atalk_iface *iface;
363 * Return a point-to-point interface only if
364 * there is no non-ptp interface available.
366 read_lock_bh(&atalk_interfaces_lock);
367 for (iface = atalk_interfaces; iface; iface = iface->next) {
368 if (!fiface && !(iface->dev->flags & IFF_LOOPBACK))
370 if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
371 retval = &iface->address;
377 retval = &fiface->address;
378 else if (atalk_interfaces)
379 retval = &atalk_interfaces->address;
383 read_unlock_bh(&atalk_interfaces_lock);
388 * Find a match for 'any network' - ie any of our interfaces with that
389 * node number will do just nicely.
391 static struct atalk_iface *atalk_find_anynet(int node, struct net_device *dev)
393 struct atalk_iface *iface = dev->atalk_ptr;
395 if (!iface || iface->status & ATIF_PROBE)
398 if (node != ATADDR_BCAST &&
399 iface->address.s_node != node &&
400 node != ATADDR_ANYNODE)
409 /* Find a match for a specific network:node pair */
410 static struct atalk_iface *atalk_find_interface(int net, int node)
412 struct atalk_iface *iface;
414 read_lock_bh(&atalk_interfaces_lock);
415 for (iface = atalk_interfaces; iface; iface = iface->next) {
416 if ((node == ATADDR_BCAST ||
417 node == ATADDR_ANYNODE ||
418 iface->address.s_node == node) &&
419 iface->address.s_net == net &&
420 !(iface->status & ATIF_PROBE))
423 /* XXXX.0 -- net.0 returns the iface associated with net */
424 if (node == ATADDR_ANYNODE && net != ATADDR_ANYNET &&
425 ntohs(iface->nets.nr_firstnet) <= ntohs(net) &&
426 ntohs(net) <= ntohs(iface->nets.nr_lastnet))
429 read_unlock_bh(&atalk_interfaces_lock);
435 * Find a route for an AppleTalk packet. This ought to get cached in
436 * the socket (later on...). We know about host routes and the fact
437 * that a route must be direct to broadcast.
439 static struct atalk_route *atrtr_find(struct atalk_addr *target)
442 * we must search through all routes unless we find a
443 * host route, because some host routes might overlap
446 struct atalk_route *net_route = NULL;
447 struct atalk_route *r;
449 read_lock_bh(&atalk_routes_lock);
450 for (r = atalk_routes; r; r = r->next) {
451 if (!(r->flags & RTF_UP))
454 if (r->target.s_net == target->s_net) {
455 if (r->flags & RTF_HOST) {
457 * if this host route is for the target,
460 if (r->target.s_node == target->s_node)
464 * this route will work if there isn't a
465 * direct host route, so cache it
472 * if we found a network route but not a direct host
473 * route, then return it
477 else if (atrtr_default.dev)
479 else /* No route can be found */
482 read_unlock_bh(&atalk_routes_lock);
488 * Given an AppleTalk network, find the device to use. This can be
491 struct net_device *atrtr_get_dev(struct atalk_addr *sa)
493 struct atalk_route *atr = atrtr_find(sa);
494 return atr ? atr->dev : NULL;
497 /* Set up a default router */
498 static void atrtr_set_default(struct net_device *dev)
500 atrtr_default.dev = dev;
501 atrtr_default.flags = RTF_UP;
502 atrtr_default.gateway.s_net = htons(0);
503 atrtr_default.gateway.s_node = 0;
507 * Add a router. Basically make sure it looks valid and stuff the
508 * entry in the list. While it uses netranges we always set them to one
509 * entry to work like netatalk.
511 static int atrtr_create(struct rtentry *r, struct net_device *devhint)
513 struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst;
514 struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway;
515 struct atalk_route *rt;
516 struct atalk_iface *iface, *riface;
517 int retval = -EINVAL;
520 * Fixme: Raise/Lower a routing change semaphore for these
524 /* Validate the request */
525 if (ta->sat_family != AF_APPLETALK ||
526 (!devhint && ga->sat_family != AF_APPLETALK))
529 /* Now walk the routing table and make our decisions */
530 write_lock_bh(&atalk_routes_lock);
531 for (rt = atalk_routes; rt; rt = rt->next) {
532 if (r->rt_flags != rt->flags)
535 if (ta->sat_addr.s_net == rt->target.s_net) {
536 if (!(rt->flags & RTF_HOST))
538 if (ta->sat_addr.s_node == rt->target.s_node)
546 read_lock_bh(&atalk_interfaces_lock);
547 for (iface = atalk_interfaces; iface; iface = iface->next) {
549 ntohs(ga->sat_addr.s_net) >=
550 ntohs(iface->nets.nr_firstnet) &&
551 ntohs(ga->sat_addr.s_net) <=
552 ntohs(iface->nets.nr_lastnet))
555 if (ga->sat_addr.s_net == iface->address.s_net &&
556 ga->sat_addr.s_node == iface->address.s_node)
559 read_unlock_bh(&atalk_interfaces_lock);
561 retval = -ENETUNREACH;
565 devhint = riface->dev;
569 rt = kmalloc(sizeof(*rt), GFP_ATOMIC);
574 memset(rt, 0, sizeof(*rt));
576 rt->next = atalk_routes;
580 /* Fill in the routing entry */
581 rt->target = ta->sat_addr;
583 rt->flags = r->rt_flags;
584 rt->gateway = ga->sat_addr;
588 write_unlock_bh(&atalk_routes_lock);
593 /* Delete a route. Find it and discard it */
594 static int atrtr_delete(struct atalk_addr * addr)
596 struct atalk_route **r = &atalk_routes;
598 struct atalk_route *tmp;
600 write_lock_bh(&atalk_routes_lock);
601 while ((tmp = *r) != NULL) {
602 if (tmp->target.s_net == addr->s_net &&
603 (!(tmp->flags&RTF_GATEWAY) ||
604 tmp->target.s_node == addr->s_node)) {
614 write_unlock_bh(&atalk_routes_lock);
619 * Called when a device is downed. Just throw away any routes
622 void atrtr_device_down(struct net_device *dev)
624 struct atalk_route **r = &atalk_routes;
625 struct atalk_route *tmp;
627 write_lock_bh(&atalk_routes_lock);
628 while ((tmp = *r) != NULL) {
629 if (tmp->dev == dev) {
636 write_unlock_bh(&atalk_routes_lock);
638 if (atrtr_default.dev == dev)
639 atrtr_set_default(NULL);
642 /* Actually down the interface */
643 static inline void atalk_dev_down(struct net_device *dev)
645 atrtr_device_down(dev); /* Remove all routes for the device */
646 aarp_device_down(dev); /* Remove AARP entries for the device */
647 atif_drop_device(dev); /* Remove the device */
651 * A device event has occurred. Watch for devices going down and
652 * delete our use of them (iface and route).
654 static int ddp_device_event(struct notifier_block *this, unsigned long event,
657 if (event == NETDEV_DOWN)
658 /* Discard any use of this */
664 /* ioctl calls. Shouldn't even need touching */
665 /* Device configuration ioctl calls */
666 static int atif_ioctl(int cmd, void __user *arg)
668 static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
670 struct atalk_netrange *nr;
671 struct sockaddr_at *sa;
672 struct net_device *dev;
673 struct atalk_iface *atif;
676 struct rtentry rtdef;
679 if (copy_from_user(&atreq, arg, sizeof(atreq)))
682 dev = __dev_get_by_name(atreq.ifr_name);
686 sa = (struct sockaddr_at *)&atreq.ifr_addr;
687 atif = atalk_find_dev(dev);
691 if (!capable(CAP_NET_ADMIN))
693 if (sa->sat_family != AF_APPLETALK)
695 if (dev->type != ARPHRD_ETHER &&
696 dev->type != ARPHRD_LOOPBACK &&
697 dev->type != ARPHRD_LOCALTLK &&
698 dev->type != ARPHRD_PPP)
699 return -EPROTONOSUPPORT;
701 nr = (struct atalk_netrange *)&sa->sat_zero[0];
705 * if this is a point-to-point iface, and we already
706 * have an iface for this AppleTalk address, then we
707 * should not add a route
709 if ((dev->flags & IFF_POINTOPOINT) &&
710 atalk_find_interface(sa->sat_addr.s_net,
711 sa->sat_addr.s_node)) {
712 printk(KERN_DEBUG "AppleTalk: point-to-point "
713 "interface added with "
714 "existing address\n");
719 * Phase 1 is fine on LocalTalk but we don't do
720 * EtherTalk phase 1. Anyone wanting to add it go ahead.
722 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
723 return -EPROTONOSUPPORT;
724 if (sa->sat_addr.s_node == ATADDR_BCAST ||
725 sa->sat_addr.s_node == 254)
728 /* Already setting address */
729 if (atif->status & ATIF_PROBE)
732 atif->address.s_net = sa->sat_addr.s_net;
733 atif->address.s_node = sa->sat_addr.s_node;
734 atrtr_device_down(dev); /* Flush old routes */
736 atif = atif_add_device(dev, &sa->sat_addr);
743 * Check if the chosen address is used. If so we
744 * error and atalkd will try another.
747 if (!(dev->flags & IFF_LOOPBACK) &&
748 !(dev->flags & IFF_POINTOPOINT) &&
749 atif_probe_device(atif) < 0) {
750 atif_drop_device(dev);
754 /* Hey it worked - add the direct routes */
755 sa = (struct sockaddr_at *)&rtdef.rt_gateway;
756 sa->sat_family = AF_APPLETALK;
757 sa->sat_addr.s_net = atif->address.s_net;
758 sa->sat_addr.s_node = atif->address.s_node;
759 sa = (struct sockaddr_at *)&rtdef.rt_dst;
760 rtdef.rt_flags = RTF_UP;
761 sa->sat_family = AF_APPLETALK;
762 sa->sat_addr.s_node = ATADDR_ANYNODE;
763 if (dev->flags & IFF_LOOPBACK ||
764 dev->flags & IFF_POINTOPOINT)
765 rtdef.rt_flags |= RTF_HOST;
767 /* Routerless initial state */
768 if (nr->nr_firstnet == htons(0) &&
769 nr->nr_lastnet == htons(0xFFFE)) {
770 sa->sat_addr.s_net = atif->address.s_net;
771 atrtr_create(&rtdef, dev);
772 atrtr_set_default(dev);
774 limit = ntohs(nr->nr_lastnet);
775 if (limit - ntohs(nr->nr_firstnet) > 4096) {
776 printk(KERN_WARNING "Too many routes/"
781 for (ct = ntohs(nr->nr_firstnet);
783 sa->sat_addr.s_net = htons(ct);
784 atrtr_create(&rtdef, dev);
787 dev_mc_add(dev, aarp_mcast, 6, 1);
792 return -EADDRNOTAVAIL;
794 sa->sat_family = AF_APPLETALK;
795 sa->sat_addr = atif->address;
800 return -EADDRNOTAVAIL;
802 sa->sat_family = AF_APPLETALK;
803 sa->sat_addr.s_net = atif->address.s_net;
804 sa->sat_addr.s_node = ATADDR_BCAST;
807 case SIOCATALKDIFADDR:
809 if (!capable(CAP_NET_ADMIN))
811 if (sa->sat_family != AF_APPLETALK)
817 if (!capable(CAP_NET_ADMIN))
819 if (sa->sat_family != AF_APPLETALK)
822 return -EADDRNOTAVAIL;
825 * for now, we only support proxy AARP on ELAP;
826 * we should be able to do it for LocalTalk, too.
828 if (dev->type != ARPHRD_ETHER)
829 return -EPROTONOSUPPORT;
832 * atif points to the current interface on this network;
833 * we aren't concerned about its current status (at
834 * least for now), but it has all the settings about
835 * the network we're going to probe. Consequently, it
839 return -EADDRNOTAVAIL;
841 nr = (struct atalk_netrange *)&(atif->nets);
843 * Phase 1 is fine on Localtalk but we don't do
844 * Ethertalk phase 1. Anyone wanting to add it go ahead.
846 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
847 return -EPROTONOSUPPORT;
849 if (sa->sat_addr.s_node == ATADDR_BCAST ||
850 sa->sat_addr.s_node == 254)
854 * Check if the chosen address is used. If so we
855 * error and ATCP will try another.
857 if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0)
861 * We now have an address on the local network, and
862 * the AARP code will defend it for us until we take it
863 * down. We don't set up any routes right now, because
864 * ATCP will install them manually via SIOCADDRT.
869 if (!capable(CAP_NET_ADMIN))
871 if (sa->sat_family != AF_APPLETALK)
874 return -EADDRNOTAVAIL;
876 /* give to aarp module to remove proxy entry */
877 aarp_proxy_remove(atif->dev, &(sa->sat_addr));
881 return copy_to_user(arg, &atreq, sizeof(atreq)) ? -EFAULT : 0;
884 /* Routing ioctl() calls */
885 static int atrtr_ioctl(unsigned int cmd, void __user *arg)
889 if (copy_from_user(&rt, arg, sizeof(rt)))
894 if (rt.rt_dst.sa_family != AF_APPLETALK)
896 return atrtr_delete(&((struct sockaddr_at *)
897 &rt.rt_dst)->sat_addr);
900 struct net_device *dev = NULL;
903 if (copy_from_user(name, rt.rt_dev, IFNAMSIZ-1))
905 name[IFNAMSIZ-1] = '\0';
906 dev = __dev_get_by_name(name);
910 return atrtr_create(&rt, dev);
916 /**************************************************************************\
918 * Handling for system calls applied via the various interfaces to an *
919 * AppleTalk socket object. *
921 \**************************************************************************/
924 * Checksum: This is 'optional'. It's quite likely also a good
925 * candidate for assembler hackery 8)
927 static unsigned long atalk_sum_partial(const unsigned char *data,
928 int len, unsigned long sum)
930 /* This ought to be unwrapped neatly. I'll trust gcc for now */
943 /* Checksum skb data -- similar to skb_checksum */
944 static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
945 int len, unsigned long sum)
947 int start = skb_headlen(skb);
950 /* checksum stuff in header space */
951 if ( (copy = start - offset) > 0) {
954 sum = atalk_sum_partial(skb->data + offset, copy, sum);
955 if ( (len -= copy) == 0)
961 /* checksum stuff in frags */
962 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
965 BUG_TRAP(start <= offset + len);
967 end = start + skb_shinfo(skb)->frags[i].size;
968 if ((copy = end - offset) > 0) {
970 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
974 vaddr = kmap_skb_frag(frag);
975 sum = atalk_sum_partial(vaddr + frag->page_offset +
976 offset - start, copy, sum);
977 kunmap_skb_frag(vaddr);
986 if (skb_shinfo(skb)->frag_list) {
987 struct sk_buff *list = skb_shinfo(skb)->frag_list;
989 for (; list; list = list->next) {
992 BUG_TRAP(start <= offset + len);
994 end = start + list->len;
995 if ((copy = end - offset) > 0) {
998 sum = atalk_sum_skb(list, offset - start,
1000 if ((len -= copy) == 0)
1013 static unsigned short atalk_checksum(const struct sk_buff *skb, int len)
1017 /* skip header 4 bytes */
1018 sum = atalk_sum_skb(skb, 4, len-4, 0);
1020 /* Use 0xFFFF for 0. 0 itself means none */
1021 return sum ? htons((unsigned short)sum) : 0xFFFF;
1025 * Create a socket. Initialise the socket, blank the addresses
1028 static int atalk_create(struct socket *sock, int protocol)
1031 struct atalk_sock *at;
1032 int rc = -ESOCKTNOSUPPORT;
1035 * We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
1036 * and gives you the full ELAP frame. Should be handy for CAP 8)
1038 if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
1041 sk = sk_alloc(PF_APPLETALK, GFP_KERNEL, 1, NULL);
1044 at = sk->sk_protinfo = kmalloc(sizeof(*at), GFP_KERNEL);
1047 memset(at, 0, sizeof(*at));
1049 sock->ops = &atalk_dgram_ops;
1050 sock_init_data(sock, sk);
1051 sk_set_owner(sk, THIS_MODULE);
1053 /* Checksums on by default */
1062 /* Free a socket. No work needed */
1063 static int atalk_release(struct socket *sock)
1065 struct sock *sk = sock->sk;
1070 atalk_destroy_socket(sk);
1076 * atalk_pick_and_bind_port - Pick a source port when one is not given
1077 * @sk - socket to insert into the tables
1078 * @sat - address to search for
1080 * Pick a source port when one is not given. If we can find a suitable free
1081 * one, we insert the socket into the tables using it.
1083 * This whole operation must be atomic.
1085 static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
1089 write_lock_bh(&atalk_sockets_lock);
1091 for (sat->sat_port = ATPORT_RESERVED;
1092 sat->sat_port < ATPORT_LAST;
1095 struct hlist_node *node;
1097 sk_for_each(s, node, &atalk_sockets) {
1098 struct atalk_sock *at = at_sk(s);
1100 if (at->src_net == sat->sat_addr.s_net &&
1101 at->src_node == sat->sat_addr.s_node &&
1102 at->src_port == sat->sat_port)
1106 /* Wheee, it's free, assign and insert. */
1107 __atalk_insert_socket(sk);
1108 at_sk(sk)->src_port = sat->sat_port;
1117 write_unlock_bh(&atalk_sockets_lock);
1121 static int atalk_autobind(struct sock *sk)
1123 struct atalk_sock *at = at_sk(sk);
1124 struct sockaddr_at sat;
1125 struct atalk_addr *ap = atalk_find_primary();
1126 int n = -EADDRNOTAVAIL;
1128 if (!ap || ap->s_net == htons(ATADDR_ANYNET))
1131 at->src_net = sat.sat_addr.s_net = ap->s_net;
1132 at->src_node = sat.sat_addr.s_node = ap->s_node;
1134 n = atalk_pick_and_bind_port(sk, &sat);
1141 /* Set the address 'our end' of the connection */
1142 static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1144 struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
1145 struct sock *sk = sock->sk;
1146 struct atalk_sock *at = at_sk(sk);
1148 if (!sk->sk_zapped || addr_len != sizeof(struct sockaddr_at))
1151 if (addr->sat_family != AF_APPLETALK)
1152 return -EAFNOSUPPORT;
1154 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
1155 struct atalk_addr *ap = atalk_find_primary();
1158 return -EADDRNOTAVAIL;
1160 at->src_net = addr->sat_addr.s_net = ap->s_net;
1161 at->src_node = addr->sat_addr.s_node= ap->s_node;
1163 if (!atalk_find_interface(addr->sat_addr.s_net,
1164 addr->sat_addr.s_node))
1165 return -EADDRNOTAVAIL;
1167 at->src_net = addr->sat_addr.s_net;
1168 at->src_node = addr->sat_addr.s_node;
1171 if (addr->sat_port == ATADDR_ANYPORT) {
1172 int n = atalk_pick_and_bind_port(sk, addr);
1177 at->src_port = addr->sat_port;
1179 if (atalk_find_or_insert_socket(sk, addr))
1187 /* Set the address we talk to */
1188 static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1189 int addr_len, int flags)
1191 struct sock *sk = sock->sk;
1192 struct atalk_sock *at = at_sk(sk);
1193 struct sockaddr_at *addr;
1195 sk->sk_state = TCP_CLOSE;
1196 sock->state = SS_UNCONNECTED;
1198 if (addr_len != sizeof(*addr))
1201 addr = (struct sockaddr_at *)uaddr;
1203 if (addr->sat_family != AF_APPLETALK)
1204 return -EAFNOSUPPORT;
1206 if (addr->sat_addr.s_node == ATADDR_BCAST &&
1207 !sock_flag(sk, SOCK_BROADCAST)) {
1209 printk(KERN_WARNING "%s is broken and did not set "
1210 "SO_BROADCAST. It will break when 2.2 is "
1219 if (atalk_autobind(sk) < 0)
1222 if (!atrtr_get_dev(&addr->sat_addr))
1223 return -ENETUNREACH;
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;
1235 * Find the name of an AppleTalk socket. Just copy the right
1236 * fields into the sockaddr.
1238 static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1239 int *uaddr_len, int peer)
1241 struct sockaddr_at sat;
1242 struct sock *sk = sock->sk;
1243 struct atalk_sock *at = at_sk(sk);
1246 if (atalk_autobind(sk) < 0)
1249 *uaddr_len = sizeof(struct sockaddr_at);
1252 if (sk->sk_state != TCP_ESTABLISHED)
1255 sat.sat_addr.s_net = at->dest_net;
1256 sat.sat_addr.s_node = at->dest_node;
1257 sat.sat_port = at->dest_port;
1259 sat.sat_addr.s_net = at->src_net;
1260 sat.sat_addr.s_node = at->src_node;
1261 sat.sat_port = at->src_port;
1264 sat.sat_family = AF_APPLETALK;
1265 memcpy(uaddr, &sat, sizeof(sat));
1269 #if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
1270 static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
1272 return skb->data[12] == 22;
1275 static int handle_ip_over_ddp(struct sk_buff *skb)
1277 struct net_device *dev = __dev_get_by_name("ipddp0");
1278 struct net_device_stats *stats;
1280 /* This needs to be able to handle ipddp"N" devices */
1284 skb->protocol = htons(ETH_P_IP);
1287 skb->h.raw = skb->data;
1290 stats->rx_packets++;
1291 stats->rx_bytes += skb->len + 13;
1292 netif_rx(skb); /* Send the SKB up to a higher place. */
1296 /* make it easy for gcc to optimize this test out, i.e. kill the code */
1297 #define is_ip_over_ddp(skb) 0
1298 #define handle_ip_over_ddp(skb) 0
1301 static void atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
1302 struct ddpehdr *ddp, struct ddpebits *ddphv,
1305 struct atalk_route *rt;
1306 struct atalk_addr ta;
1309 * Don't route multicast, etc., packets, or packets sent to "this
1312 if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
1316 * Can it ever happen that a packet is from a PPP iface and
1317 * needs to be broadcast onto the default network?
1319 if (dev->type == ARPHRD_PPP)
1320 printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
1321 "packet received from PPP iface\n");
1325 ta.s_net = ddp->deh_dnet;
1326 ta.s_node = ddp->deh_dnode;
1328 /* Route the packet */
1329 rt = atrtr_find(&ta);
1330 if (!rt || ddphv->deh_hops == DDP_MAXHOPS)
1332 /* FIXME: use skb->cb to be able to use shared skbs */
1336 * Route goes through another gateway, so set the target to the
1340 if (rt->flags & RTF_GATEWAY) {
1341 ta.s_net = rt->gateway.s_net;
1342 ta.s_node = rt->gateway.s_node;
1345 /* Fix up skb->len field */
1346 skb_trim(skb, min_t(unsigned int, origlen,
1347 (rt->dev->hard_header_len +
1348 ddp_dl->header_length + ddphv->deh_len)));
1350 /* Mend the byte order */
1351 /* FIXME: use skb->cb to be able to use shared skbs */
1352 *((__u16 *)ddp) = ntohs(*((__u16 *)ddphv));
1355 * Send the buffer onwards
1357 * Now we must always be careful. If it's come from LocalTalk to
1358 * EtherTalk it might not fit
1360 * Order matters here: If a packet has to be copied to make a new
1361 * headroom (rare hopefully) then it won't need unsharing.
1363 * Note. ddp-> becomes invalid at the realloc.
1365 if (skb_headroom(skb) < 22) {
1366 /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
1367 struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
1373 skb = skb_unshare(skb, GFP_ATOMIC);
1376 * If the buffer didn't vanish into the lack of space bitbucket we can
1379 if (skb && aarp_send_ddp(rt->dev, skb, &ta, NULL) == -1)
1388 * atalk_rcv - Receive a packet (in skb) from device dev
1389 * @skb - packet received
1390 * @dev - network device where the packet comes from
1393 * Receive a packet (in skb) from device dev. This has come from the SNAP
1394 * decoder, and on entry skb->h.raw is the DDP header, skb->len is the DDP
1395 * header, skb->len is the DDP length. The physical headers have been
1396 * extracted. PPP should probably pass frames marked as for this layer.
1397 * [ie ARPHRD_ETHERTALK]
1399 static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
1400 struct packet_type *pt)
1402 struct ddpehdr *ddp;
1404 struct atalk_iface *atif;
1405 struct sockaddr_at tosat;
1407 struct ddpebits ddphv;
1409 /* Don't mangle buffer if shared */
1410 if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1413 /* Size check and make sure header is contiguous */
1414 if (!pskb_may_pull(skb, sizeof(*ddp)))
1420 * Fix up the length field [Ok this is horrible but otherwise
1421 * I end up with unions of bit fields and messy bit field order
1422 * compiler/endian dependencies..]
1424 *((__u16 *)&ddphv) = ntohs(*((__u16 *)ddp));
1426 /* Trim buffer in case of stray trailing data */
1428 skb_trim(skb, min_t(unsigned int, skb->len, ddphv.deh_len));
1431 * Size check to see if ddp->deh_len was crap
1432 * (Otherwise we'll detonate most spectacularly
1433 * in the middle of recvmsg()).
1435 if (skb->len < sizeof(*ddp))
1439 * Any checksums. Note we don't do htons() on this == is assumed to be
1440 * valid for net byte orders all over the networking code...
1443 atalk_checksum(skb, ddphv.deh_len) != ddp->deh_sum)
1444 /* Not a valid AppleTalk frame - dustbin time */
1447 /* Check the packet is aimed at us */
1448 if (!ddp->deh_dnet) /* Net 0 is 'this network' */
1449 atif = atalk_find_anynet(ddp->deh_dnode, dev);
1451 atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
1453 /* Not ours, so we route the packet via the correct AppleTalk iface */
1455 atalk_route_packet(skb, dev, ddp, &ddphv, origlen);
1459 /* if IP over DDP is not selected this code will be optimized out */
1460 if (is_ip_over_ddp(skb))
1461 return handle_ip_over_ddp(skb);
1463 * Which socket - atalk_search_socket() looks for a *full match*
1464 * of the <net, node, port> tuple.
1466 tosat.sat_addr.s_net = ddp->deh_dnet;
1467 tosat.sat_addr.s_node = ddp->deh_dnode;
1468 tosat.sat_port = ddp->deh_dport;
1470 sock = atalk_search_socket(&tosat, atif);
1471 if (!sock) /* But not one of our sockets */
1474 /* Queue packet (standard) */
1477 if (sock_queue_rcv_skb(sock, skb) < 0)
1487 * Receive a LocalTalk frame. We make some demands on the caller here.
1488 * Caller must provide enough headroom on the packet to pull the short
1489 * header and append a long one.
1491 static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
1492 struct packet_type *pt)
1494 /* Expand any short form frames */
1495 if (skb->mac.raw[2] == 1) {
1496 struct ddpehdr *ddp;
1497 /* Find our address */
1498 struct atalk_addr *ap = atalk_find_dev_addr(dev);
1500 if (!ap || skb->len < sizeof(struct ddpshdr))
1503 /* Don't mangle buffer if shared */
1504 if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1508 * The push leaves us with a ddephdr not an shdr, and
1509 * handily the port bytes in the right place preset.
1511 ddp = (struct ddpehdr *) skb_push(skb, sizeof(*ddp) - 4);
1513 /* Now fill in the long header */
1516 * These two first. The mac overlays the new source/dest
1517 * network information so we MUST copy these before
1518 * we write the network numbers !
1521 ddp->deh_dnode = skb->mac.raw[0]; /* From physical header */
1522 ddp->deh_snode = skb->mac.raw[1]; /* From physical header */
1524 ddp->deh_dnet = ap->s_net; /* Network number */
1525 ddp->deh_snet = ap->s_net;
1526 ddp->deh_sum = 0; /* No checksum */
1528 * Not sure about this bit...
1530 ddp->deh_len = skb->len;
1531 ddp->deh_hops = DDP_MAXHOPS; /* Non routable, so force a drop
1532 if we slip up later */
1533 /* Mend the byte order */
1534 *((__u16 *)ddp) = htons(*((__u16 *)ddp));
1536 skb->h.raw = skb->data;
1538 return atalk_rcv(skb, dev, pt);
1544 static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
1547 struct sock *sk = sock->sk;
1548 struct atalk_sock *at = at_sk(sk);
1549 struct sockaddr_at *usat = (struct sockaddr_at *)msg->msg_name;
1550 int flags = msg->msg_flags;
1552 struct sockaddr_at local_satalk, gsat;
1553 struct sk_buff *skb;
1554 struct net_device *dev;
1555 struct ddpehdr *ddp;
1557 struct atalk_route *rt;
1560 if (flags & ~(MSG_DONTWAIT|MSG_CMSG_COMPAT))
1563 if (len > DDP_MAXSZ)
1568 if (atalk_autobind(sk) < 0)
1571 if (msg->msg_namelen < sizeof(*usat) ||
1572 usat->sat_family != AF_APPLETALK)
1575 /* netatalk doesn't implement this check */
1576 if (usat->sat_addr.s_node == ATADDR_BCAST &&
1577 !sock_flag(sk, SOCK_BROADCAST)) {
1578 printk(KERN_INFO "SO_BROADCAST: Fix your netatalk as "
1579 "it will break before 2.2\n");
1585 if (sk->sk_state != TCP_ESTABLISHED)
1587 usat = &local_satalk;
1588 usat->sat_family = AF_APPLETALK;
1589 usat->sat_port = at->dest_port;
1590 usat->sat_addr.s_node = at->dest_node;
1591 usat->sat_addr.s_net = at->dest_net;
1594 /* Build a packet */
1595 SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
1598 size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
1600 if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
1601 rt = atrtr_find(&usat->sat_addr);
1603 return -ENETUNREACH;
1607 struct atalk_addr at_hint;
1610 at_hint.s_net = at->src_net;
1612 rt = atrtr_find(&at_hint);
1614 return -ENETUNREACH;
1619 SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
1620 sk, size, dev->name);
1622 size += dev->hard_header_len;
1623 skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
1628 skb_reserve(skb, ddp_dl->header_length);
1629 skb_reserve(skb, dev->hard_header_len);
1632 SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
1634 ddp = (struct ddpehdr *)skb_put(skb, sizeof(struct ddpehdr));
1637 ddp->deh_len = len + sizeof(*ddp);
1639 * Fix up the length field [Ok this is horrible but otherwise
1640 * I end up with unions of bit fields and messy bit field order
1641 * compiler/endian dependencies..
1643 *((__u16 *)ddp) = ntohs(*((__u16 *)ddp));
1645 ddp->deh_dnet = usat->sat_addr.s_net;
1646 ddp->deh_snet = at->src_net;
1647 ddp->deh_dnode = usat->sat_addr.s_node;
1648 ddp->deh_snode = at->src_node;
1649 ddp->deh_dport = usat->sat_port;
1650 ddp->deh_sport = at->src_port;
1652 SOCK_DEBUG(sk, "SK %p: Copy user data (%Zd bytes).\n", sk, len);
1654 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1660 if (sk->sk_no_check == 1)
1663 ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
1666 * Loopback broadcast packets to non gateway targets (ie routes
1667 * to group we are in)
1669 if (ddp->deh_dnode == ATADDR_BCAST &&
1670 !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
1671 struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
1675 SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
1676 if (aarp_send_ddp(dev, skb2,
1677 &usat->sat_addr, NULL) == -1)
1679 /* else queued/sent above in the aarp queue */
1683 if (dev->flags & IFF_LOOPBACK || loopback) {
1684 SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
1687 ddp_dl->request(ddp_dl, skb, dev->dev_addr);
1689 SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
1690 if (rt->flags & RTF_GATEWAY) {
1691 gsat.sat_addr = rt->gateway;
1695 if (aarp_send_ddp(dev, skb, &usat->sat_addr, NULL) == -1)
1697 /* else queued/sent above in the aarp queue */
1699 SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
1704 static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
1705 size_t size, int flags)
1707 struct sock *sk = sock->sk;
1708 struct sockaddr_at *sat = (struct sockaddr_at *)msg->msg_name;
1709 struct ddpehdr *ddp;
1712 struct ddpebits ddphv;
1713 struct sk_buff *skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1714 flags & MSG_DONTWAIT, &err);
1718 /* FIXME: use skb->cb to be able to use shared skbs */
1720 *((__u16 *)&ddphv) = ntohs(*((__u16 *)ddp));
1722 if (sk->sk_type == SOCK_RAW) {
1723 copied = ddphv.deh_len;
1724 if (copied > size) {
1726 msg->msg_flags |= MSG_TRUNC;
1729 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1731 copied = ddphv.deh_len - sizeof(*ddp);
1732 if (copied > size) {
1734 msg->msg_flags |= MSG_TRUNC;
1736 err = skb_copy_datagram_iovec(skb, sizeof(*ddp),
1737 msg->msg_iov, copied);
1742 sat->sat_family = AF_APPLETALK;
1743 sat->sat_port = ddp->deh_sport;
1744 sat->sat_addr.s_node = ddp->deh_snode;
1745 sat->sat_addr.s_net = ddp->deh_snet;
1747 msg->msg_namelen = sizeof(*sat);
1750 skb_free_datagram(sk, skb); /* Free the datagram. */
1751 return err ? : copied;
1756 * AppleTalk ioctl calls.
1758 static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1761 struct sock *sk = sock->sk;
1762 void __user *argp = (void __user *)arg;
1765 /* Protocol layer */
1767 long amount = sk->sk_sndbuf -
1768 atomic_read(&sk->sk_wmem_alloc);
1772 rc = put_user(amount, (int __user *)argp);
1777 * These two are safe on a single CPU system as only
1778 * user tasks fiddle here
1780 struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
1784 amount = skb->len - sizeof(struct ddpehdr);
1785 rc = put_user(amount, (int __user *)argp);
1789 rc = sock_get_timestamp(sk, argp);
1795 if (capable(CAP_NET_ADMIN))
1796 rc = atrtr_ioctl(cmd, argp);
1801 case SIOCGIFBRDADDR:
1802 case SIOCATALKDIFADDR:
1804 case SIOCSARP: /* proxy AARP */
1805 case SIOCDARP: /* proxy AARP */
1807 rc = atif_ioctl(cmd, argp);
1810 /* Physical layer ioctl calls */
1823 rc = dev_ioctl(cmd, argp);
1830 static struct net_proto_family atalk_family_ops = {
1831 .family = PF_APPLETALK,
1832 .create = atalk_create,
1833 .owner = THIS_MODULE,
1836 static struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
1837 .family = PF_APPLETALK,
1838 .owner = THIS_MODULE,
1839 .release = atalk_release,
1841 .connect = atalk_connect,
1842 .socketpair = sock_no_socketpair,
1843 .accept = sock_no_accept,
1844 .getname = atalk_getname,
1845 .poll = datagram_poll,
1846 .ioctl = atalk_ioctl,
1847 .listen = sock_no_listen,
1848 .shutdown = sock_no_shutdown,
1849 .setsockopt = sock_no_setsockopt,
1850 .getsockopt = sock_no_getsockopt,
1851 .sendmsg = atalk_sendmsg,
1852 .recvmsg = atalk_recvmsg,
1853 .mmap = sock_no_mmap,
1854 .sendpage = sock_no_sendpage,
1857 #include <linux/smp_lock.h>
1858 SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
1860 static struct notifier_block ddp_notifier = {
1861 .notifier_call = ddp_device_event,
1864 struct packet_type ltalk_packet_type = {
1865 .type = __constant_htons(ETH_P_LOCALTALK),
1869 struct packet_type ppptalk_packet_type = {
1870 .type = __constant_htons(ETH_P_PPPTALK),
1874 static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
1876 /* Export symbols for use by drivers when AppleTalk is a module */
1877 EXPORT_SYMBOL(aarp_send_ddp);
1878 EXPORT_SYMBOL(atrtr_get_dev);
1879 EXPORT_SYMBOL(atalk_find_dev_addr);
1881 static char atalk_err_snap[] __initdata =
1882 KERN_CRIT "Unable to register DDP with SNAP.\n";
1884 /* Called by proto.c on kernel start up */
1885 static int __init atalk_init(void)
1887 (void)sock_register(&atalk_family_ops);
1888 ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
1890 printk(atalk_err_snap);
1892 dev_add_pack(<alk_packet_type);
1893 dev_add_pack(&ppptalk_packet_type);
1895 register_netdevice_notifier(&ddp_notifier);
1898 atalk_register_sysctl();
1901 module_init(atalk_init);
1904 * No explicit module reference count manipulation is needed in the
1905 * protocol. Socket layer sets module reference count for us
1906 * and interfaces reference counting is done
1907 * by the network device layer.
1909 * Ergo, before the AppleTalk module can be removed, all AppleTalk
1910 * sockets be closed from user space.
1912 static void __exit atalk_exit(void)
1914 #ifdef CONFIG_SYSCTL
1915 atalk_unregister_sysctl();
1916 #endif /* CONFIG_SYSCTL */
1918 aarp_cleanup_module(); /* General aarp clean-up. */
1919 unregister_netdevice_notifier(&ddp_notifier);
1920 dev_remove_pack(<alk_packet_type);
1921 dev_remove_pack(&ppptalk_packet_type);
1922 unregister_snap_client(ddp_dl);
1923 sock_unregister(PF_APPLETALK);
1925 module_exit(atalk_exit);
1927 MODULE_LICENSE("GPL");
1928 MODULE_AUTHOR("Alan Cox <Alan.Cox@linux.org>");
1929 MODULE_DESCRIPTION("AppleTalk 0.20\n");
1930 MODULE_ALIAS_NETPROTO(PF_APPLETALK);