10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/socket.h>
14 #include <linux/kernel.h>
16 #include <linux/string.h>
18 #include <linux/net.h>
19 #include <linux/slab.h>
22 #include <linux/netdevice.h>
24 #include <linux/if_arp.h>
28 #include <asm/uaccess.h>
29 #include <linux/fcntl.h>
34 #include <linux/netfilter.h>
38 #include <linux/export.h>
40 static unsigned int rose_neigh_no = 1;
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) &&
69 rose_route->
mask) == 0))
71 rose_node = rose_node->
next;
79 rose_neigh = rose_neigh_list;
80 while (rose_neigh !=
NULL) {
83 rose_neigh->
dev == dev)
85 rose_neigh = rose_neigh->
next;
88 if (rose_neigh ==
NULL) {
90 if (rose_neigh ==
NULL) {
99 rose_neigh->
count = 0;
103 rose_neigh->
number = rose_neigh_no++;
106 skb_queue_head_init(&rose_neigh->
queue);
111 if (rose_route->
ndigis != 0) {
123 for (i = 0; i < rose_route->
ndigis; i++) {
130 rose_neigh->
next = rose_neigh_list;
131 rose_neigh_list = rose_neigh;
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;
156 if (rose_node ==
NULL) {
163 rose_node->
count = 1;
167 if (rose_tmpn ==
NULL) {
168 if (rose_tmpp ==
NULL) {
169 rose_node_list = rose_node;
172 rose_tmpp->
next = rose_node;
176 if (rose_tmpp ==
NULL) {
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;
190 if (rose_node->
count < 3) {
197 spin_unlock_bh(&rose_neigh_list_lock);
198 spin_unlock_bh(&rose_node_list_lock);
210 if ((s = rose_node_list) == rose_node) {
211 rose_node_list = rose_node->
next;
217 if (s->
next == rose_node) {
232 struct rose_neigh *
s;
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);
249 if (s->
next == rose_neigh) {
251 if (rose_neigh->
ax25)
252 ax25_cb_put(rose_neigh->
ax25);
267 struct rose_route *
s;
270 rose_route->
neigh1->use--;
273 rose_route->
neigh2->use--;
275 if ((s = rose_route_list) == rose_route) {
276 rose_route_list = rose_route->
next;
282 if (s->
next == rose_route) {
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) &&
310 rose_route->
mask) == 0))
312 rose_node = rose_node->
next;
320 rose_neigh = rose_neigh_list;
321 while (rose_neigh !=
NULL) {
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);
363 spin_unlock_bh(&rose_neigh_list_lock);
364 spin_unlock_bh(&rose_node_list_lock);
374 struct rose_neigh *
sn;
377 if (!rose_loopback_neigh)
389 sn->
number = rose_neigh_no++;
392 skb_queue_head_init(&sn->
queue);
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);
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) &&
419 rose_node = rose_node->
next;
422 if (rose_node !=
NULL)
431 rose_node->
mask = 10;
432 rose_node->
count = 1;
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);
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) &&
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);
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++) {
522 rose_remove_neigh(s);
524 spin_unlock_bh(&rose_neigh_list_lock);
525 spin_unlock_bh(&rose_node_list_lock);
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;
543 rose_remove_route(s);
545 spin_unlock_bh(&rose_route_list_lock);
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;
578 rose_remove_neigh(s);
582 spin_unlock_bh(&rose_neigh_list_lock);
583 spin_unlock_bh(&rose_node_list_lock);
592 static struct net_device *rose_ax25_dev_find(
char *devname)
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))
677 unsigned char *diagnostic,
int route_frame)
680 struct rose_node *
node;
684 if (!route_frame) spin_lock_bh(&rose_node_list_lock);
685 for (node = rose_node_list; node !=
NULL; node = node->
next) {
687 for (i = 0; i < node->
count; i++) {
696 for (node = rose_node_list; node !=
NULL; node = node->
next) {
698 for (i = 0; i < node->
count; i++) {
719 if (!route_frame) spin_unlock_bh(&rose_node_list_lock);
736 if ((dev = rose_ax25_dev_find(rose_route.
device)) ==
NULL)
738 if (rose_dev_exists(&rose_route.
address))
740 if (rose_route.
mask > 10)
744 err = rose_add_node(&rose_route, dev);
750 if ((dev = rose_ax25_dev_find(rose_route.
device)) ==
NULL)
752 err = rose_del_node(&rose_route, dev);
756 return rose_clear_routes();
765 static void rose_del_route_by_neigh(
struct rose_neigh *rose_neigh)
767 struct rose_route *rose_route, *
s;
776 spin_lock_bh(&rose_route_list_lock);
778 rose_route = rose_route_list;
780 while (rose_route !=
NULL) {
781 if ((rose_route->
neigh1 == rose_neigh && rose_route->
neigh2 == rose_neigh) ||
784 s = rose_route->
next;
785 rose_remove_route(rose_route);
790 if (rose_route->
neigh1 == rose_neigh) {
791 rose_route->
neigh1->use--;
796 if (rose_route->
neigh2 == rose_neigh) {
797 rose_route->
neigh2->use--;
802 rose_route = rose_route->
next;
804 spin_unlock_bh(&rose_route_list_lock);
814 struct rose_neigh *rose_neigh;
816 spin_lock_bh(&rose_neigh_list_lock);
817 rose_neigh = rose_neigh_list;
818 while (rose_neigh !=
NULL) {
819 if (rose_neigh->
ax25 == ax25)
821 rose_neigh = rose_neigh->
next;
824 if (rose_neigh !=
NULL) {
828 rose_del_route_by_neigh(rose_neigh);
831 spin_unlock_bh(&rose_neigh_list_lock);
840 struct rose_neigh *rose_neigh;
842 for (rose_neigh = rose_neigh_list; rose_neigh !=
NULL; rose_neigh = rose_neigh->
next) {
843 if (rose_neigh->
dev == dev) {
844 rose_del_route_by_neigh(rose_neigh);
855 struct rose_neigh *rose_neigh, *new_neigh;
856 struct rose_route *rose_route;
860 unsigned short frametype;
861 unsigned int lci, new_lci;
862 unsigned char cause, diagnostic;
869 frametype = skb->
data[2];
870 lci = ((skb->
data[0] << 8) & 0xF00) + ((skb->
data[1] << 0) & 0x0FF);
879 spin_lock_bh(&rose_neigh_list_lock);
880 spin_lock_bh(&rose_route_list_lock);
882 rose_neigh = rose_neigh_list;
883 while (rose_neigh !=
NULL) {
887 rose_neigh = rose_neigh->
next;
890 if (rose_neigh ==
NULL) {
891 printk(
"rose_route : unknown neighbour or device %s\n",
934 skb_reset_transport_header(skb);
958 rose_route = rose_route_list;
959 while (rose_route !=
NULL) {
960 if (rose_route->
lci1 == lci &&
961 rose_route->
neigh1 == rose_neigh) {
964 rose_remove_route(rose_route);
967 skb->
data[0] &= 0xF0;
968 skb->
data[0] |= (rose_route->
lci2 >> 8) & 0x0F;
969 skb->
data[1] = (rose_route->
lci2 >> 0) & 0xFF;
972 rose_remove_route(rose_route);
977 rose_remove_route(rose_route);
981 if (rose_route->
lci2 == lci &&
982 rose_route->
neigh2 == rose_neigh) {
985 rose_remove_route(rose_route);
988 skb->
data[0] &= 0xF0;
989 skb->
data[0] |= (rose_route->
lci1 >> 8) & 0x0F;
990 skb->
data[1] = (rose_route->
lci1 >> 0) & 0xFF;
993 rose_remove_route(rose_route);
998 rose_remove_route(rose_route);
1002 rose_route = rose_route->
next;
1027 rose_route = rose_route_list;
1028 while (rose_route !=
NULL) {
1029 if (rose_route->
rand == facilities.
rand &&
1036 rose_route = rose_route->
next;
1059 rose_route->
rand = facilities.
rand;
1060 rose_route->
neigh1 = rose_neigh;
1061 rose_route->
lci2 = new_lci;
1062 rose_route->
neigh2 = new_neigh;
1064 rose_route->
neigh1->use++;
1065 rose_route->
neigh2->use++;
1067 rose_route->
next = rose_route_list;
1068 rose_route_list = rose_route;
1070 skb->
data[0] &= 0xF0;
1071 skb->
data[0] |= (rose_route->
lci2 >> 8) & 0x0F;
1072 skb->
data[1] = (rose_route->
lci2 >> 0) & 0xFF;
1078 spin_unlock_bh(&rose_route_list_lock);
1079 spin_unlock_bh(&rose_neigh_list_lock);
1084 #ifdef CONFIG_PROC_FS
1086 static void *rose_node_start(
struct seq_file *seq, loff_t *
pos)
1089 struct rose_node *rose_node;
1092 spin_lock_bh(&rose_node_list_lock);
1096 for (rose_node = rose_node_list; rose_node && i < *
pos;
1097 rose_node = rose_node->
next, ++
i);
1099 return (i == *pos) ? rose_node :
NULL;
1102 static void *rose_node_next(
struct seq_file *seq,
void *
v, loff_t *pos)
1107 : ((
struct rose_node *)v)->
next;
1110 static void rose_node_stop(
struct seq_file *seq,
void *v)
1113 spin_unlock_bh(&rose_node_list_lock);
1116 static int rose_node_show(
struct seq_file *seq,
void *v)
1122 seq_puts(seq,
"address mask n neigh neigh neigh\n");
1124 const struct rose_node *rose_node =
v;
1135 for (i = 0; i < rose_node->
count; i++)
1146 .
start = rose_node_start,
1147 .next = rose_node_next,
1148 .stop = rose_node_stop,
1149 .show = rose_node_show,
1154 return seq_open(file, &rose_node_seqops);
1159 .open = rose_nodes_open,
1165 static void *rose_neigh_start(
struct seq_file *seq, loff_t *pos)
1168 struct rose_neigh *rose_neigh;
1171 spin_lock_bh(&rose_neigh_list_lock);
1175 for (rose_neigh = rose_neigh_list; rose_neigh && i < *
pos;
1176 rose_neigh = rose_neigh->
next, ++
i);
1178 return (i == *pos) ? rose_neigh :
NULL;
1181 static void *rose_neigh_next(
struct seq_file *seq,
void *v, loff_t *pos)
1186 : ((
struct rose_neigh *)v)->
next;
1189 static void rose_neigh_stop(
struct seq_file *seq,
void *v)
1192 spin_unlock_bh(&rose_neigh_list_lock);
1195 static int rose_neigh_show(
struct seq_file *seq,
void *v)
1202 "addr callsign dev count use mode restart t0 tf digipeaters\n");
1204 struct rose_neigh *rose_neigh =
v;
1207 seq_printf(seq,
"%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu",
1210 rose_neigh->
dev ? rose_neigh->
dev->name :
"???",
1213 (rose_neigh->
dce_mode) ?
"DCE" :
"DTE",
1230 .
start = rose_neigh_start,
1231 .next = rose_neigh_next,
1232 .stop = rose_neigh_stop,
1233 .show = rose_neigh_show,
1238 return seq_open(file, &rose_neigh_seqops);
1243 .open = rose_neigh_open,
1250 static void *rose_route_start(
struct seq_file *seq, loff_t *pos)
1253 struct rose_route *rose_route;
1256 spin_lock_bh(&rose_route_list_lock);
1260 for (rose_route = rose_route_list; rose_route && i < *
pos;
1261 rose_route = rose_route->
next, ++
i);
1263 return (i == *pos) ? rose_route :
NULL;
1266 static void *rose_route_next(
struct seq_file *seq,
void *v, loff_t *pos)
1271 : ((
struct rose_route *)v)->
next;
1274 static void rose_route_stop(
struct seq_file *seq,
void *v)
1277 spin_unlock_bh(&rose_route_list_lock);
1280 static int rose_route_show(
struct seq_file *seq,
void *v)
1282 char buf[11], rsbuf[11];
1286 "lci address callsign neigh <-> lci address callsign neigh\n");
1288 struct rose_route *rose_route =
v;
1292 "%3.3X %-10s %-9s %05d ",
1296 rose_route->
neigh1->number);
1303 "%3.3X %-10s %-9s %05d\n",
1307 rose_route->
neigh2->number);
1316 .
start = rose_route_start,
1317 .next = rose_route_next,
1318 .stop = rose_route_stop,
1319 .show = rose_route_show,
1324 return seq_open(file, &rose_route_seqops);
1329 .open = rose_route_open,
1342 struct rose_neigh *
s, *rose_neigh = rose_neigh_list;
1343 struct rose_node *
t, *rose_node = rose_node_list;
1344 struct rose_route *
u, *rose_route = rose_route_list;
1346 while (rose_neigh !=
NULL) {
1348 rose_neigh = rose_neigh->
next;
1350 rose_remove_neigh(s);
1353 while (rose_node !=
NULL) {
1355 rose_node = rose_node->
next;
1357 rose_remove_node(t);
1360 while (rose_route !=
NULL) {
1362 rose_route = rose_route->
next;
1364 rose_remove_route(u);