ospf_flood.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. /*
  2. * OSPF Flooding -- RFC2328 Section 13.
  3. * Copyright (C) 1999, 2000 Toshiaki Takada
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation; either version 2, or (at your
  10. * option) any later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "linklist.h"
  24. #include "prefix.h"
  25. #include "if.h"
  26. #include "command.h"
  27. #include "table.h"
  28. #include "thread.h"
  29. #include "memory.h"
  30. #include "log.h"
  31. #include "zclient.h"
  32. #include "ospfd/ospfd.h"
  33. #include "ospfd/ospf_interface.h"
  34. #include "ospfd/ospf_ism.h"
  35. #include "ospfd/ospf_asbr.h"
  36. #include "ospfd/ospf_lsa.h"
  37. #include "ospfd/ospf_lsdb.h"
  38. #include "ospfd/ospf_neighbor.h"
  39. #include "ospfd/ospf_nsm.h"
  40. #include "ospfd/ospf_spf.h"
  41. #include "ospfd/ospf_flood.h"
  42. #include "ospfd/ospf_packet.h"
  43. #include "ospfd/ospf_abr.h"
  44. #include "ospfd/ospf_route.h"
  45. #include "ospfd/ospf_zebra.h"
  46. #include "ospfd/ospf_dump.h"
  47. extern struct zclient *zclient;
  48. /* Do the LSA acking specified in table 19, Section 13.5, row 2
  49. * This get called from ospf_flood_out_interface. Declared inline
  50. * for speed. */
  51. static void
  52. ospf_flood_delayed_lsa_ack (struct ospf_neighbor *inbr, struct ospf_lsa *lsa)
  53. {
  54. /* LSA is more recent than database copy, but was not
  55. flooded back out receiving interface. Delayed
  56. acknowledgment sent. If interface is in Backup state
  57. delayed acknowledgment sent only if advertisement
  58. received from Designated Router, otherwise do nothing See
  59. RFC 2328 Section 13.5 */
  60. /* Whether LSA is more recent or not, and whether this is in
  61. response to the LSA being sent out recieving interface has been
  62. worked out previously */
  63. /* Deal with router as BDR */
  64. if (inbr->oi->state == ISM_Backup && ! NBR_IS_DR (inbr))
  65. return;
  66. /* Schedule a delayed LSA Ack to be sent */
  67. listnode_add (inbr->oi->ls_ack, ospf_lsa_lock (lsa)); /* delayed LSA Ack */
  68. }
  69. /* Check LSA is related to external info. */
  70. struct external_info *
  71. ospf_external_info_check (struct ospf_lsa *lsa)
  72. {
  73. struct as_external_lsa *al;
  74. struct prefix_ipv4 p;
  75. struct route_node *rn;
  76. int type;
  77. al = (struct as_external_lsa *) lsa->data;
  78. p.family = AF_INET;
  79. p.prefix = lsa->data->id;
  80. p.prefixlen = ip_masklen (al->mask);
  81. for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
  82. {
  83. int redist_type = is_prefix_default (&p) ? DEFAULT_ROUTE : type;
  84. if (ospf_is_type_redistributed (redist_type))
  85. if (EXTERNAL_INFO (type))
  86. {
  87. rn = route_node_lookup (EXTERNAL_INFO (type),
  88. (struct prefix *) &p);
  89. if (rn)
  90. {
  91. route_unlock_node (rn);
  92. if (rn->info != NULL)
  93. return (struct external_info *) rn->info;
  94. }
  95. }
  96. }
  97. return NULL;
  98. }
  99. static void
  100. ospf_process_self_originated_lsa (struct ospf *ospf,
  101. struct ospf_lsa *new, struct ospf_area *area)
  102. {
  103. struct ospf_interface *oi;
  104. struct external_info *ei;
  105. struct listnode *node;
  106. if (IS_DEBUG_OSPF_EVENT)
  107. zlog_debug ("LSA[Type%d:%s]: Process self-originated LSA seq 0x%x",
  108. new->data->type, inet_ntoa (new->data->id),
  109. ntohl(new->data->ls_seqnum));
  110. /* If we're here, we installed a self-originated LSA that we received
  111. from a neighbor, i.e. it's more recent. We must see whether we want
  112. to originate it.
  113. If yes, we should use this LSA's sequence number and reoriginate
  114. a new instance.
  115. if not --- we must flush this LSA from the domain. */
  116. switch (new->data->type)
  117. {
  118. case OSPF_ROUTER_LSA:
  119. /* Originate a new instance and schedule flooding */
  120. if (area->router_lsa_self)
  121. area->router_lsa_self->data->ls_seqnum = new->data->ls_seqnum;
  122. ospf_router_lsa_update_area (area);
  123. return;
  124. case OSPF_NETWORK_LSA:
  125. case OSPF_OPAQUE_LINK_LSA:
  126. /* We must find the interface the LSA could belong to.
  127. If the interface is no more a broadcast type or we are no more
  128. the DR, we flush the LSA otherwise -- create the new instance and
  129. schedule flooding. */
  130. /* Look through all interfaces, not just area, since interface
  131. could be moved from one area to another. */
  132. for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
  133. /* These are sanity check. */
  134. if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &new->data->id))
  135. {
  136. if (oi->area != area ||
  137. oi->type != OSPF_IFTYPE_BROADCAST ||
  138. !IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi)))
  139. {
  140. ospf_schedule_lsa_flush_area (area, new);
  141. return;
  142. }
  143. if (new->data->type == OSPF_OPAQUE_LINK_LSA)
  144. {
  145. ospf_opaque_lsa_refresh (new);
  146. return;
  147. }
  148. if (oi->network_lsa_self)
  149. oi->network_lsa_self->data->ls_seqnum = new->data->ls_seqnum;
  150. /* Schedule network-LSA origination. */
  151. ospf_network_lsa_update (oi);
  152. return;
  153. }
  154. break;
  155. case OSPF_SUMMARY_LSA:
  156. case OSPF_ASBR_SUMMARY_LSA:
  157. ospf_schedule_abr_task (ospf);
  158. break;
  159. case OSPF_AS_EXTERNAL_LSA :
  160. case OSPF_AS_NSSA_LSA:
  161. if ( (new->data->type == OSPF_AS_EXTERNAL_LSA)
  162. && CHECK_FLAG (new->flags, OSPF_LSA_LOCAL_XLT))
  163. {
  164. ospf_translated_nssa_refresh (ospf, NULL, new);
  165. return;
  166. }
  167. ei = ospf_external_info_check (new);
  168. if (ei)
  169. ospf_external_lsa_refresh (ospf, new, ei, LSA_REFRESH_FORCE);
  170. else
  171. ospf_lsa_flush_as (ospf, new);
  172. break;
  173. case OSPF_OPAQUE_AREA_LSA:
  174. ospf_opaque_lsa_refresh (new);
  175. break;
  176. case OSPF_OPAQUE_AS_LSA:
  177. ospf_opaque_lsa_refresh (new); /* Reconsideration may needed. *//* XXX */
  178. break;
  179. default:
  180. break;
  181. }
  182. }
  183. /* OSPF LSA flooding -- RFC2328 Section 13.(5). */
  184. /* Now Updated for NSSA operation, as follows:
  185. Type-5's have no change. Blocked to STUB or NSSA.
  186. Type-7's can be received, and if a DR
  187. they will also flood the local NSSA Area as Type-7's
  188. If a Self-Originated LSA (now an ASBR),
  189. The LSDB will be updated as Type-5's, (for continual re-fresh)
  190. If an NSSA-IR it is installed/flooded as Type-7, P-bit on.
  191. if an NSSA-ABR it is installed/flooded as Type-7, P-bit off.
  192. Later, during the ABR TASK, if the ABR is the Elected NSSA
  193. translator, then All Type-7s (with P-bit ON) are Translated to
  194. Type-5's and flooded to all non-NSSA/STUB areas.
  195. During ASE Calculations,
  196. non-ABRs calculate external routes from Type-7's
  197. ABRs calculate external routes from Type-5's and non-self Type-7s
  198. */
  199. int
  200. ospf_flood (struct ospf *ospf, struct ospf_neighbor *nbr,
  201. struct ospf_lsa *current, struct ospf_lsa *new)
  202. {
  203. struct ospf_interface *oi;
  204. int lsa_ack_flag;
  205. /* Type-7 LSA's will be flooded throughout their native NSSA area,
  206. but will also be flooded as Type-5's into ABR capable links. */
  207. if (IS_DEBUG_OSPF_EVENT)
  208. zlog_debug ("LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
  209. inet_ntoa (nbr->router_id),
  210. LOOKUP (ospf_nsm_state_msg, nbr->state),
  211. (void *)current,
  212. dump_lsa_key (new));
  213. lsa_ack_flag = 0;
  214. oi = nbr->oi;
  215. /* If there is already a database copy, and if the
  216. database copy was received via flooding and installed less
  217. than MinLSArrival seconds ago, discard the new LSA
  218. (without acknowledging it). */
  219. if (current != NULL) /* -- endo. */
  220. {
  221. if (IS_LSA_SELF (current)
  222. && (ntohs (current->data->ls_age) == 0
  223. && ntohl (current->data->ls_seqnum) == OSPF_INITIAL_SEQUENCE_NUMBER))
  224. {
  225. if (IS_DEBUG_OSPF_EVENT)
  226. zlog_debug ("LSA[Flooding]: Got a self-originated LSA, "
  227. "while local one is initial instance.");
  228. ; /* Accept this LSA for quick LSDB resynchronization. */
  229. }
  230. else if (tv_cmp (tv_sub (recent_relative_time (), current->tv_recv),
  231. msec2tv (ospf->min_ls_arrival)) < 0)
  232. {
  233. if (IS_DEBUG_OSPF_EVENT)
  234. zlog_debug ("LSA[Flooding]: LSA is received recently.");
  235. return -1;
  236. }
  237. }
  238. /* Flood the new LSA out some subset of the router's interfaces.
  239. In some cases (e.g., the state of the receiving interface is
  240. DR and the LSA was received from a router other than the
  241. Backup DR) the LSA will be flooded back out the receiving
  242. interface. */
  243. lsa_ack_flag = ospf_flood_through (ospf, nbr, new);
  244. /* Remove the current database copy from all neighbors' Link state
  245. retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
  246. ^^^^^^^^^^^^^^^^^^^^^^^
  247. not have area ID.
  248. All other (even NSSA's) do have area ID. */
  249. if (current)
  250. {
  251. switch (current->data->type)
  252. {
  253. case OSPF_AS_EXTERNAL_LSA:
  254. case OSPF_OPAQUE_AS_LSA:
  255. ospf_ls_retransmit_delete_nbr_as (ospf, current);
  256. break;
  257. default:
  258. ospf_ls_retransmit_delete_nbr_area (nbr->oi->area, current);
  259. break;
  260. }
  261. }
  262. /* Do some internal house keeping that is needed here */
  263. SET_FLAG (new->flags, OSPF_LSA_RECEIVED);
  264. ospf_lsa_is_self_originated (ospf, new); /* Let it set the flag */
  265. /* Install the new LSA in the link state database
  266. (replacing the current database copy). This may cause the
  267. routing table calculation to be scheduled. In addition,
  268. timestamp the new LSA with the current time. The flooding
  269. procedure cannot overwrite the newly installed LSA until
  270. MinLSArrival seconds have elapsed. */
  271. if (! (new = ospf_lsa_install (ospf, nbr->oi, new)))
  272. return -1; /* unknown LSA type or any other error condition */
  273. /* Acknowledge the receipt of the LSA by sending a Link State
  274. Acknowledgment packet back out the receiving interface. */
  275. if (lsa_ack_flag)
  276. ospf_flood_delayed_lsa_ack (nbr, new);
  277. /* If this new LSA indicates that it was originated by the
  278. receiving router itself, the router must take special action,
  279. either updating the LSA or in some cases flushing it from
  280. the routing domain. */
  281. if (ospf_lsa_is_self_originated (ospf, new))
  282. ospf_process_self_originated_lsa (ospf, new, oi->area);
  283. else
  284. /* Update statistics value for OSPF-MIB. */
  285. ospf->rx_lsa_count++;
  286. return 0;
  287. }
  288. /* OSPF LSA flooding -- RFC2328 Section 13.3. */
  289. static int
  290. ospf_flood_through_interface (struct ospf_interface *oi,
  291. struct ospf_neighbor *inbr,
  292. struct ospf_lsa *lsa)
  293. {
  294. struct ospf_neighbor *onbr;
  295. struct route_node *rn;
  296. int retx_flag;
  297. if (IS_DEBUG_OSPF_EVENT)
  298. zlog_debug ("ospf_flood_through_interface(): "
  299. "considering int %s, INBR(%s), LSA[%s]",
  300. IF_NAME (oi), inbr ? inet_ntoa (inbr->router_id) : "NULL",
  301. dump_lsa_key (lsa));
  302. if (!ospf_if_is_enable (oi))
  303. return 0;
  304. /* Remember if new LSA is aded to a retransmit list. */
  305. retx_flag = 0;
  306. /* Each of the neighbors attached to this interface are examined,
  307. to determine whether they must receive the new LSA. The following
  308. steps are executed for each neighbor: */
  309. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  310. {
  311. struct ospf_lsa *ls_req;
  312. if (rn->info == NULL)
  313. continue;
  314. onbr = rn->info;
  315. if (IS_DEBUG_OSPF_EVENT)
  316. zlog_debug ("ospf_flood_through_interface(): considering nbr %s (%s)",
  317. inet_ntoa (onbr->router_id),
  318. LOOKUP (ospf_nsm_state_msg, onbr->state));
  319. /* If the neighbor is in a lesser state than Exchange, it
  320. does not participate in flooding, and the next neighbor
  321. should be examined. */
  322. if (onbr->state < NSM_Exchange)
  323. continue;
  324. /* If the adjacency is not yet full (neighbor state is
  325. Exchange or Loading), examine the Link state request
  326. list associated with this adjacency. If there is an
  327. instance of the new LSA on the list, it indicates that
  328. the neighboring router has an instance of the LSA
  329. already. Compare the new LSA to the neighbor's copy: */
  330. if (onbr->state < NSM_Full)
  331. {
  332. if (IS_DEBUG_OSPF_EVENT)
  333. zlog_debug ("ospf_flood_through_interface(): nbr adj is not Full");
  334. ls_req = ospf_ls_request_lookup (onbr, lsa);
  335. if (ls_req != NULL)
  336. {
  337. int ret;
  338. ret = ospf_lsa_more_recent (ls_req, lsa);
  339. /* The new LSA is less recent. */
  340. if (ret > 0)
  341. continue;
  342. /* The two copies are the same instance, then delete
  343. the LSA from the Link state request list. */
  344. else if (ret == 0)
  345. {
  346. ospf_ls_request_delete (onbr, ls_req);
  347. ospf_check_nbr_loading (onbr);
  348. continue;
  349. }
  350. /* The new LSA is more recent. Delete the LSA
  351. from the Link state request list. */
  352. else
  353. {
  354. ospf_ls_request_delete (onbr, ls_req);
  355. ospf_check_nbr_loading (onbr);
  356. }
  357. }
  358. }
  359. if (IS_OPAQUE_LSA (lsa->data->type))
  360. {
  361. if (! CHECK_FLAG (onbr->options, OSPF_OPTION_O))
  362. {
  363. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
  364. zlog_debug ("Skip this neighbor: Not Opaque-capable.");
  365. continue;
  366. }
  367. }
  368. /* If the new LSA was received from this neighbor,
  369. examine the next neighbor. */
  370. #ifdef ORIGINAL_CODING
  371. if (inbr)
  372. if (IPV4_ADDR_SAME (&inbr->router_id, &onbr->router_id))
  373. continue;
  374. #else /* ORIGINAL_CODING */
  375. if (inbr)
  376. {
  377. /*
  378. * Triggered by LSUpd message parser "ospf_ls_upd ()".
  379. * E.g., all LSAs handling here is received via network.
  380. */
  381. if (IPV4_ADDR_SAME (&inbr->router_id, &onbr->router_id))
  382. {
  383. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
  384. zlog_debug ("Skip this neighbor: inbr == onbr");
  385. continue;
  386. }
  387. }
  388. else
  389. {
  390. /*
  391. * Triggered by MaxAge remover, so far.
  392. * NULL "inbr" means flooding starts from this node.
  393. */
  394. if (IPV4_ADDR_SAME (&lsa->data->adv_router, &onbr->router_id))
  395. {
  396. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
  397. zlog_debug ("Skip this neighbor: lsah->adv_router == onbr");
  398. continue;
  399. }
  400. }
  401. #endif /* ORIGINAL_CODING */
  402. /* Add the new LSA to the Link state retransmission list
  403. for the adjacency. The LSA will be retransmitted
  404. at intervals until an acknowledgment is seen from
  405. the neighbor. */
  406. ospf_ls_retransmit_add (onbr, lsa);
  407. retx_flag = 1;
  408. }
  409. /* If in the previous step, the LSA was NOT added to any of
  410. the Link state retransmission lists, there is no need to
  411. flood the LSA out the interface. */
  412. if (retx_flag == 0)
  413. {
  414. return (inbr && inbr->oi == oi);
  415. }
  416. /* if we've received the lsa on this interface we need to perform
  417. additional checking */
  418. if (inbr && (inbr->oi == oi))
  419. {
  420. /* If the new LSA was received on this interface, and it was
  421. received from either the Designated Router or the Backup
  422. Designated Router, chances are that all the neighbors have
  423. received the LSA already. */
  424. if (NBR_IS_DR (inbr) || NBR_IS_BDR (inbr))
  425. {
  426. if (IS_DEBUG_OSPF_NSSA)
  427. zlog_debug ("ospf_flood_through_interface(): "
  428. "DR/BDR NOT SEND to int %s", IF_NAME (oi));
  429. return 1;
  430. }
  431. /* If the new LSA was received on this interface, and the
  432. interface state is Backup, examine the next interface. The
  433. Designated Router will do the flooding on this interface.
  434. However, if the Designated Router fails the router will
  435. end up retransmitting the updates. */
  436. if (oi->state == ISM_Backup)
  437. {
  438. if (IS_DEBUG_OSPF_NSSA)
  439. zlog_debug ("ospf_flood_through_interface(): "
  440. "ISM_Backup NOT SEND to int %s", IF_NAME (oi));
  441. return 1;
  442. }
  443. }
  444. /* The LSA must be flooded out the interface. Send a Link State
  445. Update packet (including the new LSA as contents) out the
  446. interface. The LSA's LS age must be incremented by InfTransDelay
  447. (which must be > 0) when it is copied into the outgoing Link
  448. State Update packet (until the LS age field reaches the maximum
  449. value of MaxAge). */
  450. /* XXX HASSO: Is this IS_DEBUG_OSPF_NSSA really correct? */
  451. if (IS_DEBUG_OSPF_NSSA)
  452. zlog_debug ("ospf_flood_through_interface(): "
  453. "DR/BDR sending upd to int %s", IF_NAME (oi));
  454. /* RFC2328 Section 13.3
  455. On non-broadcast networks, separate Link State Update
  456. packets must be sent, as unicasts, to each adjacent neighbor
  457. (i.e., those in state Exchange or greater). The destination
  458. IP addresses for these packets are the neighbors' IP
  459. addresses. */
  460. if (oi->type == OSPF_IFTYPE_NBMA)
  461. {
  462. struct route_node *rn;
  463. struct ospf_neighbor *nbr;
  464. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  465. if ((nbr = rn->info) != NULL)
  466. if (nbr != oi->nbr_self && nbr->state >= NSM_Exchange)
  467. ospf_ls_upd_send_lsa (nbr, lsa, OSPF_SEND_PACKET_DIRECT);
  468. }
  469. else
  470. ospf_ls_upd_send_lsa (oi->nbr_self, lsa, OSPF_SEND_PACKET_INDIRECT);
  471. return 0;
  472. }
  473. int
  474. ospf_flood_through_area (struct ospf_area *area,
  475. struct ospf_neighbor *inbr, struct ospf_lsa *lsa)
  476. {
  477. struct listnode *node, *nnode;
  478. struct ospf_interface *oi;
  479. int lsa_ack_flag = 0;
  480. /* All other types are specific to a single area (Area A). The
  481. eligible interfaces are all those interfaces attaching to the
  482. Area A. If Area A is the backbone, this includes all the virtual
  483. links. */
  484. for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi))
  485. {
  486. if (area->area_id.s_addr != OSPF_AREA_BACKBONE &&
  487. oi->type == OSPF_IFTYPE_VIRTUALLINK)
  488. continue;
  489. if ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) && (lsa->oi != oi))
  490. {
  491. /*
  492. * Link local scoped Opaque-LSA should only be flooded
  493. * for the link on which the LSA has received.
  494. */
  495. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
  496. zlog_debug ("Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)",
  497. (void *)lsa->oi, (void *)oi);
  498. continue;
  499. }
  500. if (ospf_flood_through_interface (oi, inbr, lsa))
  501. lsa_ack_flag = 1;
  502. }
  503. return (lsa_ack_flag);
  504. }
  505. int
  506. ospf_flood_through_as (struct ospf *ospf, struct ospf_neighbor *inbr,
  507. struct ospf_lsa *lsa)
  508. {
  509. struct listnode *node;
  510. struct ospf_area *area;
  511. int lsa_ack_flag;
  512. lsa_ack_flag = 0;
  513. /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
  514. Divert the Type-5 LSA's to all non-NSSA/STUB areas
  515. Divert the Type-7 LSA's to all NSSA areas
  516. AS-external-LSAs are flooded throughout the entire AS, with the
  517. exception of stub areas (see Section 3.6). The eligible
  518. interfaces are all the router's interfaces, excluding virtual
  519. links and those interfaces attaching to stub areas. */
  520. if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) /* Translated from 7 */
  521. if (IS_DEBUG_OSPF_NSSA)
  522. zlog_debug ("Flood/AS: NSSA TRANSLATED LSA");
  523. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  524. {
  525. int continue_flag = 0;
  526. struct listnode *if_node;
  527. struct ospf_interface *oi;
  528. switch (area->external_routing)
  529. {
  530. /* Don't send AS externals into stub areas. Various types
  531. of support for partial stub areas can be implemented
  532. here. NSSA's will receive Type-7's that have areas
  533. matching the originl LSA. */
  534. case OSPF_AREA_NSSA: /* Sending Type 5 or 7 into NSSA area */
  535. /* Type-7, flood NSSA area */
  536. if (lsa->data->type == OSPF_AS_NSSA_LSA
  537. && area == lsa->area)
  538. /* We will send it. */
  539. continue_flag = 0;
  540. else
  541. continue_flag = 1; /* Skip this NSSA area for Type-5's et al */
  542. break;
  543. case OSPF_AREA_TYPE_MAX:
  544. case OSPF_AREA_STUB:
  545. continue_flag = 1; /* Skip this area. */
  546. break;
  547. case OSPF_AREA_DEFAULT:
  548. default:
  549. /* No Type-7 into normal area */
  550. if (lsa->data->type == OSPF_AS_NSSA_LSA)
  551. continue_flag = 1; /* skip Type-7 */
  552. else
  553. continue_flag = 0; /* Do this area. */
  554. break;
  555. }
  556. /* Do continue for above switch. Saves a big if then mess */
  557. if (continue_flag)
  558. continue; /* main for-loop */
  559. /* send to every interface in this area */
  560. for (ALL_LIST_ELEMENTS_RO (area->oiflist, if_node, oi))
  561. {
  562. /* Skip virtual links */
  563. if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
  564. if (ospf_flood_through_interface (oi, inbr, lsa)) /* lsa */
  565. lsa_ack_flag = 1;
  566. }
  567. } /* main area for-loop */
  568. return (lsa_ack_flag);
  569. }
  570. int
  571. ospf_flood_through (struct ospf *ospf,
  572. struct ospf_neighbor *inbr, struct ospf_lsa *lsa)
  573. {
  574. int lsa_ack_flag = 0;
  575. /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
  576. upon return are updated in the LSDB for Type-7's. Later,
  577. re-fresh will re-send them (and also, if ABR, packet code will
  578. translate to Type-5's)
  579. As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
  580. NSSA) are flooded throughout the AS, and are updated in the
  581. global table. */
  582. #ifdef ORIGINAL_CODING
  583. switch (lsa->data->type)
  584. {
  585. case OSPF_ROUTER_LSA:
  586. case OSPF_NETWORK_LSA:
  587. case OSPF_SUMMARY_LSA:
  588. case OSPF_ASBR_SUMMARY_LSA:
  589. case OSPF_OPAQUE_LINK_LSA: /* ospf_flood_through_interface ? */
  590. case OSPF_OPAQUE_AREA_LSA:
  591. lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa);
  592. break;
  593. case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
  594. case OSPF_OPAQUE_AS_LSA:
  595. lsa_ack_flag = ospf_flood_through_as (ospf, inbr, lsa);
  596. break;
  597. /* Type-7 Only received within NSSA, then flooded */
  598. case OSPF_AS_NSSA_LSA:
  599. /* Any P-bit was installed with the Type-7. */
  600. lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa);
  601. if (IS_DEBUG_OSPF_NSSA)
  602. zlog_debug ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
  603. break;
  604. default:
  605. break;
  606. }
  607. #else /* ORIGINAL_CODING */
  608. /*
  609. * At the common sub-sub-function "ospf_flood_through_interface()",
  610. * a parameter "inbr" will be used to distinguish the called context
  611. * whether the given LSA was received from the neighbor, or the
  612. * flooding for the LSA starts from this node (e.g. the LSA was self-
  613. * originated, or the LSA is going to be flushed from routing domain).
  614. *
  615. * So, for consistency reasons, this function "ospf_flood_through()"
  616. * should also allow the usage that the given "inbr" parameter to be
  617. * NULL. If we do so, corresponding AREA parameter should be referred
  618. * by "lsa->area", instead of "inbr->oi->area".
  619. */
  620. switch (lsa->data->type)
  621. {
  622. case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
  623. case OSPF_OPAQUE_AS_LSA:
  624. lsa_ack_flag = ospf_flood_through_as (ospf, inbr, lsa);
  625. break;
  626. /* Type-7 Only received within NSSA, then flooded */
  627. case OSPF_AS_NSSA_LSA:
  628. /* Any P-bit was installed with the Type-7. */
  629. if (IS_DEBUG_OSPF_NSSA)
  630. zlog_debug ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
  631. /* Fallthrough */
  632. default:
  633. lsa_ack_flag = ospf_flood_through_area (lsa->area, inbr, lsa);
  634. break;
  635. }
  636. #endif /* ORIGINAL_CODING */
  637. return (lsa_ack_flag);
  638. }
  639. /* Management functions for neighbor's Link State Request list. */
  640. void
  641. ospf_ls_request_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
  642. {
  643. /*
  644. * We cannot make use of the newly introduced callback function
  645. * "lsdb->new_lsa_hook" to replace debug output below, just because
  646. * it seems no simple and smart way to pass neighbor information to
  647. * the common function "ospf_lsdb_add()" -- endo.
  648. */
  649. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
  650. zlog_debug ("RqstL(%lu)++, NBR(%s), LSA[%s]",
  651. ospf_ls_request_count (nbr),
  652. inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
  653. ospf_lsdb_add (&nbr->ls_req, lsa);
  654. }
  655. unsigned long
  656. ospf_ls_request_count (struct ospf_neighbor *nbr)
  657. {
  658. return ospf_lsdb_count_all (&nbr->ls_req);
  659. }
  660. int
  661. ospf_ls_request_isempty (struct ospf_neighbor *nbr)
  662. {
  663. return ospf_lsdb_isempty (&nbr->ls_req);
  664. }
  665. /* Remove LSA from neighbor's ls-request list. */
  666. void
  667. ospf_ls_request_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
  668. {
  669. if (nbr->ls_req_last == lsa)
  670. {
  671. ospf_lsa_unlock (&nbr->ls_req_last);
  672. nbr->ls_req_last = NULL;
  673. }
  674. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) /* -- endo. */
  675. zlog_debug ("RqstL(%lu)--, NBR(%s), LSA[%s]",
  676. ospf_ls_request_count (nbr),
  677. inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
  678. ospf_lsdb_delete (&nbr->ls_req, lsa);
  679. }
  680. /* Remove all LSA from neighbor's ls-requenst list. */
  681. void
  682. ospf_ls_request_delete_all (struct ospf_neighbor *nbr)
  683. {
  684. ospf_lsa_unlock (&nbr->ls_req_last);
  685. nbr->ls_req_last = NULL;
  686. ospf_lsdb_delete_all (&nbr->ls_req);
  687. }
  688. /* Lookup LSA from neighbor's ls-request list. */
  689. struct ospf_lsa *
  690. ospf_ls_request_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
  691. {
  692. return ospf_lsdb_lookup (&nbr->ls_req, lsa);
  693. }
  694. struct ospf_lsa *
  695. ospf_ls_request_new (struct lsa_header *lsah)
  696. {
  697. struct ospf_lsa *new;
  698. new = ospf_lsa_new ();
  699. new->data = ospf_lsa_data_new (OSPF_LSA_HEADER_SIZE);
  700. memcpy (new->data, lsah, OSPF_LSA_HEADER_SIZE);
  701. return new;
  702. }
  703. /* Management functions for neighbor's ls-retransmit list. */
  704. unsigned long
  705. ospf_ls_retransmit_count (struct ospf_neighbor *nbr)
  706. {
  707. return ospf_lsdb_count_all (&nbr->ls_rxmt);
  708. }
  709. unsigned long
  710. ospf_ls_retransmit_count_self (struct ospf_neighbor *nbr, int lsa_type)
  711. {
  712. return ospf_lsdb_count_self (&nbr->ls_rxmt, lsa_type);
  713. }
  714. int
  715. ospf_ls_retransmit_isempty (struct ospf_neighbor *nbr)
  716. {
  717. return ospf_lsdb_isempty (&nbr->ls_rxmt);
  718. }
  719. /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
  720. void
  721. ospf_ls_retransmit_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
  722. {
  723. struct ospf_lsa *old;
  724. old = ospf_ls_retransmit_lookup (nbr, lsa);
  725. if (ospf_lsa_more_recent (old, lsa) < 0)
  726. {
  727. if (old)
  728. {
  729. old->retransmit_counter--;
  730. ospf_lsdb_delete (&nbr->ls_rxmt, old);
  731. }
  732. lsa->retransmit_counter++;
  733. /*
  734. * We cannot make use of the newly introduced callback function
  735. * "lsdb->new_lsa_hook" to replace debug output below, just because
  736. * it seems no simple and smart way to pass neighbor information to
  737. * the common function "ospf_lsdb_add()" -- endo.
  738. */
  739. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
  740. zlog_debug ("RXmtL(%lu)++, NBR(%s), LSA[%s]",
  741. ospf_ls_retransmit_count (nbr),
  742. inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
  743. ospf_lsdb_add (&nbr->ls_rxmt, lsa);
  744. }
  745. }
  746. /* Remove LSA from neibghbor's ls-retransmit list. */
  747. void
  748. ospf_ls_retransmit_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
  749. {
  750. if (ospf_ls_retransmit_lookup (nbr, lsa))
  751. {
  752. lsa->retransmit_counter--;
  753. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) /* -- endo. */
  754. zlog_debug ("RXmtL(%lu)--, NBR(%s), LSA[%s]",
  755. ospf_ls_retransmit_count (nbr),
  756. inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
  757. ospf_lsdb_delete (&nbr->ls_rxmt, lsa);
  758. }
  759. }
  760. /* Clear neighbor's ls-retransmit list. */
  761. void
  762. ospf_ls_retransmit_clear (struct ospf_neighbor *nbr)
  763. {
  764. struct ospf_lsdb *lsdb;
  765. int i;
  766. lsdb = &nbr->ls_rxmt;
  767. for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
  768. {
  769. struct route_table *table = lsdb->type[i].db;
  770. struct route_node *rn;
  771. struct ospf_lsa *lsa;
  772. for (rn = route_top (table); rn; rn = route_next (rn))
  773. if ((lsa = rn->info) != NULL)
  774. ospf_ls_retransmit_delete (nbr, lsa);
  775. }
  776. ospf_lsa_unlock (&nbr->ls_req_last);
  777. nbr->ls_req_last = NULL;
  778. }
  779. /* Lookup LSA from neighbor's ls-retransmit list. */
  780. struct ospf_lsa *
  781. ospf_ls_retransmit_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
  782. {
  783. return ospf_lsdb_lookup (&nbr->ls_rxmt, lsa);
  784. }
  785. static void
  786. ospf_ls_retransmit_delete_nbr_if (struct ospf_interface *oi,
  787. struct ospf_lsa *lsa)
  788. {
  789. struct route_node *rn;
  790. struct ospf_neighbor *nbr;
  791. struct ospf_lsa *lsr;
  792. if (ospf_if_is_enable (oi))
  793. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  794. /* If LSA find in LS-retransmit list, then remove it. */
  795. if ((nbr = rn->info) != NULL)
  796. {
  797. lsr = ospf_ls_retransmit_lookup (nbr, lsa);
  798. /* If LSA find in ls-retransmit list, remove it. */
  799. if (lsr != NULL && lsr->data->ls_seqnum == lsa->data->ls_seqnum)
  800. ospf_ls_retransmit_delete (nbr, lsr);
  801. }
  802. }
  803. void
  804. ospf_ls_retransmit_delete_nbr_area (struct ospf_area *area,
  805. struct ospf_lsa *lsa)
  806. {
  807. struct listnode *node, *nnode;
  808. struct ospf_interface *oi;
  809. for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi))
  810. ospf_ls_retransmit_delete_nbr_if (oi, lsa);
  811. }
  812. void
  813. ospf_ls_retransmit_delete_nbr_as (struct ospf *ospf, struct ospf_lsa *lsa)
  814. {
  815. struct listnode *node, *nnode;
  816. struct ospf_interface *oi;
  817. for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
  818. ospf_ls_retransmit_delete_nbr_if (oi, lsa);
  819. }
  820. /* Sets ls_age to MaxAge and floods throu the area.
  821. When we implement ASE routing, there will be anothe function
  822. flushing an LSA from the whole domain. */
  823. void
  824. ospf_lsa_flush_area (struct ospf_lsa *lsa, struct ospf_area *area)
  825. {
  826. /* Reset the lsa origination time such that it gives
  827. more time for the ACK to be received and avoid
  828. retransmissions */
  829. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
  830. lsa->tv_recv = recent_relative_time ();
  831. lsa->tv_orig = lsa->tv_recv;
  832. ospf_flood_through_area (area, NULL, lsa);
  833. ospf_lsa_maxage (area->ospf, lsa);
  834. }
  835. void
  836. ospf_lsa_flush_as (struct ospf *ospf, struct ospf_lsa *lsa)
  837. {
  838. /* Reset the lsa origination time such that it gives
  839. more time for the ACK to be received and avoid
  840. retransmissions */
  841. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
  842. lsa->tv_recv = recent_relative_time ();
  843. lsa->tv_orig = lsa->tv_recv;
  844. ospf_flood_through_as (ospf, NULL, lsa);
  845. ospf_lsa_maxage (ospf, lsa);
  846. }
  847. void
  848. ospf_lsa_flush (struct ospf *ospf, struct ospf_lsa *lsa)
  849. {
  850. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
  851. switch (lsa->data->type)
  852. {
  853. case OSPF_ROUTER_LSA:
  854. case OSPF_NETWORK_LSA:
  855. case OSPF_SUMMARY_LSA:
  856. case OSPF_ASBR_SUMMARY_LSA:
  857. case OSPF_AS_NSSA_LSA:
  858. case OSPF_OPAQUE_LINK_LSA:
  859. case OSPF_OPAQUE_AREA_LSA:
  860. ospf_lsa_flush_area (lsa, lsa->area);
  861. break;
  862. case OSPF_AS_EXTERNAL_LSA:
  863. case OSPF_OPAQUE_AS_LSA:
  864. ospf_lsa_flush_as (ospf, lsa);
  865. break;
  866. default:
  867. zlog_info ("%s: Unknown LSA type %u", __func__, lsa->data->type);
  868. break;
  869. }
  870. }