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 <linux/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/init.h>
36 #include <linux/seq_file.h>
37 #include <linux/export.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 timer_setup(&rose_neigh->ftimer, NULL, 0);
108 timer_setup(&rose_neigh->t0timer, NULL, 0);
110 if (rose_route->ndigis != 0) {
111 rose_neigh->digipeat =
112 kmalloc(sizeof(ax25_digi), GFP_ATOMIC);
113 if (rose_neigh->digipeat == NULL) {
119 rose_neigh->digipeat->ndigi = rose_route->ndigis;
120 rose_neigh->digipeat->lastrepeat = -1;
122 for (i = 0; i < rose_route->ndigis; i++) {
123 rose_neigh->digipeat->calls[i] =
124 rose_route->digipeaters[i];
125 rose_neigh->digipeat->repeated[i] = 0;
129 rose_neigh->next = rose_neigh_list;
130 rose_neigh_list = rose_neigh;
134 * This is a new node to be inserted into the list. Find where it needs
135 * to be inserted into the list, and insert it. We want to be sure
136 * to order the list in descending order of mask size to ensure that
137 * later when we are searching this list the first match will be the
140 if (rose_node == NULL) {
141 rose_tmpn = rose_node_list;
144 while (rose_tmpn != NULL) {
145 if (rose_tmpn->mask > rose_route->mask) {
146 rose_tmpp = rose_tmpn;
147 rose_tmpn = rose_tmpn->next;
153 /* create new node */
154 rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC);
155 if (rose_node == NULL) {
160 rose_node->address = rose_route->address;
161 rose_node->mask = rose_route->mask;
162 rose_node->count = 1;
163 rose_node->loopback = 0;
164 rose_node->neighbour[0] = rose_neigh;
166 if (rose_tmpn == NULL) {
167 if (rose_tmpp == NULL) { /* Empty list */
168 rose_node_list = rose_node;
169 rose_node->next = NULL;
171 rose_tmpp->next = rose_node;
172 rose_node->next = NULL;
175 if (rose_tmpp == NULL) { /* 1st node */
176 rose_node->next = rose_node_list;
177 rose_node_list = rose_node;
179 rose_tmpp->next = rose_node;
180 rose_node->next = rose_tmpn;
188 /* We have space, slot it in */
189 if (rose_node->count < 3) {
190 rose_node->neighbour[rose_node->count] = rose_neigh;
196 spin_unlock_bh(&rose_neigh_list_lock);
197 spin_unlock_bh(&rose_node_list_lock);
203 * Caller is holding rose_node_list_lock.
205 static void rose_remove_node(struct rose_node *rose_node)
209 if ((s = rose_node_list) == rose_node) {
210 rose_node_list = rose_node->next;
215 while (s != NULL && s->next != NULL) {
216 if (s->next == rose_node) {
217 s->next = rose_node->next;
227 * Caller is holding rose_neigh_list_lock.
229 static void rose_remove_neigh(struct rose_neigh *rose_neigh)
231 struct rose_neigh *s;
233 rose_stop_ftimer(rose_neigh);
234 rose_stop_t0timer(rose_neigh);
236 skb_queue_purge(&rose_neigh->queue);
238 if ((s = rose_neigh_list) == rose_neigh) {
239 rose_neigh_list = rose_neigh->next;
240 if (rose_neigh->ax25)
241 ax25_cb_put(rose_neigh->ax25);
242 kfree(rose_neigh->digipeat);
247 while (s != NULL && s->next != NULL) {
248 if (s->next == rose_neigh) {
249 s->next = rose_neigh->next;
250 if (rose_neigh->ax25)
251 ax25_cb_put(rose_neigh->ax25);
252 kfree(rose_neigh->digipeat);
262 * Caller is holding rose_route_list_lock.
264 static void rose_remove_route(struct rose_route *rose_route)
266 struct rose_route *s;
268 if (rose_route->neigh1 != NULL)
269 rose_route->neigh1->use--;
271 if (rose_route->neigh2 != NULL)
272 rose_route->neigh2->use--;
274 if ((s = rose_route_list) == rose_route) {
275 rose_route_list = rose_route->next;
280 while (s != NULL && s->next != NULL) {
281 if (s->next == rose_route) {
282 s->next = rose_route->next;
292 * "Delete" a node. Strictly speaking remove a route to a node. The node
293 * is only deleted if no routes are left to it.
295 static int rose_del_node(struct rose_route_struct *rose_route,
296 struct net_device *dev)
298 struct rose_node *rose_node;
299 struct rose_neigh *rose_neigh;
302 spin_lock_bh(&rose_node_list_lock);
303 spin_lock_bh(&rose_neigh_list_lock);
305 rose_node = rose_node_list;
306 while (rose_node != NULL) {
307 if ((rose_node->mask == rose_route->mask) &&
308 (rosecmpm(&rose_route->address, &rose_node->address,
309 rose_route->mask) == 0))
311 rose_node = rose_node->next;
314 if (rose_node == NULL || rose_node->loopback) {
319 rose_neigh = rose_neigh_list;
320 while (rose_neigh != NULL) {
321 if (ax25cmp(&rose_route->neighbour,
322 &rose_neigh->callsign) == 0 &&
323 rose_neigh->dev == dev)
325 rose_neigh = rose_neigh->next;
328 if (rose_neigh == NULL) {
333 for (i = 0; i < rose_node->count; i++) {
334 if (rose_node->neighbour[i] == rose_neigh) {
337 if (rose_neigh->count == 0 && rose_neigh->use == 0)
338 rose_remove_neigh(rose_neigh);
342 if (rose_node->count == 0) {
343 rose_remove_node(rose_node);
347 rose_node->neighbour[0] =
348 rose_node->neighbour[1];
350 rose_node->neighbour[1] =
351 rose_node->neighbour[2];
362 spin_unlock_bh(&rose_neigh_list_lock);
363 spin_unlock_bh(&rose_node_list_lock);
369 * Add the loopback neighbour.
371 void rose_add_loopback_neigh(void)
373 struct rose_neigh *sn;
375 rose_loopback_neigh = kmalloc(sizeof(struct rose_neigh), GFP_KERNEL);
376 if (!rose_loopback_neigh)
378 sn = rose_loopback_neigh;
380 sn->callsign = null_ax25_address;
388 sn->number = rose_neigh_no++;
391 skb_queue_head_init(&sn->queue);
393 timer_setup(&sn->ftimer, NULL, 0);
394 timer_setup(&sn->t0timer, NULL, 0);
396 spin_lock_bh(&rose_neigh_list_lock);
397 sn->next = rose_neigh_list;
398 rose_neigh_list = sn;
399 spin_unlock_bh(&rose_neigh_list_lock);
403 * Add a loopback node.
405 int rose_add_loopback_node(rose_address *address)
407 struct rose_node *rose_node;
410 spin_lock_bh(&rose_node_list_lock);
412 rose_node = rose_node_list;
413 while (rose_node != NULL) {
414 if ((rose_node->mask == 10) &&
415 (rosecmpm(address, &rose_node->address, 10) == 0) &&
418 rose_node = rose_node->next;
421 if (rose_node != NULL)
424 if ((rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC)) == NULL) {
429 rose_node->address = *address;
430 rose_node->mask = 10;
431 rose_node->count = 1;
432 rose_node->loopback = 1;
433 rose_node->neighbour[0] = rose_loopback_neigh;
435 /* Insert at the head of list. Address is always mask=10 */
436 rose_node->next = rose_node_list;
437 rose_node_list = rose_node;
439 rose_loopback_neigh->count++;
442 spin_unlock_bh(&rose_node_list_lock);
448 * Delete a loopback node.
450 void rose_del_loopback_node(rose_address *address)
452 struct rose_node *rose_node;
454 spin_lock_bh(&rose_node_list_lock);
456 rose_node = rose_node_list;
457 while (rose_node != NULL) {
458 if ((rose_node->mask == 10) &&
459 (rosecmpm(address, &rose_node->address, 10) == 0) &&
462 rose_node = rose_node->next;
465 if (rose_node == NULL)
468 rose_remove_node(rose_node);
470 rose_loopback_neigh->count--;
473 spin_unlock_bh(&rose_node_list_lock);
477 * A device has been removed. Remove its routes and neighbours.
479 void rose_rt_device_down(struct net_device *dev)
481 struct rose_neigh *s, *rose_neigh;
482 struct rose_node *t, *rose_node;
485 spin_lock_bh(&rose_node_list_lock);
486 spin_lock_bh(&rose_neigh_list_lock);
487 rose_neigh = rose_neigh_list;
488 while (rose_neigh != NULL) {
490 rose_neigh = rose_neigh->next;
495 rose_node = rose_node_list;
497 while (rose_node != NULL) {
499 rose_node = rose_node->next;
501 for (i = 0; i < t->count; i++) {
502 if (t->neighbour[i] != s)
509 t->neighbour[0] = t->neighbour[1];
511 t->neighbour[1] = t->neighbour[2];
521 rose_remove_neigh(s);
523 spin_unlock_bh(&rose_neigh_list_lock);
524 spin_unlock_bh(&rose_node_list_lock);
527 #if 0 /* Currently unused */
529 * A device has been removed. Remove its links.
531 void rose_route_device_down(struct net_device *dev)
533 struct rose_route *s, *rose_route;
535 spin_lock_bh(&rose_route_list_lock);
536 rose_route = rose_route_list;
537 while (rose_route != NULL) {
539 rose_route = rose_route->next;
541 if (s->neigh1->dev == dev || s->neigh2->dev == dev)
542 rose_remove_route(s);
544 spin_unlock_bh(&rose_route_list_lock);
549 * Clear all nodes and neighbours out, except for neighbours with
550 * active connections going through them.
551 * Do not clear loopback neighbour and nodes.
553 static int rose_clear_routes(void)
555 struct rose_neigh *s, *rose_neigh;
556 struct rose_node *t, *rose_node;
558 spin_lock_bh(&rose_node_list_lock);
559 spin_lock_bh(&rose_neigh_list_lock);
561 rose_neigh = rose_neigh_list;
562 rose_node = rose_node_list;
564 while (rose_node != NULL) {
566 rose_node = rose_node->next;
571 while (rose_neigh != NULL) {
573 rose_neigh = rose_neigh->next;
575 if (s->use == 0 && !s->loopback) {
577 rose_remove_neigh(s);
581 spin_unlock_bh(&rose_neigh_list_lock);
582 spin_unlock_bh(&rose_node_list_lock);
588 * Check that the device given is a valid AX.25 interface that is "up".
591 static struct net_device *rose_ax25_dev_find(char *devname)
593 struct net_device *dev;
595 if ((dev = __dev_get_by_name(&init_net, devname)) == NULL)
598 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_AX25)
605 * Find the first active ROSE device, usually "rose0".
607 struct net_device *rose_dev_first(void)
609 struct net_device *dev, *first = NULL;
612 for_each_netdev_rcu(&init_net, dev) {
613 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE)
614 if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
623 * Find the ROSE device for the given address.
625 struct net_device *rose_dev_get(rose_address *addr)
627 struct net_device *dev;
630 for_each_netdev_rcu(&init_net, dev) {
631 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) {
642 static int rose_dev_exists(rose_address *addr)
644 struct net_device *dev;
647 for_each_netdev_rcu(&init_net, dev) {
648 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0)
660 struct rose_route *rose_route_free_lci(unsigned int lci, struct rose_neigh *neigh)
662 struct rose_route *rose_route;
664 for (rose_route = rose_route_list; rose_route != NULL; rose_route = rose_route->next)
665 if ((rose_route->neigh1 == neigh && rose_route->lci1 == lci) ||
666 (rose_route->neigh2 == neigh && rose_route->lci2 == lci))
673 * Find a neighbour or a route given a ROSE address.
675 struct rose_neigh *rose_get_neigh(rose_address *addr, unsigned char *cause,
676 unsigned char *diagnostic, int route_frame)
678 struct rose_neigh *res = NULL;
679 struct rose_node *node;
683 if (!route_frame) spin_lock_bh(&rose_node_list_lock);
684 for (node = rose_node_list; node != NULL; node = node->next) {
685 if (rosecmpm(addr, &node->address, node->mask) == 0) {
686 for (i = 0; i < node->count; i++) {
687 if (node->neighbour[i]->restarted) {
688 res = node->neighbour[i];
694 if (!route_frame) { /* connect request */
695 for (node = rose_node_list; node != NULL; node = node->next) {
696 if (rosecmpm(addr, &node->address, node->mask) == 0) {
697 for (i = 0; i < node->count; i++) {
698 if (!rose_ftimer_running(node->neighbour[i])) {
699 res = node->neighbour[i];
710 *cause = ROSE_OUT_OF_ORDER;
713 *cause = ROSE_NOT_OBTAINABLE;
718 if (!route_frame) spin_unlock_bh(&rose_node_list_lock);
723 * Handle the ioctls that control the routing functions.
725 int rose_rt_ioctl(unsigned int cmd, void __user *arg)
727 struct rose_route_struct rose_route;
728 struct net_device *dev;
733 if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct)))
735 if ((dev = rose_ax25_dev_find(rose_route.device)) == NULL)
737 if (rose_dev_exists(&rose_route.address)) /* Can't add routes to ourself */
739 if (rose_route.mask > 10) /* Mask can't be more than 10 digits */
741 if (rose_route.ndigis > AX25_MAX_DIGIS)
743 err = rose_add_node(&rose_route, dev);
747 if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct)))
749 if ((dev = rose_ax25_dev_find(rose_route.device)) == NULL)
751 err = rose_del_node(&rose_route, dev);
755 return rose_clear_routes();
764 static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh)
766 struct rose_route *rose_route, *s;
768 rose_neigh->restarted = 0;
770 rose_stop_t0timer(rose_neigh);
771 rose_start_ftimer(rose_neigh);
773 skb_queue_purge(&rose_neigh->queue);
775 spin_lock_bh(&rose_route_list_lock);
777 rose_route = rose_route_list;
779 while (rose_route != NULL) {
780 if ((rose_route->neigh1 == rose_neigh && rose_route->neigh2 == rose_neigh) ||
781 (rose_route->neigh1 == rose_neigh && rose_route->neigh2 == NULL) ||
782 (rose_route->neigh2 == rose_neigh && rose_route->neigh1 == NULL)) {
783 s = rose_route->next;
784 rose_remove_route(rose_route);
789 if (rose_route->neigh1 == rose_neigh) {
790 rose_route->neigh1->use--;
791 rose_route->neigh1 = NULL;
792 rose_transmit_clear_request(rose_route->neigh2, rose_route->lci2, ROSE_OUT_OF_ORDER, 0);
795 if (rose_route->neigh2 == rose_neigh) {
796 rose_route->neigh2->use--;
797 rose_route->neigh2 = NULL;
798 rose_transmit_clear_request(rose_route->neigh1, rose_route->lci1, ROSE_OUT_OF_ORDER, 0);
801 rose_route = rose_route->next;
803 spin_unlock_bh(&rose_route_list_lock);
807 * A level 2 link has timed out, therefore it appears to be a poor link,
808 * then don't use that neighbour until it is reset. Blow away all through
809 * routes and connections using this route.
811 void rose_link_failed(ax25_cb *ax25, int reason)
813 struct rose_neigh *rose_neigh;
815 spin_lock_bh(&rose_neigh_list_lock);
816 rose_neigh = rose_neigh_list;
817 while (rose_neigh != NULL) {
818 if (rose_neigh->ax25 == ax25)
820 rose_neigh = rose_neigh->next;
823 if (rose_neigh != NULL) {
824 rose_neigh->ax25 = NULL;
827 rose_del_route_by_neigh(rose_neigh);
828 rose_kill_by_neigh(rose_neigh);
830 spin_unlock_bh(&rose_neigh_list_lock);
834 * A device has been "downed" remove its link status. Blow away all
835 * through routes and connections that use this device.
837 void rose_link_device_down(struct net_device *dev)
839 struct rose_neigh *rose_neigh;
841 for (rose_neigh = rose_neigh_list; rose_neigh != NULL; rose_neigh = rose_neigh->next) {
842 if (rose_neigh->dev == dev) {
843 rose_del_route_by_neigh(rose_neigh);
844 rose_kill_by_neigh(rose_neigh);
850 * Route a frame to an appropriate AX.25 connection.
851 * A NULL ax25_cb indicates an internally generated frame.
853 int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
855 struct rose_neigh *rose_neigh, *new_neigh;
856 struct rose_route *rose_route;
857 struct rose_facilities_struct facilities;
858 rose_address *src_addr, *dest_addr;
860 unsigned short frametype;
861 unsigned int lci, new_lci;
862 unsigned char cause, diagnostic;
863 struct net_device *dev;
867 if (skb->len < ROSE_MIN_LEN)
871 return rose_loopback_queue(skb, NULL);
873 frametype = skb->data[2];
874 lci = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
875 if (frametype == ROSE_CALL_REQUEST &&
876 (skb->len <= ROSE_CALL_REQ_FACILITIES_OFF ||
877 skb->data[ROSE_CALL_REQ_ADDR_LEN_OFF] !=
878 ROSE_CALL_REQ_ADDR_LEN_VAL))
880 src_addr = (rose_address *)(skb->data + ROSE_CALL_REQ_SRC_ADDR_OFF);
881 dest_addr = (rose_address *)(skb->data + ROSE_CALL_REQ_DEST_ADDR_OFF);
883 spin_lock_bh(&rose_neigh_list_lock);
884 spin_lock_bh(&rose_route_list_lock);
886 rose_neigh = rose_neigh_list;
887 while (rose_neigh != NULL) {
888 if (ax25cmp(&ax25->dest_addr, &rose_neigh->callsign) == 0 &&
889 ax25->ax25_dev->dev == rose_neigh->dev)
891 rose_neigh = rose_neigh->next;
894 if (rose_neigh == NULL) {
895 printk("rose_route : unknown neighbour or device %s\n",
896 ax2asc(buf, &ax25->dest_addr));
901 * Obviously the link is working, halt the ftimer.
903 rose_stop_ftimer(rose_neigh);
906 * LCI of zero is always for us, and its always a restart
910 rose_link_rx_restart(skb, rose_neigh, frametype);
915 * Find an existing socket.
917 if ((sk = rose_find_socket(lci, rose_neigh)) != NULL) {
918 if (frametype == ROSE_CALL_REQUEST) {
919 struct rose_sock *rose = rose_sk(sk);
921 /* Remove an existing unused socket */
922 rose_clear_queues(sk);
923 rose->cause = ROSE_NETWORK_CONGESTION;
924 rose->diagnostic = 0;
925 rose->neighbour->use--;
926 rose->neighbour = NULL;
928 rose->state = ROSE_STATE_0;
929 sk->sk_state = TCP_CLOSE;
931 sk->sk_shutdown |= SEND_SHUTDOWN;
932 if (!sock_flag(sk, SOCK_DEAD)) {
933 sk->sk_state_change(sk);
934 sock_set_flag(sk, SOCK_DEAD);
938 skb_reset_transport_header(skb);
939 res = rose_process_rx_frame(sk, skb);
945 * Is is a Call Request and is it for us ?
947 if (frametype == ROSE_CALL_REQUEST)
948 if ((dev = rose_dev_get(dest_addr)) != NULL) {
949 res = rose_rx_call_request(skb, dev, rose_neigh, lci);
954 if (!sysctl_rose_routing_control) {
955 rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 0);
960 * Route it to the next in line if we have an entry for it.
962 rose_route = rose_route_list;
963 while (rose_route != NULL) {
964 if (rose_route->lci1 == lci &&
965 rose_route->neigh1 == rose_neigh) {
966 if (frametype == ROSE_CALL_REQUEST) {
967 /* F6FBB - Remove an existing unused route */
968 rose_remove_route(rose_route);
970 } else if (rose_route->neigh2 != NULL) {
971 skb->data[0] &= 0xF0;
972 skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F;
973 skb->data[1] = (rose_route->lci2 >> 0) & 0xFF;
974 rose_transmit_link(skb, rose_route->neigh2);
975 if (frametype == ROSE_CLEAR_CONFIRMATION)
976 rose_remove_route(rose_route);
980 if (frametype == ROSE_CLEAR_CONFIRMATION)
981 rose_remove_route(rose_route);
985 if (rose_route->lci2 == lci &&
986 rose_route->neigh2 == rose_neigh) {
987 if (frametype == ROSE_CALL_REQUEST) {
988 /* F6FBB - Remove an existing unused route */
989 rose_remove_route(rose_route);
991 } else if (rose_route->neigh1 != NULL) {
992 skb->data[0] &= 0xF0;
993 skb->data[0] |= (rose_route->lci1 >> 8) & 0x0F;
994 skb->data[1] = (rose_route->lci1 >> 0) & 0xFF;
995 rose_transmit_link(skb, rose_route->neigh1);
996 if (frametype == ROSE_CLEAR_CONFIRMATION)
997 rose_remove_route(rose_route);
1001 if (frametype == ROSE_CLEAR_CONFIRMATION)
1002 rose_remove_route(rose_route);
1006 rose_route = rose_route->next;
1011 * 1. The frame isn't for us,
1012 * 2. It isn't "owned" by any existing route.
1014 if (frametype != ROSE_CALL_REQUEST) { /* XXX */
1019 memset(&facilities, 0x00, sizeof(struct rose_facilities_struct));
1021 if (!rose_parse_facilities(skb->data + ROSE_CALL_REQ_FACILITIES_OFF,
1022 skb->len - ROSE_CALL_REQ_FACILITIES_OFF,
1024 rose_transmit_clear_request(rose_neigh, lci, ROSE_INVALID_FACILITY, 76);
1029 * Check for routing loops.
1031 rose_route = rose_route_list;
1032 while (rose_route != NULL) {
1033 if (rose_route->rand == facilities.rand &&
1034 rosecmp(src_addr, &rose_route->src_addr) == 0 &&
1035 ax25cmp(&facilities.dest_call, &rose_route->src_call) == 0 &&
1036 ax25cmp(&facilities.source_call, &rose_route->dest_call) == 0) {
1037 rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 120);
1040 rose_route = rose_route->next;
1043 if ((new_neigh = rose_get_neigh(dest_addr, &cause, &diagnostic, 1)) == NULL) {
1044 rose_transmit_clear_request(rose_neigh, lci, cause, diagnostic);
1048 if ((new_lci = rose_new_lci(new_neigh)) == 0) {
1049 rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 71);
1053 if ((rose_route = kmalloc(sizeof(*rose_route), GFP_ATOMIC)) == NULL) {
1054 rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 120);
1058 rose_route->lci1 = lci;
1059 rose_route->src_addr = *src_addr;
1060 rose_route->dest_addr = *dest_addr;
1061 rose_route->src_call = facilities.dest_call;
1062 rose_route->dest_call = facilities.source_call;
1063 rose_route->rand = facilities.rand;
1064 rose_route->neigh1 = rose_neigh;
1065 rose_route->lci2 = new_lci;
1066 rose_route->neigh2 = new_neigh;
1068 rose_route->neigh1->use++;
1069 rose_route->neigh2->use++;
1071 rose_route->next = rose_route_list;
1072 rose_route_list = rose_route;
1074 skb->data[0] &= 0xF0;
1075 skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F;
1076 skb->data[1] = (rose_route->lci2 >> 0) & 0xFF;
1078 rose_transmit_link(skb, rose_route->neigh2);
1082 spin_unlock_bh(&rose_route_list_lock);
1083 spin_unlock_bh(&rose_neigh_list_lock);
1088 #ifdef CONFIG_PROC_FS
1090 static void *rose_node_start(struct seq_file *seq, loff_t *pos)
1091 __acquires(rose_node_list_lock)
1093 struct rose_node *rose_node;
1096 spin_lock_bh(&rose_node_list_lock);
1098 return SEQ_START_TOKEN;
1100 for (rose_node = rose_node_list; rose_node && i < *pos;
1101 rose_node = rose_node->next, ++i);
1103 return (i == *pos) ? rose_node : NULL;
1106 static void *rose_node_next(struct seq_file *seq, void *v, loff_t *pos)
1110 return (v == SEQ_START_TOKEN) ? rose_node_list
1111 : ((struct rose_node *)v)->next;
1114 static void rose_node_stop(struct seq_file *seq, void *v)
1115 __releases(rose_node_list_lock)
1117 spin_unlock_bh(&rose_node_list_lock);
1120 static int rose_node_show(struct seq_file *seq, void *v)
1125 if (v == SEQ_START_TOKEN)
1126 seq_puts(seq, "address mask n neigh neigh neigh\n");
1128 const struct rose_node *rose_node = v;
1129 /* if (rose_node->loopback) {
1130 seq_printf(seq, "%-10s %04d 1 loopback\n",
1131 rose2asc(rsbuf, &rose_node->address),
1134 seq_printf(seq, "%-10s %04d %d",
1135 rose2asc(rsbuf, &rose_node->address),
1139 for (i = 0; i < rose_node->count; i++)
1140 seq_printf(seq, " %05d",
1141 rose_node->neighbour[i]->number);
1143 seq_puts(seq, "\n");
1149 static const struct seq_operations rose_node_seqops = {
1150 .start = rose_node_start,
1151 .next = rose_node_next,
1152 .stop = rose_node_stop,
1153 .show = rose_node_show,
1156 static int rose_nodes_open(struct inode *inode, struct file *file)
1158 return seq_open(file, &rose_node_seqops);
1161 const struct file_operations rose_nodes_fops = {
1162 .owner = THIS_MODULE,
1163 .open = rose_nodes_open,
1165 .llseek = seq_lseek,
1166 .release = seq_release,
1169 static void *rose_neigh_start(struct seq_file *seq, loff_t *pos)
1170 __acquires(rose_neigh_list_lock)
1172 struct rose_neigh *rose_neigh;
1175 spin_lock_bh(&rose_neigh_list_lock);
1177 return SEQ_START_TOKEN;
1179 for (rose_neigh = rose_neigh_list; rose_neigh && i < *pos;
1180 rose_neigh = rose_neigh->next, ++i);
1182 return (i == *pos) ? rose_neigh : NULL;
1185 static void *rose_neigh_next(struct seq_file *seq, void *v, loff_t *pos)
1189 return (v == SEQ_START_TOKEN) ? rose_neigh_list
1190 : ((struct rose_neigh *)v)->next;
1193 static void rose_neigh_stop(struct seq_file *seq, void *v)
1194 __releases(rose_neigh_list_lock)
1196 spin_unlock_bh(&rose_neigh_list_lock);
1199 static int rose_neigh_show(struct seq_file *seq, void *v)
1204 if (v == SEQ_START_TOKEN)
1206 "addr callsign dev count use mode restart t0 tf digipeaters\n");
1208 struct rose_neigh *rose_neigh = v;
1210 /* if (!rose_neigh->loopback) { */
1211 seq_printf(seq, "%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu",
1213 (rose_neigh->loopback) ? "RSLOOP-0" : ax2asc(buf, &rose_neigh->callsign),
1214 rose_neigh->dev ? rose_neigh->dev->name : "???",
1217 (rose_neigh->dce_mode) ? "DCE" : "DTE",
1218 (rose_neigh->restarted) ? "yes" : "no",
1219 ax25_display_timer(&rose_neigh->t0timer) / HZ,
1220 ax25_display_timer(&rose_neigh->ftimer) / HZ);
1222 if (rose_neigh->digipeat != NULL) {
1223 for (i = 0; i < rose_neigh->digipeat->ndigi; i++)
1224 seq_printf(seq, " %s", ax2asc(buf, &rose_neigh->digipeat->calls[i]));
1227 seq_puts(seq, "\n");
1233 static const struct seq_operations rose_neigh_seqops = {
1234 .start = rose_neigh_start,
1235 .next = rose_neigh_next,
1236 .stop = rose_neigh_stop,
1237 .show = rose_neigh_show,
1240 static int rose_neigh_open(struct inode *inode, struct file *file)
1242 return seq_open(file, &rose_neigh_seqops);
1245 const struct file_operations rose_neigh_fops = {
1246 .owner = THIS_MODULE,
1247 .open = rose_neigh_open,
1249 .llseek = seq_lseek,
1250 .release = seq_release,
1254 static void *rose_route_start(struct seq_file *seq, loff_t *pos)
1255 __acquires(rose_route_list_lock)
1257 struct rose_route *rose_route;
1260 spin_lock_bh(&rose_route_list_lock);
1262 return SEQ_START_TOKEN;
1264 for (rose_route = rose_route_list; rose_route && i < *pos;
1265 rose_route = rose_route->next, ++i);
1267 return (i == *pos) ? rose_route : NULL;
1270 static void *rose_route_next(struct seq_file *seq, void *v, loff_t *pos)
1274 return (v == SEQ_START_TOKEN) ? rose_route_list
1275 : ((struct rose_route *)v)->next;
1278 static void rose_route_stop(struct seq_file *seq, void *v)
1279 __releases(rose_route_list_lock)
1281 spin_unlock_bh(&rose_route_list_lock);
1284 static int rose_route_show(struct seq_file *seq, void *v)
1286 char buf[11], rsbuf[11];
1288 if (v == SEQ_START_TOKEN)
1290 "lci address callsign neigh <-> lci address callsign neigh\n");
1292 struct rose_route *rose_route = v;
1294 if (rose_route->neigh1)
1296 "%3.3X %-10s %-9s %05d ",
1298 rose2asc(rsbuf, &rose_route->src_addr),
1299 ax2asc(buf, &rose_route->src_call),
1300 rose_route->neigh1->number);
1305 if (rose_route->neigh2)
1307 "%3.3X %-10s %-9s %05d\n",
1309 rose2asc(rsbuf, &rose_route->dest_addr),
1310 ax2asc(buf, &rose_route->dest_call),
1311 rose_route->neigh2->number);
1319 static const struct seq_operations rose_route_seqops = {
1320 .start = rose_route_start,
1321 .next = rose_route_next,
1322 .stop = rose_route_stop,
1323 .show = rose_route_show,
1326 static int rose_route_open(struct inode *inode, struct file *file)
1328 return seq_open(file, &rose_route_seqops);
1331 const struct file_operations rose_routes_fops = {
1332 .owner = THIS_MODULE,
1333 .open = rose_route_open,
1335 .llseek = seq_lseek,
1336 .release = seq_release,
1339 #endif /* CONFIG_PROC_FS */
1342 * Release all memory associated with ROSE routing structures.
1344 void __exit rose_rt_free(void)
1346 struct rose_neigh *s, *rose_neigh = rose_neigh_list;
1347 struct rose_node *t, *rose_node = rose_node_list;
1348 struct rose_route *u, *rose_route = rose_route_list;
1350 while (rose_neigh != NULL) {
1352 rose_neigh = rose_neigh->next;
1354 rose_remove_neigh(s);
1357 while (rose_node != NULL) {
1359 rose_node = rose_node->next;
1361 rose_remove_node(t);
1364 while (rose_route != NULL) {
1366 rose_route = rose_route->next;
1368 rose_remove_route(u);