This source file includes following definitions.
- ipxcfg_set_auto_create
- ipxcfg_set_auto_select
- ipxcfg_get_config_data
- ipx_remove_socket
- ipx_destroy_socket
- ipxitf_clear_primary_net
- ipxitf_find_using_phys
- ipxitf_find_using_net
- ipxitf_insert_socket
- ipxitf_find_socket
- ipxitf_down
- ipxitf_device_event
- ipxitf_def_skb_handler
- ipxitf_demux_socket
- ipxitf_adjust_skbuff
- ipxitf_send
- ipxitf_add_local_route
- ipxitf_rcv
- ipxitf_insert
- ipxitf_create_internal
- ipx_map_frame_type
- ipxitf_create
- ipxitf_delete
- ipxitf_auto_create
- ipxitf_ioctl
- ipxrtr_lookup
- ipxrtr_add_route
- ipxrtr_del_routes
- ipxrtr_create
- ipxrtr_delete
- ipxrtr_route_packet
- ipxrtr_route_skb
- ipxrtr_ioctl
- ipx_frame_name
- ipx_device_name
- ipx_interface_get_info
- ipx_get_info
- ipx_rt_get_info
- ipx_fcntl
- ipx_setsockopt
- ipx_getsockopt
- ipx_listen
- def_callback1
- def_callback2
- ipx_create
- ipx_release
- ipx_dup
- ipx_first_free_socketnum
- ipx_bind
- ipx_connect
- ipx_socketpair
- ipx_accept
- ipx_getname
- dump_data
- dump_addr
- dump_hdr
- dump_pkt
- ipx_rcv
- ipx_sendmsg
- ipx_recvmsg
- ipx_shutdown
- ipx_select
- ipx_ioctl
- ipx_proto_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 #include <linux/config.h>
50 #include <linux/errno.h>
51 #include <linux/types.h>
52 #include <linux/socket.h>
53 #include <linux/in.h>
54 #include <linux/kernel.h>
55 #include <linux/sched.h>
56 #include <linux/timer.h>
57 #include <linux/string.h>
58 #include <linux/sockios.h>
59 #include <linux/net.h>
60 #include <linux/ipx.h>
61 #include <linux/inet.h>
62 #include <linux/netdevice.h>
63 #include <linux/route.h>
64 #include <linux/skbuff.h>
65 #include <net/sock.h>
66 #include <asm/segment.h>
67 #include <asm/system.h>
68 #include <linux/fcntl.h>
69 #include <linux/mm.h>
70 #include <linux/termios.h>
71 #include <linux/interrupt.h>
72 #include <net/p8022.h>
73 #include <net/psnap.h>
74 #include <linux/proc_fs.h>
75 #include <linux/stat.h>
76 #include <linux/firewall.h>
77
78 #ifdef CONFIG_IPX
79
80 static unsigned char ipxcfg_max_hops = 16;
81 static char ipxcfg_auto_select_primary = 0;
82 static char ipxcfg_auto_create_interfaces = 0;
83
84
85 static struct datalink_proto *p8022_datalink = NULL;
86 static struct datalink_proto *pEII_datalink = NULL;
87 static struct datalink_proto *p8023_datalink = NULL;
88 static struct datalink_proto *pSNAP_datalink = NULL;
89
90 static ipx_interface *ipx_interfaces = NULL;
91 static ipx_route *ipx_routes = NULL;
92 static ipx_interface *ipx_internal_net = NULL;
93 static ipx_interface *ipx_primary_net = NULL;
94
95 static int
96 ipxcfg_set_auto_create(char val)
97 {
98 ipxcfg_auto_create_interfaces = val;
99 return 0;
100 }
101
102 static int
103 ipxcfg_set_auto_select(char val)
104 {
105 ipxcfg_auto_select_primary = val;
106 if (val && (ipx_primary_net == NULL))
107 ipx_primary_net = ipx_interfaces;
108 return 0;
109 }
110
111 static int
112 ipxcfg_get_config_data(ipx_config_data *arg)
113 {
114 ipx_config_data vals;
115
116 vals.ipxcfg_auto_create_interfaces = ipxcfg_auto_create_interfaces;
117 vals.ipxcfg_auto_select_primary = ipxcfg_auto_select_primary;
118 memcpy_tofs(arg, &vals, sizeof(vals));
119 return 0;
120 }
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 static void
136 ipx_remove_socket(ipx_socket *sk)
137 {
138 ipx_socket *s;
139 ipx_interface *intrfc;
140 unsigned long flags;
141
142 save_flags(flags);
143 cli();
144
145
146 intrfc = sk->ipx_intrfc;
147 if (intrfc == NULL) {
148 restore_flags(flags);
149 return;
150 }
151
152 s=intrfc->if_sklist;
153 if(s==sk) {
154 intrfc->if_sklist=s->next;
155 restore_flags(flags);
156 return;
157 }
158
159 while(s && s->next) {
160 if(s->next==sk) {
161 s->next=sk->next;
162 restore_flags(flags);
163 return;
164 }
165 s=s->next;
166 }
167 restore_flags(flags);
168 }
169
170
171
172
173
174
175
176
177 static void
178 ipx_destroy_socket(ipx_socket *sk)
179 {
180 struct sk_buff *skb;
181
182 ipx_remove_socket(sk);
183 while((skb=skb_dequeue(&sk->receive_queue))!=NULL) {
184 kfree_skb(skb,FREE_READ);
185 }
186
187 kfree_s(sk,sizeof(*sk));
188 }
189
190
191
192
193
194 static ipx_route * ipxrtr_lookup(unsigned long);
195
196 static void
197 ipxitf_clear_primary_net(void)
198 {
199 if (ipxcfg_auto_select_primary && (ipx_interfaces != NULL))
200 ipx_primary_net = ipx_interfaces;
201 else
202 ipx_primary_net = NULL;
203 }
204
205 static ipx_interface *
206 ipxitf_find_using_phys(struct device *dev, unsigned short datalink)
207 {
208 ipx_interface *i;
209
210 for (i=ipx_interfaces;
211 i && ((i->if_dev!=dev) || (i->if_dlink_type!=datalink));
212 i=i->if_next)
213 ;
214 return i;
215 }
216
217 static ipx_interface *
218 ipxitf_find_using_net(unsigned long net)
219 {
220 ipx_interface *i;
221
222 if (net == 0L)
223 return ipx_primary_net;
224
225 for (i=ipx_interfaces; i && (i->if_netnum!=net); i=i->if_next)
226 ;
227
228 return i;
229 }
230
231
232 static void
233 ipxitf_insert_socket(ipx_interface *intrfc, ipx_socket *sk)
234 {
235 ipx_socket *s;
236
237 sk->ipx_intrfc = intrfc;
238 sk->next = NULL;
239 if (intrfc->if_sklist == NULL) {
240 intrfc->if_sklist = sk;
241 } else {
242 for (s = intrfc->if_sklist; s->next != NULL; s = s->next)
243 ;
244 s->next = sk;
245 }
246 }
247
248 static ipx_socket *
249 ipxitf_find_socket(ipx_interface *intrfc, unsigned short port)
250 {
251 ipx_socket *s;
252
253 for (s=intrfc->if_sklist;
254 (s != NULL) && (s->ipx_port != port);
255 s=s->next)
256 ;
257
258 return s;
259 }
260
261 static void ipxrtr_del_routes(ipx_interface *);
262
263 static void
264 ipxitf_down(ipx_interface *intrfc)
265 {
266 ipx_interface *i;
267 ipx_socket *s, *t;
268
269
270 ipxrtr_del_routes(intrfc);
271
272
273 for (s = intrfc->if_sklist; s != NULL; ) {
274 s->err = ENOLINK;
275 s->error_report(s);
276 s->ipx_intrfc = NULL;
277 s->ipx_port = 0;
278 s->zapped=1;
279 t = s;
280 s = s->next;
281 t->next = NULL;
282 }
283 intrfc->if_sklist = NULL;
284
285
286 if (intrfc == ipx_interfaces) {
287 ipx_interfaces = intrfc->if_next;
288 } else {
289 for (i = ipx_interfaces;
290 (i != NULL) && (i->if_next != intrfc);
291 i = i->if_next)
292 ;
293 if ((i != NULL) && (i->if_next == intrfc))
294 i->if_next = intrfc->if_next;
295 }
296
297
298 if (intrfc == ipx_primary_net)
299 ipxitf_clear_primary_net();
300 if (intrfc == ipx_internal_net)
301 ipx_internal_net = NULL;
302
303 kfree_s(intrfc, sizeof(*intrfc));
304 }
305
306 static int
307 ipxitf_device_event(struct notifier_block *notifier, unsigned long event, void *ptr)
308 {
309 struct device *dev = ptr;
310 ipx_interface *i, *tmp;
311
312 if(event!=NETDEV_DOWN)
313 return NOTIFY_DONE;
314
315 for (i = ipx_interfaces; i != NULL; ) {
316
317 tmp = i->if_next;
318 if (i->if_dev == dev)
319 ipxitf_down(i);
320 i = tmp;
321
322 }
323
324 return NOTIFY_DONE;
325 }
326
327 static int ipxitf_def_skb_handler(struct sock *sock, struct sk_buff *skb)
328 {
329 int retval;
330
331 if((retval = sock_queue_rcv_skb(sock, skb))<0)
332 {
333
334
335
336
337
338
339
340
341 kfree_skb(skb,FREE_WRITE);
342 }
343 return retval;
344 }
345
346
347
348
349
350
351
352 static int ipxitf_demux_socket(ipx_interface *intrfc, struct sk_buff *skb, int copy)
353 {
354 ipx_packet *ipx = (ipx_packet *)(skb->h.raw);
355 ipx_socket *sock1 = NULL, *sock2 = NULL;
356 struct sk_buff *skb1 = NULL, *skb2 = NULL;
357
358 sock1 = ipxitf_find_socket(intrfc, ipx->ipx_dest.sock);
359
360
361
362
363
364
365
366
367
368 if (ipx_primary_net && (intrfc != ipx_primary_net))
369 {
370 switch (ntohs(ipx->ipx_dest.sock))
371 {
372 case 0x452:
373 case 0x453:
374 case 0x456:
375
376
377
378
379
380
381 sock2 = ipxitf_find_socket(ipx_primary_net,
382 ipx->ipx_dest.sock);
383 break;
384 default:
385 break;
386 }
387 }
388
389
390
391
392
393
394 if (sock1 == NULL && sock2 == NULL)
395 {
396 if (!copy)
397 kfree_skb(skb,FREE_WRITE);
398 return 0;
399 }
400
401
402
403
404
405
406
407
408
409 if (copy)
410 {
411 skb1 = skb_clone(skb, GFP_ATOMIC);
412 if (skb1 != NULL)
413 skb1->arp = skb1->free = 1;
414 }
415 else
416 {
417 skb1 = skb;
418 }
419
420 if (skb1 == NULL)
421 return -ENOMEM;
422
423
424
425
426
427 if (sock1 && sock2)
428 {
429 skb2 = skb_clone(skb1, GFP_ATOMIC);
430 if (skb2 != NULL)
431 skb2->arp = skb2->free = 1;
432 }
433 else
434 skb2 = skb1;
435
436 if (sock1)
437 (void) ipxitf_def_skb_handler(sock1, skb1);
438
439 if (skb2 == NULL)
440 return -ENOMEM;
441
442 if (sock2)
443 (void) ipxitf_def_skb_handler(sock2, skb2);
444
445 return 0;
446 }
447
448 static struct sk_buff *
449 ipxitf_adjust_skbuff(ipx_interface *intrfc, struct sk_buff *skb)
450 {
451 struct sk_buff *skb2;
452 int in_offset = skb->h.raw - skb->head;
453 int out_offset = intrfc->if_ipx_offset;
454 int len;
455
456
457 if (in_offset >= out_offset) {
458 skb->arp = skb->free = 1;
459 return skb;
460 }
461
462
463 len = skb->len + out_offset;
464 skb2 = alloc_skb(len, GFP_ATOMIC);
465 if (skb2 != NULL) {
466 skb_reserve(skb2,out_offset);
467 skb2->h.raw=skb_put(skb2,skb->len);
468 skb2->free=1;
469 skb2->arp=1;
470 memcpy(skb2->h.raw, skb->h.raw, skb->len);
471 }
472 kfree_skb(skb, FREE_WRITE);
473 return skb2;
474 }
475
476 static int ipxitf_send(ipx_interface *intrfc, struct sk_buff *skb, char *node)
477 {
478 ipx_packet *ipx = (ipx_packet *)(skb->h.raw);
479 struct device *dev = intrfc->if_dev;
480 struct datalink_proto *dl = intrfc->if_dlink;
481 char dest_node[IPX_NODE_LEN];
482 int send_to_wire = 1;
483 int addr_len;
484
485
486
487
488
489
490 if ((dl == NULL) || (dev == NULL) || (dev->flags & IFF_LOOPBACK))
491 send_to_wire = 0;
492
493
494
495
496
497
498
499
500 if (ipx->ipx_dest.net == intrfc->if_netnum)
501 {
502
503
504
505 if (memcmp(intrfc->if_node, node, IPX_NODE_LEN) == 0)
506 {
507
508
509
510 if(skb->sk)
511 skb->sk->wmem_alloc-=skb->truesize;
512
513
514
515 return ipxitf_demux_socket(intrfc, skb, 0);
516 }
517
518
519
520 if (memcmp(ipx_broadcast_node, node, IPX_NODE_LEN) == 0)
521 {
522 if (!send_to_wire && skb->sk)
523 skb->sk->wmem_alloc-=skb->truesize;
524 ipxitf_demux_socket(intrfc, skb, send_to_wire);
525 if (!send_to_wire)
526 return 0;
527 }
528 }
529
530
531
532
533
534
535
536 if (ipx->ipx_source.net != intrfc->if_netnum)
537 {
538 if (++(ipx->ipx_tctrl) > ipxcfg_max_hops)
539 send_to_wire = 0;
540 }
541
542 if (!send_to_wire)
543 {
544
545
546
547
548
549
550
551
552 kfree_skb(skb,FREE_WRITE);
553 return 0;
554 }
555
556
557
558
559
560 addr_len = dev->addr_len;
561 if (memcmp(ipx_broadcast_node, node, IPX_NODE_LEN) == 0)
562 memcpy(dest_node, dev->broadcast, addr_len);
563 else
564 memcpy(dest_node, &(node[IPX_NODE_LEN-addr_len]), addr_len);
565
566
567
568
569
570 skb = ipxitf_adjust_skbuff(intrfc, skb);
571 if (skb == NULL)
572 return 0;
573
574
575 skb->dev = dev;
576 skb->protocol = htons(ETH_P_IPX);
577 dl->datalink_header(dl, skb, dest_node);
578 #if 0
579
580
581
582
583 dump_pkt("IPX snd:", (ipx_packet *)skb->h.raw);
584 dump_data("ETH hdr:", skb->data, skb->h.raw - skb->data);
585 #endif
586
587
588
589
590
591 dev_queue_xmit(skb, dev, SOPRI_NORMAL);
592 return 0;
593 }
594
595 static int ipxrtr_add_route(unsigned long, ipx_interface *, unsigned char *);
596
597 static int ipxitf_add_local_route(ipx_interface *intrfc)
598 {
599 return ipxrtr_add_route(intrfc->if_netnum, intrfc, NULL);
600 }
601
602 static const char * ipx_frame_name(unsigned short);
603 static const char * ipx_device_name(ipx_interface *);
604 static int ipxrtr_route_skb(struct sk_buff *);
605
606 static int ipxitf_rcv(ipx_interface *intrfc, struct sk_buff *skb)
607 {
608 ipx_packet *ipx = (ipx_packet *) (skb->h.raw);
609 ipx_interface *i;
610
611 #ifdef CONFIG_FIREWALL
612
613
614
615
616 if (call_in_firewall(PF_IPX, skb, ipx)!=FW_ACCEPT)
617 {
618 kfree_skb(skb, FREE_READ);
619 return 0;
620 }
621
622 #endif
623
624
625 if ((intrfc->if_netnum == 0L) &&
626 (ipx->ipx_source.net == ipx->ipx_dest.net) &&
627 (ipx->ipx_source.net != 0L))
628 {
629
630
631
632
633 if ((i=ipxitf_find_using_net(ipx->ipx_source.net))==NULL)
634 {
635 intrfc->if_netnum = ipx->ipx_source.net;
636 (void) ipxitf_add_local_route(intrfc);
637 }
638 else
639 {
640 printk("IPX: Network number collision %lx\n\t%s %s and %s %s\n",
641 htonl(ipx->ipx_source.net),
642 ipx_device_name(i),
643 ipx_frame_name(i->if_dlink_type),
644 ipx_device_name(intrfc),
645 ipx_frame_name(intrfc->if_dlink_type));
646 }
647 }
648
649 if (ipx->ipx_dest.net == 0L)
650 ipx->ipx_dest.net = intrfc->if_netnum;
651 if (ipx->ipx_source.net == 0L)
652 ipx->ipx_source.net = intrfc->if_netnum;
653
654 if (intrfc->if_netnum != ipx->ipx_dest.net)
655 {
656 #ifdef CONFIG_FIREWALL
657
658
659
660 if (call_fw_firewall(PF_IPX, skb, ipx)!=FW_ACCEPT)
661 {
662 kfree_skb(skb, FREE_READ);
663 return 0;
664 }
665 #endif
666
667 if ((skb->pkt_type != PACKET_BROADCAST) &&
668 (skb->pkt_type != PACKET_MULTICAST))
669 return ipxrtr_route_skb(skb);
670
671 kfree_skb(skb,FREE_READ);
672 return 0;
673 }
674
675
676 if ((memcmp(ipx_broadcast_node, ipx->ipx_dest.node, IPX_NODE_LEN) == 0)
677 || (memcmp(intrfc->if_node, ipx->ipx_dest.node, IPX_NODE_LEN) == 0))
678 {
679 return ipxitf_demux_socket(intrfc, skb, 0);
680 }
681
682
683 kfree_skb(skb,FREE_READ);
684 return 0;
685 }
686
687 static void
688 ipxitf_insert(ipx_interface *intrfc)
689 {
690 ipx_interface *i;
691
692 intrfc->if_next = NULL;
693 if (ipx_interfaces == NULL) {
694 ipx_interfaces = intrfc;
695 } else {
696 for (i = ipx_interfaces; i->if_next != NULL; i = i->if_next)
697 ;
698 i->if_next = intrfc;
699 }
700
701 if (ipxcfg_auto_select_primary && (ipx_primary_net == NULL))
702 ipx_primary_net = intrfc;
703 }
704
705 static int
706 ipxitf_create_internal(ipx_interface_definition *idef)
707 {
708 ipx_interface *intrfc;
709
710
711 if (ipx_primary_net != NULL) return -EEXIST;
712
713
714 if (idef->ipx_network == 0L) return -EADDRNOTAVAIL;
715 if (ipxitf_find_using_net(idef->ipx_network) != NULL)
716 return -EADDRINUSE;
717
718 intrfc=(ipx_interface *)kmalloc(sizeof(ipx_interface),GFP_ATOMIC);
719 if (intrfc==NULL)
720 return -EAGAIN;
721 intrfc->if_dev=NULL;
722 intrfc->if_netnum=idef->ipx_network;
723 intrfc->if_dlink_type = 0;
724 intrfc->if_dlink = NULL;
725 intrfc->if_sklist = NULL;
726 intrfc->if_internal = 1;
727 intrfc->if_ipx_offset = 0;
728 intrfc->if_sknum = IPX_MIN_EPHEMERAL_SOCKET;
729 memcpy((char *)&(intrfc->if_node), idef->ipx_node, IPX_NODE_LEN);
730 ipx_internal_net = intrfc;
731 ipx_primary_net = intrfc;
732 ipxitf_insert(intrfc);
733 return ipxitf_add_local_route(intrfc);
734 }
735
736 static int
737 ipx_map_frame_type(unsigned char type)
738 {
739 switch (type) {
740 case IPX_FRAME_ETHERII: return htons(ETH_P_IPX);
741 case IPX_FRAME_8022: return htons(ETH_P_802_2);
742 case IPX_FRAME_SNAP: return htons(ETH_P_SNAP);
743 case IPX_FRAME_8023: return htons(ETH_P_802_3);
744 }
745 return 0;
746 }
747
748 static int
749 ipxitf_create(ipx_interface_definition *idef)
750 {
751 struct device *dev;
752 unsigned short dlink_type = 0;
753 struct datalink_proto *datalink = NULL;
754 ipx_interface *intrfc;
755
756 if (idef->ipx_special == IPX_INTERNAL)
757 return ipxitf_create_internal(idef);
758
759 if ((idef->ipx_special == IPX_PRIMARY) && (ipx_primary_net != NULL))
760 return -EEXIST;
761
762 if ((idef->ipx_network != 0L) &&
763 (ipxitf_find_using_net(idef->ipx_network) != NULL))
764 return -EADDRINUSE;
765
766 switch (idef->ipx_dlink_type) {
767 case IPX_FRAME_ETHERII:
768 dlink_type = htons(ETH_P_IPX);
769 datalink = pEII_datalink;
770 break;
771 case IPX_FRAME_8022:
772 dlink_type = htons(ETH_P_802_2);
773 datalink = p8022_datalink;
774 break;
775 case IPX_FRAME_SNAP:
776 dlink_type = htons(ETH_P_SNAP);
777 datalink = pSNAP_datalink;
778 break;
779 case IPX_FRAME_8023:
780 dlink_type = htons(ETH_P_802_3);
781 datalink = p8023_datalink;
782 break;
783 case IPX_FRAME_NONE:
784 default:
785 break;
786 }
787
788 if (datalink == NULL)
789 return -EPROTONOSUPPORT;
790
791 dev=dev_get(idef->ipx_device);
792 if (dev==NULL)
793 return -ENODEV;
794
795 if (!(dev->flags & IFF_UP))
796 return -ENETDOWN;
797
798
799 if(dev->addr_len>IPX_NODE_LEN)
800 return -EINVAL;
801
802 if ((intrfc = ipxitf_find_using_phys(dev, dlink_type)) == NULL) {
803
804
805 intrfc=(ipx_interface *)kmalloc(sizeof(ipx_interface),GFP_ATOMIC);
806 if (intrfc==NULL)
807 return -EAGAIN;
808 intrfc->if_dev=dev;
809 intrfc->if_netnum=idef->ipx_network;
810 intrfc->if_dlink_type = dlink_type;
811 intrfc->if_dlink = datalink;
812 intrfc->if_sklist = NULL;
813 intrfc->if_sknum = IPX_MIN_EPHEMERAL_SOCKET;
814
815 if ((idef->ipx_special == IPX_PRIMARY))
816 ipx_primary_net = intrfc;
817 intrfc->if_internal = 0;
818 intrfc->if_ipx_offset = dev->hard_header_len + datalink->header_length;
819 memset(intrfc->if_node, 0, IPX_NODE_LEN);
820 memcpy((char *)&(intrfc->if_node[IPX_NODE_LEN-dev->addr_len]), dev->dev_addr, dev->addr_len);
821
822 ipxitf_insert(intrfc);
823 }
824
825
826 if (intrfc->if_netnum == 0L)
827 return 0;
828
829 return ipxitf_add_local_route(intrfc);
830 }
831
832 static int
833 ipxitf_delete(ipx_interface_definition *idef)
834 {
835 struct device *dev = NULL;
836 unsigned short dlink_type = 0;
837 ipx_interface *intrfc;
838
839 if (idef->ipx_special == IPX_INTERNAL) {
840 if (ipx_internal_net != NULL) {
841 ipxitf_down(ipx_internal_net);
842 return 0;
843 }
844 return -ENOENT;
845 }
846
847 dlink_type = ipx_map_frame_type(idef->ipx_dlink_type);
848 if (dlink_type == 0)
849 return -EPROTONOSUPPORT;
850
851 dev=dev_get(idef->ipx_device);
852 if(dev==NULL) return -ENODEV;
853
854 intrfc = ipxitf_find_using_phys(dev, dlink_type);
855 if (intrfc != NULL) {
856 ipxitf_down(intrfc);
857 return 0;
858 }
859 return -EINVAL;
860 }
861
862 static ipx_interface *
863 ipxitf_auto_create(struct device *dev, unsigned short dlink_type)
864 {
865 struct datalink_proto *datalink = NULL;
866 ipx_interface *intrfc;
867
868 switch (htons(dlink_type)) {
869 case ETH_P_IPX: datalink = pEII_datalink; break;
870 case ETH_P_802_2: datalink = p8022_datalink; break;
871 case ETH_P_SNAP: datalink = pSNAP_datalink; break;
872 case ETH_P_802_3: datalink = p8023_datalink; break;
873 default: return NULL;
874 }
875
876 if (dev == NULL)
877 return NULL;
878
879
880 if(dev->addr_len>IPX_NODE_LEN) return NULL;
881
882 intrfc=(ipx_interface *)kmalloc(sizeof(ipx_interface),GFP_ATOMIC);
883 if (intrfc!=NULL) {
884 intrfc->if_dev=dev;
885 intrfc->if_netnum=0L;
886 intrfc->if_dlink_type = dlink_type;
887 intrfc->if_dlink = datalink;
888 intrfc->if_sklist = NULL;
889 intrfc->if_internal = 0;
890 intrfc->if_sknum = IPX_MIN_EPHEMERAL_SOCKET;
891 intrfc->if_ipx_offset = dev->hard_header_len +
892 datalink->header_length;
893 memset(intrfc->if_node, 0, IPX_NODE_LEN);
894 memcpy((char *)&(intrfc->if_node[IPX_NODE_LEN-dev->addr_len]),
895 dev->dev_addr, dev->addr_len);
896 ipxitf_insert(intrfc);
897 }
898
899 return intrfc;
900 }
901
902 static int
903 ipxitf_ioctl(unsigned int cmd, void *arg)
904 {
905 int err;
906 switch(cmd)
907 {
908 case SIOCSIFADDR:
909 {
910 struct ifreq ifr;
911 struct sockaddr_ipx *sipx;
912 ipx_interface_definition f;
913 err=verify_area(VERIFY_READ,arg,sizeof(ifr));
914 if(err)
915 return err;
916 memcpy_fromfs(&ifr,arg,sizeof(ifr));
917 sipx=(struct sockaddr_ipx *)&ifr.ifr_addr;
918 if(sipx->sipx_family!=AF_IPX)
919 return -EINVAL;
920 f.ipx_network=sipx->sipx_network;
921 memcpy(f.ipx_device, ifr.ifr_name, sizeof(f.ipx_device));
922 memcpy(f.ipx_node, sipx->sipx_node, IPX_NODE_LEN);
923 f.ipx_dlink_type=sipx->sipx_type;
924 f.ipx_special=sipx->sipx_special;
925 if(sipx->sipx_action==IPX_DLTITF)
926 return ipxitf_delete(&f);
927 else
928 return ipxitf_create(&f);
929 }
930 case SIOCGIFADDR:
931 {
932 struct ifreq ifr;
933 struct sockaddr_ipx *sipx;
934 ipx_interface *ipxif;
935 struct device *dev;
936 err=verify_area(VERIFY_WRITE,arg,sizeof(ifr));
937 if(err)
938 return err;
939 memcpy_fromfs(&ifr,arg,sizeof(ifr));
940 sipx=(struct sockaddr_ipx *)&ifr.ifr_addr;
941 dev=dev_get(ifr.ifr_name);
942 if(!dev)
943 return -ENODEV;
944 ipxif=ipxitf_find_using_phys(dev, ipx_map_frame_type(sipx->sipx_type));
945 if(ipxif==NULL)
946 return -EADDRNOTAVAIL;
947 sipx->sipx_network=ipxif->if_netnum;
948 memcpy(sipx->sipx_node, ipxif->if_node, sizeof(sipx->sipx_node));
949 memcpy_tofs(arg,&ifr,sizeof(ifr));
950 return 0;
951 }
952 case SIOCAIPXITFCRT:
953 err=verify_area(VERIFY_READ,arg,sizeof(char));
954 if(err)
955 return err;
956 return ipxcfg_set_auto_create(get_fs_byte(arg));
957 case SIOCAIPXPRISLT:
958 err=verify_area(VERIFY_READ,arg,sizeof(char));
959 if(err)
960 return err;
961 return ipxcfg_set_auto_select(get_fs_byte(arg));
962 default:
963 return -EINVAL;
964 }
965 }
966
967
968
969
970
971
972
973 static ipx_route *
974 ipxrtr_lookup(unsigned long net)
975 {
976 ipx_route *r;
977
978 for (r=ipx_routes; (r!=NULL) && (r->ir_net!=net); r=r->ir_next)
979 ;
980
981 return r;
982 }
983
984 static int
985 ipxrtr_add_route(unsigned long network, ipx_interface *intrfc, unsigned char *node)
986 {
987 ipx_route *rt;
988
989
990 rt = ipxrtr_lookup(network);
991 if (rt==NULL) {
992 rt=(ipx_route *)kmalloc(sizeof(ipx_route),GFP_ATOMIC);
993 if(rt==NULL)
994 return -EAGAIN;
995 rt->ir_next=ipx_routes;
996 ipx_routes=rt;
997 }
998
999 rt->ir_net = network;
1000 rt->ir_intrfc = intrfc;
1001 if (node == NULL) {
1002 memset(rt->ir_router_node, '\0', IPX_NODE_LEN);
1003 rt->ir_routed = 0;
1004 } else {
1005 memcpy(rt->ir_router_node, node, IPX_NODE_LEN);
1006 rt->ir_routed=1;
1007 }
1008 return 0;
1009 }
1010
1011 static void
1012 ipxrtr_del_routes(ipx_interface *intrfc)
1013 {
1014 ipx_route **r, *tmp;
1015
1016 for (r = &ipx_routes; (tmp = *r) != NULL; ) {
1017 if (tmp->ir_intrfc == intrfc) {
1018 *r = tmp->ir_next;
1019 kfree_s(tmp, sizeof(ipx_route));
1020 } else {
1021 r = &(tmp->ir_next);
1022 }
1023 }
1024 }
1025
1026 static int
1027 ipxrtr_create(ipx_route_definition *rd)
1028 {
1029 ipx_interface *intrfc;
1030
1031
1032 intrfc = ipxitf_find_using_net(rd->ipx_router_network);
1033 if (intrfc == NULL)
1034 return -ENETUNREACH;
1035
1036 return ipxrtr_add_route(rd->ipx_network, intrfc, rd->ipx_router_node);
1037 }
1038
1039
1040 static int
1041 ipxrtr_delete(long net)
1042 {
1043 ipx_route **r;
1044 ipx_route *tmp;
1045
1046 for (r = &ipx_routes; (tmp = *r) != NULL; ) {
1047 if (tmp->ir_net == net) {
1048 if (!(tmp->ir_routed)) {
1049
1050 return -EPERM;
1051 }
1052 *r = tmp->ir_next;
1053 kfree_s(tmp, sizeof(ipx_route));
1054 return 0;
1055 }
1056 r = &(tmp->ir_next);
1057 }
1058
1059 return -ENOENT;
1060 }
1061
1062
1063
1064
1065
1066 static int ipxrtr_route_packet(ipx_socket *sk, struct sockaddr_ipx *usipx, struct iovec *iov, int len)
1067 {
1068 struct sk_buff *skb;
1069 ipx_interface *intrfc;
1070 ipx_packet *ipx;
1071 int size;
1072 int ipx_offset;
1073 ipx_route *rt = NULL;
1074 int err;
1075
1076
1077 if ((usipx->sipx_network == 0L) && (ipx_primary_net != NULL))
1078 {
1079 usipx->sipx_network = ipx_primary_net->if_netnum;
1080 intrfc = ipx_primary_net;
1081 }
1082 else
1083 {
1084 rt = ipxrtr_lookup(usipx->sipx_network);
1085 if (rt==NULL) {
1086 return -ENETUNREACH;
1087 }
1088 intrfc = rt->ir_intrfc;
1089 }
1090
1091 ipx_offset = intrfc->if_ipx_offset;
1092 size=sizeof(ipx_packet)+len;
1093 size += ipx_offset;
1094
1095 skb=sock_alloc_send_skb(sk, size, 0, 0, &err);
1096 if(skb==NULL)
1097 return err;
1098
1099 skb_reserve(skb,ipx_offset);
1100 skb->free=1;
1101 skb->arp=1;
1102 skb->sk=sk;
1103
1104
1105 ipx=(ipx_packet *)skb_put(skb,sizeof(ipx_packet));
1106 ipx->ipx_checksum=0xFFFF;
1107 ipx->ipx_pktsize=htons(len+sizeof(ipx_packet));
1108 ipx->ipx_tctrl=0;
1109 ipx->ipx_type=usipx->sipx_type;
1110 skb->h.raw = (unsigned char *)ipx;
1111
1112 ipx->ipx_source.net = sk->ipx_intrfc->if_netnum;
1113 memcpy(ipx->ipx_source.node, sk->ipx_intrfc->if_node, IPX_NODE_LEN);
1114 ipx->ipx_source.sock = sk->ipx_port;
1115 ipx->ipx_dest.net=usipx->sipx_network;
1116 memcpy(ipx->ipx_dest.node,usipx->sipx_node,IPX_NODE_LEN);
1117 ipx->ipx_dest.sock=usipx->sipx_port;
1118
1119 memcpy_fromiovec(skb_put(skb,len),iov,len);
1120
1121 #ifdef CONFIG_FIREWALL
1122 if(call_out_firewall(PF_IPX, skb, ipx)!=FW_ACCEPT)
1123 {
1124 kfree_skb(skb, FREE_WRITE);
1125 return -EPERM;
1126 }
1127 #endif
1128
1129 return ipxitf_send(intrfc, skb, (rt && rt->ir_routed) ?
1130 rt->ir_router_node : ipx->ipx_dest.node);
1131 }
1132
1133 static int
1134 ipxrtr_route_skb(struct sk_buff *skb)
1135 {
1136 ipx_packet *ipx = (ipx_packet *) (skb->h.raw);
1137 ipx_route *r;
1138 ipx_interface *i;
1139
1140 r = ipxrtr_lookup(ipx->ipx_dest.net);
1141 if (r == NULL) {
1142
1143 kfree_skb(skb,FREE_READ);
1144 return 0;
1145 }
1146 i = r->ir_intrfc;
1147 (void)ipxitf_send(i, skb, (r->ir_routed) ?
1148 r->ir_router_node : ipx->ipx_dest.node);
1149 return 0;
1150 }
1151
1152
1153
1154
1155
1156 static int ipxrtr_ioctl(unsigned int cmd, void *arg)
1157 {
1158 int err;
1159 struct rtentry rt;
1160 struct sockaddr_ipx *sg,*st;
1161
1162 err=verify_area(VERIFY_READ,arg,sizeof(rt));
1163 if(err)
1164 return err;
1165
1166 memcpy_fromfs(&rt,arg,sizeof(rt));
1167
1168 sg=(struct sockaddr_ipx *)&rt.rt_gateway;
1169 st=(struct sockaddr_ipx *)&rt.rt_dst;
1170
1171 if(!(rt.rt_flags&RTF_GATEWAY))
1172 return -EINVAL;
1173 if(sg->sipx_family!=AF_IPX)
1174 return -EINVAL;
1175 if(st->sipx_family!=AF_IPX)
1176 return -EINVAL;
1177
1178 switch(cmd)
1179 {
1180 case SIOCDELRT:
1181 return ipxrtr_delete(st->sipx_network);
1182 case SIOCADDRT:
1183 {
1184 struct ipx_route_definition f;
1185 f.ipx_network=st->sipx_network;
1186 f.ipx_router_network=sg->sipx_network;
1187 memcpy(f.ipx_router_node, sg->sipx_node, IPX_NODE_LEN);
1188 return ipxrtr_create(&f);
1189 }
1190 default:
1191 return -EINVAL;
1192 }
1193 }
1194
1195 static const char *
1196 ipx_frame_name(unsigned short frame)
1197 {
1198 switch (ntohs(frame)) {
1199 case ETH_P_IPX: return "EtherII";
1200 case ETH_P_802_2: return "802.2";
1201 case ETH_P_SNAP: return "SNAP";
1202 case ETH_P_802_3: return "802.3";
1203 default: return "None";
1204 }
1205 }
1206
1207 static const char *
1208 ipx_device_name(ipx_interface *intrfc)
1209 {
1210 return (intrfc->if_internal ? "Internal" :
1211 (intrfc->if_dev ? intrfc->if_dev->name : "Unknown"));
1212 }
1213
1214
1215 static int ipx_interface_get_info(char *buffer, char **start, off_t offset,
1216 int length, int dummy)
1217 {
1218 ipx_interface *i;
1219 int len=0;
1220 off_t pos=0;
1221 off_t begin=0;
1222
1223
1224
1225 len += sprintf (buffer,"%-11s%-15s%-9s%-11s%s\n", "Network",
1226 "Node_Address", "Primary", "Device", "Frame_Type");
1227 for (i = ipx_interfaces; i != NULL; i = i->if_next) {
1228 len += sprintf(buffer+len, "%08lX ", ntohl(i->if_netnum));
1229 len += sprintf (buffer+len,"%02X%02X%02X%02X%02X%02X ",
1230 i->if_node[0], i->if_node[1], i->if_node[2],
1231 i->if_node[3], i->if_node[4], i->if_node[5]);
1232 len += sprintf(buffer+len, "%-9s", (i == ipx_primary_net) ?
1233 "Yes" : "No");
1234 len += sprintf (buffer+len, "%-11s", ipx_device_name(i));
1235 len += sprintf (buffer+len, "%s\n",
1236 ipx_frame_name(i->if_dlink_type));
1237
1238
1239 pos=begin+len;
1240
1241 if(pos<offset) {
1242 len=0;
1243 begin=pos;
1244 }
1245 if(pos>offset+length)
1246 break;
1247 }
1248
1249
1250 *start=buffer+(offset-begin);
1251 len-=(offset-begin);
1252 if(len>length)
1253 len=length;
1254
1255 return len;
1256 }
1257
1258 static int ipx_get_info(char *buffer, char **start, off_t offset,
1259 int length, int dummy)
1260 {
1261 ipx_socket *s;
1262 ipx_interface *i;
1263 int len=0;
1264 off_t pos=0;
1265 off_t begin=0;
1266
1267
1268
1269 len += sprintf (buffer,"%-15s%-28s%-10s%-10s%-7s%s\n", "Local_Address",
1270 "Remote_Address", "Tx_Queue", "Rx_Queue",
1271 "State", "Uid");
1272 for (i = ipx_interfaces; i != NULL; i = i->if_next) {
1273 for (s = i->if_sklist; s != NULL; s = s->next) {
1274 len += sprintf (buffer+len,"%08lX:%04X ",
1275 htonl(i->if_netnum),
1276 htons(s->ipx_port));
1277 if (s->state!=TCP_ESTABLISHED) {
1278 len += sprintf(buffer+len, "%-28s", "Not_Connected");
1279 } else {
1280 len += sprintf (buffer+len,
1281 "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
1282 htonl(s->ipx_dest_addr.net),
1283 s->ipx_dest_addr.node[0], s->ipx_dest_addr.node[1],
1284 s->ipx_dest_addr.node[2], s->ipx_dest_addr.node[3],
1285 s->ipx_dest_addr.node[4], s->ipx_dest_addr.node[5],
1286 htons(s->ipx_dest_addr.sock));
1287 }
1288 len += sprintf (buffer+len,"%08lX %08lX ",
1289 s->wmem_alloc, s->rmem_alloc);
1290 len += sprintf (buffer+len,"%02X %03d\n",
1291 s->state, SOCK_INODE(s->socket)->i_uid);
1292
1293
1294 pos=begin+len;
1295
1296 if(pos<offset)
1297 {
1298 len=0;
1299 begin=pos;
1300 }
1301 if(pos>offset+length)
1302 break;
1303 }
1304 }
1305
1306
1307 *start=buffer+(offset-begin);
1308 len-=(offset-begin);
1309 if(len>length)
1310 len=length;
1311
1312 return len;
1313 }
1314
1315 static int ipx_rt_get_info(char *buffer, char **start, off_t offset,
1316 int length, int dummy)
1317 {
1318 ipx_route *rt;
1319 int len=0;
1320 off_t pos=0;
1321 off_t begin=0;
1322
1323 len += sprintf (buffer,"%-11s%-13s%s\n",
1324 "Network", "Router_Net", "Router_Node");
1325 for (rt = ipx_routes; rt != NULL; rt = rt->ir_next)
1326 {
1327 len += sprintf (buffer+len,"%08lX ", ntohl(rt->ir_net));
1328 if (rt->ir_routed) {
1329 len += sprintf (buffer+len,"%08lX %02X%02X%02X%02X%02X%02X\n",
1330 ntohl(rt->ir_intrfc->if_netnum),
1331 rt->ir_router_node[0], rt->ir_router_node[1],
1332 rt->ir_router_node[2], rt->ir_router_node[3],
1333 rt->ir_router_node[4], rt->ir_router_node[5]);
1334 } else {
1335 len += sprintf (buffer+len, "%-13s%s\n",
1336 "Directly", "Connected");
1337 }
1338 pos=begin+len;
1339 if(pos<offset)
1340 {
1341 len=0;
1342 begin=pos;
1343 }
1344 if(pos>offset+length)
1345 break;
1346 }
1347 *start=buffer+(offset-begin);
1348 len-=(offset-begin);
1349 if(len>length)
1350 len=length;
1351 return len;
1352 }
1353
1354
1355
1356
1357
1358
1359
1360 static int ipx_fcntl(struct socket *sock, unsigned int cmd, unsigned long arg)
1361 {
1362 switch(cmd)
1363 {
1364 default:
1365 return(-EINVAL);
1366 }
1367 }
1368
1369 static int ipx_setsockopt(struct socket *sock, int level, int optname, char *optval, int optlen)
1370 {
1371 ipx_socket *sk;
1372 int err,opt;
1373
1374 sk=(ipx_socket *)sock->data;
1375
1376 if(optval==NULL)
1377 return(-EINVAL);
1378
1379 err=verify_area(VERIFY_READ,optval,sizeof(int));
1380 if(err)
1381 return err;
1382 opt=get_fs_long((unsigned long *)optval);
1383
1384 switch(level)
1385 {
1386 case SOL_IPX:
1387 switch(optname)
1388 {
1389 case IPX_TYPE:
1390 sk->ipx_type=opt;
1391 return 0;
1392 default:
1393 return -EOPNOTSUPP;
1394 }
1395 break;
1396
1397 case SOL_SOCKET:
1398 return sock_setsockopt(sk,level,optname,optval,optlen);
1399
1400 default:
1401 return -EOPNOTSUPP;
1402 }
1403 }
1404
1405 static int ipx_getsockopt(struct socket *sock, int level, int optname,
1406 char *optval, int *optlen)
1407 {
1408 ipx_socket *sk;
1409 int val=0;
1410 int err;
1411
1412 sk=(ipx_socket *)sock->data;
1413
1414 switch(level)
1415 {
1416
1417 case SOL_IPX:
1418 switch(optname)
1419 {
1420 case IPX_TYPE:
1421 val=sk->ipx_type;
1422 break;
1423 default:
1424 return -ENOPROTOOPT;
1425 }
1426 break;
1427
1428 case SOL_SOCKET:
1429 return sock_getsockopt(sk,level,optname,optval,optlen);
1430
1431 default:
1432 return -EOPNOTSUPP;
1433 }
1434 err=verify_area(VERIFY_WRITE,optlen,sizeof(int));
1435 if(err)
1436 return err;
1437 put_fs_long(sizeof(int),(unsigned long *)optlen);
1438 err=verify_area(VERIFY_WRITE,optval,sizeof(int));
1439 put_fs_long(val,(unsigned long *)optval);
1440 return(0);
1441 }
1442
1443 static int ipx_listen(struct socket *sock, int backlog)
1444 {
1445 return -EOPNOTSUPP;
1446 }
1447
1448 static void def_callback1(struct sock *sk)
1449 {
1450 if(!sk->dead)
1451 wake_up_interruptible(sk->sleep);
1452 }
1453
1454 static void def_callback2(struct sock *sk, int len)
1455 {
1456 if(!sk->dead)
1457 {
1458 wake_up_interruptible(sk->sleep);
1459 sock_wake_async(sk->socket, 1);
1460 }
1461 }
1462
1463 static int
1464 ipx_create(struct socket *sock, int protocol)
1465 {
1466 ipx_socket *sk;
1467 sk=(ipx_socket *)kmalloc(sizeof(*sk),GFP_KERNEL);
1468 if(sk==NULL)
1469 return(-ENOMEM);
1470 switch(sock->type)
1471 {
1472 case SOCK_DGRAM:
1473 break;
1474 default:
1475 kfree_s((void *)sk,sizeof(*sk));
1476 return(-ESOCKTNOSUPPORT);
1477 }
1478 sk->dead=0;
1479 sk->next=NULL;
1480 sk->broadcast=0;
1481 sk->rcvbuf=SK_RMEM_MAX;
1482 sk->sndbuf=SK_WMEM_MAX;
1483 sk->wmem_alloc=0;
1484 sk->rmem_alloc=0;
1485 sk->inuse=0;
1486 sk->shutdown=0;
1487 sk->prot=NULL;
1488 sk->err=0;
1489 skb_queue_head_init(&sk->receive_queue);
1490 skb_queue_head_init(&sk->write_queue);
1491 sk->send_head=NULL;
1492 skb_queue_head_init(&sk->back_log);
1493 sk->state=TCP_CLOSE;
1494 sk->socket=sock;
1495 sk->type=sock->type;
1496 sk->ipx_type=0;
1497 sk->debug=0;
1498 sk->ipx_intrfc = NULL;
1499 memset(&sk->ipx_dest_addr,'\0',sizeof(sk->ipx_dest_addr));
1500 sk->ipx_port = 0;
1501 sk->mtu=IPX_MTU;
1502
1503 if(sock!=NULL)
1504 {
1505 sock->data=(void *)sk;
1506 sk->sleep=sock->wait;
1507 }
1508
1509 sk->state_change=def_callback1;
1510 sk->data_ready=def_callback2;
1511 sk->write_space=def_callback1;
1512 sk->error_report=def_callback1;
1513
1514 sk->zapped=1;
1515 return 0;
1516 }
1517
1518 static int ipx_release(struct socket *sock, struct socket *peer)
1519 {
1520 ipx_socket *sk=(ipx_socket *)sock->data;
1521 if(sk==NULL)
1522 return(0);
1523 if(!sk->dead)
1524 sk->state_change(sk);
1525 sk->dead=1;
1526 sock->data=NULL;
1527 ipx_destroy_socket(sk);
1528 return(0);
1529 }
1530
1531 static int ipx_dup(struct socket *newsock,struct socket *oldsock)
1532 {
1533 return(ipx_create(newsock,SOCK_DGRAM));
1534 }
1535
1536 static unsigned short
1537 ipx_first_free_socketnum(ipx_interface *intrfc)
1538 {
1539 unsigned short socketNum = intrfc->if_sknum;
1540
1541 if (socketNum < IPX_MIN_EPHEMERAL_SOCKET)
1542 socketNum = IPX_MIN_EPHEMERAL_SOCKET;
1543
1544 while (ipxitf_find_socket(intrfc, ntohs(socketNum)) != NULL)
1545 if (socketNum > IPX_MAX_EPHEMERAL_SOCKET)
1546 socketNum = IPX_MIN_EPHEMERAL_SOCKET;
1547 else
1548 socketNum++;
1549
1550 intrfc->if_sknum = socketNum;
1551 return ntohs(socketNum);
1552 }
1553
1554 static int ipx_bind(struct socket *sock, struct sockaddr *uaddr,int addr_len)
1555 {
1556 ipx_socket *sk;
1557 ipx_interface *intrfc;
1558 struct sockaddr_ipx *addr=(struct sockaddr_ipx *)uaddr;
1559
1560 sk=(ipx_socket *)sock->data;
1561
1562 if(sk->zapped==0)
1563 return -EIO;
1564
1565 if(addr_len!=sizeof(struct sockaddr_ipx))
1566 return -EINVAL;
1567
1568 intrfc = ipxitf_find_using_net(addr->sipx_network);
1569 if (intrfc == NULL)
1570 return -EADDRNOTAVAIL;
1571
1572 if (addr->sipx_port == 0) {
1573 addr->sipx_port = ipx_first_free_socketnum(intrfc);
1574 if (addr->sipx_port == 0)
1575 return -EINVAL;
1576 }
1577
1578 if(ntohs(addr->sipx_port)<IPX_MIN_EPHEMERAL_SOCKET && !suser())
1579 return -EPERM;
1580
1581
1582
1583
1584 if(ipxitf_find_socket(intrfc, addr->sipx_port)!=NULL) {
1585 if(sk->debug)
1586 printk("IPX: bind failed because port %X in use.\n",
1587 (int)addr->sipx_port);
1588 return -EADDRINUSE;
1589 }
1590
1591 sk->ipx_port=addr->sipx_port;
1592 ipxitf_insert_socket(intrfc, sk);
1593 sk->zapped=0;
1594 if(sk->debug)
1595 printk("IPX: socket is bound.\n");
1596 return 0;
1597 }
1598
1599 static int ipx_connect(struct socket *sock, struct sockaddr *uaddr,
1600 int addr_len, int flags)
1601 {
1602 ipx_socket *sk=(ipx_socket *)sock->data;
1603 struct sockaddr_ipx *addr;
1604
1605 sk->state = TCP_CLOSE;
1606 sock->state = SS_UNCONNECTED;
1607
1608 if(addr_len!=sizeof(*addr))
1609 return(-EINVAL);
1610 addr=(struct sockaddr_ipx *)uaddr;
1611
1612 if(sk->ipx_port==0)
1613
1614 {
1615 struct sockaddr_ipx uaddr;
1616 int ret;
1617
1618 uaddr.sipx_port = 0;
1619 uaddr.sipx_network = 0L;
1620 ret = ipx_bind (sock, (struct sockaddr *)&uaddr, sizeof(struct sockaddr_ipx));
1621 if (ret != 0) return (ret);
1622 }
1623
1624 if(ipxrtr_lookup(addr->sipx_network)==NULL)
1625 return -ENETUNREACH;
1626 sk->ipx_dest_addr.net=addr->sipx_network;
1627 sk->ipx_dest_addr.sock=addr->sipx_port;
1628 memcpy(sk->ipx_dest_addr.node,addr->sipx_node,IPX_NODE_LEN);
1629 sk->ipx_type=addr->sipx_type;
1630 sock->state = SS_CONNECTED;
1631 sk->state=TCP_ESTABLISHED;
1632 return 0;
1633 }
1634
1635 static int ipx_socketpair(struct socket *sock1, struct socket *sock2)
1636 {
1637 return(-EOPNOTSUPP);
1638 }
1639
1640 static int ipx_accept(struct socket *sock, struct socket *newsock, int flags)
1641 {
1642 if(newsock->data)
1643 kfree_s(newsock->data,sizeof(ipx_socket));
1644 return -EOPNOTSUPP;
1645 }
1646
1647 static int ipx_getname(struct socket *sock, struct sockaddr *uaddr,
1648 int *uaddr_len, int peer)
1649 {
1650 ipx_address *addr;
1651 struct sockaddr_ipx sipx;
1652 ipx_socket *sk;
1653
1654 sk=(ipx_socket *)sock->data;
1655
1656 *uaddr_len = sizeof(struct sockaddr_ipx);
1657
1658 if(peer) {
1659 if(sk->state!=TCP_ESTABLISHED)
1660 return -ENOTCONN;
1661 addr=&sk->ipx_dest_addr;
1662 sipx.sipx_network = addr->net;
1663 memcpy(sipx.sipx_node,addr->node,IPX_NODE_LEN);
1664 sipx.sipx_port = addr->sock;
1665 } else {
1666 if (sk->ipx_intrfc != NULL) {
1667 sipx.sipx_network = sk->ipx_intrfc->if_netnum;
1668 memcpy(sipx.sipx_node, sk->ipx_intrfc->if_node,
1669 IPX_NODE_LEN);
1670 } else {
1671 sipx.sipx_network = 0L;
1672 memset(sipx.sipx_node, '\0', IPX_NODE_LEN);
1673 }
1674 sipx.sipx_port = sk->ipx_port;
1675 }
1676
1677 sipx.sipx_family = AF_IPX;
1678 sipx.sipx_type = sk->ipx_type;
1679 memcpy(uaddr,&sipx,sizeof(sipx));
1680 return 0;
1681 }
1682
1683 #if 0
1684
1685
1686
1687 void dump_data(char *str,unsigned char *d, int len) {
1688 static char h2c[] = "0123456789ABCDEF";
1689 int l,i;
1690 char *p, b[64];
1691 for (l=0;len > 0 && l<16;l++) {
1692 p = b;
1693 for (i=0; i < 8 ; i++, --len) {
1694 if (len > 0) {
1695 *(p++) = h2c[(d[i] >> 4) & 0x0f];
1696 *(p++) = h2c[d[i] & 0x0f];
1697 }
1698 else {
1699 *(p++) = ' ';
1700 *(p++) = ' ';
1701 }
1702 *(p++) = ' ';
1703 }
1704 *(p++) = '-';
1705 *(p++) = ' ';
1706 len += 8;
1707 for (i=0; i < 8 ; i++, --len)
1708 if (len > 0)
1709 *(p++) = ' '<= d[i] && d[i]<'\177' ? d[i] : '.';
1710 else
1711 *(p++) = ' ';
1712 *p = '\000';
1713 d += i;
1714 printk("%s-%04X: %s\n",str,l*8,b);
1715 }
1716 }
1717
1718 void dump_addr(char *str,ipx_address *p) {
1719 printk("%s: %08X:%02X%02X%02X%02X%02X%02X:%04X\n",
1720 str,ntohl(p->net),p->node[0],p->node[1],p->node[2],
1721 p->node[3],p->node[4],p->node[5],ntohs(p->sock));
1722 }
1723
1724 void dump_hdr(char *str,ipx_packet *p) {
1725 printk("%s: CHKSUM=%04X SIZE=%d (%04X) HOPS=%d (%02X) TYPE=%02X\n",
1726 str,p->ipx_checksum,ntohs(p->ipx_pktsize),ntohs(p->ipx_pktsize),
1727 p->ipx_tctrl,p->ipx_tctrl,p->ipx_type);
1728 dump_addr(" IPX-DST",&p->ipx_dest);
1729 dump_addr(" IPX-SRC",&p->ipx_source);
1730 }
1731
1732 void dump_pkt(char *str,ipx_packet *p) {
1733 int len = ntohs(p->ipx_pktsize);
1734 dump_hdr(str,p);
1735 if (len > 30)
1736 dump_data(str,(unsigned char *)p + 30, len - 30);
1737 }
1738 #endif
1739
1740 int ipx_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
1741 {
1742
1743 ipx_interface *intrfc;
1744 ipx_packet *ipx;
1745
1746
1747 ipx=(ipx_packet *)skb->h.raw;
1748
1749 if(ipx->ipx_checksum!=IPX_NO_CHECKSUM) {
1750
1751
1752
1753 kfree_skb(skb,FREE_READ);
1754 return 0;
1755 }
1756
1757
1758 if(htons(ipx->ipx_pktsize)<sizeof(ipx_packet)) {
1759 kfree_skb(skb,FREE_READ);
1760 return 0;
1761 }
1762
1763
1764 intrfc = ipxitf_find_using_phys(dev, pt->type);
1765 if (intrfc == NULL) {
1766 if (ipxcfg_auto_create_interfaces) {
1767 intrfc = ipxitf_auto_create(dev, pt->type);
1768 }
1769
1770 if (intrfc == NULL) {
1771
1772 kfree_skb(skb,FREE_READ);
1773 return 0;
1774 }
1775 }
1776
1777 return ipxitf_rcv(intrfc, skb);
1778 }
1779
1780 static int ipx_sendmsg(struct socket *sock, struct msghdr *msg, int len, int noblock,
1781 int flags)
1782 {
1783 ipx_socket *sk=(ipx_socket *)sock->data;
1784 struct sockaddr_ipx *usipx=(struct sockaddr_ipx *)msg->msg_name;
1785 struct sockaddr_ipx local_sipx;
1786 int retval;
1787
1788 if (sk->zapped) return -EIO;
1789 if(flags) return -EINVAL;
1790
1791 if(usipx)
1792 {
1793 if(sk->ipx_port == 0)
1794 {
1795 struct sockaddr_ipx uaddr;
1796 int ret;
1797
1798 uaddr.sipx_port = 0;
1799 uaddr.sipx_network = 0L;
1800 ret = ipx_bind (sock, (struct sockaddr *)&uaddr, sizeof(struct sockaddr_ipx));
1801 if (ret != 0) return ret;
1802 }
1803
1804 if(msg->msg_namelen <sizeof(*usipx))
1805 return -EINVAL;
1806 if(usipx->sipx_family != AF_IPX)
1807 return -EINVAL;
1808 }
1809 else
1810 {
1811 if(sk->state!=TCP_ESTABLISHED)
1812 return -ENOTCONN;
1813 usipx=&local_sipx;
1814 usipx->sipx_family=AF_IPX;
1815 usipx->sipx_type=sk->ipx_type;
1816 usipx->sipx_port=sk->ipx_dest_addr.sock;
1817 usipx->sipx_network=sk->ipx_dest_addr.net;
1818 memcpy(usipx->sipx_node,sk->ipx_dest_addr.node,IPX_NODE_LEN);
1819 }
1820
1821 retval = ipxrtr_route_packet(sk, usipx, msg->msg_iov, len);
1822 if (retval < 0) return retval;
1823
1824 return len;
1825 }
1826
1827
1828 static int ipx_recvmsg(struct socket *sock, struct msghdr *msg, int size, int noblock,
1829 int flags, int *addr_len)
1830 {
1831 ipx_socket *sk=(ipx_socket *)sock->data;
1832 struct sockaddr_ipx *sipx=(struct sockaddr_ipx *)msg->msg_name;
1833 struct ipx_packet *ipx = NULL;
1834 int copied = 0;
1835 int truesize;
1836 struct sk_buff *skb;
1837 int er;
1838
1839 if(sk->err)
1840 return sock_error(sk);
1841
1842 if (sk->zapped)
1843 return -EIO;
1844
1845
1846 skb=skb_recv_datagram(sk,flags,noblock,&er);
1847 if(skb==NULL)
1848 return er;
1849
1850 if(addr_len)
1851 *addr_len=sizeof(*sipx);
1852
1853 ipx = (ipx_packet *)(skb->h.raw);
1854 truesize=ntohs(ipx->ipx_pktsize) - sizeof(ipx_packet);
1855 copied = (truesize > size) ? size : truesize;
1856 skb_copy_datagram_iovec(skb,sizeof(struct ipx_packet),msg->msg_iov,copied);
1857
1858 if(sipx)
1859 {
1860 sipx->sipx_family=AF_IPX;
1861 sipx->sipx_port=ipx->ipx_source.sock;
1862 memcpy(sipx->sipx_node,ipx->ipx_source.node,IPX_NODE_LEN);
1863 sipx->sipx_network=ipx->ipx_source.net;
1864 sipx->sipx_type = ipx->ipx_type;
1865 }
1866 skb_free_datagram(skb);
1867 return(truesize);
1868 }
1869
1870 static int ipx_shutdown(struct socket *sk,int how)
1871 {
1872 return -EOPNOTSUPP;
1873 }
1874
1875 static int ipx_select(struct socket *sock , int sel_type, select_table *wait)
1876 {
1877 ipx_socket *sk=(ipx_socket *)sock->data;
1878
1879 return datagram_select(sk,sel_type,wait);
1880 }
1881
1882 static int ipx_ioctl(struct socket *sock,unsigned int cmd, unsigned long arg)
1883 {
1884 int err;
1885 long amount=0;
1886 ipx_socket *sk=(ipx_socket *)sock->data;
1887
1888 switch(cmd)
1889 {
1890 case TIOCOUTQ:
1891 err=verify_area(VERIFY_WRITE,(void *)arg,sizeof(unsigned long));
1892 if(err)
1893 return err;
1894 amount=sk->sndbuf-sk->wmem_alloc;
1895 if(amount<0)
1896 amount=0;
1897 put_fs_long(amount,(unsigned long *)arg);
1898 return 0;
1899 case TIOCINQ:
1900 {
1901 struct sk_buff *skb;
1902
1903 if((skb=skb_peek(&sk->receive_queue))!=NULL)
1904 amount=skb->len;
1905 err=verify_area(VERIFY_WRITE,(void *)arg,sizeof(unsigned long));
1906 if(err)
1907 return err;
1908 put_fs_long(amount,(unsigned long *)arg);
1909 return 0;
1910 }
1911 case SIOCADDRT:
1912 case SIOCDELRT:
1913 if(!suser())
1914 return -EPERM;
1915 return(ipxrtr_ioctl(cmd,(void *)arg));
1916 case SIOCSIFADDR:
1917 case SIOCGIFADDR:
1918 case SIOCAIPXITFCRT:
1919 case SIOCAIPXPRISLT:
1920 if(!suser())
1921 return -EPERM;
1922 return(ipxitf_ioctl(cmd,(void *)arg));
1923 case SIOCIPXCFGDATA:
1924 {
1925 err=verify_area(VERIFY_WRITE,(void *)arg,
1926 sizeof(ipx_config_data));
1927 if(err) return err;
1928 return(ipxcfg_get_config_data((void *)arg));
1929 }
1930 case SIOCGSTAMP:
1931 if (sk)
1932 {
1933 if(sk->stamp.tv_sec==0)
1934 return -ENOENT;
1935 err=verify_area(VERIFY_WRITE,(void *)arg,sizeof(struct timeval));
1936 if(err)
1937 return err;
1938 memcpy_tofs((void *)arg,&sk->stamp,sizeof(struct timeval));
1939 return 0;
1940 }
1941 return -EINVAL;
1942 case SIOCGIFDSTADDR:
1943 case SIOCSIFDSTADDR:
1944 case SIOCGIFBRDADDR:
1945 case SIOCSIFBRDADDR:
1946 case SIOCGIFNETMASK:
1947 case SIOCSIFNETMASK:
1948 return -EINVAL;
1949 default:
1950 return(dev_ioctl(cmd,(void *) arg));
1951 }
1952
1953 return(0);
1954 }
1955
1956 static struct proto_ops ipx_proto_ops = {
1957 AF_IPX,
1958
1959 ipx_create,
1960 ipx_dup,
1961 ipx_release,
1962 ipx_bind,
1963 ipx_connect,
1964 ipx_socketpair,
1965 ipx_accept,
1966 ipx_getname,
1967 ipx_select,
1968 ipx_ioctl,
1969 ipx_listen,
1970 ipx_shutdown,
1971 ipx_setsockopt,
1972 ipx_getsockopt,
1973 ipx_fcntl,
1974 ipx_sendmsg,
1975 ipx_recvmsg
1976 };
1977
1978
1979
1980 static struct packet_type ipx_8023_packet_type =
1981
1982 {
1983 0,
1984 NULL,
1985 ipx_rcv,
1986 NULL,
1987 NULL,
1988 };
1989
1990 static struct packet_type ipx_dix_packet_type =
1991 {
1992 0,
1993 NULL,
1994 ipx_rcv,
1995 NULL,
1996 NULL,
1997 };
1998
1999 static struct notifier_block ipx_dev_notifier={
2000 ipxitf_device_event,
2001 NULL,
2002 0
2003 };
2004
2005
2006 extern struct datalink_proto *make_EII_client(void);
2007 extern struct datalink_proto *make_8023_client(void);
2008
2009 void ipx_proto_init(struct net_proto *pro)
2010 {
2011 unsigned char val = 0xE0;
2012 unsigned char snapval[5] = { 0x0, 0x0, 0x0, 0x81, 0x37 };
2013
2014 (void) sock_register(ipx_proto_ops.family, &ipx_proto_ops);
2015
2016 pEII_datalink = make_EII_client();
2017 ipx_dix_packet_type.type=htons(ETH_P_IPX);
2018 dev_add_pack(&ipx_dix_packet_type);
2019
2020 p8023_datalink = make_8023_client();
2021 ipx_8023_packet_type.type=htons(ETH_P_802_3);
2022 dev_add_pack(&ipx_8023_packet_type);
2023
2024 if ((p8022_datalink = register_8022_client(val, ipx_rcv)) == NULL)
2025 printk("IPX: Unable to register with 802.2\n");
2026
2027 if ((pSNAP_datalink = register_snap_client(snapval, ipx_rcv)) == NULL)
2028 printk("IPX: Unable to register with SNAP\n");
2029
2030 register_netdevice_notifier(&ipx_dev_notifier);
2031
2032 proc_net_register(&(struct proc_dir_entry) {
2033 PROC_NET_IPX, 3, "ipx",
2034 S_IFREG | S_IRUGO, 1, 0, 0,
2035 0, &proc_net_inode_operations,
2036 ipx_get_info
2037 });
2038 proc_net_register(&(struct proc_dir_entry) {
2039 PROC_NET_IPX_INTERFACE, 13, "ipx_interface",
2040 S_IFREG | S_IRUGO, 1, 0, 0,
2041 0, &proc_net_inode_operations,
2042 ipx_interface_get_info
2043 });
2044 proc_net_register(&(struct proc_dir_entry) {
2045 PROC_NET_IPX_ROUTE, 9, "ipx_route",
2046 S_IFREG | S_IRUGO, 1, 0, 0,
2047 0, &proc_net_inode_operations,
2048 ipx_rt_get_info
2049 });
2050
2051 printk("Swansea University Computer Society IPX 0.33 for NET3.032\n");
2052 printk("IPX Portions Copyright (c) 1995 Caldera, Inc.\n");
2053 }
2054 #endif