This source file includes following definitions.
- ax2asc
- ax25cmp
- ax25_remove_socket
- ax25_kill_by_device
- ax25_device_event
- ax25_insert_socket
- ax25_find_listener
- ax25_find_socket
- ax25_find_cb
- ax25_addr_match
- ax25_send_to_raw
- ax25_destroy_timer
- ax25_destroy_socket
- ax25_findbyuid
- ax25_uid_ioctl
- ax25_ctl_ioctl
- ax25_create_cb
- ax25_dev_is_dama_slave
- ax25_fillin_cb
- ax25_send_frame
- ax25rtr_get_dev
- ax25_fcntl
- ax25_setsockopt
- ax25_getsockopt
- ax25_listen
- def_callback1
- def_callback2
- ax25_create
- ax25_make_new
- ax25_dup
- ax25_release
- ax25_bind
- ax25_connect
- ax25_socketpair
- ax25_accept
- ax25_getname
- ax25_rcv
- kiss_rcv
- bpq_rcv
- ax25_sendmsg
- ax25_recvmsg
- ax25_shutdown
- ax25_select
- ax25_ioctl
- ax25_get_info
- ax25_proto_init
- ax25_queue_xmit
- ax25_encapsulate
- ax25_rebuild_header
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 #include <linux/config.h>
92 #ifdef CONFIG_AX25
93 #include <linux/errno.h>
94 #include <linux/types.h>
95 #include <linux/socket.h>
96 #include <linux/in.h>
97 #include <linux/kernel.h>
98 #include <linux/sched.h>
99 #include <linux/timer.h>
100 #include <linux/string.h>
101 #include <linux/sockios.h>
102 #include <linux/net.h>
103 #include <net/ax25.h>
104 #include <linux/inet.h>
105 #include <linux/netdevice.h>
106 #include <linux/if_arp.h>
107 #include <linux/skbuff.h>
108 #include <net/sock.h>
109 #include <asm/segment.h>
110 #include <asm/system.h>
111 #include <linux/fcntl.h>
112 #include <linux/termios.h>
113 #include <linux/mm.h>
114 #include <linux/interrupt.h>
115 #include <linux/notifier.h>
116 #include <linux/proc_fs.h>
117 #include <linux/stat.h>
118 #include <linux/firewall.h>
119
120 #include <net/ip.h>
121 #include <net/arp.h>
122
123
124
125
126
127 ax25_address null_ax25_address = {{0x40,0x40,0x40,0x40,0x40,0x40,0x00}};
128
129 ax25_cb *volatile ax25_list = NULL;
130
131
132
133
134 char *ax2asc(ax25_address *a)
135 {
136 static char buf[11];
137 char c, *s;
138 int n;
139
140 for (n = 0, s = buf; n < 6; n++)
141 {
142 c = (a->ax25_call[n] >> 1) & 0x7F;
143
144 if (c != ' ') *s++ = c;
145 }
146
147 *s++ = '-';
148
149 if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9)
150 {
151 *s++ = '1';
152 n -= 10;
153 }
154
155 *s++ = n + '0';
156 *s++ = '\0';
157
158 if (*buf == '\0' || *buf == '-')
159 return "*";
160
161 return buf;
162
163 }
164
165
166
167
168 int ax25cmp(ax25_address *a, ax25_address *b)
169 {
170 int ct = 0;
171
172 while (ct < 6) {
173 if ((a->ax25_call[ct] & 0xFE) != (b->ax25_call[ct] & 0xFE))
174 return 1;
175 ct++;
176 }
177
178 if ((a->ax25_call[ct] & 0x1E) == (b->ax25_call[ct] & 0x1E))
179 return 0;
180
181 return 2;
182 }
183
184
185
186
187 static void ax25_remove_socket(ax25_cb *ax25)
188 {
189 ax25_cb *s;
190 unsigned long flags;
191
192 save_flags(flags);
193 cli();
194
195 if ((s = ax25_list) == ax25) {
196 ax25_list = s->next;
197 restore_flags(flags);
198 return;
199 }
200
201 while (s != NULL && s->next != NULL) {
202 if (s->next == ax25) {
203 s->next = ax25->next;
204 restore_flags(flags);
205 return;
206 }
207
208 s = s->next;
209 }
210
211 restore_flags(flags);
212 }
213
214
215
216
217 static void ax25_kill_by_device(struct device *dev)
218 {
219 ax25_cb *s;
220
221 for (s = ax25_list; s != NULL; s = s->next) {
222 if (s->device == dev) {
223 s->state = AX25_STATE_0;
224 s->device = NULL;
225 if (s->sk != NULL) {
226 s->sk->state = TCP_CLOSE;
227 s->sk->err = ENETUNREACH;
228 if (!s->sk->dead)
229 s->sk->state_change(s->sk);
230 s->sk->dead = 1;
231 }
232 }
233 }
234 }
235
236
237
238
239 static int ax25_device_event(struct notifier_block *this,unsigned long event, void *ptr)
240 {
241 struct device *dev = (struct device *)ptr;
242
243 switch (event) {
244 case NETDEV_UP:
245 ax25_dev_device_up(dev);
246 break;
247 case NETDEV_DOWN:
248 ax25_kill_by_device(dev);
249 ax25_rt_device_down(dev);
250 ax25_dev_device_down(dev);
251 break;
252 default:
253 break;
254 }
255
256 return NOTIFY_DONE;
257 }
258
259
260
261
262 static void ax25_insert_socket(ax25_cb *ax25)
263 {
264 unsigned long flags;
265
266 save_flags(flags);
267 cli();
268
269 ax25->next = ax25_list;
270 ax25_list = ax25;
271
272 restore_flags(flags);
273 }
274
275
276
277
278
279 static struct sock *ax25_find_listener(ax25_address *addr, struct device *dev, int type)
280 {
281 unsigned long flags;
282 ax25_cb *s;
283
284 save_flags(flags);
285 cli();
286
287 for (s = ax25_list; s != NULL; s = s->next) {
288 if (s->sk != NULL && ax25cmp(&s->source_addr, addr) == 0 && s->sk->type == type && s->sk->state == TCP_LISTEN) {
289
290 if (s->device == NULL || s->device == dev) {
291 restore_flags(flags);
292 return s->sk;
293 }
294 }
295 }
296
297 restore_flags(flags);
298 return NULL;
299 }
300
301
302
303
304 static struct sock *ax25_find_socket(ax25_address *my_addr, ax25_address *dest_addr, int type)
305 {
306 ax25_cb *s;
307 unsigned long flags;
308
309 save_flags(flags);
310 cli();
311
312 for (s = ax25_list; s != NULL; s = s->next) {
313 if (s->sk != NULL && ax25cmp(&s->source_addr, my_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->sk->type == type) {
314 restore_flags(flags);
315 return s->sk;
316 }
317 }
318
319 restore_flags(flags);
320
321 return NULL;
322 }
323
324
325
326
327
328 static ax25_cb *ax25_find_cb(ax25_address *my_addr, ax25_address *dest_addr, struct device *dev)
329 {
330 ax25_cb *s;
331 unsigned long flags;
332
333 save_flags(flags);
334 cli();
335
336 for (s = ax25_list; s != NULL; s = s->next) {
337 if (s->sk != NULL && s->sk->type != SOCK_SEQPACKET)
338 continue;
339 if (ax25cmp(&s->source_addr, my_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->device == dev) {
340 restore_flags(flags);
341 return s;
342 }
343 }
344
345 restore_flags(flags);
346
347 return NULL;
348 }
349
350
351
352
353 static struct sock *ax25_addr_match(ax25_address *addr)
354 {
355 unsigned long flags;
356 ax25_cb *s;
357
358 save_flags(flags);
359 cli();
360
361 for (s = ax25_list; s != NULL; s = s->next) {
362 if (s->sk != NULL && ax25cmp(&s->source_addr, addr) == 0 && s->sk->type == SOCK_RAW) {
363 restore_flags(flags);
364 return s->sk;
365 }
366 }
367
368 restore_flags(flags);
369
370 return NULL;
371 }
372
373 static void ax25_send_to_raw(struct sock *sk, struct sk_buff *skb, int proto)
374 {
375 struct sk_buff *copy;
376
377 while (sk != NULL) {
378 if (sk->type == SOCK_RAW && sk->protocol == proto && sk->rmem_alloc <= sk->rcvbuf) {
379 if ((copy = skb_clone(skb, GFP_ATOMIC)) == NULL)
380 return;
381
382 copy->sk = sk;
383 atomic_add(copy->truesize, &sk->rmem_alloc);
384 skb_queue_tail(&sk->receive_queue, copy);
385 if (!sk->dead)
386 sk->data_ready(sk, skb->len);
387 }
388
389 sk = sk->next;
390 }
391 }
392
393
394
395
396 void ax25_destory_socket(ax25_cb *);
397
398
399
400
401 static void ax25_destroy_timer(unsigned long data)
402 {
403 ax25_destroy_socket((ax25_cb *)data);
404 }
405
406
407
408
409
410
411
412 void ax25_destroy_socket(ax25_cb *ax25)
413 {
414 struct sk_buff *skb;
415 unsigned long flags;
416
417 save_flags(flags);
418 cli();
419
420 del_timer(&ax25->timer);
421
422 ax25_remove_socket(ax25);
423 ax25_clear_queues(ax25);
424
425 if (ax25->sk != NULL) {
426 while ((skb = skb_dequeue(&ax25->sk->receive_queue)) != NULL) {
427 if (skb->sk != ax25->sk) {
428 skb->sk->dead = 1;
429 ax25_set_timer(skb->sk->ax25);
430 skb->sk->ax25->state = AX25_STATE_0;
431 }
432
433 kfree_skb(skb, FREE_READ);
434 }
435 }
436
437 if (ax25->sk != NULL) {
438 if (ax25->sk->wmem_alloc || ax25->sk->rmem_alloc) {
439 init_timer(&ax25->timer);
440 ax25->timer.expires = jiffies + 10 * HZ;
441 ax25->timer.function = ax25_destroy_timer;
442 ax25->timer.data = (unsigned long)ax25;
443 add_timer(&ax25->timer);
444 } else {
445 if (ax25->digipeat != NULL) {
446 kfree_s(ax25->digipeat, sizeof(ax25_digi));
447 ax25->digipeat = NULL;
448 }
449
450 kfree_s(ax25->sk, sizeof(*ax25->sk));
451 kfree_s(ax25, sizeof(*ax25));
452 }
453 } else {
454 if (ax25->digipeat != NULL) {
455 kfree_s(ax25->digipeat, sizeof(ax25_digi));
456 ax25->digipeat = NULL;
457 }
458 kfree_s(ax25, sizeof(*ax25));
459 }
460
461 restore_flags(flags);
462 }
463
464
465
466
467
468 ax25_uid_assoc *ax25_uid_list;
469
470 int ax25_uid_policy = 0;
471
472 ax25_address *ax25_findbyuid(uid_t uid)
473 {
474 ax25_uid_assoc *a;
475
476 for (a = ax25_uid_list; a != NULL; a = a->next) {
477 if (a->uid == uid)
478 return &a->call;
479 }
480
481 return NULL;
482 }
483
484 static int ax25_uid_ioctl(int cmd, struct sockaddr_ax25 *sax)
485 {
486 ax25_uid_assoc *a;
487
488 switch (cmd) {
489 case SIOCAX25GETUID:
490 for (a = ax25_uid_list; a != NULL; a = a->next) {
491 if (ax25cmp(&sax->sax25_call, &a->call) == 0)
492 return a->uid;
493 }
494 return -ENOENT;
495 case SIOCAX25ADDUID:
496 if(!suser())
497 return -EPERM;
498 if (ax25_findbyuid(sax->sax25_uid))
499 return -EEXIST;
500 a = (ax25_uid_assoc *)kmalloc(sizeof(*a), GFP_KERNEL);
501 if (a == NULL)
502 return -ENOMEM;
503 a->uid = sax->sax25_uid;
504 a->call = sax->sax25_call;
505 a->next = ax25_uid_list;
506 ax25_uid_list = a;
507 return 0;
508 case SIOCAX25DELUID:
509 {
510 ax25_uid_assoc **l;
511
512 if(!suser())
513 return -EPERM;
514 l = &ax25_uid_list;
515 while ((*l) != NULL) {
516 if (ax25cmp(&((*l)->call), &(sax->sax25_call)) == 0) {
517 a = *l;
518 *l = (*l)->next;
519 kfree_s(a, sizeof(*a));
520 return 0;
521 }
522
523 l = &((*l)->next);
524 }
525 return -ENOENT;
526 }
527 }
528
529 return -EINVAL;
530 }
531
532
533
534
535
536
537
538 static int ax25_ctl_ioctl(const unsigned int cmd, const unsigned long arg)
539 {
540 struct ax25_ctl_struct ax25_ctl;
541 struct device *dev;
542 ax25_cb *ax25;
543 unsigned long flags;
544 int err;
545
546 if ((err = verify_area(VERIFY_READ, (void *)arg, sizeof(ax25_ctl))) != 0)
547 return err;
548
549 memcpy_fromfs(&ax25_ctl, (void *) arg, sizeof(ax25_ctl));
550
551 if ((dev = ax25rtr_get_dev(&ax25_ctl.port_addr)) == NULL)
552 return -ENODEV;
553
554 if ((ax25 = ax25_find_cb(&ax25_ctl.source_addr, &ax25_ctl.dest_addr, dev)) == NULL)
555 return -ENOTCONN;
556
557 switch (ax25_ctl.cmd) {
558 case AX25_KILL:
559 #ifdef CONFIG_NETROM
560 nr_link_failed(&ax25->dest_addr, ax25->device);
561 #endif
562 ax25_clear_queues(ax25);
563 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
564
565 ax25->state = AX25_STATE_0;
566 if (ax25->sk != NULL) {
567 ax25->sk->state = TCP_CLOSE;
568 ax25->sk->err = ENETRESET;
569 if (!ax25->sk->dead)
570 ax25->sk->state_change(ax25->sk);
571 ax25->sk->dead = 1;
572 }
573
574 ax25_dama_off(ax25);
575 ax25_set_timer(ax25);
576 break;
577 case AX25_WINDOW:
578 if (ax25->modulus == MODULUS) {
579 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7)
580 return -EINVAL;
581 } else {
582 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63)
583 return -EINVAL;
584 }
585 ax25->window = ax25_ctl.arg;
586 break;
587 case AX25_T1:
588 if (ax25_ctl.arg < 1)
589 return -EINVAL;
590 ax25->rtt = (ax25_ctl.arg * PR_SLOWHZ) / 2;
591 ax25->t1 = ax25_ctl.arg * PR_SLOWHZ;
592 save_flags(flags); cli();
593 if (ax25->t1timer > ax25->t1)
594 ax25->t1timer = ax25->t1;
595 restore_flags(flags);
596 break;
597 case AX25_T2:
598 if (ax25_ctl.arg < 1)
599 return -EINVAL;
600 save_flags(flags); cli();
601 ax25->t2 = ax25_ctl.arg * PR_SLOWHZ;
602 if (ax25->t2timer > ax25->t2)
603 ax25->t2timer = ax25->t2;
604 restore_flags(flags);
605 break;
606 case AX25_N2:
607 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31)
608 return -EINVAL;
609 ax25->n2count = 0;
610 ax25->n2 = ax25_ctl.arg;
611 break;
612 case AX25_T3:
613 if (ax25_ctl.arg < 1)
614 return -EINVAL;
615 save_flags(flags); cli();
616 ax25->t3 = ax25_ctl.arg * PR_SLOWHZ;
617 if (ax25->t3timer != 0)
618 ax25->t3timer = ax25->t3;
619 restore_flags(flags);
620 break;
621 case AX25_IDLE:
622 if (ax25_ctl.arg < 1)
623 return -EINVAL;
624 if (ax25->idle == 0)
625 return 0;
626 save_flags(flags); cli();
627 ax25->idle = ax25_ctl.arg * PR_SLOWHZ * 60;
628 if (ax25->idletimer != 0)
629 ax25->idletimer = ax25->idle;
630 restore_flags(flags);
631 break;
632 case AX25_PACLEN:
633 if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535)
634 return -EINVAL;
635
636 if (ax25_ctl.arg > 256)
637 printk("ax25_ctl_ioctl(): Warning --- huge paclen %d", (int) ax25_ctl.arg);
638 ax25->paclen = ax25_ctl.arg;
639 break;
640 case AX25_IPMAXQUEUE:
641 if (ax25_ctl.arg < 1)
642 return -EINVAL;
643
644 ax25->maxqueue = ax25_ctl.arg;
645 break;
646 default:
647 return -EINVAL;
648 }
649
650 return 0;
651 }
652
653
654
655
656
657 static ax25_cb *ax25_create_cb(void)
658 {
659 ax25_cb *ax25;
660
661 if ((ax25 = (ax25_cb *)kmalloc(sizeof(*ax25), GFP_ATOMIC)) == NULL)
662 return NULL;
663
664 skb_queue_head_init(&ax25->write_queue);
665 skb_queue_head_init(&ax25->frag_queue);
666 skb_queue_head_init(&ax25->ack_queue);
667 skb_queue_head_init(&ax25->reseq_queue);
668
669 init_timer(&ax25->timer);
670
671 ax25->dama_slave = 0;
672
673 ax25->rtt = (AX25_DEF_T1 * PR_SLOWHZ) / 2;
674 ax25->t1 = AX25_DEF_T1 * PR_SLOWHZ;
675 ax25->t2 = AX25_DEF_T2 * PR_SLOWHZ;
676 ax25->t3 = AX25_DEF_T3 * PR_SLOWHZ;
677 ax25->n2 = AX25_DEF_N2;
678 ax25->paclen = AX25_DEF_PACLEN;
679 ax25->maxqueue= AX25_DEF_IPMAXQUEUE;
680 ax25->idle = 0;
681
682 ax25->modulus = AX25_DEF_AXDEFMODE;
683 ax25->fragno = 0;
684 ax25->fraglen = 0;
685 ax25->hdrincl = 0;
686 ax25->backoff = AX25_DEF_BACKOFF == 'E';
687 ax25->condition = 0x00;
688 ax25->t1timer = 0;
689 ax25->t2timer = 0;
690 ax25->t3timer = 0;
691 ax25->n2count = 0;
692 ax25->idletimer = 0;
693
694 ax25->va = 0;
695 ax25->vr = 0;
696 ax25->vs = 0;
697
698 if (AX25_DEF_AXDEFMODE == EMODULUS) {
699 ax25->window = AX25_DEF_EWINDOW;
700 } else {
701 ax25->window = AX25_DEF_WINDOW;
702 }
703 ax25->device = NULL;
704 ax25->digipeat = NULL;
705 ax25->sk = NULL;
706
707 ax25->state = AX25_STATE_0;
708
709 memset(&ax25->dest_addr, '\0', AX25_ADDR_LEN);
710 memset(&ax25->source_addr, '\0', AX25_ADDR_LEN);
711
712 return ax25;
713 }
714
715
716
717
718
719
720
721 int ax25_dev_is_dama_slave(struct device *dev)
722 {
723 ax25_cb *ax25;
724 int count = 0;
725
726 for (ax25 = ax25_list; ax25 != NULL; ax25 = ax25->next) {
727 if (ax25->device == dev && ax25->dama_slave) {
728 count++;
729 break;
730 }
731 }
732
733 return count;
734 }
735
736
737
738
739
740 static void ax25_fillin_cb(ax25_cb *ax25, struct device *dev)
741 {
742 ax25->device = dev;
743
744 ax25->rtt = ax25_dev_get_value(dev, AX25_VALUES_T1);
745 ax25->t1 = ax25_dev_get_value(dev, AX25_VALUES_T1);
746 ax25->t2 = ax25_dev_get_value(dev, AX25_VALUES_T2);
747 ax25->t3 = ax25_dev_get_value(dev, AX25_VALUES_T3);
748 ax25->n2 = ax25_dev_get_value(dev, AX25_VALUES_N2);
749 ax25->paclen = ax25_dev_get_value(dev, AX25_VALUES_PACLEN);
750 ax25->maxqueue = ax25_dev_get_value(dev, AX25_VALUES_IPMAXQUEUE);
751
752 ax25->dama_slave = 0;
753 ax25->idle = 0;
754
755 ax25->modulus = ax25_dev_get_value(dev, AX25_VALUES_AXDEFMODE);
756
757 if (ax25->modulus == MODULUS) {
758 ax25->window = ax25_dev_get_value(dev, AX25_VALUES_WINDOW);
759 } else {
760 ax25->window = ax25_dev_get_value(dev, AX25_VALUES_EWINDOW);
761 }
762
763 ax25->backoff = ax25_dev_get_value(dev, AX25_VALUES_BACKOFF) == 'E';
764 }
765
766 int ax25_send_frame(struct sk_buff *skb, ax25_address *src, ax25_address *dest,
767 ax25_digi *digi, struct device *dev)
768 {
769 ax25_cb *ax25;
770
771 if (skb == NULL)
772 return 0;
773
774
775
776
777 for (ax25 = ax25_list; ax25 != NULL; ax25 = ax25->next) {
778 if (ax25->sk != NULL && ax25->sk->type != SOCK_SEQPACKET)
779 continue;
780
781 if (ax25cmp(&ax25->source_addr, src) == 0 && ax25cmp(&ax25->dest_addr, dest) == 0 && ax25->device == dev) {
782 if (ax25_queue_length(ax25, skb) > ax25->maxqueue * ax25->window) {
783 kfree_skb(skb, FREE_WRITE);
784 } else {
785 ax25_output(ax25, skb);
786 }
787 ax25->idletimer = ax25->idle;
788 return 1;
789 }
790 }
791
792 if ((ax25 = ax25_create_cb()) == NULL)
793 return 0;
794
795 ax25_fillin_cb(ax25, dev);
796
797 ax25->source_addr = *src;
798 ax25->dest_addr = *dest;
799
800 if (digi != NULL) {
801 if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
802 kfree_s(ax25, sizeof(ax25));
803 return 0;
804 }
805 *ax25->digipeat = *digi;
806 } else {
807 ax25_rt_build_path(ax25, dest);
808 }
809
810 if (ax25_dev_is_dama_slave(ax25->device))
811 dama_establish_data_link(ax25);
812 else
813 ax25_establish_data_link(ax25);
814
815
816
817 ax25->idletimer = ax25->idle = ax25_dev_get_value(ax25->device, AX25_VALUES_IDLE);
818
819 ax25_insert_socket(ax25);
820
821 ax25->state = AX25_STATE_1;
822
823 ax25_set_timer(ax25);
824
825 ax25_output(ax25, skb);
826
827 return 1;
828 }
829
830
831
832
833 struct device *ax25rtr_get_dev(ax25_address *addr)
834 {
835 struct device *dev;
836
837 for (dev = dev_base; dev != NULL; dev = dev->next) {
838 if (dev->flags & IFF_UP) {
839 switch (dev->type) {
840 case ARPHRD_AX25:
841 if (ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0)
842 return dev;
843 break;
844 #ifdef CONFIG_BPQETHER
845 case ARPHRD_ETHER: {
846 ax25_address *dev_addr;
847
848 if ((dev_addr = ax25_bpq_get_addr(dev)) != NULL)
849 if (ax25cmp(addr, dev_addr) == 0)
850 return dev;
851 }
852 break;
853 #endif
854 default:
855 break;
856 }
857 }
858 }
859
860 return NULL;
861 }
862
863
864
865
866
867
868 static int ax25_fcntl(struct socket *sock, unsigned int cmd, unsigned long arg)
869 {
870 return -EINVAL;
871 }
872
873 static int ax25_setsockopt(struct socket *sock, int level, int optname,
874 char *optval, int optlen)
875 {
876 struct sock *sk;
877 int err, opt;
878
879 sk = (struct sock *)sock->data;
880
881 if (level == SOL_SOCKET)
882 return sock_setsockopt(sk, level, optname, optval, optlen);
883
884 if (level != SOL_AX25)
885 return -EOPNOTSUPP;
886
887 if (optval == NULL)
888 return -EINVAL;
889
890 if ((err = verify_area(VERIFY_READ, optval, sizeof(int))) != 0)
891 return err;
892
893 opt = get_fs_long((unsigned long *)optval);
894
895 switch (optname) {
896 case AX25_WINDOW:
897 if (sk->ax25->modulus == MODULUS) {
898 if (opt < 1 || opt > 7)
899 return -EINVAL;
900 } else {
901 if (opt < 1 || opt > 63)
902 return -EINVAL;
903 }
904 sk->ax25->window = opt;
905 return 0;
906
907 case AX25_T1:
908 if (opt < 1)
909 return -EINVAL;
910 sk->ax25->rtt = (opt * PR_SLOWHZ) / 2;
911 return 0;
912
913 case AX25_T2:
914 if (opt < 1)
915 return -EINVAL;
916 sk->ax25->t2 = opt * PR_SLOWHZ;
917 return 0;
918
919 case AX25_N2:
920 if (opt < 1 || opt > 31)
921 return -EINVAL;
922 sk->ax25->n2 = opt;
923 return 0;
924
925 case AX25_T3:
926 if (opt < 1)
927 return -EINVAL;
928 sk->ax25->t3 = opt * PR_SLOWHZ;
929 return 0;
930
931 case AX25_IDLE:
932 if (opt < 0)
933 return -EINVAL;
934 sk->ax25->idle = opt * PR_SLOWHZ * 60;
935 return 0;
936
937 case AX25_BACKOFF:
938 sk->ax25->backoff = opt ? 1 : 0;
939 return 0;
940
941 case AX25_EXTSEQ:
942 sk->ax25->modulus = opt ? EMODULUS : MODULUS;
943 return 0;
944
945 case AX25_HDRINCL:
946 sk->ax25->hdrincl = opt ? 1 : 0;
947 return 0;
948
949 case AX25_PACLEN:
950 if (opt < 16 || opt > 65535)
951 return -EINVAL;
952 sk->ax25->paclen = opt;
953 return 0;
954
955 default:
956 return -ENOPROTOOPT;
957 }
958 }
959
960 static int ax25_getsockopt(struct socket *sock, int level, int optname,
961 char *optval, int *optlen)
962 {
963 struct sock *sk;
964 int val = 0;
965 int err;
966
967 sk = (struct sock *)sock->data;
968
969 if (level == SOL_SOCKET)
970 return sock_getsockopt(sk, level, optname, optval, optlen);
971
972 if (level != SOL_AX25)
973 return -EOPNOTSUPP;
974
975 switch (optname) {
976 case AX25_WINDOW:
977 val = sk->ax25->window;
978 break;
979
980 case AX25_T1:
981 val = (sk->ax25->t1 * 2) / PR_SLOWHZ;
982 break;
983
984 case AX25_T2:
985 val = sk->ax25->t2 / PR_SLOWHZ;
986 break;
987
988 case AX25_N2:
989 val = sk->ax25->n2;
990 break;
991
992 case AX25_T3:
993 val = sk->ax25->t3 / PR_SLOWHZ;
994 break;
995
996 case AX25_IDLE:
997 val = sk->ax25->idle / (PR_SLOWHZ * 60);
998 break;
999
1000 case AX25_BACKOFF:
1001 val = sk->ax25->backoff;
1002 break;
1003
1004 case AX25_EXTSEQ:
1005 val = (sk->ax25->modulus == EMODULUS);
1006 break;
1007
1008 case AX25_HDRINCL:
1009 val = sk->ax25->hdrincl;
1010 break;
1011
1012 case AX25_PACLEN:
1013 val = sk->ax25->paclen;
1014 break;
1015
1016 default:
1017 return -ENOPROTOOPT;
1018 }
1019
1020 if ((err = verify_area(VERIFY_WRITE, optlen, sizeof(int))) != 0)
1021 return err;
1022
1023 put_user(sizeof(int), optlen);
1024
1025 if ((err = verify_area(VERIFY_WRITE, optval, sizeof(int))) != 0)
1026 return err;
1027
1028 put_user(val, optval);
1029
1030 return 0;
1031 }
1032
1033 static int ax25_listen(struct socket *sock, int backlog)
1034 {
1035 struct sock *sk = (struct sock *)sock->data;
1036
1037 if (sk->type == SOCK_SEQPACKET && sk->state != TCP_LISTEN) {
1038 sk->max_ack_backlog = backlog;
1039 sk->state = TCP_LISTEN;
1040 return 0;
1041 }
1042
1043 return -EOPNOTSUPP;
1044 }
1045
1046 static void def_callback1(struct sock *sk)
1047 {
1048 if (!sk->dead)
1049 wake_up_interruptible(sk->sleep);
1050 }
1051
1052 static void def_callback2(struct sock *sk, int len)
1053 {
1054 if (!sk->dead)
1055 wake_up_interruptible(sk->sleep);
1056 }
1057
1058 static int ax25_create(struct socket *sock, int protocol)
1059 {
1060 struct sock *sk;
1061 ax25_cb *ax25;
1062
1063 switch (sock->type) {
1064 case SOCK_DGRAM:
1065 if (protocol == 0 || protocol == AF_AX25)
1066 protocol = AX25_P_TEXT;
1067 break;
1068 case SOCK_SEQPACKET:
1069 switch (protocol) {
1070 case 0:
1071 case AF_AX25:
1072 protocol = AX25_P_TEXT;
1073 break;
1074 case AX25_P_SEGMENT:
1075 #ifdef CONFIG_INET
1076 case AX25_P_ARP:
1077 case AX25_P_IP:
1078 #endif
1079 #ifdef CONFIG_NETROM
1080 case AX25_P_NETROM:
1081 #endif
1082 return -ESOCKTNOSUPPORT;
1083 default:
1084 break;
1085 }
1086 break;
1087 case SOCK_RAW:
1088 break;
1089 default:
1090 return -ESOCKTNOSUPPORT;
1091 }
1092
1093 if ((sk = sk_alloc(GFP_ATOMIC)) == NULL)
1094 return -ENOMEM;
1095
1096 if ((ax25 = ax25_create_cb()) == NULL) {
1097 sk_free(sk);
1098 return -ENOMEM;
1099 }
1100
1101 skb_queue_head_init(&sk->receive_queue);
1102 skb_queue_head_init(&sk->write_queue);
1103 skb_queue_head_init(&sk->back_log);
1104
1105 sk->socket = sock;
1106 sk->type = sock->type;
1107 sk->protocol = protocol;
1108 sk->dead = 0;
1109 sk->next = NULL;
1110 sk->broadcast = 0;
1111 sk->allocation = GFP_KERNEL;
1112 sk->rcvbuf = SK_RMEM_MAX;
1113 sk->sndbuf = SK_WMEM_MAX;
1114 sk->wmem_alloc = 0;
1115 sk->rmem_alloc = 0;
1116 sk->users = 0;
1117 sk->debug = 0;
1118 sk->destroy = 0;
1119 sk->prot = NULL;
1120 sk->err = 0;
1121 sk->localroute = 0;
1122 sk->send_head = NULL;
1123 sk->state = TCP_CLOSE;
1124 sk->shutdown = 0;
1125 sk->priority = SOPRI_NORMAL;
1126 sk->ack_backlog = 0;
1127 sk->mtu = AX25_MTU;
1128 sk->zapped = 1;
1129
1130 sk->state_change = def_callback1;
1131 sk->data_ready = def_callback2;
1132 sk->write_space = def_callback1;
1133 sk->error_report = def_callback1;
1134
1135 if (sock != NULL) {
1136 sock->data = (void *)sk;
1137 sk->sleep = sock->wait;
1138 }
1139
1140 ax25->sk = sk;
1141 sk->ax25 = ax25;
1142
1143 return 0;
1144 }
1145
1146 static struct sock *ax25_make_new(struct sock *osk, struct device *dev)
1147 {
1148 struct sock *sk;
1149 ax25_cb *ax25;
1150
1151 if ((sk = sk_alloc(GFP_ATOMIC)) == NULL)
1152 return NULL;
1153
1154 if ((ax25 = ax25_create_cb()) == NULL) {
1155 sk_free(sk);
1156 return NULL;
1157 }
1158
1159 ax25_fillin_cb(ax25, dev);
1160
1161 sk->type = osk->type;
1162 sk->socket = osk->socket;
1163
1164 switch (osk->type) {
1165 case SOCK_DGRAM:
1166 break;
1167 case SOCK_SEQPACKET:
1168 break;
1169 default:
1170 sk_free(sk);
1171 kfree_s((void *)ax25, sizeof(*ax25));
1172 return NULL;
1173 }
1174
1175 skb_queue_head_init(&sk->receive_queue);
1176 skb_queue_head_init(&sk->write_queue);
1177 skb_queue_head_init(&sk->back_log);
1178
1179 sk->dead = 0;
1180 sk->next = NULL;
1181 sk->priority = osk->priority;
1182 sk->broadcast = 0;
1183 sk->protocol = osk->protocol;
1184 sk->rcvbuf = osk->rcvbuf;
1185 sk->sndbuf = osk->sndbuf;
1186 sk->wmem_alloc = 0;
1187 sk->rmem_alloc = 0;
1188 sk->users = 0;
1189 sk->ack_backlog = 0;
1190 sk->destroy = 0;
1191 sk->prot = NULL;
1192 sk->err = 0;
1193 sk->localroute = 0;
1194 sk->send_head = NULL;
1195 sk->debug = osk->debug;
1196 sk->state = TCP_ESTABLISHED;
1197 sk->window = osk->window;
1198 sk->shutdown = 0;
1199 sk->mtu = osk->mtu;
1200 sk->sleep = osk->sleep;
1201 sk->zapped = osk->zapped;
1202
1203 sk->state_change = def_callback1;
1204 sk->data_ready = def_callback2;
1205 sk->write_space = def_callback1;
1206 sk->error_report = def_callback1;
1207
1208 ax25->modulus = osk->ax25->modulus;
1209 ax25->backoff = osk->ax25->backoff;
1210 ax25->hdrincl = osk->ax25->hdrincl;
1211 ax25->rtt = osk->ax25->rtt;
1212 ax25->t1 = osk->ax25->t1;
1213 ax25->t2 = osk->ax25->t2;
1214 ax25->t3 = osk->ax25->t3;
1215 ax25->n2 = osk->ax25->n2;
1216 ax25->idle = osk->ax25->idle;
1217
1218 ax25->window = osk->ax25->window;
1219
1220 ax25->source_addr = osk->ax25->source_addr;
1221
1222 if (osk->ax25->digipeat != NULL) {
1223 if ((ax25->digipeat = (ax25_digi *)kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
1224 sk_free(sk);
1225 kfree_s(ax25, sizeof(*ax25));
1226 return NULL;
1227 }
1228
1229
1230 *ax25->digipeat = *osk->ax25->digipeat;
1231 }
1232
1233 sk->ax25 = ax25;
1234 ax25->sk = sk;
1235
1236 return sk;
1237 }
1238
1239 static int ax25_dup(struct socket *newsock, struct socket *oldsock)
1240 {
1241 struct sock *sk = (struct sock *)oldsock->data;
1242
1243 return ax25_create(newsock, sk->protocol);
1244 }
1245
1246 static int ax25_release(struct socket *sock, struct socket *peer)
1247 {
1248 struct sock *sk = (struct sock *)sock->data;
1249
1250 if (sk == NULL) return 0;
1251
1252 if (sk->type == SOCK_SEQPACKET) {
1253 switch (sk->ax25->state) {
1254 case AX25_STATE_0:
1255 sk->state = TCP_CLOSE;
1256 sk->state_change(sk);
1257 sk->dead = 1;
1258 ax25_destroy_socket(sk->ax25);
1259 break;
1260
1261 case AX25_STATE_1:
1262 ax25_send_control(sk->ax25, DISC, POLLON, C_COMMAND);
1263 sk->ax25->state = AX25_STATE_0;
1264 sk->state = TCP_CLOSE;
1265 sk->state_change(sk);
1266 sk->dead = 1;
1267 ax25_destroy_socket(sk->ax25);
1268 break;
1269
1270 case AX25_STATE_2:
1271 if (sk->ax25->dama_slave)
1272 ax25_send_control(sk->ax25, DISC, POLLON, C_COMMAND);
1273 else
1274 ax25_send_control(sk->ax25, DM, POLLON, C_RESPONSE);
1275 sk->ax25->state = AX25_STATE_0;
1276 sk->state = TCP_CLOSE;
1277 sk->state_change(sk);
1278 sk->dead = 1;
1279 ax25_destroy_socket(sk->ax25);
1280 break;
1281
1282 case AX25_STATE_3:
1283 case AX25_STATE_4:
1284 ax25_clear_queues(sk->ax25);
1285 sk->ax25->n2count = 0;
1286 if (!sk->ax25->dama_slave) {
1287 ax25_send_control(sk->ax25, DISC, POLLON, C_COMMAND);
1288 sk->ax25->t3timer = 0;
1289 } else {
1290 sk->ax25->t3timer = sk->ax25->t3;
1291 }
1292 sk->ax25->t1timer = sk->ax25->t1 = ax25_calculate_t1(sk->ax25);
1293 sk->ax25->state = AX25_STATE_2;
1294 sk->state = TCP_CLOSE;
1295 sk->state_change(sk);
1296 sk->dead = 1;
1297 sk->destroy = 1;
1298 break;
1299
1300 default:
1301 break;
1302 }
1303 } else {
1304 sk->state = TCP_CLOSE;
1305 sk->state_change(sk);
1306 sk->dead = 1;
1307 ax25_destroy_socket(sk->ax25);
1308 }
1309
1310 sock->data = NULL;
1311 sk->socket = NULL;
1312
1313 return 0;
1314 }
1315
1316
1317
1318
1319
1320
1321
1322 static int ax25_bind(struct socket *sock, struct sockaddr *uaddr,int addr_len)
1323 {
1324 struct sock *sk;
1325 struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr;
1326 struct device *dev;
1327 ax25_address *call;
1328
1329 sk = (struct sock *)sock->data;
1330
1331 if (sk->zapped == 0)
1332 return -EIO;
1333
1334 if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25))
1335 return -EINVAL;
1336
1337 call = ax25_findbyuid(current->euid);
1338 if (call == NULL && ax25_uid_policy && !suser())
1339 return -EPERM;
1340
1341 if (call == NULL)
1342 sk->ax25->source_addr = addr->fsa_ax25.sax25_call;
1343 else
1344 sk->ax25->source_addr = *call;
1345
1346 if (sk->debug)
1347 printk("AX25: source address set to %s\n", ax2asc(&sk->ax25->source_addr));
1348
1349 if (addr_len == sizeof(struct full_sockaddr_ax25) && addr->fsa_ax25.sax25_ndigis == 1) {
1350 if (ax25cmp(&addr->fsa_digipeater[0], &null_ax25_address) == 0) {
1351 dev = NULL;
1352 if (sk->debug)
1353 printk("AX25: bound to any device\n");
1354 } else {
1355 if ((dev = ax25rtr_get_dev(&addr->fsa_digipeater[0])) == NULL) {
1356 if (sk->debug)
1357 printk("AX25: bind failed - no device\n");
1358 return -EADDRNOTAVAIL;
1359 }
1360 if (sk->debug)
1361 printk("AX25: bound to device %s\n", dev->name);
1362 }
1363 } else {
1364 if ((dev = ax25rtr_get_dev(&addr->fsa_ax25.sax25_call)) == NULL) {
1365 if (sk->debug)
1366 printk("AX25: bind failed - no device\n");
1367 return -EADDRNOTAVAIL;
1368 }
1369 if (sk->debug)
1370 printk("AX25: bound to device %s\n", dev->name);
1371 }
1372
1373 ax25_fillin_cb(sk->ax25, dev);
1374 ax25_insert_socket(sk->ax25);
1375
1376 sk->zapped = 0;
1377
1378 if (sk->debug)
1379 printk("AX25: socket is bound\n");
1380
1381 return 0;
1382 }
1383
1384 static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
1385 int addr_len, int flags)
1386 {
1387 struct sock *sk = (struct sock *)sock->data;
1388 struct sockaddr_ax25 *addr = (struct sockaddr_ax25 *)uaddr;
1389 int err;
1390
1391 if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
1392 sock->state = SS_CONNECTED;
1393 return 0;
1394 }
1395
1396 if (sk->state == TCP_CLOSE && sock->state == SS_CONNECTING) {
1397 sock->state = SS_UNCONNECTED;
1398 return -ECONNREFUSED;
1399 }
1400
1401 if (sk->state == TCP_ESTABLISHED && sk->type == SOCK_SEQPACKET)
1402 return -EISCONN;
1403
1404 sk->state = TCP_CLOSE;
1405 sock->state = SS_UNCONNECTED;
1406
1407 if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25))
1408 return -EINVAL;
1409
1410
1411
1412
1413 if (addr_len == sizeof(struct full_sockaddr_ax25) && addr->sax25_ndigis != 0) {
1414 int ct = 0;
1415 struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)addr;
1416
1417
1418 if (addr->sax25_ndigis < 1 || addr->sax25_ndigis > AX25_MAX_DIGIS)
1419 return -EINVAL;
1420
1421 if (sk->ax25->digipeat == NULL) {
1422 if ((sk->ax25->digipeat = (ax25_digi *)kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL)
1423 return -ENOMEM;
1424 }
1425
1426 sk->ax25->digipeat->ndigi = addr->sax25_ndigis;
1427
1428 while (ct < addr->sax25_ndigis) {
1429 sk->ax25->digipeat->repeated[ct] = 0;
1430 sk->ax25->digipeat->calls[ct] = fsa->fsa_digipeater[ct];
1431 ct++;
1432 }
1433
1434 sk->ax25->digipeat->lastrepeat = 0;
1435 } else {
1436 if (sk->debug)
1437 printk("building digipeater path\n");
1438 ax25_rt_build_path(sk->ax25, &addr->sax25_call);
1439 }
1440
1441
1442
1443
1444
1445
1446 if (sk->zapped) {
1447 if ((err = ax25_rt_autobind(sk->ax25, &addr->sax25_call)) < 0)
1448 return err;
1449 ax25_fillin_cb(sk->ax25, sk->ax25->device);
1450 ax25_insert_socket(sk->ax25);
1451 } else {
1452 if (sk->ax25->device == NULL)
1453 return -EHOSTUNREACH;
1454 }
1455
1456 if (sk->type == SOCK_SEQPACKET && ax25_find_cb(&sk->ax25->source_addr, &addr->sax25_call, sk->ax25->device) != NULL)
1457 return -EBUSY;
1458
1459 sk->ax25->dest_addr = addr->sax25_call;
1460
1461
1462 if (sk->type != SOCK_SEQPACKET) {
1463 sock->state = SS_CONNECTED;
1464 sk->state = TCP_ESTABLISHED;
1465 return 0;
1466 }
1467
1468
1469 sock->state = SS_CONNECTING;
1470 sk->state = TCP_SYN_SENT;
1471
1472 if (ax25_dev_is_dama_slave(sk->ax25->device))
1473 dama_establish_data_link(sk->ax25);
1474 else
1475 ax25_establish_data_link(sk->ax25);
1476
1477 sk->ax25->state = AX25_STATE_1;
1478 ax25_set_timer(sk->ax25);
1479
1480
1481 if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
1482 return -EINPROGRESS;
1483
1484 cli();
1485
1486
1487 while (sk->state == TCP_SYN_SENT) {
1488 interruptible_sleep_on(sk->sleep);
1489 if (current->signal & ~current->blocked) {
1490 sti();
1491 return -ERESTARTSYS;
1492 }
1493 }
1494
1495 if (sk->state != TCP_ESTABLISHED)
1496 {
1497
1498 sti();
1499 sock->state = SS_UNCONNECTED;
1500 return sock_error(sk);
1501 }
1502
1503 sock->state = SS_CONNECTED;
1504
1505 sti();
1506
1507 return 0;
1508 }
1509
1510 static int ax25_socketpair(struct socket *sock1, struct socket *sock2)
1511 {
1512 return -EOPNOTSUPP;
1513 }
1514
1515 static int ax25_accept(struct socket *sock, struct socket *newsock, int flags)
1516 {
1517 struct sock *sk;
1518 struct sock *newsk;
1519 struct sk_buff *skb;
1520
1521 if (newsock->data)
1522 sk_free(newsock->data);
1523
1524 newsock->data = NULL;
1525
1526 sk = (struct sock *)sock->data;
1527
1528 if (sk->type != SOCK_SEQPACKET)
1529 return -EOPNOTSUPP;
1530
1531 if (sk->state != TCP_LISTEN)
1532 return -EINVAL;
1533
1534
1535
1536
1537
1538 do {
1539 cli();
1540 if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) {
1541 if (flags & O_NONBLOCK) {
1542 sti();
1543 return 0;
1544 }
1545 interruptible_sleep_on(sk->sleep);
1546 if (current->signal & ~current->blocked) {
1547 sti();
1548 return -ERESTARTSYS;
1549 }
1550 }
1551 } while (skb == NULL);
1552
1553 newsk = skb->sk;
1554 newsk->pair = NULL;
1555 sti();
1556
1557
1558 skb->sk = NULL;
1559 kfree_skb(skb, FREE_READ);
1560 sk->ack_backlog--;
1561 newsock->data = newsk;
1562
1563 return 0;
1564 }
1565
1566 static int ax25_getname(struct socket *sock, struct sockaddr *uaddr,
1567 int *uaddr_len, int peer)
1568 {
1569 ax25_address *addr;
1570 struct full_sockaddr_ax25 *sax = (struct full_sockaddr_ax25 *)uaddr;
1571 struct sock *sk;
1572 unsigned char ndigi, i;
1573
1574 sk = (struct sock *)sock->data;
1575
1576 if (peer != 0) {
1577 if (sk->state != TCP_ESTABLISHED)
1578 return -ENOTCONN;
1579 addr = &sk->ax25->dest_addr;
1580 } else {
1581 addr = &sk->ax25->source_addr;
1582 }
1583
1584 sax->fsa_ax25.sax25_family = AF_AX25;
1585 sax->fsa_ax25.sax25_call = *addr;
1586 sax->fsa_ax25.sax25_ndigis = 0;
1587 *uaddr_len = sizeof(struct sockaddr_ax25);
1588
1589
1590 if (sk->ax25->digipeat != NULL) {
1591 ndigi = sk->ax25->digipeat->ndigi;
1592 sax->fsa_ax25.sax25_ndigis = ndigi;
1593 *uaddr_len += AX25_ADDR_LEN * ndigi;
1594 for (i = 0; i < ndigi; i++)
1595 sax->fsa_digipeater[i] = sk->ax25->digipeat->calls[i];
1596 }
1597
1598 return 0;
1599 }
1600
1601 static int ax25_rcv(struct sk_buff *skb, struct device *dev, ax25_address *dev_addr, struct packet_type *ptype)
1602 {
1603 struct sock *make;
1604 struct sock *sk;
1605 int type = 0;
1606 ax25_digi dp;
1607 ax25_cb *ax25;
1608 ax25_address src, dest;
1609 struct sock *raw;
1610 int mine = 0;
1611 int dama;
1612
1613
1614
1615
1616
1617 skb->h.raw = skb->data;
1618
1619 #ifdef CONFIG_FIREWALL
1620 if (call_in_firewall(PF_AX25, skb, skb->h.raw) != FW_ACCEPT) {
1621 kfree_skb(skb, FREE_READ);
1622 return 0;
1623 }
1624 #endif
1625
1626
1627
1628
1629
1630 if (ax25_parse_addr(skb->data, skb->len, &src, &dest, &dp, &type, &dama) == NULL) {
1631 kfree_skb(skb, FREE_READ);
1632 return 0;
1633 }
1634
1635
1636
1637
1638 #ifdef notdef
1639 ax25_rt_rx_frame(&src, dev, &dp);
1640 #endif
1641
1642
1643
1644
1645 if (dp.lastrepeat + 1 < dp.ndigi) {
1646 if (ax25cmp(&dp.calls[dp.lastrepeat + 1], dev_addr) == 0) {
1647 struct device *dev_out = dev;
1648
1649
1650
1651 dp.lastrepeat++;
1652 dp.repeated[(int)dp.lastrepeat] = 1;
1653
1654 if (ax25_dev_get_value(dev, AX25_VALUES_DIGI) & AX25_DIGI_XBAND) {
1655 while (dp.lastrepeat + 1 < dp.ndigi) {
1656 struct device *dev_scan;
1657 if ((dev_scan = ax25rtr_get_dev(&dp.calls[dp.lastrepeat + 1])) == NULL)
1658 break;
1659 dp.lastrepeat++;
1660 dp.repeated[(int)dp.lastrepeat] = 1;
1661 dev_out = dev_scan;
1662 }
1663 if (dev != dev_out && (ax25_dev_get_value(dev_out, AX25_VALUES_DIGI) & AX25_DIGI_XBAND) == 0) {
1664 kfree_skb(skb, FREE_READ);
1665 return 0;
1666 }
1667 }
1668
1669 if (dev == dev_out && (ax25_dev_get_value(dev, AX25_VALUES_DIGI) & AX25_DIGI_INBAND) == 0) {
1670 kfree_skb(skb, FREE_READ);
1671 return 0;
1672 }
1673
1674 ax25_rt_rx_frame(&src, dev, &dp);
1675
1676 build_ax25_addr(skb->data, &src, &dest, &dp, type, MODULUS);
1677 #ifdef CONFIG_FIREWALL
1678 if (call_fw_firewall(PF_AX25, skb, skb->data) != FW_ACCEPT) {
1679 kfree_skb(skb, FREE_READ);
1680 return 0;
1681 }
1682 #endif
1683
1684 skb->arp = 1;
1685 ax25_queue_xmit(skb, dev_out, SOPRI_NORMAL);
1686 } else {
1687 kfree_skb(skb, FREE_READ);
1688 }
1689
1690 return 0;
1691 }
1692
1693
1694
1695
1696 skb_pull(skb, size_ax25_addr(&dp));
1697
1698
1699 if (ax25cmp(&dest, dev_addr) == 0)
1700 mine = 1;
1701
1702 #ifdef CONFIG_NETROM
1703
1704 if (!mine && nr_dev_get(&dest) != NULL)
1705 mine = 1;
1706 #endif
1707
1708 if ((*skb->data & ~0x10) == LAPB_UI) {
1709 skb->h.raw = skb->data + 2;
1710
1711 if ((raw = ax25_addr_match(&dest)) != NULL)
1712 ax25_send_to_raw(raw, skb, skb->data[1]);
1713
1714 if (!mine && ax25cmp(&dest, (ax25_address *)dev->broadcast) != 0) {
1715 kfree_skb(skb, FREE_READ);
1716 return 0;
1717 }
1718
1719
1720 switch (skb->data[1]) {
1721 #ifdef CONFIG_INET
1722 case AX25_P_IP:
1723 ax25_rt_rx_frame(&src, dev, &dp);
1724 skb_pull(skb,2);
1725 ax25_ip_mode_set(&src, dev, 'D');
1726 ip_rcv(skb, dev, ptype);
1727 break;
1728
1729 case AX25_P_ARP:
1730 ax25_rt_rx_frame(&src, dev, &dp);
1731 skb_pull(skb,2);
1732 arp_rcv(skb, dev, ptype);
1733 break;
1734 #endif
1735 case AX25_P_TEXT:
1736
1737 if ((sk = ax25_find_socket(&dest, &src, SOCK_DGRAM)) != NULL) {
1738 if (sk->rmem_alloc >= sk->rcvbuf) {
1739 kfree_skb(skb, FREE_READ);
1740 } else {
1741 ax25_rt_rx_frame(&src, dev, &dp);
1742
1743
1744
1745 skb_pull(skb, 2);
1746 skb_queue_tail(&sk->receive_queue, skb);
1747 skb->sk = sk;
1748 atomic_add(skb->truesize, &sk->rmem_alloc);
1749 if (!sk->dead)
1750 sk->data_ready(sk, skb->len);
1751 }
1752 } else {
1753 kfree_skb(skb, FREE_READ);
1754 }
1755 break;
1756
1757 default:
1758 kfree_skb(skb, FREE_READ);
1759 break;
1760 }
1761
1762 return 0;
1763 }
1764
1765
1766
1767
1768
1769
1770 if (!ax25_dev_get_value(dev, AX25_VALUES_CONMODE)) {
1771 kfree_skb(skb, FREE_READ);
1772 return 0;
1773 }
1774
1775
1776
1777
1778
1779 if ((ax25 = ax25_find_cb(&dest, &src, dev)) != NULL) {
1780
1781
1782
1783
1784
1785 ax25_rt_rx_frame(&src, dev, &dp);
1786 if (ax25_process_rx_frame(ax25, skb, type, dama) == 0)
1787 kfree_skb(skb, FREE_READ);
1788
1789 return 0;
1790 }
1791
1792
1793
1794
1795
1796 if ((*skb->data & ~PF) != SABM && (*skb->data & ~PF) != SABME) {
1797
1798
1799
1800
1801 if ((*skb->data & ~PF) != DM && mine)
1802 ax25_return_dm(dev, &src, &dest, &dp);
1803
1804 kfree_skb(skb, FREE_READ);
1805 return 0;
1806 }
1807
1808
1809
1810 if ((sk = ax25_find_listener(&dest, dev, SOCK_SEQPACKET)) != NULL) {
1811 ax25_rt_rx_frame(&src, dev, &dp);
1812 if (sk->ack_backlog == sk->max_ack_backlog || (make = ax25_make_new(sk, dev)) == NULL) {
1813 if (mine)
1814 ax25_return_dm(dev, &src, &dest, &dp);
1815
1816 kfree_skb(skb, FREE_READ);
1817 return 0;
1818 }
1819
1820 ax25 = make->ax25;
1821
1822 skb_queue_head(&sk->receive_queue, skb);
1823
1824 skb->sk = make;
1825 make->state = TCP_ESTABLISHED;
1826 make->pair = sk;
1827
1828 sk->ack_backlog++;
1829 } else {
1830 #ifdef CONFIG_NETROM
1831 if (!mine) {
1832 kfree_skb(skb, FREE_READ);
1833 return 0;
1834 }
1835
1836 ax25_rt_rx_frame(&src, dev, &dp);
1837
1838 if ((ax25 = ax25_create_cb()) == NULL) {
1839 ax25_return_dm(dev, &src, &dest, &dp);
1840 kfree_skb(skb, FREE_READ);
1841 return 0;
1842 }
1843
1844 ax25_fillin_cb(ax25, dev);
1845 ax25->idletimer = ax25->idle = ax25_dev_get_value(ax25->device, AX25_VALUES_IDLE);
1846 #else
1847 if (mine) {
1848 ax25_rt_rx_frame(&src, dev, &dp);
1849 ax25_return_dm(dev, &src, &dest, &dp);
1850 }
1851
1852 kfree_skb(skb, FREE_READ);
1853 return 0;
1854 #endif
1855 }
1856
1857 ax25->source_addr = dest;
1858 ax25->dest_addr = src;
1859
1860
1861
1862
1863 if (dp.ndigi != 0 && ax25->digipeat == NULL && (ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
1864 kfree_skb(skb, FREE_READ);
1865 ax25_destroy_socket(ax25);
1866 return 0;
1867 }
1868
1869 if (dp.ndigi == 0) {
1870 if (ax25->digipeat != NULL) {
1871 kfree_s(ax25->digipeat, sizeof(ax25_digi));
1872 ax25->digipeat = NULL;
1873 }
1874 } else {
1875
1876 ax25_digi_invert(&dp, ax25->digipeat);
1877 }
1878
1879 if ((*skb->data & ~PF) == SABME) {
1880 ax25->modulus = EMODULUS;
1881 ax25->window = ax25_dev_get_value(dev, AX25_VALUES_EWINDOW);
1882 } else {
1883 ax25->modulus = MODULUS;
1884 ax25->window = ax25_dev_get_value(dev, AX25_VALUES_WINDOW);
1885 }
1886
1887 ax25->device = dev;
1888
1889 ax25_send_control(ax25, UA, POLLON, C_RESPONSE);
1890
1891 if (dama) ax25_dama_on(ax25);
1892
1893 ax25->dama_slave = dama;
1894 ax25->t3timer = ax25->t3;
1895 ax25->state = AX25_STATE_3;
1896
1897 ax25_insert_socket(ax25);
1898
1899 ax25_set_timer(ax25);
1900
1901 if (sk != NULL) {
1902 if (!sk->dead)
1903 sk->data_ready(sk, skb->len );
1904 } else {
1905 kfree_skb(skb, FREE_READ);
1906 }
1907
1908 return 0;
1909 }
1910
1911
1912
1913
1914 static int kiss_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *ptype)
1915 {
1916 skb->sk = NULL;
1917
1918 if ((*skb->data & 0x0F) != 0) {
1919 kfree_skb(skb, FREE_READ);
1920 return 0;
1921 }
1922
1923 skb_pull(skb, AX25_KISS_HEADER_LEN);
1924
1925 return ax25_rcv(skb, dev, (ax25_address *)dev->dev_addr, ptype);
1926 }
1927
1928 #ifdef CONFIG_BPQETHER
1929
1930
1931
1932 static int bpq_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *ptype)
1933 {
1934 ax25_address *port_call;
1935 int len;
1936
1937 skb->sk = NULL;
1938
1939 if ((port_call = ax25_bpq_get_addr(dev)) == NULL) {
1940 kfree_skb(skb, FREE_READ);
1941 return 0;
1942 }
1943
1944 len = skb->data[0] + skb->data[1] * 256 - 5;
1945
1946 skb_pull(skb, 2);
1947 skb_trim(skb, len);
1948
1949 return ax25_rcv(skb, dev, port_call, ptype);
1950 }
1951 #endif
1952
1953 static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, int len, int noblock, int flags)
1954 {
1955 struct sock *sk = (struct sock *)sock->data;
1956 struct sockaddr_ax25 *usax = (struct sockaddr_ax25 *)msg->msg_name;
1957 int err;
1958 struct sockaddr_ax25 sax;
1959 struct sk_buff *skb;
1960 unsigned char *asmptr;
1961 int size;
1962 ax25_digi *dp;
1963 ax25_digi dtmp;
1964 int lv;
1965 int addr_len=msg->msg_namelen;
1966
1967 if (sk->err) {
1968 return sock_error(sk);
1969 }
1970
1971 if (flags|| msg->msg_accrights)
1972 return -EINVAL;
1973
1974 if (sk->zapped)
1975 return -EADDRNOTAVAIL;
1976
1977 if (sk->ax25->device == NULL)
1978 return -ENETUNREACH;
1979
1980 if (usax) {
1981 if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25))
1982 return -EINVAL;
1983 if (usax->sax25_family != AF_AX25)
1984 return -EINVAL;
1985 if (addr_len == sizeof(struct full_sockaddr_ax25) && usax->sax25_ndigis != 0) {
1986 int ct = 0;
1987 struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)usax;
1988
1989
1990 if (usax->sax25_ndigis < 1 || usax->sax25_ndigis > AX25_MAX_DIGIS)
1991 return -EINVAL;
1992
1993 dtmp.ndigi = usax->sax25_ndigis;
1994
1995 while (ct < usax->sax25_ndigis) {
1996 dtmp.repeated[ct] = 0;
1997 dtmp.calls[ct] = fsa->fsa_digipeater[ct];
1998 ct++;
1999 }
2000
2001 dtmp.lastrepeat = 0;
2002 }
2003
2004 sax = *usax;
2005 if (sk->type == SOCK_SEQPACKET && ax25cmp(&sk->ax25->dest_addr, &sax.sax25_call) != 0)
2006 return -EISCONN;
2007 if (usax->sax25_ndigis == 0)
2008 dp = NULL;
2009 else
2010 dp = &dtmp;
2011 } else {
2012 if (sk->state != TCP_ESTABLISHED)
2013 return -ENOTCONN;
2014 sax.sax25_family = AF_AX25;
2015 sax.sax25_call = sk->ax25->dest_addr;
2016 dp = sk->ax25->digipeat;
2017 }
2018
2019 if (sk->debug)
2020 printk("AX.25: sendto: Addresses built.\n");
2021
2022
2023 if (sk->debug)
2024 printk("AX.25: sendto: building packet.\n");
2025
2026
2027 size = len + 3 + size_ax25_addr(dp) + AX25_BPQ_HEADER_LEN;
2028
2029 if ((skb = sock_alloc_send_skb(sk, size, 0, 0, &err)) == NULL)
2030 return err;
2031
2032 skb->sk = sk;
2033 skb->free = 1;
2034 skb->arp = 1;
2035
2036 skb_reserve(skb, size - len);
2037
2038 if (sk->debug)
2039 printk("AX.25: Appending user data\n");
2040
2041
2042 memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
2043
2044
2045 asmptr = skb_push(skb, 1);
2046 *asmptr = sk->protocol;
2047
2048 if (sk->debug)
2049 printk("AX.25: Transmitting buffer\n");
2050
2051 if (sk->type == SOCK_SEQPACKET) {
2052
2053 if (sk->state != TCP_ESTABLISHED) {
2054 kfree_skb(skb, FREE_WRITE);
2055 return -ENOTCONN;
2056 }
2057
2058 ax25_output(sk->ax25, skb);
2059
2060 return len;
2061 } else {
2062 asmptr = skb_push(skb, 1 + size_ax25_addr(dp));
2063
2064 if (sk->debug) {
2065 printk("Building AX.25 Header (dp=%p).\n", dp);
2066 if (dp != 0)
2067 printk("Num digipeaters=%d\n", dp->ndigi);
2068 }
2069
2070
2071 asmptr += (lv = build_ax25_addr(asmptr, &sk->ax25->source_addr, &sax.sax25_call, dp, C_COMMAND, MODULUS));
2072
2073 if (sk->debug)
2074 printk("Built header (%d bytes)\n",lv);
2075
2076 skb->h.raw = asmptr;
2077
2078 if (sk->debug)
2079 printk("base=%p pos=%p\n", skb->data, asmptr);
2080
2081 *asmptr = LAPB_UI;
2082
2083
2084 ax25_queue_xmit(skb, sk->ax25->device, SOPRI_NORMAL);
2085
2086 return len;
2087 }
2088
2089 }
2090
2091 static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, int size, int noblock, int flags, int *addr_len)
2092 {
2093 struct sock *sk = (struct sock *)sock->data;
2094 struct sockaddr_ax25 *sax = (struct sockaddr_ax25 *)msg->msg_name;
2095 int copied, length;
2096 struct sk_buff *skb;
2097 int er;
2098 int dama;
2099
2100 if (sk->err) {
2101 return sock_error(sk);
2102 }
2103
2104 if (addr_len != NULL)
2105 *addr_len = sizeof(*sax);
2106
2107
2108
2109
2110
2111 if (sk->type == SOCK_SEQPACKET && sk->state != TCP_ESTABLISHED)
2112 return -ENOTCONN;
2113
2114
2115 if ((skb = skb_recv_datagram(sk, flags, noblock, &er)) == NULL)
2116 return er;
2117
2118 if (sk->ax25->hdrincl) {
2119 length = skb->len + (skb->data - skb->h.raw);
2120 } else {
2121 if (sk->type == SOCK_SEQPACKET)
2122 skb_pull(skb, 1);
2123 length = skb->len;
2124 skb->h.raw = skb->data;
2125 }
2126
2127 copied = (size < length) ? size : length;
2128 skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
2129
2130 if (sax) {
2131 ax25_digi digi;
2132 ax25_address dest;
2133
2134 if (addr_len == (int *)0)
2135 return -EINVAL;
2136 if (*addr_len != sizeof(struct sockaddr_ax25) && *addr_len != sizeof(struct full_sockaddr_ax25))
2137 return -EINVAL;
2138
2139 ax25_parse_addr(skb->data, skb->len, NULL, &dest, &digi, NULL, &dama);
2140
2141 sax->sax25_family = AF_AX25;
2142
2143
2144
2145 sax->sax25_ndigis = digi.ndigi;
2146 sax->sax25_call = dest;
2147
2148 *addr_len = sizeof(struct sockaddr_ax25);
2149
2150 if (*addr_len == sizeof(struct full_sockaddr_ax25) && sax->sax25_ndigis != 0) {
2151 int ct = 0;
2152 struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)sax;
2153
2154 while (ct < digi.ndigi) {
2155 fsa->fsa_digipeater[ct] = digi.calls[ct];
2156 ct++;
2157 }
2158
2159 *addr_len = sizeof(struct full_sockaddr_ax25);
2160 }
2161 }
2162
2163 skb_free_datagram(sk, skb);
2164
2165 return copied;
2166 }
2167
2168 static int ax25_shutdown(struct socket *sk, int how)
2169 {
2170
2171 return -EOPNOTSUPP;
2172 }
2173
2174 static int ax25_select(struct socket *sock , int sel_type, select_table *wait)
2175 {
2176 struct sock *sk = (struct sock *)sock->data;
2177
2178 return datagram_select(sk, sel_type, wait);
2179 }
2180
2181 static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2182 {
2183 struct sock *sk = (struct sock *)sock->data;
2184 int err;
2185 long amount = 0;
2186
2187 switch (cmd) {
2188 case TIOCOUTQ:
2189 if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(unsigned long))) != 0)
2190 return err;
2191 amount = sk->sndbuf - sk->wmem_alloc;
2192 if (amount < 0)
2193 amount = 0;
2194 put_fs_long(amount, (unsigned long *)arg);
2195 return 0;
2196
2197 case TIOCINQ:
2198 {
2199 struct sk_buff *skb;
2200
2201 if ((skb = skb_peek(&sk->receive_queue)) != NULL)
2202 amount = skb->len;
2203 if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(unsigned long))) != 0)
2204 return err;
2205 put_fs_long(amount, (unsigned long *)arg);
2206 return 0;
2207 }
2208
2209 case SIOCGSTAMP:
2210 if (sk != NULL) {
2211 if (sk->stamp.tv_sec==0)
2212 return -ENOENT;
2213 if ((err = verify_area(VERIFY_WRITE,(void *)arg,sizeof(struct timeval))) != 0)
2214 return err;
2215 memcpy_tofs((void *)arg, &sk->stamp, sizeof(struct timeval));
2216 return 0;
2217 }
2218 return -EINVAL;
2219
2220 case SIOCAX25ADDUID:
2221 case SIOCAX25DELUID:
2222 case SIOCAX25GETUID:
2223 {
2224 struct sockaddr_ax25 sax25;
2225 if ((err = verify_area(VERIFY_READ, (void *)arg, sizeof(struct sockaddr_ax25))) != 0)
2226 return err;
2227 memcpy_fromfs(&sax25, (void *)arg, sizeof(sax25));
2228 return ax25_uid_ioctl(cmd, &sax25);
2229 }
2230
2231 case SIOCAX25NOUID:
2232 if ((err = verify_area(VERIFY_READ, (void *)arg, sizeof(unsigned long))) != 0)
2233 return err;
2234 if(!suser())
2235 return -EPERM;
2236 amount = get_fs_long((void *)arg);
2237 if (amount > AX25_NOUID_BLOCK)
2238 return -EINVAL;
2239 ax25_uid_policy = amount;
2240 return 0;
2241
2242 #ifdef CONFIG_BPQETHER
2243 case SIOCAX25BPQADDR:
2244 if (!suser())
2245 return -EPERM;
2246 return ax25_bpq_ioctl(cmd, (void *)arg);
2247 #endif
2248
2249 case SIOCAX25GETPARMS:
2250 case SIOCAX25SETPARMS:
2251 return ax25_dev_ioctl(cmd, (void *)arg);
2252
2253 case SIOCADDRT:
2254 case SIOCDELRT:
2255 case SIOCAX25OPTRT:
2256 if (!suser())
2257 return -EPERM;
2258 return ax25_rt_ioctl(cmd, (void *)arg);
2259
2260 case SIOCAX25CTLCON:
2261 if (!suser())
2262 return -EPERM;
2263 return ax25_ctl_ioctl(cmd, arg);
2264
2265 case SIOCGIFADDR:
2266 case SIOCSIFADDR:
2267 case SIOCGIFDSTADDR:
2268 case SIOCSIFDSTADDR:
2269 case SIOCGIFBRDADDR:
2270 case SIOCSIFBRDADDR:
2271 case SIOCGIFNETMASK:
2272 case SIOCSIFNETMASK:
2273 case SIOCGIFMETRIC:
2274 case SIOCSIFMETRIC:
2275 return -EINVAL;
2276
2277 default:
2278 return(dev_ioctl(cmd, (void *)arg));
2279 }
2280
2281
2282 return(0);
2283 }
2284
2285
2286 static int ax25_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
2287 {
2288 ax25_cb *ax25;
2289 struct device *dev;
2290 const char *devname;
2291 int len = 0;
2292 off_t pos = 0;
2293 off_t begin = 0;
2294 int idletimer;
2295
2296 cli();
2297
2298 len += sprintf(buffer, "dest_addr src_addr dev st vs vr va t1 t2 t3 idle n2 rtt wnd paclen dama Snd-Q Rcv-Q\n");
2299
2300 for (ax25 = ax25_list; ax25 != NULL; ax25 = ax25->next) {
2301 if ((dev = ax25->device) == NULL)
2302 devname = "???";
2303 else
2304 devname = dev->name;
2305
2306 idletimer = ax25->idletimer / (PR_SLOWHZ * 60);
2307 idletimer += (ax25->idletimer && ax25->idletimer < ax25->idle)? 1:0;
2308
2309 len += sprintf(buffer + len, "%-9s ",
2310 ax2asc(&ax25->dest_addr));
2311 len += sprintf(buffer + len, "%-9s %-4s %2d %3d %3d %3d %3d/%03d %2d/%02d %3d/%03d %3d/%03d %2d/%02d %3d %3d %5d",
2312 ax2asc(&ax25->source_addr), devname,
2313 ax25->state,
2314 ax25->vs, ax25->vr, ax25->va,
2315 ax25->t1timer / PR_SLOWHZ,
2316 ax25->t1 / PR_SLOWHZ,
2317 ax25->t2timer / PR_SLOWHZ,
2318 ax25->t2 / PR_SLOWHZ,
2319 ax25->t3timer / PR_SLOWHZ,
2320 ax25->t3 / PR_SLOWHZ,
2321 idletimer,
2322 ax25->idle / (PR_SLOWHZ*60),
2323 ax25->n2count, ax25->n2,
2324 ax25->rtt / PR_SLOWHZ,
2325 ax25->window,
2326 ax25->paclen);
2327
2328 len += sprintf(buffer + len, " %s", ax25->dama_slave? " slave" : " no");
2329
2330 if (ax25->sk != NULL) {
2331 len += sprintf(buffer + len, " %5d %5d\n",
2332 ax25->sk->wmem_alloc,
2333 ax25->sk->rmem_alloc);
2334 } else {
2335 len += sprintf(buffer + len, "\n");
2336 }
2337
2338 pos = begin + len;
2339
2340 if (pos < offset) {
2341 len = 0;
2342 begin = pos;
2343 }
2344
2345 if (pos > offset + length)
2346 break;
2347 }
2348
2349 sti();
2350
2351 *start = buffer + (offset - begin);
2352 len -= (offset - begin);
2353
2354 if (len > length) len = length;
2355
2356 return(len);
2357 }
2358
2359 static struct proto_ops ax25_proto_ops = {
2360 AF_AX25,
2361
2362 ax25_create,
2363 ax25_dup,
2364 ax25_release,
2365 ax25_bind,
2366 ax25_connect,
2367 ax25_socketpair,
2368 ax25_accept,
2369 ax25_getname,
2370 ax25_select,
2371 ax25_ioctl,
2372 ax25_listen,
2373 ax25_shutdown,
2374 ax25_setsockopt,
2375 ax25_getsockopt,
2376 ax25_fcntl,
2377 ax25_sendmsg,
2378 ax25_recvmsg
2379 };
2380
2381
2382
2383
2384
2385 static struct packet_type ax25_packet_type =
2386 {
2387 0,
2388 0,
2389 kiss_rcv,
2390 NULL,
2391 NULL,
2392 };
2393
2394 #ifdef CONFIG_BPQETHER
2395 static struct packet_type bpq_packet_type =
2396 {
2397 0,
2398 0,
2399 bpq_rcv,
2400 NULL,
2401 NULL,
2402 };
2403 #endif
2404
2405 static struct notifier_block ax25_dev_notifier = {
2406 ax25_device_event,
2407 0
2408 };
2409
2410 void ax25_proto_init(struct net_proto *pro)
2411 {
2412 sock_register(ax25_proto_ops.family, &ax25_proto_ops);
2413 ax25_packet_type.type = htons(ETH_P_AX25);
2414 dev_add_pack(&ax25_packet_type);
2415 #ifdef CONFIG_BPQETHER
2416 bpq_packet_type.type = htons(ETH_P_BPQ);
2417 dev_add_pack(&bpq_packet_type);
2418 #endif
2419 register_netdevice_notifier(&ax25_dev_notifier);
2420
2421 proc_net_register(&(struct proc_dir_entry) {
2422 PROC_NET_AX25_ROUTE, 10, "ax25_route",
2423 S_IFREG | S_IRUGO, 1, 0, 0,
2424 0, &proc_net_inode_operations,
2425 ax25_rt_get_info
2426 });
2427 proc_net_register(&(struct proc_dir_entry) {
2428 PROC_NET_AX25, 4, "ax25",
2429 S_IFREG | S_IRUGO, 1, 0, 0,
2430 0, &proc_net_inode_operations,
2431 ax25_get_info
2432 });
2433 proc_net_register(&(struct proc_dir_entry) {
2434 PROC_NET_AX25_CALLS, 10, "ax25_calls",
2435 S_IFREG | S_IRUGO, 1, 0, 0,
2436 0, &proc_net_inode_operations,
2437 ax25_cs_get_info
2438 });
2439
2440 printk("G4KLX/GW4PTS AX.25 for Linux. Version 0.32 BETA for Linux NET3.034 (Linux 1.3.77)\n");
2441
2442 #ifdef CONFIG_BPQETHER
2443 proc_net_register(&(struct proc_dir_entry) {
2444 PROC_NET_AX25_BPQETHER, 13, "ax25_bpqether",
2445 S_IFREG | S_IRUGO, 1, 0, 0,
2446 0, &proc_net_inode_operations,
2447 ax25_bpq_get_info
2448 });
2449
2450 printk("G8BPQ Encapsulation of AX.25 frames enabled\n");
2451 #endif
2452 }
2453
2454
2455
2456
2457
2458
2459 void ax25_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
2460 {
2461 unsigned char *ptr;
2462
2463 #ifdef CONFIG_FIREWALL
2464 if (call_out_firewall(PF_AX25, skb, skb->data) != FW_ACCEPT) {
2465 dev_kfree_skb(skb, FREE_WRITE);
2466 return;
2467 }
2468 #endif
2469
2470 skb->protocol = htons (ETH_P_AX25);
2471
2472 #ifdef CONFIG_BPQETHER
2473 if(dev->type == ARPHRD_ETHER) {
2474 static char bcast_addr[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
2475 int size;
2476
2477 if(skb_headroom(skb) < AX25_BPQ_HEADER_LEN) {
2478 printk("ax25_queue_xmit: not enough space to add BPQ Ether header\n");
2479 dev_kfree_skb(skb, FREE_WRITE);
2480 return;
2481 }
2482
2483 size = skb->len;
2484
2485 ptr = skb_push(skb, 2);
2486
2487 *ptr++ = (size + 5) % 256;
2488 *ptr++ = (size + 5) / 256;
2489
2490 dev->hard_header(skb, dev, ETH_P_BPQ, bcast_addr, NULL, 0);
2491 dev_queue_xmit(skb, dev, pri);
2492 return;
2493 }
2494 #endif
2495
2496 ptr = skb_push(skb, 1);
2497 *ptr++ = 0;
2498 dev_queue_xmit(skb, dev, pri);
2499 }
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509 #ifdef CONFIG_INET
2510
2511 int ax25_encapsulate(struct sk_buff *skb, struct device *dev, unsigned short type, void *daddr,
2512 void *saddr, unsigned len)
2513 {
2514
2515 unsigned char *buff = skb_push(skb, AX25_HEADER_LEN);
2516
2517 *buff++ = 0;
2518
2519 if (daddr != NULL)
2520 memcpy(buff, daddr, dev->addr_len);
2521
2522 buff[6] &= ~LAPB_C;
2523 buff[6] &= ~LAPB_E;
2524 buff[6] |= SSSID_SPARE;
2525 buff += AX25_ADDR_LEN;
2526
2527 if (saddr != NULL)
2528 memcpy(buff, saddr, dev->addr_len);
2529 else
2530 memcpy(buff, dev->dev_addr, dev->addr_len);
2531
2532 buff[6] &= ~LAPB_C;
2533 buff[6] |= LAPB_E;
2534 buff[6] |= SSSID_SPARE;
2535 buff += AX25_ADDR_LEN;
2536
2537 *buff++ = LAPB_UI;
2538
2539
2540 switch (type) {
2541 case ETH_P_IP:
2542 *buff++ = AX25_P_IP;
2543 break;
2544
2545 case ETH_P_ARP:
2546 *buff++ = AX25_P_ARP;
2547 break;
2548 default:
2549 printk("wrong protocol type 0x%x2.2\n", type);
2550 *buff++ = 0;
2551 break;
2552 }
2553
2554 if (daddr != NULL)
2555 return AX25_HEADER_LEN;
2556
2557 return -AX25_HEADER_LEN;
2558 }
2559
2560 int ax25_rebuild_header(unsigned char *bp, struct device *dev, unsigned long dest, struct sk_buff *skb)
2561 {
2562 int mode;
2563
2564 if (arp_find(bp + 1, dest, dev, dev->pa_addr, skb))
2565 return 1;
2566
2567 if (bp[16] == AX25_P_IP) {
2568 mode = ax25_ip_mode_get((ax25_address *)(bp + 1), dev);
2569 if (mode == 'V' || mode == 'v' || (mode == ' ' && ax25_dev_get_value(dev, AX25_VALUES_IPDEFMODE) == 'V'))
2570 {
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584 struct sk_buff *ourskb=skb_clone(skb, GFP_ATOMIC);
2585
2586 if(ourskb==NULL) {
2587 dev_kfree_skb(skb, FREE_WRITE);
2588 return 1;
2589 }
2590
2591 ourskb->sk = skb->sk;
2592 if (ourskb->sk != NULL)
2593 atomic_add(ourskb->truesize, &ourskb->sk->wmem_alloc);
2594
2595 dev_kfree_skb(skb, FREE_WRITE);
2596 skb_pull(ourskb, AX25_HEADER_LEN - 1);
2597 ax25_send_frame(ourskb, (ax25_address *)(bp + 8), (ax25_address *)(bp + 1), NULL, dev);
2598 return 1;
2599 }
2600 }
2601
2602 bp[7] &= ~LAPB_C;
2603 bp[7] &= ~LAPB_E;
2604 bp[7] |= SSSID_SPARE;
2605
2606 bp[14] &= ~LAPB_C;
2607 bp[14] |= LAPB_E;
2608 bp[14] |= SSSID_SPARE;
2609
2610
2611
2612
2613
2614
2615 ax25_dg_build_path(skb, (ax25_address *)(bp + 1), dev);
2616 ax25_queue_xmit(skb, dev, SOPRI_NORMAL);
2617
2618 return 1;
2619 }
2620
2621 #endif
2622
2623 #endif