2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
8 * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net)
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/socket.h>
14 #include <linux/kernel.h>
15 #include <linux/timer.h>
16 #include <linux/string.h>
17 #include <linux/sockios.h>
18 #include <linux/net.h>
20 #include <linux/inet.h>
21 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/skbuff.h>
26 #include <net/tcp_states.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
29 #include <linux/fcntl.h>
30 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
32 #include <linux/interrupt.h>
33 #include <linux/notifier.h>
34 #include <linux/netfilter.h>
35 #include <linux/init.h>
37 #include <linux/seq_file.h>
39 static unsigned int rose_neigh_no
= 1;
41 static struct rose_node
*rose_node_list
;
42 static DEFINE_SPINLOCK(rose_node_list_lock
);
43 static struct rose_neigh
*rose_neigh_list
;
44 static DEFINE_SPINLOCK(rose_neigh_list_lock
);
45 static struct rose_route
*rose_route_list
;
46 static DEFINE_SPINLOCK(rose_route_list_lock
);
48 struct rose_neigh
*rose_loopback_neigh
;
51 * Add a new route to a node, and in the process add the node and the
52 * neighbour if it is new.
54 static int __must_check
rose_add_node(struct rose_route_struct
*rose_route
,
55 struct net_device
*dev
)
57 struct rose_node
*rose_node
, *rose_tmpn
, *rose_tmpp
;
58 struct rose_neigh
*rose_neigh
;
61 spin_lock_bh(&rose_node_list_lock
);
62 spin_lock_bh(&rose_neigh_list_lock
);
64 rose_node
= rose_node_list
;
65 while (rose_node
!= NULL
) {
66 if ((rose_node
->mask
== rose_route
->mask
) &&
67 (rosecmpm(&rose_route
->address
, &rose_node
->address
,
68 rose_route
->mask
) == 0))
70 rose_node
= rose_node
->next
;
73 if (rose_node
!= NULL
&& rose_node
->loopback
) {
78 rose_neigh
= rose_neigh_list
;
79 while (rose_neigh
!= NULL
) {
80 if (ax25cmp(&rose_route
->neighbour
, &rose_neigh
->callsign
) == 0
81 && rose_neigh
->dev
== dev
)
83 rose_neigh
= rose_neigh
->next
;
86 if (rose_neigh
== NULL
) {
87 rose_neigh
= kmalloc(sizeof(*rose_neigh
), GFP_ATOMIC
);
88 if (rose_neigh
== NULL
) {
93 rose_neigh
->callsign
= rose_route
->neighbour
;
94 rose_neigh
->digipeat
= NULL
;
95 rose_neigh
->ax25
= NULL
;
96 rose_neigh
->dev
= dev
;
97 rose_neigh
->count
= 0;
99 rose_neigh
->dce_mode
= 0;
100 rose_neigh
->loopback
= 0;
101 rose_neigh
->number
= rose_neigh_no
++;
102 rose_neigh
->restarted
= 0;
104 skb_queue_head_init(&rose_neigh
->queue
);
106 init_timer(&rose_neigh
->ftimer
);
107 init_timer(&rose_neigh
->t0timer
);
109 if (rose_route
->ndigis
!= 0) {
110 if ((rose_neigh
->digipeat
= kmalloc(sizeof(ax25_digi
), GFP_KERNEL
)) == NULL
) {
116 rose_neigh
->digipeat
->ndigi
= rose_route
->ndigis
;
117 rose_neigh
->digipeat
->lastrepeat
= -1;
119 for (i
= 0; i
< rose_route
->ndigis
; i
++) {
120 rose_neigh
->digipeat
->calls
[i
] =
121 rose_route
->digipeaters
[i
];
122 rose_neigh
->digipeat
->repeated
[i
] = 0;
126 rose_neigh
->next
= rose_neigh_list
;
127 rose_neigh_list
= rose_neigh
;
131 * This is a new node to be inserted into the list. Find where it needs
132 * to be inserted into the list, and insert it. We want to be sure
133 * to order the list in descending order of mask size to ensure that
134 * later when we are searching this list the first match will be the
137 if (rose_node
== NULL
) {
138 rose_tmpn
= rose_node_list
;
141 while (rose_tmpn
!= NULL
) {
142 if (rose_tmpn
->mask
> rose_route
->mask
) {
143 rose_tmpp
= rose_tmpn
;
144 rose_tmpn
= rose_tmpn
->next
;
150 /* create new node */
151 rose_node
= kmalloc(sizeof(*rose_node
), GFP_ATOMIC
);
152 if (rose_node
== NULL
) {
157 rose_node
->address
= rose_route
->address
;
158 rose_node
->mask
= rose_route
->mask
;
159 rose_node
->count
= 1;
160 rose_node
->loopback
= 0;
161 rose_node
->neighbour
[0] = rose_neigh
;
163 if (rose_tmpn
== NULL
) {
164 if (rose_tmpp
== NULL
) { /* Empty list */
165 rose_node_list
= rose_node
;
166 rose_node
->next
= NULL
;
168 rose_tmpp
->next
= rose_node
;
169 rose_node
->next
= NULL
;
172 if (rose_tmpp
== NULL
) { /* 1st node */
173 rose_node
->next
= rose_node_list
;
174 rose_node_list
= rose_node
;
176 rose_tmpp
->next
= rose_node
;
177 rose_node
->next
= rose_tmpn
;
185 /* We have space, slot it in */
186 if (rose_node
->count
< 3) {
187 rose_node
->neighbour
[rose_node
->count
] = rose_neigh
;
193 spin_unlock_bh(&rose_neigh_list_lock
);
194 spin_unlock_bh(&rose_node_list_lock
);
200 * Caller is holding rose_node_list_lock.
202 static void rose_remove_node(struct rose_node
*rose_node
)
206 if ((s
= rose_node_list
) == rose_node
) {
207 rose_node_list
= rose_node
->next
;
212 while (s
!= NULL
&& s
->next
!= NULL
) {
213 if (s
->next
== rose_node
) {
214 s
->next
= rose_node
->next
;
224 * Caller is holding rose_neigh_list_lock.
226 static void rose_remove_neigh(struct rose_neigh
*rose_neigh
)
228 struct rose_neigh
*s
;
230 rose_stop_ftimer(rose_neigh
);
231 rose_stop_t0timer(rose_neigh
);
233 skb_queue_purge(&rose_neigh
->queue
);
235 if ((s
= rose_neigh_list
) == rose_neigh
) {
236 rose_neigh_list
= rose_neigh
->next
;
237 kfree(rose_neigh
->digipeat
);
242 while (s
!= NULL
&& s
->next
!= NULL
) {
243 if (s
->next
== rose_neigh
) {
244 s
->next
= rose_neigh
->next
;
245 kfree(rose_neigh
->digipeat
);
255 * Caller is holding rose_route_list_lock.
257 static void rose_remove_route(struct rose_route
*rose_route
)
259 struct rose_route
*s
;
261 if (rose_route
->neigh1
!= NULL
)
262 rose_route
->neigh1
->use
--;
264 if (rose_route
->neigh2
!= NULL
)
265 rose_route
->neigh2
->use
--;
267 if ((s
= rose_route_list
) == rose_route
) {
268 rose_route_list
= rose_route
->next
;
273 while (s
!= NULL
&& s
->next
!= NULL
) {
274 if (s
->next
== rose_route
) {
275 s
->next
= rose_route
->next
;
285 * "Delete" a node. Strictly speaking remove a route to a node. The node
286 * is only deleted if no routes are left to it.
288 static int rose_del_node(struct rose_route_struct
*rose_route
,
289 struct net_device
*dev
)
291 struct rose_node
*rose_node
;
292 struct rose_neigh
*rose_neigh
;
295 spin_lock_bh(&rose_node_list_lock
);
296 spin_lock_bh(&rose_neigh_list_lock
);
298 rose_node
= rose_node_list
;
299 while (rose_node
!= NULL
) {
300 if ((rose_node
->mask
== rose_route
->mask
) &&
301 (rosecmpm(&rose_route
->address
, &rose_node
->address
,
302 rose_route
->mask
) == 0))
304 rose_node
= rose_node
->next
;
307 if (rose_node
== NULL
|| rose_node
->loopback
) {
312 rose_neigh
= rose_neigh_list
;
313 while (rose_neigh
!= NULL
) {
314 if (ax25cmp(&rose_route
->neighbour
, &rose_neigh
->callsign
) == 0
315 && rose_neigh
->dev
== dev
)
317 rose_neigh
= rose_neigh
->next
;
320 if (rose_neigh
== NULL
) {
325 for (i
= 0; i
< rose_node
->count
; i
++) {
326 if (rose_node
->neighbour
[i
] == rose_neigh
) {
329 if (rose_neigh
->count
== 0 && rose_neigh
->use
== 0)
330 rose_remove_neigh(rose_neigh
);
334 if (rose_node
->count
== 0) {
335 rose_remove_node(rose_node
);
339 rose_node
->neighbour
[0] =
340 rose_node
->neighbour
[1];
342 rose_node
->neighbour
[1] =
343 rose_node
->neighbour
[2];
354 spin_unlock_bh(&rose_neigh_list_lock
);
355 spin_unlock_bh(&rose_node_list_lock
);
361 * Add the loopback neighbour.
363 void rose_add_loopback_neigh(void)
365 struct rose_neigh
*sn
;
367 rose_loopback_neigh
= kmalloc(sizeof(struct rose_neigh
), GFP_KERNEL
);
368 if (!rose_loopback_neigh
)
370 sn
= rose_loopback_neigh
;
372 sn
->callsign
= null_ax25_address
;
380 sn
->number
= rose_neigh_no
++;
383 skb_queue_head_init(&sn
->queue
);
385 init_timer(&sn
->ftimer
);
386 init_timer(&sn
->t0timer
);
388 spin_lock_bh(&rose_neigh_list_lock
);
389 sn
->next
= rose_neigh_list
;
390 rose_neigh_list
= sn
;
391 spin_unlock_bh(&rose_neigh_list_lock
);
395 * Add a loopback node.
397 int rose_add_loopback_node(rose_address
*address
)
399 struct rose_node
*rose_node
;
402 spin_lock_bh(&rose_node_list_lock
);
404 rose_node
= rose_node_list
;
405 while (rose_node
!= NULL
) {
406 if ((rose_node
->mask
== 10) &&
407 (rosecmpm(address
, &rose_node
->address
, 10) == 0) &&
410 rose_node
= rose_node
->next
;
413 if (rose_node
!= NULL
)
416 if ((rose_node
= kmalloc(sizeof(*rose_node
), GFP_ATOMIC
)) == NULL
) {
421 rose_node
->address
= *address
;
422 rose_node
->mask
= 10;
423 rose_node
->count
= 1;
424 rose_node
->loopback
= 1;
425 rose_node
->neighbour
[0] = rose_loopback_neigh
;
427 /* Insert at the head of list. Address is always mask=10 */
428 rose_node
->next
= rose_node_list
;
429 rose_node_list
= rose_node
;
431 rose_loopback_neigh
->count
++;
434 spin_unlock_bh(&rose_node_list_lock
);
440 * Delete a loopback node.
442 void rose_del_loopback_node(rose_address
*address
)
444 struct rose_node
*rose_node
;
446 spin_lock_bh(&rose_node_list_lock
);
448 rose_node
= rose_node_list
;
449 while (rose_node
!= NULL
) {
450 if ((rose_node
->mask
== 10) &&
451 (rosecmpm(address
, &rose_node
->address
, 10) == 0) &&
454 rose_node
= rose_node
->next
;
457 if (rose_node
== NULL
)
460 rose_remove_node(rose_node
);
462 rose_loopback_neigh
->count
--;
465 spin_unlock_bh(&rose_node_list_lock
);
469 * A device has been removed. Remove its routes and neighbours.
471 void rose_rt_device_down(struct net_device
*dev
)
473 struct rose_neigh
*s
, *rose_neigh
;
474 struct rose_node
*t
, *rose_node
;
477 spin_lock_bh(&rose_node_list_lock
);
478 spin_lock_bh(&rose_neigh_list_lock
);
479 rose_neigh
= rose_neigh_list
;
480 while (rose_neigh
!= NULL
) {
482 rose_neigh
= rose_neigh
->next
;
487 rose_node
= rose_node_list
;
489 while (rose_node
!= NULL
) {
491 rose_node
= rose_node
->next
;
493 for (i
= 0; i
< t
->count
; i
++) {
494 if (t
->neighbour
[i
] != s
)
501 t
->neighbour
[0] = t
->neighbour
[1];
503 t
->neighbour
[1] = t
->neighbour
[2];
513 rose_remove_neigh(s
);
515 spin_unlock_bh(&rose_neigh_list_lock
);
516 spin_unlock_bh(&rose_node_list_lock
);
519 #if 0 /* Currently unused */
521 * A device has been removed. Remove its links.
523 void rose_route_device_down(struct net_device
*dev
)
525 struct rose_route
*s
, *rose_route
;
527 spin_lock_bh(&rose_route_list_lock
);
528 rose_route
= rose_route_list
;
529 while (rose_route
!= NULL
) {
531 rose_route
= rose_route
->next
;
533 if (s
->neigh1
->dev
== dev
|| s
->neigh2
->dev
== dev
)
534 rose_remove_route(s
);
536 spin_unlock_bh(&rose_route_list_lock
);
541 * Clear all nodes and neighbours out, except for neighbours with
542 * active connections going through them.
543 * Do not clear loopback neighbour and nodes.
545 static int rose_clear_routes(void)
547 struct rose_neigh
*s
, *rose_neigh
;
548 struct rose_node
*t
, *rose_node
;
550 spin_lock_bh(&rose_node_list_lock
);
551 spin_lock_bh(&rose_neigh_list_lock
);
553 rose_neigh
= rose_neigh_list
;
554 rose_node
= rose_node_list
;
556 while (rose_node
!= NULL
) {
558 rose_node
= rose_node
->next
;
563 while (rose_neigh
!= NULL
) {
565 rose_neigh
= rose_neigh
->next
;
567 if (s
->use
== 0 && !s
->loopback
) {
569 rose_remove_neigh(s
);
573 spin_unlock_bh(&rose_neigh_list_lock
);
574 spin_unlock_bh(&rose_node_list_lock
);
580 * Check that the device given is a valid AX.25 interface that is "up".
583 static struct net_device
*rose_ax25_dev_find(char *devname
)
585 struct net_device
*dev
;
587 if ((dev
= __dev_get_by_name(&init_net
, devname
)) == NULL
)
590 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_AX25
)
597 * Find the first active ROSE device, usually "rose0".
599 struct net_device
*rose_dev_first(void)
601 struct net_device
*dev
, *first
= NULL
;
603 read_lock(&dev_base_lock
);
604 for_each_netdev(&init_net
, dev
) {
605 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
)
606 if (first
== NULL
|| strncmp(dev
->name
, first
->name
, 3) < 0)
609 read_unlock(&dev_base_lock
);
615 * Find the ROSE device for the given address.
617 struct net_device
*rose_dev_get(rose_address
*addr
)
619 struct net_device
*dev
;
621 read_lock(&dev_base_lock
);
622 for_each_netdev(&init_net
, dev
) {
623 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0) {
630 read_unlock(&dev_base_lock
);
634 static int rose_dev_exists(rose_address
*addr
)
636 struct net_device
*dev
;
638 read_lock(&dev_base_lock
);
639 for_each_netdev(&init_net
, dev
) {
640 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0)
645 read_unlock(&dev_base_lock
);
652 struct rose_route
*rose_route_free_lci(unsigned int lci
, struct rose_neigh
*neigh
)
654 struct rose_route
*rose_route
;
656 for (rose_route
= rose_route_list
; rose_route
!= NULL
; rose_route
= rose_route
->next
)
657 if ((rose_route
->neigh1
== neigh
&& rose_route
->lci1
== lci
) ||
658 (rose_route
->neigh2
== neigh
&& rose_route
->lci2
== lci
))
665 * Find a neighbour or a route given a ROSE address.
667 struct rose_neigh
*rose_get_neigh(rose_address
*addr
, unsigned char *cause
,
668 unsigned char *diagnostic
, int new)
670 struct rose_neigh
*res
= NULL
;
671 struct rose_node
*node
;
675 if (!new) spin_lock_bh(&rose_node_list_lock
);
676 for (node
= rose_node_list
; node
!= NULL
; node
= node
->next
) {
677 if (rosecmpm(addr
, &node
->address
, node
->mask
) == 0) {
678 for (i
= 0; i
< node
->count
; i
++) {
680 if (node
->neighbour
[i
]->restarted
) {
681 res
= node
->neighbour
[i
];
686 if (!rose_ftimer_running(node
->neighbour
[i
])) {
687 res
= node
->neighbour
[i
];
697 *cause
= ROSE_OUT_OF_ORDER
;
700 *cause
= ROSE_NOT_OBTAINABLE
;
705 if (!new) spin_unlock_bh(&rose_node_list_lock
);
711 * Handle the ioctls that control the routing functions.
713 int rose_rt_ioctl(unsigned int cmd
, void __user
*arg
)
715 struct rose_route_struct rose_route
;
716 struct net_device
*dev
;
721 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
723 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
725 if (rose_dev_exists(&rose_route
.address
)) /* Can't add routes to ourself */
727 if (rose_route
.mask
> 10) /* Mask can't be more than 10 digits */
729 if (rose_route
.ndigis
> AX25_MAX_DIGIS
)
731 err
= rose_add_node(&rose_route
, dev
);
735 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
737 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
739 err
= rose_del_node(&rose_route
, dev
);
743 return rose_clear_routes();
752 static void rose_del_route_by_neigh(struct rose_neigh
*rose_neigh
)
754 struct rose_route
*rose_route
, *s
;
756 rose_neigh
->restarted
= 0;
758 rose_stop_t0timer(rose_neigh
);
759 rose_start_ftimer(rose_neigh
);
761 skb_queue_purge(&rose_neigh
->queue
);
763 spin_lock_bh(&rose_route_list_lock
);
765 rose_route
= rose_route_list
;
767 while (rose_route
!= NULL
) {
768 if ((rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== rose_neigh
) ||
769 (rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== NULL
) ||
770 (rose_route
->neigh2
== rose_neigh
&& rose_route
->neigh1
== NULL
)) {
771 s
= rose_route
->next
;
772 rose_remove_route(rose_route
);
777 if (rose_route
->neigh1
== rose_neigh
) {
778 rose_route
->neigh1
->use
--;
779 rose_route
->neigh1
= NULL
;
780 rose_transmit_clear_request(rose_route
->neigh2
, rose_route
->lci2
, ROSE_OUT_OF_ORDER
, 0);
783 if (rose_route
->neigh2
== rose_neigh
) {
784 rose_route
->neigh2
->use
--;
785 rose_route
->neigh2
= NULL
;
786 rose_transmit_clear_request(rose_route
->neigh1
, rose_route
->lci1
, ROSE_OUT_OF_ORDER
, 0);
789 rose_route
= rose_route
->next
;
791 spin_unlock_bh(&rose_route_list_lock
);
795 * A level 2 link has timed out, therefore it appears to be a poor link,
796 * then don't use that neighbour until it is reset. Blow away all through
797 * routes and connections using this route.
799 void rose_link_failed(ax25_cb
*ax25
, int reason
)
801 struct rose_neigh
*rose_neigh
;
803 spin_lock_bh(&rose_neigh_list_lock
);
804 rose_neigh
= rose_neigh_list
;
805 while (rose_neigh
!= NULL
) {
806 if (rose_neigh
->ax25
== ax25
)
808 rose_neigh
= rose_neigh
->next
;
811 if (rose_neigh
!= NULL
) {
812 rose_neigh
->ax25
= NULL
;
814 rose_del_route_by_neigh(rose_neigh
);
815 rose_kill_by_neigh(rose_neigh
);
817 spin_unlock_bh(&rose_neigh_list_lock
);
821 * A device has been "downed" remove its link status. Blow away all
822 * through routes and connections that use this device.
824 void rose_link_device_down(struct net_device
*dev
)
826 struct rose_neigh
*rose_neigh
;
828 for (rose_neigh
= rose_neigh_list
; rose_neigh
!= NULL
; rose_neigh
= rose_neigh
->next
) {
829 if (rose_neigh
->dev
== dev
) {
830 rose_del_route_by_neigh(rose_neigh
);
831 rose_kill_by_neigh(rose_neigh
);
837 * Route a frame to an appropriate AX.25 connection.
839 int rose_route_frame(struct sk_buff
*skb
, ax25_cb
*ax25
)
841 struct rose_neigh
*rose_neigh
, *new_neigh
;
842 struct rose_route
*rose_route
;
843 struct rose_facilities_struct facilities
;
844 rose_address
*src_addr
, *dest_addr
;
846 unsigned short frametype
;
847 unsigned int lci
, new_lci
;
848 unsigned char cause
, diagnostic
;
849 struct net_device
*dev
;
854 if (call_in_firewall(PF_ROSE
, skb
->dev
, skb
->data
, NULL
, &skb
) != FW_ACCEPT
)
858 frametype
= skb
->data
[2];
859 lci
= ((skb
->data
[0] << 8) & 0xF00) + ((skb
->data
[1] << 0) & 0x0FF);
860 src_addr
= (rose_address
*)(skb
->data
+ 9);
861 dest_addr
= (rose_address
*)(skb
->data
+ 4);
863 spin_lock_bh(&rose_neigh_list_lock
);
864 spin_lock_bh(&rose_route_list_lock
);
866 rose_neigh
= rose_neigh_list
;
867 while (rose_neigh
!= NULL
) {
868 if (ax25cmp(&ax25
->dest_addr
, &rose_neigh
->callsign
) == 0 &&
869 ax25
->ax25_dev
->dev
== rose_neigh
->dev
)
871 rose_neigh
= rose_neigh
->next
;
874 if (rose_neigh
== NULL
) {
875 printk("rose_route : unknown neighbour or device %s\n",
876 ax2asc(buf
, &ax25
->dest_addr
));
881 * Obviously the link is working, halt the ftimer.
883 rose_stop_ftimer(rose_neigh
);
886 * LCI of zero is always for us, and its always a restart
890 rose_link_rx_restart(skb
, rose_neigh
, frametype
);
895 * Find an existing socket.
897 if ((sk
= rose_find_socket(lci
, rose_neigh
)) != NULL
) {
898 if (frametype
== ROSE_CALL_REQUEST
) {
899 struct rose_sock
*rose
= rose_sk(sk
);
901 /* Remove an existing unused socket */
902 rose_clear_queues(sk
);
903 rose
->cause
= ROSE_NETWORK_CONGESTION
;
904 rose
->diagnostic
= 0;
905 rose
->neighbour
->use
--;
906 rose
->neighbour
= NULL
;
908 rose
->state
= ROSE_STATE_0
;
909 sk
->sk_state
= TCP_CLOSE
;
911 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
912 if (!sock_flag(sk
, SOCK_DEAD
)) {
913 sk
->sk_state_change(sk
);
914 sock_set_flag(sk
, SOCK_DEAD
);
918 skb_reset_transport_header(skb
);
919 res
= rose_process_rx_frame(sk
, skb
);
925 * Is is a Call Request and is it for us ?
927 if (frametype
== ROSE_CALL_REQUEST
)
928 if ((dev
= rose_dev_get(dest_addr
)) != NULL
) {
929 res
= rose_rx_call_request(skb
, dev
, rose_neigh
, lci
);
934 if (!sysctl_rose_routing_control
) {
935 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 0);
940 * Route it to the next in line if we have an entry for it.
942 rose_route
= rose_route_list
;
943 while (rose_route
!= NULL
) {
944 if (rose_route
->lci1
== lci
&&
945 rose_route
->neigh1
== rose_neigh
) {
946 if (frametype
== ROSE_CALL_REQUEST
) {
947 /* F6FBB - Remove an existing unused route */
948 rose_remove_route(rose_route
);
950 } else if (rose_route
->neigh2
!= NULL
) {
951 skb
->data
[0] &= 0xF0;
952 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
953 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
954 rose_transmit_link(skb
, rose_route
->neigh2
);
955 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
956 rose_remove_route(rose_route
);
960 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
961 rose_remove_route(rose_route
);
965 if (rose_route
->lci2
== lci
&&
966 rose_route
->neigh2
== rose_neigh
) {
967 if (frametype
== ROSE_CALL_REQUEST
) {
968 /* F6FBB - Remove an existing unused route */
969 rose_remove_route(rose_route
);
971 } else if (rose_route
->neigh1
!= NULL
) {
972 skb
->data
[0] &= 0xF0;
973 skb
->data
[0] |= (rose_route
->lci1
>> 8) & 0x0F;
974 skb
->data
[1] = (rose_route
->lci1
>> 0) & 0xFF;
975 rose_transmit_link(skb
, rose_route
->neigh1
);
976 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
977 rose_remove_route(rose_route
);
981 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
982 rose_remove_route(rose_route
);
986 rose_route
= rose_route
->next
;
991 * 1. The frame isn't for us,
992 * 2. It isn't "owned" by any existing route.
994 if (frametype
!= ROSE_CALL_REQUEST
) { /* XXX */
999 len
= (((skb
->data
[3] >> 4) & 0x0F) + 1) >> 1;
1000 len
+= (((skb
->data
[3] >> 0) & 0x0F) + 1) >> 1;
1002 memset(&facilities
, 0x00, sizeof(struct rose_facilities_struct
));
1004 if (!rose_parse_facilities(skb
->data
+ len
+ 4, &facilities
)) {
1005 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_INVALID_FACILITY
, 76);
1010 * Check for routing loops.
1012 rose_route
= rose_route_list
;
1013 while (rose_route
!= NULL
) {
1014 if (rose_route
->rand
== facilities
.rand
&&
1015 rosecmp(src_addr
, &rose_route
->src_addr
) == 0 &&
1016 ax25cmp(&facilities
.dest_call
, &rose_route
->src_call
) == 0 &&
1017 ax25cmp(&facilities
.source_call
, &rose_route
->dest_call
) == 0) {
1018 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 120);
1021 rose_route
= rose_route
->next
;
1024 if ((new_neigh
= rose_get_neigh(dest_addr
, &cause
, &diagnostic
, 1)) == NULL
) {
1025 rose_transmit_clear_request(rose_neigh
, lci
, cause
, diagnostic
);
1029 if ((new_lci
= rose_new_lci(new_neigh
)) == 0) {
1030 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 71);
1034 if ((rose_route
= kmalloc(sizeof(*rose_route
), GFP_ATOMIC
)) == NULL
) {
1035 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 120);
1039 rose_route
->lci1
= lci
;
1040 rose_route
->src_addr
= *src_addr
;
1041 rose_route
->dest_addr
= *dest_addr
;
1042 rose_route
->src_call
= facilities
.dest_call
;
1043 rose_route
->dest_call
= facilities
.source_call
;
1044 rose_route
->rand
= facilities
.rand
;
1045 rose_route
->neigh1
= rose_neigh
;
1046 rose_route
->lci2
= new_lci
;
1047 rose_route
->neigh2
= new_neigh
;
1049 rose_route
->neigh1
->use
++;
1050 rose_route
->neigh2
->use
++;
1052 rose_route
->next
= rose_route_list
;
1053 rose_route_list
= rose_route
;
1055 skb
->data
[0] &= 0xF0;
1056 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
1057 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
1059 rose_transmit_link(skb
, rose_route
->neigh2
);
1063 spin_unlock_bh(&rose_route_list_lock
);
1064 spin_unlock_bh(&rose_neigh_list_lock
);
1069 #ifdef CONFIG_PROC_FS
1071 static void *rose_node_start(struct seq_file
*seq
, loff_t
*pos
)
1072 __acquires(rose_node_list_lock
)
1074 struct rose_node
*rose_node
;
1077 spin_lock_bh(&rose_node_list_lock
);
1079 return SEQ_START_TOKEN
;
1081 for (rose_node
= rose_node_list
; rose_node
&& i
< *pos
;
1082 rose_node
= rose_node
->next
, ++i
);
1084 return (i
== *pos
) ? rose_node
: NULL
;
1087 static void *rose_node_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1091 return (v
== SEQ_START_TOKEN
) ? rose_node_list
1092 : ((struct rose_node
*)v
)->next
;
1095 static void rose_node_stop(struct seq_file
*seq
, void *v
)
1096 __releases(rose_node_list_lock
)
1098 spin_unlock_bh(&rose_node_list_lock
);
1101 static int rose_node_show(struct seq_file
*seq
, void *v
)
1106 if (v
== SEQ_START_TOKEN
)
1107 seq_puts(seq
, "address mask n neigh neigh neigh\n");
1109 const struct rose_node
*rose_node
= v
;
1110 /* if (rose_node->loopback) {
1111 seq_printf(seq, "%-10s %04d 1 loopback\n",
1112 rose2asc(rsbuf, &rose_node->address),
1115 seq_printf(seq
, "%-10s %04d %d",
1116 rose2asc(rsbuf
, &rose_node
->address
),
1120 for (i
= 0; i
< rose_node
->count
; i
++)
1121 seq_printf(seq
, " %05d",
1122 rose_node
->neighbour
[i
]->number
);
1124 seq_puts(seq
, "\n");
1130 static const struct seq_operations rose_node_seqops
= {
1131 .start
= rose_node_start
,
1132 .next
= rose_node_next
,
1133 .stop
= rose_node_stop
,
1134 .show
= rose_node_show
,
1137 static int rose_nodes_open(struct inode
*inode
, struct file
*file
)
1139 return seq_open(file
, &rose_node_seqops
);
1142 const struct file_operations rose_nodes_fops
= {
1143 .owner
= THIS_MODULE
,
1144 .open
= rose_nodes_open
,
1146 .llseek
= seq_lseek
,
1147 .release
= seq_release
,
1150 static void *rose_neigh_start(struct seq_file
*seq
, loff_t
*pos
)
1151 __acquires(rose_neigh_list_lock
)
1153 struct rose_neigh
*rose_neigh
;
1156 spin_lock_bh(&rose_neigh_list_lock
);
1158 return SEQ_START_TOKEN
;
1160 for (rose_neigh
= rose_neigh_list
; rose_neigh
&& i
< *pos
;
1161 rose_neigh
= rose_neigh
->next
, ++i
);
1163 return (i
== *pos
) ? rose_neigh
: NULL
;
1166 static void *rose_neigh_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1170 return (v
== SEQ_START_TOKEN
) ? rose_neigh_list
1171 : ((struct rose_neigh
*)v
)->next
;
1174 static void rose_neigh_stop(struct seq_file
*seq
, void *v
)
1175 __releases(rose_neigh_list_lock
)
1177 spin_unlock_bh(&rose_neigh_list_lock
);
1180 static int rose_neigh_show(struct seq_file
*seq
, void *v
)
1185 if (v
== SEQ_START_TOKEN
)
1187 "addr callsign dev count use mode restart t0 tf digipeaters\n");
1189 struct rose_neigh
*rose_neigh
= v
;
1191 /* if (!rose_neigh->loopback) { */
1192 seq_printf(seq
, "%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu",
1194 (rose_neigh
->loopback
) ? "RSLOOP-0" : ax2asc(buf
, &rose_neigh
->callsign
),
1195 rose_neigh
->dev
? rose_neigh
->dev
->name
: "???",
1198 (rose_neigh
->dce_mode
) ? "DCE" : "DTE",
1199 (rose_neigh
->restarted
) ? "yes" : "no",
1200 ax25_display_timer(&rose_neigh
->t0timer
) / HZ
,
1201 ax25_display_timer(&rose_neigh
->ftimer
) / HZ
);
1203 if (rose_neigh
->digipeat
!= NULL
) {
1204 for (i
= 0; i
< rose_neigh
->digipeat
->ndigi
; i
++)
1205 seq_printf(seq
, " %s", ax2asc(buf
, &rose_neigh
->digipeat
->calls
[i
]));
1208 seq_puts(seq
, "\n");
1214 static const struct seq_operations rose_neigh_seqops
= {
1215 .start
= rose_neigh_start
,
1216 .next
= rose_neigh_next
,
1217 .stop
= rose_neigh_stop
,
1218 .show
= rose_neigh_show
,
1221 static int rose_neigh_open(struct inode
*inode
, struct file
*file
)
1223 return seq_open(file
, &rose_neigh_seqops
);
1226 const struct file_operations rose_neigh_fops
= {
1227 .owner
= THIS_MODULE
,
1228 .open
= rose_neigh_open
,
1230 .llseek
= seq_lseek
,
1231 .release
= seq_release
,
1235 static void *rose_route_start(struct seq_file
*seq
, loff_t
*pos
)
1236 __acquires(rose_route_list_lock
)
1238 struct rose_route
*rose_route
;
1241 spin_lock_bh(&rose_route_list_lock
);
1243 return SEQ_START_TOKEN
;
1245 for (rose_route
= rose_route_list
; rose_route
&& i
< *pos
;
1246 rose_route
= rose_route
->next
, ++i
);
1248 return (i
== *pos
) ? rose_route
: NULL
;
1251 static void *rose_route_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1255 return (v
== SEQ_START_TOKEN
) ? rose_route_list
1256 : ((struct rose_route
*)v
)->next
;
1259 static void rose_route_stop(struct seq_file
*seq
, void *v
)
1260 __releases(rose_route_list_lock
)
1262 spin_unlock_bh(&rose_route_list_lock
);
1265 static int rose_route_show(struct seq_file
*seq
, void *v
)
1267 char buf
[11], rsbuf
[11];
1269 if (v
== SEQ_START_TOKEN
)
1271 "lci address callsign neigh <-> lci address callsign neigh\n");
1273 struct rose_route
*rose_route
= v
;
1275 if (rose_route
->neigh1
)
1277 "%3.3X %-10s %-9s %05d ",
1279 rose2asc(rsbuf
, &rose_route
->src_addr
),
1280 ax2asc(buf
, &rose_route
->src_call
),
1281 rose_route
->neigh1
->number
);
1286 if (rose_route
->neigh2
)
1288 "%3.3X %-10s %-9s %05d\n",
1290 rose2asc(rsbuf
, &rose_route
->dest_addr
),
1291 ax2asc(buf
, &rose_route
->dest_call
),
1292 rose_route
->neigh2
->number
);
1300 static const struct seq_operations rose_route_seqops
= {
1301 .start
= rose_route_start
,
1302 .next
= rose_route_next
,
1303 .stop
= rose_route_stop
,
1304 .show
= rose_route_show
,
1307 static int rose_route_open(struct inode
*inode
, struct file
*file
)
1309 return seq_open(file
, &rose_route_seqops
);
1312 const struct file_operations rose_routes_fops
= {
1313 .owner
= THIS_MODULE
,
1314 .open
= rose_route_open
,
1316 .llseek
= seq_lseek
,
1317 .release
= seq_release
,
1320 #endif /* CONFIG_PROC_FS */
1323 * Release all memory associated with ROSE routing structures.
1325 void __exit
rose_rt_free(void)
1327 struct rose_neigh
*s
, *rose_neigh
= rose_neigh_list
;
1328 struct rose_node
*t
, *rose_node
= rose_node_list
;
1329 struct rose_route
*u
, *rose_route
= rose_route_list
;
1331 while (rose_neigh
!= NULL
) {
1333 rose_neigh
= rose_neigh
->next
;
1335 rose_remove_neigh(s
);
1338 while (rose_node
!= NULL
) {
1340 rose_node
= rose_node
->next
;
1342 rose_remove_node(t
);
1345 while (rose_route
!= NULL
) {
1347 rose_route
= rose_route
->next
;
1349 rose_remove_route(u
);