2 * Implements an IPX socket layer.
4 * This code is derived from work by
5 * Ross Biro : Writing the original IP stack
6 * Fred Van Kempen : Tidying up the TCP/IP
8 * Many thanks go to Keith Baker, Institute For Industrial Information
9 * Technology Ltd, Swansea University for allowing me to work on this
10 * in my own time even though it was in some ways related to commercial
11 * work I am currently employed to do there.
13 * All the material in this file is subject to the Gnu license version 2.
14 * Neither Alan Cox nor the Swansea University Computer Society admit
15 * liability nor provide warranty for any of this software. This material
16 * is provided as is and at no charge.
18 * Revision 0.21: Uses the new generic socket option code.
19 * Revision 0.22: Gcc clean ups and drop out device registration. Use the
20 * new multi-protocol edition of hard_header
21 * Revision 0.23: IPX /proc by Mark Evans. Adding a route will
22 * will overwrite any existing route to the same network.
23 * Revision 0.24: Supports new /proc with no 4K limit
24 * Revision 0.25: Add ephemeral sockets, passive local network
25 * identification, support for local net 0 and
26 * multiple datalinks <Greg Page>
27 * Revision 0.26: Device drop kills IPX routes via it. (needed for module)
28 * Revision 0.27: Autobind <Mark Evans>
29 * Revision 0.28: Small fix for multiple local networks <Thomas Winder>
30 * Revision 0.29: Assorted major errors removed <Mark Evans>
31 * Small correction to promisc mode error fix <Alan Cox>
32 * Asynchronous I/O support. Changed to use notifiers
33 * and the newer packet_type stuff. Assorted major
34 * fixes <Alejandro Liu>
35 * Revision 0.30: Moved to net/ipx/... <Alan Cox>
36 * Don't set address length on recvfrom that errors.
37 * Incorrect verify_area.
38 * Revision 0.31: New sk_buffs. This still needs a lot of
40 * Revision 0.32: Using sock_alloc_send_skb, firewall hooks. <Alan Cox>
41 * Supports sendmsg/recvmsg
42 * Revision 0.33: Internal network support, routing changes, uses a
43 * protocol private area for ipx data.
44 * Revision 0.34: Module support. <Jim Freeman>
45 * Revision 0.35: Checksum support. <Neil Turton>, hooked in by <Alan Cox>
46 * Handles WIN95 discovery packets <Volker Lendecke>
47 * Revision 0.36: Internal bump up for 2.1
48 * Revision 0.37: Began adding POSIXisms.
49 * Revision 0.38: Asynchronous socket stuff made current.
50 * Revision 0.39: SPX interfaces
51 * Revision 0.40: Tiny SIOCGSTAMP fix (chris@cybernet.co.nz)
52 * Revision 0.41: 802.2TR removed (p.norton@computer.org)
53 * Fixed connecting to primary net,
54 * Automatic binding on send & receive,
55 * Martijn van Oosterhout <kleptogimp@geocities.com>
56 * Revision 042: Multithreading - use spinlocks and refcounting to
57 * protect some structures: ipx_interface sock list, list
58 * of ipx interfaces, etc.
59 * Bugfixes - do refcounting on net_devices, check function
60 * results, etc. Thanks to davem and freitag for
61 * suggestions and guidance.
62 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>,
64 * Revision 043: Shared SKBs, don't mangle packets, some cleanups
65 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>,
67 * Revision 044: Call ipxitf_hold on NETDEV_UP (acme)
68 * Revision 045: fix PPROP routing bug (acme)
69 * Revision 046: Further fixes to PPROP, ipxitf_create_internal was
70 * doing an unneeded MOD_INC_USE_COUNT, implement
71 * sysctl for ipx_pprop_broacasting, fix the ipx sysctl
72 * handling, making it dynamic, some cleanups, thanks to
73 * Petr Vandrovec for review and good suggestions. (acme)
74 * Revision 047: Cleanups, CodingStyle changes, move the ncp connection
75 * hack out of line (acme)
77 * Protect the module by a MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT
78 * pair. Also, now usage count is managed this way
79 * -Count one if the auto_interface mode is on
80 * -Count one per configured interface
82 * Jacques Gelinas (jacques@solucorp.qc.ca)
85 * Portions Copyright (c) 1995 Caldera, Inc. <greg@caldera.com>
86 * Neither Greg Page nor Caldera, Inc. admit liability nor provide
87 * warranty for any of this software. This material is provided
88 * "AS-IS" and at no charge.
91 #include <linux/config.h>
92 #include <linux/module.h>
93 #include <linux/errno.h>
94 #include <linux/types.h>
95 #include <linux/socket.h>
97 #include <linux/kernel.h>
98 #include <linux/sched.h>
99 #include <linux/timer.h>
100 #include <linux/string.h>
101 #include <linux/sockios.h>
102 #include <linux/net.h>
103 #include <linux/netdevice.h>
105 #include <linux/inet.h>
106 #include <linux/route.h>
107 #include <net/sock.h>
108 #include <asm/uaccess.h>
109 #include <asm/system.h>
110 #include <linux/fcntl.h>
111 #include <linux/mm.h>
112 #include <linux/termios.h> /* For TIOCOUTQ/INQ */
113 #include <linux/interrupt.h>
114 #include <net/p8022.h>
115 #include <net/psnap.h>
116 #include <linux/proc_fs.h>
117 #include <linux/stat.h>
118 #include <linux/init.h>
119 #include <linux/if_arp.h>
122 extern void ipx_register_sysctl(void);
123 extern void ipx_unregister_sysctl(void);
125 #define ipx_register_sysctl()
126 #define ipx_unregister_sysctl()
129 /* Configuration Variables */
130 static unsigned char ipxcfg_max_hops = 16;
131 static char ipxcfg_auto_select_primary;
132 static char ipxcfg_auto_create_interfaces;
133 int sysctl_ipx_pprop_broadcasting = 1;
135 /* Global Variables */
136 static struct datalink_proto *p8022_datalink;
137 static struct datalink_proto *pEII_datalink;
138 static struct datalink_proto *p8023_datalink;
139 static struct datalink_proto *pSNAP_datalink;
141 static struct proto_ops ipx_dgram_ops;
143 static struct net_proto_family *spx_family_ops;
145 static ipx_route *ipx_routes;
146 static rwlock_t ipx_routes_lock = RW_LOCK_UNLOCKED;
148 static ipx_interface *ipx_interfaces;
149 static spinlock_t ipx_interfaces_lock = SPIN_LOCK_UNLOCKED;
151 static ipx_interface *ipx_primary_net;
152 static ipx_interface *ipx_internal_net;
154 #define IPX_SKB_CB(__skb) ((struct ipx_cb *)&((__skb)->cb[0]))
156 #undef IPX_REFCNT_DEBUG
157 #ifdef IPX_REFCNT_DEBUG
158 atomic_t ipx_sock_nr;
161 static void ipxcfg_set_auto_create(char val)
163 if (ipxcfg_auto_create_interfaces != val) {
169 ipxcfg_auto_create_interfaces = val;
173 static void ipxcfg_set_auto_select(char val)
175 ipxcfg_auto_select_primary = val;
176 if (val && !ipx_primary_net)
177 ipx_primary_net = ipx_interfaces;
180 static int ipxcfg_get_config_data(ipx_config_data *arg)
182 ipx_config_data vals;
184 vals.ipxcfg_auto_create_interfaces = ipxcfg_auto_create_interfaces;
185 vals.ipxcfg_auto_select_primary = ipxcfg_auto_select_primary;
187 return copy_to_user(arg, &vals, sizeof(vals)) ? -EFAULT : 0;
190 /* Handlers for the socket list. */
192 static inline void ipxitf_hold(ipx_interface *intrfc)
194 atomic_inc(&intrfc->refcnt);
197 static void ipxitf_down(ipx_interface *intrfc);
199 static inline void ipxitf_put(ipx_interface *intrfc)
201 if (atomic_dec_and_test(&intrfc->refcnt))
205 static void __ipxitf_down(ipx_interface *intrfc);
207 static inline void __ipxitf_put(ipx_interface *intrfc)
209 if (atomic_dec_and_test(&intrfc->refcnt))
210 __ipxitf_down(intrfc);
213 * Note: Sockets may not be removed _during_ an interrupt or inet_bh
214 * handler using this technique. They can be added although we do not
218 void ipx_remove_socket(struct sock *sk)
221 ipx_interface *intrfc;
223 /* Determine interface with which socket is associated */
224 intrfc = sk->protinfo.af_ipx.intrfc;
229 spin_lock_bh(&intrfc->if_sklist_lock);
230 s = intrfc->if_sklist;
232 intrfc->if_sklist = s->next;
236 while (s && s->next) {
244 spin_unlock_bh(&intrfc->if_sklist_lock);
250 static void ipx_destroy_socket(struct sock *sk)
252 ipx_remove_socket(sk);
253 skb_queue_purge(&sk->receive_queue);
254 #ifdef IPX_REFCNT_DEBUG
255 atomic_dec(&ipx_sock_nr);
256 printk(KERN_DEBUG "IPX socket %p released, %d are still alive\n", sk,
257 atomic_read(&ipx_sock_nr));
258 if (atomic_read(&sk->refcnt) != 1)
259 printk(KERN_DEBUG "Destruction sock ipx %p delayed, cnt=%d\n",
260 sk, atomic_read(&sk->refcnt));
266 * The following code is used to support IPX Interfaces (IPXITF). An
267 * IPX interface is defined by a physical device and a frame type.
269 static ipx_route * ipxrtr_lookup(__u32);
271 /* ipxitf_clear_primary_net has to be called with ipx_interfaces_lock held */
273 static void ipxitf_clear_primary_net(void)
275 ipx_primary_net = ipxcfg_auto_select_primary ? ipx_interfaces : NULL;
278 static ipx_interface *__ipxitf_find_using_phys(struct net_device *dev,
279 unsigned short datalink)
281 ipx_interface *i = ipx_interfaces;
283 while (i && (i->if_dev != dev || i->if_dlink_type != datalink))
289 static ipx_interface *ipxitf_find_using_phys(struct net_device *dev,
290 unsigned short datalink)
294 spin_lock_bh(&ipx_interfaces_lock);
295 i = __ipxitf_find_using_phys(dev, datalink);
298 spin_unlock_bh(&ipx_interfaces_lock);
302 static ipx_interface *ipxitf_find_using_net(__u32 net)
306 spin_lock_bh(&ipx_interfaces_lock);
308 for (i = ipx_interfaces; i && i->if_netnum != net;
315 spin_unlock_bh(&ipx_interfaces_lock);
320 /* Sockets are bound to a particular IPX interface. */
321 static void ipxitf_insert_socket(ipx_interface *intrfc, struct sock *sk)
325 spin_lock_bh(&intrfc->if_sklist_lock);
326 sk->protinfo.af_ipx.intrfc = intrfc;
328 if (!intrfc->if_sklist)
329 intrfc->if_sklist = sk;
331 struct sock *s = intrfc->if_sklist;
336 spin_unlock_bh(&intrfc->if_sklist_lock);
340 /* caller must hold intrfc->if_sklist_lock */
341 static struct sock *__ipxitf_find_socket(ipx_interface *intrfc,
344 struct sock *s = intrfc->if_sklist;
346 while (s && s->protinfo.af_ipx.port != port)
352 /* caller must hold a reference to intrfc */
353 static struct sock *ipxitf_find_socket(ipx_interface *intrfc,
358 spin_lock_bh(&intrfc->if_sklist_lock);
359 s = __ipxitf_find_socket(intrfc, port);
362 spin_unlock_bh(&intrfc->if_sklist_lock);
367 #ifdef CONFIG_IPX_INTERN
368 static struct sock *ipxitf_find_internal_socket(ipx_interface *intrfc,
369 unsigned char *node, unsigned short port)
374 spin_lock_bh(&intrfc->if_sklist_lock);
375 s = intrfc->if_sklist;
378 if (s->protinfo.af_ipx.port == port &&
379 !memcmp(node, s->protinfo.af_ipx.node, IPX_NODE_LEN))
383 spin_unlock_bh(&intrfc->if_sklist_lock);
390 static void ipxrtr_del_routes(ipx_interface *);
392 static void __ipxitf_down(ipx_interface *intrfc)
396 /* Delete all routes associated with this interface */
397 ipxrtr_del_routes(intrfc);
399 spin_lock_bh(&intrfc->if_sklist_lock);
401 for (s = intrfc->if_sklist; s;) {
404 s->protinfo.af_ipx.intrfc = NULL;
405 s->protinfo.af_ipx.port = 0;
406 s->zapped = 1; /* Indicates it is no longer bound */
411 intrfc->if_sklist = NULL;
412 spin_unlock_bh(&intrfc->if_sklist_lock);
414 /* remove this interface from list */
415 if (intrfc == ipx_interfaces)
416 ipx_interfaces = intrfc->if_next;
418 ipx_interface *i = ipx_interfaces;
419 while (i && i->if_next != intrfc)
421 if (i && i->if_next == intrfc)
422 i->if_next = intrfc->if_next;
425 /* remove this interface from *special* networks */
426 if (intrfc == ipx_primary_net)
427 ipxitf_clear_primary_net();
428 if (intrfc == ipx_internal_net)
429 ipx_internal_net = NULL;
432 dev_put(intrfc->if_dev);
437 static void ipxitf_down(ipx_interface *intrfc)
439 spin_lock_bh(&ipx_interfaces_lock);
440 __ipxitf_down(intrfc);
441 spin_unlock_bh(&ipx_interfaces_lock);
444 static int ipxitf_device_event(struct notifier_block *notifier,
445 unsigned long event, void *ptr)
447 struct net_device *dev = ptr;
448 ipx_interface *i, *tmp;
450 if (event != NETDEV_DOWN && event != NETDEV_UP)
453 spin_lock_bh(&ipx_interfaces_lock);
454 for (i = ipx_interfaces; i;) {
456 if (i->if_dev == dev) {
457 if (event == NETDEV_UP)
464 spin_unlock_bh(&ipx_interfaces_lock);
465 out: return NOTIFY_DONE;
468 static void ipxitf_def_skb_handler(struct sock *sock, struct sk_buff *skb)
470 if (sock_queue_rcv_skb(sock, skb) < 0)
475 * On input skb->sk is NULL. Nobody is charged for the memory.
478 /* caller must hold a reference to intrfc */
480 #ifdef CONFIG_IPX_INTERN
481 static int ipxitf_demux_socket(ipx_interface *intrfc, struct sk_buff *skb,
484 struct ipxhdr *ipx = skb->nh.ipxh;
485 int is_broadcast = !memcmp(ipx->ipx_dest.node, ipx_broadcast_node,
490 spin_lock_bh(&intrfc->if_sklist_lock);
491 s = intrfc->if_sklist;
494 if (s->protinfo.af_ipx.port == ipx->ipx_dest.sock &&
495 (is_broadcast || !memcmp(ipx->ipx_dest.node,
496 s->protinfo.af_ipx.node,
498 /* We found a socket to which to send */
499 struct sk_buff *skb1;
502 skb1 = skb_clone(skb, GFP_ATOMIC);
508 copy = 1; /* skb may only be used once */
510 ipxitf_def_skb_handler(s, skb1);
512 /* On an external interface, one socket can listen */
513 if (intrfc != ipx_internal_net)
519 /* skb was solely for us, and we did not make a copy, so free it. */
524 out: spin_unlock_bh(&intrfc->if_sklist_lock);
528 static struct sock *ncp_connection_hack(ipx_interface *intrfc,
531 /* The packet's target is a NCP connection handler. We want to hand it
532 * to the correct socket directly within the kernel, so that the
533 * mars_nwe packet distribution process does not have to do it. Here we
534 * only care about NCP and BURST packets.
536 * You might call this a hack, but believe me, you do not want a
537 * complete NCP layer in the kernel, and this is VERY fast as well. */
538 struct sock *sk = NULL;
540 u8 *ncphdr = (u8 *)(ipx + 1);
542 if (*ncphdr == 0x22 && *(ncphdr + 1) == 0x22) /* NCP request */
543 connection = (((int) *(ncphdr + 5)) << 8) | (int) *(ncphdr + 3);
544 else if (*ncphdr == 0x77 && *(ncphdr + 1) == 0x77) /* BURST packet */
545 connection = (((int) *(ncphdr + 9)) << 8) | (int) *(ncphdr + 8);
548 /* Now we have to look for a special NCP connection handling
549 * socket. Only these sockets have ipx_ncp_conn != 0, set by
551 spin_lock_bh(&intrfc->if_sklist_lock);
552 for (sk = intrfc->if_sklist;
553 sk && sk->protinfo.af_ipx.ipx_ncp_conn != connection;
557 spin_unlock_bh(&intrfc->if_sklist_lock);
562 static int ipxitf_demux_socket(ipx_interface *intrfc, struct sk_buff *skb,
565 struct ipxhdr *ipx = skb->nh.ipxh;
566 struct sock *sock1 = NULL, *sock2 = NULL;
567 struct sk_buff *skb1 = NULL, *skb2 = NULL;
570 if (intrfc == ipx_primary_net && ntohs(ipx->ipx_dest.sock) == 0x451)
571 sock1 = ncp_connection_hack(intrfc, ipx);
573 /* No special socket found, forward the packet the normal way */
574 sock1 = ipxitf_find_socket(intrfc, ipx->ipx_dest.sock);
577 * We need to check if there is a primary net and if
578 * this is addressed to one of the *SPECIAL* sockets because
579 * these need to be propagated to the primary net.
580 * The *SPECIAL* socket list contains: 0x452(SAP), 0x453(RIP) and
584 if (ipx_primary_net && intrfc != ipx_primary_net) {
585 const int dsock = ntohs(ipx->ipx_dest.sock);
587 if (dsock == 0x452 || dsock == 0x453 || dsock == 0x456)
588 /* The appropriate thing to do here is to dup the
589 * packet and route to the primary net interface via
590 * ipxitf_send; however, we'll cheat and just demux it
592 sock2 = ipxitf_find_socket(ipx_primary_net,
597 * If there is nothing to do return. The kfree will cancel any charging.
599 if (!sock1 && !sock2) {
606 * This next segment of code is a little awkward, but it sets it up
607 * so that the appropriate number of copies of the SKB are made and
608 * that skb1 and skb2 point to it (them) so that it (they) can be
609 * demuxed to sock1 and/or sock2. If we are unable to make enough
610 * copies, we do as much as is possible.
614 skb1 = skb_clone(skb, GFP_ATOMIC);
622 /* Do we need 2 SKBs? */
624 skb2 = skb_clone(skb1, GFP_ATOMIC);
629 ipxitf_def_skb_handler(sock1, skb1);
636 ipxitf_def_skb_handler(sock2, skb2);
645 #endif /* CONFIG_IPX_INTERN */
647 static struct sk_buff *ipxitf_adjust_skbuff(ipx_interface *intrfc,
650 struct sk_buff *skb2;
651 int in_offset = skb->h.raw - skb->head;
652 int out_offset = intrfc->if_ipx_offset;
655 /* Hopefully, most cases */
656 if (in_offset >= out_offset)
660 len = skb->len + out_offset;
661 skb2 = alloc_skb(len, GFP_ATOMIC);
663 skb_reserve(skb2, out_offset);
664 skb2->nh.raw = skb2->h.raw = skb_put(skb2, skb->len);
665 memcpy(skb2->h.raw, skb->h.raw, skb->len);
666 memcpy(skb2->cb, skb->cb, sizeof(skb->cb));
672 /* caller must hold a reference to intrfc and the skb has to be unshared */
674 static int ipxitf_send(ipx_interface *intrfc, struct sk_buff *skb, char *node)
676 struct ipxhdr *ipx = skb->nh.ipxh;
677 struct net_device *dev = intrfc->if_dev;
678 struct datalink_proto *dl = intrfc->if_dlink;
679 char dest_node[IPX_NODE_LEN];
680 int send_to_wire = 1;
683 ipx->ipx_tctrl = IPX_SKB_CB(skb)->ipx_tctrl;
684 ipx->ipx_dest.net = IPX_SKB_CB(skb)->ipx_dest_net;
685 ipx->ipx_source.net = IPX_SKB_CB(skb)->ipx_source_net;
687 /* see if we need to include the netnum in the route list */
688 if (IPX_SKB_CB(skb)->last_hop.index >= 0) {
689 u32 *last_hop = (u32 *)(((u8 *) skb->data) +
690 sizeof(struct ipxhdr) +
691 IPX_SKB_CB(skb)->last_hop.index *
693 *last_hop = IPX_SKB_CB(skb)->last_hop.netnum;
694 IPX_SKB_CB(skb)->last_hop.index = -1;
698 * We need to know how many skbuffs it will take to send out this
699 * packet to avoid unnecessary copies.
702 if (!dl || !dev || dev->flags & IFF_LOOPBACK)
703 send_to_wire = 0; /* No non looped */
706 * See if this should be demuxed to sockets on this interface
708 * We want to ensure the original was eaten or that we only use
712 if (ipx->ipx_dest.net == intrfc->if_netnum) {
714 * To our own node, loop and free the original.
715 * The internal net will receive on all node address.
717 if (intrfc == ipx_internal_net ||
718 !memcmp(intrfc->if_node, node, IPX_NODE_LEN)) {
719 /* Don't charge sender */
722 /* Will charge receiver */
723 return ipxitf_demux_socket(intrfc, skb, 0);
726 /* Broadcast, loop and possibly keep to send on. */
727 if (!memcmp(ipx_broadcast_node, node, IPX_NODE_LEN)) {
730 ipxitf_demux_socket(intrfc, skb, send_to_wire);
737 * If the originating net is not equal to our net; this is routed
738 * We are still charging the sender. Which is right - the driver
739 * free will handle this fairly.
741 if (ipx->ipx_source.net != intrfc->if_netnum) {
743 * Unshare the buffer before modifying the count in
744 * case its a flood or tcpdump
746 skb = skb_unshare(skb, GFP_ATOMIC);
749 if (++ipx->ipx_tctrl > ipxcfg_max_hops)
758 /* Determine the appropriate hardware address */
759 addr_len = dev->addr_len;
760 if (!memcmp(ipx_broadcast_node, node, IPX_NODE_LEN))
761 memcpy(dest_node, dev->broadcast, addr_len);
763 memcpy(dest_node, &(node[IPX_NODE_LEN-addr_len]), addr_len);
765 /* Make any compensation for differing physical/data link size */
766 skb = ipxitf_adjust_skbuff(intrfc, skb);
770 /* set up data link and physical headers */
772 skb->protocol = __constant_htons(ETH_P_IPX);
773 dl->datalink_header(dl, skb, dest_node);
780 static int ipxrtr_add_route(__u32, ipx_interface *, unsigned char *);
782 static int ipxitf_add_local_route(ipx_interface *intrfc)
784 return ipxrtr_add_route(intrfc->if_netnum, intrfc, NULL);
787 static const char * ipx_frame_name(unsigned short);
788 static const char * ipx_device_name(ipx_interface *);
789 static void ipxitf_discover_netnum(ipx_interface *intrfc, struct sk_buff *skb);
790 static int ipxitf_pprop(ipx_interface *intrfc, struct sk_buff *skb);
792 static int ipxitf_rcv(ipx_interface *intrfc, struct sk_buff *skb)
794 struct ipxhdr *ipx = skb->nh.ipxh;
799 /* See if we should update our network number */
800 if (!intrfc->if_netnum) /* net number of intrfc not known yet */
801 ipxitf_discover_netnum(intrfc, skb);
803 IPX_SKB_CB(skb)->last_hop.index = -1;
804 if (ipx->ipx_type == IPX_TYPE_PPROP) {
805 ret = ipxitf_pprop(intrfc, skb);
810 /* local processing follows */
811 if (!IPX_SKB_CB(skb)->ipx_dest_net)
812 IPX_SKB_CB(skb)->ipx_dest_net = intrfc->if_netnum;
813 if (!IPX_SKB_CB(skb)->ipx_source_net)
814 IPX_SKB_CB(skb)->ipx_source_net = intrfc->if_netnum;
816 /* it doesn't make sense to route a pprop packet, there's no meaning
817 * in the ipx_dest_net for such packets */
818 if (ipx->ipx_type != IPX_TYPE_PPROP &&
819 intrfc->if_netnum != IPX_SKB_CB(skb)->ipx_dest_net) {
820 /* We only route point-to-point packets. */
821 if (skb->pkt_type == PACKET_HOST) {
822 skb = skb_unshare(skb, GFP_ATOMIC);
824 ret = ipxrtr_route_skb(skb);
831 /* see if we should keep it */
832 if (!memcmp(ipx_broadcast_node, ipx->ipx_dest.node, IPX_NODE_LEN) ||
833 !memcmp(intrfc->if_node, ipx->ipx_dest.node, IPX_NODE_LEN)) {
834 ret = ipxitf_demux_socket(intrfc, skb, 0);
838 /* we couldn't pawn it off so unload it */
846 static void ipxitf_discover_netnum(ipx_interface *intrfc, struct sk_buff *skb)
848 const struct ipx_cb *cb = IPX_SKB_CB(skb);
850 /* see if this is an intra packet: source_net == dest_net */
851 if (cb->ipx_source_net == cb->ipx_dest_net && cb->ipx_source_net) {
852 ipx_interface *i = ipxitf_find_using_net(cb->ipx_source_net);
853 /* NB: NetWare servers lie about their hop count so we
854 * dropped the test based on it. This is the best way
855 * to determine this is a 0 hop count packet. */
857 intrfc->if_netnum = cb->ipx_source_net;
858 ipxitf_add_local_route(intrfc);
860 printk(KERN_WARNING "IPX: Network number collision "
861 "%lx\n %s %s and %s %s\n",
862 (unsigned long) htonl(cb->ipx_source_net),
864 ipx_frame_name(i->if_dlink_type),
865 ipx_device_name(intrfc),
866 ipx_frame_name(intrfc->if_dlink_type));
873 * ipxitf_pprop - Process packet propagation IPX packet type 0x14, used for
875 * @intrfc: IPX interface receiving this packet
876 * @skb: Received packet
878 * Checks if packet is valid: if its more than %IPX_MAX_PPROP_HOPS hops or if it
879 * is smaller than a IPX header + the room for %IPX_MAX_PPROP_HOPS hops we drop
880 * it, not even processing it locally, if it has exact %IPX_MAX_PPROP_HOPS we
881 * don't broadcast it, but process it locally. See chapter 5 of Novell's "IPX
882 * RIP and SAP Router Specification", Part Number 107-000029-001.
884 * If it is valid, check if we have pprop broadcasting enabled by the user,
885 * if not, just return zero for local processing.
887 * If it is enabled check the packet and don't broadcast it if we have already
890 * Broadcast: send it to the interfaces that aren't on the packet visited nets
891 * array, just after the IPX header.
893 * Returns -EINVAL for invalid packets, so that the calling function drops
894 * the packet without local processing. 0 if packet is to be locally processed.
896 static int ipxitf_pprop(ipx_interface *intrfc, struct sk_buff *skb)
898 struct ipxhdr *ipx = skb->nh.ipxh;
899 int i, ret = -EINVAL;
904 /* Illegal packet - too many hops or too short */
905 /* We decide to throw it away: no broadcasting, no local processing.
906 * NetBIOS unaware implementations route them as normal packets -
907 * tctrl <= 15, any data payload... */
908 if (IPX_SKB_CB(skb)->ipx_tctrl > IPX_MAX_PPROP_HOPS ||
909 ntohs(ipx->ipx_pktsize) < sizeof(struct ipxhdr) +
910 IPX_MAX_PPROP_HOPS * sizeof(u32))
912 /* are we broadcasting this damn thing? */
914 if (!sysctl_ipx_pprop_broadcasting)
916 /* We do broadcast packet on the IPX_MAX_PPROP_HOPS hop, but we
917 * process it locally. All previous hops broadcasted it, and process it
919 if (IPX_SKB_CB(skb)->ipx_tctrl == IPX_MAX_PPROP_HOPS)
922 c = ((u8 *) ipx) + sizeof(struct ipxhdr);
925 /* Don't broadcast packet if already seen this net */
926 for (i = 0; i < IPX_SKB_CB(skb)->ipx_tctrl; i++)
927 if (*l++ == intrfc->if_netnum)
930 /* < IPX_MAX_PPROP_HOPS hops && input interface not in list. Save the
931 * position where we will insert recvd netnum into list, later on,
933 IPX_SKB_CB(skb)->last_hop.index = i;
934 IPX_SKB_CB(skb)->last_hop.netnum = intrfc->if_netnum;
935 /* xmit on all other interfaces... */
936 spin_lock_bh(&ipx_interfaces_lock);
937 for (ifcs = ipx_interfaces; ifcs; ifcs = ifcs->if_next) {
938 /* Except unconfigured interfaces */
939 if (!ifcs->if_netnum)
942 /* That aren't in the list */
946 /* don't consider the last entry in the packet list,
947 * it is our netnum, and it is not there yet */
948 for (i = 0; i < IPX_SKB_CB(skb)->ipx_tctrl; i++)
949 if (ifcs->if_netnum == *l++)
951 if (i == IPX_SKB_CB(skb)->ipx_tctrl) {
952 struct sk_buff *s = skb_copy(skb, GFP_ATOMIC);
955 IPX_SKB_CB(s)->ipx_dest_net = ifcs->if_netnum;
960 spin_unlock_bh(&ipx_interfaces_lock);
964 static void ipxitf_insert(ipx_interface *intrfc)
966 intrfc->if_next = NULL;
967 spin_lock_bh(&ipx_interfaces_lock);
969 ipx_interfaces = intrfc;
971 ipx_interface *i = ipx_interfaces;
976 spin_unlock_bh(&ipx_interfaces_lock);
978 if (ipxcfg_auto_select_primary && !ipx_primary_net)
979 ipx_primary_net = intrfc;
982 static ipx_interface *ipxitf_alloc(struct net_device *dev, __u32 netnum,
983 unsigned short dlink_type,
984 struct datalink_proto *dlink,
985 unsigned char internal, int ipx_offset)
987 ipx_interface *intrfc = kmalloc(sizeof(*intrfc), GFP_ATOMIC);
990 intrfc->if_dev = dev;
991 intrfc->if_netnum = netnum;
992 intrfc->if_dlink_type = dlink_type;
993 intrfc->if_dlink = dlink;
994 intrfc->if_internal = internal;
995 intrfc->if_ipx_offset = ipx_offset;
996 intrfc->if_sknum = IPX_MIN_EPHEMERAL_SOCKET;
997 intrfc->if_sklist = NULL;
998 atomic_set(&intrfc->refcnt, 1);
999 spin_lock_init(&intrfc->if_sklist_lock);
1006 static int ipxitf_create_internal(ipx_interface_definition *idef)
1008 ipx_interface *intrfc;
1011 /* Only one primary network allowed */
1012 if (ipx_primary_net)
1015 /* Must have a valid network number */
1016 ret = -EADDRNOTAVAIL;
1017 if (!idef->ipx_network)
1019 intrfc = ipxitf_find_using_net(idef->ipx_network);
1025 intrfc = ipxitf_alloc(NULL, idef->ipx_network, 0, NULL, 1, 0);
1029 memcpy((char *)&(intrfc->if_node), idef->ipx_node, IPX_NODE_LEN);
1030 ipx_internal_net = ipx_primary_net = intrfc;
1031 ipxitf_hold(intrfc);
1032 ipxitf_insert(intrfc);
1034 ret = ipxitf_add_local_route(intrfc);
1039 static int ipx_map_frame_type(unsigned char type)
1044 case IPX_FRAME_ETHERII:
1045 ret = __constant_htons(ETH_P_IPX);
1047 case IPX_FRAME_8022:
1048 ret = __constant_htons(ETH_P_802_2);
1050 case IPX_FRAME_SNAP:
1051 ret = __constant_htons(ETH_P_SNAP);
1053 case IPX_FRAME_8023:
1054 ret = __constant_htons(ETH_P_802_3);
1061 static int ipxitf_create(ipx_interface_definition *idef)
1063 struct net_device *dev;
1064 unsigned short dlink_type = 0;
1065 struct datalink_proto *datalink = NULL;
1066 ipx_interface *intrfc;
1069 if (idef->ipx_special == IPX_INTERNAL) {
1070 err = ipxitf_create_internal(idef);
1075 if (idef->ipx_special == IPX_PRIMARY && ipx_primary_net)
1078 intrfc = ipxitf_find_using_net(idef->ipx_network);
1080 if (idef->ipx_network && intrfc) {
1088 dev = dev_get_by_name(idef->ipx_device);
1093 switch (idef->ipx_dlink_type) {
1094 case IPX_FRAME_TR_8022:
1095 printk(KERN_WARNING "IPX frame type 802.2TR is "
1096 "obsolete Use 802.2 instead.\n");
1098 case IPX_FRAME_8022:
1099 dlink_type = __constant_htons(ETH_P_802_2);
1100 datalink = p8022_datalink;
1102 case IPX_FRAME_ETHERII:
1103 if (dev->type != ARPHRD_IEEE802) {
1104 dlink_type = __constant_htons(ETH_P_IPX);
1105 datalink = pEII_datalink;
1108 printk(KERN_WARNING "IPX frame type EtherII "
1109 "over token-ring is obsolete. Use SNAP "
1112 case IPX_FRAME_SNAP:
1113 dlink_type = __constant_htons(ETH_P_SNAP);
1114 datalink = pSNAP_datalink;
1116 case IPX_FRAME_8023:
1117 dlink_type = __constant_htons(ETH_P_802_3);
1118 datalink = p8023_datalink;
1120 case IPX_FRAME_NONE:
1122 err = -EPROTONOSUPPORT;
1127 if (!(dev->flags & IFF_UP))
1130 /* Check addresses are suitable */
1132 if (dev->addr_len > IPX_NODE_LEN)
1135 intrfc = ipxitf_find_using_phys(dev, dlink_type);
1138 intrfc = ipxitf_alloc(dev, idef->ipx_network, dlink_type,
1139 datalink, 0, dev->hard_header_len +
1140 datalink->header_length);
1144 /* Setup primary if necessary */
1145 if (idef->ipx_special == IPX_PRIMARY)
1146 ipx_primary_net = intrfc;
1147 if (!memcmp(idef->ipx_node, "\000\000\000\000\000\000",
1149 memset(intrfc->if_node, 0, IPX_NODE_LEN);
1150 memcpy(intrfc->if_node + IPX_NODE_LEN - dev->addr_len,
1151 dev->dev_addr, dev->addr_len);
1153 memcpy(intrfc->if_node, idef->ipx_node, IPX_NODE_LEN);
1154 ipxitf_hold(intrfc);
1155 ipxitf_insert(intrfc);
1159 /* If the network number is known, add a route */
1161 if (!intrfc->if_netnum)
1164 err = ipxitf_add_local_route(intrfc);
1173 static int ipxitf_delete(ipx_interface_definition *idef)
1175 struct net_device *dev = NULL;
1176 unsigned short dlink_type = 0;
1177 ipx_interface *intrfc;
1180 spin_lock_bh(&ipx_interfaces_lock);
1181 if (idef->ipx_special == IPX_INTERNAL) {
1182 if (ipx_internal_net) {
1183 __ipxitf_put(ipx_internal_net);
1190 dlink_type = ipx_map_frame_type(idef->ipx_dlink_type);
1191 ret = -EPROTONOSUPPORT;
1195 dev = __dev_get_by_name(idef->ipx_device);
1200 intrfc = __ipxitf_find_using_phys(dev, dlink_type);
1204 __ipxitf_put(intrfc);
1207 out: spin_unlock_bh(&ipx_interfaces_lock);
1211 static ipx_interface *ipxitf_auto_create(struct net_device *dev,
1212 unsigned short dlink_type)
1214 ipx_interface *intrfc = NULL;
1215 struct datalink_proto *datalink;
1220 /* Check addresses are suitable */
1221 if (dev->addr_len > IPX_NODE_LEN)
1224 switch (htons(dlink_type)) {
1226 datalink = pEII_datalink;
1230 datalink = p8022_datalink;
1234 datalink = pSNAP_datalink;
1238 datalink = p8023_datalink;
1245 intrfc = ipxitf_alloc(dev, 0, dlink_type, datalink, 0,
1246 dev->hard_header_len + datalink->header_length);
1249 memset(intrfc->if_node, 0, IPX_NODE_LEN);
1250 memcpy((char *)&(intrfc->if_node[IPX_NODE_LEN-dev->addr_len]),
1251 dev->dev_addr, dev->addr_len);
1252 spin_lock_init(&intrfc->if_sklist_lock);
1253 atomic_set(&intrfc->refcnt, 1);
1254 ipxitf_insert(intrfc);
1261 static int ipxitf_ioctl(unsigned int cmd, void *arg)
1268 struct sockaddr_ipx *sipx;
1269 ipx_interface_definition f;
1271 if (copy_from_user(&ifr, arg, sizeof(ifr)))
1274 sipx = (struct sockaddr_ipx *)&ifr.ifr_addr;
1275 if (sipx->sipx_family != AF_IPX)
1278 f.ipx_network = sipx->sipx_network;
1279 memcpy(f.ipx_device, ifr.ifr_name,
1280 sizeof(f.ipx_device));
1281 memcpy(f.ipx_node, sipx->sipx_node, IPX_NODE_LEN);
1282 f.ipx_dlink_type = sipx->sipx_type;
1283 f.ipx_special = sipx->sipx_special;
1285 if (sipx->sipx_action == IPX_DLTITF)
1286 return ipxitf_delete(&f);
1288 return ipxitf_create(&f);
1293 struct sockaddr_ipx *sipx;
1294 ipx_interface *ipxif;
1295 struct net_device *dev;
1297 if (copy_from_user(&ifr, arg, sizeof(ifr)))
1300 sipx = (struct sockaddr_ipx *)&ifr.ifr_addr;
1301 dev = __dev_get_by_name(ifr.ifr_name);
1305 ipxif = ipxitf_find_using_phys(dev, ipx_map_frame_type(sipx->sipx_type));
1307 return -EADDRNOTAVAIL;
1309 sipx->sipx_family = AF_IPX;
1310 sipx->sipx_network = ipxif->if_netnum;
1311 memcpy(sipx->sipx_node, ipxif->if_node,
1312 sizeof(sipx->sipx_node));
1313 if (copy_to_user(arg, &ifr, sizeof(ifr)))
1320 case SIOCAIPXITFCRT:
1321 if (get_user(val, (unsigned char *) arg))
1323 ipxcfg_set_auto_create(val);
1326 case SIOCAIPXPRISLT:
1327 if (get_user(val, (unsigned char *) arg))
1329 ipxcfg_set_auto_select(val);
1339 /* Routing tables for the IPX socket layer. */
1341 static inline void ipxrtr_hold(ipx_route *rt)
1343 atomic_inc(&rt->refcnt);
1346 static inline void ipxrtr_put(ipx_route *rt)
1348 if (atomic_dec_and_test(&rt->refcnt))
1352 static ipx_route *ipxrtr_lookup(__u32 net)
1356 read_lock_bh(&ipx_routes_lock);
1357 for (r = ipx_routes; r && r->ir_net != net; r = r->ir_next)
1361 read_unlock_bh(&ipx_routes_lock);
1366 /* caller must hold a reference to intrfc */
1368 static int ipxrtr_add_route(__u32 network, ipx_interface *intrfc,
1369 unsigned char *node)
1374 /* Get a route structure; either existing or create */
1375 rt = ipxrtr_lookup(network);
1377 rt = kmalloc(sizeof(ipx_route), GFP_ATOMIC);
1382 atomic_set(&rt->refcnt, 1);
1384 write_lock_bh(&ipx_routes_lock);
1385 rt->ir_next = ipx_routes;
1387 write_unlock_bh(&ipx_routes_lock);
1390 if (intrfc == ipx_internal_net)
1394 rt->ir_net = network;
1395 rt->ir_intrfc = intrfc;
1397 memset(rt->ir_router_node, '\0', IPX_NODE_LEN);
1400 memcpy(rt->ir_router_node, node, IPX_NODE_LEN);
1410 static void ipxrtr_del_routes(ipx_interface *intrfc)
1412 ipx_route **r, *tmp;
1414 write_lock_bh(&ipx_routes_lock);
1415 for (r = &ipx_routes; (tmp = *r) != NULL;) {
1416 if (tmp->ir_intrfc == intrfc) {
1420 r = &(tmp->ir_next);
1422 write_unlock_bh(&ipx_routes_lock);
1425 static int ipxrtr_create(ipx_route_definition *rd)
1427 ipx_interface *intrfc;
1428 int ret = -ENETUNREACH;
1430 /* Find the appropriate interface */
1431 intrfc = ipxitf_find_using_net(rd->ipx_router_network);
1434 ret = ipxrtr_add_route(rd->ipx_network, intrfc, rd->ipx_router_node);
1439 static int ipxrtr_delete(long net)
1445 write_lock_bh(&ipx_routes_lock);
1446 for (r = &ipx_routes; (tmp = *r) != NULL;) {
1447 if (tmp->ir_net == net) {
1448 /* Directly connected; can't lose route */
1450 if (!tmp->ir_routed)
1459 r = &(tmp->ir_next);
1462 out: write_unlock_bh(&ipx_routes_lock);
1467 * Checksum routine for IPX
1470 /* Note: We assume ipx_tctrl==0 and htons(length)==ipx_pktsize */
1471 /* This functions should *not* mess with packet contents */
1473 static __u16 ipx_cksum(struct ipxhdr *packet, int length)
1476 * NOTE: sum is a net byte order quantity, which optimizes the
1477 * loop. This only works on big and little endian machines. (I
1478 * don't know of a machine that isn't.)
1480 /* start at ipx_dest - We skip the checksum field and start with
1481 * ipx_type before the loop, not considering ipx_tctrl in the calc */
1482 __u16 *p = (__u16 *)&packet->ipx_dest;
1483 __u32 i = (length >> 1) - 1; /* Number of complete words */
1484 __u32 sum = packet->ipx_type << sizeof(packet->ipx_tctrl);
1486 /* Loop through all complete words except the checksum field,
1487 * ipx_type (accounted above) and ipx_tctrl (not used in the cksum) */
1491 /* Add on the last part word if it exists */
1492 if (packet->ipx_pktsize & __constant_htons(1))
1493 sum += ntohs(0xff00) & *p;
1495 /* Do final fixup */
1496 sum = (sum & 0xffff) + (sum >> 16);
1498 /* It's a pity there's no concept of carry in C */
1506 * Route an outgoing frame from a socket.
1508 static int ipxrtr_route_packet(struct sock *sk, struct sockaddr_ipx *usipx,
1509 struct iovec *iov, int len, int noblock)
1511 struct sk_buff *skb;
1512 ipx_interface *intrfc;
1516 ipx_route *rt = NULL;
1519 /* Find the appropriate interface on which to send packet */
1520 if (!usipx->sipx_network && ipx_primary_net) {
1521 usipx->sipx_network = ipx_primary_net->if_netnum;
1522 intrfc = ipx_primary_net;
1524 rt = ipxrtr_lookup(usipx->sipx_network);
1528 intrfc = rt->ir_intrfc;
1531 ipxitf_hold(intrfc);
1532 ipx_offset = intrfc->if_ipx_offset;
1533 size = sizeof(struct ipxhdr) + len + ipx_offset;
1535 skb = sock_alloc_send_skb(sk, size, noblock, &err);
1539 skb_reserve(skb, ipx_offset);
1542 /* Fill in IPX header */
1543 ipx = (struct ipxhdr *)skb_put(skb, sizeof(struct ipxhdr));
1544 ipx->ipx_pktsize = htons(len + sizeof(struct ipxhdr));
1545 IPX_SKB_CB(skb)->ipx_tctrl = 0;
1546 ipx->ipx_type = usipx->sipx_type;
1547 skb->h.raw = (void *)skb->nh.ipxh = ipx;
1549 IPX_SKB_CB(skb)->last_hop.index = -1;
1550 #ifdef CONFIG_IPX_INTERN
1551 IPX_SKB_CB(skb)->ipx_source_net = sk->protinfo.af_ipx.intrfc->if_netnum;
1552 memcpy(ipx->ipx_source.node, sk->protinfo.af_ipx.node, IPX_NODE_LEN);
1554 err = ntohs(sk->protinfo.af_ipx.port);
1555 if (err == 0x453 || err == 0x452) {
1556 /* RIP/SAP special handling for mars_nwe */
1557 IPX_SKB_CB(skb)->ipx_source_net = intrfc->if_netnum;
1558 memcpy(ipx->ipx_source.node, intrfc->if_node, IPX_NODE_LEN);
1560 IPX_SKB_CB(skb)->ipx_source_net =
1561 sk->protinfo.af_ipx.intrfc->if_netnum;
1562 memcpy(ipx->ipx_source.node, sk->protinfo.af_ipx.intrfc->if_node, IPX_NODE_LEN);
1564 #endif /* CONFIG_IPX_INTERN */
1565 ipx->ipx_source.sock = sk->protinfo.af_ipx.port;
1566 IPX_SKB_CB(skb)->ipx_dest_net = usipx->sipx_network;
1567 memcpy(ipx->ipx_dest.node, usipx->sipx_node, IPX_NODE_LEN);
1568 ipx->ipx_dest.sock = usipx->sipx_port;
1570 err = memcpy_fromiovec(skb_put(skb, len), iov, len);
1576 /* Apply checksum. Not allowed on 802.3 links. */
1577 if (sk->no_check || intrfc->if_dlink_type == IPX_FRAME_8023)
1578 ipx->ipx_checksum = 0xFFFF;
1580 ipx->ipx_checksum = ipx_cksum(ipx, len + sizeof(struct ipxhdr));
1582 err = ipxitf_send(intrfc, skb, (rt && rt->ir_routed) ?
1583 rt->ir_router_node : ipx->ipx_dest.node);
1591 /* the skb has to be unshared, we'll end up calling ipxitf_send, that'll
1592 * modify the packet */
1593 int ipxrtr_route_skb(struct sk_buff *skb)
1595 struct ipxhdr *ipx = skb->nh.ipxh;
1596 ipx_route *r = ipxrtr_lookup(IPX_SKB_CB(skb)->ipx_dest_net);
1598 if (!r) { /* no known route */
1603 ipxitf_hold(r->ir_intrfc);
1604 ipxitf_send(r->ir_intrfc, skb, r->ir_routed ?
1605 r->ir_router_node : ipx->ipx_dest.node);
1606 ipxitf_put(r->ir_intrfc);
1613 * We use a normal struct rtentry for route handling
1615 static int ipxrtr_ioctl(unsigned int cmd, void *arg)
1617 struct rtentry rt; /* Use these to behave like 'other' stacks */
1618 struct sockaddr_ipx *sg, *st;
1621 if (copy_from_user(&rt, arg, sizeof(rt)))
1624 sg = (struct sockaddr_ipx *)&rt.rt_gateway;
1625 st = (struct sockaddr_ipx *)&rt.rt_dst;
1628 if (!(rt.rt_flags & RTF_GATEWAY) || /* Direct routes are fixed */
1629 sg->sipx_family != AF_IPX ||
1630 st->sipx_family != AF_IPX)
1635 ret = ipxrtr_delete(st->sipx_network);
1638 struct ipx_route_definition f;
1639 f.ipx_network = st->sipx_network;
1640 f.ipx_router_network = sg->sipx_network;
1641 memcpy(f.ipx_router_node, sg->sipx_node, IPX_NODE_LEN);
1642 ret = ipxrtr_create(&f);
1650 static const char *ipx_frame_name(unsigned short frame)
1654 switch (ntohs(frame)) {
1655 case ETH_P_IPX: ret = "EtherII"; break;
1656 case ETH_P_802_2: ret = "802.2"; break;
1657 case ETH_P_SNAP: ret = "SNAP"; break;
1658 case ETH_P_802_3: ret = "802.3"; break;
1659 case ETH_P_TR_802_2: ret = "802.2TR"; break;
1665 static const char *ipx_device_name(ipx_interface *intrfc)
1667 return intrfc->if_internal ? "Internal" :
1668 intrfc->if_dev ? intrfc->if_dev->name : "Unknown";
1671 /* Called from proc fs */
1672 static int ipx_interface_get_info(char *buffer, char **start, off_t offset,
1676 off_t begin = 0, pos = 0;
1679 /* Theory.. Keep printing in the same place until we pass offset */
1681 len += sprintf(buffer, "%-11s%-15s%-9s%-11s%s", "Network",
1682 "Node_Address", "Primary", "Device", "Frame_Type");
1683 #ifdef IPX_REFCNT_DEBUG
1684 len += sprintf(buffer + len, " refcnt");
1686 strcat(buffer + len++, "\n");
1687 spin_lock_bh(&ipx_interfaces_lock);
1688 for (i = ipx_interfaces; i; i = i->if_next) {
1689 len += sprintf(buffer + len, "%08lX ",
1690 (long unsigned int) ntohl(i->if_netnum));
1691 len += sprintf(buffer + len, "%02X%02X%02X%02X%02X%02X ",
1692 i->if_node[0], i->if_node[1], i->if_node[2],
1693 i->if_node[3], i->if_node[4], i->if_node[5]);
1694 len += sprintf(buffer + len, "%-9s", i == ipx_primary_net ?
1696 len += sprintf(buffer + len, "%-11s", ipx_device_name(i));
1697 len += sprintf(buffer + len, "%-9s",
1698 ipx_frame_name(i->if_dlink_type));
1699 #ifdef IPX_REFCNT_DEBUG
1700 len += sprintf(buffer + len, "%6d", atomic_read(&i->refcnt));
1702 strcat(buffer + len++, "\n");
1703 /* Are we still dumping unwanted data then discard the record */
1707 len = 0; /* Keep dumping into the buffer start */
1710 if (pos > offset + length) /* We have dumped enough */
1713 spin_unlock_bh(&ipx_interfaces_lock);
1715 /* The data in question runs from begin to begin+len */
1716 *start = buffer + (offset - begin); /* Start of wanted data */
1717 len -= (offset - begin); /* Remove unwanted header data from length */
1719 len = length; /* Remove unwanted tail data from length */
1724 static int ipx_get_info(char *buffer, char **start, off_t offset, int length)
1728 off_t begin = 0, pos = 0;
1731 /* Theory.. Keep printing in the same place until we pass offset */
1733 #ifdef CONFIG_IPX_INTERN
1734 len += sprintf(buffer, "%-28s%-28s%-10s%-10s%-7s%s\n", "Local_Address",
1736 len += sprintf(buffer, "%-15s%-28s%-10s%-10s%-7s%s\n", "Local_Address",
1737 #endif /* CONFIG_IPX_INTERN */
1738 "Remote_Address", "Tx_Queue", "Rx_Queue",
1741 spin_lock_bh(&ipx_interfaces_lock);
1742 for (i = ipx_interfaces; i; i = i->if_next) {
1744 spin_lock_bh(&i->if_sklist_lock);
1745 for (s = i->if_sklist; s; s = s->next) {
1746 #ifdef CONFIG_IPX_INTERN
1747 len += sprintf(buffer + len,
1748 "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
1749 (unsigned long) htonl(s->protinfo.af_ipx.intrfc->if_netnum),
1750 s->protinfo.af_ipx.node[0],
1751 s->protinfo.af_ipx.node[1],
1752 s->protinfo.af_ipx.node[2],
1753 s->protinfo.af_ipx.node[3],
1754 s->protinfo.af_ipx.node[4],
1755 s->protinfo.af_ipx.node[5],
1756 htons(s->protinfo.af_ipx.port));
1758 len += sprintf(buffer + len, "%08lX:%04X ",
1759 (unsigned long) htonl(i->if_netnum),
1760 htons(s->protinfo.af_ipx.port));
1761 #endif /* CONFIG_IPX_INTERN */
1762 if (s->state != TCP_ESTABLISHED)
1763 len += sprintf(buffer + len, "%-28s",
1766 len += sprintf(buffer + len,
1767 "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
1768 (unsigned long) htonl(s->protinfo.af_ipx.dest_addr.net),
1769 s->protinfo.af_ipx.dest_addr.node[0],
1770 s->protinfo.af_ipx.dest_addr.node[1],
1771 s->protinfo.af_ipx.dest_addr.node[2],
1772 s->protinfo.af_ipx.dest_addr.node[3],
1773 s->protinfo.af_ipx.dest_addr.node[4],
1774 s->protinfo.af_ipx.dest_addr.node[5],
1775 htons(s->protinfo.af_ipx.dest_addr.sock));
1778 len += sprintf(buffer + len, "%08X %08X ",
1779 atomic_read(&s->wmem_alloc),
1780 atomic_read(&s->rmem_alloc));
1781 len += sprintf(buffer + len, "%02X %03d\n",
1782 s->state, SOCK_INODE(s->socket)->i_uid);
1790 if (pos > offset + length) /* We have dumped enough */
1793 spin_unlock_bh(&i->if_sklist_lock);
1796 spin_unlock_bh(&ipx_interfaces_lock);
1798 /* The data in question runs from begin to begin+len */
1799 *start = buffer + offset - begin;
1800 len -= (offset - begin);
1807 static int ipx_rt_get_info(char *buffer, char **start, off_t offset, int length)
1810 off_t begin = 0, pos = 0;
1813 len += sprintf(buffer, "%-11s%-13s%s\n",
1814 "Network", "Router_Net", "Router_Node");
1815 read_lock_bh(&ipx_routes_lock);
1816 for (rt = ipx_routes; rt; rt = rt->ir_next) {
1817 len += sprintf(buffer + len, "%08lX ",
1818 (long unsigned int) ntohl(rt->ir_net));
1819 if (rt->ir_routed) {
1820 len += sprintf(buffer + len,
1821 "%08lX %02X%02X%02X%02X%02X%02X\n",
1822 (long unsigned int) ntohl(rt->ir_intrfc->if_netnum),
1823 rt->ir_router_node[0], rt->ir_router_node[1],
1824 rt->ir_router_node[2], rt->ir_router_node[3],
1825 rt->ir_router_node[4], rt->ir_router_node[5]);
1827 len += sprintf(buffer + len, "%-13s%s\n",
1828 "Directly", "Connected");
1837 if (pos > offset + length)
1840 read_unlock_bh(&ipx_routes_lock);
1842 *start = buffer + (offset - begin);
1843 len -= (offset - begin);
1850 /* Handling for system calls applied via the various interfaces to an IPX
1853 static int ipx_setsockopt(struct socket *sock, int level, int optname,
1854 char *optval, int optlen)
1856 struct sock *sk = sock->sk;
1860 if (optlen != sizeof(int))
1864 if (get_user(opt, (unsigned int *)optval))
1868 if (!(level == SOL_IPX && optname == IPX_TYPE))
1871 sk->protinfo.af_ipx.type = opt;
1876 static int ipx_getsockopt(struct socket *sock, int level, int optname,
1877 char *optval, int *optlen)
1879 struct sock *sk = sock->sk;
1882 int ret = -ENOPROTOOPT;
1884 if (!(level == SOL_IPX && optname == IPX_TYPE))
1887 val = sk->protinfo.af_ipx.type;
1890 if (get_user(len, optlen))
1893 len = min_t(unsigned int, len, sizeof(int));
1899 if (put_user(len, optlen) || copy_to_user(optval, &val, len))
1906 static int ipx_create(struct socket *sock, int protocol)
1908 int ret = -ESOCKTNOSUPPORT;
1911 switch (sock->type) {
1913 sk = sk_alloc(PF_IPX, GFP_KERNEL, 1);
1917 sock->ops = &ipx_dgram_ops;
1920 case SOCK_SEQPACKET:
1922 * From this point on SPX sockets are handled
1923 * by af_spx.c and the methods replaced.
1925 if (spx_family_ops) {
1926 ret = spx_family_ops->create(sock, protocol);
1929 /* Fall through if SPX is not loaded */
1930 case SOCK_STREAM: /* Allow higher levels to piggyback */
1934 #ifdef IPX_REFCNT_DEBUG
1935 atomic_inc(&ipx_sock_nr);
1936 printk(KERN_DEBUG "IPX socket %p created, now we have %d alive\n", sk,
1937 atomic_read(&ipx_sock_nr));
1939 sock_init_data(sock, sk);
1940 sk->destruct = NULL;
1941 sk->no_check = 1; /* Checksum off by default */
1948 static int ipx_release(struct socket *sock)
1950 struct sock *sk = sock->sk;
1956 sk->state_change(sk);
1960 ipx_destroy_socket(sk);
1962 if (sock->type == SOCK_DGRAM)
1968 /* caller must hold a reference to intrfc */
1970 static unsigned short ipx_first_free_socketnum(ipx_interface *intrfc)
1972 unsigned short socketNum = intrfc->if_sknum;
1974 spin_lock_bh(&intrfc->if_sklist_lock);
1976 if (socketNum < IPX_MIN_EPHEMERAL_SOCKET)
1977 socketNum = IPX_MIN_EPHEMERAL_SOCKET;
1979 while (__ipxitf_find_socket(intrfc, ntohs(socketNum)))
1980 if (socketNum > IPX_MAX_EPHEMERAL_SOCKET)
1981 socketNum = IPX_MIN_EPHEMERAL_SOCKET;
1985 spin_unlock_bh(&intrfc->if_sklist_lock);
1986 intrfc->if_sknum = socketNum;
1988 return ntohs(socketNum);
1991 static int ipx_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1993 struct sock *sk = sock->sk;
1994 ipx_interface *intrfc;
1995 struct sockaddr_ipx *addr = (struct sockaddr_ipx *)uaddr;
1998 if (!sk->zapped || addr_len != sizeof(struct sockaddr_ipx))
2001 intrfc = ipxitf_find_using_net(addr->sipx_network);
2002 ret = -EADDRNOTAVAIL;
2006 if (!addr->sipx_port) {
2007 addr->sipx_port = ipx_first_free_socketnum(intrfc);
2009 if (!addr->sipx_port)
2013 /* protect IPX system stuff like routing/sap */
2015 if (ntohs(addr->sipx_port) < IPX_MIN_EPHEMERAL_SOCKET &&
2016 !capable(CAP_NET_ADMIN))
2019 sk->protinfo.af_ipx.port = addr->sipx_port;
2021 #ifdef CONFIG_IPX_INTERN
2022 if (intrfc == ipx_internal_net) {
2023 /* The source address is to be set explicitly if the
2024 * socket is to be bound on the internal network. If a
2025 * node number 0 was specified, the default is used.
2029 if (!memcmp(addr->sipx_node, ipx_broadcast_node, IPX_NODE_LEN))
2031 if (!memcmp(addr->sipx_node, ipx_this_node, IPX_NODE_LEN))
2032 memcpy(sk->protinfo.af_ipx.node, intrfc->if_node,
2035 memcpy(sk->protinfo.af_ipx.node, addr->sipx_node,
2039 if (ipxitf_find_internal_socket(intrfc,
2040 sk->protinfo.af_ipx.node,
2041 sk->protinfo.af_ipx.port)) {
2043 "IPX: bind failed because port %X in use.\n",
2044 ntohs((int)addr->sipx_port));
2048 /* Source addresses are easy. It must be our
2049 * network:node pair for an interface routed to IPX
2050 * with the ipx routing ioctl()
2053 memcpy(sk->protinfo.af_ipx.node, intrfc->if_node,
2057 if (ipxitf_find_socket(intrfc, addr->sipx_port)) {
2059 "IPX: bind failed because port %X in use.\n",
2060 ntohs((int)addr->sipx_port));
2065 #else /* !def CONFIG_IPX_INTERN */
2067 /* Source addresses are easy. It must be our network:node pair for
2068 an interface routed to IPX with the ipx routing ioctl() */
2071 if (ipxitf_find_socket(intrfc, addr->sipx_port)) {
2072 SOCK_DEBUG(sk, "IPX: bind failed because port %X in use.\n",
2073 ntohs((int)addr->sipx_port));
2077 #endif /* CONFIG_IPX_INTERN */
2079 ipxitf_insert_socket(intrfc, sk);
2081 SOCK_DEBUG(sk, "IPX: bound socket 0x%04X.\n", ntohs(addr->sipx_port) );
2089 static int ipx_connect(struct socket *sock, struct sockaddr *uaddr,
2090 int addr_len, int flags)
2092 struct sock *sk = sock->sk;
2093 struct sockaddr_ipx *addr;
2097 sk->state = TCP_CLOSE;
2098 sock->state = SS_UNCONNECTED;
2100 if (addr_len != sizeof(*addr))
2102 addr = (struct sockaddr_ipx *)uaddr;
2104 /* put the autobinding in */
2105 if (!sk->protinfo.af_ipx.port) {
2106 struct sockaddr_ipx uaddr;
2108 uaddr.sipx_port = 0;
2109 uaddr.sipx_network = 0;
2111 #ifdef CONFIG_IPX_INTERN
2113 if (!sk->protinfo.af_ipx.intrfc)
2114 goto out; /* Someone zonked the iface */
2115 memcpy(uaddr.sipx_node, sk->protinfo.af_ipx.intrfc->if_node,
2117 #endif /* CONFIG_IPX_INTERN */
2119 ret = ipx_bind(sock, (struct sockaddr *)&uaddr,
2120 sizeof(struct sockaddr_ipx));
2125 /* We can either connect to primary network or somewhere
2126 * we can route to */
2127 rt = ipxrtr_lookup(addr->sipx_network);
2129 if (!rt && !(!addr->sipx_network && ipx_primary_net))
2132 sk->protinfo.af_ipx.dest_addr.net = addr->sipx_network;
2133 sk->protinfo.af_ipx.dest_addr.sock = addr->sipx_port;
2134 memcpy(sk->protinfo.af_ipx.dest_addr.node,
2135 addr->sipx_node, IPX_NODE_LEN);
2136 sk->protinfo.af_ipx.type = addr->sipx_type;
2138 if (sock->type == SOCK_DGRAM) {
2139 sock->state = SS_CONNECTED;
2140 sk->state = TCP_ESTABLISHED;
2150 static int ipx_getname(struct socket *sock, struct sockaddr *uaddr,
2151 int *uaddr_len, int peer)
2154 struct sockaddr_ipx sipx;
2155 struct sock *sk = sock->sk;
2158 *uaddr_len = sizeof(struct sockaddr_ipx);
2162 if (sk->state != TCP_ESTABLISHED)
2165 addr = &sk->protinfo.af_ipx.dest_addr;
2166 sipx.sipx_network = addr->net;
2167 sipx.sipx_port = addr->sock;
2168 memcpy(sipx.sipx_node, addr->node, IPX_NODE_LEN);
2170 if (sk->protinfo.af_ipx.intrfc) {
2172 sk->protinfo.af_ipx.intrfc->if_netnum;
2173 #ifdef CONFIG_IPX_INTERN
2174 memcpy(sipx.sipx_node, sk->protinfo.af_ipx.node,
2177 memcpy(sipx.sipx_node,
2178 sk->protinfo.af_ipx.intrfc->if_node,
2180 #endif /* CONFIG_IPX_INTERN */
2183 sipx.sipx_network = 0;
2184 memset(sipx.sipx_node, '\0', IPX_NODE_LEN);
2187 sipx.sipx_port = sk->protinfo.af_ipx.port;
2190 sipx.sipx_family = AF_IPX;
2191 sipx.sipx_type = sk->protinfo.af_ipx.type;
2192 memcpy(uaddr, &sipx, sizeof(sipx));
2198 int ipx_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
2200 /* NULL here for pt means the packet was looped back */
2201 ipx_interface *intrfc;
2207 if (skb->pkt_type == PACKET_OTHERHOST)
2210 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
2214 ipx_pktsize = ntohs(ipx->ipx_pktsize);
2216 /* Too small or invalid header? */
2217 if (ipx_pktsize < sizeof(struct ipxhdr) || ipx_pktsize > skb->len)
2220 if (ipx->ipx_checksum != IPX_NO_CHECKSUM &&
2221 ipx->ipx_checksum != ipx_cksum(ipx, ipx_pktsize))
2224 IPX_SKB_CB(skb)->ipx_tctrl = ipx->ipx_tctrl;
2225 IPX_SKB_CB(skb)->ipx_dest_net = ipx->ipx_dest.net;
2226 IPX_SKB_CB(skb)->ipx_source_net = ipx->ipx_source.net;
2228 /* Determine what local ipx endpoint this is */
2229 intrfc = ipxitf_find_using_phys(dev, pt->type);
2231 if (ipxcfg_auto_create_interfaces &&
2232 ntohl(IPX_SKB_CB(skb)->ipx_dest_net)) {
2233 intrfc = ipxitf_auto_create(dev, pt->type);
2235 ipxitf_hold(intrfc);
2238 if (!intrfc) /* Not one of ours */
2239 /* or invalid packet for auto creation */
2243 ret = ipxitf_rcv(intrfc, skb);
2246 drop: kfree_skb(skb);
2250 static int ipx_sendmsg(struct socket *sock, struct msghdr *msg, int len,
2251 struct scm_cookie *scm)
2253 struct sock *sk = sock->sk;
2254 struct sockaddr_ipx *usipx = (struct sockaddr_ipx *)msg->msg_name;
2255 struct sockaddr_ipx local_sipx;
2257 int flags = msg->msg_flags;
2259 /* Socket gets bound below anyway */
2261 return -EIO; */ /* Socket not bound */
2262 if (flags & ~MSG_DONTWAIT)
2266 if (!sk->protinfo.af_ipx.port) {
2267 struct sockaddr_ipx uaddr;
2269 uaddr.sipx_port = 0;
2270 uaddr.sipx_network = 0;
2271 #ifdef CONFIG_IPX_INTERN
2273 if (!sk->protinfo.af_ipx.intrfc)
2274 goto out; /* Someone zonked the iface */
2275 memcpy(uaddr.sipx_node,
2276 sk->protinfo.af_ipx.intrfc->if_node,
2279 ret = ipx_bind(sock, (struct sockaddr *)&uaddr,
2280 sizeof(struct sockaddr_ipx));
2286 if (msg->msg_namelen < sizeof(*usipx) ||
2287 usipx->sipx_family != AF_IPX)
2291 if (sk->state != TCP_ESTABLISHED)
2294 usipx = &local_sipx;
2295 usipx->sipx_family = AF_IPX;
2296 usipx->sipx_type = sk->protinfo.af_ipx.type;
2297 usipx->sipx_port = sk->protinfo.af_ipx.dest_addr.sock;
2298 usipx->sipx_network = sk->protinfo.af_ipx.dest_addr.net;
2299 memcpy(usipx->sipx_node, sk->protinfo.af_ipx.dest_addr.node,
2303 ret = ipxrtr_route_packet(sk, usipx, msg->msg_iov, len,
2304 flags & MSG_DONTWAIT);
2311 static int ipx_recvmsg(struct socket *sock, struct msghdr *msg, int size,
2312 int flags, struct scm_cookie *scm)
2314 struct sock *sk = sock->sk;
2315 struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)msg->msg_name;
2316 struct ipxhdr *ipx = NULL;
2317 struct sk_buff *skb;
2320 /* put the autobinding in */
2321 if (!sk->protinfo.af_ipx.port) {
2322 struct sockaddr_ipx uaddr;
2324 uaddr.sipx_port = 0;
2325 uaddr.sipx_network = 0;
2327 #ifdef CONFIG_IPX_INTERN
2329 if (!sk->protinfo.af_ipx.intrfc)
2330 goto out; /* Someone zonked the iface */
2331 memcpy(uaddr.sipx_node,
2332 sk->protinfo.af_ipx.intrfc->if_node, IPX_NODE_LEN);
2333 #endif /* CONFIG_IPX_INTERN */
2335 err = ipx_bind(sock, (struct sockaddr *)&uaddr,
2336 sizeof(struct sockaddr_ipx));
2345 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
2346 flags & MSG_DONTWAIT, &err);
2351 copied = ntohs(ipx->ipx_pktsize) - sizeof(struct ipxhdr);
2352 if (copied > size) {
2354 msg->msg_flags |= MSG_TRUNC;
2357 err = skb_copy_datagram_iovec(skb, sizeof(struct ipxhdr), msg->msg_iov,
2361 sk->stamp = skb->stamp;
2363 msg->msg_namelen = sizeof(*sipx);
2366 sipx->sipx_family = AF_IPX;
2367 sipx->sipx_port = ipx->ipx_source.sock;
2368 memcpy(sipx->sipx_node, ipx->ipx_source.node, IPX_NODE_LEN);
2369 sipx->sipx_network = IPX_SKB_CB(skb)->ipx_source_net;
2370 sipx->sipx_type = ipx->ipx_type;
2375 skb_free_datagram(sk, skb);
2380 static int ipx_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2383 struct sock *sk = sock->sk;
2387 amount = sk->sndbuf - atomic_read(&sk->wmem_alloc);
2390 return put_user(amount, (int *)arg);
2393 struct sk_buff *skb = skb_peek(&sk->receive_queue);
2394 /* These two are safe on a single CPU system as only
2395 * user tasks fiddle here */
2397 amount = skb->len - sizeof(struct ipxhdr);
2398 return put_user(amount, (int *)arg);
2403 if (!capable(CAP_NET_ADMIN))
2405 return ipxrtr_ioctl(cmd, (void *)arg);
2408 case SIOCAIPXITFCRT:
2409 case SIOCAIPXPRISLT:
2410 if (!capable(CAP_NET_ADMIN))
2414 return ipxitf_ioctl(cmd, (void *)arg);
2416 case SIOCIPXCFGDATA:
2417 return ipxcfg_get_config_data((void *)arg);
2419 case SIOCIPXNCPCONN:
2421 * This socket wants to take care of the NCP connection
2422 * handed to us in arg.
2424 if (!capable(CAP_NET_ADMIN))
2426 return get_user(sk->protinfo.af_ipx.ipx_ncp_conn,
2427 (const unsigned short *)(arg));
2432 if (!sk->stamp.tv_sec)
2435 if (!copy_to_user((void *)arg, &sk->stamp,
2436 sizeof(struct timeval)))
2443 case SIOCGIFDSTADDR:
2444 case SIOCSIFDSTADDR:
2445 case SIOCGIFBRDADDR:
2446 case SIOCSIFBRDADDR:
2447 case SIOCGIFNETMASK:
2448 case SIOCSIFNETMASK:
2452 return dev_ioctl(cmd,(void *) arg);
2460 * SPX interface support
2463 int ipx_register_spx(struct proto_ops **p, struct net_proto_family *spx)
2469 *p = &ipx_dgram_ops;
2470 spx_family_ops = spx;
2475 int ipx_unregister_spx(void)
2477 spx_family_ops = NULL;
2483 * Socket family declarations
2486 static struct net_proto_family ipx_family_ops = {
2491 static struct proto_ops SOCKOPS_WRAPPED(ipx_dgram_ops) = {
2494 release: ipx_release,
2496 connect: ipx_connect,
2497 socketpair: sock_no_socketpair,
2498 accept: sock_no_accept,
2499 getname: ipx_getname,
2500 poll: datagram_poll,
2502 listen: sock_no_listen,
2503 shutdown: sock_no_shutdown, /* FIXME: have to support shutdown */
2504 setsockopt: ipx_setsockopt,
2505 getsockopt: ipx_getsockopt,
2506 sendmsg: ipx_sendmsg,
2507 recvmsg: ipx_recvmsg,
2509 sendpage: sock_no_sendpage,
2512 #include <linux/smp_lock.h>
2513 SOCKOPS_WRAP(ipx_dgram, PF_IPX);
2515 static struct packet_type ipx_8023_packet_type = {
2516 type: __constant_htons(ETH_P_802_3),
2518 data: (void *) 1, /* yap, I understand shared skbs :-) */
2521 static struct packet_type ipx_dix_packet_type = {
2522 type: __constant_htons(ETH_P_IPX),
2524 data: (void *) 1, /* yap, I understand shared skbs :-) */
2527 static struct notifier_block ipx_dev_notifier = {
2528 notifier_call: ipxitf_device_event,
2532 extern struct datalink_proto *make_EII_client(void);
2533 extern struct datalink_proto *make_8023_client(void);
2534 extern void destroy_EII_client(struct datalink_proto *);
2535 extern void destroy_8023_client(struct datalink_proto *);
2537 static unsigned char ipx_8022_type = 0xE0;
2538 static unsigned char ipx_snap_id[5] = { 0x0, 0x0, 0x0, 0x81, 0x37 };
2539 static char banner[] __initdata =
2540 KERN_INFO "NET4: Linux IPX 0.47 for NET4.0\n"
2541 KERN_INFO "IPX Portions Copyright (c) 1995 Caldera, Inc.\n" \
2542 KERN_INFO "IPX Portions Copyright (c) 2000, 2001 Conectiva, Inc.\n";
2544 static int __init ipx_init(void)
2546 sock_register(&ipx_family_ops);
2548 pEII_datalink = make_EII_client();
2549 dev_add_pack(&ipx_dix_packet_type);
2551 p8023_datalink = make_8023_client();
2552 dev_add_pack(&ipx_8023_packet_type);
2554 p8022_datalink = register_8022_client(ipx_8022_type, ipx_rcv);
2555 if (!p8022_datalink)
2556 printk(KERN_CRIT "IPX: Unable to register with 802.2\n");
2558 pSNAP_datalink = register_snap_client(ipx_snap_id, ipx_rcv);
2559 if (!pSNAP_datalink)
2560 printk(KERN_CRIT "IPX: Unable to register with SNAP\n");
2562 register_netdevice_notifier(&ipx_dev_notifier);
2563 ipx_register_sysctl();
2564 #ifdef CONFIG_PROC_FS
2565 proc_net_create("ipx", 0, ipx_get_info);
2566 proc_net_create("ipx_interface", 0, ipx_interface_get_info);
2567 proc_net_create("ipx_route", 0, ipx_rt_get_info);
2573 module_init(ipx_init);
2575 /* Higher layers need this info to prep tx pkts */
2576 int ipx_if_offset(unsigned long ipx_net_number)
2578 ipx_route *rt = ipxrtr_lookup(ipx_net_number);
2579 int ret = -ENETUNREACH;
2583 ret = rt->ir_intrfc->if_ipx_offset;
2588 /* Export symbols for higher layers */
2589 EXPORT_SYMBOL(ipxrtr_route_skb);
2590 EXPORT_SYMBOL(ipx_if_offset);
2591 EXPORT_SYMBOL(ipx_remove_socket);
2592 EXPORT_SYMBOL(ipx_register_spx);
2593 EXPORT_SYMBOL(ipx_unregister_spx);
2595 /* Note on MOD_{INC,DEC}_USE_COUNT:
2597 * Use counts are incremented/decremented when
2598 * sockets are created/deleted.
2600 * Routes are always associated with an interface, and
2601 * allocs/frees will remain properly accounted for by
2602 * their associated interfaces.
2604 * Ergo, before the ipx module can be removed, all IPX
2605 * sockets be closed from user space.
2608 static void __exit ipx_proto_finito(void)
2610 /* no need to worry about having anything on the ipx_interfaces
2611 * list, when a interface is created we increment the module
2612 * usage count, so the module will only be unloaded when there
2613 * are no more interfaces */
2615 proc_net_remove("ipx_route");
2616 proc_net_remove("ipx_interface");
2617 proc_net_remove("ipx");
2618 ipx_unregister_sysctl();
2620 unregister_netdevice_notifier(&ipx_dev_notifier);
2622 unregister_snap_client(ipx_snap_id);
2623 pSNAP_datalink = NULL;
2625 unregister_8022_client(ipx_8022_type);
2626 p8022_datalink = NULL;
2628 dev_remove_pack(&ipx_8023_packet_type);
2629 destroy_8023_client(p8023_datalink);
2630 p8023_datalink = NULL;
2632 dev_remove_pack(&ipx_dix_packet_type);
2633 destroy_EII_client(pEII_datalink);
2634 pEII_datalink = NULL;
2636 sock_unregister(ipx_family_ops.family);
2639 module_exit(ipx_proto_finito);
2640 MODULE_LICENSE("GPL");