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
,
81 &rose_neigh
->callsign
) == 0 &&
82 rose_neigh
->dev
== dev
)
84 rose_neigh
= rose_neigh
->next
;
87 if (rose_neigh
== NULL
) {
88 rose_neigh
= kmalloc(sizeof(*rose_neigh
), GFP_ATOMIC
);
89 if (rose_neigh
== NULL
) {
94 rose_neigh
->callsign
= rose_route
->neighbour
;
95 rose_neigh
->digipeat
= NULL
;
96 rose_neigh
->ax25
= NULL
;
97 rose_neigh
->dev
= dev
;
98 rose_neigh
->count
= 0;
100 rose_neigh
->dce_mode
= 0;
101 rose_neigh
->loopback
= 0;
102 rose_neigh
->number
= rose_neigh_no
++;
103 rose_neigh
->restarted
= 0;
105 skb_queue_head_init(&rose_neigh
->queue
);
107 init_timer(&rose_neigh
->ftimer
);
108 init_timer(&rose_neigh
->t0timer
);
110 if (rose_route
->ndigis
!= 0) {
111 if ((rose_neigh
->digipeat
= kmalloc(sizeof(ax25_digi
), GFP_KERNEL
)) == NULL
) {
117 rose_neigh
->digipeat
->ndigi
= rose_route
->ndigis
;
118 rose_neigh
->digipeat
->lastrepeat
= -1;
120 for (i
= 0; i
< rose_route
->ndigis
; i
++) {
121 rose_neigh
->digipeat
->calls
[i
] =
122 rose_route
->digipeaters
[i
];
123 rose_neigh
->digipeat
->repeated
[i
] = 0;
127 rose_neigh
->next
= rose_neigh_list
;
128 rose_neigh_list
= rose_neigh
;
132 * This is a new node to be inserted into the list. Find where it needs
133 * to be inserted into the list, and insert it. We want to be sure
134 * to order the list in descending order of mask size to ensure that
135 * later when we are searching this list the first match will be the
138 if (rose_node
== NULL
) {
139 rose_tmpn
= rose_node_list
;
142 while (rose_tmpn
!= NULL
) {
143 if (rose_tmpn
->mask
> rose_route
->mask
) {
144 rose_tmpp
= rose_tmpn
;
145 rose_tmpn
= rose_tmpn
->next
;
151 /* create new node */
152 rose_node
= kmalloc(sizeof(*rose_node
), GFP_ATOMIC
);
153 if (rose_node
== NULL
) {
158 rose_node
->address
= rose_route
->address
;
159 rose_node
->mask
= rose_route
->mask
;
160 rose_node
->count
= 1;
161 rose_node
->loopback
= 0;
162 rose_node
->neighbour
[0] = rose_neigh
;
164 if (rose_tmpn
== NULL
) {
165 if (rose_tmpp
== NULL
) { /* Empty list */
166 rose_node_list
= rose_node
;
167 rose_node
->next
= NULL
;
169 rose_tmpp
->next
= rose_node
;
170 rose_node
->next
= NULL
;
173 if (rose_tmpp
== NULL
) { /* 1st node */
174 rose_node
->next
= rose_node_list
;
175 rose_node_list
= rose_node
;
177 rose_tmpp
->next
= rose_node
;
178 rose_node
->next
= rose_tmpn
;
186 /* We have space, slot it in */
187 if (rose_node
->count
< 3) {
188 rose_node
->neighbour
[rose_node
->count
] = rose_neigh
;
194 spin_unlock_bh(&rose_neigh_list_lock
);
195 spin_unlock_bh(&rose_node_list_lock
);
201 * Caller is holding rose_node_list_lock.
203 static void rose_remove_node(struct rose_node
*rose_node
)
207 if ((s
= rose_node_list
) == rose_node
) {
208 rose_node_list
= rose_node
->next
;
213 while (s
!= NULL
&& s
->next
!= NULL
) {
214 if (s
->next
== rose_node
) {
215 s
->next
= rose_node
->next
;
225 * Caller is holding rose_neigh_list_lock.
227 static void rose_remove_neigh(struct rose_neigh
*rose_neigh
)
229 struct rose_neigh
*s
;
231 rose_stop_ftimer(rose_neigh
);
232 rose_stop_t0timer(rose_neigh
);
234 skb_queue_purge(&rose_neigh
->queue
);
236 if ((s
= rose_neigh_list
) == rose_neigh
) {
237 rose_neigh_list
= rose_neigh
->next
;
238 if (rose_neigh
->ax25
)
239 ax25_cb_put(rose_neigh
->ax25
);
240 kfree(rose_neigh
->digipeat
);
245 while (s
!= NULL
&& s
->next
!= NULL
) {
246 if (s
->next
== rose_neigh
) {
247 s
->next
= rose_neigh
->next
;
248 if (rose_neigh
->ax25
)
249 ax25_cb_put(rose_neigh
->ax25
);
250 kfree(rose_neigh
->digipeat
);
260 * Caller is holding rose_route_list_lock.
262 static void rose_remove_route(struct rose_route
*rose_route
)
264 struct rose_route
*s
;
266 if (rose_route
->neigh1
!= NULL
)
267 rose_route
->neigh1
->use
--;
269 if (rose_route
->neigh2
!= NULL
)
270 rose_route
->neigh2
->use
--;
272 if ((s
= rose_route_list
) == rose_route
) {
273 rose_route_list
= rose_route
->next
;
278 while (s
!= NULL
&& s
->next
!= NULL
) {
279 if (s
->next
== rose_route
) {
280 s
->next
= rose_route
->next
;
290 * "Delete" a node. Strictly speaking remove a route to a node. The node
291 * is only deleted if no routes are left to it.
293 static int rose_del_node(struct rose_route_struct
*rose_route
,
294 struct net_device
*dev
)
296 struct rose_node
*rose_node
;
297 struct rose_neigh
*rose_neigh
;
300 spin_lock_bh(&rose_node_list_lock
);
301 spin_lock_bh(&rose_neigh_list_lock
);
303 rose_node
= rose_node_list
;
304 while (rose_node
!= NULL
) {
305 if ((rose_node
->mask
== rose_route
->mask
) &&
306 (rosecmpm(&rose_route
->address
, &rose_node
->address
,
307 rose_route
->mask
) == 0))
309 rose_node
= rose_node
->next
;
312 if (rose_node
== NULL
|| rose_node
->loopback
) {
317 rose_neigh
= rose_neigh_list
;
318 while (rose_neigh
!= NULL
) {
319 if (ax25cmp(&rose_route
->neighbour
,
320 &rose_neigh
->callsign
) == 0 &&
321 rose_neigh
->dev
== dev
)
323 rose_neigh
= rose_neigh
->next
;
326 if (rose_neigh
== NULL
) {
331 for (i
= 0; i
< rose_node
->count
; i
++) {
332 if (rose_node
->neighbour
[i
] == rose_neigh
) {
335 if (rose_neigh
->count
== 0 && rose_neigh
->use
== 0)
336 rose_remove_neigh(rose_neigh
);
340 if (rose_node
->count
== 0) {
341 rose_remove_node(rose_node
);
345 rose_node
->neighbour
[0] =
346 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 init_timer(&sn
->ftimer
);
392 init_timer(&sn
->t0timer
);
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];
509 t
->neighbour
[1] = t
->neighbour
[2];
519 rose_remove_neigh(s
);
521 spin_unlock_bh(&rose_neigh_list_lock
);
522 spin_unlock_bh(&rose_node_list_lock
);
525 #if 0 /* Currently unused */
527 * A device has been removed. Remove its links.
529 void rose_route_device_down(struct net_device
*dev
)
531 struct rose_route
*s
, *rose_route
;
533 spin_lock_bh(&rose_route_list_lock
);
534 rose_route
= rose_route_list
;
535 while (rose_route
!= NULL
) {
537 rose_route
= rose_route
->next
;
539 if (s
->neigh1
->dev
== dev
|| s
->neigh2
->dev
== dev
)
540 rose_remove_route(s
);
542 spin_unlock_bh(&rose_route_list_lock
);
547 * Clear all nodes and neighbours out, except for neighbours with
548 * active connections going through them.
549 * Do not clear loopback neighbour and nodes.
551 static int rose_clear_routes(void)
553 struct rose_neigh
*s
, *rose_neigh
;
554 struct rose_node
*t
, *rose_node
;
556 spin_lock_bh(&rose_node_list_lock
);
557 spin_lock_bh(&rose_neigh_list_lock
);
559 rose_neigh
= rose_neigh_list
;
560 rose_node
= rose_node_list
;
562 while (rose_node
!= NULL
) {
564 rose_node
= rose_node
->next
;
569 while (rose_neigh
!= NULL
) {
571 rose_neigh
= rose_neigh
->next
;
573 if (s
->use
== 0 && !s
->loopback
) {
575 rose_remove_neigh(s
);
579 spin_unlock_bh(&rose_neigh_list_lock
);
580 spin_unlock_bh(&rose_node_list_lock
);
586 * Check that the device given is a valid AX.25 interface that is "up".
589 static struct net_device
*rose_ax25_dev_find(char *devname
)
591 struct net_device
*dev
;
593 if ((dev
= __dev_get_by_name(&init_net
, devname
)) == NULL
)
596 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_AX25
)
603 * Find the first active ROSE device, usually "rose0".
605 struct net_device
*rose_dev_first(void)
607 struct net_device
*dev
, *first
= NULL
;
610 for_each_netdev_rcu(&init_net
, dev
) {
611 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
)
612 if (first
== NULL
|| strncmp(dev
->name
, first
->name
, 3) < 0)
621 * Find the ROSE device for the given address.
623 struct net_device
*rose_dev_get(rose_address
*addr
)
625 struct net_device
*dev
;
628 for_each_netdev_rcu(&init_net
, dev
) {
629 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0) {
640 static int rose_dev_exists(rose_address
*addr
)
642 struct net_device
*dev
;
645 for_each_netdev_rcu(&init_net
, dev
) {
646 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_ROSE
&& rosecmp(addr
, (rose_address
*)dev
->dev_addr
) == 0)
658 struct rose_route
*rose_route_free_lci(unsigned int lci
, struct rose_neigh
*neigh
)
660 struct rose_route
*rose_route
;
662 for (rose_route
= rose_route_list
; rose_route
!= NULL
; rose_route
= rose_route
->next
)
663 if ((rose_route
->neigh1
== neigh
&& rose_route
->lci1
== lci
) ||
664 (rose_route
->neigh2
== neigh
&& rose_route
->lci2
== lci
))
671 * Find a neighbour or a route given a ROSE address.
673 struct rose_neigh
*rose_get_neigh(rose_address
*addr
, unsigned char *cause
,
674 unsigned char *diagnostic
, int new)
676 struct rose_neigh
*res
= NULL
;
677 struct rose_node
*node
;
681 if (!new) spin_lock_bh(&rose_node_list_lock
);
682 for (node
= rose_node_list
; node
!= NULL
; node
= node
->next
) {
683 if (rosecmpm(addr
, &node
->address
, node
->mask
) == 0) {
684 for (i
= 0; i
< node
->count
; i
++) {
686 if (node
->neighbour
[i
]->restarted
) {
687 res
= node
->neighbour
[i
];
692 if (!rose_ftimer_running(node
->neighbour
[i
])) {
693 res
= node
->neighbour
[i
];
703 *cause
= ROSE_OUT_OF_ORDER
;
706 *cause
= ROSE_NOT_OBTAINABLE
;
711 if (!new) spin_unlock_bh(&rose_node_list_lock
);
717 * Handle the ioctls that control the routing functions.
719 int rose_rt_ioctl(unsigned int cmd
, void __user
*arg
)
721 struct rose_route_struct rose_route
;
722 struct net_device
*dev
;
727 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
729 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
731 if (rose_dev_exists(&rose_route
.address
)) /* Can't add routes to ourself */
733 if (rose_route
.mask
> 10) /* Mask can't be more than 10 digits */
735 if (rose_route
.ndigis
> AX25_MAX_DIGIS
)
737 err
= rose_add_node(&rose_route
, dev
);
741 if (copy_from_user(&rose_route
, arg
, sizeof(struct rose_route_struct
)))
743 if ((dev
= rose_ax25_dev_find(rose_route
.device
)) == NULL
)
745 err
= rose_del_node(&rose_route
, dev
);
749 return rose_clear_routes();
758 static void rose_del_route_by_neigh(struct rose_neigh
*rose_neigh
)
760 struct rose_route
*rose_route
, *s
;
762 rose_neigh
->restarted
= 0;
764 rose_stop_t0timer(rose_neigh
);
765 rose_start_ftimer(rose_neigh
);
767 skb_queue_purge(&rose_neigh
->queue
);
769 spin_lock_bh(&rose_route_list_lock
);
771 rose_route
= rose_route_list
;
773 while (rose_route
!= NULL
) {
774 if ((rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== rose_neigh
) ||
775 (rose_route
->neigh1
== rose_neigh
&& rose_route
->neigh2
== NULL
) ||
776 (rose_route
->neigh2
== rose_neigh
&& rose_route
->neigh1
== NULL
)) {
777 s
= rose_route
->next
;
778 rose_remove_route(rose_route
);
783 if (rose_route
->neigh1
== rose_neigh
) {
784 rose_route
->neigh1
->use
--;
785 rose_route
->neigh1
= NULL
;
786 rose_transmit_clear_request(rose_route
->neigh2
, rose_route
->lci2
, ROSE_OUT_OF_ORDER
, 0);
789 if (rose_route
->neigh2
== rose_neigh
) {
790 rose_route
->neigh2
->use
--;
791 rose_route
->neigh2
= NULL
;
792 rose_transmit_clear_request(rose_route
->neigh1
, rose_route
->lci1
, ROSE_OUT_OF_ORDER
, 0);
795 rose_route
= rose_route
->next
;
797 spin_unlock_bh(&rose_route_list_lock
);
801 * A level 2 link has timed out, therefore it appears to be a poor link,
802 * then don't use that neighbour until it is reset. Blow away all through
803 * routes and connections using this route.
805 void rose_link_failed(ax25_cb
*ax25
, int reason
)
807 struct rose_neigh
*rose_neigh
;
809 spin_lock_bh(&rose_neigh_list_lock
);
810 rose_neigh
= rose_neigh_list
;
811 while (rose_neigh
!= NULL
) {
812 if (rose_neigh
->ax25
== ax25
)
814 rose_neigh
= rose_neigh
->next
;
817 if (rose_neigh
!= NULL
) {
818 rose_neigh
->ax25
= NULL
;
821 rose_del_route_by_neigh(rose_neigh
);
822 rose_kill_by_neigh(rose_neigh
);
824 spin_unlock_bh(&rose_neigh_list_lock
);
828 * A device has been "downed" remove its link status. Blow away all
829 * through routes and connections that use this device.
831 void rose_link_device_down(struct net_device
*dev
)
833 struct rose_neigh
*rose_neigh
;
835 for (rose_neigh
= rose_neigh_list
; rose_neigh
!= NULL
; rose_neigh
= rose_neigh
->next
) {
836 if (rose_neigh
->dev
== dev
) {
837 rose_del_route_by_neigh(rose_neigh
);
838 rose_kill_by_neigh(rose_neigh
);
844 * Route a frame to an appropriate AX.25 connection.
846 int rose_route_frame(struct sk_buff
*skb
, ax25_cb
*ax25
)
848 struct rose_neigh
*rose_neigh
, *new_neigh
;
849 struct rose_route
*rose_route
;
850 struct rose_facilities_struct facilities
;
851 rose_address
*src_addr
, *dest_addr
;
853 unsigned short frametype
;
854 unsigned int lci
, new_lci
;
855 unsigned char cause
, diagnostic
;
856 struct net_device
*dev
;
861 if (call_in_firewall(PF_ROSE
, skb
->dev
, skb
->data
, NULL
, &skb
) != FW_ACCEPT
)
865 frametype
= skb
->data
[2];
866 lci
= ((skb
->data
[0] << 8) & 0xF00) + ((skb
->data
[1] << 0) & 0x0FF);
867 src_addr
= (rose_address
*)(skb
->data
+ 9);
868 dest_addr
= (rose_address
*)(skb
->data
+ 4);
870 spin_lock_bh(&rose_neigh_list_lock
);
871 spin_lock_bh(&rose_route_list_lock
);
873 rose_neigh
= rose_neigh_list
;
874 while (rose_neigh
!= NULL
) {
875 if (ax25cmp(&ax25
->dest_addr
, &rose_neigh
->callsign
) == 0 &&
876 ax25
->ax25_dev
->dev
== rose_neigh
->dev
)
878 rose_neigh
= rose_neigh
->next
;
881 if (rose_neigh
== NULL
) {
882 printk("rose_route : unknown neighbour or device %s\n",
883 ax2asc(buf
, &ax25
->dest_addr
));
888 * Obviously the link is working, halt the ftimer.
890 rose_stop_ftimer(rose_neigh
);
893 * LCI of zero is always for us, and its always a restart
897 rose_link_rx_restart(skb
, rose_neigh
, frametype
);
902 * Find an existing socket.
904 if ((sk
= rose_find_socket(lci
, rose_neigh
)) != NULL
) {
905 if (frametype
== ROSE_CALL_REQUEST
) {
906 struct rose_sock
*rose
= rose_sk(sk
);
908 /* Remove an existing unused socket */
909 rose_clear_queues(sk
);
910 rose
->cause
= ROSE_NETWORK_CONGESTION
;
911 rose
->diagnostic
= 0;
912 rose
->neighbour
->use
--;
913 rose
->neighbour
= NULL
;
915 rose
->state
= ROSE_STATE_0
;
916 sk
->sk_state
= TCP_CLOSE
;
918 sk
->sk_shutdown
|= SEND_SHUTDOWN
;
919 if (!sock_flag(sk
, SOCK_DEAD
)) {
920 sk
->sk_state_change(sk
);
921 sock_set_flag(sk
, SOCK_DEAD
);
925 skb_reset_transport_header(skb
);
926 res
= rose_process_rx_frame(sk
, skb
);
932 * Is is a Call Request and is it for us ?
934 if (frametype
== ROSE_CALL_REQUEST
)
935 if ((dev
= rose_dev_get(dest_addr
)) != NULL
) {
936 res
= rose_rx_call_request(skb
, dev
, rose_neigh
, lci
);
941 if (!sysctl_rose_routing_control
) {
942 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 0);
947 * Route it to the next in line if we have an entry for it.
949 rose_route
= rose_route_list
;
950 while (rose_route
!= NULL
) {
951 if (rose_route
->lci1
== lci
&&
952 rose_route
->neigh1
== rose_neigh
) {
953 if (frametype
== ROSE_CALL_REQUEST
) {
954 /* F6FBB - Remove an existing unused route */
955 rose_remove_route(rose_route
);
957 } else if (rose_route
->neigh2
!= NULL
) {
958 skb
->data
[0] &= 0xF0;
959 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
960 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
961 rose_transmit_link(skb
, rose_route
->neigh2
);
962 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
963 rose_remove_route(rose_route
);
967 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
968 rose_remove_route(rose_route
);
972 if (rose_route
->lci2
== lci
&&
973 rose_route
->neigh2
== rose_neigh
) {
974 if (frametype
== ROSE_CALL_REQUEST
) {
975 /* F6FBB - Remove an existing unused route */
976 rose_remove_route(rose_route
);
978 } else if (rose_route
->neigh1
!= NULL
) {
979 skb
->data
[0] &= 0xF0;
980 skb
->data
[0] |= (rose_route
->lci1
>> 8) & 0x0F;
981 skb
->data
[1] = (rose_route
->lci1
>> 0) & 0xFF;
982 rose_transmit_link(skb
, rose_route
->neigh1
);
983 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
984 rose_remove_route(rose_route
);
988 if (frametype
== ROSE_CLEAR_CONFIRMATION
)
989 rose_remove_route(rose_route
);
993 rose_route
= rose_route
->next
;
998 * 1. The frame isn't for us,
999 * 2. It isn't "owned" by any existing route.
1001 if (frametype
!= ROSE_CALL_REQUEST
) { /* XXX */
1006 len
= (((skb
->data
[3] >> 4) & 0x0F) + 1) >> 1;
1007 len
+= (((skb
->data
[3] >> 0) & 0x0F) + 1) >> 1;
1009 memset(&facilities
, 0x00, sizeof(struct rose_facilities_struct
));
1011 if (!rose_parse_facilities(skb
->data
+ len
+ 4, &facilities
)) {
1012 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_INVALID_FACILITY
, 76);
1017 * Check for routing loops.
1019 rose_route
= rose_route_list
;
1020 while (rose_route
!= NULL
) {
1021 if (rose_route
->rand
== facilities
.rand
&&
1022 rosecmp(src_addr
, &rose_route
->src_addr
) == 0 &&
1023 ax25cmp(&facilities
.dest_call
, &rose_route
->src_call
) == 0 &&
1024 ax25cmp(&facilities
.source_call
, &rose_route
->dest_call
) == 0) {
1025 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NOT_OBTAINABLE
, 120);
1028 rose_route
= rose_route
->next
;
1031 if ((new_neigh
= rose_get_neigh(dest_addr
, &cause
, &diagnostic
, 1)) == NULL
) {
1032 rose_transmit_clear_request(rose_neigh
, lci
, cause
, diagnostic
);
1036 if ((new_lci
= rose_new_lci(new_neigh
)) == 0) {
1037 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 71);
1041 if ((rose_route
= kmalloc(sizeof(*rose_route
), GFP_ATOMIC
)) == NULL
) {
1042 rose_transmit_clear_request(rose_neigh
, lci
, ROSE_NETWORK_CONGESTION
, 120);
1046 rose_route
->lci1
= lci
;
1047 rose_route
->src_addr
= *src_addr
;
1048 rose_route
->dest_addr
= *dest_addr
;
1049 rose_route
->src_call
= facilities
.dest_call
;
1050 rose_route
->dest_call
= facilities
.source_call
;
1051 rose_route
->rand
= facilities
.rand
;
1052 rose_route
->neigh1
= rose_neigh
;
1053 rose_route
->lci2
= new_lci
;
1054 rose_route
->neigh2
= new_neigh
;
1056 rose_route
->neigh1
->use
++;
1057 rose_route
->neigh2
->use
++;
1059 rose_route
->next
= rose_route_list
;
1060 rose_route_list
= rose_route
;
1062 skb
->data
[0] &= 0xF0;
1063 skb
->data
[0] |= (rose_route
->lci2
>> 8) & 0x0F;
1064 skb
->data
[1] = (rose_route
->lci2
>> 0) & 0xFF;
1066 rose_transmit_link(skb
, rose_route
->neigh2
);
1070 spin_unlock_bh(&rose_route_list_lock
);
1071 spin_unlock_bh(&rose_neigh_list_lock
);
1076 #ifdef CONFIG_PROC_FS
1078 static void *rose_node_start(struct seq_file
*seq
, loff_t
*pos
)
1079 __acquires(rose_node_list_lock
)
1081 struct rose_node
*rose_node
;
1084 spin_lock_bh(&rose_node_list_lock
);
1086 return SEQ_START_TOKEN
;
1088 for (rose_node
= rose_node_list
; rose_node
&& i
< *pos
;
1089 rose_node
= rose_node
->next
, ++i
);
1091 return (i
== *pos
) ? rose_node
: NULL
;
1094 static void *rose_node_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1098 return (v
== SEQ_START_TOKEN
) ? rose_node_list
1099 : ((struct rose_node
*)v
)->next
;
1102 static void rose_node_stop(struct seq_file
*seq
, void *v
)
1103 __releases(rose_node_list_lock
)
1105 spin_unlock_bh(&rose_node_list_lock
);
1108 static int rose_node_show(struct seq_file
*seq
, void *v
)
1113 if (v
== SEQ_START_TOKEN
)
1114 seq_puts(seq
, "address mask n neigh neigh neigh\n");
1116 const struct rose_node
*rose_node
= v
;
1117 /* if (rose_node->loopback) {
1118 seq_printf(seq, "%-10s %04d 1 loopback\n",
1119 rose2asc(rsbuf, &rose_node->address),
1122 seq_printf(seq
, "%-10s %04d %d",
1123 rose2asc(rsbuf
, &rose_node
->address
),
1127 for (i
= 0; i
< rose_node
->count
; i
++)
1128 seq_printf(seq
, " %05d",
1129 rose_node
->neighbour
[i
]->number
);
1131 seq_puts(seq
, "\n");
1137 static const struct seq_operations rose_node_seqops
= {
1138 .start
= rose_node_start
,
1139 .next
= rose_node_next
,
1140 .stop
= rose_node_stop
,
1141 .show
= rose_node_show
,
1144 static int rose_nodes_open(struct inode
*inode
, struct file
*file
)
1146 return seq_open(file
, &rose_node_seqops
);
1149 const struct file_operations rose_nodes_fops
= {
1150 .owner
= THIS_MODULE
,
1151 .open
= rose_nodes_open
,
1153 .llseek
= seq_lseek
,
1154 .release
= seq_release
,
1157 static void *rose_neigh_start(struct seq_file
*seq
, loff_t
*pos
)
1158 __acquires(rose_neigh_list_lock
)
1160 struct rose_neigh
*rose_neigh
;
1163 spin_lock_bh(&rose_neigh_list_lock
);
1165 return SEQ_START_TOKEN
;
1167 for (rose_neigh
= rose_neigh_list
; rose_neigh
&& i
< *pos
;
1168 rose_neigh
= rose_neigh
->next
, ++i
);
1170 return (i
== *pos
) ? rose_neigh
: NULL
;
1173 static void *rose_neigh_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1177 return (v
== SEQ_START_TOKEN
) ? rose_neigh_list
1178 : ((struct rose_neigh
*)v
)->next
;
1181 static void rose_neigh_stop(struct seq_file
*seq
, void *v
)
1182 __releases(rose_neigh_list_lock
)
1184 spin_unlock_bh(&rose_neigh_list_lock
);
1187 static int rose_neigh_show(struct seq_file
*seq
, void *v
)
1192 if (v
== SEQ_START_TOKEN
)
1194 "addr callsign dev count use mode restart t0 tf digipeaters\n");
1196 struct rose_neigh
*rose_neigh
= v
;
1198 /* if (!rose_neigh->loopback) { */
1199 seq_printf(seq
, "%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu",
1201 (rose_neigh
->loopback
) ? "RSLOOP-0" : ax2asc(buf
, &rose_neigh
->callsign
),
1202 rose_neigh
->dev
? rose_neigh
->dev
->name
: "???",
1205 (rose_neigh
->dce_mode
) ? "DCE" : "DTE",
1206 (rose_neigh
->restarted
) ? "yes" : "no",
1207 ax25_display_timer(&rose_neigh
->t0timer
) / HZ
,
1208 ax25_display_timer(&rose_neigh
->ftimer
) / HZ
);
1210 if (rose_neigh
->digipeat
!= NULL
) {
1211 for (i
= 0; i
< rose_neigh
->digipeat
->ndigi
; i
++)
1212 seq_printf(seq
, " %s", ax2asc(buf
, &rose_neigh
->digipeat
->calls
[i
]));
1215 seq_puts(seq
, "\n");
1221 static const struct seq_operations rose_neigh_seqops
= {
1222 .start
= rose_neigh_start
,
1223 .next
= rose_neigh_next
,
1224 .stop
= rose_neigh_stop
,
1225 .show
= rose_neigh_show
,
1228 static int rose_neigh_open(struct inode
*inode
, struct file
*file
)
1230 return seq_open(file
, &rose_neigh_seqops
);
1233 const struct file_operations rose_neigh_fops
= {
1234 .owner
= THIS_MODULE
,
1235 .open
= rose_neigh_open
,
1237 .llseek
= seq_lseek
,
1238 .release
= seq_release
,
1242 static void *rose_route_start(struct seq_file
*seq
, loff_t
*pos
)
1243 __acquires(rose_route_list_lock
)
1245 struct rose_route
*rose_route
;
1248 spin_lock_bh(&rose_route_list_lock
);
1250 return SEQ_START_TOKEN
;
1252 for (rose_route
= rose_route_list
; rose_route
&& i
< *pos
;
1253 rose_route
= rose_route
->next
, ++i
);
1255 return (i
== *pos
) ? rose_route
: NULL
;
1258 static void *rose_route_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1262 return (v
== SEQ_START_TOKEN
) ? rose_route_list
1263 : ((struct rose_route
*)v
)->next
;
1266 static void rose_route_stop(struct seq_file
*seq
, void *v
)
1267 __releases(rose_route_list_lock
)
1269 spin_unlock_bh(&rose_route_list_lock
);
1272 static int rose_route_show(struct seq_file
*seq
, void *v
)
1274 char buf
[11], rsbuf
[11];
1276 if (v
== SEQ_START_TOKEN
)
1278 "lci address callsign neigh <-> lci address callsign neigh\n");
1280 struct rose_route
*rose_route
= v
;
1282 if (rose_route
->neigh1
)
1284 "%3.3X %-10s %-9s %05d ",
1286 rose2asc(rsbuf
, &rose_route
->src_addr
),
1287 ax2asc(buf
, &rose_route
->src_call
),
1288 rose_route
->neigh1
->number
);
1293 if (rose_route
->neigh2
)
1295 "%3.3X %-10s %-9s %05d\n",
1297 rose2asc(rsbuf
, &rose_route
->dest_addr
),
1298 ax2asc(buf
, &rose_route
->dest_call
),
1299 rose_route
->neigh2
->number
);
1307 static const struct seq_operations rose_route_seqops
= {
1308 .start
= rose_route_start
,
1309 .next
= rose_route_next
,
1310 .stop
= rose_route_stop
,
1311 .show
= rose_route_show
,
1314 static int rose_route_open(struct inode
*inode
, struct file
*file
)
1316 return seq_open(file
, &rose_route_seqops
);
1319 const struct file_operations rose_routes_fops
= {
1320 .owner
= THIS_MODULE
,
1321 .open
= rose_route_open
,
1323 .llseek
= seq_lseek
,
1324 .release
= seq_release
,
1327 #endif /* CONFIG_PROC_FS */
1330 * Release all memory associated with ROSE routing structures.
1332 void __exit
rose_rt_free(void)
1334 struct rose_neigh
*s
, *rose_neigh
= rose_neigh_list
;
1335 struct rose_node
*t
, *rose_node
= rose_node_list
;
1336 struct rose_route
*u
, *rose_route
= rose_route_list
;
1338 while (rose_neigh
!= NULL
) {
1340 rose_neigh
= rose_neigh
->next
;
1342 rose_remove_neigh(s
);
1345 while (rose_node
!= NULL
) {
1347 rose_node
= rose_node
->next
;
1349 rose_remove_node(t
);
1352 while (rose_route
!= NULL
) {
1354 rose_route
= rose_route
->next
;
1356 rose_remove_route(u
);