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 * Portions Copyright (c) 2000-2003 Conectiva, Inc. <acme@conectiva.com.br>
19 * Neither Arnaldo Carvalho de Melo nor Conectiva, Inc. admit liability nor
20 * provide warranty for any of this software. This material is provided
21 * "AS-IS" and at no charge.
23 * Portions Copyright (c) 1995 Caldera, Inc. <greg@caldera.com>
24 * Neither Greg Page nor Caldera, Inc. admit liability nor provide
25 * warranty for any of this software. This material is provided
26 * "AS-IS" and at no charge.
28 * See net/ipx/ChangeLog.
31 #include <linux/capability.h>
32 #include <linux/errno.h>
33 #include <linux/if_arp.h>
34 #include <linux/if_ether.h>
35 #include <linux/init.h>
36 #include <linux/ipx.h>
37 #include <linux/kernel.h>
38 #include <linux/list.h>
39 #include <linux/module.h>
40 #include <linux/net.h>
41 #include <linux/netdevice.h>
42 #include <linux/uio.h>
43 #include <linux/slab.h>
44 #include <linux/skbuff.h>
45 #include <linux/smp_lock.h>
46 #include <linux/socket.h>
47 #include <linux/sockios.h>
48 #include <linux/string.h>
49 #include <linux/types.h>
50 #include <linux/termios.h>
53 #include <net/p8022.h>
54 #include <net/psnap.h>
56 #include <net/tcp_states.h>
58 #include <asm/uaccess.h>
61 extern void ipx_register_sysctl(void);
62 extern void ipx_unregister_sysctl(void);
64 #define ipx_register_sysctl()
65 #define ipx_unregister_sysctl()
68 /* Configuration Variables */
69 static unsigned char ipxcfg_max_hops
= 16;
70 static char ipxcfg_auto_select_primary
;
71 static char ipxcfg_auto_create_interfaces
;
72 int sysctl_ipx_pprop_broadcasting
= 1;
74 /* Global Variables */
75 static struct datalink_proto
*p8022_datalink
;
76 static struct datalink_proto
*pEII_datalink
;
77 static struct datalink_proto
*p8023_datalink
;
78 static struct datalink_proto
*pSNAP_datalink
;
80 static const struct proto_ops ipx_dgram_ops
;
82 LIST_HEAD(ipx_interfaces
);
83 DEFINE_SPINLOCK(ipx_interfaces_lock
);
85 struct ipx_interface
*ipx_primary_net
;
86 struct ipx_interface
*ipx_internal_net
;
88 extern int ipxrtr_add_route(__be32 network
, struct ipx_interface
*intrfc
,
90 extern void ipxrtr_del_routes(struct ipx_interface
*intrfc
);
91 extern int ipxrtr_route_packet(struct sock
*sk
, struct sockaddr_ipx
*usipx
,
92 struct iovec
*iov
, size_t len
, int noblock
);
93 extern int ipxrtr_route_skb(struct sk_buff
*skb
);
94 extern struct ipx_route
*ipxrtr_lookup(__be32 net
);
95 extern int ipxrtr_ioctl(unsigned int cmd
, void __user
*arg
);
97 struct ipx_interface
*ipx_interfaces_head(void)
99 struct ipx_interface
*rc
= NULL
;
101 if (!list_empty(&ipx_interfaces
))
102 rc
= list_entry(ipx_interfaces
.next
,
103 struct ipx_interface
, node
);
107 static void ipxcfg_set_auto_select(char val
)
109 ipxcfg_auto_select_primary
= val
;
110 if (val
&& !ipx_primary_net
)
111 ipx_primary_net
= ipx_interfaces_head();
114 static int ipxcfg_get_config_data(struct ipx_config_data __user
*arg
)
116 struct ipx_config_data vals
;
118 vals
.ipxcfg_auto_create_interfaces
= ipxcfg_auto_create_interfaces
;
119 vals
.ipxcfg_auto_select_primary
= ipxcfg_auto_select_primary
;
121 return copy_to_user(arg
, &vals
, sizeof(vals
)) ? -EFAULT
: 0;
125 * Note: Sockets may not be removed _during_ an interrupt or inet_bh
126 * handler using this technique. They can be added although we do not
130 static void ipx_remove_socket(struct sock
*sk
)
132 /* Determine interface with which socket is associated */
133 struct ipx_interface
*intrfc
= ipx_sk(sk
)->intrfc
;
139 spin_lock_bh(&intrfc
->if_sklist_lock
);
140 sk_del_node_init(sk
);
141 spin_unlock_bh(&intrfc
->if_sklist_lock
);
147 static void ipx_destroy_socket(struct sock
*sk
)
149 ipx_remove_socket(sk
);
150 skb_queue_purge(&sk
->sk_receive_queue
);
151 sk_refcnt_debug_dec(sk
);
156 * The following code is used to support IPX Interfaces (IPXITF). An
157 * IPX interface is defined by a physical device and a frame type.
160 /* ipxitf_clear_primary_net has to be called with ipx_interfaces_lock held */
162 static void ipxitf_clear_primary_net(void)
164 ipx_primary_net
= NULL
;
165 if (ipxcfg_auto_select_primary
)
166 ipx_primary_net
= ipx_interfaces_head();
169 static struct ipx_interface
*__ipxitf_find_using_phys(struct net_device
*dev
,
172 struct ipx_interface
*i
;
174 list_for_each_entry(i
, &ipx_interfaces
, node
)
175 if (i
->if_dev
== dev
&& i
->if_dlink_type
== datalink
)
182 static struct ipx_interface
*ipxitf_find_using_phys(struct net_device
*dev
,
185 struct ipx_interface
*i
;
187 spin_lock_bh(&ipx_interfaces_lock
);
188 i
= __ipxitf_find_using_phys(dev
, datalink
);
191 spin_unlock_bh(&ipx_interfaces_lock
);
195 struct ipx_interface
*ipxitf_find_using_net(__be32 net
)
197 struct ipx_interface
*i
;
199 spin_lock_bh(&ipx_interfaces_lock
);
201 list_for_each_entry(i
, &ipx_interfaces
, node
)
202 if (i
->if_netnum
== net
)
213 spin_unlock_bh(&ipx_interfaces_lock
);
217 /* Sockets are bound to a particular IPX interface. */
218 static void ipxitf_insert_socket(struct ipx_interface
*intrfc
, struct sock
*sk
)
221 spin_lock_bh(&intrfc
->if_sklist_lock
);
222 ipx_sk(sk
)->intrfc
= intrfc
;
223 sk_add_node(sk
, &intrfc
->if_sklist
);
224 spin_unlock_bh(&intrfc
->if_sklist_lock
);
228 /* caller must hold intrfc->if_sklist_lock */
229 static struct sock
*__ipxitf_find_socket(struct ipx_interface
*intrfc
,
233 struct hlist_node
*node
;
235 sk_for_each(s
, node
, &intrfc
->if_sklist
)
236 if (ipx_sk(s
)->port
== port
)
243 /* caller must hold a reference to intrfc */
244 static struct sock
*ipxitf_find_socket(struct ipx_interface
*intrfc
,
249 spin_lock_bh(&intrfc
->if_sklist_lock
);
250 s
= __ipxitf_find_socket(intrfc
, port
);
253 spin_unlock_bh(&intrfc
->if_sklist_lock
);
258 #ifdef CONFIG_IPX_INTERN
259 static struct sock
*ipxitf_find_internal_socket(struct ipx_interface
*intrfc
,
260 unsigned char *ipx_node
,
264 struct hlist_node
*node
;
267 spin_lock_bh(&intrfc
->if_sklist_lock
);
269 sk_for_each(s
, node
, &intrfc
->if_sklist
) {
270 struct ipx_sock
*ipxs
= ipx_sk(s
);
272 if (ipxs
->port
== port
&&
273 !memcmp(ipx_node
, ipxs
->node
, IPX_NODE_LEN
))
278 spin_unlock_bh(&intrfc
->if_sklist_lock
);
284 static void __ipxitf_down(struct ipx_interface
*intrfc
)
287 struct hlist_node
*node
, *t
;
289 /* Delete all routes associated with this interface */
290 ipxrtr_del_routes(intrfc
);
292 spin_lock_bh(&intrfc
->if_sklist_lock
);
294 sk_for_each_safe(s
, node
, t
, &intrfc
->if_sklist
) {
295 struct ipx_sock
*ipxs
= ipx_sk(s
);
298 s
->sk_error_report(s
);
301 sock_set_flag(s
, SOCK_ZAPPED
); /* Indicates it is no longer bound */
304 INIT_HLIST_HEAD(&intrfc
->if_sklist
);
305 spin_unlock_bh(&intrfc
->if_sklist_lock
);
307 /* remove this interface from list */
308 list_del(&intrfc
->node
);
310 /* remove this interface from *special* networks */
311 if (intrfc
== ipx_primary_net
)
312 ipxitf_clear_primary_net();
313 if (intrfc
== ipx_internal_net
)
314 ipx_internal_net
= NULL
;
317 dev_put(intrfc
->if_dev
);
321 void ipxitf_down(struct ipx_interface
*intrfc
)
323 spin_lock_bh(&ipx_interfaces_lock
);
324 __ipxitf_down(intrfc
);
325 spin_unlock_bh(&ipx_interfaces_lock
);
328 static __inline__
void __ipxitf_put(struct ipx_interface
*intrfc
)
330 if (atomic_dec_and_test(&intrfc
->refcnt
))
331 __ipxitf_down(intrfc
);
334 static int ipxitf_device_event(struct notifier_block
*notifier
,
335 unsigned long event
, void *ptr
)
337 struct net_device
*dev
= ptr
;
338 struct ipx_interface
*i
, *tmp
;
340 if (!net_eq(dev_net(dev
), &init_net
))
343 if (event
!= NETDEV_DOWN
&& event
!= NETDEV_UP
)
346 spin_lock_bh(&ipx_interfaces_lock
);
347 list_for_each_entry_safe(i
, tmp
, &ipx_interfaces
, node
)
348 if (i
->if_dev
== dev
) {
349 if (event
== NETDEV_UP
)
354 spin_unlock_bh(&ipx_interfaces_lock
);
360 static __exit
void ipxitf_cleanup(void)
362 struct ipx_interface
*i
, *tmp
;
364 spin_lock_bh(&ipx_interfaces_lock
);
365 list_for_each_entry_safe(i
, tmp
, &ipx_interfaces
, node
)
367 spin_unlock_bh(&ipx_interfaces_lock
);
370 static void ipxitf_def_skb_handler(struct sock
*sock
, struct sk_buff
*skb
)
372 if (sock_queue_rcv_skb(sock
, skb
) < 0)
377 * On input skb->sk is NULL. Nobody is charged for the memory.
380 /* caller must hold a reference to intrfc */
382 #ifdef CONFIG_IPX_INTERN
383 static int ipxitf_demux_socket(struct ipx_interface
*intrfc
,
384 struct sk_buff
*skb
, int copy
)
386 struct ipxhdr
*ipx
= ipx_hdr(skb
);
387 int is_broadcast
= !memcmp(ipx
->ipx_dest
.node
, ipx_broadcast_node
,
390 struct hlist_node
*node
;
393 spin_lock_bh(&intrfc
->if_sklist_lock
);
395 sk_for_each(s
, node
, &intrfc
->if_sklist
) {
396 struct ipx_sock
*ipxs
= ipx_sk(s
);
398 if (ipxs
->port
== ipx
->ipx_dest
.sock
&&
399 (is_broadcast
|| !memcmp(ipx
->ipx_dest
.node
,
400 ipxs
->node
, IPX_NODE_LEN
))) {
401 /* We found a socket to which to send */
402 struct sk_buff
*skb1
;
405 skb1
= skb_clone(skb
, GFP_ATOMIC
);
411 copy
= 1; /* skb may only be used once */
413 ipxitf_def_skb_handler(s
, skb1
);
415 /* On an external interface, one socket can listen */
416 if (intrfc
!= ipx_internal_net
)
421 /* skb was solely for us, and we did not make a copy, so free it. */
427 spin_unlock_bh(&intrfc
->if_sklist_lock
);
431 static struct sock
*ncp_connection_hack(struct ipx_interface
*intrfc
,
434 /* The packet's target is a NCP connection handler. We want to hand it
435 * to the correct socket directly within the kernel, so that the
436 * mars_nwe packet distribution process does not have to do it. Here we
437 * only care about NCP and BURST packets.
439 * You might call this a hack, but believe me, you do not want a
440 * complete NCP layer in the kernel, and this is VERY fast as well. */
441 struct sock
*sk
= NULL
;
443 u8
*ncphdr
= (u8
*)(ipx
+ 1);
445 if (*ncphdr
== 0x22 && *(ncphdr
+ 1) == 0x22) /* NCP request */
446 connection
= (((int) *(ncphdr
+ 5)) << 8) | (int) *(ncphdr
+ 3);
447 else if (*ncphdr
== 0x77 && *(ncphdr
+ 1) == 0x77) /* BURST packet */
448 connection
= (((int) *(ncphdr
+ 9)) << 8) | (int) *(ncphdr
+ 8);
451 struct hlist_node
*node
;
452 /* Now we have to look for a special NCP connection handling
453 * socket. Only these sockets have ipx_ncp_conn != 0, set by
455 spin_lock_bh(&intrfc
->if_sklist_lock
);
456 sk_for_each(sk
, node
, &intrfc
->if_sklist
)
457 if (ipx_sk(sk
)->ipx_ncp_conn
== connection
) {
463 spin_unlock_bh(&intrfc
->if_sklist_lock
);
468 static int ipxitf_demux_socket(struct ipx_interface
*intrfc
,
469 struct sk_buff
*skb
, int copy
)
471 struct ipxhdr
*ipx
= ipx_hdr(skb
);
472 struct sock
*sock1
= NULL
, *sock2
= NULL
;
473 struct sk_buff
*skb1
= NULL
, *skb2
= NULL
;
476 if (intrfc
== ipx_primary_net
&& ntohs(ipx
->ipx_dest
.sock
) == 0x451)
477 sock1
= ncp_connection_hack(intrfc
, ipx
);
479 /* No special socket found, forward the packet the normal way */
480 sock1
= ipxitf_find_socket(intrfc
, ipx
->ipx_dest
.sock
);
483 * We need to check if there is a primary net and if
484 * this is addressed to one of the *SPECIAL* sockets because
485 * these need to be propagated to the primary net.
486 * The *SPECIAL* socket list contains: 0x452(SAP), 0x453(RIP) and
490 if (ipx_primary_net
&& intrfc
!= ipx_primary_net
) {
491 const int dsock
= ntohs(ipx
->ipx_dest
.sock
);
493 if (dsock
== 0x452 || dsock
== 0x453 || dsock
== 0x456)
494 /* The appropriate thing to do here is to dup the
495 * packet and route to the primary net interface via
496 * ipxitf_send; however, we'll cheat and just demux it
498 sock2
= ipxitf_find_socket(ipx_primary_net
,
503 * If there is nothing to do return. The kfree will cancel any charging.
506 if (!sock1
&& !sock2
) {
513 * This next segment of code is a little awkward, but it sets it up
514 * so that the appropriate number of copies of the SKB are made and
515 * that skb1 and skb2 point to it (them) so that it (they) can be
516 * demuxed to sock1 and/or sock2. If we are unable to make enough
517 * copies, we do as much as is possible.
521 skb1
= skb_clone(skb
, GFP_ATOMIC
);
529 /* Do we need 2 SKBs? */
531 skb2
= skb_clone(skb1
, GFP_ATOMIC
);
536 ipxitf_def_skb_handler(sock1
, skb1
);
542 ipxitf_def_skb_handler(sock2
, skb2
);
553 #endif /* CONFIG_IPX_INTERN */
555 static struct sk_buff
*ipxitf_adjust_skbuff(struct ipx_interface
*intrfc
,
558 struct sk_buff
*skb2
;
559 int in_offset
= (unsigned char *)ipx_hdr(skb
) - skb
->head
;
560 int out_offset
= intrfc
->if_ipx_offset
;
563 /* Hopefully, most cases */
564 if (in_offset
>= out_offset
)
568 len
= skb
->len
+ out_offset
;
569 skb2
= alloc_skb(len
, GFP_ATOMIC
);
571 skb_reserve(skb2
, out_offset
);
572 skb_reset_network_header(skb2
);
573 skb_reset_transport_header(skb2
);
574 skb_put(skb2
, skb
->len
);
575 memcpy(ipx_hdr(skb2
), ipx_hdr(skb
), skb
->len
);
576 memcpy(skb2
->cb
, skb
->cb
, sizeof(skb
->cb
));
582 /* caller must hold a reference to intrfc and the skb has to be unshared */
583 int ipxitf_send(struct ipx_interface
*intrfc
, struct sk_buff
*skb
, char *node
)
585 struct ipxhdr
*ipx
= ipx_hdr(skb
);
586 struct net_device
*dev
= intrfc
->if_dev
;
587 struct datalink_proto
*dl
= intrfc
->if_dlink
;
588 char dest_node
[IPX_NODE_LEN
];
589 int send_to_wire
= 1;
592 ipx
->ipx_tctrl
= IPX_SKB_CB(skb
)->ipx_tctrl
;
593 ipx
->ipx_dest
.net
= IPX_SKB_CB(skb
)->ipx_dest_net
;
594 ipx
->ipx_source
.net
= IPX_SKB_CB(skb
)->ipx_source_net
;
596 /* see if we need to include the netnum in the route list */
597 if (IPX_SKB_CB(skb
)->last_hop
.index
>= 0) {
598 __be32
*last_hop
= (__be32
*)(((u8
*) skb
->data
) +
599 sizeof(struct ipxhdr
) +
600 IPX_SKB_CB(skb
)->last_hop
.index
*
602 *last_hop
= IPX_SKB_CB(skb
)->last_hop
.netnum
;
603 IPX_SKB_CB(skb
)->last_hop
.index
= -1;
607 * We need to know how many skbuffs it will take to send out this
608 * packet to avoid unnecessary copies.
611 if (!dl
|| !dev
|| dev
->flags
& IFF_LOOPBACK
)
612 send_to_wire
= 0; /* No non looped */
615 * See if this should be demuxed to sockets on this interface
617 * We want to ensure the original was eaten or that we only use
621 if (ipx
->ipx_dest
.net
== intrfc
->if_netnum
) {
623 * To our own node, loop and free the original.
624 * The internal net will receive on all node address.
626 if (intrfc
== ipx_internal_net
||
627 !memcmp(intrfc
->if_node
, node
, IPX_NODE_LEN
)) {
628 /* Don't charge sender */
631 /* Will charge receiver */
632 return ipxitf_demux_socket(intrfc
, skb
, 0);
635 /* Broadcast, loop and possibly keep to send on. */
636 if (!memcmp(ipx_broadcast_node
, node
, IPX_NODE_LEN
)) {
639 ipxitf_demux_socket(intrfc
, skb
, send_to_wire
);
646 * If the originating net is not equal to our net; this is routed
647 * We are still charging the sender. Which is right - the driver
648 * free will handle this fairly.
650 if (ipx
->ipx_source
.net
!= intrfc
->if_netnum
) {
652 * Unshare the buffer before modifying the count in
653 * case it's a flood or tcpdump
655 skb
= skb_unshare(skb
, GFP_ATOMIC
);
658 if (++ipx
->ipx_tctrl
> ipxcfg_max_hops
)
667 /* Determine the appropriate hardware address */
668 addr_len
= dev
->addr_len
;
669 if (!memcmp(ipx_broadcast_node
, node
, IPX_NODE_LEN
))
670 memcpy(dest_node
, dev
->broadcast
, addr_len
);
672 memcpy(dest_node
, &(node
[IPX_NODE_LEN
-addr_len
]), addr_len
);
674 /* Make any compensation for differing physical/data link size */
675 skb
= ipxitf_adjust_skbuff(intrfc
, skb
);
679 /* set up data link and physical headers */
681 skb
->protocol
= htons(ETH_P_IPX
);
684 dl
->request(dl
, skb
, dest_node
);
689 static int ipxitf_add_local_route(struct ipx_interface
*intrfc
)
691 return ipxrtr_add_route(intrfc
->if_netnum
, intrfc
, NULL
);
694 static void ipxitf_discover_netnum(struct ipx_interface
*intrfc
,
695 struct sk_buff
*skb
);
696 static int ipxitf_pprop(struct ipx_interface
*intrfc
, struct sk_buff
*skb
);
698 static int ipxitf_rcv(struct ipx_interface
*intrfc
, struct sk_buff
*skb
)
700 struct ipxhdr
*ipx
= ipx_hdr(skb
);
705 /* See if we should update our network number */
706 if (!intrfc
->if_netnum
) /* net number of intrfc not known yet */
707 ipxitf_discover_netnum(intrfc
, skb
);
709 IPX_SKB_CB(skb
)->last_hop
.index
= -1;
710 if (ipx
->ipx_type
== IPX_TYPE_PPROP
) {
711 rc
= ipxitf_pprop(intrfc
, skb
);
716 /* local processing follows */
717 if (!IPX_SKB_CB(skb
)->ipx_dest_net
)
718 IPX_SKB_CB(skb
)->ipx_dest_net
= intrfc
->if_netnum
;
719 if (!IPX_SKB_CB(skb
)->ipx_source_net
)
720 IPX_SKB_CB(skb
)->ipx_source_net
= intrfc
->if_netnum
;
722 /* it doesn't make sense to route a pprop packet, there's no meaning
723 * in the ipx_dest_net for such packets */
724 if (ipx
->ipx_type
!= IPX_TYPE_PPROP
&&
725 intrfc
->if_netnum
!= IPX_SKB_CB(skb
)->ipx_dest_net
) {
726 /* We only route point-to-point packets. */
727 if (skb
->pkt_type
== PACKET_HOST
) {
728 skb
= skb_unshare(skb
, GFP_ATOMIC
);
730 rc
= ipxrtr_route_skb(skb
);
737 /* see if we should keep it */
738 if (!memcmp(ipx_broadcast_node
, ipx
->ipx_dest
.node
, IPX_NODE_LEN
) ||
739 !memcmp(intrfc
->if_node
, ipx
->ipx_dest
.node
, IPX_NODE_LEN
)) {
740 rc
= ipxitf_demux_socket(intrfc
, skb
, 0);
744 /* we couldn't pawn it off so unload it */
752 static void ipxitf_discover_netnum(struct ipx_interface
*intrfc
,
755 const struct ipx_cb
*cb
= IPX_SKB_CB(skb
);
757 /* see if this is an intra packet: source_net == dest_net */
758 if (cb
->ipx_source_net
== cb
->ipx_dest_net
&& cb
->ipx_source_net
) {
759 struct ipx_interface
*i
=
760 ipxitf_find_using_net(cb
->ipx_source_net
);
761 /* NB: NetWare servers lie about their hop count so we
762 * dropped the test based on it. This is the best way
763 * to determine this is a 0 hop count packet. */
765 intrfc
->if_netnum
= cb
->ipx_source_net
;
766 ipxitf_add_local_route(intrfc
);
768 printk(KERN_WARNING
"IPX: Network number collision "
769 "%lx\n %s %s and %s %s\n",
770 (unsigned long) ntohl(cb
->ipx_source_net
),
772 ipx_frame_name(i
->if_dlink_type
),
773 ipx_device_name(intrfc
),
774 ipx_frame_name(intrfc
->if_dlink_type
));
781 * ipxitf_pprop - Process packet propagation IPX packet type 0x14, used for
783 * @intrfc: IPX interface receiving this packet
784 * @skb: Received packet
786 * Checks if packet is valid: if its more than %IPX_MAX_PPROP_HOPS hops or if it
787 * is smaller than a IPX header + the room for %IPX_MAX_PPROP_HOPS hops we drop
788 * it, not even processing it locally, if it has exact %IPX_MAX_PPROP_HOPS we
789 * don't broadcast it, but process it locally. See chapter 5 of Novell's "IPX
790 * RIP and SAP Router Specification", Part Number 107-000029-001.
792 * If it is valid, check if we have pprop broadcasting enabled by the user,
793 * if not, just return zero for local processing.
795 * If it is enabled check the packet and don't broadcast it if we have already
798 * Broadcast: send it to the interfaces that aren't on the packet visited nets
799 * array, just after the IPX header.
801 * Returns -EINVAL for invalid packets, so that the calling function drops
802 * the packet without local processing. 0 if packet is to be locally processed.
804 static int ipxitf_pprop(struct ipx_interface
*intrfc
, struct sk_buff
*skb
)
806 struct ipxhdr
*ipx
= ipx_hdr(skb
);
808 struct ipx_interface
*ifcs
;
812 /* Illegal packet - too many hops or too short */
813 /* We decide to throw it away: no broadcasting, no local processing.
814 * NetBIOS unaware implementations route them as normal packets -
815 * tctrl <= 15, any data payload... */
816 if (IPX_SKB_CB(skb
)->ipx_tctrl
> IPX_MAX_PPROP_HOPS
||
817 ntohs(ipx
->ipx_pktsize
) < sizeof(struct ipxhdr
) +
818 IPX_MAX_PPROP_HOPS
* sizeof(u32
))
820 /* are we broadcasting this damn thing? */
822 if (!sysctl_ipx_pprop_broadcasting
)
824 /* We do broadcast packet on the IPX_MAX_PPROP_HOPS hop, but we
825 * process it locally. All previous hops broadcasted it, and process it
827 if (IPX_SKB_CB(skb
)->ipx_tctrl
== IPX_MAX_PPROP_HOPS
)
830 c
= ((u8
*) ipx
) + sizeof(struct ipxhdr
);
833 /* Don't broadcast packet if already seen this net */
834 for (i
= 0; i
< IPX_SKB_CB(skb
)->ipx_tctrl
; i
++)
835 if (*l
++ == intrfc
->if_netnum
)
838 /* < IPX_MAX_PPROP_HOPS hops && input interface not in list. Save the
839 * position where we will insert recvd netnum into list, later on,
841 IPX_SKB_CB(skb
)->last_hop
.index
= i
;
842 IPX_SKB_CB(skb
)->last_hop
.netnum
= intrfc
->if_netnum
;
843 /* xmit on all other interfaces... */
844 spin_lock_bh(&ipx_interfaces_lock
);
845 list_for_each_entry(ifcs
, &ipx_interfaces
, node
) {
846 /* Except unconfigured interfaces */
847 if (!ifcs
->if_netnum
)
850 /* That aren't in the list */
854 /* don't consider the last entry in the packet list,
855 * it is our netnum, and it is not there yet */
856 for (i
= 0; i
< IPX_SKB_CB(skb
)->ipx_tctrl
; i
++)
857 if (ifcs
->if_netnum
== *l
++)
859 if (i
== IPX_SKB_CB(skb
)->ipx_tctrl
) {
860 struct sk_buff
*s
= skb_copy(skb
, GFP_ATOMIC
);
863 IPX_SKB_CB(s
)->ipx_dest_net
= ifcs
->if_netnum
;
868 spin_unlock_bh(&ipx_interfaces_lock
);
873 static void ipxitf_insert(struct ipx_interface
*intrfc
)
875 spin_lock_bh(&ipx_interfaces_lock
);
876 list_add_tail(&intrfc
->node
, &ipx_interfaces
);
877 spin_unlock_bh(&ipx_interfaces_lock
);
879 if (ipxcfg_auto_select_primary
&& !ipx_primary_net
)
880 ipx_primary_net
= intrfc
;
883 static struct ipx_interface
*ipxitf_alloc(struct net_device
*dev
, __be32 netnum
,
885 struct datalink_proto
*dlink
,
886 unsigned char internal
,
889 struct ipx_interface
*intrfc
= kmalloc(sizeof(*intrfc
), GFP_ATOMIC
);
892 intrfc
->if_dev
= dev
;
893 intrfc
->if_netnum
= netnum
;
894 intrfc
->if_dlink_type
= dlink_type
;
895 intrfc
->if_dlink
= dlink
;
896 intrfc
->if_internal
= internal
;
897 intrfc
->if_ipx_offset
= ipx_offset
;
898 intrfc
->if_sknum
= IPX_MIN_EPHEMERAL_SOCKET
;
899 INIT_HLIST_HEAD(&intrfc
->if_sklist
);
900 atomic_set(&intrfc
->refcnt
, 1);
901 spin_lock_init(&intrfc
->if_sklist_lock
);
907 static int ipxitf_create_internal(struct ipx_interface_definition
*idef
)
909 struct ipx_interface
*intrfc
;
912 /* Only one primary network allowed */
916 /* Must have a valid network number */
918 if (!idef
->ipx_network
)
920 intrfc
= ipxitf_find_using_net(idef
->ipx_network
);
926 intrfc
= ipxitf_alloc(NULL
, idef
->ipx_network
, 0, NULL
, 1, 0);
930 memcpy((char *)&(intrfc
->if_node
), idef
->ipx_node
, IPX_NODE_LEN
);
931 ipx_internal_net
= ipx_primary_net
= intrfc
;
933 ipxitf_insert(intrfc
);
935 rc
= ipxitf_add_local_route(intrfc
);
941 static __be16
ipx_map_frame_type(unsigned char type
)
946 case IPX_FRAME_ETHERII
: rc
= htons(ETH_P_IPX
); break;
947 case IPX_FRAME_8022
: rc
= htons(ETH_P_802_2
); break;
948 case IPX_FRAME_SNAP
: rc
= htons(ETH_P_SNAP
); break;
949 case IPX_FRAME_8023
: rc
= htons(ETH_P_802_3
); break;
955 static int ipxitf_create(struct ipx_interface_definition
*idef
)
957 struct net_device
*dev
;
958 __be16 dlink_type
= 0;
959 struct datalink_proto
*datalink
= NULL
;
960 struct ipx_interface
*intrfc
;
963 if (idef
->ipx_special
== IPX_INTERNAL
) {
964 rc
= ipxitf_create_internal(idef
);
969 if (idef
->ipx_special
== IPX_PRIMARY
&& ipx_primary_net
)
972 intrfc
= ipxitf_find_using_net(idef
->ipx_network
);
974 if (idef
->ipx_network
&& intrfc
) {
982 dev
= dev_get_by_name(&init_net
, idef
->ipx_device
);
987 switch (idef
->ipx_dlink_type
) {
988 case IPX_FRAME_TR_8022
:
989 printk(KERN_WARNING
"IPX frame type 802.2TR is "
990 "obsolete Use 802.2 instead.\n");
993 dlink_type
= htons(ETH_P_802_2
);
994 datalink
= p8022_datalink
;
996 case IPX_FRAME_ETHERII
:
997 if (dev
->type
!= ARPHRD_IEEE802
) {
998 dlink_type
= htons(ETH_P_IPX
);
999 datalink
= pEII_datalink
;
1002 printk(KERN_WARNING
"IPX frame type EtherII over "
1003 "token-ring is obsolete. Use SNAP "
1006 case IPX_FRAME_SNAP
:
1007 dlink_type
= htons(ETH_P_SNAP
);
1008 datalink
= pSNAP_datalink
;
1010 case IPX_FRAME_8023
:
1011 dlink_type
= htons(ETH_P_802_3
);
1012 datalink
= p8023_datalink
;
1014 case IPX_FRAME_NONE
:
1016 rc
= -EPROTONOSUPPORT
;
1021 if (!(dev
->flags
& IFF_UP
))
1024 /* Check addresses are suitable */
1026 if (dev
->addr_len
> IPX_NODE_LEN
)
1029 intrfc
= ipxitf_find_using_phys(dev
, dlink_type
);
1032 intrfc
= ipxitf_alloc(dev
, idef
->ipx_network
, dlink_type
,
1033 datalink
, 0, dev
->hard_header_len
+
1034 datalink
->header_length
);
1038 /* Setup primary if necessary */
1039 if (idef
->ipx_special
== IPX_PRIMARY
)
1040 ipx_primary_net
= intrfc
;
1041 if (!memcmp(idef
->ipx_node
, "\000\000\000\000\000\000",
1043 memset(intrfc
->if_node
, 0, IPX_NODE_LEN
);
1044 memcpy(intrfc
->if_node
+ IPX_NODE_LEN
- dev
->addr_len
,
1045 dev
->dev_addr
, dev
->addr_len
);
1047 memcpy(intrfc
->if_node
, idef
->ipx_node
, IPX_NODE_LEN
);
1048 ipxitf_hold(intrfc
);
1049 ipxitf_insert(intrfc
);
1053 /* If the network number is known, add a route */
1055 if (!intrfc
->if_netnum
)
1058 rc
= ipxitf_add_local_route(intrfc
);
1068 static int ipxitf_delete(struct ipx_interface_definition
*idef
)
1070 struct net_device
*dev
= NULL
;
1071 __be16 dlink_type
= 0;
1072 struct ipx_interface
*intrfc
;
1075 spin_lock_bh(&ipx_interfaces_lock
);
1076 if (idef
->ipx_special
== IPX_INTERNAL
) {
1077 if (ipx_internal_net
) {
1078 __ipxitf_put(ipx_internal_net
);
1085 dlink_type
= ipx_map_frame_type(idef
->ipx_dlink_type
);
1086 rc
= -EPROTONOSUPPORT
;
1090 dev
= __dev_get_by_name(&init_net
, idef
->ipx_device
);
1095 intrfc
= __ipxitf_find_using_phys(dev
, dlink_type
);
1099 __ipxitf_put(intrfc
);
1103 spin_unlock_bh(&ipx_interfaces_lock
);
1107 static struct ipx_interface
*ipxitf_auto_create(struct net_device
*dev
,
1110 struct ipx_interface
*intrfc
= NULL
;
1111 struct datalink_proto
*datalink
;
1116 /* Check addresses are suitable */
1117 if (dev
->addr_len
> IPX_NODE_LEN
)
1120 switch (ntohs(dlink_type
)) {
1121 case ETH_P_IPX
: datalink
= pEII_datalink
; break;
1122 case ETH_P_802_2
: datalink
= p8022_datalink
; break;
1123 case ETH_P_SNAP
: datalink
= pSNAP_datalink
; break;
1124 case ETH_P_802_3
: datalink
= p8023_datalink
; break;
1128 intrfc
= ipxitf_alloc(dev
, 0, dlink_type
, datalink
, 0,
1129 dev
->hard_header_len
+ datalink
->header_length
);
1132 memset(intrfc
->if_node
, 0, IPX_NODE_LEN
);
1133 memcpy((char *)&(intrfc
->if_node
[IPX_NODE_LEN
-dev
->addr_len
]),
1134 dev
->dev_addr
, dev
->addr_len
);
1135 spin_lock_init(&intrfc
->if_sklist_lock
);
1136 atomic_set(&intrfc
->refcnt
, 1);
1137 ipxitf_insert(intrfc
);
1145 static int ipxitf_ioctl(unsigned int cmd
, void __user
*arg
)
1153 struct sockaddr_ipx
*sipx
;
1154 struct ipx_interface_definition f
;
1157 if (copy_from_user(&ifr
, arg
, sizeof(ifr
)))
1159 sipx
= (struct sockaddr_ipx
*)&ifr
.ifr_addr
;
1161 if (sipx
->sipx_family
!= AF_IPX
)
1163 f
.ipx_network
= sipx
->sipx_network
;
1164 memcpy(f
.ipx_device
, ifr
.ifr_name
,
1165 sizeof(f
.ipx_device
));
1166 memcpy(f
.ipx_node
, sipx
->sipx_node
, IPX_NODE_LEN
);
1167 f
.ipx_dlink_type
= sipx
->sipx_type
;
1168 f
.ipx_special
= sipx
->sipx_special
;
1170 if (sipx
->sipx_action
== IPX_DLTITF
)
1171 rc
= ipxitf_delete(&f
);
1173 rc
= ipxitf_create(&f
);
1177 struct sockaddr_ipx
*sipx
;
1178 struct ipx_interface
*ipxif
;
1179 struct net_device
*dev
;
1182 if (copy_from_user(&ifr
, arg
, sizeof(ifr
)))
1184 sipx
= (struct sockaddr_ipx
*)&ifr
.ifr_addr
;
1185 dev
= __dev_get_by_name(&init_net
, ifr
.ifr_name
);
1189 ipxif
= ipxitf_find_using_phys(dev
,
1190 ipx_map_frame_type(sipx
->sipx_type
));
1191 rc
= -EADDRNOTAVAIL
;
1195 sipx
->sipx_family
= AF_IPX
;
1196 sipx
->sipx_network
= ipxif
->if_netnum
;
1197 memcpy(sipx
->sipx_node
, ipxif
->if_node
,
1198 sizeof(sipx
->sipx_node
));
1200 if (copy_to_user(arg
, &ifr
, sizeof(ifr
)))
1206 case SIOCAIPXITFCRT
:
1208 if (get_user(val
, (unsigned char __user
*) arg
))
1211 ipxcfg_auto_create_interfaces
= val
;
1213 case SIOCAIPXPRISLT
:
1215 if (get_user(val
, (unsigned char __user
*) arg
))
1218 ipxcfg_set_auto_select(val
);
1226 * Checksum routine for IPX
1229 /* Note: We assume ipx_tctrl==0 and htons(length)==ipx_pktsize */
1230 /* This functions should *not* mess with packet contents */
1232 __be16
ipx_cksum(struct ipxhdr
*packet
, int length
)
1235 * NOTE: sum is a net byte order quantity, which optimizes the
1236 * loop. This only works on big and little endian machines. (I
1237 * don't know of a machine that isn't.)
1239 /* handle the first 3 words separately; checksum should be skipped
1240 * and ipx_tctrl masked out */
1241 __u16
*p
= (__u16
*)packet
;
1242 __u32 sum
= p
[1] + (p
[2] & (__force u16
)htons(0x00ff));
1243 __u32 i
= (length
>> 1) - 3; /* Number of remaining complete words */
1245 /* Loop through them */
1250 /* Add on the last part word if it exists */
1251 if (packet
->ipx_pktsize
& htons(1))
1252 sum
+= (__force u16
)htons(0xff00) & *p
;
1254 /* Do final fixup */
1255 sum
= (sum
& 0xffff) + (sum
>> 16);
1257 /* It's a pity there's no concept of carry in C */
1262 * Leave 0 alone; we don't want 0xffff here. Note that we can't get
1263 * here with 0x10000, so this check is the same as ((__u16)sum)
1268 return (__force __be16
)sum
;
1271 const char *ipx_frame_name(__be16 frame
)
1275 switch (ntohs(frame
)) {
1276 case ETH_P_IPX
: rc
= "EtherII"; break;
1277 case ETH_P_802_2
: rc
= "802.2"; break;
1278 case ETH_P_SNAP
: rc
= "SNAP"; break;
1279 case ETH_P_802_3
: rc
= "802.3"; break;
1280 case ETH_P_TR_802_2
: rc
= "802.2TR"; break;
1286 const char *ipx_device_name(struct ipx_interface
*intrfc
)
1288 return intrfc
->if_internal
? "Internal" :
1289 intrfc
->if_dev
? intrfc
->if_dev
->name
: "Unknown";
1292 /* Handling for system calls applied via the various interfaces to an IPX
1295 static int ipx_setsockopt(struct socket
*sock
, int level
, int optname
,
1296 char __user
*optval
, unsigned int optlen
)
1298 struct sock
*sk
= sock
->sk
;
1303 if (optlen
!= sizeof(int))
1307 if (get_user(opt
, (unsigned int __user
*)optval
))
1311 if (!(level
== SOL_IPX
&& optname
== IPX_TYPE
))
1314 ipx_sk(sk
)->type
= opt
;
1321 static int ipx_getsockopt(struct socket
*sock
, int level
, int optname
,
1322 char __user
*optval
, int __user
*optlen
)
1324 struct sock
*sk
= sock
->sk
;
1327 int rc
= -ENOPROTOOPT
;
1330 if (!(level
== SOL_IPX
&& optname
== IPX_TYPE
))
1333 val
= ipx_sk(sk
)->type
;
1336 if (get_user(len
, optlen
))
1339 len
= min_t(unsigned int, len
, sizeof(int));
1345 if (put_user(len
, optlen
) || copy_to_user(optval
, &val
, len
))
1354 static struct proto ipx_proto
= {
1356 .owner
= THIS_MODULE
,
1357 .obj_size
= sizeof(struct ipx_sock
),
1360 static int ipx_create(struct net
*net
, struct socket
*sock
, int protocol
,
1363 int rc
= -ESOCKTNOSUPPORT
;
1366 if (!net_eq(net
, &init_net
))
1367 return -EAFNOSUPPORT
;
1370 * SPX support is not anymore in the kernel sources. If you want to
1371 * ressurrect it, completing it and making it understand shared skbs,
1372 * be fully multithreaded, etc, grab the sources in an early 2.5 kernel
1375 if (sock
->type
!= SOCK_DGRAM
)
1379 sk
= sk_alloc(net
, PF_IPX
, GFP_KERNEL
, &ipx_proto
);
1383 sk_refcnt_debug_inc(sk
);
1384 sock_init_data(sock
, sk
);
1385 sk
->sk_no_check
= 1; /* Checksum off by default */
1386 sock
->ops
= &ipx_dgram_ops
;
1392 static int ipx_release(struct socket
*sock
)
1394 struct sock
*sk
= sock
->sk
;
1400 if (!sock_flag(sk
, SOCK_DEAD
))
1401 sk
->sk_state_change(sk
);
1403 sock_set_flag(sk
, SOCK_DEAD
);
1405 sk_refcnt_debug_release(sk
);
1406 ipx_destroy_socket(sk
);
1412 /* caller must hold a reference to intrfc */
1414 static __be16
ipx_first_free_socketnum(struct ipx_interface
*intrfc
)
1416 unsigned short socketNum
= intrfc
->if_sknum
;
1418 spin_lock_bh(&intrfc
->if_sklist_lock
);
1420 if (socketNum
< IPX_MIN_EPHEMERAL_SOCKET
)
1421 socketNum
= IPX_MIN_EPHEMERAL_SOCKET
;
1423 while (__ipxitf_find_socket(intrfc
, htons(socketNum
)))
1424 if (socketNum
> IPX_MAX_EPHEMERAL_SOCKET
)
1425 socketNum
= IPX_MIN_EPHEMERAL_SOCKET
;
1429 spin_unlock_bh(&intrfc
->if_sklist_lock
);
1430 intrfc
->if_sknum
= socketNum
;
1432 return htons(socketNum
);
1435 static int __ipx_bind(struct socket
*sock
,
1436 struct sockaddr
*uaddr
, int addr_len
)
1438 struct sock
*sk
= sock
->sk
;
1439 struct ipx_sock
*ipxs
= ipx_sk(sk
);
1440 struct ipx_interface
*intrfc
;
1441 struct sockaddr_ipx
*addr
= (struct sockaddr_ipx
*)uaddr
;
1444 if (!sock_flag(sk
, SOCK_ZAPPED
) || addr_len
!= sizeof(struct sockaddr_ipx
))
1447 intrfc
= ipxitf_find_using_net(addr
->sipx_network
);
1448 rc
= -EADDRNOTAVAIL
;
1452 if (!addr
->sipx_port
) {
1453 addr
->sipx_port
= ipx_first_free_socketnum(intrfc
);
1455 if (!addr
->sipx_port
)
1459 /* protect IPX system stuff like routing/sap */
1461 if (ntohs(addr
->sipx_port
) < IPX_MIN_EPHEMERAL_SOCKET
&&
1462 !capable(CAP_NET_ADMIN
))
1465 ipxs
->port
= addr
->sipx_port
;
1467 #ifdef CONFIG_IPX_INTERN
1468 if (intrfc
== ipx_internal_net
) {
1469 /* The source address is to be set explicitly if the
1470 * socket is to be bound on the internal network. If a
1471 * node number 0 was specified, the default is used.
1475 if (!memcmp(addr
->sipx_node
, ipx_broadcast_node
, IPX_NODE_LEN
))
1477 if (!memcmp(addr
->sipx_node
, ipx_this_node
, IPX_NODE_LEN
))
1478 memcpy(ipxs
->node
, intrfc
->if_node
, IPX_NODE_LEN
);
1480 memcpy(ipxs
->node
, addr
->sipx_node
, IPX_NODE_LEN
);
1483 if (ipxitf_find_internal_socket(intrfc
, ipxs
->node
,
1486 "IPX: bind failed because port %X in use.\n",
1487 ntohs(addr
->sipx_port
));
1491 /* Source addresses are easy. It must be our
1492 * network:node pair for an interface routed to IPX
1493 * with the ipx routing ioctl()
1496 memcpy(ipxs
->node
, intrfc
->if_node
, IPX_NODE_LEN
);
1499 if (ipxitf_find_socket(intrfc
, addr
->sipx_port
)) {
1501 "IPX: bind failed because port %X in use.\n",
1502 ntohs(addr
->sipx_port
));
1507 #else /* !def CONFIG_IPX_INTERN */
1509 /* Source addresses are easy. It must be our network:node pair for
1510 an interface routed to IPX with the ipx routing ioctl() */
1513 if (ipxitf_find_socket(intrfc
, addr
->sipx_port
)) {
1514 SOCK_DEBUG(sk
, "IPX: bind failed because port %X in use.\n",
1515 ntohs((int)addr
->sipx_port
));
1519 #endif /* CONFIG_IPX_INTERN */
1521 ipxitf_insert_socket(intrfc
, sk
);
1522 sock_reset_flag(sk
, SOCK_ZAPPED
);
1531 static int ipx_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
1536 rc
= __ipx_bind(sock
, uaddr
, addr_len
);
1542 static int ipx_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
1543 int addr_len
, int flags
)
1545 struct sock
*sk
= sock
->sk
;
1546 struct ipx_sock
*ipxs
= ipx_sk(sk
);
1547 struct sockaddr_ipx
*addr
;
1549 struct ipx_route
*rt
;
1551 sk
->sk_state
= TCP_CLOSE
;
1552 sock
->state
= SS_UNCONNECTED
;
1555 if (addr_len
!= sizeof(*addr
))
1557 addr
= (struct sockaddr_ipx
*)uaddr
;
1559 /* put the autobinding in */
1561 struct sockaddr_ipx uaddr
;
1563 uaddr
.sipx_port
= 0;
1564 uaddr
.sipx_network
= 0;
1566 #ifdef CONFIG_IPX_INTERN
1569 goto out
; /* Someone zonked the iface */
1570 memcpy(uaddr
.sipx_node
, ipxs
->intrfc
->if_node
,
1572 #endif /* CONFIG_IPX_INTERN */
1574 rc
= __ipx_bind(sock
, (struct sockaddr
*)&uaddr
,
1575 sizeof(struct sockaddr_ipx
));
1580 /* We can either connect to primary network or somewhere
1581 * we can route to */
1582 rt
= ipxrtr_lookup(addr
->sipx_network
);
1584 if (!rt
&& !(!addr
->sipx_network
&& ipx_primary_net
))
1587 ipxs
->dest_addr
.net
= addr
->sipx_network
;
1588 ipxs
->dest_addr
.sock
= addr
->sipx_port
;
1589 memcpy(ipxs
->dest_addr
.node
, addr
->sipx_node
, IPX_NODE_LEN
);
1590 ipxs
->type
= addr
->sipx_type
;
1592 if (sock
->type
== SOCK_DGRAM
) {
1593 sock
->state
= SS_CONNECTED
;
1594 sk
->sk_state
= TCP_ESTABLISHED
;
1606 static int ipx_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
1607 int *uaddr_len
, int peer
)
1609 struct ipx_address
*addr
;
1610 struct sockaddr_ipx sipx
;
1611 struct sock
*sk
= sock
->sk
;
1612 struct ipx_sock
*ipxs
= ipx_sk(sk
);
1615 *uaddr_len
= sizeof(struct sockaddr_ipx
);
1620 if (sk
->sk_state
!= TCP_ESTABLISHED
)
1623 addr
= &ipxs
->dest_addr
;
1624 sipx
.sipx_network
= addr
->net
;
1625 sipx
.sipx_port
= addr
->sock
;
1626 memcpy(sipx
.sipx_node
, addr
->node
, IPX_NODE_LEN
);
1629 sipx
.sipx_network
= ipxs
->intrfc
->if_netnum
;
1630 #ifdef CONFIG_IPX_INTERN
1631 memcpy(sipx
.sipx_node
, ipxs
->node
, IPX_NODE_LEN
);
1633 memcpy(sipx
.sipx_node
, ipxs
->intrfc
->if_node
,
1635 #endif /* CONFIG_IPX_INTERN */
1638 sipx
.sipx_network
= 0;
1639 memset(sipx
.sipx_node
, '\0', IPX_NODE_LEN
);
1642 sipx
.sipx_port
= ipxs
->port
;
1645 sipx
.sipx_family
= AF_IPX
;
1646 sipx
.sipx_type
= ipxs
->type
;
1648 memcpy(uaddr
, &sipx
, sizeof(sipx
));
1656 static unsigned int ipx_datagram_poll(struct file
*file
, struct socket
*sock
,
1662 rc
= datagram_poll(file
, sock
, wait
);
1668 static int ipx_rcv(struct sk_buff
*skb
, struct net_device
*dev
, struct packet_type
*pt
, struct net_device
*orig_dev
)
1670 /* NULL here for pt means the packet was looped back */
1671 struct ipx_interface
*intrfc
;
1676 if (!net_eq(dev_net(dev
), &init_net
))
1680 if (skb
->pkt_type
== PACKET_OTHERHOST
)
1683 if ((skb
= skb_share_check(skb
, GFP_ATOMIC
)) == NULL
)
1686 if (!pskb_may_pull(skb
, sizeof(struct ipxhdr
)))
1689 ipx_pktsize
= ntohs(ipx_hdr(skb
)->ipx_pktsize
);
1691 /* Too small or invalid header? */
1692 if (ipx_pktsize
< sizeof(struct ipxhdr
) ||
1693 !pskb_may_pull(skb
, ipx_pktsize
))
1697 if (ipx
->ipx_checksum
!= IPX_NO_CHECKSUM
&&
1698 ipx
->ipx_checksum
!= ipx_cksum(ipx
, ipx_pktsize
))
1701 IPX_SKB_CB(skb
)->ipx_tctrl
= ipx
->ipx_tctrl
;
1702 IPX_SKB_CB(skb
)->ipx_dest_net
= ipx
->ipx_dest
.net
;
1703 IPX_SKB_CB(skb
)->ipx_source_net
= ipx
->ipx_source
.net
;
1705 /* Determine what local ipx endpoint this is */
1706 intrfc
= ipxitf_find_using_phys(dev
, pt
->type
);
1708 if (ipxcfg_auto_create_interfaces
&&
1709 IPX_SKB_CB(skb
)->ipx_dest_net
) {
1710 intrfc
= ipxitf_auto_create(dev
, pt
->type
);
1712 ipxitf_hold(intrfc
);
1715 if (!intrfc
) /* Not one of ours */
1716 /* or invalid packet for auto creation */
1720 rc
= ipxitf_rcv(intrfc
, skb
);
1729 static int ipx_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
1730 struct msghdr
*msg
, size_t len
)
1732 struct sock
*sk
= sock
->sk
;
1733 struct ipx_sock
*ipxs
= ipx_sk(sk
);
1734 struct sockaddr_ipx
*usipx
= (struct sockaddr_ipx
*)msg
->msg_name
;
1735 struct sockaddr_ipx local_sipx
;
1737 int flags
= msg
->msg_flags
;
1740 /* Socket gets bound below anyway */
1741 /* if (sk->sk_zapped)
1742 return -EIO; */ /* Socket not bound */
1743 if (flags
& ~(MSG_DONTWAIT
|MSG_CMSG_COMPAT
))
1746 /* Max possible packet size limited by 16 bit pktsize in header */
1747 if (len
>= 65535 - sizeof(struct ipxhdr
))
1752 struct sockaddr_ipx uaddr
;
1754 uaddr
.sipx_port
= 0;
1755 uaddr
.sipx_network
= 0;
1756 #ifdef CONFIG_IPX_INTERN
1759 goto out
; /* Someone zonked the iface */
1760 memcpy(uaddr
.sipx_node
, ipxs
->intrfc
->if_node
,
1763 rc
= __ipx_bind(sock
, (struct sockaddr
*)&uaddr
,
1764 sizeof(struct sockaddr_ipx
));
1770 if (msg
->msg_namelen
< sizeof(*usipx
) ||
1771 usipx
->sipx_family
!= AF_IPX
)
1775 if (sk
->sk_state
!= TCP_ESTABLISHED
)
1778 usipx
= &local_sipx
;
1779 usipx
->sipx_family
= AF_IPX
;
1780 usipx
->sipx_type
= ipxs
->type
;
1781 usipx
->sipx_port
= ipxs
->dest_addr
.sock
;
1782 usipx
->sipx_network
= ipxs
->dest_addr
.net
;
1783 memcpy(usipx
->sipx_node
, ipxs
->dest_addr
.node
, IPX_NODE_LEN
);
1786 rc
= ipxrtr_route_packet(sk
, usipx
, msg
->msg_iov
, len
,
1787 flags
& MSG_DONTWAIT
);
1796 static int ipx_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
1797 struct msghdr
*msg
, size_t size
, int flags
)
1799 struct sock
*sk
= sock
->sk
;
1800 struct ipx_sock
*ipxs
= ipx_sk(sk
);
1801 struct sockaddr_ipx
*sipx
= (struct sockaddr_ipx
*)msg
->msg_name
;
1802 struct ipxhdr
*ipx
= NULL
;
1803 struct sk_buff
*skb
;
1807 /* put the autobinding in */
1809 struct sockaddr_ipx uaddr
;
1811 uaddr
.sipx_port
= 0;
1812 uaddr
.sipx_network
= 0;
1814 #ifdef CONFIG_IPX_INTERN
1817 goto out
; /* Someone zonked the iface */
1818 memcpy(uaddr
.sipx_node
, ipxs
->intrfc
->if_node
, IPX_NODE_LEN
);
1819 #endif /* CONFIG_IPX_INTERN */
1821 rc
= __ipx_bind(sock
, (struct sockaddr
*)&uaddr
,
1822 sizeof(struct sockaddr_ipx
));
1828 if (sock_flag(sk
, SOCK_ZAPPED
))
1831 skb
= skb_recv_datagram(sk
, flags
& ~MSG_DONTWAIT
,
1832 flags
& MSG_DONTWAIT
, &rc
);
1837 copied
= ntohs(ipx
->ipx_pktsize
) - sizeof(struct ipxhdr
);
1838 if (copied
> size
) {
1840 msg
->msg_flags
|= MSG_TRUNC
;
1843 rc
= skb_copy_datagram_iovec(skb
, sizeof(struct ipxhdr
), msg
->msg_iov
,
1847 if (skb
->tstamp
.tv64
)
1848 sk
->sk_stamp
= skb
->tstamp
;
1850 msg
->msg_namelen
= sizeof(*sipx
);
1853 sipx
->sipx_family
= AF_IPX
;
1854 sipx
->sipx_port
= ipx
->ipx_source
.sock
;
1855 memcpy(sipx
->sipx_node
, ipx
->ipx_source
.node
, IPX_NODE_LEN
);
1856 sipx
->sipx_network
= IPX_SKB_CB(skb
)->ipx_source_net
;
1857 sipx
->sipx_type
= ipx
->ipx_type
;
1858 sipx
->sipx_zero
= 0;
1863 skb_free_datagram(sk
, skb
);
1870 static int ipx_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1874 struct sock
*sk
= sock
->sk
;
1875 void __user
*argp
= (void __user
*)arg
;
1880 amount
= sk
->sk_sndbuf
- sk_wmem_alloc_get(sk
);
1883 rc
= put_user(amount
, (int __user
*)argp
);
1886 struct sk_buff
*skb
= skb_peek(&sk
->sk_receive_queue
);
1887 /* These two are safe on a single CPU system as only
1888 * user tasks fiddle here */
1890 amount
= skb
->len
- sizeof(struct ipxhdr
);
1891 rc
= put_user(amount
, (int __user
*)argp
);
1897 if (capable(CAP_NET_ADMIN
))
1898 rc
= ipxrtr_ioctl(cmd
, argp
);
1901 case SIOCAIPXITFCRT
:
1902 case SIOCAIPXPRISLT
:
1904 if (!capable(CAP_NET_ADMIN
))
1907 rc
= ipxitf_ioctl(cmd
, argp
);
1909 case SIOCIPXCFGDATA
:
1910 rc
= ipxcfg_get_config_data(argp
);
1912 case SIOCIPXNCPCONN
:
1914 * This socket wants to take care of the NCP connection
1915 * handed to us in arg.
1918 if (!capable(CAP_NET_ADMIN
))
1920 rc
= get_user(ipx_sk(sk
)->ipx_ncp_conn
,
1921 (const unsigned short __user
*)argp
);
1926 rc
= sock_get_timestamp(sk
, argp
);
1928 case SIOCGIFDSTADDR
:
1929 case SIOCSIFDSTADDR
:
1930 case SIOCGIFBRDADDR
:
1931 case SIOCSIFBRDADDR
:
1932 case SIOCGIFNETMASK
:
1933 case SIOCSIFNETMASK
:
1946 #ifdef CONFIG_COMPAT
1947 static int ipx_compat_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1950 * These 4 commands use same structure on 32bit and 64bit. Rest of IPX
1951 * commands is handled by generic ioctl code. As these commands are
1952 * SIOCPROTOPRIVATE..SIOCPROTOPRIVATE+3, they cannot be handled by generic
1956 case SIOCAIPXITFCRT
:
1957 case SIOCAIPXPRISLT
:
1958 case SIOCIPXCFGDATA
:
1959 case SIOCIPXNCPCONN
:
1960 return ipx_ioctl(sock
, cmd
, arg
);
1962 return -ENOIOCTLCMD
;
1969 * Socket family declarations
1972 static const struct net_proto_family ipx_family_ops
= {
1974 .create
= ipx_create
,
1975 .owner
= THIS_MODULE
,
1978 static const struct proto_ops ipx_dgram_ops
= {
1980 .owner
= THIS_MODULE
,
1981 .release
= ipx_release
,
1983 .connect
= ipx_connect
,
1984 .socketpair
= sock_no_socketpair
,
1985 .accept
= sock_no_accept
,
1986 .getname
= ipx_getname
,
1987 .poll
= ipx_datagram_poll
,
1989 #ifdef CONFIG_COMPAT
1990 .compat_ioctl
= ipx_compat_ioctl
,
1992 .listen
= sock_no_listen
,
1993 .shutdown
= sock_no_shutdown
, /* FIXME: support shutdown */
1994 .setsockopt
= ipx_setsockopt
,
1995 .getsockopt
= ipx_getsockopt
,
1996 .sendmsg
= ipx_sendmsg
,
1997 .recvmsg
= ipx_recvmsg
,
1998 .mmap
= sock_no_mmap
,
1999 .sendpage
= sock_no_sendpage
,
2002 static struct packet_type ipx_8023_packet_type __read_mostly
= {
2003 .type
= cpu_to_be16(ETH_P_802_3
),
2007 static struct packet_type ipx_dix_packet_type __read_mostly
= {
2008 .type
= cpu_to_be16(ETH_P_IPX
),
2012 static struct notifier_block ipx_dev_notifier
= {
2013 .notifier_call
= ipxitf_device_event
,
2016 extern struct datalink_proto
*make_EII_client(void);
2017 extern void destroy_EII_client(struct datalink_proto
*);
2019 static const unsigned char ipx_8022_type
= 0xE0;
2020 static const unsigned char ipx_snap_id
[5] = { 0x0, 0x0, 0x0, 0x81, 0x37 };
2021 static const char ipx_EII_err_msg
[] __initconst
=
2022 KERN_CRIT
"IPX: Unable to register with Ethernet II\n";
2023 static const char ipx_8023_err_msg
[] __initconst
=
2024 KERN_CRIT
"IPX: Unable to register with 802.3\n";
2025 static const char ipx_llc_err_msg
[] __initconst
=
2026 KERN_CRIT
"IPX: Unable to register with 802.2\n";
2027 static const char ipx_snap_err_msg
[] __initconst
=
2028 KERN_CRIT
"IPX: Unable to register with SNAP\n";
2030 static int __init
ipx_init(void)
2032 int rc
= proto_register(&ipx_proto
, 1);
2037 sock_register(&ipx_family_ops
);
2039 pEII_datalink
= make_EII_client();
2041 dev_add_pack(&ipx_dix_packet_type
);
2043 printk(ipx_EII_err_msg
);
2045 p8023_datalink
= make_8023_client();
2047 dev_add_pack(&ipx_8023_packet_type
);
2049 printk(ipx_8023_err_msg
);
2051 p8022_datalink
= register_8022_client(ipx_8022_type
, ipx_rcv
);
2052 if (!p8022_datalink
)
2053 printk(ipx_llc_err_msg
);
2055 pSNAP_datalink
= register_snap_client(ipx_snap_id
, ipx_rcv
);
2056 if (!pSNAP_datalink
)
2057 printk(ipx_snap_err_msg
);
2059 register_netdevice_notifier(&ipx_dev_notifier
);
2060 ipx_register_sysctl();
2066 static void __exit
ipx_proto_finito(void)
2069 ipx_unregister_sysctl();
2071 unregister_netdevice_notifier(&ipx_dev_notifier
);
2075 if (pSNAP_datalink
) {
2076 unregister_snap_client(pSNAP_datalink
);
2077 pSNAP_datalink
= NULL
;
2080 if (p8022_datalink
) {
2081 unregister_8022_client(p8022_datalink
);
2082 p8022_datalink
= NULL
;
2085 dev_remove_pack(&ipx_8023_packet_type
);
2086 if (p8023_datalink
) {
2087 destroy_8023_client(p8023_datalink
);
2088 p8023_datalink
= NULL
;
2091 dev_remove_pack(&ipx_dix_packet_type
);
2092 if (pEII_datalink
) {
2093 destroy_EII_client(pEII_datalink
);
2094 pEII_datalink
= NULL
;
2097 proto_unregister(&ipx_proto
);
2098 sock_unregister(ipx_family_ops
.family
);
2101 module_init(ipx_init
);
2102 module_exit(ipx_proto_finito
);
2103 MODULE_LICENSE("GPL");
2104 MODULE_ALIAS_NETPROTO(PF_IPX
);