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 extern void aarp_cleanup_module(void);
66 extern void aarp_probe_network(struct atalk_iface *atif);
67 extern int aarp_proxy_probe_network(struct atalk_iface *atif,
68 struct atalk_addr *sa);
69 extern void aarp_proxy_remove(struct net_device *dev, struct atalk_addr *sa);
71 extern void atalk_register_sysctl(void);
72 extern void atalk_unregister_sysctl(void);
74 struct datalink_proto *ddp_dl, *aarp_dl;
75 static struct proto_ops atalk_dgram_ops;
77 /**************************************************************************\
79 * Handlers for the socket list. *
81 \**************************************************************************/
83 HLIST_HEAD(atalk_sockets);
84 rwlock_t atalk_sockets_lock = RW_LOCK_UNLOCKED;
86 static inline void __atalk_insert_socket(struct sock *sk)
88 sk_add_node(sk, &atalk_sockets);
91 static inline void atalk_insert_socket(struct sock *sk)
93 write_lock_bh(&atalk_sockets_lock);
94 __atalk_insert_socket(sk);
95 write_unlock_bh(&atalk_sockets_lock);
98 static inline void atalk_remove_socket(struct sock *sk)
100 write_lock_bh(&atalk_sockets_lock);
101 sk_del_node_init(sk);
102 write_unlock_bh(&atalk_sockets_lock);
105 static struct sock *atalk_search_socket(struct sockaddr_at *to,
106 struct atalk_iface *atif)
109 struct hlist_node *node;
111 read_lock_bh(&atalk_sockets_lock);
112 sk_for_each(s, node, &atalk_sockets) {
113 struct atalk_sock *at = at_sk(s);
115 if (to->sat_port != at->src_port)
118 if (to->sat_addr.s_net == ATADDR_ANYNET &&
119 to->sat_addr.s_node == ATADDR_BCAST &&
120 at->src_net == atif->address.s_net)
123 if (to->sat_addr.s_net == at->src_net &&
124 (to->sat_addr.s_node == at->src_node ||
125 to->sat_addr.s_node == ATADDR_BCAST ||
126 to->sat_addr.s_node == ATADDR_ANYNODE))
129 /* XXXX.0 -- we got a request for this router. make sure
130 * that the node is appropriately set. */
131 if (to->sat_addr.s_node == ATADDR_ANYNODE &&
132 to->sat_addr.s_net != ATADDR_ANYNET &&
133 atif->address.s_node == at->src_node) {
134 to->sat_addr.s_node = atif->address.s_node;
140 read_unlock_bh(&atalk_sockets_lock);
145 * atalk_find_or_insert_socket - Try to find a socket matching ADDR
146 * @sk - socket to insert in the list if it is not there already
147 * @sat - address to search for
149 * Try to find a socket matching ADDR in the socket list, if found then return
150 * it. If not, insert SK into the socket list.
152 * This entire operation must execute atomically.
154 static struct sock *atalk_find_or_insert_socket(struct sock *sk,
155 struct sockaddr_at *sat)
158 struct hlist_node *node;
159 struct atalk_sock *at;
161 write_lock_bh(&atalk_sockets_lock);
162 sk_for_each(s, node, &atalk_sockets) {
165 if (at->src_net == sat->sat_addr.s_net &&
166 at->src_node == sat->sat_addr.s_node &&
167 at->src_port == sat->sat_port)
171 __atalk_insert_socket(sk); /* Wheee, it's free, assign and insert. */
173 write_unlock_bh(&atalk_sockets_lock);
177 static void atalk_destroy_timer(unsigned long data)
179 struct sock *sk = (struct sock *)data;
181 if (atomic_read(&sk->sk_wmem_alloc) ||
182 atomic_read(&sk->sk_rmem_alloc)) {
183 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
184 add_timer(&sk->sk_timer);
189 static inline void atalk_destroy_socket(struct sock *sk)
191 atalk_remove_socket(sk);
192 skb_queue_purge(&sk->sk_receive_queue);
194 if (atomic_read(&sk->sk_wmem_alloc) ||
195 atomic_read(&sk->sk_rmem_alloc)) {
196 init_timer(&sk->sk_timer);
197 sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
198 sk->sk_timer.function = atalk_destroy_timer;
199 sk->sk_timer.data = (unsigned long)sk;
200 add_timer(&sk->sk_timer);
205 /**************************************************************************\
207 * Routing tables for the AppleTalk socket layer. *
209 \**************************************************************************/
211 /* Anti-deadlock ordering is atalk_routes_lock --> iface_lock -DaveM */
212 struct atalk_route *atalk_routes;
213 rwlock_t atalk_routes_lock = RW_LOCK_UNLOCKED;
215 struct atalk_iface *atalk_interfaces;
216 rwlock_t atalk_interfaces_lock = RW_LOCK_UNLOCKED;
218 /* For probing devices or in a routerless network */
219 struct atalk_route atrtr_default;
221 /* AppleTalk interface control */
223 * Drop a device. Doesn't drop any of its routes - that is the caller's
224 * problem. Called when we down the interface or delete the address.
226 static void atif_drop_device(struct net_device *dev)
228 struct atalk_iface **iface = &atalk_interfaces;
229 struct atalk_iface *tmp;
231 write_lock_bh(&atalk_interfaces_lock);
232 while ((tmp = *iface) != NULL) {
233 if (tmp->dev == dev) {
237 dev->atalk_ptr = NULL;
241 write_unlock_bh(&atalk_interfaces_lock);
244 static struct atalk_iface *atif_add_device(struct net_device *dev,
245 struct atalk_addr *sa)
247 struct atalk_iface *iface = kmalloc(sizeof(*iface), GFP_KERNEL);
252 memset(iface, 0, sizeof(*iface));
255 dev->atalk_ptr = iface;
256 iface->address = *sa;
259 write_lock_bh(&atalk_interfaces_lock);
260 iface->next = atalk_interfaces;
261 atalk_interfaces = iface;
262 write_unlock_bh(&atalk_interfaces_lock);
267 /* Perform phase 2 AARP probing on our tentative address */
268 static int atif_probe_device(struct atalk_iface *atif)
270 int netrange = ntohs(atif->nets.nr_lastnet) -
271 ntohs(atif->nets.nr_firstnet) + 1;
272 int probe_net = ntohs(atif->address.s_net);
273 int probe_node = atif->address.s_node;
276 /* Offset the network we start probing with */
277 if (probe_net == ATADDR_ANYNET) {
278 probe_net = ntohs(atif->nets.nr_firstnet);
280 probe_net += jiffies % netrange;
282 if (probe_node == ATADDR_ANYNODE)
283 probe_node = jiffies & 0xFF;
285 /* Scan the networks */
286 atif->status |= ATIF_PROBE;
287 for (netct = 0; netct <= netrange; netct++) {
288 /* Sweep the available nodes from a given start */
289 atif->address.s_net = htons(probe_net);
290 for (nodect = 0; nodect < 256; nodect++) {
291 atif->address.s_node = (nodect + probe_node) & 0xFF;
292 if (atif->address.s_node > 0 &&
293 atif->address.s_node < 254) {
294 /* Probe a proposed address */
295 aarp_probe_network(atif);
297 if (!(atif->status & ATIF_PROBE_FAIL)) {
298 atif->status &= ~ATIF_PROBE;
302 atif->status &= ~ATIF_PROBE_FAIL;
305 if (probe_net > ntohs(atif->nets.nr_lastnet))
306 probe_net = ntohs(atif->nets.nr_firstnet);
308 atif->status &= ~ATIF_PROBE;
310 return -EADDRINUSE; /* Network is full... */
314 /* Perform AARP probing for a proxy address */
315 static int atif_proxy_probe_device(struct atalk_iface *atif,
316 struct atalk_addr* proxy_addr)
318 int netrange = ntohs(atif->nets.nr_lastnet) -
319 ntohs(atif->nets.nr_firstnet) + 1;
320 /* we probe the interface's network */
321 int probe_net = ntohs(atif->address.s_net);
322 int probe_node = ATADDR_ANYNODE; /* we'll take anything */
325 /* Offset the network we start probing with */
326 if (probe_net == ATADDR_ANYNET) {
327 probe_net = ntohs(atif->nets.nr_firstnet);
329 probe_net += jiffies % netrange;
332 if (probe_node == ATADDR_ANYNODE)
333 probe_node = jiffies & 0xFF;
335 /* Scan the networks */
336 for (netct = 0; netct <= netrange; netct++) {
337 /* Sweep the available nodes from a given start */
338 proxy_addr->s_net = htons(probe_net);
339 for (nodect = 0; nodect < 256; nodect++) {
340 proxy_addr->s_node = (nodect + probe_node) & 0xFF;
341 if (proxy_addr->s_node > 0 &&
342 proxy_addr->s_node < 254) {
343 /* Tell AARP to probe a proposed address */
344 int ret = aarp_proxy_probe_network(atif,
347 if (ret != -EADDRINUSE)
352 if (probe_net > ntohs(atif->nets.nr_lastnet))
353 probe_net = ntohs(atif->nets.nr_firstnet);
356 return -EADDRINUSE; /* Network is full... */
360 struct atalk_addr *atalk_find_dev_addr(struct net_device *dev)
362 struct atalk_iface *iface = dev->atalk_ptr;
363 return iface ? &iface->address : NULL;
366 static struct atalk_addr *atalk_find_primary(void)
368 struct atalk_iface *fiface = NULL;
369 struct atalk_addr *retval;
370 struct atalk_iface *iface;
373 * Return a point-to-point interface only if
374 * there is no non-ptp interface available.
376 read_lock_bh(&atalk_interfaces_lock);
377 for (iface = atalk_interfaces; iface; iface = iface->next) {
378 if (!fiface && !(iface->dev->flags & IFF_LOOPBACK))
380 if (!(iface->dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
381 retval = &iface->address;
387 retval = &fiface->address;
388 else if (atalk_interfaces)
389 retval = &atalk_interfaces->address;
393 read_unlock_bh(&atalk_interfaces_lock);
398 * Find a match for 'any network' - ie any of our interfaces with that
399 * node number will do just nicely.
401 static struct atalk_iface *atalk_find_anynet(int node, struct net_device *dev)
403 struct atalk_iface *iface = dev->atalk_ptr;
405 if (!iface || iface->status & ATIF_PROBE)
408 if (node != ATADDR_BCAST &&
409 iface->address.s_node != node &&
410 node != ATADDR_ANYNODE)
419 /* Find a match for a specific network:node pair */
420 static struct atalk_iface *atalk_find_interface(int net, int node)
422 struct atalk_iface *iface;
424 read_lock_bh(&atalk_interfaces_lock);
425 for (iface = atalk_interfaces; iface; iface = iface->next) {
426 if ((node == ATADDR_BCAST ||
427 node == ATADDR_ANYNODE ||
428 iface->address.s_node == node) &&
429 iface->address.s_net == net &&
430 !(iface->status & ATIF_PROBE))
433 /* XXXX.0 -- net.0 returns the iface associated with net */
434 if (node == ATADDR_ANYNODE && net != ATADDR_ANYNET &&
435 ntohs(iface->nets.nr_firstnet) <= ntohs(net) &&
436 ntohs(net) <= ntohs(iface->nets.nr_lastnet))
439 read_unlock_bh(&atalk_interfaces_lock);
445 * Find a route for an AppleTalk packet. This ought to get cached in
446 * the socket (later on...). We know about host routes and the fact
447 * that a route must be direct to broadcast.
449 static struct atalk_route *atrtr_find(struct atalk_addr *target)
452 * we must search through all routes unless we find a
453 * host route, because some host routes might overlap
456 struct atalk_route *net_route = NULL;
457 struct atalk_route *r;
459 read_lock_bh(&atalk_routes_lock);
460 for (r = atalk_routes; r; r = r->next) {
461 if (!(r->flags & RTF_UP))
464 if (r->target.s_net == target->s_net) {
465 if (r->flags & RTF_HOST) {
467 * if this host route is for the target,
470 if (r->target.s_node == target->s_node)
474 * this route will work if there isn't a
475 * direct host route, so cache it
482 * if we found a network route but not a direct host
483 * route, then return it
487 else if (atrtr_default.dev)
489 else /* No route can be found */
492 read_unlock_bh(&atalk_routes_lock);
498 * Given an AppleTalk network, find the device to use. This can be
501 struct net_device *atrtr_get_dev(struct atalk_addr *sa)
503 struct atalk_route *atr = atrtr_find(sa);
504 return atr ? atr->dev : NULL;
507 /* Set up a default router */
508 static void atrtr_set_default(struct net_device *dev)
510 atrtr_default.dev = dev;
511 atrtr_default.flags = RTF_UP;
512 atrtr_default.gateway.s_net = htons(0);
513 atrtr_default.gateway.s_node = 0;
517 * Add a router. Basically make sure it looks valid and stuff the
518 * entry in the list. While it uses netranges we always set them to one
519 * entry to work like netatalk.
521 static int atrtr_create(struct rtentry *r, struct net_device *devhint)
523 struct sockaddr_at *ta = (struct sockaddr_at *)&r->rt_dst;
524 struct sockaddr_at *ga = (struct sockaddr_at *)&r->rt_gateway;
525 struct atalk_route *rt;
526 struct atalk_iface *iface, *riface;
527 int retval = -EINVAL;
530 * Fixme: Raise/Lower a routing change semaphore for these
534 /* Validate the request */
535 if (ta->sat_family != AF_APPLETALK ||
536 (!devhint && ga->sat_family != AF_APPLETALK))
539 /* Now walk the routing table and make our decisions */
540 write_lock_bh(&atalk_routes_lock);
541 for (rt = atalk_routes; rt; rt = rt->next) {
542 if (r->rt_flags != rt->flags)
545 if (ta->sat_addr.s_net == rt->target.s_net) {
546 if (!(rt->flags & RTF_HOST))
548 if (ta->sat_addr.s_node == rt->target.s_node)
556 read_lock_bh(&atalk_interfaces_lock);
557 for (iface = atalk_interfaces; iface; iface = iface->next) {
559 ntohs(ga->sat_addr.s_net) >=
560 ntohs(iface->nets.nr_firstnet) &&
561 ntohs(ga->sat_addr.s_net) <=
562 ntohs(iface->nets.nr_lastnet))
565 if (ga->sat_addr.s_net == iface->address.s_net &&
566 ga->sat_addr.s_node == iface->address.s_node)
569 read_unlock_bh(&atalk_interfaces_lock);
571 retval = -ENETUNREACH;
575 devhint = riface->dev;
579 rt = kmalloc(sizeof(*rt), GFP_ATOMIC);
584 memset(rt, 0, sizeof(*rt));
586 rt->next = atalk_routes;
590 /* Fill in the routing entry */
591 rt->target = ta->sat_addr;
593 rt->flags = r->rt_flags;
594 rt->gateway = ga->sat_addr;
598 write_unlock_bh(&atalk_routes_lock);
603 /* Delete a route. Find it and discard it */
604 static int atrtr_delete(struct atalk_addr * addr)
606 struct atalk_route **r = &atalk_routes;
608 struct atalk_route *tmp;
610 write_lock_bh(&atalk_routes_lock);
611 while ((tmp = *r) != NULL) {
612 if (tmp->target.s_net == addr->s_net &&
613 (!(tmp->flags&RTF_GATEWAY) ||
614 tmp->target.s_node == addr->s_node)) {
624 write_unlock_bh(&atalk_routes_lock);
629 * Called when a device is downed. Just throw away any routes
632 void atrtr_device_down(struct net_device *dev)
634 struct atalk_route **r = &atalk_routes;
635 struct atalk_route *tmp;
637 write_lock_bh(&atalk_routes_lock);
638 while ((tmp = *r) != NULL) {
639 if (tmp->dev == dev) {
646 write_unlock_bh(&atalk_routes_lock);
648 if (atrtr_default.dev == dev)
649 atrtr_set_default(NULL);
652 /* Actually down the interface */
653 static inline void atalk_dev_down(struct net_device *dev)
655 atrtr_device_down(dev); /* Remove all routes for the device */
656 aarp_device_down(dev); /* Remove AARP entries for the device */
657 atif_drop_device(dev); /* Remove the device */
661 * A device event has occurred. Watch for devices going down and
662 * delete our use of them (iface and route).
664 static int ddp_device_event(struct notifier_block *this, unsigned long event,
667 if (event == NETDEV_DOWN)
668 /* Discard any use of this */
674 /* ioctl calls. Shouldn't even need touching */
675 /* Device configuration ioctl calls */
676 static int atif_ioctl(int cmd, void *arg)
678 static char aarp_mcast[6] = { 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
680 struct atalk_netrange *nr;
681 struct sockaddr_at *sa;
682 struct net_device *dev;
683 struct atalk_iface *atif;
686 struct rtentry rtdef;
689 if (copy_from_user(&atreq, arg, sizeof(atreq)))
692 dev = __dev_get_by_name(atreq.ifr_name);
696 sa = (struct sockaddr_at *)&atreq.ifr_addr;
697 atif = atalk_find_dev(dev);
701 if (!capable(CAP_NET_ADMIN))
703 if (sa->sat_family != AF_APPLETALK)
705 if (dev->type != ARPHRD_ETHER &&
706 dev->type != ARPHRD_LOOPBACK &&
707 dev->type != ARPHRD_LOCALTLK &&
708 dev->type != ARPHRD_PPP)
709 return -EPROTONOSUPPORT;
711 nr = (struct atalk_netrange *)&sa->sat_zero[0];
715 * if this is a point-to-point iface, and we already
716 * have an iface for this AppleTalk address, then we
717 * should not add a route
719 if ((dev->flags & IFF_POINTOPOINT) &&
720 atalk_find_interface(sa->sat_addr.s_net,
721 sa->sat_addr.s_node)) {
722 printk(KERN_DEBUG "AppleTalk: point-to-point "
723 "interface added with "
724 "existing address\n");
729 * Phase 1 is fine on LocalTalk but we don't do
730 * EtherTalk phase 1. Anyone wanting to add it go ahead.
732 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
733 return -EPROTONOSUPPORT;
734 if (sa->sat_addr.s_node == ATADDR_BCAST ||
735 sa->sat_addr.s_node == 254)
738 /* Already setting address */
739 if (atif->status & ATIF_PROBE)
742 atif->address.s_net = sa->sat_addr.s_net;
743 atif->address.s_node = sa->sat_addr.s_node;
744 atrtr_device_down(dev); /* Flush old routes */
746 atif = atif_add_device(dev, &sa->sat_addr);
753 * Check if the chosen address is used. If so we
754 * error and atalkd will try another.
757 if (!(dev->flags & IFF_LOOPBACK) &&
758 !(dev->flags & IFF_POINTOPOINT) &&
759 atif_probe_device(atif) < 0) {
760 atif_drop_device(dev);
764 /* Hey it worked - add the direct routes */
765 sa = (struct sockaddr_at *)&rtdef.rt_gateway;
766 sa->sat_family = AF_APPLETALK;
767 sa->sat_addr.s_net = atif->address.s_net;
768 sa->sat_addr.s_node = atif->address.s_node;
769 sa = (struct sockaddr_at *)&rtdef.rt_dst;
770 rtdef.rt_flags = RTF_UP;
771 sa->sat_family = AF_APPLETALK;
772 sa->sat_addr.s_node = ATADDR_ANYNODE;
773 if (dev->flags & IFF_LOOPBACK ||
774 dev->flags & IFF_POINTOPOINT)
775 rtdef.rt_flags |= RTF_HOST;
777 /* Routerless initial state */
778 if (nr->nr_firstnet == htons(0) &&
779 nr->nr_lastnet == htons(0xFFFE)) {
780 sa->sat_addr.s_net = atif->address.s_net;
781 atrtr_create(&rtdef, dev);
782 atrtr_set_default(dev);
784 limit = ntohs(nr->nr_lastnet);
785 if (limit - ntohs(nr->nr_firstnet) > 4096) {
786 printk(KERN_WARNING "Too many routes/"
791 for (ct = ntohs(nr->nr_firstnet);
793 sa->sat_addr.s_net = htons(ct);
794 atrtr_create(&rtdef, dev);
797 dev_mc_add(dev, aarp_mcast, 6, 1);
802 return -EADDRNOTAVAIL;
804 sa->sat_family = AF_APPLETALK;
805 sa->sat_addr = atif->address;
810 return -EADDRNOTAVAIL;
812 sa->sat_family = AF_APPLETALK;
813 sa->sat_addr.s_net = atif->address.s_net;
814 sa->sat_addr.s_node = ATADDR_BCAST;
817 case SIOCATALKDIFADDR:
819 if (!capable(CAP_NET_ADMIN))
821 if (sa->sat_family != AF_APPLETALK)
827 if (!capable(CAP_NET_ADMIN))
829 if (sa->sat_family != AF_APPLETALK)
832 return -EADDRNOTAVAIL;
835 * for now, we only support proxy AARP on ELAP;
836 * we should be able to do it for LocalTalk, too.
838 if (dev->type != ARPHRD_ETHER)
839 return -EPROTONOSUPPORT;
842 * atif points to the current interface on this network;
843 * we aren't concerned about its current status (at
844 * least for now), but it has all the settings about
845 * the network we're going to probe. Consequently, it
849 return -EADDRNOTAVAIL;
851 nr = (struct atalk_netrange *)&(atif->nets);
853 * Phase 1 is fine on Localtalk but we don't do
854 * Ethertalk phase 1. Anyone wanting to add it go ahead.
856 if (dev->type == ARPHRD_ETHER && nr->nr_phase != 2)
857 return -EPROTONOSUPPORT;
859 if (sa->sat_addr.s_node == ATADDR_BCAST ||
860 sa->sat_addr.s_node == 254)
864 * Check if the chosen address is used. If so we
865 * error and ATCP will try another.
867 if (atif_proxy_probe_device(atif, &(sa->sat_addr)) < 0)
871 * We now have an address on the local network, and
872 * the AARP code will defend it for us until we take it
873 * down. We don't set up any routes right now, because
874 * ATCP will install them manually via SIOCADDRT.
879 if (!capable(CAP_NET_ADMIN))
881 if (sa->sat_family != AF_APPLETALK)
884 return -EADDRNOTAVAIL;
886 /* give to aarp module to remove proxy entry */
887 aarp_proxy_remove(atif->dev, &(sa->sat_addr));
891 return copy_to_user(arg, &atreq, sizeof(atreq)) ? -EFAULT : 0;
894 /* Routing ioctl() calls */
895 static int atrtr_ioctl(unsigned int cmd, void *arg)
899 if (copy_from_user(&rt, arg, sizeof(rt)))
904 if (rt.rt_dst.sa_family != AF_APPLETALK)
906 return atrtr_delete(&((struct sockaddr_at *)
907 &rt.rt_dst)->sat_addr);
910 struct net_device *dev = NULL;
912 * FIXME: the name of the device is still in user
916 dev = __dev_get_by_name(rt.rt_dev);
920 return atrtr_create(&rt, dev);
926 /**************************************************************************\
928 * Handling for system calls applied via the various interfaces to an *
929 * AppleTalk socket object. *
931 \**************************************************************************/
934 * Checksum: This is 'optional'. It's quite likely also a good
935 * candidate for assembler hackery 8)
937 static unsigned long atalk_sum_partial(const unsigned char *data,
938 int len, unsigned long sum)
940 /* This ought to be unwrapped neatly. I'll trust gcc for now */
953 /* Checksum skb data -- similar to skb_checksum */
954 static unsigned long atalk_sum_skb(const struct sk_buff *skb, int offset,
955 int len, unsigned long sum)
957 int start = skb_headlen(skb);
960 /* checksum stuff in header space */
961 if ( (copy = start - offset) > 0) {
964 sum = atalk_sum_partial(skb->data + offset, copy, sum);
965 if ( (len -= copy) == 0)
971 /* checksum stuff in frags */
972 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
975 BUG_TRAP(start <= offset + len);
977 end = start + skb_shinfo(skb)->frags[i].size;
978 if ((copy = end - offset) > 0) {
980 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
984 vaddr = kmap_skb_frag(frag);
985 sum = atalk_sum_partial(vaddr + frag->page_offset +
986 offset - start, copy, sum);
987 kunmap_skb_frag(vaddr);
996 if (skb_shinfo(skb)->frag_list) {
997 struct sk_buff *list = skb_shinfo(skb)->frag_list;
999 for (; list; list = list->next) {
1002 BUG_TRAP(start <= offset + len);
1004 end = start + list->len;
1005 if ((copy = end - offset) > 0) {
1008 sum = atalk_sum_skb(list, offset - start,
1010 if ((len -= copy) == 0)
1023 static unsigned short atalk_checksum(const struct sk_buff *skb, int len)
1027 /* skip header 4 bytes */
1028 sum = atalk_sum_skb(skb, 4, len-4, 0);
1030 /* Use 0xFFFF for 0. 0 itself means none */
1031 return sum ? htons((unsigned short)sum) : 0xFFFF;
1035 * Create a socket. Initialise the socket, blank the addresses
1038 static int atalk_create(struct socket *sock, int protocol)
1041 struct atalk_sock *at;
1042 int rc = -ESOCKTNOSUPPORT;
1045 * We permit SOCK_DGRAM and RAW is an extension. It is trivial to do
1046 * and gives you the full ELAP frame. Should be handy for CAP 8)
1048 if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
1051 sk = sk_alloc(PF_APPLETALK, GFP_KERNEL, 1, NULL);
1054 at = sk->sk_protinfo = kmalloc(sizeof(*at), GFP_KERNEL);
1057 memset(at, 0, sizeof(*at));
1059 sock->ops = &atalk_dgram_ops;
1060 sock_init_data(sock, sk);
1061 sk_set_owner(sk, THIS_MODULE);
1063 /* Checksums on by default */
1072 /* Free a socket. No work needed */
1073 static int atalk_release(struct socket *sock)
1075 struct sock *sk = sock->sk;
1080 atalk_destroy_socket(sk);
1086 * atalk_pick_and_bind_port - Pick a source port when one is not given
1087 * @sk - socket to insert into the tables
1088 * @sat - address to search for
1090 * Pick a source port when one is not given. If we can find a suitable free
1091 * one, we insert the socket into the tables using it.
1093 * This whole operation must be atomic.
1095 static int atalk_pick_and_bind_port(struct sock *sk, struct sockaddr_at *sat)
1099 write_lock_bh(&atalk_sockets_lock);
1101 for (sat->sat_port = ATPORT_RESERVED;
1102 sat->sat_port < ATPORT_LAST;
1105 struct hlist_node *node;
1107 sk_for_each(s, node, &atalk_sockets) {
1108 struct atalk_sock *at = at_sk(s);
1110 if (at->src_net == sat->sat_addr.s_net &&
1111 at->src_node == sat->sat_addr.s_node &&
1112 at->src_port == sat->sat_port)
1116 /* Wheee, it's free, assign and insert. */
1117 __atalk_insert_socket(sk);
1118 at_sk(sk)->src_port = sat->sat_port;
1127 write_unlock_bh(&atalk_sockets_lock);
1131 static int atalk_autobind(struct sock *sk)
1133 struct atalk_sock *at = at_sk(sk);
1134 struct sockaddr_at sat;
1135 struct atalk_addr *ap = atalk_find_primary();
1136 int n = -EADDRNOTAVAIL;
1138 if (!ap || ap->s_net == htons(ATADDR_ANYNET))
1141 at->src_net = sat.sat_addr.s_net = ap->s_net;
1142 at->src_node = sat.sat_addr.s_node = ap->s_node;
1144 n = atalk_pick_and_bind_port(sk, &sat);
1151 /* Set the address 'our end' of the connection */
1152 static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1154 struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
1155 struct sock *sk = sock->sk;
1156 struct atalk_sock *at = at_sk(sk);
1158 if (!sk->sk_zapped || addr_len != sizeof(struct sockaddr_at))
1161 if (addr->sat_family != AF_APPLETALK)
1162 return -EAFNOSUPPORT;
1164 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
1165 struct atalk_addr *ap = atalk_find_primary();
1168 return -EADDRNOTAVAIL;
1170 at->src_net = addr->sat_addr.s_net = ap->s_net;
1171 at->src_node = addr->sat_addr.s_node= ap->s_node;
1173 if (!atalk_find_interface(addr->sat_addr.s_net,
1174 addr->sat_addr.s_node))
1175 return -EADDRNOTAVAIL;
1177 at->src_net = addr->sat_addr.s_net;
1178 at->src_node = addr->sat_addr.s_node;
1181 if (addr->sat_port == ATADDR_ANYPORT) {
1182 int n = atalk_pick_and_bind_port(sk, addr);
1187 at->src_port = addr->sat_port;
1189 if (atalk_find_or_insert_socket(sk, addr))
1197 /* Set the address we talk to */
1198 static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1199 int addr_len, int flags)
1201 struct sock *sk = sock->sk;
1202 struct atalk_sock *at = at_sk(sk);
1203 struct sockaddr_at *addr;
1205 sk->sk_state = TCP_CLOSE;
1206 sock->state = SS_UNCONNECTED;
1208 if (addr_len != sizeof(*addr))
1211 addr = (struct sockaddr_at *)uaddr;
1213 if (addr->sat_family != AF_APPLETALK)
1214 return -EAFNOSUPPORT;
1216 if (addr->sat_addr.s_node == ATADDR_BCAST &&
1217 !sock_flag(sk, SOCK_BROADCAST)) {
1219 printk(KERN_WARNING "%s is broken and did not set "
1220 "SO_BROADCAST. It will break when 2.2 is "
1229 if (atalk_autobind(sk) < 0)
1232 if (!atrtr_get_dev(&addr->sat_addr))
1233 return -ENETUNREACH;
1235 at->dest_port = addr->sat_port;
1236 at->dest_net = addr->sat_addr.s_net;
1237 at->dest_node = addr->sat_addr.s_node;
1239 sock->state = SS_CONNECTED;
1240 sk->sk_state = TCP_ESTABLISHED;
1245 * Find the name of an AppleTalk socket. Just copy the right
1246 * fields into the sockaddr.
1248 static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1249 int *uaddr_len, int peer)
1251 struct sockaddr_at sat;
1252 struct sock *sk = sock->sk;
1253 struct atalk_sock *at = at_sk(sk);
1256 if (atalk_autobind(sk) < 0)
1259 *uaddr_len = sizeof(struct sockaddr_at);
1262 if (sk->sk_state != TCP_ESTABLISHED)
1265 sat.sat_addr.s_net = at->dest_net;
1266 sat.sat_addr.s_node = at->dest_node;
1267 sat.sat_port = at->dest_port;
1269 sat.sat_addr.s_net = at->src_net;
1270 sat.sat_addr.s_node = at->src_node;
1271 sat.sat_port = at->src_port;
1274 sat.sat_family = AF_APPLETALK;
1275 memcpy(uaddr, &sat, sizeof(sat));
1279 #if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
1280 static __inline__ int is_ip_over_ddp(struct sk_buff *skb)
1282 return skb->data[12] == 22;
1285 static int handle_ip_over_ddp(struct sk_buff *skb)
1287 struct net_device *dev = __dev_get_by_name("ipddp0");
1288 struct net_device_stats *stats;
1290 /* This needs to be able to handle ipddp"N" devices */
1294 skb->protocol = htons(ETH_P_IP);
1297 skb->h.raw = skb->data;
1300 stats->rx_packets++;
1301 stats->rx_bytes += skb->len + 13;
1302 netif_rx(skb); /* Send the SKB up to a higher place. */
1306 /* make it easy for gcc to optimize this test out, i.e. kill the code */
1307 #define is_ip_over_ddp(skb) 0
1308 #define handle_ip_over_ddp(skb) 0
1311 static void atalk_route_packet(struct sk_buff *skb, struct net_device *dev,
1312 struct ddpehdr *ddp, struct ddpebits *ddphv,
1315 struct atalk_route *rt;
1316 struct atalk_addr ta;
1319 * Don't route multicast, etc., packets, or packets sent to "this
1322 if (skb->pkt_type != PACKET_HOST || !ddp->deh_dnet) {
1326 * Can it ever happen that a packet is from a PPP iface and
1327 * needs to be broadcast onto the default network?
1329 if (dev->type == ARPHRD_PPP)
1330 printk(KERN_DEBUG "AppleTalk: didn't forward broadcast "
1331 "packet received from PPP iface\n");
1335 ta.s_net = ddp->deh_dnet;
1336 ta.s_node = ddp->deh_dnode;
1338 /* Route the packet */
1339 rt = atrtr_find(&ta);
1340 if (!rt || ddphv->deh_hops == DDP_MAXHOPS)
1342 /* FIXME: use skb->cb to be able to use shared skbs */
1346 * Route goes through another gateway, so set the target to the
1350 if (rt->flags & RTF_GATEWAY) {
1351 ta.s_net = rt->gateway.s_net;
1352 ta.s_node = rt->gateway.s_node;
1355 /* Fix up skb->len field */
1356 skb_trim(skb, min_t(unsigned int, origlen,
1357 (rt->dev->hard_header_len +
1358 ddp_dl->header_length + ddphv->deh_len)));
1360 /* Mend the byte order */
1361 /* FIXME: use skb->cb to be able to use shared skbs */
1362 *((__u16 *)ddp) = ntohs(*((__u16 *)ddphv));
1365 * Send the buffer onwards
1367 * Now we must always be careful. If it's come from LocalTalk to
1368 * EtherTalk it might not fit
1370 * Order matters here: If a packet has to be copied to make a new
1371 * headroom (rare hopefully) then it won't need unsharing.
1373 * Note. ddp-> becomes invalid at the realloc.
1375 if (skb_headroom(skb) < 22) {
1376 /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
1377 struct sk_buff *nskb = skb_realloc_headroom(skb, 32);
1383 skb = skb_unshare(skb, GFP_ATOMIC);
1386 * If the buffer didn't vanish into the lack of space bitbucket we can
1389 if (skb && aarp_send_ddp(rt->dev, skb, &ta, NULL) == -1)
1398 * atalk_rcv - Receive a packet (in skb) from device dev
1399 * @skb - packet received
1400 * @dev - network device where the packet comes from
1403 * Receive a packet (in skb) from device dev. This has come from the SNAP
1404 * decoder, and on entry skb->h.raw is the DDP header, skb->len is the DDP
1405 * header, skb->len is the DDP length. The physical headers have been
1406 * extracted. PPP should probably pass frames marked as for this layer.
1407 * [ie ARPHRD_ETHERTALK]
1409 static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
1410 struct packet_type *pt)
1412 struct ddpehdr *ddp;
1414 struct atalk_iface *atif;
1415 struct sockaddr_at tosat;
1417 struct ddpebits ddphv;
1419 /* Don't mangle buffer if shared */
1420 if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1423 /* Size check and make sure header is contiguous */
1424 if (!pskb_may_pull(skb, sizeof(*ddp)))
1430 * Fix up the length field [Ok this is horrible but otherwise
1431 * I end up with unions of bit fields and messy bit field order
1432 * compiler/endian dependencies..]
1434 *((__u16 *)&ddphv) = ntohs(*((__u16 *)ddp));
1436 /* Trim buffer in case of stray trailing data */
1438 skb_trim(skb, min_t(unsigned int, skb->len, ddphv.deh_len));
1441 * Size check to see if ddp->deh_len was crap
1442 * (Otherwise we'll detonate most spectacularly
1443 * in the middle of recvmsg()).
1445 if (skb->len < sizeof(*ddp))
1449 * Any checksums. Note we don't do htons() on this == is assumed to be
1450 * valid for net byte orders all over the networking code...
1453 atalk_checksum(skb, ddphv.deh_len) != ddp->deh_sum)
1454 /* Not a valid AppleTalk frame - dustbin time */
1457 /* Check the packet is aimed at us */
1458 if (!ddp->deh_dnet) /* Net 0 is 'this network' */
1459 atif = atalk_find_anynet(ddp->deh_dnode, dev);
1461 atif = atalk_find_interface(ddp->deh_dnet, ddp->deh_dnode);
1463 /* Not ours, so we route the packet via the correct AppleTalk iface */
1465 atalk_route_packet(skb, dev, ddp, &ddphv, origlen);
1469 /* if IP over DDP is not selected this code will be optimized out */
1470 if (is_ip_over_ddp(skb))
1471 return handle_ip_over_ddp(skb);
1473 * Which socket - atalk_search_socket() looks for a *full match*
1474 * of the <net, node, port> tuple.
1476 tosat.sat_addr.s_net = ddp->deh_dnet;
1477 tosat.sat_addr.s_node = ddp->deh_dnode;
1478 tosat.sat_port = ddp->deh_dport;
1480 sock = atalk_search_socket(&tosat, atif);
1481 if (!sock) /* But not one of our sockets */
1484 /* Queue packet (standard) */
1487 if (sock_queue_rcv_skb(sock, skb) < 0)
1497 * Receive a LocalTalk frame. We make some demands on the caller here.
1498 * Caller must provide enough headroom on the packet to pull the short
1499 * header and append a long one.
1501 static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
1502 struct packet_type *pt)
1504 /* Expand any short form frames */
1505 if (skb->mac.raw[2] == 1) {
1506 struct ddpehdr *ddp;
1507 /* Find our address */
1508 struct atalk_addr *ap = atalk_find_dev_addr(dev);
1510 if (!ap || skb->len < sizeof(struct ddpshdr))
1513 /* Don't mangle buffer if shared */
1514 if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
1518 * The push leaves us with a ddephdr not an shdr, and
1519 * handily the port bytes in the right place preset.
1521 ddp = (struct ddpehdr *) skb_push(skb, sizeof(*ddp) - 4);
1523 /* Now fill in the long header */
1526 * These two first. The mac overlays the new source/dest
1527 * network information so we MUST copy these before
1528 * we write the network numbers !
1531 ddp->deh_dnode = skb->mac.raw[0]; /* From physical header */
1532 ddp->deh_snode = skb->mac.raw[1]; /* From physical header */
1534 ddp->deh_dnet = ap->s_net; /* Network number */
1535 ddp->deh_snet = ap->s_net;
1536 ddp->deh_sum = 0; /* No checksum */
1538 * Not sure about this bit...
1540 ddp->deh_len = skb->len;
1541 ddp->deh_hops = DDP_MAXHOPS; /* Non routable, so force a drop
1542 if we slip up later */
1543 /* Mend the byte order */
1544 *((__u16 *)ddp) = htons(*((__u16 *)ddp));
1546 skb->h.raw = skb->data;
1548 return atalk_rcv(skb, dev, pt);
1554 static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
1557 struct sock *sk = sock->sk;
1558 struct atalk_sock *at = at_sk(sk);
1559 struct sockaddr_at *usat = (struct sockaddr_at *)msg->msg_name;
1560 int flags = msg->msg_flags;
1562 struct sockaddr_at local_satalk, gsat;
1563 struct sk_buff *skb;
1564 struct net_device *dev;
1565 struct ddpehdr *ddp;
1567 struct atalk_route *rt;
1570 if (flags & ~MSG_DONTWAIT)
1573 if (len > DDP_MAXSZ)
1578 if (atalk_autobind(sk) < 0)
1581 if (msg->msg_namelen < sizeof(*usat) ||
1582 usat->sat_family != AF_APPLETALK)
1585 /* netatalk doesn't implement this check */
1586 if (usat->sat_addr.s_node == ATADDR_BCAST &&
1587 !sock_flag(sk, SOCK_BROADCAST)) {
1588 printk(KERN_INFO "SO_BROADCAST: Fix your netatalk as "
1589 "it will break before 2.2\n");
1595 if (sk->sk_state != TCP_ESTABLISHED)
1597 usat = &local_satalk;
1598 usat->sat_family = AF_APPLETALK;
1599 usat->sat_port = at->dest_port;
1600 usat->sat_addr.s_node = at->dest_node;
1601 usat->sat_addr.s_net = at->dest_net;
1604 /* Build a packet */
1605 SOCK_DEBUG(sk, "SK %p: Got address.\n", sk);
1608 size = sizeof(struct ddpehdr) + len + ddp_dl->header_length;
1610 if (usat->sat_addr.s_net || usat->sat_addr.s_node == ATADDR_ANYNODE) {
1611 rt = atrtr_find(&usat->sat_addr);
1613 return -ENETUNREACH;
1617 struct atalk_addr at_hint;
1620 at_hint.s_net = at->src_net;
1622 rt = atrtr_find(&at_hint);
1624 return -ENETUNREACH;
1629 SOCK_DEBUG(sk, "SK %p: Size needed %d, device %s\n",
1630 sk, size, dev->name);
1632 size += dev->hard_header_len;
1633 skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
1638 skb_reserve(skb, ddp_dl->header_length);
1639 skb_reserve(skb, dev->hard_header_len);
1642 SOCK_DEBUG(sk, "SK %p: Begin build.\n", sk);
1644 ddp = (struct ddpehdr *)skb_put(skb, sizeof(struct ddpehdr));
1647 ddp->deh_len = len + sizeof(*ddp);
1649 * Fix up the length field [Ok this is horrible but otherwise
1650 * I end up with unions of bit fields and messy bit field order
1651 * compiler/endian dependencies..
1653 *((__u16 *)ddp) = ntohs(*((__u16 *)ddp));
1655 ddp->deh_dnet = usat->sat_addr.s_net;
1656 ddp->deh_snet = at->src_net;
1657 ddp->deh_dnode = usat->sat_addr.s_node;
1658 ddp->deh_snode = at->src_node;
1659 ddp->deh_dport = usat->sat_port;
1660 ddp->deh_sport = at->src_port;
1662 SOCK_DEBUG(sk, "SK %p: Copy user data (%Zd bytes).\n", sk, len);
1664 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1670 if (sk->sk_no_check == 1)
1673 ddp->deh_sum = atalk_checksum(skb, len + sizeof(*ddp));
1676 * Loopback broadcast packets to non gateway targets (ie routes
1677 * to group we are in)
1679 if (ddp->deh_dnode == ATADDR_BCAST &&
1680 !(rt->flags & RTF_GATEWAY) && !(dev->flags & IFF_LOOPBACK)) {
1681 struct sk_buff *skb2 = skb_copy(skb, GFP_KERNEL);
1685 SOCK_DEBUG(sk, "SK %p: send out(copy).\n", sk);
1686 if (aarp_send_ddp(dev, skb2,
1687 &usat->sat_addr, NULL) == -1)
1689 /* else queued/sent above in the aarp queue */
1693 if (dev->flags & IFF_LOOPBACK || loopback) {
1694 SOCK_DEBUG(sk, "SK %p: Loop back.\n", sk);
1697 ddp_dl->request(ddp_dl, skb, dev->dev_addr);
1699 SOCK_DEBUG(sk, "SK %p: send out.\n", sk);
1700 if (rt->flags & RTF_GATEWAY) {
1701 gsat.sat_addr = rt->gateway;
1705 if (aarp_send_ddp(dev, skb, &usat->sat_addr, NULL) == -1)
1707 /* else queued/sent above in the aarp queue */
1709 SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
1714 static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
1715 size_t size, int flags)
1717 struct sock *sk = sock->sk;
1718 struct sockaddr_at *sat = (struct sockaddr_at *)msg->msg_name;
1719 struct ddpehdr *ddp;
1722 struct ddpebits ddphv;
1723 struct sk_buff *skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1724 flags & MSG_DONTWAIT, &err);
1728 /* FIXME: use skb->cb to be able to use shared skbs */
1730 *((__u16 *)&ddphv) = ntohs(*((__u16 *)ddp));
1732 if (sk->sk_type == SOCK_RAW) {
1733 copied = ddphv.deh_len;
1734 if (copied > size) {
1736 msg->msg_flags |= MSG_TRUNC;
1739 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1741 copied = ddphv.deh_len - sizeof(*ddp);
1742 if (copied > size) {
1744 msg->msg_flags |= MSG_TRUNC;
1746 err = skb_copy_datagram_iovec(skb, sizeof(*ddp),
1747 msg->msg_iov, copied);
1752 sat->sat_family = AF_APPLETALK;
1753 sat->sat_port = ddp->deh_sport;
1754 sat->sat_addr.s_node = ddp->deh_snode;
1755 sat->sat_addr.s_net = ddp->deh_snet;
1757 msg->msg_namelen = sizeof(*sat);
1760 skb_free_datagram(sk, skb); /* Free the datagram. */
1761 return err ? : copied;
1766 * AppleTalk ioctl calls.
1768 static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1771 struct sock *sk = sock->sk;
1774 /* Protocol layer */
1776 long amount = sk->sk_sndbuf -
1777 atomic_read(&sk->sk_wmem_alloc);
1781 rc = put_user(amount, (int *)arg);
1786 * These two are safe on a single CPU system as only
1787 * user tasks fiddle here
1789 struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
1793 amount = skb->len - sizeof(struct ddpehdr);
1794 rc = put_user(amount, (int *)arg);
1798 rc = sock_get_timestamp(sk, (struct timeval *)arg);
1804 if (capable(CAP_NET_ADMIN))
1805 rc = atrtr_ioctl(cmd, (void *)arg);
1810 case SIOCGIFBRDADDR:
1811 case SIOCATALKDIFADDR:
1813 case SIOCSARP: /* proxy AARP */
1814 case SIOCDARP: /* proxy AARP */
1816 rc = atif_ioctl(cmd, (void *)arg);
1819 /* Physical layer ioctl calls */
1832 rc = dev_ioctl(cmd, (void *)arg);
1839 static struct net_proto_family atalk_family_ops = {
1840 .family = PF_APPLETALK,
1841 .create = atalk_create,
1842 .owner = THIS_MODULE,
1845 static struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
1846 .family = PF_APPLETALK,
1847 .owner = THIS_MODULE,
1848 .release = atalk_release,
1850 .connect = atalk_connect,
1851 .socketpair = sock_no_socketpair,
1852 .accept = sock_no_accept,
1853 .getname = atalk_getname,
1854 .poll = datagram_poll,
1855 .ioctl = atalk_ioctl,
1856 .listen = sock_no_listen,
1857 .shutdown = sock_no_shutdown,
1858 .setsockopt = sock_no_setsockopt,
1859 .getsockopt = sock_no_getsockopt,
1860 .sendmsg = atalk_sendmsg,
1861 .recvmsg = atalk_recvmsg,
1862 .mmap = sock_no_mmap,
1863 .sendpage = sock_no_sendpage,
1866 #include <linux/smp_lock.h>
1867 SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
1869 static struct notifier_block ddp_notifier = {
1870 .notifier_call = ddp_device_event,
1873 struct packet_type ltalk_packet_type = {
1874 .type = __constant_htons(ETH_P_LOCALTALK),
1878 struct packet_type ppptalk_packet_type = {
1879 .type = __constant_htons(ETH_P_PPPTALK),
1883 static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
1885 /* Export symbols for use by drivers when AppleTalk is a module */
1886 EXPORT_SYMBOL(aarp_send_ddp);
1887 EXPORT_SYMBOL(atrtr_get_dev);
1888 EXPORT_SYMBOL(atalk_find_dev_addr);
1890 static char atalk_err_snap[] __initdata =
1891 KERN_CRIT "Unable to register DDP with SNAP.\n";
1893 /* Called by proto.c on kernel start up */
1894 static int __init atalk_init(void)
1896 (void)sock_register(&atalk_family_ops);
1897 ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
1899 printk(atalk_err_snap);
1901 dev_add_pack(<alk_packet_type);
1902 dev_add_pack(&ppptalk_packet_type);
1904 register_netdevice_notifier(&ddp_notifier);
1907 atalk_register_sysctl();
1910 module_init(atalk_init);
1913 * No explicit module reference count manipulation is needed in the
1914 * protocol. Socket layer sets module reference count for us
1915 * and interfaces reference counting is done
1916 * by the network device layer.
1918 * Ergo, before the AppleTalk module can be removed, all AppleTalk
1919 * sockets be closed from user space.
1921 static void __exit atalk_exit(void)
1923 #ifdef CONFIG_SYSCTL
1924 atalk_unregister_sysctl();
1925 #endif /* CONFIG_SYSCTL */
1927 aarp_cleanup_module(); /* General aarp clean-up. */
1928 unregister_netdevice_notifier(&ddp_notifier);
1929 dev_remove_pack(<alk_packet_type);
1930 dev_remove_pack(&ppptalk_packet_type);
1931 unregister_snap_client(ddp_dl);
1932 sock_unregister(PF_APPLETALK);
1934 module_exit(atalk_exit);
1936 MODULE_LICENSE("GPL");
1937 MODULE_AUTHOR("Alan Cox <Alan.Cox@linux.org>");
1938 MODULE_DESCRIPTION("AppleTalk 0.20\n");
1939 MODULE_ALIAS_NETPROTO(PF_APPLETALK);