rose_route.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. /*
  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.
  6. *
  7. * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  8. * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net)
  9. */
  10. #include <linux/errno.h>
  11. #include <linux/types.h>
  12. #include <linux/socket.h>
  13. #include <linux/in.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>
  20. #include <net/ax25.h>
  21. #include <linux/inet.h>
  22. #include <linux/netdevice.h>
  23. #include <net/arp.h>
  24. #include <linux/if_arp.h>
  25. #include <linux/skbuff.h>
  26. #include <net/sock.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 */
  32. #include <linux/mm.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/notifier.h>
  35. #include <linux/netfilter.h>
  36. #include <linux/init.h>
  37. #include <net/rose.h>
  38. #include <linux/seq_file.h>
  39. static unsigned int rose_neigh_no = 1;
  40. static struct rose_node *rose_node_list;
  41. static DEFINE_SPINLOCK(rose_node_list_lock);
  42. static struct rose_neigh *rose_neigh_list;
  43. static DEFINE_SPINLOCK(rose_neigh_list_lock);
  44. static struct rose_route *rose_route_list;
  45. static DEFINE_SPINLOCK(rose_route_list_lock);
  46. struct rose_neigh *rose_loopback_neigh;
  47. /*
  48. * Add a new route to a node, and in the process add the node and the
  49. * neighbour if it is new.
  50. */
  51. static int __must_check rose_add_node(struct rose_route_struct *rose_route,
  52. struct net_device *dev)
  53. {
  54. struct rose_node *rose_node, *rose_tmpn, *rose_tmpp;
  55. struct rose_neigh *rose_neigh;
  56. int i, res = 0;
  57. spin_lock_bh(&rose_node_list_lock);
  58. spin_lock_bh(&rose_neigh_list_lock);
  59. rose_node = rose_node_list;
  60. while (rose_node != NULL) {
  61. if ((rose_node->mask == rose_route->mask) &&
  62. (rosecmpm(&rose_route->address, &rose_node->address,
  63. rose_route->mask) == 0))
  64. break;
  65. rose_node = rose_node->next;
  66. }
  67. if (rose_node != NULL && rose_node->loopback) {
  68. res = -EINVAL;
  69. goto out;
  70. }
  71. rose_neigh = rose_neigh_list;
  72. while (rose_neigh != NULL) {
  73. if (ax25cmp(&rose_route->neighbour,
  74. &rose_neigh->callsign) == 0 &&
  75. rose_neigh->dev == dev)
  76. break;
  77. rose_neigh = rose_neigh->next;
  78. }
  79. if (rose_neigh == NULL) {
  80. rose_neigh = kmalloc(sizeof(*rose_neigh), GFP_ATOMIC);
  81. if (rose_neigh == NULL) {
  82. res = -ENOMEM;
  83. goto out;
  84. }
  85. rose_neigh->callsign = rose_route->neighbour;
  86. rose_neigh->digipeat = NULL;
  87. rose_neigh->ax25 = NULL;
  88. rose_neigh->dev = dev;
  89. rose_neigh->count = 0;
  90. rose_neigh->use = 0;
  91. rose_neigh->dce_mode = 0;
  92. rose_neigh->loopback = 0;
  93. rose_neigh->number = rose_neigh_no++;
  94. rose_neigh->restarted = 0;
  95. skb_queue_head_init(&rose_neigh->queue);
  96. init_timer(&rose_neigh->ftimer);
  97. init_timer(&rose_neigh->t0timer);
  98. if (rose_route->ndigis != 0) {
  99. rose_neigh->digipeat =
  100. kmalloc(sizeof(ax25_digi), GFP_ATOMIC);
  101. if (rose_neigh->digipeat == NULL) {
  102. kfree(rose_neigh);
  103. res = -ENOMEM;
  104. goto out;
  105. }
  106. rose_neigh->digipeat->ndigi = rose_route->ndigis;
  107. rose_neigh->digipeat->lastrepeat = -1;
  108. for (i = 0; i < rose_route->ndigis; i++) {
  109. rose_neigh->digipeat->calls[i] =
  110. rose_route->digipeaters[i];
  111. rose_neigh->digipeat->repeated[i] = 0;
  112. }
  113. }
  114. rose_neigh->next = rose_neigh_list;
  115. rose_neigh_list = rose_neigh;
  116. }
  117. /*
  118. * This is a new node to be inserted into the list. Find where it needs
  119. * to be inserted into the list, and insert it. We want to be sure
  120. * to order the list in descending order of mask size to ensure that
  121. * later when we are searching this list the first match will be the
  122. * best match.
  123. */
  124. if (rose_node == NULL) {
  125. rose_tmpn = rose_node_list;
  126. rose_tmpp = NULL;
  127. while (rose_tmpn != NULL) {
  128. if (rose_tmpn->mask > rose_route->mask) {
  129. rose_tmpp = rose_tmpn;
  130. rose_tmpn = rose_tmpn->next;
  131. } else {
  132. break;
  133. }
  134. }
  135. /* create new node */
  136. rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC);
  137. if (rose_node == NULL) {
  138. res = -ENOMEM;
  139. goto out;
  140. }
  141. rose_node->address = rose_route->address;
  142. rose_node->mask = rose_route->mask;
  143. rose_node->count = 1;
  144. rose_node->loopback = 0;
  145. rose_node->neighbour[0] = rose_neigh;
  146. if (rose_tmpn == NULL) {
  147. if (rose_tmpp == NULL) { /* Empty list */
  148. rose_node_list = rose_node;
  149. rose_node->next = NULL;
  150. } else {
  151. rose_tmpp->next = rose_node;
  152. rose_node->next = NULL;
  153. }
  154. } else {
  155. if (rose_tmpp == NULL) { /* 1st node */
  156. rose_node->next = rose_node_list;
  157. rose_node_list = rose_node;
  158. } else {
  159. rose_tmpp->next = rose_node;
  160. rose_node->next = rose_tmpn;
  161. }
  162. }
  163. rose_neigh->count++;
  164. goto out;
  165. }
  166. /* We have space, slot it in */
  167. if (rose_node->count < 3) {
  168. rose_node->neighbour[rose_node->count] = rose_neigh;
  169. rose_node->count++;
  170. rose_neigh->count++;
  171. }
  172. out:
  173. spin_unlock_bh(&rose_neigh_list_lock);
  174. spin_unlock_bh(&rose_node_list_lock);
  175. return res;
  176. }
  177. /*
  178. * Caller is holding rose_node_list_lock.
  179. */
  180. static void rose_remove_node(struct rose_node *rose_node)
  181. {
  182. struct rose_node *s;
  183. if ((s = rose_node_list) == rose_node) {
  184. rose_node_list = rose_node->next;
  185. kfree(rose_node);
  186. return;
  187. }
  188. while (s != NULL && s->next != NULL) {
  189. if (s->next == rose_node) {
  190. s->next = rose_node->next;
  191. kfree(rose_node);
  192. return;
  193. }
  194. s = s->next;
  195. }
  196. }
  197. /*
  198. * Caller is holding rose_neigh_list_lock.
  199. */
  200. static void rose_remove_neigh(struct rose_neigh *rose_neigh)
  201. {
  202. struct rose_neigh *s;
  203. rose_stop_ftimer(rose_neigh);
  204. rose_stop_t0timer(rose_neigh);
  205. skb_queue_purge(&rose_neigh->queue);
  206. if ((s = rose_neigh_list) == rose_neigh) {
  207. rose_neigh_list = rose_neigh->next;
  208. if (rose_neigh->ax25)
  209. ax25_cb_put(rose_neigh->ax25);
  210. kfree(rose_neigh->digipeat);
  211. kfree(rose_neigh);
  212. return;
  213. }
  214. while (s != NULL && s->next != NULL) {
  215. if (s->next == rose_neigh) {
  216. s->next = rose_neigh->next;
  217. if (rose_neigh->ax25)
  218. ax25_cb_put(rose_neigh->ax25);
  219. kfree(rose_neigh->digipeat);
  220. kfree(rose_neigh);
  221. return;
  222. }
  223. s = s->next;
  224. }
  225. }
  226. /*
  227. * Caller is holding rose_route_list_lock.
  228. */
  229. static void rose_remove_route(struct rose_route *rose_route)
  230. {
  231. struct rose_route *s;
  232. if (rose_route->neigh1 != NULL)
  233. rose_route->neigh1->use--;
  234. if (rose_route->neigh2 != NULL)
  235. rose_route->neigh2->use--;
  236. if ((s = rose_route_list) == rose_route) {
  237. rose_route_list = rose_route->next;
  238. kfree(rose_route);
  239. return;
  240. }
  241. while (s != NULL && s->next != NULL) {
  242. if (s->next == rose_route) {
  243. s->next = rose_route->next;
  244. kfree(rose_route);
  245. return;
  246. }
  247. s = s->next;
  248. }
  249. }
  250. /*
  251. * "Delete" a node. Strictly speaking remove a route to a node. The node
  252. * is only deleted if no routes are left to it.
  253. */
  254. static int rose_del_node(struct rose_route_struct *rose_route,
  255. struct net_device *dev)
  256. {
  257. struct rose_node *rose_node;
  258. struct rose_neigh *rose_neigh;
  259. int i, err = 0;
  260. spin_lock_bh(&rose_node_list_lock);
  261. spin_lock_bh(&rose_neigh_list_lock);
  262. rose_node = rose_node_list;
  263. while (rose_node != NULL) {
  264. if ((rose_node->mask == rose_route->mask) &&
  265. (rosecmpm(&rose_route->address, &rose_node->address,
  266. rose_route->mask) == 0))
  267. break;
  268. rose_node = rose_node->next;
  269. }
  270. if (rose_node == NULL || rose_node->loopback) {
  271. err = -EINVAL;
  272. goto out;
  273. }
  274. rose_neigh = rose_neigh_list;
  275. while (rose_neigh != NULL) {
  276. if (ax25cmp(&rose_route->neighbour,
  277. &rose_neigh->callsign) == 0 &&
  278. rose_neigh->dev == dev)
  279. break;
  280. rose_neigh = rose_neigh->next;
  281. }
  282. if (rose_neigh == NULL) {
  283. err = -EINVAL;
  284. goto out;
  285. }
  286. for (i = 0; i < rose_node->count; i++) {
  287. if (rose_node->neighbour[i] == rose_neigh) {
  288. rose_neigh->count--;
  289. if (rose_neigh->count == 0 && rose_neigh->use == 0)
  290. rose_remove_neigh(rose_neigh);
  291. rose_node->count--;
  292. if (rose_node->count == 0) {
  293. rose_remove_node(rose_node);
  294. } else {
  295. switch (i) {
  296. case 0:
  297. rose_node->neighbour[0] =
  298. rose_node->neighbour[1];
  299. case 1:
  300. rose_node->neighbour[1] =
  301. rose_node->neighbour[2];
  302. case 2:
  303. break;
  304. }
  305. }
  306. goto out;
  307. }
  308. }
  309. err = -EINVAL;
  310. out:
  311. spin_unlock_bh(&rose_neigh_list_lock);
  312. spin_unlock_bh(&rose_node_list_lock);
  313. return err;
  314. }
  315. /*
  316. * Add the loopback neighbour.
  317. */
  318. void rose_add_loopback_neigh(void)
  319. {
  320. struct rose_neigh *sn;
  321. rose_loopback_neigh = kmalloc(sizeof(struct rose_neigh), GFP_KERNEL);
  322. if (!rose_loopback_neigh)
  323. return;
  324. sn = rose_loopback_neigh;
  325. sn->callsign = null_ax25_address;
  326. sn->digipeat = NULL;
  327. sn->ax25 = NULL;
  328. sn->dev = NULL;
  329. sn->count = 0;
  330. sn->use = 0;
  331. sn->dce_mode = 1;
  332. sn->loopback = 1;
  333. sn->number = rose_neigh_no++;
  334. sn->restarted = 1;
  335. skb_queue_head_init(&sn->queue);
  336. init_timer(&sn->ftimer);
  337. init_timer(&sn->t0timer);
  338. spin_lock_bh(&rose_neigh_list_lock);
  339. sn->next = rose_neigh_list;
  340. rose_neigh_list = sn;
  341. spin_unlock_bh(&rose_neigh_list_lock);
  342. }
  343. /*
  344. * Add a loopback node.
  345. */
  346. int rose_add_loopback_node(rose_address *address)
  347. {
  348. struct rose_node *rose_node;
  349. int err = 0;
  350. spin_lock_bh(&rose_node_list_lock);
  351. rose_node = rose_node_list;
  352. while (rose_node != NULL) {
  353. if ((rose_node->mask == 10) &&
  354. (rosecmpm(address, &rose_node->address, 10) == 0) &&
  355. rose_node->loopback)
  356. break;
  357. rose_node = rose_node->next;
  358. }
  359. if (rose_node != NULL)
  360. goto out;
  361. if ((rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC)) == NULL) {
  362. err = -ENOMEM;
  363. goto out;
  364. }
  365. rose_node->address = *address;
  366. rose_node->mask = 10;
  367. rose_node->count = 1;
  368. rose_node->loopback = 1;
  369. rose_node->neighbour[0] = rose_loopback_neigh;
  370. /* Insert at the head of list. Address is always mask=10 */
  371. rose_node->next = rose_node_list;
  372. rose_node_list = rose_node;
  373. rose_loopback_neigh->count++;
  374. out:
  375. spin_unlock_bh(&rose_node_list_lock);
  376. return err;
  377. }
  378. /*
  379. * Delete a loopback node.
  380. */
  381. void rose_del_loopback_node(rose_address *address)
  382. {
  383. struct rose_node *rose_node;
  384. spin_lock_bh(&rose_node_list_lock);
  385. rose_node = rose_node_list;
  386. while (rose_node != NULL) {
  387. if ((rose_node->mask == 10) &&
  388. (rosecmpm(address, &rose_node->address, 10) == 0) &&
  389. rose_node->loopback)
  390. break;
  391. rose_node = rose_node->next;
  392. }
  393. if (rose_node == NULL)
  394. goto out;
  395. rose_remove_node(rose_node);
  396. rose_loopback_neigh->count--;
  397. out:
  398. spin_unlock_bh(&rose_node_list_lock);
  399. }
  400. /*
  401. * A device has been removed. Remove its routes and neighbours.
  402. */
  403. void rose_rt_device_down(struct net_device *dev)
  404. {
  405. struct rose_neigh *s, *rose_neigh;
  406. struct rose_node *t, *rose_node;
  407. int i;
  408. spin_lock_bh(&rose_node_list_lock);
  409. spin_lock_bh(&rose_neigh_list_lock);
  410. rose_neigh = rose_neigh_list;
  411. while (rose_neigh != NULL) {
  412. s = rose_neigh;
  413. rose_neigh = rose_neigh->next;
  414. if (s->dev != dev)
  415. continue;
  416. rose_node = rose_node_list;
  417. while (rose_node != NULL) {
  418. t = rose_node;
  419. rose_node = rose_node->next;
  420. for (i = 0; i < t->count; i++) {
  421. if (t->neighbour[i] != s)
  422. continue;
  423. t->count--;
  424. switch (i) {
  425. case 0:
  426. t->neighbour[0] = t->neighbour[1];
  427. case 1:
  428. t->neighbour[1] = t->neighbour[2];
  429. case 2:
  430. break;
  431. }
  432. }
  433. if (t->count <= 0)
  434. rose_remove_node(t);
  435. }
  436. rose_remove_neigh(s);
  437. }
  438. spin_unlock_bh(&rose_neigh_list_lock);
  439. spin_unlock_bh(&rose_node_list_lock);
  440. }
  441. #if 0 /* Currently unused */
  442. /*
  443. * A device has been removed. Remove its links.
  444. */
  445. void rose_route_device_down(struct net_device *dev)
  446. {
  447. struct rose_route *s, *rose_route;
  448. spin_lock_bh(&rose_route_list_lock);
  449. rose_route = rose_route_list;
  450. while (rose_route != NULL) {
  451. s = rose_route;
  452. rose_route = rose_route->next;
  453. if (s->neigh1->dev == dev || s->neigh2->dev == dev)
  454. rose_remove_route(s);
  455. }
  456. spin_unlock_bh(&rose_route_list_lock);
  457. }
  458. #endif
  459. /*
  460. * Clear all nodes and neighbours out, except for neighbours with
  461. * active connections going through them.
  462. * Do not clear loopback neighbour and nodes.
  463. */
  464. static int rose_clear_routes(void)
  465. {
  466. struct rose_neigh *s, *rose_neigh;
  467. struct rose_node *t, *rose_node;
  468. spin_lock_bh(&rose_node_list_lock);
  469. spin_lock_bh(&rose_neigh_list_lock);
  470. rose_neigh = rose_neigh_list;
  471. rose_node = rose_node_list;
  472. while (rose_node != NULL) {
  473. t = rose_node;
  474. rose_node = rose_node->next;
  475. if (!t->loopback)
  476. rose_remove_node(t);
  477. }
  478. while (rose_neigh != NULL) {
  479. s = rose_neigh;
  480. rose_neigh = rose_neigh->next;
  481. if (s->use == 0 && !s->loopback) {
  482. s->count = 0;
  483. rose_remove_neigh(s);
  484. }
  485. }
  486. spin_unlock_bh(&rose_neigh_list_lock);
  487. spin_unlock_bh(&rose_node_list_lock);
  488. return 0;
  489. }
  490. /*
  491. * Check that the device given is a valid AX.25 interface that is "up".
  492. * called with RTNL
  493. */
  494. static struct net_device *rose_ax25_dev_find(char *devname)
  495. {
  496. struct net_device *dev;
  497. if ((dev = __dev_get_by_name(&init_net, devname)) == NULL)
  498. return NULL;
  499. if ((dev->flags & IFF_UP) && dev->type == ARPHRD_AX25)
  500. return dev;
  501. return NULL;
  502. }
  503. /*
  504. * Find the first active ROSE device, usually "rose0".
  505. */
  506. struct net_device *rose_dev_first(void)
  507. {
  508. struct net_device *dev, *first = NULL;
  509. rcu_read_lock();
  510. for_each_netdev_rcu(&init_net, dev) {
  511. if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE)
  512. if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
  513. first = dev;
  514. }
  515. rcu_read_unlock();
  516. return first;
  517. }
  518. /*
  519. * Find the ROSE device for the given address.
  520. */
  521. struct net_device *rose_dev_get(rose_address *addr)
  522. {
  523. struct net_device *dev;
  524. rcu_read_lock();
  525. for_each_netdev_rcu(&init_net, dev) {
  526. if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) {
  527. dev_hold(dev);
  528. goto out;
  529. }
  530. }
  531. dev = NULL;
  532. out:
  533. rcu_read_unlock();
  534. return dev;
  535. }
  536. static int rose_dev_exists(rose_address *addr)
  537. {
  538. struct net_device *dev;
  539. rcu_read_lock();
  540. for_each_netdev_rcu(&init_net, dev) {
  541. if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0)
  542. goto out;
  543. }
  544. dev = NULL;
  545. out:
  546. rcu_read_unlock();
  547. return dev != NULL;
  548. }
  549. struct rose_route *rose_route_free_lci(unsigned int lci, struct rose_neigh *neigh)
  550. {
  551. struct rose_route *rose_route;
  552. for (rose_route = rose_route_list; rose_route != NULL; rose_route = rose_route->next)
  553. if ((rose_route->neigh1 == neigh && rose_route->lci1 == lci) ||
  554. (rose_route->neigh2 == neigh && rose_route->lci2 == lci))
  555. return rose_route;
  556. return NULL;
  557. }
  558. /*
  559. * Find a neighbour or a route given a ROSE address.
  560. */
  561. struct rose_neigh *rose_get_neigh(rose_address *addr, unsigned char *cause,
  562. unsigned char *diagnostic, int route_frame)
  563. {
  564. struct rose_neigh *res = NULL;
  565. struct rose_node *node;
  566. int failed = 0;
  567. int i;
  568. if (!route_frame) spin_lock_bh(&rose_node_list_lock);
  569. for (node = rose_node_list; node != NULL; node = node->next) {
  570. if (rosecmpm(addr, &node->address, node->mask) == 0) {
  571. for (i = 0; i < node->count; i++) {
  572. if (node->neighbour[i]->restarted) {
  573. res = node->neighbour[i];
  574. goto out;
  575. }
  576. }
  577. }
  578. }
  579. if (!route_frame) { /* connect request */
  580. for (node = rose_node_list; node != NULL; node = node->next) {
  581. if (rosecmpm(addr, &node->address, node->mask) == 0) {
  582. for (i = 0; i < node->count; i++) {
  583. if (!rose_ftimer_running(node->neighbour[i])) {
  584. res = node->neighbour[i];
  585. failed = 0;
  586. goto out;
  587. }
  588. failed = 1;
  589. }
  590. }
  591. }
  592. }
  593. if (failed) {
  594. *cause = ROSE_OUT_OF_ORDER;
  595. *diagnostic = 0;
  596. } else {
  597. *cause = ROSE_NOT_OBTAINABLE;
  598. *diagnostic = 0;
  599. }
  600. out:
  601. if (!route_frame) spin_unlock_bh(&rose_node_list_lock);
  602. return res;
  603. }
  604. /*
  605. * Handle the ioctls that control the routing functions.
  606. */
  607. int rose_rt_ioctl(unsigned int cmd, void __user *arg)
  608. {
  609. struct rose_route_struct rose_route;
  610. struct net_device *dev;
  611. int err;
  612. switch (cmd) {
  613. case SIOCADDRT:
  614. if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct)))
  615. return -EFAULT;
  616. if ((dev = rose_ax25_dev_find(rose_route.device)) == NULL)
  617. return -EINVAL;
  618. if (rose_dev_exists(&rose_route.address)) /* Can't add routes to ourself */
  619. return -EINVAL;
  620. if (rose_route.mask > 10) /* Mask can't be more than 10 digits */
  621. return -EINVAL;
  622. if (rose_route.ndigis > AX25_MAX_DIGIS)
  623. return -EINVAL;
  624. err = rose_add_node(&rose_route, dev);
  625. return err;
  626. case SIOCDELRT:
  627. if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct)))
  628. return -EFAULT;
  629. if ((dev = rose_ax25_dev_find(rose_route.device)) == NULL)
  630. return -EINVAL;
  631. err = rose_del_node(&rose_route, dev);
  632. return err;
  633. case SIOCRSCLRRT:
  634. return rose_clear_routes();
  635. default:
  636. return -EINVAL;
  637. }
  638. return 0;
  639. }
  640. static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh)
  641. {
  642. struct rose_route *rose_route, *s;
  643. rose_neigh->restarted = 0;
  644. rose_stop_t0timer(rose_neigh);
  645. rose_start_ftimer(rose_neigh);
  646. skb_queue_purge(&rose_neigh->queue);
  647. spin_lock_bh(&rose_route_list_lock);
  648. rose_route = rose_route_list;
  649. while (rose_route != NULL) {
  650. if ((rose_route->neigh1 == rose_neigh && rose_route->neigh2 == rose_neigh) ||
  651. (rose_route->neigh1 == rose_neigh && rose_route->neigh2 == NULL) ||
  652. (rose_route->neigh2 == rose_neigh && rose_route->neigh1 == NULL)) {
  653. s = rose_route->next;
  654. rose_remove_route(rose_route);
  655. rose_route = s;
  656. continue;
  657. }
  658. if (rose_route->neigh1 == rose_neigh) {
  659. rose_route->neigh1->use--;
  660. rose_route->neigh1 = NULL;
  661. rose_transmit_clear_request(rose_route->neigh2, rose_route->lci2, ROSE_OUT_OF_ORDER, 0);
  662. }
  663. if (rose_route->neigh2 == rose_neigh) {
  664. rose_route->neigh2->use--;
  665. rose_route->neigh2 = NULL;
  666. rose_transmit_clear_request(rose_route->neigh1, rose_route->lci1, ROSE_OUT_OF_ORDER, 0);
  667. }
  668. rose_route = rose_route->next;
  669. }
  670. spin_unlock_bh(&rose_route_list_lock);
  671. }
  672. /*
  673. * A level 2 link has timed out, therefore it appears to be a poor link,
  674. * then don't use that neighbour until it is reset. Blow away all through
  675. * routes and connections using this route.
  676. */
  677. void rose_link_failed(ax25_cb *ax25, int reason)
  678. {
  679. struct rose_neigh *rose_neigh;
  680. spin_lock_bh(&rose_neigh_list_lock);
  681. rose_neigh = rose_neigh_list;
  682. while (rose_neigh != NULL) {
  683. if (rose_neigh->ax25 == ax25)
  684. break;
  685. rose_neigh = rose_neigh->next;
  686. }
  687. if (rose_neigh != NULL) {
  688. rose_neigh->ax25 = NULL;
  689. ax25_cb_put(ax25);
  690. rose_del_route_by_neigh(rose_neigh);
  691. rose_kill_by_neigh(rose_neigh);
  692. }
  693. spin_unlock_bh(&rose_neigh_list_lock);
  694. }
  695. /*
  696. * A device has been "downed" remove its link status. Blow away all
  697. * through routes and connections that use this device.
  698. */
  699. void rose_link_device_down(struct net_device *dev)
  700. {
  701. struct rose_neigh *rose_neigh;
  702. for (rose_neigh = rose_neigh_list; rose_neigh != NULL; rose_neigh = rose_neigh->next) {
  703. if (rose_neigh->dev == dev) {
  704. rose_del_route_by_neigh(rose_neigh);
  705. rose_kill_by_neigh(rose_neigh);
  706. }
  707. }
  708. }
  709. /*
  710. * Route a frame to an appropriate AX.25 connection.
  711. */
  712. int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
  713. {
  714. struct rose_neigh *rose_neigh, *new_neigh;
  715. struct rose_route *rose_route;
  716. struct rose_facilities_struct facilities;
  717. rose_address *src_addr, *dest_addr;
  718. struct sock *sk;
  719. unsigned short frametype;
  720. unsigned int lci, new_lci;
  721. unsigned char cause, diagnostic;
  722. struct net_device *dev;
  723. int res = 0;
  724. char buf[11];
  725. #if 0
  726. if (call_in_firewall(PF_ROSE, skb->dev, skb->data, NULL, &skb) != FW_ACCEPT)
  727. return res;
  728. #endif
  729. if (skb->len < ROSE_MIN_LEN)
  730. return res;
  731. frametype = skb->data[2];
  732. lci = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
  733. if (frametype == ROSE_CALL_REQUEST &&
  734. (skb->len <= ROSE_CALL_REQ_FACILITIES_OFF ||
  735. skb->data[ROSE_CALL_REQ_ADDR_LEN_OFF] !=
  736. ROSE_CALL_REQ_ADDR_LEN_VAL))
  737. return res;
  738. src_addr = (rose_address *)(skb->data + ROSE_CALL_REQ_SRC_ADDR_OFF);
  739. dest_addr = (rose_address *)(skb->data + ROSE_CALL_REQ_DEST_ADDR_OFF);
  740. spin_lock_bh(&rose_neigh_list_lock);
  741. spin_lock_bh(&rose_route_list_lock);
  742. rose_neigh = rose_neigh_list;
  743. while (rose_neigh != NULL) {
  744. if (ax25cmp(&ax25->dest_addr, &rose_neigh->callsign) == 0 &&
  745. ax25->ax25_dev->dev == rose_neigh->dev)
  746. break;
  747. rose_neigh = rose_neigh->next;
  748. }
  749. if (rose_neigh == NULL) {
  750. printk("rose_route : unknown neighbour or device %s\n",
  751. ax2asc(buf, &ax25->dest_addr));
  752. goto out;
  753. }
  754. /*
  755. * Obviously the link is working, halt the ftimer.
  756. */
  757. rose_stop_ftimer(rose_neigh);
  758. /*
  759. * LCI of zero is always for us, and its always a restart
  760. * frame.
  761. */
  762. if (lci == 0) {
  763. rose_link_rx_restart(skb, rose_neigh, frametype);
  764. goto out;
  765. }
  766. /*
  767. * Find an existing socket.
  768. */
  769. if ((sk = rose_find_socket(lci, rose_neigh)) != NULL) {
  770. if (frametype == ROSE_CALL_REQUEST) {
  771. struct rose_sock *rose = rose_sk(sk);
  772. /* Remove an existing unused socket */
  773. rose_clear_queues(sk);
  774. rose->cause = ROSE_NETWORK_CONGESTION;
  775. rose->diagnostic = 0;
  776. rose->neighbour->use--;
  777. rose->neighbour = NULL;
  778. rose->lci = 0;
  779. rose->state = ROSE_STATE_0;
  780. sk->sk_state = TCP_CLOSE;
  781. sk->sk_err = 0;
  782. sk->sk_shutdown |= SEND_SHUTDOWN;
  783. if (!sock_flag(sk, SOCK_DEAD)) {
  784. sk->sk_state_change(sk);
  785. sock_set_flag(sk, SOCK_DEAD);
  786. }
  787. }
  788. else {
  789. skb_reset_transport_header(skb);
  790. res = rose_process_rx_frame(sk, skb);
  791. goto out;
  792. }
  793. }
  794. /*
  795. * Is is a Call Request and is it for us ?
  796. */
  797. if (frametype == ROSE_CALL_REQUEST)
  798. if ((dev = rose_dev_get(dest_addr)) != NULL) {
  799. res = rose_rx_call_request(skb, dev, rose_neigh, lci);
  800. dev_put(dev);
  801. goto out;
  802. }
  803. if (!sysctl_rose_routing_control) {
  804. rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 0);
  805. goto out;
  806. }
  807. /*
  808. * Route it to the next in line if we have an entry for it.
  809. */
  810. rose_route = rose_route_list;
  811. while (rose_route != NULL) {
  812. if (rose_route->lci1 == lci &&
  813. rose_route->neigh1 == rose_neigh) {
  814. if (frametype == ROSE_CALL_REQUEST) {
  815. /* F6FBB - Remove an existing unused route */
  816. rose_remove_route(rose_route);
  817. break;
  818. } else if (rose_route->neigh2 != NULL) {
  819. skb->data[0] &= 0xF0;
  820. skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F;
  821. skb->data[1] = (rose_route->lci2 >> 0) & 0xFF;
  822. rose_transmit_link(skb, rose_route->neigh2);
  823. if (frametype == ROSE_CLEAR_CONFIRMATION)
  824. rose_remove_route(rose_route);
  825. res = 1;
  826. goto out;
  827. } else {
  828. if (frametype == ROSE_CLEAR_CONFIRMATION)
  829. rose_remove_route(rose_route);
  830. goto out;
  831. }
  832. }
  833. if (rose_route->lci2 == lci &&
  834. rose_route->neigh2 == rose_neigh) {
  835. if (frametype == ROSE_CALL_REQUEST) {
  836. /* F6FBB - Remove an existing unused route */
  837. rose_remove_route(rose_route);
  838. break;
  839. } else if (rose_route->neigh1 != NULL) {
  840. skb->data[0] &= 0xF0;
  841. skb->data[0] |= (rose_route->lci1 >> 8) & 0x0F;
  842. skb->data[1] = (rose_route->lci1 >> 0) & 0xFF;
  843. rose_transmit_link(skb, rose_route->neigh1);
  844. if (frametype == ROSE_CLEAR_CONFIRMATION)
  845. rose_remove_route(rose_route);
  846. res = 1;
  847. goto out;
  848. } else {
  849. if (frametype == ROSE_CLEAR_CONFIRMATION)
  850. rose_remove_route(rose_route);
  851. goto out;
  852. }
  853. }
  854. rose_route = rose_route->next;
  855. }
  856. /*
  857. * We know that:
  858. * 1. The frame isn't for us,
  859. * 2. It isn't "owned" by any existing route.
  860. */
  861. if (frametype != ROSE_CALL_REQUEST) { /* XXX */
  862. res = 0;
  863. goto out;
  864. }
  865. memset(&facilities, 0x00, sizeof(struct rose_facilities_struct));
  866. if (!rose_parse_facilities(skb->data + ROSE_CALL_REQ_FACILITIES_OFF,
  867. skb->len - ROSE_CALL_REQ_FACILITIES_OFF,
  868. &facilities)) {
  869. rose_transmit_clear_request(rose_neigh, lci, ROSE_INVALID_FACILITY, 76);
  870. goto out;
  871. }
  872. /*
  873. * Check for routing loops.
  874. */
  875. rose_route = rose_route_list;
  876. while (rose_route != NULL) {
  877. if (rose_route->rand == facilities.rand &&
  878. rosecmp(src_addr, &rose_route->src_addr) == 0 &&
  879. ax25cmp(&facilities.dest_call, &rose_route->src_call) == 0 &&
  880. ax25cmp(&facilities.source_call, &rose_route->dest_call) == 0) {
  881. rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 120);
  882. goto out;
  883. }
  884. rose_route = rose_route->next;
  885. }
  886. if ((new_neigh = rose_get_neigh(dest_addr, &cause, &diagnostic, 1)) == NULL) {
  887. rose_transmit_clear_request(rose_neigh, lci, cause, diagnostic);
  888. goto out;
  889. }
  890. if ((new_lci = rose_new_lci(new_neigh)) == 0) {
  891. rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 71);
  892. goto out;
  893. }
  894. if ((rose_route = kmalloc(sizeof(*rose_route), GFP_ATOMIC)) == NULL) {
  895. rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 120);
  896. goto out;
  897. }
  898. rose_route->lci1 = lci;
  899. rose_route->src_addr = *src_addr;
  900. rose_route->dest_addr = *dest_addr;
  901. rose_route->src_call = facilities.dest_call;
  902. rose_route->dest_call = facilities.source_call;
  903. rose_route->rand = facilities.rand;
  904. rose_route->neigh1 = rose_neigh;
  905. rose_route->lci2 = new_lci;
  906. rose_route->neigh2 = new_neigh;
  907. rose_route->neigh1->use++;
  908. rose_route->neigh2->use++;
  909. rose_route->next = rose_route_list;
  910. rose_route_list = rose_route;
  911. skb->data[0] &= 0xF0;
  912. skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F;
  913. skb->data[1] = (rose_route->lci2 >> 0) & 0xFF;
  914. rose_transmit_link(skb, rose_route->neigh2);
  915. res = 1;
  916. out:
  917. spin_unlock_bh(&rose_route_list_lock);
  918. spin_unlock_bh(&rose_neigh_list_lock);
  919. return res;
  920. }
  921. #ifdef CONFIG_PROC_FS
  922. static void *rose_node_start(struct seq_file *seq, loff_t *pos)
  923. __acquires(rose_node_list_lock)
  924. {
  925. struct rose_node *rose_node;
  926. int i = 1;
  927. spin_lock_bh(&rose_node_list_lock);
  928. if (*pos == 0)
  929. return SEQ_START_TOKEN;
  930. for (rose_node = rose_node_list; rose_node && i < *pos;
  931. rose_node = rose_node->next, ++i);
  932. return (i == *pos) ? rose_node : NULL;
  933. }
  934. static void *rose_node_next(struct seq_file *seq, void *v, loff_t *pos)
  935. {
  936. ++*pos;
  937. return (v == SEQ_START_TOKEN) ? rose_node_list
  938. : ((struct rose_node *)v)->next;
  939. }
  940. static void rose_node_stop(struct seq_file *seq, void *v)
  941. __releases(rose_node_list_lock)
  942. {
  943. spin_unlock_bh(&rose_node_list_lock);
  944. }
  945. static int rose_node_show(struct seq_file *seq, void *v)
  946. {
  947. char rsbuf[11];
  948. int i;
  949. if (v == SEQ_START_TOKEN)
  950. seq_puts(seq, "address mask n neigh neigh neigh\n");
  951. else {
  952. const struct rose_node *rose_node = v;
  953. /* if (rose_node->loopback) {
  954. seq_printf(seq, "%-10s %04d 1 loopback\n",
  955. rose2asc(rsbuf, &rose_node->address),
  956. rose_node->mask);
  957. } else { */
  958. seq_printf(seq, "%-10s %04d %d",
  959. rose2asc(rsbuf, &rose_node->address),
  960. rose_node->mask,
  961. rose_node->count);
  962. for (i = 0; i < rose_node->count; i++)
  963. seq_printf(seq, " %05d",
  964. rose_node->neighbour[i]->number);
  965. seq_puts(seq, "\n");
  966. /* } */
  967. }
  968. return 0;
  969. }
  970. static const struct seq_operations rose_node_seqops = {
  971. .start = rose_node_start,
  972. .next = rose_node_next,
  973. .stop = rose_node_stop,
  974. .show = rose_node_show,
  975. };
  976. static int rose_nodes_open(struct inode *inode, struct file *file)
  977. {
  978. return seq_open(file, &rose_node_seqops);
  979. }
  980. const struct file_operations rose_nodes_fops = {
  981. .owner = THIS_MODULE,
  982. .open = rose_nodes_open,
  983. .read = seq_read,
  984. .llseek = seq_lseek,
  985. .release = seq_release,
  986. };
  987. static void *rose_neigh_start(struct seq_file *seq, loff_t *pos)
  988. __acquires(rose_neigh_list_lock)
  989. {
  990. struct rose_neigh *rose_neigh;
  991. int i = 1;
  992. spin_lock_bh(&rose_neigh_list_lock);
  993. if (*pos == 0)
  994. return SEQ_START_TOKEN;
  995. for (rose_neigh = rose_neigh_list; rose_neigh && i < *pos;
  996. rose_neigh = rose_neigh->next, ++i);
  997. return (i == *pos) ? rose_neigh : NULL;
  998. }
  999. static void *rose_neigh_next(struct seq_file *seq, void *v, loff_t *pos)
  1000. {
  1001. ++*pos;
  1002. return (v == SEQ_START_TOKEN) ? rose_neigh_list
  1003. : ((struct rose_neigh *)v)->next;
  1004. }
  1005. static void rose_neigh_stop(struct seq_file *seq, void *v)
  1006. __releases(rose_neigh_list_lock)
  1007. {
  1008. spin_unlock_bh(&rose_neigh_list_lock);
  1009. }
  1010. static int rose_neigh_show(struct seq_file *seq, void *v)
  1011. {
  1012. char buf[11];
  1013. int i;
  1014. if (v == SEQ_START_TOKEN)
  1015. seq_puts(seq,
  1016. "addr callsign dev count use mode restart t0 tf digipeaters\n");
  1017. else {
  1018. struct rose_neigh *rose_neigh = v;
  1019. /* if (!rose_neigh->loopback) { */
  1020. seq_printf(seq, "%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu",
  1021. rose_neigh->number,
  1022. (rose_neigh->loopback) ? "RSLOOP-0" : ax2asc(buf, &rose_neigh->callsign),
  1023. rose_neigh->dev ? rose_neigh->dev->name : "???",
  1024. rose_neigh->count,
  1025. rose_neigh->use,
  1026. (rose_neigh->dce_mode) ? "DCE" : "DTE",
  1027. (rose_neigh->restarted) ? "yes" : "no",
  1028. ax25_display_timer(&rose_neigh->t0timer) / HZ,
  1029. ax25_display_timer(&rose_neigh->ftimer) / HZ);
  1030. if (rose_neigh->digipeat != NULL) {
  1031. for (i = 0; i < rose_neigh->digipeat->ndigi; i++)
  1032. seq_printf(seq, " %s", ax2asc(buf, &rose_neigh->digipeat->calls[i]));
  1033. }
  1034. seq_puts(seq, "\n");
  1035. }
  1036. return 0;
  1037. }
  1038. static const struct seq_operations rose_neigh_seqops = {
  1039. .start = rose_neigh_start,
  1040. .next = rose_neigh_next,
  1041. .stop = rose_neigh_stop,
  1042. .show = rose_neigh_show,
  1043. };
  1044. static int rose_neigh_open(struct inode *inode, struct file *file)
  1045. {
  1046. return seq_open(file, &rose_neigh_seqops);
  1047. }
  1048. const struct file_operations rose_neigh_fops = {
  1049. .owner = THIS_MODULE,
  1050. .open = rose_neigh_open,
  1051. .read = seq_read,
  1052. .llseek = seq_lseek,
  1053. .release = seq_release,
  1054. };
  1055. static void *rose_route_start(struct seq_file *seq, loff_t *pos)
  1056. __acquires(rose_route_list_lock)
  1057. {
  1058. struct rose_route *rose_route;
  1059. int i = 1;
  1060. spin_lock_bh(&rose_route_list_lock);
  1061. if (*pos == 0)
  1062. return SEQ_START_TOKEN;
  1063. for (rose_route = rose_route_list; rose_route && i < *pos;
  1064. rose_route = rose_route->next, ++i);
  1065. return (i == *pos) ? rose_route : NULL;
  1066. }
  1067. static void *rose_route_next(struct seq_file *seq, void *v, loff_t *pos)
  1068. {
  1069. ++*pos;
  1070. return (v == SEQ_START_TOKEN) ? rose_route_list
  1071. : ((struct rose_route *)v)->next;
  1072. }
  1073. static void rose_route_stop(struct seq_file *seq, void *v)
  1074. __releases(rose_route_list_lock)
  1075. {
  1076. spin_unlock_bh(&rose_route_list_lock);
  1077. }
  1078. static int rose_route_show(struct seq_file *seq, void *v)
  1079. {
  1080. char buf[11], rsbuf[11];
  1081. if (v == SEQ_START_TOKEN)
  1082. seq_puts(seq,
  1083. "lci address callsign neigh <-> lci address callsign neigh\n");
  1084. else {
  1085. struct rose_route *rose_route = v;
  1086. if (rose_route->neigh1)
  1087. seq_printf(seq,
  1088. "%3.3X %-10s %-9s %05d ",
  1089. rose_route->lci1,
  1090. rose2asc(rsbuf, &rose_route->src_addr),
  1091. ax2asc(buf, &rose_route->src_call),
  1092. rose_route->neigh1->number);
  1093. else
  1094. seq_puts(seq,
  1095. "000 * * 00000 ");
  1096. if (rose_route->neigh2)
  1097. seq_printf(seq,
  1098. "%3.3X %-10s %-9s %05d\n",
  1099. rose_route->lci2,
  1100. rose2asc(rsbuf, &rose_route->dest_addr),
  1101. ax2asc(buf, &rose_route->dest_call),
  1102. rose_route->neigh2->number);
  1103. else
  1104. seq_puts(seq,
  1105. "000 * * 00000\n");
  1106. }
  1107. return 0;
  1108. }
  1109. static const struct seq_operations rose_route_seqops = {
  1110. .start = rose_route_start,
  1111. .next = rose_route_next,
  1112. .stop = rose_route_stop,
  1113. .show = rose_route_show,
  1114. };
  1115. static int rose_route_open(struct inode *inode, struct file *file)
  1116. {
  1117. return seq_open(file, &rose_route_seqops);
  1118. }
  1119. const struct file_operations rose_routes_fops = {
  1120. .owner = THIS_MODULE,
  1121. .open = rose_route_open,
  1122. .read = seq_read,
  1123. .llseek = seq_lseek,
  1124. .release = seq_release,
  1125. };
  1126. #endif /* CONFIG_PROC_FS */
  1127. /*
  1128. * Release all memory associated with ROSE routing structures.
  1129. */
  1130. void __exit rose_rt_free(void)
  1131. {
  1132. struct rose_neigh *s, *rose_neigh = rose_neigh_list;
  1133. struct rose_node *t, *rose_node = rose_node_list;
  1134. struct rose_route *u, *rose_route = rose_route_list;
  1135. while (rose_neigh != NULL) {
  1136. s = rose_neigh;
  1137. rose_neigh = rose_neigh->next;
  1138. rose_remove_neigh(s);
  1139. }
  1140. while (rose_node != NULL) {
  1141. t = rose_node;
  1142. rose_node = rose_node->next;
  1143. rose_remove_node(t);
  1144. }
  1145. while (rose_route != NULL) {
  1146. u = rose_route;
  1147. rose_route = rose_route->next;
  1148. rose_remove_route(u);
  1149. }
  1150. }