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