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