This source file includes following definitions.
- atalk_remove_socket
- atalk_insert_socket
- atalk_search_socket
- atalk_find_socket
- atalk_destroy_timer
- atalk_destroy_socket
- atalk_get_info
- atif_drop_device
- atif_add_device
- atif_probe_device
- atalk_find_dev_addr
- atalk_find_primary
- atalk_find_dev
- atalk_find_anynet
- atalk_find_interface
- atrtr_find
- atrtr_get_dev
- atrtr_set_default
- atrtr_create
- atrtr_delete
- atrtr_device_down
- ddp_device_event
- atif_ioctl
- atrtr_ioctl
- atalk_if_get_info
- atalk_rt_get_info
- atalk_checksum
- atalk_fcntl
- atalk_setsockopt
- atalk_getsockopt
- atalk_listen
- def_callback1
- def_callback2
- atalk_create
- atalk_dup
- atalk_release
- atalk_pick_port
- atalk_autobind
- atalk_bind
- atalk_connect
- atalk_socketpair
- atalk_accept
- atalk_getname
- atalk_rcv
- atalk_sendto
- atalk_send
- atalk_recvfrom
- atalk_write
- atalk_recv
- atalk_read
- atalk_shutdown
- atalk_select
- atalk_ioctl
- atalk_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 #include <asm/segment.h>
27 #include <asm/system.h>
28 #include <asm/bitops.h>
29 #include <linux/config.h>
30 #include <linux/types.h>
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/string.h>
34 #include <linux/mm.h>
35 #include <linux/socket.h>
36 #include <linux/sockios.h>
37 #include <linux/in.h>
38 #include <linux/errno.h>
39 #include <linux/interrupt.h>
40 #include <linux/if_ether.h>
41 #include <linux/inet.h>
42 #include <linux/notifier.h>
43 #include <linux/netdevice.h>
44 #include <linux/etherdevice.h>
45 #include <linux/skbuff.h>
46 #include <linux/termios.h>
47 #include <net/datalink.h>
48 #include <net/p8022.h>
49 #include <net/psnap.h>
50 #include <net/sock.h>
51 #include <linux/atalk.h>
52 #include <linux/proc_fs.h>
53
54 #ifdef CONFIG_ATALK
55
56 #define APPLETALK_DEBUG
57
58
59 #ifdef APPLETALK_DEBUG
60 #define DPRINT(x) print(x)
61 #else
62 #define DPRINT(x)
63 #endif
64
65 struct datalink_proto *ddp_dl, *aarp_dl;
66
67 #define min(a,b) (((a)<(b))?(a):(b))
68
69
70
71
72
73
74
75 static atalk_socket *volatile atalk_socket_list=NULL;
76
77
78
79
80
81
82
83 static void atalk_remove_socket(atalk_socket *sk)
84 {
85 unsigned long flags;
86 atalk_socket *s;
87
88 save_flags(flags);
89 cli();
90
91 s=atalk_socket_list;
92 if(s==sk)
93 {
94 atalk_socket_list=s->next;
95 restore_flags(flags);
96 return;
97 }
98 while(s && s->next)
99 {
100 if(s->next==sk)
101 {
102 s->next=sk->next;
103 restore_flags(flags);
104 return;
105 }
106 s=s->next;
107 }
108 restore_flags(flags);
109 }
110
111 static void atalk_insert_socket(atalk_socket *sk)
112 {
113 unsigned long flags;
114 save_flags(flags);
115 cli();
116 sk->next=atalk_socket_list;
117 atalk_socket_list=sk;
118 restore_flags(flags);
119 }
120
121 static atalk_socket *atalk_search_socket(struct sockaddr_at *to, struct atalk_iface *atif)
122 {
123 atalk_socket *s;
124
125 for( s = atalk_socket_list; s != NULL; s = s->next ) {
126 if ( to->sat_port != s->at.src_port ) {
127 continue;
128 }
129
130 if ( to->sat_addr.s_net == 0 &&
131 to->sat_addr.s_node == ATADDR_BCAST &&
132 s->at.src_net == atif->address.s_net ) {
133 break;
134 }
135
136 if ( to->sat_addr.s_net == s->at.src_net &&
137 to->sat_addr.s_node == s->at.src_node ) {
138 break;
139 }
140
141
142 }
143 return( s );
144 }
145
146
147
148
149
150 static atalk_socket *atalk_find_socket(struct sockaddr_at *sat)
151 {
152 atalk_socket *s;
153
154 for ( s = atalk_socket_list; s != NULL; s = s->next ) {
155 if ( s->at.src_net != sat->sat_addr.s_net ) {
156 continue;
157 }
158 if ( s->at.src_node != sat->sat_addr.s_node ) {
159 continue;
160 }
161 if ( s->at.src_port != sat->sat_port ) {
162 continue;
163 }
164 break;
165 }
166 return( s );
167 }
168
169
170
171
172
173
174
175
176 static void atalk_destroy_socket(atalk_socket *sk);
177
178
179
180
181
182 static void atalk_destroy_timer(unsigned long data)
183 {
184 atalk_destroy_socket((atalk_socket *)data);
185 }
186
187 static void atalk_destroy_socket(atalk_socket *sk)
188 {
189 struct sk_buff *skb;
190 atalk_remove_socket(sk);
191
192 while((skb=skb_dequeue(&sk->receive_queue))!=NULL)
193 {
194 kfree_skb(skb,FREE_READ);
195 }
196
197 if(sk->wmem_alloc == 0 && sk->rmem_alloc == 0 && sk->dead)
198 kfree_s(sk,sizeof(*sk));
199 else
200 {
201
202
203
204 init_timer(&sk->timer);
205 sk->timer.expires=jiffies+10*HZ;
206 sk->timer.function=atalk_destroy_timer;
207 sk->timer.data = (unsigned long)sk;
208 add_timer(&sk->timer);
209 }
210 }
211
212
213
214 int atalk_get_info(char *buffer, char **start, off_t offset, int length)
215 {
216 atalk_socket *s;
217 int len=0;
218 off_t pos=0;
219 off_t begin=0;
220
221
222
223
224
225
226
227 len += sprintf (buffer,"Type local_addr remote_addr tx_queue rx_queue st uid\n");
228 for (s = atalk_socket_list; s != NULL; s = s->next)
229 {
230 len += sprintf (buffer+len,"%02X ", s->type);
231 len += sprintf (buffer+len,"%04X:%02X:%02X ",
232 s->at.src_net,s->at.src_node,s->at.src_port);
233 len += sprintf (buffer+len,"%04X:%02X:%02X ",
234 s->at.dest_net,s->at.dest_node,s->at.dest_port);
235 len += sprintf (buffer+len,"%08lX:%08lX ", s->wmem_alloc, s->rmem_alloc);
236 len += sprintf (buffer+len,"%02X %d\n", s->state, SOCK_INODE(s->socket)->i_uid);
237
238
239 pos=begin+len;
240
241 if(pos<offset)
242 {
243 len=0;
244 begin=pos;
245 }
246 if(pos>offset+length)
247 break;
248 }
249
250
251 *start=buffer+(offset-begin);
252 len-=(offset-begin);
253 if(len>length)
254 len=length;
255
256 return len;
257 }
258
259
260
261
262
263
264
265
266 static struct atalk_route *atalk_router_list=NULL;
267 static struct atalk_route atrtr_default;
268 static struct atalk_iface *atalk_iface_list=NULL;
269
270
271
272
273
274
275
276
277
278
279
280 static void atif_drop_device(struct device *dev)
281 {
282 struct atalk_iface **iface = &atalk_iface_list;
283 struct atalk_iface *tmp;
284
285 while ((tmp = *iface) != NULL)
286 {
287 if (tmp->dev == dev)
288 {
289 *iface = tmp->next;
290 kfree_s(tmp, sizeof(struct atalk_iface));
291 }
292 else
293 iface = &tmp->next;
294 }
295 }
296
297 static struct atalk_iface *atif_add_device(struct device *dev, struct at_addr *sa)
298 {
299 struct atalk_iface *iface=(struct atalk_iface *)
300 kmalloc(sizeof(*iface), GFP_KERNEL);
301 unsigned long flags;
302 if(iface==NULL)
303 return NULL;
304 iface->dev=dev;
305 iface->address= *sa;
306 iface->status=0;
307 save_flags(flags);
308 cli();
309 iface->next=atalk_iface_list;
310 atalk_iface_list=iface;
311 restore_flags(flags);
312 return iface;
313 }
314
315
316
317
318
319 static int atif_probe_device(struct atalk_iface *atif)
320 {
321 int ct;
322 int netrange=ntohs(atif->nets.nr_lastnet)-ntohs(atif->nets.nr_firstnet)+1;
323 int probe_net=ntohs(atif->address.s_net);
324 int probe_node=atif->address.s_node;
325 int netct;
326 int nodect;
327
328
329
330
331
332
333 if(probe_net==ATADDR_ANYNET)
334 {
335 if(!netrange)
336 probe_net=ntohs(atif->nets.nr_firstnet);
337 else
338 probe_net=ntohs(atif->nets.nr_firstnet) + (jiffies%netrange);
339 }
340
341 if(probe_node == ATADDR_ANYNODE)
342 probe_node = jiffies&0xFF;
343
344
345
346
347
348
349 for(netct=0;netct<=netrange;netct++)
350 {
351
352
353
354
355 atif->address.s_net=htons(probe_net);
356 for(nodect=0;nodect<256;nodect++)
357 {
358 atif->address.s_node=((nodect+probe_node)&0xFF);
359 if(atif->address.s_node>0&&atif->address.s_node<254)
360 {
361
362
363
364 for(ct=0;ct<AARP_RETRANSMIT_LIMIT;ct++)
365 {
366 aarp_send_probe(atif->dev, &atif->address);
367
368
369
370 current->timeout = jiffies + (HZ/10);
371 current->state = TASK_INTERRUPTIBLE;
372 schedule();
373 if(atif->status&ATIF_PROBE_FAIL)
374 break;
375 }
376 if(!(atif->status&ATIF_PROBE_FAIL))
377 return 0;
378 }
379 atif->status&=~ATIF_PROBE_FAIL;
380 }
381 probe_net++;
382 if(probe_net>ntohs(atif->nets.nr_lastnet))
383 probe_net=ntohs(atif->nets.nr_firstnet);
384 }
385 return -EADDRINUSE;
386 }
387
388 struct at_addr *atalk_find_dev_addr(struct device *dev)
389 {
390 struct atalk_iface *iface;
391 for(iface=atalk_iface_list;iface!=NULL;iface=iface->next)
392 if(iface->dev==dev)
393 return &iface->address;
394 return NULL;
395 }
396
397 static struct at_addr *atalk_find_primary(void)
398 {
399 struct atalk_iface *iface;
400 for(iface=atalk_iface_list;iface!=NULL;iface=iface->next)
401 if(!(iface->dev->flags&IFF_LOOPBACK))
402 return &iface->address;
403 if ( atalk_iface_list != NULL ) {
404 return &atalk_iface_list->address;
405 } else {
406 return NULL;
407 }
408 }
409
410
411
412
413
414 struct atalk_iface *atalk_find_dev(struct device *dev)
415 {
416 struct atalk_iface *iface;
417 for(iface=atalk_iface_list;iface!=NULL;iface=iface->next)
418 if(iface->dev==dev)
419 return iface;
420 return NULL;
421 }
422
423
424
425
426
427
428 static struct atalk_iface *atalk_find_anynet(int node, struct device *dev)
429 {
430 struct atalk_iface *iface;
431 for(iface=atalk_iface_list;iface!=NULL;iface=iface->next) {
432 if ( iface->dev != dev || ( iface->status & ATIF_PROBE )) {
433 continue;
434 }
435 if ( node == ATADDR_BCAST || iface->address.s_node == node ) {
436 return iface;
437 }
438 }
439 return NULL;
440 }
441
442
443
444
445
446 static struct atalk_iface *atalk_find_interface(int net, int node)
447 {
448 struct atalk_iface *iface;
449 for(iface=atalk_iface_list;iface!=NULL;iface=iface->next)
450 {
451 if((node==ATADDR_BCAST || iface->address.s_node==node)
452 && iface->address.s_net==net && !(iface->status&ATIF_PROBE))
453 return iface;
454 }
455 return NULL;
456 }
457
458
459
460
461
462
463
464
465 static struct atalk_route *atrtr_find(struct at_addr *target)
466 {
467 struct atalk_route *r;
468 for(r=atalk_router_list;r!=NULL;r=r->next)
469 {
470 if(!(r->flags&RTF_UP))
471 continue;
472 if(r->target.s_net==target->s_net)
473 {
474 if(!(r->flags&RTF_HOST) || r->target.s_node==target->s_node)
475 return r;
476 }
477 }
478 if(atrtr_default.dev)
479 return &atrtr_default;
480 return NULL;
481 }
482
483
484
485
486
487
488
489 static struct device *atrtr_get_dev(struct at_addr *sa)
490 {
491 struct atalk_route *atr=atrtr_find(sa);
492 if(atr==NULL)
493 return NULL;
494 else
495 return atr->dev;
496 }
497
498
499
500
501
502 static void atrtr_set_default(struct device *dev)
503 {
504 atrtr_default.dev=dev;
505 atrtr_default.flags= RTF_UP;
506 atrtr_default.gateway.s_net=htons(0);
507 atrtr_default.gateway.s_node=0;
508 }
509
510
511
512
513
514
515
516 static int atrtr_create(struct rtentry *r, struct device *devhint)
517 {
518 struct sockaddr_at *ta=(struct sockaddr_at *)&r->rt_dst;
519 struct sockaddr_at *ga=(struct sockaddr_at *)&r->rt_gateway;
520 struct atalk_route *rt;
521 struct atalk_iface *iface, *riface;
522 unsigned long flags;
523
524 save_flags(flags);
525
526
527
528
529
530
531
532
533
534 if(ta->sat_family!=AF_APPLETALK)
535 return -EINVAL;
536 if(devhint == NULL && ga->sat_family != AF_APPLETALK)
537 return -EINVAL;
538
539
540
541
542
543 for(rt=atalk_router_list;rt!=NULL;rt=rt->next)
544 {
545 if(r->rt_flags != rt->flags)
546 continue;
547
548 if(ta->sat_addr.s_net == rt->target.s_net) {
549 if(!(rt->flags&RTF_HOST))
550 break;
551 if(ta->sat_addr.s_node == rt->target.s_node)
552 break;
553 }
554 }
555
556 if ( devhint == NULL ) {
557 for ( riface = NULL, iface = atalk_iface_list; iface;
558 iface = iface->next ) {
559 if ( riface == NULL && ntohs( ga->sat_addr.s_net ) >=
560 ntohs( iface->nets.nr_firstnet ) &&
561 ntohs( ga->sat_addr.s_net ) <=
562 ntohs( iface->nets.nr_lastnet ))
563 riface = iface;
564 if ( ga->sat_addr.s_net == iface->address.s_net &&
565 ga->sat_addr.s_node == iface->address.s_node )
566 riface = iface;
567 }
568 if ( riface == NULL )
569 return -ENETUNREACH;
570 devhint = riface->dev;
571 }
572
573 if(rt==NULL)
574 {
575 rt=(struct atalk_route *)kmalloc(sizeof(struct atalk_route), GFP_KERNEL);
576 if(rt==NULL)
577 return -ENOBUFS;
578 cli();
579 rt->next=atalk_router_list;
580 atalk_router_list=rt;
581 }
582
583
584
585
586 rt->target=ta->sat_addr;
587 rt->dev=devhint;
588 rt->flags=r->rt_flags;
589 rt->gateway=ga->sat_addr;
590
591 restore_flags(flags);
592 return 0;
593 }
594
595
596
597
598
599
600 static int atrtr_delete( struct at_addr *addr )
601 {
602 struct atalk_route **r = &atalk_router_list;
603 struct atalk_route *tmp;
604
605 while ((tmp = *r) != NULL) {
606 if (tmp->target.s_net == addr->s_net &&
607 (!(tmp->flags&RTF_GATEWAY) ||
608 tmp->target.s_node == addr->s_node )) {
609 *r = tmp->next;
610 kfree_s(tmp, sizeof(struct atalk_route));
611 return 0;
612 }
613 r = &tmp->next;
614 }
615 return -ENOENT;
616 }
617
618
619
620
621
622
623 void atrtr_device_down(struct device *dev)
624 {
625 struct atalk_route **r = &atalk_router_list;
626 struct atalk_route *tmp;
627
628 while ((tmp = *r) != NULL) {
629 if (tmp->dev == dev) {
630 *r = tmp->next;
631 kfree_s(tmp, sizeof(struct atalk_route));
632 }
633 else
634 r = &tmp->next;
635 }
636 if(atrtr_default.dev==dev)
637 atrtr_set_default(NULL);
638 }
639
640
641
642
643
644
645 static int ddp_device_event(unsigned long event, void *ptr)
646 {
647 if(event==NETDEV_DOWN)
648 {
649
650 atrtr_device_down((struct device *)ptr);
651 atif_drop_device((struct device *)ptr);
652 }
653 return NOTIFY_DONE;
654 }
655
656
657
658
659
660
661
662
663
664 int atif_ioctl(int cmd, void *arg)
665 {
666 struct ifreq atreq;
667 static char aarp_mcast[6]={0x09,0x00,0x00,0xFF,0xFF,0xFF};
668 struct netrange *nr;
669 struct sockaddr_at *sa;
670 struct device *dev;
671 struct atalk_iface *atif;
672 int ro=(cmd==SIOCSIFADDR);
673 int err=verify_area(ro?VERIFY_READ:VERIFY_WRITE, arg,sizeof(atreq));
674 int ct;
675 int limit;
676 struct rtentry rtdef;
677
678 if(err)
679 return err;
680
681 memcpy_fromfs(&atreq,arg,sizeof(atreq));
682
683 if((dev=dev_get(atreq.ifr_name))==NULL)
684 return -ENODEV;
685
686 sa=(struct sockaddr_at*)&atreq.ifr_addr;
687 atif=atalk_find_dev(dev);
688
689 switch(cmd)
690 {
691 case SIOCSIFADDR:
692 if(!suser())
693 return -EPERM;
694 if(sa->sat_family!=AF_APPLETALK)
695 return -EINVAL;
696 if(dev->type!=ARPHRD_ETHER)
697 return -EPROTONOSUPPORT;
698 nr=(struct netrange *)&sa->sat_zero[0];
699 if(nr->nr_phase!=2)
700 return -EPROTONOSUPPORT;
701 if(sa->sat_addr.s_node==ATADDR_BCAST || sa->sat_addr.s_node == 254)
702 return -EINVAL;
703 if(atif)
704 {
705
706
707
708 if(atif->status&ATIF_PROBE)
709 return -EBUSY;
710
711 atif->address.s_net=sa->sat_addr.s_net;
712 atif->address.s_node=sa->sat_addr.s_node;
713 atrtr_device_down(dev);
714 }
715 else
716 {
717 atif=atif_add_device(dev, &sa->sat_addr);
718 }
719 atif->nets= *nr;
720
721
722
723
724
725
726 if(!(dev->flags&IFF_LOOPBACK) && atif_probe_device(atif)<0)
727 {
728 atif_drop_device(dev);
729 return -EADDRINUSE;
730 }
731
732
733
734
735
736
737 sa=(struct sockaddr_at *)&rtdef.rt_gateway;
738 sa->sat_family=AF_APPLETALK;
739 sa->sat_addr.s_net=atif->address.s_net;
740 sa->sat_addr.s_node=atif->address.s_node;
741 sa=(struct sockaddr_at *)&rtdef.rt_dst;
742 rtdef.rt_flags=RTF_UP;
743 sa->sat_family=AF_APPLETALK;
744 sa->sat_addr.s_node=ATADDR_ANYNODE;
745 if(dev->flags&IFF_LOOPBACK)
746 rtdef.rt_flags|=RTF_HOST;
747
748
749
750 if(nr->nr_firstnet==htons(0) && nr->nr_lastnet==htons(0xFFFE)) {
751 sa->sat_addr.s_net=atif->address.s_net;
752 atrtr_create(&rtdef, dev);
753 atrtr_set_default(dev);
754 } else {
755 limit=ntohs(nr->nr_lastnet);
756 if(limit-ntohs(nr->nr_firstnet) > 256)
757 {
758 printk("Too many routes/iface.\n");
759 return -EINVAL;
760 }
761 for(ct=ntohs(nr->nr_firstnet);ct<=limit;ct++)
762 {
763 sa->sat_addr.s_net=htons(ct);
764 atrtr_create(&rtdef, dev);
765 }
766 }
767 dev_mc_add(dev, aarp_mcast, 6, 1);
768 return 0;
769 case SIOCGIFADDR:
770 if(atif==NULL)
771 return -EADDRNOTAVAIL;
772 ((struct sockaddr_at *)(&atreq.ifr_addr))->sat_family=AF_APPLETALK;
773 ((struct sockaddr_at *)(&atreq.ifr_addr))->sat_addr=atif->address;
774 break;
775 case SIOCGIFBRDADDR:
776 if(atif==NULL)
777 return -EADDRNOTAVAIL;
778 ((struct sockaddr_at *)(&atreq.ifr_addr))->sat_family=AF_APPLETALK;
779 ((struct sockaddr_at *)(&atreq.ifr_addr))->sat_addr.s_net=atif->address.s_net;
780 ((struct sockaddr_at *)(&atreq.ifr_addr))->sat_addr.s_node=ATADDR_BCAST;
781 break;
782 }
783 memcpy_tofs(arg,&atreq,sizeof(atreq));
784 return 0;
785 }
786
787
788
789
790
791 static int atrtr_ioctl(unsigned int cmd, void *arg)
792 {
793 int err;
794 struct rtentry rt;
795
796 err=verify_area(VERIFY_READ, arg, sizeof(rt));
797 if(err)
798 return err;
799 memcpy_fromfs(&rt,arg,sizeof(rt));
800
801 switch(cmd)
802 {
803 case SIOCDELRT:
804 if(rt.rt_dst.sa_family!=AF_APPLETALK)
805 return -EINVAL;
806 return atrtr_delete(&((struct sockaddr_at *)&rt.rt_dst)->sat_addr);
807 case SIOCADDRT:
808 return atrtr_create(&rt, NULL);
809 default:
810 return -EINVAL;
811 }
812 }
813
814
815
816 int atalk_if_get_info(char *buffer, char **start, off_t offset, int length)
817 {
818 struct atalk_iface *iface;
819 int len=0;
820 off_t pos=0;
821 off_t begin=0;
822
823 len += sprintf (buffer,"Interface Address Networks Status\n");
824 for (iface = atalk_iface_list; iface != NULL; iface = iface->next)
825 {
826 len += sprintf (buffer+len,"%-16s %04X:%02X %04X-%04X %d\n",
827 iface->dev->name,
828 ntohs(iface->address.s_net),iface->address.s_node,
829 ntohs(iface->nets.nr_firstnet),ntohs(iface->nets.nr_lastnet),
830 iface->status);
831 pos=begin+len;
832 if(pos<offset)
833 {
834 len=0;
835 begin=pos;
836 }
837 if(pos>offset+length)
838 break;
839 }
840 *start=buffer+(offset-begin);
841 len-=(offset-begin);
842 if(len>length)
843 len=length;
844 return len;
845 }
846
847
848
849 int atalk_rt_get_info(char *buffer, char **start, off_t offset, int length)
850 {
851 struct atalk_route *rt;
852 int len=0;
853 off_t pos=0;
854 off_t begin=0;
855
856 len += sprintf (buffer,"Target Router Flags Dev\n");
857 if(atrtr_default.dev)
858 {
859 rt=&atrtr_default;
860 len += sprintf (buffer+len,"Default %5d:%-3d %-4d %s\n",
861 ntohs(rt->gateway.s_net), rt->gateway.s_node, rt->flags,
862 rt->dev->name);
863 }
864 for (rt = atalk_router_list; rt != NULL; rt = rt->next)
865 {
866 len += sprintf (buffer+len,"%04X:%02X %5d:%-3d %-4d %s\n",
867 ntohs(rt->target.s_net),rt->target.s_node,
868 ntohs(rt->gateway.s_net), rt->gateway.s_node, rt->flags,
869 rt->dev->name);
870 pos=begin+len;
871 if(pos<offset)
872 {
873 len=0;
874 begin=pos;
875 }
876 if(pos>offset+length)
877 break;
878 }
879 *start=buffer+(offset-begin);
880 len-=(offset-begin);
881 if(len>length)
882 len=length;
883 return len;
884 }
885
886
887
888
889
890
891
892
893
894
895
896
897 unsigned short atalk_checksum(struct ddpehdr *ddp, int len)
898 {
899 unsigned long sum=0;
900 unsigned char *data=(unsigned char *)ddp;
901
902 len-=4;
903 data+=4;
904
905
906 while(len--)
907 {
908 sum+=*data;
909 sum<<=1;
910 if(sum&0x10000)
911 {
912 sum++;
913 sum&=0xFFFF;
914 }
915 data++;
916 }
917 if(sum)
918 return htons((unsigned short)sum);
919 return 0xFFFF;
920 }
921
922
923
924
925
926
927 static int atalk_fcntl(struct socket *sock, unsigned int cmd, unsigned long arg)
928 {
929
930 switch(cmd)
931 {
932 default:
933 return(-EINVAL);
934 }
935 }
936
937
938
939
940
941
942 static int atalk_setsockopt(struct socket *sock, int level, int optname, char *optval, int optlen)
943 {
944 atalk_socket *sk;
945 int err,opt;
946
947 sk=(atalk_socket *)sock->data;
948
949 if(optval==NULL)
950 return(-EINVAL);
951
952 err=verify_area(VERIFY_READ,optval,sizeof(int));
953 if(err)
954 return err;
955 opt=get_fs_long((unsigned long *)optval);
956
957 switch(level)
958 {
959 case SOL_ATALK:
960 switch(optname)
961 {
962 default:
963 return -EOPNOTSUPP;
964 }
965 break;
966
967 case SOL_SOCKET:
968 return sock_setsockopt(sk,level,optname,optval,optlen);
969
970 default:
971 return -EOPNOTSUPP;
972 }
973 }
974
975
976
977
978
979
980 static int atalk_getsockopt(struct socket *sock, int level, int optname,
981 char *optval, int *optlen)
982 {
983 atalk_socket *sk;
984 int val=0;
985 int err;
986
987 sk=(atalk_socket *)sock->data;
988
989 switch(level)
990 {
991
992 case SOL_ATALK:
993 switch(optname)
994 {
995 default:
996 return -ENOPROTOOPT;
997 }
998 break;
999
1000 case SOL_SOCKET:
1001 return sock_getsockopt(sk,level,optname,optval,optlen);
1002
1003 default:
1004 return -EOPNOTSUPP;
1005 }
1006 err=verify_area(VERIFY_WRITE,optlen,sizeof(int));
1007 if(err)
1008 return err;
1009 put_user(sizeof(int),optlen);
1010 err=verify_area(VERIFY_WRITE,optval,sizeof(int));
1011 put_user(val,optval);
1012 return(0);
1013 }
1014
1015
1016
1017
1018
1019 static int atalk_listen(struct socket *sock, int backlog)
1020 {
1021 return -EOPNOTSUPP;
1022 }
1023
1024
1025
1026
1027
1028 static void def_callback1(struct sock *sk)
1029 {
1030 if(!sk->dead)
1031 wake_up_interruptible(sk->sleep);
1032 }
1033
1034 static void def_callback2(struct sock *sk, int len)
1035 {
1036 if(!sk->dead)
1037 {
1038 wake_up_interruptible(sk->sleep);
1039 sock_wake_async(sk->socket,0);
1040 }
1041 }
1042
1043
1044
1045
1046
1047
1048 static int atalk_create(struct socket *sock, int protocol)
1049 {
1050 atalk_socket *sk;
1051 sk=(atalk_socket *)kmalloc(sizeof(*sk),GFP_KERNEL);
1052 if(sk==NULL)
1053 return(-ENOMEM);
1054 switch(sock->type)
1055 {
1056
1057
1058 case SOCK_RAW:
1059
1060 case SOCK_DGRAM:
1061 break;
1062 default:
1063 kfree_s((void *)sk,sizeof(*sk));
1064 return(-ESOCKTNOSUPPORT);
1065 }
1066 sk->dead=0;
1067 sk->next=NULL;
1068 sk->broadcast=0;
1069 sk->no_check=0;
1070 sk->rcvbuf=SK_RMEM_MAX;
1071 sk->sndbuf=SK_WMEM_MAX;
1072 sk->pair=NULL;
1073 sk->wmem_alloc=0;
1074 sk->rmem_alloc=0;
1075 sk->inuse=0;
1076 sk->proc=0;
1077 sk->priority=1;
1078 sk->shutdown=0;
1079 sk->prot=NULL;
1080 sk->broadcast=0;
1081 sk->err=0;
1082 skb_queue_head_init(&sk->receive_queue);
1083 skb_queue_head_init(&sk->write_queue);
1084 sk->send_head=NULL;
1085 skb_queue_head_init(&sk->back_log);
1086 sk->state=TCP_CLOSE;
1087 sk->socket=sock;
1088 sk->type=sock->type;
1089 sk->debug=0;
1090
1091 sk->at.src_net=0;
1092 sk->at.src_node=0;
1093 sk->at.src_port=0;
1094
1095 sk->at.dest_net=0;
1096 sk->at.dest_node=0;
1097 sk->at.dest_port=0;
1098
1099 sk->mtu=DDP_MAXSZ;
1100
1101 if(sock!=NULL)
1102 {
1103 sock->data=(void *)sk;
1104 sk->sleep=sock->wait;
1105 }
1106
1107 sk->state_change=def_callback1;
1108 sk->data_ready=def_callback2;
1109 sk->write_space=def_callback1;
1110 sk->error_report=def_callback1;
1111
1112 sk->zapped=1;
1113 return(0);
1114 }
1115
1116
1117
1118
1119
1120 static int atalk_dup(struct socket *newsock,struct socket *oldsock)
1121 {
1122 return(atalk_create(newsock,SOCK_DGRAM));
1123 }
1124
1125
1126
1127
1128
1129 static int atalk_release(struct socket *sock, struct socket *peer)
1130 {
1131 atalk_socket *sk=(atalk_socket *)sock->data;
1132 if(sk==NULL)
1133 return(0);
1134 if(!sk->dead)
1135 sk->state_change(sk);
1136 sk->dead=1;
1137 sock->data=NULL;
1138 atalk_destroy_socket(sk);
1139 return(0);
1140 }
1141
1142
1143
1144
1145
1146
1147 static int atalk_pick_port(struct sockaddr_at *sat)
1148 {
1149 for ( sat->sat_port = ATPORT_RESERVED; sat->sat_port < ATPORT_LAST;
1150 sat->sat_port++ )
1151 if ( atalk_find_socket( sat ) == NULL )
1152 return sat->sat_port;
1153 return -EBUSY;
1154 }
1155
1156 static int atalk_autobind(atalk_socket *sk)
1157 {
1158 struct at_addr *ap = atalk_find_primary();
1159 struct sockaddr_at sat;
1160 int n;
1161
1162 if ( ap == NULL || ap->s_net == htons( ATADDR_ANYNET ))
1163 return -EADDRNOTAVAIL;
1164 sk->at.src_net = sat.sat_addr.s_net = ap->s_net;
1165 sk->at.src_node = sat.sat_addr.s_node = ap->s_node;
1166
1167 if (( n = atalk_pick_port( &sat )) < 0 )
1168 return( n );
1169 sk->at.src_port=n;
1170 atalk_insert_socket(sk);
1171 sk->zapped=0;
1172 return 0;
1173 }
1174
1175
1176
1177
1178
1179 static int atalk_bind(struct socket *sock, struct sockaddr *uaddr,int addr_len)
1180 {
1181 atalk_socket *sk;
1182 struct sockaddr_at *addr=(struct sockaddr_at *)uaddr;
1183
1184 sk=(atalk_socket *)sock->data;
1185
1186 if(sk->zapped==0)
1187 return(-EIO);
1188
1189 if(addr_len!=sizeof(struct sockaddr_at))
1190 return -EINVAL;
1191
1192 if(addr->sat_family!=AF_APPLETALK)
1193 return -EAFNOSUPPORT;
1194
1195 if(addr->sat_addr.s_net==htons(ATADDR_ANYNET))
1196 {
1197 struct at_addr *ap=atalk_find_primary();
1198 if(ap==NULL)
1199 return -EADDRNOTAVAIL;
1200 sk->at.src_net=addr->sat_addr.s_net=ap->s_net;
1201 sk->at.src_node=addr->sat_addr.s_node=ap->s_node;
1202 }
1203 else
1204 {
1205 if ( atalk_find_interface( addr->sat_addr.s_net,
1206 addr->sat_addr.s_node ) == NULL )
1207 return -EADDRNOTAVAIL;
1208 sk->at.src_net=addr->sat_addr.s_net;
1209 sk->at.src_node=addr->sat_addr.s_node;
1210 }
1211
1212 if(addr->sat_port == ATADDR_ANYPORT)
1213 {
1214 int n = atalk_pick_port(addr);
1215 if(n < 0)
1216 return n;
1217 sk->at.src_port=addr->sat_port=n;
1218 }
1219 else
1220 sk->at.src_port=addr->sat_port;
1221
1222 if(atalk_find_socket(addr)!=NULL)
1223 return -EADDRINUSE;
1224
1225 atalk_insert_socket(sk);
1226 sk->zapped=0;
1227 return(0);
1228 }
1229
1230
1231
1232
1233
1234 static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1235 int addr_len, int flags)
1236 {
1237 atalk_socket *sk=(atalk_socket *)sock->data;
1238 struct sockaddr_at *addr;
1239
1240 sk->state = TCP_CLOSE;
1241 sock->state = SS_UNCONNECTED;
1242
1243 if(addr_len!=sizeof(*addr))
1244 return(-EINVAL);
1245 addr=(struct sockaddr_at *)uaddr;
1246
1247 if(addr->sat_family!=AF_APPLETALK)
1248 return -EAFNOSUPPORT;
1249 #if 0
1250 if(addr->sat_addr.s_node==ATADDR_BCAST && !sk->broadcast)
1251 return -EPERM;
1252 #endif
1253 if(sk->zapped)
1254 {
1255 if(atalk_autobind(sk)<0)
1256 return -EBUSY;
1257 }
1258
1259 if(atrtr_get_dev(&addr->sat_addr)==NULL)
1260 return -ENETUNREACH;
1261
1262 sk->at.dest_port=addr->sat_port;
1263 sk->at.dest_net=addr->sat_addr.s_net;
1264 sk->at.dest_node=addr->sat_addr.s_node;
1265 sock->state = SS_CONNECTED;
1266 sk->state=TCP_ESTABLISHED;
1267 return(0);
1268 }
1269
1270
1271
1272
1273
1274 static int atalk_socketpair(struct socket *sock1, struct socket *sock2)
1275 {
1276 return(-EOPNOTSUPP);
1277 }
1278
1279
1280
1281
1282
1283 static int atalk_accept(struct socket *sock, struct socket *newsock, int flags)
1284 {
1285 if(newsock->data)
1286 kfree_s(newsock->data,sizeof(atalk_socket));
1287 return -EOPNOTSUPP;
1288 }
1289
1290
1291
1292
1293
1294
1295 static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1296 int *uaddr_len, int peer)
1297 {
1298 struct sockaddr_at sat;
1299 atalk_socket *sk;
1300
1301 sk=(atalk_socket *)sock->data;
1302 if(sk->zapped)
1303 {
1304 if(atalk_autobind(sk)<0)
1305 return -EBUSY;
1306 }
1307
1308 *uaddr_len = sizeof(struct sockaddr_at);
1309
1310 if(peer)
1311 {
1312 if(sk->state!=TCP_ESTABLISHED)
1313 return -ENOTCONN;
1314 sat.sat_addr.s_net=sk->at.dest_net;
1315 sat.sat_addr.s_node=sk->at.dest_node;
1316 sat.sat_port=sk->at.dest_port;
1317 }
1318 else
1319 {
1320 sat.sat_addr.s_net=sk->at.src_net;
1321 sat.sat_addr.s_node=sk->at.src_node;
1322 sat.sat_port=sk->at.src_port;
1323 }
1324 sat.sat_family = AF_APPLETALK;
1325 memcpy(uaddr,&sat,sizeof(sat));
1326 return(0);
1327 }
1328
1329
1330
1331
1332
1333
1334
1335 int atalk_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
1336 {
1337 atalk_socket *sock;
1338 struct ddpehdr *ddp=(void *)skb->h.raw;
1339 struct atalk_iface *atif;
1340 struct sockaddr_at tosat;
1341 int origlen;
1342
1343
1344 if(skb->len<sizeof(*ddp))
1345 {
1346 kfree_skb(skb,FREE_READ);
1347 return(0);
1348 }
1349
1350
1351
1352
1353
1354
1355
1356
1357 *((__u16 *)ddp)=ntohs(*((__u16 *)ddp));
1358
1359
1360
1361
1362
1363 origlen = skb->len;
1364
1365 skb_trim(skb,min(skb->len,ddp->deh_len));
1366
1367
1368
1369
1370
1371
1372
1373 if(skb->len<sizeof(*ddp))
1374 {
1375 kfree_skb(skb,FREE_READ);
1376 return(0);
1377 }
1378
1379
1380
1381
1382
1383
1384 if(ddp->deh_sum && atalk_checksum(ddp, ddp->deh_len)!= ddp->deh_sum)
1385 {
1386
1387 kfree_skb(skb,FREE_READ);
1388 return(0);
1389 }
1390
1391
1392
1393 if(ddp->deh_dnet == 0)
1394 atif=atalk_find_anynet(ddp->deh_dnode, dev);
1395 else
1396 atif=atalk_find_interface(ddp->deh_dnet,ddp->deh_dnode);
1397
1398
1399 if(atif==NULL)
1400 {
1401 struct atalk_route *rt;
1402 struct at_addr ta;
1403
1404
1405
1406 if (skb->pkt_type != PACKET_HOST || ddp->deh_dnet == 0)
1407 {
1408 kfree_skb(skb, FREE_READ);
1409 return(0);
1410 }
1411
1412 ta.s_net=ddp->deh_dnet;
1413 ta.s_node=ddp->deh_dnode;
1414
1415
1416 rt=atrtr_find(&ta);
1417 if(rt==NULL || ddp->deh_hops==15)
1418 {
1419 kfree_skb(skb, FREE_READ);
1420 return(0);
1421 }
1422 ddp->deh_hops++;
1423
1424
1425 skb_trim(skb,min(origlen, rt->dev->hard_header_len +
1426 ddp_dl->header_length + ddp->deh_len));
1427
1428 *((__u16 *)ddp)=ntohs(*((__u16 *)ddp));
1429
1430
1431
1432 if(aarp_send_ddp(rt->dev, skb, &ta, NULL)==-1)
1433 kfree_skb(skb, FREE_READ);
1434 return 0;
1435 }
1436
1437
1438
1439 tosat.sat_addr.s_net = ddp->deh_dnet;
1440 tosat.sat_addr.s_node = ddp->deh_dnode;
1441 tosat.sat_port = ddp->deh_dport;
1442
1443 sock=atalk_search_socket( &tosat, atif );
1444
1445 if(sock==NULL)
1446 {
1447 kfree_skb(skb,FREE_READ);
1448 return(0);
1449 }
1450
1451
1452
1453
1454
1455
1456 skb->sk = sock;
1457
1458 if(sock_queue_rcv_skb(sock,skb)<0)
1459 {
1460 skb->sk=NULL;
1461 kfree_skb(skb, FREE_WRITE);
1462 }
1463 return(0);
1464 }
1465
1466 static int atalk_sendto(struct socket *sock, const void *ubuf, int len, int noblock,
1467 unsigned flags, struct sockaddr *sat, int addr_len)
1468 {
1469 atalk_socket *sk=(atalk_socket *)sock->data;
1470 struct sockaddr_at *usat=(struct sockaddr_at *)sat;
1471 struct sockaddr_at local_satalk, gsat;
1472 struct sk_buff *skb;
1473 struct device *dev;
1474 struct ddpehdr *ddp;
1475 int size;
1476 struct atalk_route *rt;
1477 int loopback=0;
1478 int err;
1479
1480 if(flags)
1481 return -EINVAL;
1482
1483 if(len>587)
1484 return -EMSGSIZE;
1485
1486 if(usat)
1487 {
1488 if(sk->zapped)
1489
1490 {
1491 if(atalk_autobind(sk)<0)
1492 return -EBUSY;
1493 }
1494
1495 if(addr_len <sizeof(*usat))
1496 return(-EINVAL);
1497 if(usat->sat_family != AF_APPLETALK)
1498 return -EINVAL;
1499 #if 0
1500 if(usat->sat_addr.s_node==ATADDR_BCAST && !sk->broadcast)
1501 return -EPERM;
1502 #endif
1503 }
1504 else
1505 {
1506 if(sk->state!=TCP_ESTABLISHED)
1507 return -ENOTCONN;
1508 usat=&local_satalk;
1509 usat->sat_family=AF_APPLETALK;
1510 usat->sat_port=sk->at.dest_port;
1511 usat->sat_addr.s_node=sk->at.dest_node;
1512 usat->sat_addr.s_net=sk->at.dest_net;
1513 }
1514
1515
1516
1517 if(sk->debug)
1518 printk("SK %p: Got address.\n",sk);
1519
1520 size=sizeof(struct ddpehdr)+len+ddp_dl->header_length;
1521
1522 if(usat->sat_addr.s_net!=0 || usat->sat_addr.s_node == ATADDR_ANYNODE)
1523 {
1524 rt=atrtr_find(&usat->sat_addr);
1525 if(rt==NULL)
1526 return -ENETUNREACH;
1527 dev=rt->dev;
1528 }
1529 else
1530 {
1531 struct at_addr at_hint;
1532 at_hint.s_node=0;
1533 at_hint.s_net=sk->at.src_net;
1534 rt=atrtr_find(&at_hint);
1535 if(rt==NULL)
1536 return -ENETUNREACH;
1537 dev=rt->dev;
1538 }
1539
1540 if(sk->debug)
1541 printk("SK %p: Size needed %d, device %s\n", sk, size, dev->name);
1542
1543 size += dev->hard_header_len;
1544
1545 skb = sock_alloc_send_skb(sk, size, 0 , &err);
1546 if(skb==NULL)
1547 return err;
1548
1549 skb->sk=sk;
1550 skb->free=1;
1551 skb->arp=1;
1552 skb_reserve(skb,ddp_dl->header_length);
1553 skb_reserve(skb,dev->hard_header_len);
1554
1555 skb->dev=dev;
1556
1557 if(sk->debug)
1558 printk("SK %p: Begin build.\n", sk);
1559
1560 ddp=(struct ddpehdr *)skb_put(skb,sizeof(struct ddpehdr));
1561 ddp->deh_pad=0;
1562 ddp->deh_hops=0;
1563 ddp->deh_len=len+sizeof(*ddp);
1564
1565
1566
1567
1568
1569 *((__u16 *)ddp)=ntohs(*((__u16 *)ddp));
1570
1571 ddp->deh_dnet=usat->sat_addr.s_net;
1572 ddp->deh_snet=sk->at.src_net;
1573 ddp->deh_dnode=usat->sat_addr.s_node;
1574 ddp->deh_snode=sk->at.src_node;
1575 ddp->deh_dport=usat->sat_port;
1576 ddp->deh_sport=sk->at.src_port;
1577
1578 if(sk->debug)
1579 printk("SK %p: Copy user data (%d bytes).\n", sk, len);
1580
1581 memcpy_fromfs(skb_put(skb,len),ubuf,len);
1582
1583 if(sk->no_check==1)
1584 ddp->deh_sum=0;
1585 else
1586 ddp->deh_sum=atalk_checksum(ddp, len+sizeof(*ddp));
1587
1588
1589
1590
1591
1592
1593 if(ddp->deh_dnode==ATADDR_BCAST)
1594 {
1595 if((!(rt->flags&RTF_GATEWAY))&&(!(dev->flags&IFF_LOOPBACK)))
1596 {
1597 struct sk_buff *skb2=skb_clone(skb, GFP_KERNEL);
1598 if(skb2)
1599 {
1600 loopback=1;
1601 if(sk->debug)
1602 printk("SK %p: send out(copy).\n", sk);
1603 if(aarp_send_ddp(dev,skb2,&usat->sat_addr, NULL)==-1)
1604 kfree_skb(skb2, FREE_WRITE);
1605
1606 }
1607 }
1608 }
1609
1610 if((dev->flags&IFF_LOOPBACK) || loopback)
1611 {
1612 if(sk->debug)
1613 printk("SK %p: Loop back.\n", sk);
1614
1615 sk->wmem_alloc-=skb->truesize;
1616 ddp_dl->datalink_header(ddp_dl, skb, dev->dev_addr);
1617 skb->sk = NULL;
1618 skb->mac.raw=skb->data;
1619 skb->h.raw = skb->data + ddp_dl->header_length + dev->hard_header_len;
1620 skb_pull(skb,dev->hard_header_len);
1621 skb_pull(skb,ddp_dl->header_length);
1622 atalk_rcv(skb,dev,NULL);
1623 }
1624 else
1625 {
1626 if(sk->debug)
1627 printk("SK %p: send out.\n", sk);
1628
1629 if ( rt->flags & RTF_GATEWAY ) {
1630 gsat.sat_addr = rt->gateway;
1631 usat = &gsat;
1632 }
1633
1634 if(aarp_send_ddp(dev,skb,&usat->sat_addr, NULL)==-1)
1635 kfree_skb(skb, FREE_WRITE);
1636
1637 }
1638 if(sk->debug)
1639 printk("SK %p: Done write (%d).\n", sk, len);
1640 return len;
1641 }
1642
1643 static int atalk_send(struct socket *sock, const void *ubuf, int size, int noblock, unsigned flags)
1644 {
1645 return atalk_sendto(sock,ubuf,size,noblock,flags,NULL,0);
1646 }
1647
1648 static int atalk_recvfrom(struct socket *sock, void *ubuf, int size, int noblock,
1649 unsigned flags, struct sockaddr *sip, int *addr_len)
1650 {
1651 atalk_socket *sk=(atalk_socket *)sock->data;
1652 struct sockaddr_at *sat=(struct sockaddr_at *)sip;
1653 struct ddpehdr *ddp = NULL;
1654 int copied = 0;
1655 struct sk_buff *skb;
1656 int er;
1657
1658 if(sk->err)
1659 {
1660 er= -sk->err;
1661 sk->err=0;
1662 return er;
1663 }
1664
1665 if(addr_len)
1666 *addr_len=sizeof(*sat);
1667
1668 skb=skb_recv_datagram(sk,flags,noblock,&er);
1669 if(skb==NULL)
1670 return er;
1671
1672 ddp = (struct ddpehdr *)(skb->h.raw);
1673 if(sk->type==SOCK_RAW)
1674 {
1675 copied=ddp->deh_len;
1676 if(copied > size)
1677 copied=size;
1678 skb_copy_datagram(skb,0,ubuf,copied);
1679 }
1680 else
1681 {
1682 copied=ddp->deh_len - sizeof(*ddp);
1683 if (copied > size)
1684 copied = size;
1685 skb_copy_datagram(skb,sizeof(*ddp),ubuf,copied);
1686 }
1687 if(sat)
1688 {
1689 sat->sat_family=AF_APPLETALK;
1690 sat->sat_port=ddp->deh_sport;
1691 sat->sat_addr.s_node=ddp->deh_snode;
1692 sat->sat_addr.s_net=ddp->deh_snet;
1693 }
1694 skb_free_datagram(skb);
1695 return(copied);
1696 }
1697
1698
1699 static int atalk_write(struct socket *sock, const char *ubuf, int size, int noblock)
1700 {
1701 return atalk_send(sock,ubuf,size,noblock,0);
1702 }
1703
1704
1705 static int atalk_recv(struct socket *sock, void *ubuf, int size , int noblock,
1706 unsigned flags)
1707 {
1708 atalk_socket *sk=(atalk_socket *)sock->data;
1709 if(sk->zapped)
1710 return -ENOTCONN;
1711 return atalk_recvfrom(sock,ubuf,size,noblock,flags,NULL, NULL);
1712 }
1713
1714 static int atalk_read(struct socket *sock, char *ubuf, int size, int noblock)
1715 {
1716 return atalk_recv(sock,ubuf,size,noblock,0);
1717 }
1718
1719
1720 static int atalk_shutdown(struct socket *sk,int how)
1721 {
1722 return -EOPNOTSUPP;
1723 }
1724
1725 static int atalk_select(struct socket *sock , int sel_type, select_table *wait)
1726 {
1727 atalk_socket *sk=(atalk_socket *)sock->data;
1728
1729 return datagram_select(sk,sel_type,wait);
1730 }
1731
1732
1733
1734
1735
1736 static int atalk_ioctl(struct socket *sock,unsigned int cmd, unsigned long arg)
1737 {
1738 int err;
1739 long amount=0;
1740 atalk_socket *sk=(atalk_socket *)sock->data;
1741 int v;
1742
1743 switch(cmd)
1744 {
1745
1746
1747
1748 case TIOCOUTQ:
1749 v=sk->sndbuf-sk->wmem_alloc;
1750 if(v<0)
1751 v=0;
1752 break;
1753 case TIOCINQ:
1754 {
1755 struct sk_buff *skb;
1756
1757 if((skb=skb_peek(&sk->receive_queue))!=NULL)
1758 v=skb->len-sizeof(struct ddpehdr);
1759 break;
1760 }
1761 case SIOCGSTAMP:
1762 if (sk)
1763 {
1764 if(sk->stamp.tv_sec==0)
1765 return -ENOENT;
1766 err=verify_area(VERIFY_WRITE,(void *)arg,sizeof(struct timeval));
1767 if(err)
1768 return err;
1769 memcpy_tofs((void *)arg,&sk->stamp,sizeof(struct timeval));
1770 return 0;
1771 }
1772 return -EINVAL;
1773
1774
1775
1776 case SIOCADDRT:
1777 case SIOCDELRT:
1778 if(!suser())
1779 return -EPERM;
1780 return(atrtr_ioctl(cmd,(void *)arg));
1781
1782
1783
1784 case SIOCGIFADDR:
1785 case SIOCSIFADDR:
1786 case SIOCGIFBRDADDR:
1787 return atif_ioctl(cmd,(void *)arg);
1788
1789
1790
1791 case SIOCSIFLINK:
1792 case SIOCGIFHWADDR:
1793 case SIOCSIFHWADDR:
1794 case OLD_SIOCGIFHWADDR:
1795 case SIOCGIFFLAGS:
1796 case SIOCSIFFLAGS:
1797 case SIOCGIFMTU:
1798 case SIOCGIFCONF:
1799 case SIOCADDMULTI:
1800 case SIOCDELMULTI:
1801
1802 return(dev_ioctl(cmd,(void *) arg));
1803
1804 case SIOCSIFMETRIC:
1805 case SIOCSIFBRDADDR:
1806 case SIOCGIFNETMASK:
1807 case SIOCSIFNETMASK:
1808 case SIOCGIFMEM:
1809 case SIOCSIFMEM:
1810 case SIOCGIFDSTADDR:
1811 case SIOCSIFDSTADDR:
1812 return -EINVAL;
1813
1814 default:
1815 return -EINVAL;
1816 }
1817 err=verify_area(VERIFY_WRITE,(void *)arg,sizeof(unsigned long));
1818 if(err)
1819 return err;
1820 put_fs_long(amount,(unsigned long *)arg);
1821 return(0);
1822 }
1823
1824 static struct proto_ops atalk_proto_ops = {
1825 AF_APPLETALK,
1826
1827 atalk_create,
1828 atalk_dup,
1829 atalk_release,
1830 atalk_bind,
1831 atalk_connect,
1832 atalk_socketpair,
1833 atalk_accept,
1834 atalk_getname,
1835 atalk_read,
1836 atalk_write,
1837 atalk_select,
1838 atalk_ioctl,
1839 atalk_listen,
1840 atalk_send,
1841 atalk_recv,
1842 atalk_sendto,
1843 atalk_recvfrom,
1844 atalk_shutdown,
1845 atalk_setsockopt,
1846 atalk_getsockopt,
1847 atalk_fcntl,
1848 };
1849
1850 static struct notifier_block ddp_notifier={
1851 ddp_device_event,
1852 NULL,
1853 0
1854 };
1855
1856
1857
1858 void atalk_proto_init(struct net_proto *pro)
1859 {
1860 static char ddp_snap_id[]={0x08,0x00,0x07,0x80,0x9B};
1861 (void) sock_register(atalk_proto_ops.family, &atalk_proto_ops);
1862 if ((ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv)) == NULL)
1863 printk("Unable to register DDP with SNAP.\n");
1864 register_netdevice_notifier(&ddp_notifier);
1865 aarp_proto_init();
1866
1867 proc_net_register(&(struct proc_dir_entry) {
1868 PROC_NET_ATALK, 9, "appletalk",
1869 S_IFREG | S_IRUGO, 1, 0, 0,
1870 0, &proc_net_inode_operations,
1871 atalk_get_info
1872 });
1873 proc_net_register(&(struct proc_dir_entry) {
1874 PROC_NET_AT_ROUTE, 11,"atalk_route",
1875 S_IFREG | S_IRUGO, 1, 0, 0,
1876 atalk_rt_get_info
1877 });
1878 proc_net_register(&(struct proc_dir_entry) {
1879 PROC_NET_ATIF, 11,"atalk_iface",
1880 S_IFREG | S_IRUGO, 1, 0, 0,
1881 0, &proc_net_inode_operations,
1882 atalk_if_get_info
1883 });
1884
1885 printk("Appletalk BETA 0.11 for Linux NET3.030\n");
1886 }
1887 #endif