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 proc fs,
33 * moved probing to AARP module.
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
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.
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>
60 #include <linux/socket.h>
61 #include <linux/sockios.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/termios.h> /* For TIOCOUTQ/INQ */
75 #include <net/datalink.h>
76 #include <net/p8022.h>
77 #include <net/psnap.h>
80 #include <net/route.h>
81 #include <linux/atalk.h>
82 #include <linux/proc_fs.h>
83 #include <linux/stat.h>
84 #include <linux/init.h>
88 extern void aarp_register_proc_fs(void);
89 extern void aarp_unregister_proc_fs(void);
92 extern void aarp_probe_network(struct atalk_iface
*atif
);
93 extern int aarp_proxy_probe_network(struct atalk_iface
*atif
, struct at_addr
*sa
);
94 extern void aarp_proxy_remove(struct net_device
*dev
, struct at_addr
*sa
);
97 #undef APPLETALK_DEBUG
99 #ifdef APPLETALK_DEBUG
100 #define DPRINT(x) print(x)
103 #endif /* APPLETALK_DEBUG */
106 extern inline void atalk_register_sysctl(void);
107 extern inline void atalk_unregister_sysctl(void);
108 #endif /* CONFIG_SYSCTL */
110 struct datalink_proto
*ddp_dl
, *aarp_dl
;
111 static struct proto_ops atalk_dgram_ops
;
113 #define min(a,b) (((a)<(b))?(a):(b))
115 /**************************************************************************\
117 * Handlers for the socket list. *
119 \**************************************************************************/
121 static struct sock
*atalk_socket_list
= NULL
;
124 * Note: Sockets may not be removed _during_ an interrupt or inet_bh
125 * handler using this technique. They can be added although we do not
129 extern inline void atalk_remove_socket(struct sock
*sk
)
131 sklist_remove_socket(&atalk_socket_list
,sk
);
134 extern inline void atalk_insert_socket(struct sock
*sk
)
136 sklist_insert_socket(&atalk_socket_list
,sk
);
139 static struct sock
*atalk_search_socket(struct sockaddr_at
*to
, struct atalk_iface
*atif
)
143 for(s
= atalk_socket_list
; s
!= NULL
; s
= s
->next
)
145 if(to
->sat_port
!= s
->protinfo
.af_at
.src_port
)
150 if(to
->sat_addr
.s_net
== ATADDR_ANYNET
151 && to
->sat_addr
.s_node
== ATADDR_BCAST
152 && s
->protinfo
.af_at
.src_net
== atif
->address
.s_net
)
157 if(to
->sat_addr
.s_net
== s
->protinfo
.af_at
.src_net
158 && (to
->sat_addr
.s_node
== s
->protinfo
.af_at
.src_node
159 || to
->sat_addr
.s_node
== ATADDR_BCAST
160 || to
->sat_addr
.s_node
== ATADDR_ANYNODE
))
165 /* XXXX.0 -- we got a request for this router. make sure
166 * that the node is appropriately set. */
167 if (to
->sat_addr
.s_node
== ATADDR_ANYNODE
&&
168 to
->sat_addr
.s_net
!= ATADDR_ANYNET
&&
169 atif
->address
.s_node
== s
->protinfo
.af_at
.src_node
) {
170 to
->sat_addr
.s_node
= atif
->address
.s_node
;
179 * Find a socket in the list.
181 static struct sock
*atalk_find_socket(struct sockaddr_at
*sat
)
185 for(s
= atalk_socket_list
; s
!= NULL
; s
= s
->next
)
187 if(s
->protinfo
.af_at
.src_net
!= sat
->sat_addr
.s_net
)
192 if(s
->protinfo
.af_at
.src_node
!= sat
->sat_addr
.s_node
)
197 if(s
->protinfo
.af_at
.src_port
!= sat
->sat_port
)
208 extern inline void atalk_destroy_socket(struct sock
*sk
)
210 sklist_destroy_socket(&atalk_socket_list
, sk
);
215 * Called from proc fs
217 int atalk_get_info(char *buffer
, char **start
, off_t offset
, int length
, int dummy
)
225 * Output the AppleTalk data for the /proc filesystem.
228 len
+= sprintf(buffer
,"Type local_addr remote_addr tx_queue rx_queue st uid\n");
229 for(s
= atalk_socket_list
; s
!= NULL
; s
= s
->next
)
231 len
+= sprintf(buffer
+len
,"%02X ", s
->type
);
232 len
+= sprintf(buffer
+len
,"%04X:%02X:%02X ",
233 ntohs(s
->protinfo
.af_at
.src_net
),
234 s
->protinfo
.af_at
.src_node
,
235 s
->protinfo
.af_at
.src_port
);
236 len
+= sprintf(buffer
+len
,"%04X:%02X:%02X ",
237 ntohs(s
->protinfo
.af_at
.dest_net
),
238 s
->protinfo
.af_at
.dest_node
,
239 s
->protinfo
.af_at
.dest_port
);
240 len
+= sprintf(buffer
+len
,"%08X:%08X ",
241 atomic_read(&s
->wmem_alloc
),
242 atomic_read(&s
->rmem_alloc
));
243 len
+= sprintf(buffer
+len
,"%02X %d\n", s
->state
,
244 SOCK_INODE(s
->socket
)->i_uid
);
246 /* Are we still dumping unwanted data then discard the record */
251 len
= 0; /* Keep dumping into the buffer start */
254 if(pos
> offset
+ length
) /* We have dumped enough */
258 /* The data in question runs from begin to begin+len */
259 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
260 len
-= (offset
- begin
); /* Remove unwanted header data from length */
262 len
= length
; /* Remove unwanted tail data from length */
267 /**************************************************************************\
269 * Routing tables for the AppleTalk socket layer. *
271 \**************************************************************************/
273 static struct atalk_route
*atalk_router_list
= NULL
;
274 static struct atalk_iface
*atalk_iface_list
= NULL
;
275 static struct atalk_route atrtr_default
; /* For probing devices or in a routerless network */
278 * AppleTalk interface control
282 * Drop a device. Doesn't drop any of its routes - that is the caller's
283 * problem. Called when we down the interface or delete the address.
285 static void atif_drop_device(struct net_device
*dev
)
287 struct atalk_iface
**iface
= &atalk_iface_list
;
288 struct atalk_iface
*tmp
;
290 while((tmp
= *iface
) != NULL
)
295 kfree_s(tmp
, sizeof(struct atalk_iface
));
305 static struct atalk_iface
*atif_add_device(struct net_device
*dev
, struct at_addr
*sa
)
307 struct atalk_iface
*iface
= (struct atalk_iface
*)
308 kmalloc(sizeof(*iface
), GFP_KERNEL
);
315 dev
->atalk_ptr
=iface
;
320 iface
->next
=atalk_iface_list
;
321 atalk_iface_list
=iface
;
322 restore_flags(flags
);
331 * Perform phase 2 AARP probing on our tentative address.
333 static int atif_probe_device(struct atalk_iface
*atif
)
335 int netrange
=ntohs(atif
->nets
.nr_lastnet
)-ntohs(atif
->nets
.nr_firstnet
)+1;
336 int probe_net
=ntohs(atif
->address
.s_net
);
337 int probe_node
=atif
->address
.s_node
;
341 * Offset the network we start probing with.
344 if(probe_net
== ATADDR_ANYNET
)
347 probe_net
= ntohs(atif
->nets
.nr_firstnet
);
349 probe_net
= ntohs(atif
->nets
.nr_firstnet
) + (jiffies
%netrange
);
352 if(probe_node
== ATADDR_ANYNODE
)
353 probe_node
= jiffies
&0xFF;
358 atif
->status
|= ATIF_PROBE
;
359 for(netct
= 0; netct
<= netrange
; netct
++)
362 * Sweep the available nodes from a given start.
365 atif
->address
.s_net
= htons(probe_net
);
366 for(nodect
= 0; nodect
< 256; nodect
++)
368 atif
->address
.s_node
= ((nodect
+probe_node
) & 0xFF);
369 if(atif
->address
.s_node
> 0 && atif
->address
.s_node
<254)
372 * Probe a proposed address.
374 aarp_probe_network(atif
);
376 if(!(atif
->status
& ATIF_PROBE_FAIL
)) {
377 atif
->status
&= ~ATIF_PROBE
;
381 atif
->status
&= ~ATIF_PROBE_FAIL
;
384 if(probe_net
> ntohs(atif
->nets
.nr_lastnet
))
385 probe_net
= ntohs(atif
->nets
.nr_firstnet
);
387 atif
->status
&= ~ATIF_PROBE
;
388 return (-EADDRINUSE
); /* Network is full... */
393 * Perform AARP probing for a proxy address
395 static int atif_proxy_probe_device(struct atalk_iface
*atif
, struct at_addr
* proxy_addr
)
397 int netrange
=ntohs(atif
->nets
.nr_lastnet
)-ntohs(atif
->nets
.nr_firstnet
)+1;
398 int probe_net
=ntohs(atif
->address
.s_net
); // we probe the interface's network
399 int probe_node
=ATADDR_ANYNODE
; // we'll take anything
403 * Offset the network we start probing with.
406 if(probe_net
== ATADDR_ANYNET
)
409 probe_net
= ntohs(atif
->nets
.nr_firstnet
);
411 probe_net
= ntohs(atif
->nets
.nr_firstnet
) + (jiffies
%netrange
);
414 if(probe_node
== ATADDR_ANYNODE
)
415 probe_node
= jiffies
&0xFF;
421 for(netct
= 0; netct
<= netrange
; netct
++)
424 * Sweep the available nodes from a given start.
427 proxy_addr
->s_net
= htons(probe_net
);
428 for(nodect
= 0; nodect
< 256; nodect
++)
430 proxy_addr
->s_node
= ((nodect
+probe_node
) & 0xFF);
431 if((proxy_addr
->s_node
>0) && (proxy_addr
->s_node
<254))
434 * Tell AARP to probe a proposed address.
436 int probe_result
= aarp_proxy_probe_network(atif
, proxy_addr
);
438 if (probe_result
== 0)
441 if (probe_result
!= -EADDRINUSE
)
446 if(probe_net
> ntohs(atif
->nets
.nr_lastnet
))
447 probe_net
= ntohs(atif
->nets
.nr_firstnet
);
450 return (-EADDRINUSE
); /* Network is full... */
454 struct at_addr
*atalk_find_dev_addr(struct net_device
*dev
)
456 struct atalk_iface
*iface
=dev
->atalk_ptr
;
459 return (&iface
->address
);
464 static struct at_addr
*atalk_find_primary(void)
466 struct atalk_iface
*iface
;
467 struct atalk_iface
*fiface
= NULL
;
470 * Return a point-to-point interface only if
471 * there is no non-ptp interface available.
473 for(iface
=atalk_iface_list
; iface
!= NULL
; iface
=iface
->next
)
475 if(!fiface
&& !(iface
->dev
->flags
& IFF_LOOPBACK
))
477 if(!(iface
->dev
->flags
& (IFF_LOOPBACK
| IFF_POINTOPOINT
)))
478 return (&iface
->address
);
482 return (&fiface
->address
);
483 if(atalk_iface_list
!= NULL
)
484 return (&atalk_iface_list
->address
);
490 * Find a match for 'any network' - ie any of our interfaces with that
491 * node number will do just nicely.
493 static struct atalk_iface
*atalk_find_anynet(int node
, struct net_device
*dev
)
495 struct atalk_iface
*iface
=dev
->atalk_ptr
;
497 if(iface
==NULL
|| (iface
->status
& ATIF_PROBE
))
499 if(node
== ATADDR_BCAST
|| iface
->address
.s_node
== node
500 || node
== ATADDR_ANYNODE
)
507 * Find a match for a specific network:node pair
509 static struct atalk_iface
*atalk_find_interface(int net
, int node
)
511 struct atalk_iface
*iface
;
513 for(iface
=atalk_iface_list
; iface
!= NULL
; iface
=iface
->next
)
515 if((node
==ATADDR_BCAST
|| node
==ATADDR_ANYNODE
516 || iface
->address
.s_node
==node
)
517 && iface
->address
.s_net
==net
518 && !(iface
->status
& ATIF_PROBE
))
521 /* XXXX.0 -- net.0 returns the iface associated with net */
522 if ((node
==ATADDR_ANYNODE
) && (net
!= ATADDR_ANYNET
) &&
523 (ntohs(iface
->nets
.nr_firstnet
) <= ntohs(net
)) &&
524 (ntohs(net
) <= ntohs(iface
->nets
.nr_lastnet
)))
533 * Find a route for an AppleTalk packet. This ought to get cached in
534 * the socket (later on...). We know about host routes and the fact
535 * that a route must be direct to broadcast.
537 static struct atalk_route
*atrtr_find(struct at_addr
*target
)
540 * we must search through all routes unless we find a
541 * host route, because some host routes might overlap
544 struct atalk_route
*r
;
545 struct atalk_route
*net_route
= NULL
;
547 for(r
=atalk_router_list
; r
!= NULL
; r
=r
->next
)
549 if(!(r
->flags
& RTF_UP
))
551 if(r
->target
.s_net
== target
->s_net
)
553 if (r
->flags
& RTF_HOST
)
556 * if this host route is for the target,
559 if (r
->target
.s_node
== target
->s_node
)
565 * this route will work if there isn't a
566 * direct host route, so cache it
574 * if we found a network route but not a direct host
575 * route, then return it
577 if (net_route
!= NULL
)
580 if(atrtr_default
.dev
)
581 return (&atrtr_default
);
588 * Given an AppleTalk network, find the device to use. This can be
591 struct net_device
*atrtr_get_dev(struct at_addr
*sa
)
593 struct atalk_route
*atr
=atrtr_find(sa
);
602 * Set up a default router.
604 static void atrtr_set_default(struct net_device
*dev
)
606 atrtr_default
.dev
= dev
;
607 atrtr_default
.flags
= RTF_UP
;
608 atrtr_default
.gateway
.s_net
= htons(0);
609 atrtr_default
.gateway
.s_node
= 0;
613 * Add a router. Basically make sure it looks valid and stuff the
614 * entry in the list. While it uses netranges we always set them to one
615 * entry to work like netatalk.
617 static int atrtr_create(struct rtentry
*r
, struct net_device
*devhint
)
619 struct sockaddr_at
*ta
=(struct sockaddr_at
*)&r
->rt_dst
;
620 struct sockaddr_at
*ga
=(struct sockaddr_at
*)&r
->rt_gateway
;
621 struct atalk_route
*rt
;
622 struct atalk_iface
*iface
, *riface
;
628 * Fixme: Raise/Lower a routing change semaphore for these
633 * Validate the request
635 if(ta
->sat_family
!= AF_APPLETALK
)
637 if(devhint
== NULL
&& ga
->sat_family
!= AF_APPLETALK
)
641 * Now walk the routing table and make our decisions.
643 for(rt
=atalk_router_list
; rt
!=NULL
; rt
=rt
->next
)
645 if(r
->rt_flags
!= rt
->flags
)
648 if(ta
->sat_addr
.s_net
== rt
->target
.s_net
)
650 if(!(rt
->flags
& RTF_HOST
))
652 if(ta
->sat_addr
.s_node
== rt
->target
.s_node
)
659 for(riface
= NULL
, iface
= atalk_iface_list
; iface
; iface
= iface
->next
)
661 if(riface
== NULL
&& ntohs(ga
->sat_addr
.s_net
) >= ntohs(iface
->nets
.nr_firstnet
) &&
662 ntohs(ga
->sat_addr
.s_net
) <= ntohs(iface
->nets
.nr_lastnet
))
666 if(ga
->sat_addr
.s_net
== iface
->address
.s_net
667 && ga
->sat_addr
.s_node
== iface
->address
.s_node
)
672 return (-ENETUNREACH
);
673 devhint
= riface
->dev
;
678 rt
= (struct atalk_route
*)kmalloc(sizeof(struct atalk_route
), GFP_KERNEL
);
682 rt
->next
= atalk_router_list
;
683 atalk_router_list
= rt
;
687 * Fill in the routing entry.
689 rt
->target
= ta
->sat_addr
;
691 rt
->flags
= r
->rt_flags
;
692 rt
->gateway
= ga
->sat_addr
;
694 restore_flags(flags
);
700 * Delete a route. Find it and discard it.
702 static int atrtr_delete( struct at_addr
*addr
)
704 struct atalk_route
**r
= &atalk_router_list
;
705 struct atalk_route
*tmp
;
707 while((tmp
= *r
) != NULL
)
709 if(tmp
->target
.s_net
== addr
->s_net
710 && (!(tmp
->flags
&RTF_GATEWAY
)
711 || tmp
->target
.s_node
== addr
->s_node
))
714 kfree_s(tmp
, sizeof(struct atalk_route
));
724 * Called when a device is downed. Just throw away any routes
727 void atrtr_device_down(struct net_device
*dev
)
729 struct atalk_route
**r
= &atalk_router_list
;
730 struct atalk_route
*tmp
;
732 while((tmp
= *r
) != NULL
)
737 kfree_s(tmp
, sizeof(struct atalk_route
));
743 if(atrtr_default
.dev
== dev
)
744 atrtr_set_default(NULL
);
748 * Actually down the interface.
750 static inline void atalk_dev_down(struct net_device
*dev
)
752 atrtr_device_down(dev
); /* Remove all routes for the device */
753 aarp_device_down(dev
); /* Remove AARP entries for the device */
754 atif_drop_device(dev
); /* Remove the device */
758 * A device event has occurred. Watch for devices going down and
759 * delete our use of them (iface and route).
761 static int ddp_device_event(struct notifier_block
*this, unsigned long event
, void *ptr
)
763 if(event
== NETDEV_DOWN
)
765 /* Discard any use of this */
766 atalk_dev_down((struct net_device
*) ptr
);
769 return (NOTIFY_DONE
);
773 * ioctl calls. Shouldn't even need touching.
777 * Device configuration ioctl calls.
779 int atif_ioctl(int cmd
, void *arg
)
782 static char aarp_mcast
[6] = {0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF};
784 struct sockaddr_at
*sa
;
785 struct net_device
*dev
;
786 struct atalk_iface
*atif
;
789 struct rtentry rtdef
;
792 if(copy_from_user(&atreq
,arg
,sizeof(atreq
)))
795 if((dev
= __dev_get_by_name(atreq
.ifr_name
)) == NULL
)
798 sa
=(struct sockaddr_at
*)&atreq
.ifr_addr
;
799 atif
=atalk_find_dev(dev
);
804 if(!capable(CAP_NET_ADMIN
))
806 if(sa
->sat_family
!= AF_APPLETALK
)
808 if(dev
->type
!= ARPHRD_ETHER
809 && dev
->type
!= ARPHRD_LOOPBACK
810 && dev
->type
!= ARPHRD_LOCALTLK
811 && dev
->type
!= ARPHRD_PPP
)
812 return (-EPROTONOSUPPORT
);
814 nr
=(struct netrange
*)&sa
->sat_zero
[0];
819 * if this is a point-to-point iface, and we already have an
820 * iface for this AppleTalk address, then we should not add a route
822 if (dev
->flags
& IFF_POINTOPOINT
&& atalk_find_interface(sa
->sat_addr
.s_net
, sa
->sat_addr
.s_node
))
824 printk(KERN_DEBUG
"AppleTalk: point-to-point interface added with existing address\n");
829 * Phase 1 is fine on LocalTalk but we don't do
830 * EtherTalk phase 1. Anyone wanting to add it go ahead.
832 if(dev
->type
== ARPHRD_ETHER
&& nr
->nr_phase
!= 2)
833 return (-EPROTONOSUPPORT
);
834 if(sa
->sat_addr
.s_node
== ATADDR_BCAST
835 || sa
->sat_addr
.s_node
== 254)
840 * Already setting address.
842 if(atif
->status
&ATIF_PROBE
)
845 atif
->address
.s_net
= sa
->sat_addr
.s_net
;
846 atif
->address
.s_node
= sa
->sat_addr
.s_node
;
847 atrtr_device_down(dev
); /* Flush old routes */
851 atif
=atif_add_device(dev
, &sa
->sat_addr
);
858 * Check if the chosen address is used. If so we
859 * error and atalkd will try another.
862 if(!(dev
->flags
& IFF_LOOPBACK
) && !(dev
->flags
& IFF_POINTOPOINT
) && atif_probe_device(atif
) < 0)
864 atif_drop_device(dev
);
865 return (-EADDRINUSE
);
869 * Hey it worked - add the direct routes.
872 sa
= (struct sockaddr_at
*)&rtdef
.rt_gateway
;
873 sa
->sat_family
= AF_APPLETALK
;
874 sa
->sat_addr
.s_net
= atif
->address
.s_net
;
875 sa
->sat_addr
.s_node
= atif
->address
.s_node
;
876 sa
= (struct sockaddr_at
*)&rtdef
.rt_dst
;
877 rtdef
.rt_flags
= RTF_UP
;
878 sa
->sat_family
= AF_APPLETALK
;
879 sa
->sat_addr
.s_node
= ATADDR_ANYNODE
;
880 if((dev
->flags
& IFF_LOOPBACK
) || (dev
->flags
& IFF_POINTOPOINT
))
881 rtdef
.rt_flags
|= RTF_HOST
;
884 * Routerless initial state.
886 if(nr
->nr_firstnet
== htons(0)
887 && nr
->nr_lastnet
== htons(0xFFFE))
889 sa
->sat_addr
.s_net
= atif
->address
.s_net
;
890 atrtr_create(&rtdef
, dev
);
891 atrtr_set_default(dev
);
895 limit
= ntohs(nr
->nr_lastnet
);
896 if(limit
- ntohs(nr
->nr_firstnet
) > 4096)
898 printk(KERN_WARNING
"Too many routes/iface.\n");
902 for(ct
=ntohs(nr
->nr_firstnet
);ct
<=limit
;ct
++)
904 sa
->sat_addr
.s_net
= htons(ct
);
905 atrtr_create(&rtdef
, dev
);
908 dev_mc_add(dev
, aarp_mcast
, 6, 1);
913 return (-EADDRNOTAVAIL
);
914 ((struct sockaddr_at
*)(&atreq
.ifr_addr
))->sat_family
=AF_APPLETALK
;
915 ((struct sockaddr_at
*)(&atreq
.ifr_addr
))->sat_addr
=atif
->address
;
920 return (-EADDRNOTAVAIL
);
921 ((struct sockaddr_at
*)(&atreq
.ifr_addr
))->sat_family
=AF_APPLETALK
;
922 ((struct sockaddr_at
*)(&atreq
.ifr_addr
))->sat_addr
.s_net
=atif
->address
.s_net
;
923 ((struct sockaddr_at
*)(&atreq
.ifr_addr
))->sat_addr
.s_node
=ATADDR_BCAST
;
926 case SIOCATALKDIFADDR
:
928 if(!capable(CAP_NET_ADMIN
))
930 if(sa
->sat_family
!= AF_APPLETALK
)
936 if(!capable(CAP_NET_ADMIN
))
938 if(sa
->sat_family
!= AF_APPLETALK
)
941 return (-EADDRNOTAVAIL
);
944 * for now, we only support proxy AARP on ELAP;
945 * we should be able to do it for LocalTalk, too.
947 if(dev
->type
!= ARPHRD_ETHER
)
948 return (-EPROTONOSUPPORT
);
951 * atif points to the current interface on this network;
952 * we aren't concerned about its current status (at least for now),
953 * but it has all the settings about the network we're going
954 * to probe. consequently, it must exist.
957 return (-EADDRNOTAVAIL
);
959 nr
=(struct netrange
*)&(atif
->nets
);
961 * Phase 1 is fine on Localtalk but we don't do
962 * Ethertalk phase 1. Anyone wanting to add it go ahead.
964 if(dev
->type
== ARPHRD_ETHER
&& nr
->nr_phase
!= 2)
965 return (-EPROTONOSUPPORT
);
967 if(sa
->sat_addr
.s_node
== ATADDR_BCAST
968 || sa
->sat_addr
.s_node
== 254)
972 * Check if the chosen address is used. If so we
973 * error and ATCP will try another.
975 if (atif_proxy_probe_device(atif
, &(sa
->sat_addr
)) < 0)
976 return (-EADDRINUSE
);
979 * We now have an address on the local network, and the AARP
980 * code will defend it for us until we take it down.
981 * We don't set up any routes right now, because ATCP will
982 * install them manually via SIOCADDRT.
987 if(!capable(CAP_NET_ADMIN
))
989 if(sa
->sat_family
!= AF_APPLETALK
)
992 return (-EADDRNOTAVAIL
);
995 * give to aarp module to remove proxy entry
997 aarp_proxy_remove(atif
->dev
, &(sa
->sat_addr
));
1002 if(copy_to_user(arg
, &atreq
, sizeof(atreq
)))
1009 * Routing ioctl() calls
1011 static int atrtr_ioctl(unsigned int cmd
, void *arg
)
1014 struct net_device
*dev
= NULL
;
1016 if(copy_from_user(&rt
, arg
, sizeof(rt
)))
1022 if(rt
.rt_dst
.sa_family
!= AF_APPLETALK
)
1024 return (atrtr_delete(&((struct sockaddr_at
*)&rt
.rt_dst
)->sat_addr
));
1027 /* FIX ME: the name of the device is still in user space, isn't it? */
1028 if (rt
.rt_dev
!= NULL
)
1029 if ((dev
= __dev_get_by_name(rt
.rt_dev
)) == NULL
)
1032 return (atrtr_create(&rt
, dev
));
1039 /* Called from proc fs - just make it print the ifaces neatly */
1041 int atalk_if_get_info(char *buffer
, char **start
, off_t offset
, int length
, int dummy
)
1043 struct atalk_iface
*iface
;
1048 len
+= sprintf(buffer
,"Interface Address Networks Status\n");
1049 for(iface
= atalk_iface_list
; iface
!= NULL
; iface
= iface
->next
)
1051 len
+= sprintf(buffer
+len
,"%-16s %04X:%02X %04X-%04X %d\n",
1052 iface
->dev
->name
, ntohs(iface
->address
.s_net
),
1053 iface
->address
.s_node
, ntohs(iface
->nets
.nr_firstnet
),
1054 ntohs(iface
->nets
.nr_lastnet
), iface
->status
);
1061 if(pos
> offset
+ length
)
1064 *start
= buffer
+ (offset
- begin
);
1065 len
-= (offset
- begin
);
1072 /* Called from proc fs - just make it print the routes neatly */
1074 int atalk_rt_get_info(char *buffer
, char **start
, off_t offset
, int length
, int dummy
)
1076 struct atalk_route
*rt
;
1081 len
+= sprintf(buffer
,"Target Router Flags Dev\n");
1082 if(atrtr_default
.dev
)
1084 rt
= &atrtr_default
;
1085 len
+= sprintf(buffer
+len
,"Default %04X:%02X %-4d %s\n",
1086 ntohs(rt
->gateway
.s_net
), rt
->gateway
.s_node
, rt
->flags
,
1090 for(rt
= atalk_router_list
; rt
!= NULL
; rt
= rt
->next
)
1092 len
+= sprintf(buffer
+len
,"%04X:%02X %04X:%02X %-4d %s\n",
1093 ntohs(rt
->target
.s_net
),rt
->target
.s_node
,
1094 ntohs(rt
->gateway
.s_net
), rt
->gateway
.s_node
, rt
->flags
,
1102 if(pos
> offset
+ length
)
1106 *start
= buffer
+ (offset
- begin
);
1107 len
-= (offset
- begin
);
1114 /**************************************************************************\
1116 * Handling for system calls applied via the various interfaces to an *
1117 * AppleTalk socket object. *
1119 \**************************************************************************/
1122 * Checksum: This is 'optional'. It's quite likely also a good
1123 * candidate for assembler hackery 8)
1125 unsigned short atalk_checksum(struct ddpehdr
*ddp
, int len
)
1127 unsigned long sum
=0; /* Assume unsigned long is >16 bits */
1128 unsigned char *data
=(unsigned char *)ddp
;
1130 len
-= 4; /* skip header 4 bytes */
1133 /* This ought to be unwrapped neatly. I'll trust gcc for now */
1147 return htons((unsigned short)sum
);
1149 return 0xFFFF; /* Use 0xFFFF for 0. 0 itself means none */
1153 * Create a socket. Initialise the socket, blank the addresses
1156 static int atalk_create(struct socket
*sock
, int protocol
)
1160 sk
= sk_alloc(PF_APPLETALK
, GFP_KERNEL
, 1);
1167 * We permit SOCK_DGRAM and RAW is an extension. It is
1168 * trivial to do and gives you the full ELAP frame.
1169 * Should be handy for CAP 8)
1173 sock
->ops
= &atalk_dgram_ops
;
1178 * TO DO: if you want to implement ADSP, here's the place to start
1181 sock->ops = &atalk_stream_ops;
1185 sk_free((void *)sk
);
1186 return (-ESOCKTNOSUPPORT
);
1191 sock_init_data(sock
,sk
);
1193 sk
->destruct
= NULL
;
1194 /* Checksums on by default */
1201 * Free a socket. No work needed
1203 static int atalk_release(struct socket
*sock
)
1205 struct sock
*sk
=sock
->sk
;
1211 sk
->state_change(sk
);
1215 atalk_destroy_socket(sk
);
1221 * Pick a source address if one is not given. Just return
1222 * an error if not supportable.
1224 static int atalk_pick_port(struct sockaddr_at
*sat
)
1226 for(sat
->sat_port
= ATPORT_RESERVED
; sat
->sat_port
< ATPORT_LAST
; sat
->sat_port
++)
1228 if(atalk_find_socket(sat
) == NULL
)
1229 return sat
->sat_port
;
1235 static int atalk_autobind(struct sock
*sk
)
1237 struct at_addr
*ap
= atalk_find_primary();
1238 struct sockaddr_at sat
;
1241 if(ap
== NULL
|| ap
->s_net
== htons(ATADDR_ANYNET
))
1242 return (-EADDRNOTAVAIL
);
1244 sk
->protinfo
.af_at
.src_net
= sat
.sat_addr
.s_net
= ap
->s_net
;
1245 sk
->protinfo
.af_at
.src_node
= sat
.sat_addr
.s_node
= ap
->s_node
;
1247 if((n
= atalk_pick_port(&sat
)) < 0)
1250 sk
->protinfo
.af_at
.src_port
= n
;
1251 atalk_insert_socket(sk
);
1258 * Set the address 'our end' of the connection.
1260 static int atalk_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
1263 struct sockaddr_at
*addr
=(struct sockaddr_at
*)uaddr
;
1270 if(addr_len
!= sizeof(struct sockaddr_at
))
1273 if(addr
->sat_family
!= AF_APPLETALK
)
1274 return (-EAFNOSUPPORT
);
1276 if(addr
->sat_addr
.s_net
== htons(ATADDR_ANYNET
))
1278 struct at_addr
*ap
=atalk_find_primary();
1281 return (-EADDRNOTAVAIL
);
1283 sk
->protinfo
.af_at
.src_net
= addr
->sat_addr
.s_net
= ap
->s_net
;
1284 sk
->protinfo
.af_at
.src_node
= addr
->sat_addr
.s_node
= ap
->s_node
;
1288 if(atalk_find_interface(addr
->sat_addr
.s_net
, addr
->sat_addr
.s_node
) == NULL
)
1289 return (-EADDRNOTAVAIL
);
1291 sk
->protinfo
.af_at
.src_net
= addr
->sat_addr
.s_net
;
1292 sk
->protinfo
.af_at
.src_node
= addr
->sat_addr
.s_node
;
1295 if(addr
->sat_port
== ATADDR_ANYPORT
)
1297 int n
= atalk_pick_port(addr
);
1301 sk
->protinfo
.af_at
.src_port
= addr
->sat_port
= n
;
1304 sk
->protinfo
.af_at
.src_port
= addr
->sat_port
;
1306 if(atalk_find_socket(addr
) != NULL
)
1307 return (-EADDRINUSE
);
1309 atalk_insert_socket(sk
);
1316 * Set the address we talk to.
1318 static int atalk_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
1319 int addr_len
, int flags
)
1321 struct sock
*sk
=sock
->sk
;
1322 struct sockaddr_at
*addr
;
1324 sk
->state
= TCP_CLOSE
;
1325 sock
->state
= SS_UNCONNECTED
;
1327 if(addr_len
!= sizeof(*addr
))
1329 addr
= (struct sockaddr_at
*)uaddr
;
1331 if(addr
->sat_family
!= AF_APPLETALK
)
1332 return (-EAFNOSUPPORT
);
1334 if(addr
->sat_addr
.s_node
== ATADDR_BCAST
&& !sk
->broadcast
)
1337 printk(KERN_WARNING
"%s is broken and did not set SO_BROADCAST. It will break when 2.2 is released.\n",
1346 if(atalk_autobind(sk
) < 0)
1350 if(atrtr_get_dev(&addr
->sat_addr
) == NULL
)
1351 return (-ENETUNREACH
);
1353 sk
->protinfo
.af_at
.dest_port
= addr
->sat_port
;
1354 sk
->protinfo
.af_at
.dest_net
= addr
->sat_addr
.s_net
;
1355 sk
->protinfo
.af_at
.dest_node
= addr
->sat_addr
.s_node
;
1357 sock
->state
= SS_CONNECTED
;
1358 sk
->state
= TCP_ESTABLISHED
;
1365 * Find the name of an AppleTalk socket. Just copy the right
1366 * fields into the sockaddr.
1368 static int atalk_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
1369 int *uaddr_len
, int peer
)
1371 struct sockaddr_at sat
;
1377 if(atalk_autobind(sk
) < 0)
1381 *uaddr_len
= sizeof(struct sockaddr_at
);
1385 if(sk
->state
!= TCP_ESTABLISHED
)
1387 sat
.sat_addr
.s_net
= sk
->protinfo
.af_at
.dest_net
;
1388 sat
.sat_addr
.s_node
= sk
->protinfo
.af_at
.dest_node
;
1389 sat
.sat_port
= sk
->protinfo
.af_at
.dest_port
;
1393 sat
.sat_addr
.s_net
= sk
->protinfo
.af_at
.src_net
;
1394 sat
.sat_addr
.s_node
= sk
->protinfo
.af_at
.src_node
;
1395 sat
.sat_port
= sk
->protinfo
.af_at
.src_port
;
1398 sat
.sat_family
= AF_APPLETALK
;
1399 memcpy(uaddr
, &sat
, sizeof(sat
));
1405 * Receive a packet (in skb) from device dev. This has come from the SNAP
1406 * decoder, and on entry skb->h.raw is the DDP header, skb->len is the DDP
1407 * header, skb->len is the DDP length. The physical headers have been
1408 * extracted. PPP should probably pass frames marked as for this layer.
1409 * [ie ARPHRD_ETHERTALK]
1411 static int atalk_rcv(struct sk_buff
*skb
, struct net_device
*dev
, struct packet_type
*pt
)
1414 struct ddpehdr
*ddp
=(void *)skb
->h
.raw
;
1415 struct atalk_iface
*atif
;
1416 struct sockaddr_at tosat
;
1418 struct ddpebits ddphv
;
1421 if(skb
->len
< sizeof(*ddp
))
1428 * Fix up the length field [Ok this is horrible but otherwise
1429 * I end up with unions of bit fields and messy bit field order
1430 * compiler/endian dependencies..]
1432 * FIXME: This is a write to a shared object. Granted it
1433 * happens to be safe BUT.. (Its safe as user space will not
1434 * run until we put it back)
1437 *((__u16
*)&ddphv
) = ntohs(*((__u16
*)ddp
));
1440 * Trim buffer in case of stray trailing data
1445 skb_trim(skb
, min(skb
->len
, ddphv
.deh_len
));
1448 * Size check to see if ddp->deh_len was crap
1449 * (Otherwise we'll detonate most spectacularly
1450 * in the middle of recvmsg()).
1452 if(skb
->len
< sizeof(*ddp
))
1459 * Any checksums. Note we don't do htons() on this == is assumed to be
1460 * valid for net byte orders all over the networking code...
1462 if(ddp
->deh_sum
&& atalk_checksum(ddp
, ddphv
.deh_len
) != ddp
->deh_sum
)
1464 /* Not a valid AppleTalk frame - dustbin time */
1469 /* Check the packet is aimed at us */
1471 if(ddp
->deh_dnet
== 0) /* Net 0 is 'this network' */
1472 atif
= atalk_find_anynet(ddp
->deh_dnode
, dev
);
1474 atif
= atalk_find_interface(ddp
->deh_dnet
, ddp
->deh_dnode
);
1477 * Not ours, so we route the packet via the correct AppleTalk interface.
1481 struct atalk_route
*rt
;
1485 * Don't route multicast, etc., packets, or packets
1486 * sent to "this network"
1488 if (skb
->pkt_type
!= PACKET_HOST
|| ddp
->deh_dnet
== 0)
1492 * Can it ever happen that a packet is from a PPP iface and needs to be broadcast onto the default network?
1494 if (dev
->type
== ARPHRD_PPP
)
1495 printk(KERN_DEBUG
"AppleTalk: didn't forward broadcast packet received from PPP iface\n");
1501 ta
.s_net
= ddp
->deh_dnet
;
1502 ta
.s_node
= ddp
->deh_dnode
;
1504 /* Route the packet */
1505 rt
= atrtr_find(&ta
);
1506 if(rt
== NULL
|| ddphv
.deh_hops
== DDP_MAXHOPS
)
1514 * Route goes through another gateway, so
1515 * set the target to the gateway instead.
1517 if(rt
->flags
& RTF_GATEWAY
)
1519 ta
.s_net
= rt
->gateway
.s_net
;
1520 ta
.s_node
= rt
->gateway
.s_node
;
1523 /* Fix up skb->len field */
1524 skb_trim(skb
, min(origlen
, rt
->dev
->hard_header_len
+
1525 ddp_dl
->header_length
+ ddphv
.deh_len
));
1527 /* Mend the byte order */
1528 *((__u16
*)ddp
) = ntohs(*((__u16
*)&ddphv
));
1531 * Send the buffer onwards
1533 * Now we must always be careful. If it's come from
1534 * LocalTalk to EtherTalk it might not fit
1536 * Order matters here: If a packet has to be copied
1537 * to make a new headroom (rare hopefully) then it
1538 * won't need unsharing.
1540 * Note. ddp-> becomes invalid at the realloc.
1542 if(skb_headroom(skb
) < 22)
1543 /* 22 bytes - 12 ether, 2 len, 3 802.2 5 snap */
1544 skb
= skb_realloc_headroom(skb
, 32);
1546 skb
= skb_unshare(skb
, GFP_ATOMIC
);
1549 * If the buffer didn't vanish into the lack of
1550 * space bitbucket we can send it.
1554 if(aarp_send_ddp(rt
->dev
, skb
, &ta
, NULL
) == -1)
1561 #if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
1563 * Check if IP-over-DDP
1565 if(skb
->data
[12] == 22)
1567 struct net_device
*dev
;
1569 /* This needs to be able to handle ipddp"N" devices */
1570 if((dev
= __dev_get_by_name("ipddp0")) == NULL
)
1573 skb
->protocol
= htons(ETH_P_IP
);
1576 skb
->h
.raw
= skb
->data
;
1578 ((struct net_device_stats
*)dev
->priv
)->rx_packets
++;
1579 ((struct net_device_stats
*)dev
->priv
)->rx_bytes
+= skb
->len
+13;
1580 netif_rx(skb
); /* Send the SKB up to a higher place. */
1587 * Which socket - atalk_search_socket() looks for a *full match*
1588 * of the <net,node,port> tuple.
1590 tosat
.sat_addr
.s_net
= ddp
->deh_dnet
;
1591 tosat
.sat_addr
.s_node
= ddp
->deh_dnode
;
1592 tosat
.sat_port
= ddp
->deh_dport
;
1594 sock
= atalk_search_socket(&tosat
, atif
);
1596 if(sock
== NULL
) /* But not one of our sockets */
1603 * Queue packet (standard)
1608 if(sock_queue_rcv_skb(sock
, skb
) < 0)
1615 * Receive a LocalTalk frame. We make some demands on the caller here.
1616 * Caller must provide enough headroom on the packet to pull the short
1617 * header and append a long one.
1619 static int ltalk_rcv(struct sk_buff
*skb
, struct net_device
*dev
, struct packet_type
*pt
)
1621 struct ddpehdr
*ddp
;
1625 * Expand any short form frames.
1627 if(skb
->mac
.raw
[2] == 1)
1633 ap
= atalk_find_dev_addr(dev
);
1634 if(ap
== NULL
|| skb
->len
< sizeof(struct ddpshdr
))
1641 * The push leaves us with a ddephdr not an shdr, and
1642 * handily the port bytes in the right place preset.
1645 skb_push(skb
, sizeof(*ddp
) - 4);
1646 ddp
= (struct ddpehdr
*)skb
->data
;
1649 * Now fill in the long header.
1653 * These two first. The mac overlays the new source/dest
1654 * network information so we MUST copy these before
1655 * we write the network numbers !
1658 ddp
->deh_dnode
= skb
->mac
.raw
[0]; /* From physical header */
1659 ddp
->deh_snode
= skb
->mac
.raw
[1]; /* From physical header */
1661 ddp
->deh_dnet
= ap
->s_net
; /* Network number */
1662 ddp
->deh_snet
= ap
->s_net
;
1663 ddp
->deh_sum
= 0; /* No checksum */
1665 * Not sure about this bit...
1667 ddp
->deh_len
= skb
->len
;
1668 ddp
->deh_hops
= DDP_MAXHOPS
; /* Non routable, so force a drop
1669 if we slip up later */
1671 /* Mend the byte order */
1672 *((__u16
*)ddp
) = htons(*((__u16
*)ddp
));
1674 skb
->h
.raw
= skb
->data
;
1676 return (atalk_rcv(skb
, dev
, pt
));
1679 static int atalk_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int len
,
1680 struct scm_cookie
*scm
)
1682 struct sock
*sk
=sock
->sk
;
1683 struct sockaddr_at
*usat
=(struct sockaddr_at
*)msg
->msg_name
;
1684 struct sockaddr_at local_satalk
, gsat
;
1685 struct sk_buff
*skb
;
1686 struct net_device
*dev
;
1687 struct ddpehdr
*ddp
;
1689 struct atalk_route
*rt
;
1692 int flags
= msg
->msg_flags
;
1694 if(flags
& ~MSG_DONTWAIT
)
1704 if(atalk_autobind(sk
) < 0)
1708 if(msg
->msg_namelen
< sizeof(*usat
))
1710 if(usat
->sat_family
!= AF_APPLETALK
)
1713 /* netatalk doesn't implement this check */
1714 if(usat
->sat_addr
.s_node
== ATADDR_BCAST
&& !sk
->broadcast
)
1716 printk(KERN_INFO
"SO_BROADCAST: Fix your netatalk as it will break before 2.2\n");
1724 if(sk
->state
!= TCP_ESTABLISHED
)
1726 usat
=& local_satalk
;
1727 usat
->sat_family
= AF_APPLETALK
;
1728 usat
->sat_port
= sk
->protinfo
.af_at
.dest_port
;
1729 usat
->sat_addr
.s_node
= sk
->protinfo
.af_at
.dest_node
;
1730 usat
->sat_addr
.s_net
= sk
->protinfo
.af_at
.dest_net
;
1733 /* Build a packet */
1735 SOCK_DEBUG(sk
, "SK %p: Got address.\n",sk
);
1738 size
= sizeof(struct ddpehdr
) + len
+ ddp_dl
->header_length
;
1740 if(usat
->sat_addr
.s_net
!= 0 || usat
->sat_addr
.s_node
== ATADDR_ANYNODE
)
1742 rt
= atrtr_find(&usat
->sat_addr
);
1744 return (-ENETUNREACH
);
1749 struct at_addr at_hint
;
1751 at_hint
.s_net
= sk
->protinfo
.af_at
.src_net
;
1752 rt
= atrtr_find(&at_hint
);
1754 return (-ENETUNREACH
);
1758 SOCK_DEBUG(sk
, "SK %p: Size needed %d, device %s\n", sk
, size
, dev
->name
);
1760 size
+= dev
->hard_header_len
;
1762 skb
= sock_alloc_send_skb(sk
, size
, 0, flags
&MSG_DONTWAIT
, &err
);
1767 skb_reserve(skb
, ddp_dl
->header_length
);
1768 skb_reserve(skb
, dev
->hard_header_len
);
1772 SOCK_DEBUG(sk
, "SK %p: Begin build.\n", sk
);
1774 ddp
= (struct ddpehdr
*)skb_put(skb
,sizeof(struct ddpehdr
));
1777 ddp
->deh_len
= len
+ sizeof(*ddp
);
1779 * Fix up the length field [Ok this is horrible but otherwise
1780 * I end up with unions of bit fields and messy bit field order
1781 * compiler/endian dependencies..
1783 *((__u16
*)ddp
) = ntohs(*((__u16
*)ddp
));
1785 ddp
->deh_dnet
= usat
->sat_addr
.s_net
;
1786 ddp
->deh_snet
= sk
->protinfo
.af_at
.src_net
;
1787 ddp
->deh_dnode
= usat
->sat_addr
.s_node
;
1788 ddp
->deh_snode
= sk
->protinfo
.af_at
.src_node
;
1789 ddp
->deh_dport
= usat
->sat_port
;
1790 ddp
->deh_sport
= sk
->protinfo
.af_at
.src_port
;
1792 SOCK_DEBUG(sk
, "SK %p: Copy user data (%d bytes).\n", sk
, len
);
1794 err
= memcpy_fromiovec(skb_put(skb
,len
), msg
->msg_iov
, len
);
1801 if(sk
->no_check
== 1)
1804 ddp
->deh_sum
= atalk_checksum(ddp
, len
+ sizeof(*ddp
));
1807 * Loopback broadcast packets to non gateway targets (ie routes
1808 * to group we are in)
1810 if(ddp
->deh_dnode
== ATADDR_BCAST
)
1812 if((!(rt
->flags
&RTF_GATEWAY
)) && (!(dev
->flags
&IFF_LOOPBACK
)))
1814 struct sk_buff
*skb2
= skb_copy(skb
, GFP_KERNEL
);
1818 SOCK_DEBUG(sk
, "SK %p: send out(copy).\n", sk
);
1819 if(aarp_send_ddp(dev
, skb2
, &usat
->sat_addr
, NULL
) == -1)
1821 /* else queued/sent above in the aarp queue */
1826 if((dev
->flags
& IFF_LOOPBACK
) || loopback
)
1828 SOCK_DEBUG(sk
, "SK %p: Loop back.\n", sk
);
1831 ddp_dl
->datalink_header(ddp_dl
, skb
, dev
->dev_addr
);
1832 skb
->mac
.raw
= skb
->data
;
1833 skb
->h
.raw
= skb
->data
+ ddp_dl
->header_length
+ dev
->hard_header_len
;
1834 skb_pull(skb
,dev
->hard_header_len
);
1835 skb_pull(skb
,ddp_dl
->header_length
);
1836 atalk_rcv(skb
, dev
, NULL
);
1840 SOCK_DEBUG(sk
, "SK %p: send out.\n", sk
);
1841 if (rt
->flags
& RTF_GATEWAY
)
1843 gsat
.sat_addr
= rt
->gateway
;
1847 if(aarp_send_ddp(dev
, skb
, &usat
->sat_addr
, NULL
) == -1)
1849 /* else queued/sent above in the aarp queue */
1851 SOCK_DEBUG(sk
, "SK %p: Done write (%d).\n", sk
, len
);
1856 static int atalk_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
1857 int flags
, struct scm_cookie
*scm
)
1859 struct sock
*sk
=sock
->sk
;
1860 struct sockaddr_at
*sat
=(struct sockaddr_at
*)msg
->msg_name
;
1861 struct ddpehdr
*ddp
= NULL
;
1862 struct ddpebits ddphv
;
1864 struct sk_buff
*skb
;
1868 skb
= skb_recv_datagram(sk
,flags
&~MSG_DONTWAIT
,flags
&MSG_DONTWAIT
,&err
);
1872 ddp
= (struct ddpehdr
*)(skb
->h
.raw
);
1873 *((__u16
*)&ddphv
) = ntohs(*((__u16
*)ddp
));
1875 if(sk
->type
== SOCK_RAW
)
1877 copied
= ddphv
.deh_len
;
1881 msg
->msg_flags
|= MSG_TRUNC
;
1884 err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
1888 copied
= ddphv
.deh_len
- sizeof(*ddp
);
1892 msg
->msg_flags
|= MSG_TRUNC
;
1894 err
= skb_copy_datagram_iovec(skb
,sizeof(*ddp
),msg
->msg_iov
,copied
);
1901 sat
->sat_family
= AF_APPLETALK
;
1902 sat
->sat_port
= ddp
->deh_sport
;
1903 sat
->sat_addr
.s_node
= ddp
->deh_snode
;
1904 sat
->sat_addr
.s_net
= ddp
->deh_snet
;
1906 msg
->msg_namelen
= sizeof(*sat
);
1909 skb_free_datagram(sk
, skb
); /* Free the datagram. */
1911 return (err
? err
: (copied
));
1916 * AppleTalk ioctl calls.
1918 static int atalk_ioctl(struct socket
*sock
,unsigned int cmd
, unsigned long arg
)
1921 struct sock
*sk
=sock
->sk
;
1929 amount
= sk
->sndbuf
- atomic_read(&sk
->wmem_alloc
);
1936 struct sk_buff
*skb
;
1937 /* These two are safe on a single CPU system as only user tasks fiddle here */
1938 if((skb
= skb_peek(&sk
->receive_queue
)) != NULL
)
1939 amount
= skb
->len
-sizeof(struct ddpehdr
);
1946 if(sk
->stamp
.tv_sec
== 0)
1948 return (copy_to_user((void *)arg
,&sk
->stamp
,sizeof(struct timeval
)) ? -EFAULT
: 0);
1957 if(!capable(CAP_NET_ADMIN
))
1959 return (atrtr_ioctl(cmd
,(void *)arg
));
1966 case SIOCGIFBRDADDR
:
1967 case SIOCATALKDIFADDR
:
1969 case SIOCSARP
: /* proxy AARP */
1970 case SIOCDARP
: /* proxy AARP */
1971 return (atif_ioctl(cmd
,(void *)arg
));
1974 * Physical layer ioctl calls
1988 return ((dev_ioctl(cmd
,(void *) arg
)));
1991 case SIOCSIFBRDADDR
:
1992 case SIOCGIFNETMASK
:
1993 case SIOCSIFNETMASK
:
1996 case SIOCGIFDSTADDR
:
1997 case SIOCSIFDSTADDR
:
2004 return (put_user(amount
, (int *)arg
));
2007 static struct net_proto_family atalk_family_ops
=
2013 static struct proto_ops
SOCKOPS_WRAPPED(atalk_dgram_ops
)=
2035 #include <linux/smp_lock.h>
2036 SOCKOPS_WRAP(atalk_dgram
, PF_APPLETALK
);
2038 static struct notifier_block ddp_notifier
=
2045 struct packet_type ltalk_packet_type
=
2054 struct packet_type ppptalk_packet_type
=
2063 static char ddp_snap_id
[] = {0x08, 0x00, 0x07, 0x80, 0x9B};
2066 * Export symbols for use by drivers when AppleTalk is a module.
2068 EXPORT_SYMBOL(aarp_send_ddp
);
2069 EXPORT_SYMBOL(atrtr_get_dev
);
2070 EXPORT_SYMBOL(atalk_find_dev_addr
);
2072 #ifdef CONFIG_PROC_FS
2073 static struct proc_dir_entry proc_appletalk
=
2075 PROC_NET_ATALK
, 9, "appletalk",
2076 S_IFREG
| S_IRUGO
, 1, 0, 0,
2077 0, &proc_net_inode_operations
,
2081 static struct proc_dir_entry proc_atalk_route
=
2083 PROC_NET_AT_ROUTE
, 11,"atalk_route",
2084 S_IFREG
| S_IRUGO
, 1, 0, 0,
2085 0, &proc_net_inode_operations
,
2089 static struct proc_dir_entry proc_atalk_iface
=
2091 PROC_NET_ATIF
, 11,"atalk_iface",
2092 S_IFREG
| S_IRUGO
, 1, 0, 0,
2093 0, &proc_net_inode_operations
,
2096 #endif /* CONFIG_PROC_FS */
2098 /* Called by proto.c on kernel start up */
2100 void __init
atalk_proto_init(struct net_proto
*pro
)
2102 (void) sock_register(&atalk_family_ops
);
2103 if((ddp_dl
= register_snap_client(ddp_snap_id
, atalk_rcv
)) == NULL
)
2104 printk(KERN_CRIT
"Unable to register DDP with SNAP.\n");
2106 ltalk_packet_type
.type
= htons(ETH_P_LOCALTALK
);
2107 dev_add_pack(<alk_packet_type
);
2109 ppptalk_packet_type
.type
= htons(ETH_P_PPPTALK
);
2110 dev_add_pack(&ppptalk_packet_type
);
2112 register_netdevice_notifier(&ddp_notifier
);
2115 #ifdef CONFIG_PROC_FS
2116 proc_net_register(&proc_appletalk
);
2117 proc_net_register(&proc_atalk_route
);
2118 proc_net_register(&proc_atalk_iface
);
2120 aarp_register_proc_fs();
2121 #endif /* CONFIG_PROC_FS */
2123 #ifdef CONFIG_SYSCTL
2124 atalk_register_sysctl();
2125 #endif /* CONFIG_SYSCTL */
2127 printk(KERN_INFO
"NET4: AppleTalk 0.18 for Linux NET4.0\n");
2132 int init_module(void)
2134 atalk_proto_init(NULL
);
2139 * Note on MOD_{INC,DEC}_USE_COUNT:
2141 * Use counts are incremented/decremented when
2142 * sockets are created/deleted.
2144 * AppleTalk interfaces are not incremented untill atalkd is run
2145 * and are only decremented when they are downed.
2147 * Ergo, before the AppleTalk module can be removed, all AppleTalk
2148 * sockets be closed from user space.
2151 void cleanup_module(void)
2153 #ifdef CONFIG_SYSCTL
2154 atalk_unregister_sysctl();
2155 #endif /* CONFIG_SYSCTL */
2157 #ifdef CONFIG_PROC_FS
2158 proc_net_unregister(PROC_NET_ATALK
);
2159 proc_net_unregister(PROC_NET_AT_ROUTE
);
2160 proc_net_unregister(PROC_NET_ATIF
);
2162 aarp_unregister_proc_fs();
2163 #endif /* CONFIG_PROC_FS */
2165 aarp_cleanup_module(); /* General aarp clean-up. */
2167 unregister_netdevice_notifier(&ddp_notifier
);
2168 dev_remove_pack(<alk_packet_type
);
2169 dev_remove_pack(&ppptalk_packet_type
);
2170 unregister_snap_client(ddp_snap_id
);
2171 sock_unregister(PF_APPLETALK
);
2177 #endif /* CONFIG_ATALK || CONFIG_ATALK_MODULE */