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