ospf6_flood.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /*
  2. * Copyright (C) 2003 Yasuhiro Ohara
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "log.h"
  23. #include "thread.h"
  24. #include "linklist.h"
  25. #include "vty.h"
  26. #include "ospf6d.h"
  27. #include "ospf6_proto.h"
  28. #include "ospf6_lsa.h"
  29. #include "ospf6_lsdb.h"
  30. #include "ospf6_message.h"
  31. #include "ospf6_route.h"
  32. #include "ospf6_spf.h"
  33. #include "ospf6_top.h"
  34. #include "ospf6_area.h"
  35. #include "ospf6_interface.h"
  36. #include "ospf6_neighbor.h"
  37. void *
  38. ospf6_get_lsa_scope (u_int16_t type, struct ospf6_neighbor *from)
  39. {
  40. void *scope = NULL;
  41. if (from == NULL)
  42. return NULL;
  43. switch (OSPF6_LSA_SCOPE (type))
  44. {
  45. case OSPF6_LSA_SCOPE_AS:
  46. scope = (from)->ospf6_if->area->ospf6;
  47. break;
  48. case OSPF6_LSA_SCOPE_AREA:
  49. scope = (from)->ospf6_if->area;
  50. break;
  51. case OSPF6_LSA_SCOPE_LINKLOCAL:
  52. scope = (from)->ospf6_if;
  53. break;
  54. default:
  55. break;
  56. }
  57. return scope;
  58. }
  59. struct ospf6_lsdb *
  60. ospf6_get_scoped_lsdb (u_int16_t type, void *scope)
  61. {
  62. struct ospf6_lsdb *lsdb = NULL;
  63. if (scope == NULL)
  64. return NULL;
  65. switch (OSPF6_LSA_SCOPE (type))
  66. {
  67. case OSPF6_LSA_SCOPE_AS:
  68. lsdb = ((struct ospf6 *)(scope))->lsdb;
  69. break;
  70. case OSPF6_LSA_SCOPE_AREA:
  71. lsdb = ((struct ospf6_area *)(scope))->lsdb;
  72. break;
  73. case OSPF6_LSA_SCOPE_LINKLOCAL:
  74. lsdb = ((struct ospf6_interface *)(scope))->lsdb;
  75. break;
  76. default:
  77. break;
  78. }
  79. return lsdb;
  80. }
  81. void
  82. ospf6_flood_clear (struct ospf6_lsa *lsa)
  83. {
  84. struct ospf6_neighbor *on;
  85. struct ospf6_interface *oi, *ospf6_if = NULL;
  86. struct ospf6_area *oa, *area = NULL;
  87. struct ospf6 *ospf6 = NULL;
  88. u_int16_t scope_type;
  89. list scoped_interfaces;
  90. struct ospf6_lsa *rxmt;
  91. listnode i, j;
  92. scoped_interfaces = list_new ();
  93. scope_type = OSPF6_LSA_SCOPE (lsa->header->type);
  94. if (scope_type == OSPF6_LSA_SCOPE_LINKLOCAL)
  95. {
  96. ospf6_if = (struct ospf6_interface *) lsa->scope;
  97. area = ospf6_if->area;
  98. ospf6 = area->ospf6;
  99. }
  100. else if (scope_type == OSPF6_LSA_SCOPE_AREA)
  101. {
  102. area = (struct ospf6_area *) lsa->scope;
  103. ospf6 = area->ospf6;
  104. }
  105. else if (scope_type == OSPF6_LSA_SCOPE_AS)
  106. {
  107. ospf6 = (struct ospf6 *) lsa->scope;
  108. }
  109. else
  110. {
  111. zlog_warn ("Can't decide LSA scope, quit ospf6_flood_clear ()");
  112. return;
  113. }
  114. /* Collect eligible interfaces */
  115. for (i = listhead (ospf6->area_list); i; nextnode (i))
  116. {
  117. oa = (struct ospf6_area *) getdata (i);
  118. if (scope_type != OSPF6_LSA_SCOPE_AS && oa != area)
  119. continue;
  120. for (j = listhead (oa->if_list); j; nextnode (j))
  121. {
  122. oi = (struct ospf6_interface *) getdata (j);
  123. if (scope_type != OSPF6_LSA_SCOPE_AS &&
  124. scope_type != OSPF6_LSA_SCOPE_AREA && oi != ospf6_if)
  125. continue;
  126. listnode_add (scoped_interfaces, oi);
  127. }
  128. }
  129. for (i = listhead (scoped_interfaces); i; nextnode (i))
  130. {
  131. oi = (struct ospf6_interface *) getdata (i);
  132. for (j = listhead (oi->neighbor_list); j; nextnode (j))
  133. {
  134. on = (struct ospf6_neighbor *) getdata (j);
  135. rxmt = ospf6_lsdb_lookup (lsa->header->type, lsa->header->id,
  136. lsa->header->adv_router, on->retrans_list);
  137. if (rxmt && ! ospf6_lsa_compare (rxmt, lsa))
  138. {
  139. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  140. zlog_info ("Remove %s from retrans_list of %s",
  141. rxmt->name, on->name);
  142. ospf6_lsdb_remove (rxmt, on->retrans_list);
  143. }
  144. }
  145. }
  146. list_delete (scoped_interfaces);
  147. }
  148. /* RFC2328 section 13.2 Installing LSAs in the database */
  149. void
  150. ospf6_install_lsa (struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
  151. {
  152. struct ospf6_lsa *old;
  153. if (IS_OSPF6_DEBUG_LSA (RECV) || IS_OSPF6_DEBUG_LSA (DATABASE))
  154. zlog_info ("Install LSA: %s", lsa->name);
  155. /* Remove the old instance from all neighbors' Link state
  156. retransmission list (RFC2328 13.2 last paragraph) */
  157. old = ospf6_lsdb_lookup (lsa->header->type, lsa->header->id,
  158. lsa->header->adv_router, lsdb);
  159. if (old)
  160. ospf6_flood_clear (old);
  161. /* actually install */
  162. gettimeofday (&lsa->installed, (struct timezone *) NULL);
  163. ospf6_lsdb_add (lsa, lsdb);
  164. return;
  165. }
  166. /* RFC2328 section 13.3 Next step in the flooding procedure */
  167. void
  168. ospf6_flood_lsa (struct ospf6_lsa *lsa, struct ospf6_neighbor *from)
  169. {
  170. struct ospf6 *scope_as = NULL;
  171. struct ospf6_area *oa, *scope_area = NULL;
  172. struct ospf6_interface *oi, *scope_linklocal = NULL;
  173. struct ospf6_neighbor *on;
  174. list eligible_interfaces;
  175. listnode i, j;
  176. u_int16_t scope_type;
  177. struct ospf6_lsa *req;
  178. int retrans_added = 0;
  179. scope_type = OSPF6_LSA_SCOPE (lsa->header->type);
  180. switch (scope_type)
  181. {
  182. case OSPF6_LSA_SCOPE_AS:
  183. scope_as = (struct ospf6 *) lsa->scope;
  184. break;
  185. case OSPF6_LSA_SCOPE_AREA:
  186. scope_as = ((struct ospf6_area *) lsa->scope)->ospf6;
  187. scope_area = (struct ospf6_area *) lsa->scope;
  188. break;
  189. case OSPF6_LSA_SCOPE_LINKLOCAL:
  190. scope_as = ((struct ospf6_interface *) lsa->scope)->area->ospf6;
  191. scope_area = ((struct ospf6_interface *) lsa->scope)->area;
  192. scope_linklocal = (struct ospf6_interface *) lsa->scope;
  193. break;
  194. default:
  195. if (IS_OSPF6_DEBUG_LSA (SEND))
  196. zlog_info ("Can't decide LSA scope");
  197. return;
  198. }
  199. if (IS_OSPF6_DEBUG_LSA (SEND))
  200. zlog_info ("Flood %s", lsa->name);
  201. /* Collect eligible interfaces */
  202. eligible_interfaces = list_new ();
  203. for (i = listhead (scope_as->area_list); i; nextnode (i))
  204. {
  205. oa = (struct ospf6_area *) getdata (i);
  206. if (scope_type != OSPF6_LSA_SCOPE_AS &&
  207. oa != scope_area)
  208. continue;
  209. for (j = listhead (oa->if_list); j; nextnode (j))
  210. {
  211. oi = (struct ospf6_interface *) getdata (j);
  212. if (scope_type != OSPF6_LSA_SCOPE_AS &&
  213. scope_type != OSPF6_LSA_SCOPE_AREA &&
  214. oi != scope_linklocal)
  215. continue;
  216. listnode_add (eligible_interfaces, oi);
  217. }
  218. }
  219. /* For each eligible interface: */
  220. for (i = listhead (eligible_interfaces); i; nextnode (i))
  221. {
  222. oi = (struct ospf6_interface *) getdata (i);
  223. /* (1) For each neighbor */
  224. for (j = listhead (oi->neighbor_list); j; nextnode (j))
  225. {
  226. on = (struct ospf6_neighbor *) getdata (j);
  227. /* (a) if neighbor state < Exchange, examin next */
  228. if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
  229. continue;
  230. /* (b) if neighbor not yet Full, check request-list */
  231. if (on->state != OSPF6_NEIGHBOR_FULL)
  232. {
  233. req = ospf6_lsdb_lookup (lsa->header->type, lsa->header->id,
  234. lsa->header->adv_router,
  235. on->request_list);
  236. if (req)
  237. {
  238. /* If new LSA less recent, examin next neighbor */
  239. if (ospf6_lsa_compare (lsa, req) > 0)
  240. continue;
  241. /* If the same instance, delete from request-list and
  242. examin next neighbor */
  243. if (ospf6_lsa_compare (lsa, req) == 0)
  244. {
  245. if (IS_OSPF6_DEBUG_LSA (SEND) || IS_OSPF6_DEBUG_LSA (DATABASE))
  246. zlog_info ("Remove %s from request-list of %s: "
  247. "the same instance", req->name, on->name);
  248. ospf6_lsdb_remove (req, on->request_list);
  249. continue;
  250. }
  251. /* If the new LSA is more recent, delete from
  252. request-list */
  253. if (ospf6_lsa_compare (lsa, req) < 0)
  254. {
  255. if (IS_OSPF6_DEBUG_LSA (SEND) || IS_OSPF6_DEBUG_LSA (DATABASE))
  256. zlog_info ("Remove %s from request-list of %s: "
  257. "newer instance", req->name, on->name);
  258. ospf6_lsdb_remove (req, on->request_list);
  259. /* fall through */
  260. }
  261. }
  262. }
  263. /* (c) If the new LSA was received from this neighbor,
  264. examin next neighbor */
  265. if (from == on)
  266. continue;
  267. /* (d) add retrans-list, schedule retransmission */
  268. if (IS_OSPF6_DEBUG_LSA (SEND) || IS_OSPF6_DEBUG_LSA (DATABASE))
  269. zlog_info (" Add copy of %s to retrans-list of %s",
  270. lsa->name, on->name);
  271. ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
  272. if (on->thread_send_lsupdate == NULL)
  273. on->thread_send_lsupdate =
  274. thread_add_event (master, ospf6_lsupdate_send_neighbor,
  275. on, on->ospf6_if->rxmt_interval);
  276. retrans_added++;
  277. }
  278. /* (2) examin next interface if not added to retrans-list */
  279. if (retrans_added == 0)
  280. continue;
  281. /* (3) If the new LSA was received on this interface,
  282. and it was from DR or BDR, examin next interface */
  283. if (from && from->ospf6_if == oi &&
  284. (from->router_id == oi->drouter || from->router_id == oi->bdrouter))
  285. continue;
  286. /* (4) If the new LSA was received on this interface,
  287. and the interface state is BDR, examin next interface */
  288. if (from && from->ospf6_if == oi && oi->state == OSPF6_INTERFACE_BDR)
  289. continue;
  290. /* (5) flood the LSA out the interface. */
  291. if (if_is_broadcast (oi->interface))
  292. {
  293. if (IS_OSPF6_DEBUG_LSA (SEND) || IS_OSPF6_DEBUG_LSA (DATABASE))
  294. zlog_info (" Add copy of %s to lsupdate_list of %s",
  295. lsa->name, oi->interface->name);
  296. ospf6_lsdb_add (ospf6_lsa_copy (lsa), oi->lsupdate_list);
  297. if (oi->thread_send_lsupdate == NULL)
  298. oi->thread_send_lsupdate =
  299. thread_add_event (master, ospf6_lsupdate_send_interface, oi, 0);
  300. }
  301. else
  302. {
  303. for (j = listhead (oi->neighbor_list); j; nextnode (j))
  304. {
  305. on = (struct ospf6_neighbor *) getdata (j);
  306. THREAD_OFF (on->thread_send_lsupdate);
  307. on->thread_send_lsupdate =
  308. thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
  309. }
  310. }
  311. }
  312. list_delete (eligible_interfaces);
  313. }
  314. /* RFC2328 13.5 (Table 19): Sending link state acknowledgements. */
  315. static void
  316. ospf6_acknowledge_lsa_bdrouter (struct ospf6_lsa *lsa, int ismore_recent,
  317. struct ospf6_neighbor *from)
  318. {
  319. struct ospf6_interface *oi;
  320. assert (from && from->ospf6_if);
  321. oi = from->ospf6_if;
  322. /* LSA has been flood back out receiving interface.
  323. No acknowledgement sent. */
  324. if (CHECK_FLAG (lsa->flag, OSPF6_LSA_FLOODBACK))
  325. {
  326. if (IS_OSPF6_DEBUG_LSA (RECV))
  327. zlog_info (" BDR, FloodBack, No acknowledgement.");
  328. return;
  329. }
  330. /* LSA is more recent than database copy, but was not flooded
  331. back out receiving interface. Delayed acknowledgement sent
  332. if advertisement received from Designated Router,
  333. otherwide do nothing. */
  334. if (ismore_recent < 0)
  335. {
  336. if (IS_OSPF6_DEBUG_LSA (RECV))
  337. zlog_info (" BDR, Not FloodBack, MoreRecent, ");
  338. if (oi->drouter == from->router_id)
  339. {
  340. if (IS_OSPF6_DEBUG_LSA (RECV))
  341. zlog_info (" From DR, Delayed acknowledgement.");
  342. /* Delayed acknowledgement */
  343. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  344. zlog_info (" Add copy of %s to lsack_list of %s",
  345. lsa->name, oi->interface->name);
  346. ospf6_lsdb_add (ospf6_lsa_copy (lsa), oi->lsack_list);
  347. if (oi->thread_send_lsack == NULL)
  348. oi->thread_send_lsack =
  349. thread_add_timer (master, ospf6_lsack_send_interface, oi, 3);
  350. }
  351. else
  352. {
  353. if (IS_OSPF6_DEBUG_LSA (RECV))
  354. zlog_info (" Not From DR, No acknowledgement.");
  355. }
  356. return;
  357. }
  358. /* LSA is a duplicate, and was treated as an implied acknowledgement.
  359. Delayed acknowledgement sent if advertisement received from
  360. Designated Router, otherwise do nothing */
  361. if (CHECK_FLAG (lsa->flag, OSPF6_LSA_DUPLICATE) &&
  362. CHECK_FLAG (lsa->flag, OSPF6_LSA_IMPLIEDACK))
  363. {
  364. if (IS_OSPF6_DEBUG_LSA (RECV))
  365. zlog_info (" BDR, Duplicate, ImpliedAck, ");
  366. if (oi->drouter == from->router_id)
  367. {
  368. if (IS_OSPF6_DEBUG_LSA (RECV))
  369. zlog_info (" From DR, Delayed acknowledgement.");
  370. /* Delayed acknowledgement */
  371. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  372. zlog_info (" Add copy of %s to lsack_list of %s",
  373. lsa->name, oi->interface->name);
  374. ospf6_lsdb_add (ospf6_lsa_copy (lsa), oi->lsack_list);
  375. if (oi->thread_send_lsack == NULL)
  376. oi->thread_send_lsack =
  377. thread_add_timer (master, ospf6_lsack_send_interface, oi, 3);
  378. }
  379. else
  380. {
  381. if (IS_OSPF6_DEBUG_LSA (RECV))
  382. zlog_info (" Not From DR, No acknowledgement.");
  383. }
  384. return;
  385. }
  386. /* LSA is a duplicate, and was not treated as an implied acknowledgement.
  387. Direct acknowledgement sent */
  388. if (CHECK_FLAG (lsa->flag, OSPF6_LSA_DUPLICATE) &&
  389. ! CHECK_FLAG (lsa->flag, OSPF6_LSA_IMPLIEDACK))
  390. {
  391. if (IS_OSPF6_DEBUG_LSA (RECV))
  392. zlog_info (" BDR, Duplicate, Not ImpliedAck, Direct acknowledgement.");
  393. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  394. zlog_info (" Add copy of %s to lsack_list of %s",
  395. lsa->name, from->name);
  396. ospf6_lsdb_add (ospf6_lsa_copy (lsa), from->lsack_list);
  397. if (from->thread_send_lsack == NULL)
  398. from->thread_send_lsack =
  399. thread_add_event (master, ospf6_lsack_send_neighbor, from, 0);
  400. return;
  401. }
  402. /* LSA's LS age is equal to Maxage, and there is no current instance
  403. of the LSA in the link state database, and none of router's
  404. neighbors are in states Exchange or Loading */
  405. /* Direct acknowledgement sent, but this case is handled in
  406. early of ospf6_receive_lsa () */
  407. }
  408. static void
  409. ospf6_acknowledge_lsa_allother (struct ospf6_lsa *lsa, int ismore_recent,
  410. struct ospf6_neighbor *from)
  411. {
  412. struct ospf6_interface *oi;
  413. assert (from && from->ospf6_if);
  414. oi = from->ospf6_if;
  415. /* LSA has been flood back out receiving interface.
  416. No acknowledgement sent. */
  417. if (CHECK_FLAG (lsa->flag, OSPF6_LSA_FLOODBACK))
  418. {
  419. if (IS_OSPF6_DEBUG_LSA (RECV))
  420. zlog_info (" AllOther, FloodBack, No acknowledgement.");
  421. return;
  422. }
  423. /* LSA is more recent than database copy, but was not flooded
  424. back out receiving interface. Delayed acknowledgement sent. */
  425. if (ismore_recent < 0)
  426. {
  427. if (IS_OSPF6_DEBUG_LSA (RECV))
  428. zlog_info (" AllOther, Not FloodBack, Delayed acknowledgement.");
  429. /* Delayed acknowledgement */
  430. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  431. zlog_info (" Add copy of %s to lsack_list of %s",
  432. lsa->name, oi->interface->name);
  433. ospf6_lsdb_add (ospf6_lsa_copy (lsa), oi->lsack_list);
  434. if (oi->thread_send_lsack == NULL)
  435. oi->thread_send_lsack =
  436. thread_add_timer (master, ospf6_lsack_send_interface, oi, 3);
  437. return;
  438. }
  439. /* LSA is a duplicate, and was treated as an implied acknowledgement.
  440. No acknowledgement sent. */
  441. if (CHECK_FLAG (lsa->flag, OSPF6_LSA_DUPLICATE) &&
  442. CHECK_FLAG (lsa->flag, OSPF6_LSA_IMPLIEDACK))
  443. {
  444. if (IS_OSPF6_DEBUG_LSA (RECV))
  445. zlog_info (" AllOther, Duplicate, ImpliedAck, No acknowledgement.");
  446. return;
  447. }
  448. /* LSA is a duplicate, and was not treated as an implied acknowledgement.
  449. Direct acknowledgement sent */
  450. if (CHECK_FLAG (lsa->flag, OSPF6_LSA_DUPLICATE) &&
  451. ! CHECK_FLAG (lsa->flag, OSPF6_LSA_IMPLIEDACK))
  452. {
  453. if (IS_OSPF6_DEBUG_LSA (RECV))
  454. zlog_info (" AllOther, Duplicate, Not ImpliedAck, Direct acknowledgement.");
  455. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  456. zlog_info (" Add copy of %s to lsack_list of %s",
  457. lsa->name, from->name);
  458. ospf6_lsdb_add (ospf6_lsa_copy (lsa), from->lsack_list);
  459. if (from->thread_send_lsack == NULL)
  460. from->thread_send_lsack =
  461. thread_add_event (master, ospf6_lsack_send_neighbor, from, 0);
  462. return;
  463. }
  464. /* LSA's LS age is equal to Maxage, and there is no current instance
  465. of the LSA in the link state database, and none of router's
  466. neighbors are in states Exchange or Loading */
  467. /* Direct acknowledgement sent, but this case is handled in
  468. early of ospf6_receive_lsa () */
  469. }
  470. void
  471. ospf6_acknowledge_lsa (struct ospf6_lsa *lsa, int ismore_recent,
  472. struct ospf6_neighbor *from)
  473. {
  474. struct ospf6_interface *oi;
  475. assert (from && from->ospf6_if);
  476. oi = from->ospf6_if;
  477. if (oi->state == OSPF6_INTERFACE_BDR)
  478. ospf6_acknowledge_lsa_bdrouter (lsa, ismore_recent, from);
  479. else
  480. ospf6_acknowledge_lsa_allother (lsa, ismore_recent, from);
  481. }
  482. /* RFC2328 section 13 (4):
  483. if MaxAge LSA and if we have no instance, and no neighbor
  484. is in states Exchange or Loading
  485. returns 1 if match this case, else returns 0 */
  486. static int
  487. ospf6_is_maxage_lsa_drop (struct ospf6_lsa *lsa,
  488. struct ospf6_neighbor *from)
  489. {
  490. struct ospf6_lsdb *lsdb = NULL;
  491. struct ospf6_neighbor *on;
  492. struct ospf6_interface *oi, *ospf6_if = NULL;
  493. struct ospf6_area *oa, *area = NULL;
  494. struct ospf6 *ospf6 = NULL;
  495. u_int16_t scope_type;
  496. list scoped_interfaces;
  497. listnode i, j;
  498. int count = 0;
  499. if (! OSPF6_LSA_IS_MAXAGE (lsa))
  500. return 0;
  501. lsdb = ospf6_get_scoped_lsdb (lsa->header->type, lsa->scope);
  502. if (lsdb == NULL)
  503. {
  504. zlog_info ("Can't decide scoped LSDB");
  505. return 0;
  506. }
  507. if (ospf6_lsdb_lookup (lsa->header->type, lsa->header->id,
  508. lsa->header->adv_router, lsdb))
  509. return 0;
  510. scoped_interfaces = list_new ();
  511. scope_type = OSPF6_LSA_SCOPE (lsa->header->type);
  512. if (scope_type == OSPF6_LSA_SCOPE_LINKLOCAL)
  513. {
  514. ospf6_if = (struct ospf6_interface *) lsa->scope;
  515. area = ospf6_if->area;
  516. ospf6 = area->ospf6;
  517. }
  518. else if (scope_type == OSPF6_LSA_SCOPE_AREA)
  519. {
  520. area = (struct ospf6_area *) lsa->scope;
  521. ospf6 = area->ospf6;
  522. }
  523. else if (scope_type == OSPF6_LSA_SCOPE_AS)
  524. {
  525. ospf6 = (struct ospf6 *) lsa->scope;
  526. }
  527. else
  528. {
  529. zlog_info ("Can't decide LSA scope");
  530. return 0;
  531. }
  532. /* Collect eligible interfaces */
  533. for (i = listhead (ospf6->area_list); i; nextnode (i))
  534. {
  535. oa = (struct ospf6_area *) getdata (i);
  536. if (scope_type != OSPF6_LSA_SCOPE_AS && oa != area)
  537. continue;
  538. for (j = listhead (oa->if_list); j; nextnode (j))
  539. {
  540. oi = (struct ospf6_interface *) getdata (j);
  541. if (scope_type != OSPF6_LSA_SCOPE_AS &&
  542. scope_type != OSPF6_LSA_SCOPE_AREA && oi != ospf6_if)
  543. continue;
  544. listnode_add (scoped_interfaces, oi);
  545. }
  546. }
  547. for (i = listhead (scoped_interfaces); i; nextnode (i))
  548. {
  549. oi = (struct ospf6_interface *) getdata (i);
  550. for (j = listhead (oi->neighbor_list); j; nextnode (j))
  551. {
  552. on = (struct ospf6_neighbor *) getdata (j);
  553. if (on->state == OSPF6_NEIGHBOR_EXCHANGE ||
  554. on->state == OSPF6_NEIGHBOR_LOADING)
  555. count ++;
  556. }
  557. }
  558. list_delete (scoped_interfaces);
  559. if (count == 0)
  560. return 1;
  561. return 0;
  562. }
  563. /* RFC2328 section 13 The Flooding Procedure */
  564. void
  565. ospf6_receive_lsa (struct ospf6_lsa_header *lsa_header,
  566. struct ospf6_neighbor *from)
  567. {
  568. struct ospf6_lsa *new = NULL, *old = NULL, *rem = NULL;
  569. int ismore_recent;
  570. unsigned short cksum;
  571. struct ospf6_lsdb *lsdb = NULL;
  572. ismore_recent = 1;
  573. /* make lsa structure for received lsa */
  574. new = ospf6_lsa_create (lsa_header);
  575. if (IS_OSPF6_DEBUG_LSA (RECV))
  576. {
  577. zlog_info ("LSA Receive from %s", from->name);
  578. ospf6_lsa_header_print (new);
  579. }
  580. new->scope = ospf6_get_lsa_scope (new->header->type, from);
  581. if (new->scope == NULL)
  582. {
  583. zlog_warn ("Can't decide LSA scope, ignore");
  584. ospf6_lsa_delete (new);
  585. return;
  586. }
  587. /* (1) LSA Checksum */
  588. cksum = ntohs (new->header->checksum);
  589. if (ntohs (ospf6_lsa_checksum (new->header)) != cksum)
  590. {
  591. if (IS_OSPF6_DEBUG_LSA (RECV))
  592. zlog_info ("Wrong LSA Checksum");
  593. ospf6_lsa_delete (new);
  594. return;
  595. }
  596. /* (3) Ebit Missmatch: AS-External-LSA */
  597. if (ntohs (new->header->type) == OSPF6_LSTYPE_AS_EXTERNAL &&
  598. ospf6_area_is_stub (from->ospf6_if->area))
  599. {
  600. if (IS_OSPF6_DEBUG_LSA (RECV))
  601. zlog_info ("AS-External-LSA in stub area");
  602. ospf6_lsa_delete (new);
  603. return;
  604. }
  605. /* (4) if MaxAge LSA and if we have no instance, and no neighbor
  606. is in states Exchange or Loading */
  607. if (ospf6_is_maxage_lsa_drop (new, from))
  608. {
  609. /* log */
  610. if (IS_OSPF6_DEBUG_LSA (RECV))
  611. zlog_info ("Drop MaxAge LSA with Direct acknowledgement.");
  612. /* a) Acknowledge back to neighbor (Direct acknowledgement, 13.5) */
  613. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  614. zlog_info (" Add %s to lsack_list of %s",
  615. new->name, from->name);
  616. ospf6_lsdb_add (new, from->lsack_list);
  617. if (from->thread_send_lsack == NULL)
  618. from->thread_send_lsack =
  619. thread_add_event (master, ospf6_lsack_send_neighbor, from, 0);
  620. /* b) Discard */
  621. /* "new" LSA will be discarded just after the LSAck sent */
  622. return;
  623. }
  624. /* (5) */
  625. /* lookup the same database copy in lsdb */
  626. lsdb = ospf6_get_scoped_lsdb (new->header->type, new->scope);
  627. if (lsdb == NULL)
  628. {
  629. zlog_warn ("Can't decide scoped LSDB, ignore");
  630. ospf6_lsa_delete (new);
  631. return;
  632. }
  633. old = ospf6_lsdb_lookup (new->header->type, new->header->id,
  634. new->header->adv_router, lsdb);
  635. if (old)
  636. {
  637. ismore_recent = ospf6_lsa_compare (new, old);
  638. if (ntohl (new->header->seqnum) == ntohl (old->header->seqnum))
  639. {
  640. if (IS_OSPF6_DEBUG_LSA (RECV))
  641. zlog_info ("Duplicated LSA");
  642. SET_FLAG (new->flag, OSPF6_LSA_DUPLICATE);
  643. }
  644. }
  645. /* if no database copy or received is more recent */
  646. if (old == NULL || ismore_recent < 0)
  647. {
  648. /* in case we have no database copy */
  649. ismore_recent = -1;
  650. /* (a) MinLSArrival check */
  651. if (old)
  652. {
  653. struct timeval now, res;
  654. gettimeofday (&now, (struct timezone *) NULL);
  655. timersub (&now, &old->installed, &res);
  656. if (res.tv_sec < MIN_LS_ARRIVAL)
  657. {
  658. if (IS_OSPF6_DEBUG_LSA (RECV) || IS_OSPF6_DEBUG_LSA (TIMER))
  659. zlog_info ("LSA can't be updated within MinLSArrival");
  660. ospf6_lsa_delete (new);
  661. return; /* examin next lsa */
  662. }
  663. }
  664. /* (b) immediately flood and (c) remove from all retrans-list */
  665. ospf6_flood_lsa (new, from);
  666. /* (d), installing lsdb, which may cause routing
  667. table calculation (replacing database copy) */
  668. ospf6_install_lsa (new, lsdb);
  669. /* (e) possibly acknowledge */
  670. ospf6_acknowledge_lsa (new, ismore_recent, from);
  671. /* (f) */
  672. /* Self Originated LSA, section 13.4 */
  673. if (new->header->adv_router == from->ospf6_if->area->ospf6->router_id
  674. && (! old || ismore_recent < 0))
  675. {
  676. /* We have to make a new instance of the LSA
  677. or have to flush this LSA. */
  678. if (IS_OSPF6_DEBUG_LSA (RECV))
  679. zlog_info ("New instance of the self-originated LSA");
  680. SET_FLAG (new->flag, OSPF6_LSA_REFRESH);
  681. ospf6_lsa_re_originate (new);
  682. }
  683. return;
  684. }
  685. /* (6) if there is instance on sending neighbor's request list */
  686. if (ospf6_lsdb_lookup (new->header->type, new->header->id,
  687. new->header->adv_router, from->request_list))
  688. {
  689. /* if no database copy, should go above state (5) */
  690. assert (old);
  691. if (IS_OSPF6_DEBUG_LSA (RECV))
  692. zlog_info ("LSA is not newer and on request-list of sending neighbor");
  693. /* BadLSReq */
  694. thread_add_event (master, bad_lsreq, from, 0);
  695. ospf6_lsa_delete (new);
  696. return;
  697. }
  698. /* (7) if neither one is more recent */
  699. if (ismore_recent == 0)
  700. {
  701. if (IS_OSPF6_DEBUG_LSA (RECV))
  702. zlog_info ("The same instance as database copy");
  703. /* (a) if on retrans-list, Treat this LSA as an Ack: Implied Ack */
  704. rem = ospf6_lsdb_lookup (new->header->type, new->header->id,
  705. new->header->adv_router, from->retrans_list);
  706. if (rem)
  707. {
  708. if (IS_OSPF6_DEBUG_LSA (RECV))
  709. zlog_info ("Treat as an Implied acknowledgement");
  710. SET_FLAG (new->flag, OSPF6_LSA_IMPLIEDACK);
  711. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  712. zlog_info ("Remove %s from retrans_list of %s",
  713. rem->name, from->name);
  714. ospf6_lsdb_remove (rem, from->retrans_list);
  715. }
  716. /* (b) possibly acknowledge */
  717. ospf6_acknowledge_lsa (new, ismore_recent, from);
  718. ospf6_lsa_delete (new);
  719. return;
  720. }
  721. /* (8) previous database copy is more recent */
  722. {
  723. assert (old);
  724. /* If database copy is in 'Seqnumber Wrapping',
  725. simply discard the received LSA */
  726. if (OSPF6_LSA_IS_MAXAGE (old) &&
  727. old->header->seqnum == htonl (MAX_SEQUENCE_NUMBER))
  728. {
  729. if (IS_OSPF6_DEBUG_LSA (RECV))
  730. zlog_info ("Database copy is in Seqnumber Wrapping");
  731. ospf6_lsa_delete (new);
  732. return;
  733. }
  734. /* Otherwise, Send database copy of this LSA to this neighbor */
  735. {
  736. if (IS_OSPF6_DEBUG_LSA (RECV))
  737. zlog_info ("Database is more recent, send back directly");
  738. /* XXX, MinLSArrival check !? RFC 2328 13 (8) */
  739. if (IS_OSPF6_DEBUG_LSA (DATABASE))
  740. zlog_info (" Add copy of %s to lsupdate_list of %s",
  741. old->name, from->name);
  742. ospf6_lsdb_add (ospf6_lsa_copy (old), from->lsupdate_list);
  743. if (from->thread_send_lsupdate == NULL)
  744. from->thread_send_lsupdate =
  745. thread_add_event (master, ospf6_lsupdate_send_neighbor, from, 0);
  746. ospf6_lsa_delete (new);
  747. return;
  748. }
  749. return;
  750. }
  751. }