ospf_flood.c 31 KB

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