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