1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
5 * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net)
7 #include <linux/errno.h>
8 #include <linux/types.h>
9 #include <linux/socket.h>
11 #include <linux/kernel.h>
12 #include <linux/timer.h>
13 #include <linux/string.h>
14 #include <linux/sockios.h>
15 #include <linux/net.h>
16 #include <linux/slab.h>
18 #include <linux/inet.h>
19 #include <linux/netdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/skbuff.h>
24 #include <net/tcp_states.h>
25 #include <linux/uaccess.h>
26 #include <linux/fcntl.h>
27 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
29 #include <linux/interrupt.h>
30 #include <linux/notifier.h>
31 #include <linux/init.h>
33 #include <linux/seq_file.h>
34 #include <linux/export.h>
36 static unsigned int rose_neigh_no
= 1;
38 static struct rose_node
*rose_node_list
;
39 static DEFINE_SPINLOCK(rose_node_list_lock
);
40 static struct rose_neigh
*rose_neigh_list
;
41 static DEFINE_SPINLOCK(rose_neigh_list_lock
);
42 static struct rose_route
*rose_route_list
;
43 static DEFINE_SPINLOCK(rose_route_list_lock
);
45 struct rose_neigh
*rose_loopback_neigh
;
48 * Add a new route to a node, and in the process add the node and the
49 * neighbour if it is new.
51 static int __must_check
rose_add_node(struct rose_route_struct
*rose_route
,
52 struct net_device
*dev
)
54 struct rose_node
*rose_node
, *rose_tmpn
, *rose_tmpp
;
55 struct rose_neigh
*rose_neigh
;
58 spin_lock_bh(&rose_node_list_lock
);
59 spin_lock_bh(&rose_neigh_list_lock
);
61 rose_node
= rose_node_list
;
62 while (rose_node
!= NULL
) {
63 if ((rose_node
->mask
== rose_route
->mask
) &&
64 (rosecmpm(&rose_route
->address
, &rose_node
->address
,
65 rose_route
->mask
) == 0))
67 rose_node
= rose_node
->next
;
70 if (rose_node
!= NULL
&& rose_node
->loopback
) {
75 rose_neigh
= rose_neigh_list
;
76 while (rose_neigh
!= NULL
) {
77 if (ax25cmp(&rose_route
->neighbour
,
78 &rose_neigh
->callsign
) == 0 &&
79 rose_neigh
->dev
== dev
)
81 rose_neigh
= rose_neigh
->next
;
84 if (rose_neigh
== NULL
) {
85 rose_neigh
= kmalloc(sizeof(*rose_neigh
), GFP_ATOMIC
);
86 if (rose_neigh
== NULL
) {
91 rose_neigh
->callsign
= rose_route
->neighbour
;
92 rose_neigh
->digipeat
= NULL
;
93 rose_neigh
->ax25
= NULL
;
94 rose_neigh
->dev
= dev
;
95 rose_neigh
->count
= 0;
97 rose_neigh
->dce_mode
= 0;
98 rose_neigh
->loopback
= 0;
99 rose_neigh
->number
= rose_neigh_no
++;
100 rose_neigh
->restarted
= 0;
102 skb_queue_head_init(&rose_neigh
->queue
);
104 timer_setup(&rose_neigh
->ftimer
, NULL
, 0);
105 timer_setup(&rose_neigh
->t0timer
, NULL
, 0);
107 if (rose_route
->ndigis
!= 0) {
108 rose_neigh
->digipeat
=
109 kmalloc(sizeof(ax25_digi
), GFP_ATOMIC
);
110 if (rose_neigh
->digipeat
== 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 if (rose_neigh
->ax25
)
238 ax25_cb_put(rose_neigh
->ax25
);
239 kfree(rose_neigh
->digipeat
);
244 while (s
!= NULL
&& s
->next
!= NULL
) {
245 if (s
->next
== rose_neigh
) {
246 s
->next
= rose_neigh
->next
;
247 if (rose_neigh
->ax25
)
248 ax25_cb_put(rose_neigh
->ax25
);
249 kfree(rose_neigh
->digipeat
);
259 * Caller is holding rose_route_list_lock.
261 static void rose_remove_route(struct rose_route
*rose_route
)
263 struct rose_route
*s
;
265 if (rose_route
->neigh1
!= NULL
)
266 rose_route
->neigh1
->use
--;
268 if (rose_route
->neigh2
!= NULL
)
269 rose_route
->neigh2
->use
--;
271 if ((s
= rose_route_list
) == rose_route
) {
272 rose_route_list
= rose_route
->next
;
277 while (s
!= NULL
&& s
->next
!= NULL
) {
278 if (s
->next
== rose_route
) {
279 s
->next
= rose_route
->next
;
289 * "Delete" a node. Strictly speaking remove a route to a node. The node
290 * is only deleted if no routes are left to it.
292 static int rose_del_node(struct rose_route_struct
*rose_route
,
293 struct net_device
*dev
)
295 struct rose_node
*rose_node
;
296 struct rose_neigh
*rose_neigh
;
299 spin_lock_bh(&rose_node_list_lock
);
300 spin_lock_bh(&rose_neigh_list_lock
);
302 rose_node
= rose_node_list
;
303 while (rose_node
!= NULL
) {
304 if ((rose_node
->mask
== rose_route
->mask
) &&
305 (rosecmpm(&rose_route
->address
, &rose_node
->address
,
306 rose_route
->mask
) == 0))
308 rose_node
= rose_node
->next
;
311 if (rose_node
== NULL
|| rose_node
->loopback
) {
316 rose_neigh
= rose_neigh_list
;
317 while (rose_neigh
!= NULL
) {
318 if (ax25cmp(&rose_route
->neighbour
,
319 &rose_neigh
->callsign
) == 0 &&
320 rose_neigh
->dev
== dev
)
322 rose_neigh
= rose_neigh
->next
;
325 if (rose_neigh
== NULL
) {
330 for (i
= 0; i
< rose_node
->count
; i
++) {
331 if (rose_node
->neighbour
[i
] == rose_neigh
) {
334 if (rose_neigh
->count
== 0 && rose_neigh
->use
== 0)
335 rose_remove_neigh(rose_neigh
);
339 if (rose_node
->count
== 0) {
340 rose_remove_node(rose_node
);
344 rose_node
->neighbour
[0] =
345 rose_node
->neighbour
[1];
348 rose_node
->neighbour
[1] =
349 rose_node
->neighbour
[2];
360 spin_unlock_bh(&rose_neigh_list_lock
);
361 spin_unlock_bh(&rose_node_list_lock
);
367 * Add the loopback neighbour.
369 void rose_add_loopback_neigh(void)
371 struct rose_neigh
*sn
;
373 rose_loopback_neigh
= kmalloc(sizeof(struct rose_neigh
), GFP_KERNEL
);
374 if (!rose_loopback_neigh
)
376 sn
= rose_loopback_neigh
;
378 sn
->callsign
= null_ax25_address
;
386 sn
->number
= rose_neigh_no
++;
389 skb_queue_head_init(&sn
->queue
);
391 timer_setup(&sn
->ftimer
, NULL
, 0);
392 timer_setup(&sn
->t0timer
, NULL
, 0);
394 spin_lock_bh(&rose_neigh_list_lock
);
395 sn
->next
= rose_neigh_list
;
396 rose_neigh_list
= sn
;
397 spin_unlock_bh(&rose_neigh_list_lock
);
401 * Add a loopback node.
403 int rose_add_loopback_node(rose_address
*address
)
405 struct rose_node
*rose_node
;
408 spin_lock_bh(&rose_node_list_lock
);
410 rose_node
= rose_node_list
;
411 while (rose_node
!= NULL
) {
412 if ((rose_node
->mask
== 10) &&
413 (rosecmpm(address
, &rose_node
->address
, 10) == 0) &&
416 rose_node
= rose_node
->next
;
419 if (rose_node
!= NULL
)
422 if ((rose_node
= kmalloc(sizeof(*rose_node
), GFP_ATOMIC
)) == NULL
) {
427 rose_node
->address
= *address
;
428 rose_node
->mask
= 10;
429 rose_node
->count
= 1;
430 rose_node
->loopback
= 1;
431 rose_node
->neighbour
[0] = rose_loopback_neigh
;
433 /* Insert at the head of list. Address is always mask=10 */
434 rose_node
->next
= rose_node_list
;
435 rose_node_list
= rose_node
;
437 rose_loopback_neigh
->count
++;
440 spin_unlock_bh(&rose_node_list_lock
);
446 * Delete a loopback node.
448 void rose_del_loopback_node(rose_address
*address
)
450 struct rose_node
*rose_node
;
452 spin_lock_bh(&rose_node_list_lock
);
454 rose_node
= rose_node_list
;
455 while (rose_node
!= NULL
) {
456 if ((rose_node
->mask
== 10) &&
457 (rosecmpm(address
, &rose_node
->address
, 10) == 0) &&
460 rose_node
= rose_node
->next
;
463 if (rose_node
== NULL
)
466 rose_remove_node(rose_node
);
468 rose_loopback_neigh
->count
--;
471 spin_unlock_bh(&rose_node_list_lock
);
475 * A device has been removed. Remove its routes and neighbours.
477 void rose_rt_device_down(struct net_device
*dev
)
479 struct rose_neigh
*s
, *rose_neigh
;
480 struct rose_node
*t
, *rose_node
;
483 spin_lock_bh(&rose_node_list_lock
);
484 spin_lock_bh(&rose_neigh_list_lock
);
485 rose_neigh
= rose_neigh_list
;
486 while (rose_neigh
!= NULL
) {
488 rose_neigh
= rose_neigh
->next
;
493 rose_node
= rose_node_list
;
495 while (rose_node
!= NULL
) {
497 rose_node
= rose_node
->next
;
499 for (i
= 0; i
< t
->count
; i
++) {
500 if (t
->neighbour
[i
] != s
)
507 t
->neighbour
[0] = t
->neighbour
[1];
510 t
->neighbour
[1] = t
->neighbour
[2];
520 rose_remove_neigh(s
);
522 spin_unlock_bh(&rose_neigh_list_lock
);
523 spin_unlock_bh(&rose_node_list_lock
);
526 #if 0 /* Currently unused */
528 * A device has been removed. Remove its links.
530 void rose_route_device_down(struct net_device
*dev
)
532 struct rose_route
*s
, *rose_route
;
534 spin_lock_bh(&rose_route_list_lock
);
535 rose_route
= rose_route_list
;
536 while (rose_route
!= NULL
) {
538 rose_route
= rose_route
->next
;
540 if (s
->neigh1
->dev
== dev
|| s
->neigh2
->dev
== dev
)
541 rose_remove_route(s
);
543 spin_unlock_bh(&rose_route_list_lock
);
548 * Clear all nodes and neighbours out, except for neighbours with
549 * active connections going through them.
550 * Do not clear loopback neighbour and nodes.
552 static int rose_clear_routes(void)
554 struct rose_neigh
*s
, *rose_neigh
;
555 struct rose_node
*t
, *rose_node
;
557 spin_lock_bh(&rose_node_list_lock
);
558 spin_lock_bh(&rose_neigh_list_lock
);
560 rose_neigh
= rose_neigh_list
;
561 rose_node
= rose_node_list
;
563 while (rose_node
!= NULL
) {
565 rose_node
= rose_node
->next
;
570 while (rose_neigh
!= NULL
) {
572 rose_neigh
= rose_neigh
->next
;
574 if (s
->use
== 0 && !s
->loopback
) {
576 rose_remove_neigh(s
);
580 spin_unlock_bh(&rose_neigh_list_lock
);
581 spin_unlock_bh(&rose_node_list_lock
);
587 * Check that the device given is a valid AX.25 interface that is "up".
590 static struct net_device
*rose_ax25_dev_find(char *devname
)
592 struct net_device
*dev
;
594 if ((dev
= __dev_get_by_name(&init_net
, devname
)) == NULL
)
597 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_AX25
)
604 * Find the first active ROSE device, usually "rose0".
606 struct net_device
*rose_dev_first(void)
608 struct net_device
*dev
, *first
= NULL
;
611 for_each_netdev_rcu(&init_net
, dev
) {
612 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
)
613 if (first
== NULL
|| strncmp(dev
->name
, first
->name
, 3) < 0)
622 * Find the ROSE device for the given address.
624 struct net_device
*rose_dev_get(rose_address
*addr
)
626 struct net_device
*dev
;
629 for_each_netdev_rcu(&init_net
, dev
) {
630 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0) {
641 static int rose_dev_exists(rose_address
*addr
)
643 struct net_device
*dev
;
646 for_each_netdev_rcu(&init_net
, dev
) {
647 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0)
659 struct rose_route
*rose_route_free_lci(unsigned int lci
, struct rose_neigh
*neigh
)
661 struct rose_route
*rose_route
;
663 for (rose_route
= rose_route_list
; rose_route
!= NULL
; rose_route
= rose_route
->next
)
664 if ((rose_route
->neigh1
== neigh
&& rose_route
->lci1
== lci
) ||
665 (rose_route
->neigh2
== neigh
&& rose_route
->lci2
== lci
))
672 * Find a neighbour or a route given a ROSE address.
674 struct rose_neigh
*rose_get_neigh(rose_address
*addr
, unsigned char *cause
,
675 unsigned char *diagnostic
, int route_frame
)
677 struct rose_neigh
*res
= NULL
;
678 struct rose_node
*node
;
682 if (!route_frame
) spin_lock_bh(&rose_node_list_lock
);
683 for (node
= rose_node_list
; node
!= NULL
; node
= node
->next
) {
684 if (rosecmpm(addr
, &node
->address
, node
->mask
) == 0) {
685 for (i
= 0; i
< node
->count
; i
++) {
686 if (node
->neighbour
[i
]->restarted
) {
687 res
= node
->neighbour
[i
];
693 if (!route_frame
) { /* connect request */
694 for (node
= rose_node_list
; node
!= NULL
; node
= node
->next
) {
695 if (rosecmpm(addr
, &node
->address
, node
->mask
) == 0) {
696 for (i
= 0; i
< node
->count
; i
++) {
697 if (!rose_ftimer_running(node
->neighbour
[i
])) {
698 res
= node
->neighbour
[i
];
708 *cause
= ROSE_OUT_OF_ORDER
;
711 *cause
= ROSE_NOT_OBTAINABLE
;
716 if (!route_frame
) spin_unlock_bh(&rose_node_list_lock
);
721 * Handle the ioctls that control the routing functions.
723 int rose_rt_ioctl(unsigned int cmd
, void __user
*arg
)
725 struct rose_route_struct rose_route
;
726 struct net_device
*dev
;
731 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
733 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
735 if (rose_dev_exists(&rose_route
.address
)) /* Can't add routes to ourself */
737 if (rose_route
.mask
> 10) /* Mask can't be more than 10 digits */
739 if (rose_route
.ndigis
> AX25_MAX_DIGIS
)
741 err
= rose_add_node(&rose_route
, dev
);
745 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
747 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
749 err
= rose_del_node(&rose_route
, dev
);
753 return rose_clear_routes();
762 static void rose_del_route_by_neigh(struct rose_neigh
*rose_neigh
)
764 struct rose_route
*rose_route
, *s
;
766 rose_neigh
->restarted
= 0;
768 rose_stop_t0timer(rose_neigh
);
769 rose_start_ftimer(rose_neigh
);
771 skb_queue_purge(&rose_neigh
->queue
);
773 spin_lock_bh(&rose_route_list_lock
);
775 rose_route
= rose_route_list
;
777 while (rose_route
!= NULL
) {
778 if ((rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== rose_neigh
) ||
779 (rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== NULL
) ||
780 (rose_route
->neigh2
== rose_neigh
&& rose_route
->neigh1
== NULL
)) {
781 s
= rose_route
->next
;
782 rose_remove_route(rose_route
);
787 if (rose_route
->neigh1
== rose_neigh
) {
788 rose_route
->neigh1
->use
--;
789 rose_route
->neigh1
= NULL
;
790 rose_transmit_clear_request(rose_route
->neigh2
, rose_route
->lci2
, ROSE_OUT_OF_ORDER
, 0);
793 if (rose_route
->neigh2
== rose_neigh
) {
794 rose_route
->neigh2
->use
--;
795 rose_route
->neigh2
= NULL
;
796 rose_transmit_clear_request(rose_route
->neigh1
, rose_route
->lci1
, ROSE_OUT_OF_ORDER
, 0);
799 rose_route
= rose_route
->next
;
801 spin_unlock_bh(&rose_route_list_lock
);
805 * A level 2 link has timed out, therefore it appears to be a poor link,
806 * then don't use that neighbour until it is reset. Blow away all through
807 * routes and connections using this route.
809 void rose_link_failed(ax25_cb
*ax25
, int reason
)
811 struct rose_neigh
*rose_neigh
;
813 spin_lock_bh(&rose_neigh_list_lock
);
814 rose_neigh
= rose_neigh_list
;
815 while (rose_neigh
!= NULL
) {
816 if (rose_neigh
->ax25
== ax25
)
818 rose_neigh
= rose_neigh
->next
;
821 if (rose_neigh
!= NULL
) {
822 rose_neigh
->ax25
= NULL
;
825 rose_del_route_by_neigh(rose_neigh
);
826 rose_kill_by_neigh(rose_neigh
);
828 spin_unlock_bh(&rose_neigh_list_lock
);
832 * A device has been "downed" remove its link status. Blow away all
833 * through routes and connections that use this device.
835 void rose_link_device_down(struct net_device
*dev
)
837 struct rose_neigh
*rose_neigh
;
839 for (rose_neigh
= rose_neigh_list
; rose_neigh
!= NULL
; rose_neigh
= rose_neigh
->next
) {
840 if (rose_neigh
->dev
== dev
) {
841 rose_del_route_by_neigh(rose_neigh
);
842 rose_kill_by_neigh(rose_neigh
);
848 * Route a frame to an appropriate AX.25 connection.
849 * A NULL ax25_cb indicates an internally generated frame.
851 int rose_route_frame(struct sk_buff
*skb
, ax25_cb
*ax25
)
853 struct rose_neigh
*rose_neigh
, *new_neigh
;
854 struct rose_route
*rose_route
;
855 struct rose_facilities_struct facilities
;
856 rose_address
*src_addr
, *dest_addr
;
858 unsigned short frametype
;
859 unsigned int lci
, new_lci
;
860 unsigned char cause
, diagnostic
;
861 struct net_device
*dev
;
865 if (skb
->len
< ROSE_MIN_LEN
)
869 return rose_loopback_queue(skb
, NULL
);
871 frametype
= skb
->data
[2];
872 lci
= ((skb
->data
[0] << 8) & 0xF00) + ((skb
->data
[1] << 0) & 0x0FF);
873 if (frametype
== ROSE_CALL_REQUEST
&&
874 (skb
->len
<= ROSE_CALL_REQ_FACILITIES_OFF
||
875 skb
->data
[ROSE_CALL_REQ_ADDR_LEN_OFF
] !=
876 ROSE_CALL_REQ_ADDR_LEN_VAL
))
878 src_addr
= (rose_address
*)(skb
->data
+ ROSE_CALL_REQ_SRC_ADDR_OFF
);
879 dest_addr
= (rose_address
*)(skb
->data
+ ROSE_CALL_REQ_DEST_ADDR_OFF
);
881 spin_lock_bh(&rose_neigh_list_lock
);
882 spin_lock_bh(&rose_route_list_lock
);
884 rose_neigh
= rose_neigh_list
;
885 while (rose_neigh
!= NULL
) {
886 if (ax25cmp(&ax25
->dest_addr
, &rose_neigh
->callsign
) == 0 &&
887 ax25
->ax25_dev
->dev
== rose_neigh
->dev
)
889 rose_neigh
= rose_neigh
->next
;
892 if (rose_neigh
== NULL
) {
893 printk("rose_route : unknown neighbour or device %s\n",
894 ax2asc(buf
, &ax25
->dest_addr
));
899 * Obviously the link is working, halt the ftimer.
901 rose_stop_ftimer(rose_neigh
);
904 * LCI of zero is always for us, and its always a restart
908 rose_link_rx_restart(skb
, rose_neigh
, frametype
);
913 * Find an existing socket.
915 if ((sk
= rose_find_socket(lci
, rose_neigh
)) != NULL
) {
916 if (frametype
== ROSE_CALL_REQUEST
) {
917 struct rose_sock
*rose
= rose_sk(sk
);
919 /* Remove an existing unused socket */
920 rose_clear_queues(sk
);
921 rose
->cause
= ROSE_NETWORK_CONGESTION
;
922 rose
->diagnostic
= 0;
923 rose
->neighbour
->use
--;
924 rose
->neighbour
= NULL
;
926 rose
->state
= ROSE_STATE_0
;
927 sk
->sk_state
= TCP_CLOSE
;
929 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
930 if (!sock_flag(sk
, SOCK_DEAD
)) {
931 sk
->sk_state_change(sk
);
932 sock_set_flag(sk
, SOCK_DEAD
);
936 skb_reset_transport_header(skb
);
937 res
= rose_process_rx_frame(sk
, skb
);
943 * Is is a Call Request and is it for us ?
945 if (frametype
== ROSE_CALL_REQUEST
)
946 if ((dev
= rose_dev_get(dest_addr
)) != NULL
) {
947 res
= rose_rx_call_request(skb
, dev
, rose_neigh
, lci
);
952 if (!sysctl_rose_routing_control
) {
953 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 0);
958 * Route it to the next in line if we have an entry for it.
960 rose_route
= rose_route_list
;
961 while (rose_route
!= NULL
) {
962 if (rose_route
->lci1
== lci
&&
963 rose_route
->neigh1
== rose_neigh
) {
964 if (frametype
== ROSE_CALL_REQUEST
) {
965 /* F6FBB - Remove an existing unused route */
966 rose_remove_route(rose_route
);
968 } else if (rose_route
->neigh2
!= NULL
) {
969 skb
->data
[0] &= 0xF0;
970 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
971 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
972 rose_transmit_link(skb
, rose_route
->neigh2
);
973 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
974 rose_remove_route(rose_route
);
978 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
979 rose_remove_route(rose_route
);
983 if (rose_route
->lci2
== lci
&&
984 rose_route
->neigh2
== rose_neigh
) {
985 if (frametype
== ROSE_CALL_REQUEST
) {
986 /* F6FBB - Remove an existing unused route */
987 rose_remove_route(rose_route
);
989 } else if (rose_route
->neigh1
!= NULL
) {
990 skb
->data
[0] &= 0xF0;
991 skb
->data
[0] |= (rose_route
->lci1
>> 8) & 0x0F;
992 skb
->data
[1] = (rose_route
->lci1
>> 0) & 0xFF;
993 rose_transmit_link(skb
, rose_route
->neigh1
);
994 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
995 rose_remove_route(rose_route
);
999 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
1000 rose_remove_route(rose_route
);
1004 rose_route
= rose_route
->next
;
1009 * 1. The frame isn't for us,
1010 * 2. It isn't "owned" by any existing route.
1012 if (frametype
!= ROSE_CALL_REQUEST
) { /* XXX */
1017 memset(&facilities
, 0x00, sizeof(struct rose_facilities_struct
));
1019 if (!rose_parse_facilities(skb
->data
+ ROSE_CALL_REQ_FACILITIES_OFF
,
1020 skb
->len
- ROSE_CALL_REQ_FACILITIES_OFF
,
1022 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_INVALID_FACILITY
, 76);
1027 * Check for routing loops.
1029 rose_route
= rose_route_list
;
1030 while (rose_route
!= NULL
) {
1031 if (rose_route
->rand
== facilities
.rand
&&
1032 rosecmp(src_addr
, &rose_route
->src_addr
) == 0 &&
1033 ax25cmp(&facilities
.dest_call
, &rose_route
->src_call
) == 0 &&
1034 ax25cmp(&facilities
.source_call
, &rose_route
->dest_call
) == 0) {
1035 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 120);
1038 rose_route
= rose_route
->next
;
1041 if ((new_neigh
= rose_get_neigh(dest_addr
, &cause
, &diagnostic
, 1)) == NULL
) {
1042 rose_transmit_clear_request(rose_neigh
, lci
, cause
, diagnostic
);
1046 if ((new_lci
= rose_new_lci(new_neigh
)) == 0) {
1047 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 71);
1051 if ((rose_route
= kmalloc(sizeof(*rose_route
), GFP_ATOMIC
)) == NULL
) {
1052 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 120);
1056 rose_route
->lci1
= lci
;
1057 rose_route
->src_addr
= *src_addr
;
1058 rose_route
->dest_addr
= *dest_addr
;
1059 rose_route
->src_call
= facilities
.dest_call
;
1060 rose_route
->dest_call
= facilities
.source_call
;
1061 rose_route
->rand
= facilities
.rand
;
1062 rose_route
->neigh1
= rose_neigh
;
1063 rose_route
->lci2
= new_lci
;
1064 rose_route
->neigh2
= new_neigh
;
1066 rose_route
->neigh1
->use
++;
1067 rose_route
->neigh2
->use
++;
1069 rose_route
->next
= rose_route_list
;
1070 rose_route_list
= rose_route
;
1072 skb
->data
[0] &= 0xF0;
1073 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
1074 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
1076 rose_transmit_link(skb
, rose_route
->neigh2
);
1080 spin_unlock_bh(&rose_route_list_lock
);
1081 spin_unlock_bh(&rose_neigh_list_lock
);
1086 #ifdef CONFIG_PROC_FS
1088 static void *rose_node_start(struct seq_file
*seq
, loff_t
*pos
)
1089 __acquires(rose_node_list_lock
)
1091 struct rose_node
*rose_node
;
1094 spin_lock_bh(&rose_node_list_lock
);
1096 return SEQ_START_TOKEN
;
1098 for (rose_node
= rose_node_list
; rose_node
&& i
< *pos
;
1099 rose_node
= rose_node
->next
, ++i
);
1101 return (i
== *pos
) ? rose_node
: NULL
;
1104 static void *rose_node_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1108 return (v
== SEQ_START_TOKEN
) ? rose_node_list
1109 : ((struct rose_node
*)v
)->next
;
1112 static void rose_node_stop(struct seq_file
*seq
, void *v
)
1113 __releases(rose_node_list_lock
)
1115 spin_unlock_bh(&rose_node_list_lock
);
1118 static int rose_node_show(struct seq_file
*seq
, void *v
)
1123 if (v
== SEQ_START_TOKEN
)
1124 seq_puts(seq
, "address mask n neigh neigh neigh\n");
1126 const struct rose_node
*rose_node
= v
;
1127 /* if (rose_node->loopback) {
1128 seq_printf(seq, "%-10s %04d 1 loopback\n",
1129 rose2asc(rsbuf, &rose_node->address),
1132 seq_printf(seq
, "%-10s %04d %d",
1133 rose2asc(rsbuf
, &rose_node
->address
),
1137 for (i
= 0; i
< rose_node
->count
; i
++)
1138 seq_printf(seq
, " %05d",
1139 rose_node
->neighbour
[i
]->number
);
1141 seq_puts(seq
, "\n");
1147 const struct seq_operations rose_node_seqops
= {
1148 .start
= rose_node_start
,
1149 .next
= rose_node_next
,
1150 .stop
= rose_node_stop
,
1151 .show
= rose_node_show
,
1154 static void *rose_neigh_start(struct seq_file
*seq
, loff_t
*pos
)
1155 __acquires(rose_neigh_list_lock
)
1157 struct rose_neigh
*rose_neigh
;
1160 spin_lock_bh(&rose_neigh_list_lock
);
1162 return SEQ_START_TOKEN
;
1164 for (rose_neigh
= rose_neigh_list
; rose_neigh
&& i
< *pos
;
1165 rose_neigh
= rose_neigh
->next
, ++i
);
1167 return (i
== *pos
) ? rose_neigh
: NULL
;
1170 static void *rose_neigh_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1174 return (v
== SEQ_START_TOKEN
) ? rose_neigh_list
1175 : ((struct rose_neigh
*)v
)->next
;
1178 static void rose_neigh_stop(struct seq_file
*seq
, void *v
)
1179 __releases(rose_neigh_list_lock
)
1181 spin_unlock_bh(&rose_neigh_list_lock
);
1184 static int rose_neigh_show(struct seq_file
*seq
, void *v
)
1189 if (v
== SEQ_START_TOKEN
)
1191 "addr callsign dev count use mode restart t0 tf digipeaters\n");
1193 struct rose_neigh
*rose_neigh
= v
;
1195 /* if (!rose_neigh->loopback) { */
1196 seq_printf(seq
, "%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu",
1198 (rose_neigh
->loopback
) ? "RSLOOP-0" : ax2asc(buf
, &rose_neigh
->callsign
),
1199 rose_neigh
->dev
? rose_neigh
->dev
->name
: "???",
1202 (rose_neigh
->dce_mode
) ? "DCE" : "DTE",
1203 (rose_neigh
->restarted
) ? "yes" : "no",
1204 ax25_display_timer(&rose_neigh
->t0timer
) / HZ
,
1205 ax25_display_timer(&rose_neigh
->ftimer
) / HZ
);
1207 if (rose_neigh
->digipeat
!= NULL
) {
1208 for (i
= 0; i
< rose_neigh
->digipeat
->ndigi
; i
++)
1209 seq_printf(seq
, " %s", ax2asc(buf
, &rose_neigh
->digipeat
->calls
[i
]));
1212 seq_puts(seq
, "\n");
1218 const struct seq_operations rose_neigh_seqops
= {
1219 .start
= rose_neigh_start
,
1220 .next
= rose_neigh_next
,
1221 .stop
= rose_neigh_stop
,
1222 .show
= rose_neigh_show
,
1225 static void *rose_route_start(struct seq_file
*seq
, loff_t
*pos
)
1226 __acquires(rose_route_list_lock
)
1228 struct rose_route
*rose_route
;
1231 spin_lock_bh(&rose_route_list_lock
);
1233 return SEQ_START_TOKEN
;
1235 for (rose_route
= rose_route_list
; rose_route
&& i
< *pos
;
1236 rose_route
= rose_route
->next
, ++i
);
1238 return (i
== *pos
) ? rose_route
: NULL
;
1241 static void *rose_route_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1245 return (v
== SEQ_START_TOKEN
) ? rose_route_list
1246 : ((struct rose_route
*)v
)->next
;
1249 static void rose_route_stop(struct seq_file
*seq
, void *v
)
1250 __releases(rose_route_list_lock
)
1252 spin_unlock_bh(&rose_route_list_lock
);
1255 static int rose_route_show(struct seq_file
*seq
, void *v
)
1257 char buf
[11], rsbuf
[11];
1259 if (v
== SEQ_START_TOKEN
)
1261 "lci address callsign neigh <-> lci address callsign neigh\n");
1263 struct rose_route
*rose_route
= v
;
1265 if (rose_route
->neigh1
)
1267 "%3.3X %-10s %-9s %05d ",
1269 rose2asc(rsbuf
, &rose_route
->src_addr
),
1270 ax2asc(buf
, &rose_route
->src_call
),
1271 rose_route
->neigh1
->number
);
1276 if (rose_route
->neigh2
)
1278 "%3.3X %-10s %-9s %05d\n",
1280 rose2asc(rsbuf
, &rose_route
->dest_addr
),
1281 ax2asc(buf
, &rose_route
->dest_call
),
1282 rose_route
->neigh2
->number
);
1290 struct seq_operations rose_route_seqops
= {
1291 .start
= rose_route_start
,
1292 .next
= rose_route_next
,
1293 .stop
= rose_route_stop
,
1294 .show
= rose_route_show
,
1296 #endif /* CONFIG_PROC_FS */
1299 * Release all memory associated with ROSE routing structures.
1301 void __exit
rose_rt_free(void)
1303 struct rose_neigh
*s
, *rose_neigh
= rose_neigh_list
;
1304 struct rose_node
*t
, *rose_node
= rose_node_list
;
1305 struct rose_route
*u
, *rose_route
= rose_route_list
;
1307 while (rose_neigh
!= NULL
) {
1309 rose_neigh
= rose_neigh
->next
;
1311 rose_remove_neigh(s
);
1314 while (rose_node
!= NULL
) {
1316 rose_node
= rose_node
->next
;
1318 rose_remove_node(t
);
1321 while (rose_route
!= NULL
) {
1323 rose_route
= rose_route
->next
;
1325 rose_remove_route(u
);