rose_route.c 31 KB

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