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>
19 #include <linux/slab.h>
21 #include <linux/inet.h>
22 #include <linux/netdevice.h>
24 #include <linux/if_arp.h>
25 #include <linux/skbuff.h>
27 #include <net/tcp_states.h>
28 #include <asm/system.h>
29 #include <asm/uaccess.h>
30 #include <linux/fcntl.h>
31 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
33 #include <linux/interrupt.h>
34 #include <linux/notifier.h>
35 #include <linux/netfilter.h>
36 #include <linux/init.h>
38 #include <linux/seq_file.h>
40 static unsigned int rose_neigh_no
= 1;
42 static struct rose_node
*rose_node_list
;
43 static DEFINE_SPINLOCK(rose_node_list_lock
);
44 static struct rose_neigh
*rose_neigh_list
;
45 static DEFINE_SPINLOCK(rose_neigh_list_lock
);
46 static struct rose_route
*rose_route_list
;
47 static DEFINE_SPINLOCK(rose_route_list_lock
);
49 struct rose_neigh
*rose_loopback_neigh
;
52 * Add a new route to a node, and in the process add the node and the
53 * neighbour if it is new.
55 static int __must_check
rose_add_node(struct rose_route_struct
*rose_route
,
56 struct net_device
*dev
)
58 struct rose_node
*rose_node
, *rose_tmpn
, *rose_tmpp
;
59 struct rose_neigh
*rose_neigh
;
62 spin_lock_bh(&rose_node_list_lock
);
63 spin_lock_bh(&rose_neigh_list_lock
);
65 rose_node
= rose_node_list
;
66 while (rose_node
!= NULL
) {
67 if ((rose_node
->mask
== rose_route
->mask
) &&
68 (rosecmpm(&rose_route
->address
, &rose_node
->address
,
69 rose_route
->mask
) == 0))
71 rose_node
= rose_node
->next
;
74 if (rose_node
!= NULL
&& rose_node
->loopback
) {
79 rose_neigh
= rose_neigh_list
;
80 while (rose_neigh
!= NULL
) {
81 if (ax25cmp(&rose_route
->neighbour
,
82 &rose_neigh
->callsign
) == 0 &&
83 rose_neigh
->dev
== dev
)
85 rose_neigh
= rose_neigh
->next
;
88 if (rose_neigh
== NULL
) {
89 rose_neigh
= kmalloc(sizeof(*rose_neigh
), GFP_ATOMIC
);
90 if (rose_neigh
== NULL
) {
95 rose_neigh
->callsign
= rose_route
->neighbour
;
96 rose_neigh
->digipeat
= NULL
;
97 rose_neigh
->ax25
= NULL
;
98 rose_neigh
->dev
= dev
;
99 rose_neigh
->count
= 0;
101 rose_neigh
->dce_mode
= 0;
102 rose_neigh
->loopback
= 0;
103 rose_neigh
->number
= rose_neigh_no
++;
104 rose_neigh
->restarted
= 0;
106 skb_queue_head_init(&rose_neigh
->queue
);
108 init_timer(&rose_neigh
->ftimer
);
109 init_timer(&rose_neigh
->t0timer
);
111 if (rose_route
->ndigis
!= 0) {
112 rose_neigh
->digipeat
=
113 kmalloc(sizeof(ax25_digi
), GFP_ATOMIC
);
114 if (rose_neigh
->digipeat
== NULL
) {
120 rose_neigh
->digipeat
->ndigi
= rose_route
->ndigis
;
121 rose_neigh
->digipeat
->lastrepeat
= -1;
123 for (i
= 0; i
< rose_route
->ndigis
; i
++) {
124 rose_neigh
->digipeat
->calls
[i
] =
125 rose_route
->digipeaters
[i
];
126 rose_neigh
->digipeat
->repeated
[i
] = 0;
130 rose_neigh
->next
= rose_neigh_list
;
131 rose_neigh_list
= rose_neigh
;
135 * This is a new node to be inserted into the list. Find where it needs
136 * to be inserted into the list, and insert it. We want to be sure
137 * to order the list in descending order of mask size to ensure that
138 * later when we are searching this list the first match will be the
141 if (rose_node
== NULL
) {
142 rose_tmpn
= rose_node_list
;
145 while (rose_tmpn
!= NULL
) {
146 if (rose_tmpn
->mask
> rose_route
->mask
) {
147 rose_tmpp
= rose_tmpn
;
148 rose_tmpn
= rose_tmpn
->next
;
154 /* create new node */
155 rose_node
= kmalloc(sizeof(*rose_node
), GFP_ATOMIC
);
156 if (rose_node
== NULL
) {
161 rose_node
->address
= rose_route
->address
;
162 rose_node
->mask
= rose_route
->mask
;
163 rose_node
->count
= 1;
164 rose_node
->loopback
= 0;
165 rose_node
->neighbour
[0] = rose_neigh
;
167 if (rose_tmpn
== NULL
) {
168 if (rose_tmpp
== NULL
) { /* Empty list */
169 rose_node_list
= rose_node
;
170 rose_node
->next
= NULL
;
172 rose_tmpp
->next
= rose_node
;
173 rose_node
->next
= NULL
;
176 if (rose_tmpp
== NULL
) { /* 1st node */
177 rose_node
->next
= rose_node_list
;
178 rose_node_list
= rose_node
;
180 rose_tmpp
->next
= rose_node
;
181 rose_node
->next
= rose_tmpn
;
189 /* We have space, slot it in */
190 if (rose_node
->count
< 3) {
191 rose_node
->neighbour
[rose_node
->count
] = rose_neigh
;
197 spin_unlock_bh(&rose_neigh_list_lock
);
198 spin_unlock_bh(&rose_node_list_lock
);
204 * Caller is holding rose_node_list_lock.
206 static void rose_remove_node(struct rose_node
*rose_node
)
210 if ((s
= rose_node_list
) == rose_node
) {
211 rose_node_list
= rose_node
->next
;
216 while (s
!= NULL
&& s
->next
!= NULL
) {
217 if (s
->next
== rose_node
) {
218 s
->next
= rose_node
->next
;
228 * Caller is holding rose_neigh_list_lock.
230 static void rose_remove_neigh(struct rose_neigh
*rose_neigh
)
232 struct rose_neigh
*s
;
234 rose_stop_ftimer(rose_neigh
);
235 rose_stop_t0timer(rose_neigh
);
237 skb_queue_purge(&rose_neigh
->queue
);
239 if ((s
= rose_neigh_list
) == rose_neigh
) {
240 rose_neigh_list
= rose_neigh
->next
;
241 if (rose_neigh
->ax25
)
242 ax25_cb_put(rose_neigh
->ax25
);
243 kfree(rose_neigh
->digipeat
);
248 while (s
!= NULL
&& s
->next
!= NULL
) {
249 if (s
->next
== rose_neigh
) {
250 s
->next
= rose_neigh
->next
;
251 if (rose_neigh
->ax25
)
252 ax25_cb_put(rose_neigh
->ax25
);
253 kfree(rose_neigh
->digipeat
);
263 * Caller is holding rose_route_list_lock.
265 static void rose_remove_route(struct rose_route
*rose_route
)
267 struct rose_route
*s
;
269 if (rose_route
->neigh1
!= NULL
)
270 rose_route
->neigh1
->use
--;
272 if (rose_route
->neigh2
!= NULL
)
273 rose_route
->neigh2
->use
--;
275 if ((s
= rose_route_list
) == rose_route
) {
276 rose_route_list
= rose_route
->next
;
281 while (s
!= NULL
&& s
->next
!= NULL
) {
282 if (s
->next
== rose_route
) {
283 s
->next
= rose_route
->next
;
293 * "Delete" a node. Strictly speaking remove a route to a node. The node
294 * is only deleted if no routes are left to it.
296 static int rose_del_node(struct rose_route_struct
*rose_route
,
297 struct net_device
*dev
)
299 struct rose_node
*rose_node
;
300 struct rose_neigh
*rose_neigh
;
303 spin_lock_bh(&rose_node_list_lock
);
304 spin_lock_bh(&rose_neigh_list_lock
);
306 rose_node
= rose_node_list
;
307 while (rose_node
!= NULL
) {
308 if ((rose_node
->mask
== rose_route
->mask
) &&
309 (rosecmpm(&rose_route
->address
, &rose_node
->address
,
310 rose_route
->mask
) == 0))
312 rose_node
= rose_node
->next
;
315 if (rose_node
== NULL
|| rose_node
->loopback
) {
320 rose_neigh
= rose_neigh_list
;
321 while (rose_neigh
!= NULL
) {
322 if (ax25cmp(&rose_route
->neighbour
,
323 &rose_neigh
->callsign
) == 0 &&
324 rose_neigh
->dev
== dev
)
326 rose_neigh
= rose_neigh
->next
;
329 if (rose_neigh
== NULL
) {
334 for (i
= 0; i
< rose_node
->count
; i
++) {
335 if (rose_node
->neighbour
[i
] == rose_neigh
) {
338 if (rose_neigh
->count
== 0 && rose_neigh
->use
== 0)
339 rose_remove_neigh(rose_neigh
);
343 if (rose_node
->count
== 0) {
344 rose_remove_node(rose_node
);
348 rose_node
->neighbour
[0] =
349 rose_node
->neighbour
[1];
351 rose_node
->neighbour
[1] =
352 rose_node
->neighbour
[2];
363 spin_unlock_bh(&rose_neigh_list_lock
);
364 spin_unlock_bh(&rose_node_list_lock
);
370 * Add the loopback neighbour.
372 void rose_add_loopback_neigh(void)
374 struct rose_neigh
*sn
;
376 rose_loopback_neigh
= kmalloc(sizeof(struct rose_neigh
), GFP_KERNEL
);
377 if (!rose_loopback_neigh
)
379 sn
= rose_loopback_neigh
;
381 sn
->callsign
= null_ax25_address
;
389 sn
->number
= rose_neigh_no
++;
392 skb_queue_head_init(&sn
->queue
);
394 init_timer(&sn
->ftimer
);
395 init_timer(&sn
->t0timer
);
397 spin_lock_bh(&rose_neigh_list_lock
);
398 sn
->next
= rose_neigh_list
;
399 rose_neigh_list
= sn
;
400 spin_unlock_bh(&rose_neigh_list_lock
);
404 * Add a loopback node.
406 int rose_add_loopback_node(rose_address
*address
)
408 struct rose_node
*rose_node
;
411 spin_lock_bh(&rose_node_list_lock
);
413 rose_node
= rose_node_list
;
414 while (rose_node
!= NULL
) {
415 if ((rose_node
->mask
== 10) &&
416 (rosecmpm(address
, &rose_node
->address
, 10) == 0) &&
419 rose_node
= rose_node
->next
;
422 if (rose_node
!= NULL
)
425 if ((rose_node
= kmalloc(sizeof(*rose_node
), GFP_ATOMIC
)) == NULL
) {
430 rose_node
->address
= *address
;
431 rose_node
->mask
= 10;
432 rose_node
->count
= 1;
433 rose_node
->loopback
= 1;
434 rose_node
->neighbour
[0] = rose_loopback_neigh
;
436 /* Insert at the head of list. Address is always mask=10 */
437 rose_node
->next
= rose_node_list
;
438 rose_node_list
= rose_node
;
440 rose_loopback_neigh
->count
++;
443 spin_unlock_bh(&rose_node_list_lock
);
449 * Delete a loopback node.
451 void rose_del_loopback_node(rose_address
*address
)
453 struct rose_node
*rose_node
;
455 spin_lock_bh(&rose_node_list_lock
);
457 rose_node
= rose_node_list
;
458 while (rose_node
!= NULL
) {
459 if ((rose_node
->mask
== 10) &&
460 (rosecmpm(address
, &rose_node
->address
, 10) == 0) &&
463 rose_node
= rose_node
->next
;
466 if (rose_node
== NULL
)
469 rose_remove_node(rose_node
);
471 rose_loopback_neigh
->count
--;
474 spin_unlock_bh(&rose_node_list_lock
);
478 * A device has been removed. Remove its routes and neighbours.
480 void rose_rt_device_down(struct net_device
*dev
)
482 struct rose_neigh
*s
, *rose_neigh
;
483 struct rose_node
*t
, *rose_node
;
486 spin_lock_bh(&rose_node_list_lock
);
487 spin_lock_bh(&rose_neigh_list_lock
);
488 rose_neigh
= rose_neigh_list
;
489 while (rose_neigh
!= NULL
) {
491 rose_neigh
= rose_neigh
->next
;
496 rose_node
= rose_node_list
;
498 while (rose_node
!= NULL
) {
500 rose_node
= rose_node
->next
;
502 for (i
= 0; i
< t
->count
; i
++) {
503 if (t
->neighbour
[i
] != s
)
510 t
->neighbour
[0] = t
->neighbour
[1];
512 t
->neighbour
[1] = t
->neighbour
[2];
522 rose_remove_neigh(s
);
524 spin_unlock_bh(&rose_neigh_list_lock
);
525 spin_unlock_bh(&rose_node_list_lock
);
528 #if 0 /* Currently unused */
530 * A device has been removed. Remove its links.
532 void rose_route_device_down(struct net_device
*dev
)
534 struct rose_route
*s
, *rose_route
;
536 spin_lock_bh(&rose_route_list_lock
);
537 rose_route
= rose_route_list
;
538 while (rose_route
!= NULL
) {
540 rose_route
= rose_route
->next
;
542 if (s
->neigh1
->dev
== dev
|| s
->neigh2
->dev
== dev
)
543 rose_remove_route(s
);
545 spin_unlock_bh(&rose_route_list_lock
);
550 * Clear all nodes and neighbours out, except for neighbours with
551 * active connections going through them.
552 * Do not clear loopback neighbour and nodes.
554 static int rose_clear_routes(void)
556 struct rose_neigh
*s
, *rose_neigh
;
557 struct rose_node
*t
, *rose_node
;
559 spin_lock_bh(&rose_node_list_lock
);
560 spin_lock_bh(&rose_neigh_list_lock
);
562 rose_neigh
= rose_neigh_list
;
563 rose_node
= rose_node_list
;
565 while (rose_node
!= NULL
) {
567 rose_node
= rose_node
->next
;
572 while (rose_neigh
!= NULL
) {
574 rose_neigh
= rose_neigh
->next
;
576 if (s
->use
== 0 && !s
->loopback
) {
578 rose_remove_neigh(s
);
582 spin_unlock_bh(&rose_neigh_list_lock
);
583 spin_unlock_bh(&rose_node_list_lock
);
589 * Check that the device given is a valid AX.25 interface that is "up".
592 static struct net_device
*rose_ax25_dev_find(char *devname
)
594 struct net_device
*dev
;
596 if ((dev
= __dev_get_by_name(&init_net
, devname
)) == NULL
)
599 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_AX25
)
606 * Find the first active ROSE device, usually "rose0".
608 struct net_device
*rose_dev_first(void)
610 struct net_device
*dev
, *first
= NULL
;
613 for_each_netdev_rcu(&init_net
, dev
) {
614 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
)
615 if (first
== NULL
|| strncmp(dev
->name
, first
->name
, 3) < 0)
624 * Find the ROSE device for the given address.
626 struct net_device
*rose_dev_get(rose_address
*addr
)
628 struct net_device
*dev
;
631 for_each_netdev_rcu(&init_net
, dev
) {
632 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0) {
643 static int rose_dev_exists(rose_address
*addr
)
645 struct net_device
*dev
;
648 for_each_netdev_rcu(&init_net
, dev
) {
649 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0)
661 struct rose_route
*rose_route_free_lci(unsigned int lci
, struct rose_neigh
*neigh
)
663 struct rose_route
*rose_route
;
665 for (rose_route
= rose_route_list
; rose_route
!= NULL
; rose_route
= rose_route
->next
)
666 if ((rose_route
->neigh1
== neigh
&& rose_route
->lci1
== lci
) ||
667 (rose_route
->neigh2
== neigh
&& rose_route
->lci2
== lci
))
674 * Find a neighbour or a route given a ROSE address.
676 struct rose_neigh
*rose_get_neigh(rose_address
*addr
, unsigned char *cause
,
677 unsigned char *diagnostic
, int new)
679 struct rose_neigh
*res
= NULL
;
680 struct rose_node
*node
;
684 if (!new) spin_lock_bh(&rose_node_list_lock
);
685 for (node
= rose_node_list
; node
!= NULL
; node
= node
->next
) {
686 if (rosecmpm(addr
, &node
->address
, node
->mask
) == 0) {
687 for (i
= 0; i
< node
->count
; i
++) {
689 if (node
->neighbour
[i
]->restarted
) {
690 res
= node
->neighbour
[i
];
695 if (!rose_ftimer_running(node
->neighbour
[i
])) {
696 res
= node
->neighbour
[i
];
706 *cause
= ROSE_OUT_OF_ORDER
;
709 *cause
= ROSE_NOT_OBTAINABLE
;
714 if (!new) spin_unlock_bh(&rose_node_list_lock
);
720 * Handle the ioctls that control the routing functions.
722 int rose_rt_ioctl(unsigned int cmd
, void __user
*arg
)
724 struct rose_route_struct rose_route
;
725 struct net_device
*dev
;
730 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
732 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
734 if (rose_dev_exists(&rose_route
.address
)) /* Can't add routes to ourself */
736 if (rose_route
.mask
> 10) /* Mask can't be more than 10 digits */
738 if (rose_route
.ndigis
> AX25_MAX_DIGIS
)
740 err
= rose_add_node(&rose_route
, dev
);
744 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
746 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
748 err
= rose_del_node(&rose_route
, dev
);
752 return rose_clear_routes();
761 static void rose_del_route_by_neigh(struct rose_neigh
*rose_neigh
)
763 struct rose_route
*rose_route
, *s
;
765 rose_neigh
->restarted
= 0;
767 rose_stop_t0timer(rose_neigh
);
768 rose_start_ftimer(rose_neigh
);
770 skb_queue_purge(&rose_neigh
->queue
);
772 spin_lock_bh(&rose_route_list_lock
);
774 rose_route
= rose_route_list
;
776 while (rose_route
!= NULL
) {
777 if ((rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== rose_neigh
) ||
778 (rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== NULL
) ||
779 (rose_route
->neigh2
== rose_neigh
&& rose_route
->neigh1
== NULL
)) {
780 s
= rose_route
->next
;
781 rose_remove_route(rose_route
);
786 if (rose_route
->neigh1
== rose_neigh
) {
787 rose_route
->neigh1
->use
--;
788 rose_route
->neigh1
= NULL
;
789 rose_transmit_clear_request(rose_route
->neigh2
, rose_route
->lci2
, ROSE_OUT_OF_ORDER
, 0);
792 if (rose_route
->neigh2
== rose_neigh
) {
793 rose_route
->neigh2
->use
--;
794 rose_route
->neigh2
= NULL
;
795 rose_transmit_clear_request(rose_route
->neigh1
, rose_route
->lci1
, ROSE_OUT_OF_ORDER
, 0);
798 rose_route
= rose_route
->next
;
800 spin_unlock_bh(&rose_route_list_lock
);
804 * A level 2 link has timed out, therefore it appears to be a poor link,
805 * then don't use that neighbour until it is reset. Blow away all through
806 * routes and connections using this route.
808 void rose_link_failed(ax25_cb
*ax25
, int reason
)
810 struct rose_neigh
*rose_neigh
;
812 spin_lock_bh(&rose_neigh_list_lock
);
813 rose_neigh
= rose_neigh_list
;
814 while (rose_neigh
!= NULL
) {
815 if (rose_neigh
->ax25
== ax25
)
817 rose_neigh
= rose_neigh
->next
;
820 if (rose_neigh
!= NULL
) {
821 rose_neigh
->ax25
= NULL
;
824 rose_del_route_by_neigh(rose_neigh
);
825 rose_kill_by_neigh(rose_neigh
);
827 spin_unlock_bh(&rose_neigh_list_lock
);
831 * A device has been "downed" remove its link status. Blow away all
832 * through routes and connections that use this device.
834 void rose_link_device_down(struct net_device
*dev
)
836 struct rose_neigh
*rose_neigh
;
838 for (rose_neigh
= rose_neigh_list
; rose_neigh
!= NULL
; rose_neigh
= rose_neigh
->next
) {
839 if (rose_neigh
->dev
== dev
) {
840 rose_del_route_by_neigh(rose_neigh
);
841 rose_kill_by_neigh(rose_neigh
);
847 * Route a frame to an appropriate AX.25 connection.
849 int rose_route_frame(struct sk_buff
*skb
, ax25_cb
*ax25
)
851 struct rose_neigh
*rose_neigh
, *new_neigh
;
852 struct rose_route
*rose_route
;
853 struct rose_facilities_struct facilities
;
854 rose_address
*src_addr
, *dest_addr
;
856 unsigned short frametype
;
857 unsigned int lci
, new_lci
;
858 unsigned char cause
, diagnostic
;
859 struct net_device
*dev
;
864 if (call_in_firewall(PF_ROSE
, skb
->dev
, skb
->data
, NULL
, &skb
) != FW_ACCEPT
)
868 frametype
= skb
->data
[2];
869 lci
= ((skb
->data
[0] << 8) & 0xF00) + ((skb
->data
[1] << 0) & 0x0FF);
870 src_addr
= (rose_address
*)(skb
->data
+ 9);
871 dest_addr
= (rose_address
*)(skb
->data
+ 4);
873 spin_lock_bh(&rose_neigh_list_lock
);
874 spin_lock_bh(&rose_route_list_lock
);
876 rose_neigh
= rose_neigh_list
;
877 while (rose_neigh
!= NULL
) {
878 if (ax25cmp(&ax25
->dest_addr
, &rose_neigh
->callsign
) == 0 &&
879 ax25
->ax25_dev
->dev
== rose_neigh
->dev
)
881 rose_neigh
= rose_neigh
->next
;
884 if (rose_neigh
== NULL
) {
885 printk("rose_route : unknown neighbour or device %s\n",
886 ax2asc(buf
, &ax25
->dest_addr
));
891 * Obviously the link is working, halt the ftimer.
893 rose_stop_ftimer(rose_neigh
);
896 * LCI of zero is always for us, and its always a restart
900 rose_link_rx_restart(skb
, rose_neigh
, frametype
);
905 * Find an existing socket.
907 if ((sk
= rose_find_socket(lci
, rose_neigh
)) != NULL
) {
908 if (frametype
== ROSE_CALL_REQUEST
) {
909 struct rose_sock
*rose
= rose_sk(sk
);
911 /* Remove an existing unused socket */
912 rose_clear_queues(sk
);
913 rose
->cause
= ROSE_NETWORK_CONGESTION
;
914 rose
->diagnostic
= 0;
915 rose
->neighbour
->use
--;
916 rose
->neighbour
= NULL
;
918 rose
->state
= ROSE_STATE_0
;
919 sk
->sk_state
= TCP_CLOSE
;
921 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
922 if (!sock_flag(sk
, SOCK_DEAD
)) {
923 sk
->sk_state_change(sk
);
924 sock_set_flag(sk
, SOCK_DEAD
);
928 skb_reset_transport_header(skb
);
929 res
= rose_process_rx_frame(sk
, skb
);
935 * Is is a Call Request and is it for us ?
937 if (frametype
== ROSE_CALL_REQUEST
)
938 if ((dev
= rose_dev_get(dest_addr
)) != NULL
) {
939 res
= rose_rx_call_request(skb
, dev
, rose_neigh
, lci
);
944 if (!sysctl_rose_routing_control
) {
945 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 0);
950 * Route it to the next in line if we have an entry for it.
952 rose_route
= rose_route_list
;
953 while (rose_route
!= NULL
) {
954 if (rose_route
->lci1
== lci
&&
955 rose_route
->neigh1
== rose_neigh
) {
956 if (frametype
== ROSE_CALL_REQUEST
) {
957 /* F6FBB - Remove an existing unused route */
958 rose_remove_route(rose_route
);
960 } else if (rose_route
->neigh2
!= NULL
) {
961 skb
->data
[0] &= 0xF0;
962 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
963 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
964 rose_transmit_link(skb
, rose_route
->neigh2
);
965 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
966 rose_remove_route(rose_route
);
970 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
971 rose_remove_route(rose_route
);
975 if (rose_route
->lci2
== lci
&&
976 rose_route
->neigh2
== rose_neigh
) {
977 if (frametype
== ROSE_CALL_REQUEST
) {
978 /* F6FBB - Remove an existing unused route */
979 rose_remove_route(rose_route
);
981 } else if (rose_route
->neigh1
!= NULL
) {
982 skb
->data
[0] &= 0xF0;
983 skb
->data
[0] |= (rose_route
->lci1
>> 8) & 0x0F;
984 skb
->data
[1] = (rose_route
->lci1
>> 0) & 0xFF;
985 rose_transmit_link(skb
, rose_route
->neigh1
);
986 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
987 rose_remove_route(rose_route
);
991 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
992 rose_remove_route(rose_route
);
996 rose_route
= rose_route
->next
;
1001 * 1. The frame isn't for us,
1002 * 2. It isn't "owned" by any existing route.
1004 if (frametype
!= ROSE_CALL_REQUEST
) { /* XXX */
1009 len
= (((skb
->data
[3] >> 4) & 0x0F) + 1) >> 1;
1010 len
+= (((skb
->data
[3] >> 0) & 0x0F) + 1) >> 1;
1012 memset(&facilities
, 0x00, sizeof(struct rose_facilities_struct
));
1014 if (!rose_parse_facilities(skb
->data
+ len
+ 4, &facilities
)) {
1015 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_INVALID_FACILITY
, 76);
1020 * Check for routing loops.
1022 rose_route
= rose_route_list
;
1023 while (rose_route
!= NULL
) {
1024 if (rose_route
->rand
== facilities
.rand
&&
1025 rosecmp(src_addr
, &rose_route
->src_addr
) == 0 &&
1026 ax25cmp(&facilities
.dest_call
, &rose_route
->src_call
) == 0 &&
1027 ax25cmp(&facilities
.source_call
, &rose_route
->dest_call
) == 0) {
1028 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 120);
1031 rose_route
= rose_route
->next
;
1034 if ((new_neigh
= rose_get_neigh(dest_addr
, &cause
, &diagnostic
, 1)) == NULL
) {
1035 rose_transmit_clear_request(rose_neigh
, lci
, cause
, diagnostic
);
1039 if ((new_lci
= rose_new_lci(new_neigh
)) == 0) {
1040 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 71);
1044 if ((rose_route
= kmalloc(sizeof(*rose_route
), GFP_ATOMIC
)) == NULL
) {
1045 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 120);
1049 rose_route
->lci1
= lci
;
1050 rose_route
->src_addr
= *src_addr
;
1051 rose_route
->dest_addr
= *dest_addr
;
1052 rose_route
->src_call
= facilities
.dest_call
;
1053 rose_route
->dest_call
= facilities
.source_call
;
1054 rose_route
->rand
= facilities
.rand
;
1055 rose_route
->neigh1
= rose_neigh
;
1056 rose_route
->lci2
= new_lci
;
1057 rose_route
->neigh2
= new_neigh
;
1059 rose_route
->neigh1
->use
++;
1060 rose_route
->neigh2
->use
++;
1062 rose_route
->next
= rose_route_list
;
1063 rose_route_list
= rose_route
;
1065 skb
->data
[0] &= 0xF0;
1066 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
1067 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
1069 rose_transmit_link(skb
, rose_route
->neigh2
);
1073 spin_unlock_bh(&rose_route_list_lock
);
1074 spin_unlock_bh(&rose_neigh_list_lock
);
1079 #ifdef CONFIG_PROC_FS
1081 static void *rose_node_start(struct seq_file
*seq
, loff_t
*pos
)
1082 __acquires(rose_node_list_lock
)
1084 struct rose_node
*rose_node
;
1087 spin_lock_bh(&rose_node_list_lock
);
1089 return SEQ_START_TOKEN
;
1091 for (rose_node
= rose_node_list
; rose_node
&& i
< *pos
;
1092 rose_node
= rose_node
->next
, ++i
);
1094 return (i
== *pos
) ? rose_node
: NULL
;
1097 static void *rose_node_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1101 return (v
== SEQ_START_TOKEN
) ? rose_node_list
1102 : ((struct rose_node
*)v
)->next
;
1105 static void rose_node_stop(struct seq_file
*seq
, void *v
)
1106 __releases(rose_node_list_lock
)
1108 spin_unlock_bh(&rose_node_list_lock
);
1111 static int rose_node_show(struct seq_file
*seq
, void *v
)
1116 if (v
== SEQ_START_TOKEN
)
1117 seq_puts(seq
, "address mask n neigh neigh neigh\n");
1119 const struct rose_node
*rose_node
= v
;
1120 /* if (rose_node->loopback) {
1121 seq_printf(seq, "%-10s %04d 1 loopback\n",
1122 rose2asc(rsbuf, &rose_node->address),
1125 seq_printf(seq
, "%-10s %04d %d",
1126 rose2asc(rsbuf
, &rose_node
->address
),
1130 for (i
= 0; i
< rose_node
->count
; i
++)
1131 seq_printf(seq
, " %05d",
1132 rose_node
->neighbour
[i
]->number
);
1134 seq_puts(seq
, "\n");
1140 static const struct seq_operations rose_node_seqops
= {
1141 .start
= rose_node_start
,
1142 .next
= rose_node_next
,
1143 .stop
= rose_node_stop
,
1144 .show
= rose_node_show
,
1147 static int rose_nodes_open(struct inode
*inode
, struct file
*file
)
1149 return seq_open(file
, &rose_node_seqops
);
1152 const struct file_operations rose_nodes_fops
= {
1153 .owner
= THIS_MODULE
,
1154 .open
= rose_nodes_open
,
1156 .llseek
= seq_lseek
,
1157 .release
= seq_release
,
1160 static void *rose_neigh_start(struct seq_file
*seq
, loff_t
*pos
)
1161 __acquires(rose_neigh_list_lock
)
1163 struct rose_neigh
*rose_neigh
;
1166 spin_lock_bh(&rose_neigh_list_lock
);
1168 return SEQ_START_TOKEN
;
1170 for (rose_neigh
= rose_neigh_list
; rose_neigh
&& i
< *pos
;
1171 rose_neigh
= rose_neigh
->next
, ++i
);
1173 return (i
== *pos
) ? rose_neigh
: NULL
;
1176 static void *rose_neigh_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1180 return (v
== SEQ_START_TOKEN
) ? rose_neigh_list
1181 : ((struct rose_neigh
*)v
)->next
;
1184 static void rose_neigh_stop(struct seq_file
*seq
, void *v
)
1185 __releases(rose_neigh_list_lock
)
1187 spin_unlock_bh(&rose_neigh_list_lock
);
1190 static int rose_neigh_show(struct seq_file
*seq
, void *v
)
1195 if (v
== SEQ_START_TOKEN
)
1197 "addr callsign dev count use mode restart t0 tf digipeaters\n");
1199 struct rose_neigh
*rose_neigh
= v
;
1201 /* if (!rose_neigh->loopback) { */
1202 seq_printf(seq
, "%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu",
1204 (rose_neigh
->loopback
) ? "RSLOOP-0" : ax2asc(buf
, &rose_neigh
->callsign
),
1205 rose_neigh
->dev
? rose_neigh
->dev
->name
: "???",
1208 (rose_neigh
->dce_mode
) ? "DCE" : "DTE",
1209 (rose_neigh
->restarted
) ? "yes" : "no",
1210 ax25_display_timer(&rose_neigh
->t0timer
) / HZ
,
1211 ax25_display_timer(&rose_neigh
->ftimer
) / HZ
);
1213 if (rose_neigh
->digipeat
!= NULL
) {
1214 for (i
= 0; i
< rose_neigh
->digipeat
->ndigi
; i
++)
1215 seq_printf(seq
, " %s", ax2asc(buf
, &rose_neigh
->digipeat
->calls
[i
]));
1218 seq_puts(seq
, "\n");
1224 static const struct seq_operations rose_neigh_seqops
= {
1225 .start
= rose_neigh_start
,
1226 .next
= rose_neigh_next
,
1227 .stop
= rose_neigh_stop
,
1228 .show
= rose_neigh_show
,
1231 static int rose_neigh_open(struct inode
*inode
, struct file
*file
)
1233 return seq_open(file
, &rose_neigh_seqops
);
1236 const struct file_operations rose_neigh_fops
= {
1237 .owner
= THIS_MODULE
,
1238 .open
= rose_neigh_open
,
1240 .llseek
= seq_lseek
,
1241 .release
= seq_release
,
1245 static void *rose_route_start(struct seq_file
*seq
, loff_t
*pos
)
1246 __acquires(rose_route_list_lock
)
1248 struct rose_route
*rose_route
;
1251 spin_lock_bh(&rose_route_list_lock
);
1253 return SEQ_START_TOKEN
;
1255 for (rose_route
= rose_route_list
; rose_route
&& i
< *pos
;
1256 rose_route
= rose_route
->next
, ++i
);
1258 return (i
== *pos
) ? rose_route
: NULL
;
1261 static void *rose_route_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1265 return (v
== SEQ_START_TOKEN
) ? rose_route_list
1266 : ((struct rose_route
*)v
)->next
;
1269 static void rose_route_stop(struct seq_file
*seq
, void *v
)
1270 __releases(rose_route_list_lock
)
1272 spin_unlock_bh(&rose_route_list_lock
);
1275 static int rose_route_show(struct seq_file
*seq
, void *v
)
1277 char buf
[11], rsbuf
[11];
1279 if (v
== SEQ_START_TOKEN
)
1281 "lci address callsign neigh <-> lci address callsign neigh\n");
1283 struct rose_route
*rose_route
= v
;
1285 if (rose_route
->neigh1
)
1287 "%3.3X %-10s %-9s %05d ",
1289 rose2asc(rsbuf
, &rose_route
->src_addr
),
1290 ax2asc(buf
, &rose_route
->src_call
),
1291 rose_route
->neigh1
->number
);
1296 if (rose_route
->neigh2
)
1298 "%3.3X %-10s %-9s %05d\n",
1300 rose2asc(rsbuf
, &rose_route
->dest_addr
),
1301 ax2asc(buf
, &rose_route
->dest_call
),
1302 rose_route
->neigh2
->number
);
1310 static const struct seq_operations rose_route_seqops
= {
1311 .start
= rose_route_start
,
1312 .next
= rose_route_next
,
1313 .stop
= rose_route_stop
,
1314 .show
= rose_route_show
,
1317 static int rose_route_open(struct inode
*inode
, struct file
*file
)
1319 return seq_open(file
, &rose_route_seqops
);
1322 const struct file_operations rose_routes_fops
= {
1323 .owner
= THIS_MODULE
,
1324 .open
= rose_route_open
,
1326 .llseek
= seq_lseek
,
1327 .release
= seq_release
,
1330 #endif /* CONFIG_PROC_FS */
1333 * Release all memory associated with ROSE routing structures.
1335 void __exit
rose_rt_free(void)
1337 struct rose_neigh
*s
, *rose_neigh
= rose_neigh_list
;
1338 struct rose_node
*t
, *rose_node
= rose_node_list
;
1339 struct rose_route
*u
, *rose_route
= rose_route_list
;
1341 while (rose_neigh
!= NULL
) {
1343 rose_neigh
= rose_neigh
->next
;
1345 rose_remove_neigh(s
);
1348 while (rose_node
!= NULL
) {
1350 rose_node
= rose_node
->next
;
1352 rose_remove_node(t
);
1355 while (rose_route
!= NULL
) {
1357 rose_route
= rose_route
->next
;
1359 rose_remove_route(u
);