ospf_abr.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. /*
  2. * OSPF ABR functions.
  3. * Copyright (C) 1999, 2000 Alex Zinin, 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 it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * 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 Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "thread.h"
  24. #include "memory.h"
  25. #include "linklist.h"
  26. #include "prefix.h"
  27. #include "if.h"
  28. #include "table.h"
  29. #include "vty.h"
  30. #include "filter.h"
  31. #include "plist.h"
  32. #include "log.h"
  33. #include "ospfd/ospfd.h"
  34. #include "ospfd/ospf_interface.h"
  35. #include "ospfd/ospf_ism.h"
  36. #include "ospfd/ospf_asbr.h"
  37. #include "ospfd/ospf_lsa.h"
  38. #include "ospfd/ospf_lsdb.h"
  39. #include "ospfd/ospf_neighbor.h"
  40. #include "ospfd/ospf_nsm.h"
  41. #include "ospfd/ospf_spf.h"
  42. #include "ospfd/ospf_route.h"
  43. #include "ospfd/ospf_ia.h"
  44. #include "ospfd/ospf_flood.h"
  45. #include "ospfd/ospf_abr.h"
  46. #include "ospfd/ospf_ase.h"
  47. #include "ospfd/ospf_zebra.h"
  48. #include "ospfd/ospf_dump.h"
  49. static struct ospf_area_range *
  50. ospf_area_range_new (struct prefix_ipv4 *p)
  51. {
  52. struct ospf_area_range *range;
  53. range = XCALLOC (MTYPE_OSPF_AREA_RANGE, sizeof (struct ospf_area_range));
  54. range->addr = p->prefix;
  55. range->masklen = p->prefixlen;
  56. range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
  57. return range;
  58. }
  59. static void
  60. ospf_area_range_free (struct ospf_area_range *range)
  61. {
  62. XFREE (MTYPE_OSPF_AREA_RANGE, range);
  63. }
  64. static void
  65. ospf_area_range_add (struct ospf_area *area, struct ospf_area_range *range)
  66. {
  67. struct route_node *rn;
  68. struct prefix_ipv4 p;
  69. p.family = AF_INET;
  70. p.prefixlen = range->masklen;
  71. p.prefix = range->addr;
  72. rn = route_node_get (area->ranges, (struct prefix *)&p);
  73. if (rn->info)
  74. route_unlock_node (rn);
  75. else
  76. rn->info = range;
  77. }
  78. static void
  79. ospf_area_range_delete (struct ospf_area *area, struct route_node *rn)
  80. {
  81. struct ospf_area_range *range = rn->info;
  82. if (range->specifics != 0)
  83. ospf_delete_discard_route (area->ospf->new_table,
  84. (struct prefix_ipv4 *) &rn->p);
  85. ospf_area_range_free (range);
  86. rn->info = NULL;
  87. route_unlock_node (rn);
  88. route_unlock_node (rn);
  89. }
  90. struct ospf_area_range *
  91. ospf_area_range_lookup (struct ospf_area *area, struct prefix_ipv4 *p)
  92. {
  93. struct route_node *rn;
  94. rn = route_node_lookup (area->ranges, (struct prefix *)p);
  95. if (rn)
  96. {
  97. route_unlock_node (rn);
  98. return rn->info;
  99. }
  100. return NULL;
  101. }
  102. struct ospf_area_range *
  103. ospf_area_range_lookup_next (struct ospf_area *area,
  104. struct in_addr *range_net,
  105. int first)
  106. {
  107. struct route_node *rn;
  108. struct prefix_ipv4 p;
  109. struct ospf_area_range *find;
  110. p.family = AF_INET;
  111. p.prefixlen = IPV4_MAX_BITLEN;
  112. p.prefix = *range_net;
  113. if (first)
  114. rn = route_top (area->ranges);
  115. else
  116. {
  117. rn = route_node_get (area->ranges, (struct prefix *) &p);
  118. rn = route_next (rn);
  119. }
  120. for (; rn; rn = route_next (rn))
  121. if (rn->info)
  122. break;
  123. if (rn && rn->info)
  124. {
  125. find = rn->info;
  126. *range_net = rn->p.u.prefix4;
  127. route_unlock_node (rn);
  128. return find;
  129. }
  130. return NULL;
  131. }
  132. static struct ospf_area_range *
  133. ospf_area_range_match (struct ospf_area *area, struct prefix_ipv4 *p)
  134. {
  135. struct route_node *node;
  136. node = route_node_match (area->ranges, (struct prefix *) p);
  137. if (node)
  138. {
  139. route_unlock_node (node);
  140. return node->info;
  141. }
  142. return NULL;
  143. }
  144. struct ospf_area_range *
  145. ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p)
  146. {
  147. struct ospf_area_range *range;
  148. struct ospf_area *area;
  149. struct listnode *node;
  150. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  151. if ((range = ospf_area_range_match (area, p)))
  152. return range;
  153. return NULL;
  154. }
  155. int
  156. ospf_area_range_active (struct ospf_area_range *range)
  157. {
  158. return range->specifics;
  159. }
  160. static int
  161. ospf_area_actively_attached (struct ospf_area *area)
  162. {
  163. return area->act_ints;
  164. }
  165. int
  166. ospf_area_range_set (struct ospf *ospf, struct in_addr area_id,
  167. struct prefix_ipv4 *p, int advertise)
  168. {
  169. struct ospf_area *area;
  170. struct ospf_area_range *range;
  171. int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
  172. area = ospf_area_get (ospf, area_id, ret);
  173. if (area == NULL)
  174. return 0;
  175. range = ospf_area_range_lookup (area, p);
  176. if (range != NULL)
  177. {
  178. if ((CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
  179. && !CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
  180. || (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE)
  181. && CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE)))
  182. ospf_schedule_abr_task (ospf);
  183. }
  184. else
  185. {
  186. range = ospf_area_range_new (p);
  187. ospf_area_range_add (area, range);
  188. ospf_schedule_abr_task (ospf);
  189. }
  190. if (CHECK_FLAG (advertise, OSPF_AREA_RANGE_ADVERTISE))
  191. SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
  192. else
  193. UNSET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
  194. return 1;
  195. }
  196. int
  197. ospf_area_range_cost_set (struct ospf *ospf, struct in_addr area_id,
  198. struct prefix_ipv4 *p, u_int32_t cost)
  199. {
  200. struct ospf_area *area;
  201. struct ospf_area_range *range;
  202. int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
  203. area = ospf_area_get (ospf, area_id, ret);
  204. if (area == NULL)
  205. return 0;
  206. range = ospf_area_range_lookup (area, p);
  207. if (range == NULL)
  208. return 0;
  209. if (range->cost_config != cost)
  210. {
  211. range->cost_config = cost;
  212. if (ospf_area_range_active (range))
  213. ospf_schedule_abr_task (ospf);
  214. }
  215. return 1;
  216. }
  217. int
  218. ospf_area_range_unset (struct ospf *ospf, struct in_addr area_id,
  219. struct prefix_ipv4 *p)
  220. {
  221. struct ospf_area *area;
  222. struct route_node *rn;
  223. area = ospf_area_lookup_by_area_id (ospf, area_id);
  224. if (area == NULL)
  225. return 0;
  226. rn = route_node_lookup (area->ranges, (struct prefix*)p);
  227. if (rn == NULL)
  228. return 0;
  229. if (ospf_area_range_active (rn->info))
  230. ospf_schedule_abr_task (ospf);
  231. ospf_area_range_delete (area, rn);
  232. return 1;
  233. }
  234. int
  235. ospf_area_range_substitute_set (struct ospf *ospf, struct in_addr area_id,
  236. struct prefix_ipv4 *p, struct prefix_ipv4 *s)
  237. {
  238. struct ospf_area *area;
  239. struct ospf_area_range *range;
  240. int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
  241. area = ospf_area_get (ospf, area_id, ret);
  242. range = ospf_area_range_lookup (area, p);
  243. if (range != NULL)
  244. {
  245. if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE) ||
  246. !CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
  247. ospf_schedule_abr_task (ospf);
  248. }
  249. else
  250. {
  251. range = ospf_area_range_new (p);
  252. ospf_area_range_add (area, range);
  253. ospf_schedule_abr_task (ospf);
  254. }
  255. SET_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE);
  256. SET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
  257. range->subst_addr = s->prefix;
  258. range->subst_masklen = s->prefixlen;
  259. return 1;
  260. }
  261. int
  262. ospf_area_range_substitute_unset (struct ospf *ospf, struct in_addr area_id,
  263. struct prefix_ipv4 *p)
  264. {
  265. struct ospf_area *area;
  266. struct ospf_area_range *range;
  267. area = ospf_area_lookup_by_area_id (ospf, area_id);
  268. if (area == NULL)
  269. return 0;
  270. range = ospf_area_range_lookup (area, p);
  271. if (range == NULL)
  272. return 0;
  273. if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
  274. if (ospf_area_range_active (range))
  275. ospf_schedule_abr_task (ospf);
  276. UNSET_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE);
  277. range->subst_addr.s_addr = 0;
  278. range->subst_masklen = 0;
  279. return 1;
  280. }
  281. int
  282. ospf_act_bb_connection (struct ospf *ospf)
  283. {
  284. if (ospf->backbone == NULL)
  285. return 0;
  286. return ospf->backbone->full_nbrs;
  287. }
  288. /* Determine whether this router is elected translator or not for area */
  289. static int
  290. ospf_abr_nssa_am_elected (struct ospf_area *area)
  291. {
  292. struct route_node *rn;
  293. struct ospf_lsa *lsa;
  294. struct router_lsa *rlsa;
  295. struct in_addr *best = NULL;
  296. LSDB_LOOP ( ROUTER_LSDB (area), rn, lsa)
  297. {
  298. /* sanity checks */
  299. if (!lsa
  300. || (lsa->data->type != OSPF_ROUTER_LSA)
  301. || IS_LSA_SELF (lsa))
  302. continue;
  303. rlsa = (struct router_lsa *) lsa->data;
  304. /* ignore non-ABR routers */
  305. if (!IS_ROUTER_LSA_BORDER (rlsa))
  306. continue;
  307. /* Router has Nt flag - always translate */
  308. if (IS_ROUTER_LSA_NT (rlsa))
  309. {
  310. if (IS_DEBUG_OSPF_NSSA)
  311. zlog_debug ("ospf_abr_nssa_am_elected: "
  312. "router %s asserts Nt",
  313. inet_ntoa (lsa->data->id) );
  314. return 0;
  315. }
  316. if (best == NULL)
  317. best = &lsa->data->id;
  318. else
  319. if (IPV4_ADDR_CMP (&best->s_addr, &lsa->data->id.s_addr) < 0)
  320. best = &lsa->data->id;
  321. }
  322. if (IS_DEBUG_OSPF_NSSA)
  323. zlog_debug ("ospf_abr_nssa_am_elected: best electable ABR is: %s",
  324. (best) ? inet_ntoa (*best) : "<none>" );
  325. if (best == NULL)
  326. return 1;
  327. if (IPV4_ADDR_CMP (&best->s_addr, &area->ospf->router_id.s_addr) < 0)
  328. return 1;
  329. else
  330. return 0;
  331. }
  332. /* Check NSSA ABR status
  333. * assumes there are nssa areas
  334. */
  335. static void
  336. ospf_abr_nssa_check_status (struct ospf *ospf)
  337. {
  338. struct ospf_area *area;
  339. struct listnode *lnode, *nnode;
  340. for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
  341. {
  342. u_char old_state = area->NSSATranslatorState;
  343. if (area->external_routing != OSPF_AREA_NSSA)
  344. continue;
  345. if (IS_DEBUG_OSPF (nssa, NSSA))
  346. zlog_debug ("ospf_abr_nssa_check_status: "
  347. "checking area %s",
  348. inet_ntoa (area->area_id));
  349. if (!IS_OSPF_ABR (area->ospf))
  350. {
  351. if (IS_DEBUG_OSPF (nssa, NSSA))
  352. zlog_debug ("ospf_abr_nssa_check_status: "
  353. "not ABR");
  354. area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
  355. }
  356. else
  357. {
  358. switch (area->NSSATranslatorRole)
  359. {
  360. case OSPF_NSSA_ROLE_NEVER:
  361. /* We never Translate Type-7 LSA. */
  362. /* TODO: check previous state and flush? */
  363. if (IS_DEBUG_OSPF (nssa, NSSA))
  364. zlog_debug ("ospf_abr_nssa_check_status: "
  365. "never translate");
  366. area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
  367. break;
  368. case OSPF_NSSA_ROLE_ALWAYS:
  369. /* We always translate if we are an ABR
  370. * TODO: originate new LSAs if state change?
  371. * or let the nssa abr task take care of it?
  372. */
  373. if (IS_DEBUG_OSPF (nssa, NSSA))
  374. zlog_debug ("ospf_abr_nssa_check_status: "
  375. "translate always");
  376. area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
  377. break;
  378. case OSPF_NSSA_ROLE_CANDIDATE:
  379. /* We are a candidate for Translation */
  380. if (ospf_abr_nssa_am_elected (area) > 0)
  381. {
  382. area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_ENABLED;
  383. if (IS_DEBUG_OSPF (nssa, NSSA))
  384. zlog_debug ("ospf_abr_nssa_check_status: "
  385. "elected translator");
  386. }
  387. else
  388. {
  389. area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
  390. if (IS_DEBUG_OSPF (nssa, NSSA))
  391. zlog_debug ("ospf_abr_nssa_check_status: " "not elected");
  392. }
  393. break;
  394. }
  395. }
  396. /* RFC3101, 3.1:
  397. * All NSSA border routers must set the E-bit in the Type-1 router-LSAs
  398. * of their directly attached non-stub areas, even when they are not
  399. * translating.
  400. */
  401. if (old_state != area->NSSATranslatorState)
  402. {
  403. if (old_state == OSPF_NSSA_TRANSLATE_DISABLED)
  404. ospf_asbr_status_update (ospf, ++ospf->redistribute);
  405. else if (area->NSSATranslatorState == OSPF_NSSA_TRANSLATE_DISABLED)
  406. ospf_asbr_status_update (ospf, --ospf->redistribute);
  407. }
  408. }
  409. }
  410. /* Check area border router status. */
  411. void
  412. ospf_check_abr_status (struct ospf *ospf)
  413. {
  414. struct ospf_area *area;
  415. struct listnode *node, *nnode;
  416. int bb_configured = 0;
  417. int bb_act_attached = 0;
  418. int areas_configured = 0;
  419. int areas_act_attached = 0;
  420. u_char new_flags = ospf->flags;
  421. if (IS_DEBUG_OSPF_EVENT)
  422. zlog_debug ("ospf_check_abr_status(): Start");
  423. for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
  424. {
  425. if (listcount (area->oiflist))
  426. {
  427. areas_configured++;
  428. if (OSPF_IS_AREA_BACKBONE (area))
  429. bb_configured = 1;
  430. }
  431. if (ospf_area_actively_attached (area))
  432. {
  433. areas_act_attached++;
  434. if (OSPF_IS_AREA_BACKBONE (area))
  435. bb_act_attached = 1;
  436. }
  437. }
  438. if (IS_DEBUG_OSPF_EVENT)
  439. {
  440. zlog_debug ("ospf_check_abr_status(): looked through areas");
  441. zlog_debug ("ospf_check_abr_status(): bb_configured: %d", bb_configured);
  442. zlog_debug ("ospf_check_abr_status(): bb_act_attached: %d",
  443. bb_act_attached);
  444. zlog_debug ("ospf_check_abr_status(): areas_configured: %d",
  445. areas_configured);
  446. zlog_debug ("ospf_check_abr_status(): areas_act_attached: %d",
  447. areas_act_attached);
  448. }
  449. switch (ospf->abr_type)
  450. {
  451. case OSPF_ABR_SHORTCUT:
  452. case OSPF_ABR_STAND:
  453. if (areas_act_attached > 1)
  454. SET_FLAG (new_flags, OSPF_FLAG_ABR);
  455. else
  456. UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
  457. break;
  458. case OSPF_ABR_IBM:
  459. if ((areas_act_attached > 1) && bb_configured)
  460. SET_FLAG (new_flags, OSPF_FLAG_ABR);
  461. else
  462. UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
  463. break;
  464. case OSPF_ABR_CISCO:
  465. if ((areas_configured > 1) && bb_act_attached)
  466. SET_FLAG (new_flags, OSPF_FLAG_ABR);
  467. else
  468. UNSET_FLAG (new_flags, OSPF_FLAG_ABR);
  469. break;
  470. default:
  471. break;
  472. }
  473. if (new_flags != ospf->flags)
  474. {
  475. ospf_spf_calculate_schedule (ospf, SPF_FLAG_ABR_STATUS_CHANGE);
  476. if (IS_DEBUG_OSPF_EVENT)
  477. zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
  478. ospf->flags = new_flags;
  479. ospf_router_lsa_update (ospf);
  480. }
  481. }
  482. static void
  483. ospf_abr_update_aggregate (struct ospf_area_range *range,
  484. struct ospf_route *or, struct ospf_area *area)
  485. {
  486. if (IS_DEBUG_OSPF_EVENT)
  487. zlog_debug ("ospf_abr_update_aggregate(): Start");
  488. if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED) &&
  489. (range->cost != OSPF_STUB_MAX_METRIC_SUMMARY_COST))
  490. {
  491. range->cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
  492. if (IS_DEBUG_OSPF_EVENT)
  493. zlog_debug ("ospf_abr_update_aggregate(): use summary max-metric 0x%08x",
  494. range->cost);
  495. }
  496. else if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
  497. {
  498. if (IS_DEBUG_OSPF_EVENT)
  499. zlog_debug ("ospf_abr_update_aggregate(): use configured cost %d",
  500. range->cost_config);
  501. range->cost = range->cost_config;
  502. }
  503. else
  504. {
  505. if (range->specifics == 0)
  506. {
  507. if (IS_DEBUG_OSPF_EVENT)
  508. zlog_debug ("ospf_abr_update_aggregate(): use or->cost %d",
  509. or->cost);
  510. range->cost = or->cost; /* 1st time get 1st cost */
  511. }
  512. if (or->cost > range->cost)
  513. {
  514. if (IS_DEBUG_OSPF_EVENT)
  515. zlog_debug ("ospf_abr_update_aggregate(): update to %d", or->cost);
  516. range->cost = or->cost;
  517. }
  518. }
  519. range->specifics++;
  520. }
  521. static void
  522. set_metric (struct ospf_lsa *lsa, u_int32_t metric)
  523. {
  524. struct summary_lsa *header;
  525. u_char *mp;
  526. metric = htonl (metric);
  527. mp = (u_char *) &metric;
  528. mp++;
  529. header = (struct summary_lsa *) lsa->data;
  530. memcpy(header->metric, mp, 3);
  531. }
  532. /* ospf_abr_translate_nssa */
  533. static int
  534. ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
  535. {
  536. /* Incoming Type-7 or later aggregated Type-7
  537. *
  538. * LSA is skipped if P-bit is off.
  539. * LSA is aggregated if within range.
  540. *
  541. * The Type-7 is translated, Installed/Approved as a Type-5 into
  542. * global LSDB, then Flooded through AS
  543. *
  544. * Later, any Unapproved Translated Type-5's are flushed/discarded
  545. */
  546. struct ospf_lsa *old = NULL,
  547. *new = NULL;
  548. struct as_external_lsa *ext7;
  549. struct prefix_ipv4 p;
  550. if (! CHECK_FLAG (lsa->data->options, OSPF_OPTION_NP))
  551. {
  552. if (IS_DEBUG_OSPF_NSSA)
  553. zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, P-bit off, NO Translation",
  554. inet_ntoa (lsa->data->id));
  555. return 1;
  556. }
  557. if (IS_DEBUG_OSPF_NSSA)
  558. zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, TRANSLATING 7 to 5",
  559. inet_ntoa (lsa->data->id));
  560. ext7 = (struct as_external_lsa *)(lsa->data);
  561. p.prefix = lsa->data->id;
  562. p.prefixlen = ip_masklen (ext7->mask);
  563. if (ext7->e[0].fwd_addr.s_addr == OSPF_DEFAULT_DESTINATION)
  564. {
  565. if (IS_DEBUG_OSPF_NSSA)
  566. zlog_debug ("ospf_abr_translate_nssa(): LSA Id %s, "
  567. "Forward address is 0, NO Translation",
  568. inet_ntoa (lsa->data->id));
  569. return 1;
  570. }
  571. /* try find existing AS-External LSA for this prefix */
  572. old = ospf_external_info_find_lsa (area->ospf, &p);
  573. if (old)
  574. {
  575. if (IS_DEBUG_OSPF_NSSA)
  576. zlog_debug ("ospf_abr_translate_nssa(): "
  577. "found old translated LSA Id %s, refreshing",
  578. inet_ntoa (old->data->id));
  579. /* refresh */
  580. new = ospf_translated_nssa_refresh (area->ospf, lsa, old);
  581. if (!new)
  582. {
  583. if (IS_DEBUG_OSPF_NSSA)
  584. zlog_debug ("ospf_abr_translate_nssa(): "
  585. "could not refresh translated LSA Id %s",
  586. inet_ntoa (old->data->id));
  587. }
  588. }
  589. else
  590. {
  591. /* no existing external route for this LSA Id
  592. * originate translated LSA
  593. */
  594. if ((new = ospf_translated_nssa_originate (area->ospf, lsa))
  595. == NULL)
  596. {
  597. if (IS_DEBUG_OSPF_NSSA)
  598. zlog_debug ("ospf_abr_translate_nssa(): Could not translate "
  599. "Type-7 for %s to Type-5",
  600. inet_ntoa (lsa->data->id));
  601. return 1;
  602. }
  603. }
  604. /* Area where Aggregate testing will be inserted, just like summary
  605. advertisements */
  606. /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
  607. return 0;
  608. }
  609. static void
  610. ospf_abr_translate_nssa_range (struct prefix_ipv4 *p, u_int32_t cost)
  611. {
  612. /* The Type-7 is created from the aggregated prefix and forwarded
  613. for lsa installation and flooding... to be added... */
  614. }
  615. void
  616. ospf_abr_announce_network_to_area (struct prefix_ipv4 *p, u_int32_t cost,
  617. struct ospf_area *area)
  618. {
  619. struct ospf_lsa *lsa, *old = NULL;
  620. struct summary_lsa *sl = NULL;
  621. u_int32_t full_cost;
  622. if (IS_DEBUG_OSPF_EVENT)
  623. zlog_debug ("ospf_abr_announce_network_to_area(): Start");
  624. if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
  625. full_cost = OSPF_STUB_MAX_METRIC_SUMMARY_COST;
  626. else
  627. full_cost = cost;
  628. old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_SUMMARY_LSA,
  629. (struct prefix_ipv4 *) p,
  630. area->ospf->router_id);
  631. if (old)
  632. {
  633. if (IS_DEBUG_OSPF_EVENT)
  634. zlog_debug ("ospf_abr_announce_network_to_area(): old summary found");
  635. sl = (struct summary_lsa *) old->data;
  636. if (IS_DEBUG_OSPF_EVENT)
  637. zlog_debug ("ospf_abr_announce_network_to_area(): "
  638. "old metric: %d, new metric: %d",
  639. GET_METRIC (sl->metric), cost);
  640. if ((GET_METRIC (sl->metric) == full_cost) &&
  641. ((old->flags & OSPF_LSA_IN_MAXAGE) == 0))
  642. {
  643. /* unchanged. simply reapprove it */
  644. if (IS_DEBUG_OSPF_EVENT)
  645. zlog_debug ("ospf_abr_announce_network_to_area(): "
  646. "old summary approved");
  647. SET_FLAG (old->flags, OSPF_LSA_APPROVED);
  648. }
  649. else
  650. {
  651. /* LSA is changed, refresh it */
  652. if (IS_DEBUG_OSPF_EVENT)
  653. zlog_debug ("ospf_abr_announce_network_to_area(): "
  654. "refreshing summary");
  655. set_metric (old, full_cost);
  656. lsa = ospf_lsa_refresh (area->ospf, old);
  657. if (!lsa)
  658. {
  659. char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
  660. prefix2str ((struct prefix *) p, buf, sizeof(buf));
  661. zlog_warn ("%s: Could not refresh %s to %s",
  662. __func__,
  663. buf,
  664. inet_ntoa (area->area_id));
  665. return;
  666. }
  667. SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
  668. /* This will flood through area. */
  669. }
  670. }
  671. else
  672. {
  673. if (IS_DEBUG_OSPF_EVENT)
  674. zlog_debug ("ospf_abr_announce_network_to_area(): "
  675. "creating new summary");
  676. lsa = ospf_summary_lsa_originate ( (struct prefix_ipv4 *)p, full_cost, area);
  677. /* This will flood through area. */
  678. if (!lsa)
  679. {
  680. char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
  681. prefix2str ((struct prefix *)p, buf, sizeof(buf));
  682. zlog_warn ("%s: Could not originate %s to %s",
  683. __func__,
  684. buf,
  685. inet_ntoa (area->area_id));
  686. return;
  687. }
  688. SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
  689. if (IS_DEBUG_OSPF_EVENT)
  690. zlog_debug ("ospf_abr_announce_network_to_area(): "
  691. "flooding new version of summary");
  692. }
  693. if (IS_DEBUG_OSPF_EVENT)
  694. zlog_debug ("ospf_abr_announce_network_to_area(): Stop");
  695. }
  696. static int
  697. ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
  698. struct ospf_area *area)
  699. {
  700. struct listnode *node, *nnode;
  701. struct ospf_path *path;
  702. struct ospf_interface *oi;
  703. for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
  704. for (ALL_LIST_ELEMENTS_RO (area->oiflist, nnode, oi))
  705. if (oi->ifp && oi->ifp->ifindex == path->ifindex)
  706. return 1;
  707. return 0;
  708. }
  709. static int
  710. ospf_abr_should_accept (struct prefix_ipv4 *p, struct ospf_area *area)
  711. {
  712. if (IMPORT_NAME (area))
  713. {
  714. if (IMPORT_LIST (area) == NULL)
  715. IMPORT_LIST (area) = access_list_lookup (AFI_IP, IMPORT_NAME (area));
  716. if (IMPORT_LIST (area))
  717. if (access_list_apply (IMPORT_LIST (area), p) == FILTER_DENY)
  718. return 0;
  719. }
  720. return 1;
  721. }
  722. static int
  723. ospf_abr_plist_in_check (struct ospf_area *area, struct ospf_route *or,
  724. struct prefix_ipv4 *p)
  725. {
  726. if (PREFIX_NAME_IN (area))
  727. {
  728. if (PREFIX_LIST_IN (area) == NULL)
  729. PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP,
  730. PREFIX_NAME_IN (area));
  731. if (PREFIX_LIST_IN (area))
  732. if (prefix_list_apply (PREFIX_LIST_IN (area), p) != PREFIX_PERMIT)
  733. return 0;
  734. }
  735. return 1;
  736. }
  737. static int
  738. ospf_abr_plist_out_check (struct ospf_area *area, struct ospf_route *or,
  739. struct prefix_ipv4 *p)
  740. {
  741. if (PREFIX_NAME_OUT (area))
  742. {
  743. if (PREFIX_LIST_OUT (area) == NULL)
  744. PREFIX_LIST_OUT (area) = prefix_list_lookup (AFI_IP,
  745. PREFIX_NAME_OUT (area));
  746. if (PREFIX_LIST_OUT (area))
  747. if (prefix_list_apply (PREFIX_LIST_OUT (area), p) != PREFIX_PERMIT)
  748. return 0;
  749. }
  750. return 1;
  751. }
  752. static void
  753. ospf_abr_announce_network (struct ospf *ospf,
  754. struct prefix_ipv4 *p, struct ospf_route *or)
  755. {
  756. struct ospf_area_range *range;
  757. struct ospf_area *area, *or_area;
  758. struct listnode *node;
  759. if (IS_DEBUG_OSPF_EVENT)
  760. zlog_debug ("ospf_abr_announce_network(): Start");
  761. or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
  762. assert (or_area);
  763. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  764. {
  765. if (IS_DEBUG_OSPF_EVENT)
  766. zlog_debug ("ospf_abr_announce_network(): looking at area %s",
  767. inet_ntoa (area->area_id));
  768. if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
  769. continue;
  770. if (ospf_abr_nexthops_belong_to_area (or, area))
  771. continue;
  772. if (!ospf_abr_should_accept (p, area))
  773. {
  774. if (IS_DEBUG_OSPF_EVENT)
  775. zlog_debug ("ospf_abr_announce_network(): "
  776. "prefix %s/%d was denied by import-list",
  777. inet_ntoa (p->prefix), p->prefixlen);
  778. continue;
  779. }
  780. if (!ospf_abr_plist_in_check (area, or, p))
  781. {
  782. if (IS_DEBUG_OSPF_EVENT)
  783. zlog_debug ("ospf_abr_announce_network(): "
  784. "prefix %s/%d was denied by prefix-list",
  785. inet_ntoa (p->prefix), p->prefixlen);
  786. continue;
  787. }
  788. if (area->external_routing != OSPF_AREA_DEFAULT && area->no_summary)
  789. {
  790. if (IS_DEBUG_OSPF_EVENT)
  791. zlog_debug ("ospf_abr_announce_network(): "
  792. "area %s is stub and no_summary",
  793. inet_ntoa (area->area_id));
  794. continue;
  795. }
  796. if (or->path_type == OSPF_PATH_INTER_AREA)
  797. {
  798. if (IS_DEBUG_OSPF_EVENT)
  799. zlog_debug ("ospf_abr_announce_network(): this is "
  800. "inter-area route to %s/%d",
  801. inet_ntoa (p->prefix), p->prefixlen);
  802. if (!OSPF_IS_AREA_BACKBONE (area))
  803. ospf_abr_announce_network_to_area (p, or->cost, area);
  804. }
  805. if (or->path_type == OSPF_PATH_INTRA_AREA)
  806. {
  807. if (IS_DEBUG_OSPF_EVENT)
  808. zlog_debug ("ospf_abr_announce_network(): "
  809. "this is intra-area route to %s/%d",
  810. inet_ntoa (p->prefix), p->prefixlen);
  811. if ((range = ospf_area_range_match (or_area, p))
  812. && !ospf_area_is_transit (area))
  813. ospf_abr_update_aggregate (range, or, area);
  814. else
  815. ospf_abr_announce_network_to_area (p, or->cost, area);
  816. }
  817. }
  818. }
  819. static int
  820. ospf_abr_should_announce (struct ospf *ospf,
  821. struct prefix_ipv4 *p, struct ospf_route *or)
  822. {
  823. struct ospf_area *area;
  824. area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id);
  825. assert (area);
  826. if (EXPORT_NAME (area))
  827. {
  828. if (EXPORT_LIST (area) == NULL)
  829. EXPORT_LIST (area) = access_list_lookup (AFI_IP, EXPORT_NAME (area));
  830. if (EXPORT_LIST (area))
  831. if (access_list_apply (EXPORT_LIST (area), p) == FILTER_DENY)
  832. return 0;
  833. }
  834. return 1;
  835. }
  836. static void
  837. ospf_abr_process_nssa_translates (struct ospf *ospf)
  838. {
  839. /* Scan through all NSSA_LSDB records for all areas;
  840. If P-bit is on, translate all Type-7's to 5's and aggregate or
  841. flood install as approved in Type-5 LSDB with XLATE Flag on
  842. later, do same for all aggregates... At end, DISCARD all
  843. remaining UNAPPROVED Type-5's (Aggregate is for future ) */
  844. struct listnode *node;
  845. struct ospf_area *area;
  846. struct route_node *rn;
  847. struct ospf_lsa *lsa;
  848. if (IS_DEBUG_OSPF_NSSA)
  849. zlog_debug ("ospf_abr_process_nssa_translates(): Start");
  850. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  851. {
  852. if (! area->NSSATranslatorState)
  853. continue; /* skip if not translator */
  854. if (area->external_routing != OSPF_AREA_NSSA)
  855. continue; /* skip if not Nssa Area */
  856. if (IS_DEBUG_OSPF_NSSA)
  857. zlog_debug ("ospf_abr_process_nssa_translates(): "
  858. "looking at area %s", inet_ntoa (area->area_id));
  859. LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
  860. ospf_abr_translate_nssa (area, lsa);
  861. }
  862. if (IS_DEBUG_OSPF_NSSA)
  863. zlog_debug ("ospf_abr_process_nssa_translates(): Stop");
  864. }
  865. static void
  866. ospf_abr_process_network_rt (struct ospf *ospf,
  867. struct route_table *rt)
  868. {
  869. struct ospf_area *area;
  870. struct ospf_route *or;
  871. struct route_node *rn;
  872. if (IS_DEBUG_OSPF_EVENT)
  873. zlog_debug ("ospf_abr_process_network_rt(): Start");
  874. for (rn = route_top (rt); rn; rn = route_next (rn))
  875. {
  876. if ((or = rn->info) == NULL)
  877. continue;
  878. if (!(area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id)))
  879. {
  880. if (IS_DEBUG_OSPF_EVENT)
  881. zlog_debug ("ospf_abr_process_network_rt(): area %s no longer exists",
  882. inet_ntoa (or->u.std.area_id));
  883. continue;
  884. }
  885. if (IS_DEBUG_OSPF_EVENT)
  886. zlog_debug ("ospf_abr_process_network_rt(): this is a route to %s/%d",
  887. inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
  888. if (or->path_type >= OSPF_PATH_TYPE1_EXTERNAL)
  889. {
  890. if (IS_DEBUG_OSPF_EVENT)
  891. zlog_debug ("ospf_abr_process_network_rt(): "
  892. "this is an External router, skipping");
  893. continue;
  894. }
  895. if (or->cost >= OSPF_LS_INFINITY)
  896. {
  897. if (IS_DEBUG_OSPF_EVENT)
  898. zlog_debug ("ospf_abr_process_network_rt():"
  899. " this route's cost is infinity, skipping");
  900. continue;
  901. }
  902. if (or->type == OSPF_DESTINATION_DISCARD)
  903. {
  904. if (IS_DEBUG_OSPF_EVENT)
  905. zlog_debug ("ospf_abr_process_network_rt():"
  906. " this is a discard entry, skipping");
  907. continue;
  908. }
  909. if (or->path_type == OSPF_PATH_INTRA_AREA &&
  910. !ospf_abr_should_announce (ospf, (struct prefix_ipv4 *) &rn->p, or))
  911. {
  912. if (IS_DEBUG_OSPF_EVENT)
  913. zlog_debug("ospf_abr_process_network_rt(): denied by export-list");
  914. continue;
  915. }
  916. if (or->path_type == OSPF_PATH_INTRA_AREA &&
  917. !ospf_abr_plist_out_check (area, or, (struct prefix_ipv4 *) &rn->p))
  918. {
  919. if (IS_DEBUG_OSPF_EVENT)
  920. zlog_debug("ospf_abr_process_network_rt(): denied by prefix-list");
  921. continue;
  922. }
  923. if ((or->path_type == OSPF_PATH_INTER_AREA) &&
  924. !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
  925. {
  926. if (IS_DEBUG_OSPF_EVENT)
  927. zlog_debug ("ospf_abr_process_network_rt():"
  928. " this is route is not backbone one, skipping");
  929. continue;
  930. }
  931. if ((ospf->abr_type == OSPF_ABR_CISCO) ||
  932. (ospf->abr_type == OSPF_ABR_IBM))
  933. if (!ospf_act_bb_connection (ospf) &&
  934. or->path_type != OSPF_PATH_INTRA_AREA)
  935. {
  936. if (IS_DEBUG_OSPF_EVENT)
  937. zlog_debug ("ospf_abr_process_network_rt(): ALT ABR: "
  938. "No BB connection, skip not intra-area routes");
  939. continue;
  940. }
  941. if (IS_DEBUG_OSPF_EVENT)
  942. zlog_debug ("ospf_abr_process_network_rt(): announcing");
  943. ospf_abr_announce_network (ospf, (struct prefix_ipv4 *)&rn->p, or);
  944. }
  945. if (IS_DEBUG_OSPF_EVENT)
  946. zlog_debug ("ospf_abr_process_network_rt(): Stop");
  947. }
  948. static void
  949. ospf_abr_announce_rtr_to_area (struct prefix_ipv4 *p, u_int32_t cost,
  950. struct ospf_area *area)
  951. {
  952. struct ospf_lsa *lsa, *old = NULL;
  953. struct summary_lsa *slsa = NULL;
  954. if (IS_DEBUG_OSPF_EVENT)
  955. zlog_debug ("ospf_abr_announce_rtr_to_area(): Start");
  956. old = ospf_lsa_lookup_by_prefix (area->lsdb, OSPF_ASBR_SUMMARY_LSA,
  957. p, area->ospf->router_id);
  958. if (old)
  959. {
  960. if (IS_DEBUG_OSPF_EVENT)
  961. zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary found");
  962. slsa = (struct summary_lsa *) old->data;
  963. if (IS_DEBUG_OSPF_EVENT)
  964. zlog_debug ("ospf_abr_announce_network_to_area(): "
  965. "old metric: %d, new metric: %d",
  966. GET_METRIC (slsa->metric), cost);
  967. }
  968. if (old && (GET_METRIC (slsa->metric) == cost) &&
  969. ((old->flags & OSPF_LSA_IN_MAXAGE) == 0))
  970. {
  971. if (IS_DEBUG_OSPF_EVENT)
  972. zlog_debug ("ospf_abr_announce_rtr_to_area(): old summary approved");
  973. SET_FLAG (old->flags, OSPF_LSA_APPROVED);
  974. }
  975. else
  976. {
  977. if (IS_DEBUG_OSPF_EVENT)
  978. zlog_debug ("ospf_abr_announce_rtr_to_area(): 2.2");
  979. if (old)
  980. {
  981. set_metric (old, cost);
  982. lsa = ospf_lsa_refresh (area->ospf, old);
  983. }
  984. else
  985. lsa = ospf_summary_asbr_lsa_originate (p, cost, area);
  986. if (!lsa)
  987. {
  988. char buf[INET_ADDRSTRLEN + 3]; /* ipv4 and /XX */
  989. prefix2str ((struct prefix *)p, buf, sizeof(buf));
  990. zlog_warn ("%s: Could not refresh/originate %s to %s",
  991. __func__,
  992. buf,
  993. inet_ntoa (area->area_id));
  994. return;
  995. }
  996. if (IS_DEBUG_OSPF_EVENT)
  997. zlog_debug ("ospf_abr_announce_rtr_to_area(): "
  998. "flooding new version of summary");
  999. /*
  1000. zlog_info ("ospf_abr_announce_rtr_to_area(): creating new summary");
  1001. lsa = ospf_summary_asbr_lsa (p, cost, area, old); */
  1002. SET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
  1003. /* ospf_flood_through_area (area, NULL, lsa);*/
  1004. }
  1005. if (IS_DEBUG_OSPF_EVENT)
  1006. zlog_debug ("ospf_abr_announce_rtr_to_area(): Stop");
  1007. }
  1008. static void
  1009. ospf_abr_announce_rtr (struct ospf *ospf,
  1010. struct prefix_ipv4 *p, struct ospf_route *or)
  1011. {
  1012. struct listnode *node;
  1013. struct ospf_area *area;
  1014. if (IS_DEBUG_OSPF_EVENT)
  1015. zlog_debug ("ospf_abr_announce_rtr(): Start");
  1016. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  1017. {
  1018. if (IS_DEBUG_OSPF_EVENT)
  1019. zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
  1020. inet_ntoa (area->area_id));
  1021. if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
  1022. continue;
  1023. if (ospf_abr_nexthops_belong_to_area (or, area))
  1024. continue;
  1025. if (area->external_routing != OSPF_AREA_DEFAULT)
  1026. {
  1027. if (IS_DEBUG_OSPF_EVENT)
  1028. zlog_debug ("ospf_abr_announce_rtr(): "
  1029. "area %s doesn't support external routing",
  1030. inet_ntoa(area->area_id));
  1031. continue;
  1032. }
  1033. if (or->path_type == OSPF_PATH_INTER_AREA)
  1034. {
  1035. if (IS_DEBUG_OSPF_EVENT)
  1036. zlog_debug ("ospf_abr_announce_rtr(): "
  1037. "this is inter-area route to %s", inet_ntoa (p->prefix));
  1038. if (!OSPF_IS_AREA_BACKBONE (area))
  1039. ospf_abr_announce_rtr_to_area (p, or->cost, area);
  1040. }
  1041. if (or->path_type == OSPF_PATH_INTRA_AREA)
  1042. {
  1043. if (IS_DEBUG_OSPF_EVENT)
  1044. zlog_debug ("ospf_abr_announce_rtr(): "
  1045. "this is intra-area route to %s", inet_ntoa (p->prefix));
  1046. ospf_abr_announce_rtr_to_area (p, or->cost, area);
  1047. }
  1048. }
  1049. if (IS_DEBUG_OSPF_EVENT)
  1050. zlog_debug ("ospf_abr_announce_rtr(): Stop");
  1051. }
  1052. static void
  1053. ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt)
  1054. {
  1055. struct ospf_route *or;
  1056. struct route_node *rn;
  1057. struct list *l;
  1058. if (IS_DEBUG_OSPF_EVENT)
  1059. zlog_debug ("ospf_abr_process_router_rt(): Start");
  1060. for (rn = route_top (rt); rn; rn = route_next (rn))
  1061. {
  1062. struct listnode *node, *nnode;
  1063. char flag = 0;
  1064. struct ospf_route *best = NULL;
  1065. if (rn->info == NULL)
  1066. continue;
  1067. l = rn->info;
  1068. if (IS_DEBUG_OSPF_EVENT)
  1069. zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
  1070. inet_ntoa (rn->p.u.prefix4));
  1071. for (ALL_LIST_ELEMENTS (l, node, nnode, or))
  1072. {
  1073. if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
  1074. {
  1075. if (IS_DEBUG_OSPF_EVENT)
  1076. zlog_debug ("ospf_abr_process_router_rt(): area %s no longer exists",
  1077. inet_ntoa (or->u.std.area_id));
  1078. continue;
  1079. }
  1080. if (!CHECK_FLAG (or->u.std.flags, ROUTER_LSA_EXTERNAL))
  1081. {
  1082. if (IS_DEBUG_OSPF_EVENT)
  1083. zlog_debug ("ospf_abr_process_router_rt(): "
  1084. "This is not an ASBR, skipping");
  1085. continue;
  1086. }
  1087. if (!flag)
  1088. {
  1089. best = ospf_find_asbr_route (ospf, rt,
  1090. (struct prefix_ipv4 *) &rn->p);
  1091. flag = 1;
  1092. }
  1093. if (best == NULL)
  1094. continue;
  1095. if (or != best)
  1096. {
  1097. if (IS_DEBUG_OSPF_EVENT)
  1098. zlog_debug ("ospf_abr_process_router_rt(): "
  1099. "This route is not the best among possible, skipping");
  1100. continue;
  1101. }
  1102. if (or->path_type == OSPF_PATH_INTER_AREA &&
  1103. !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id))
  1104. {
  1105. if (IS_DEBUG_OSPF_EVENT)
  1106. zlog_debug ("ospf_abr_process_router_rt(): "
  1107. "This route is not a backbone one, skipping");
  1108. continue;
  1109. }
  1110. if (or->cost >= OSPF_LS_INFINITY)
  1111. {
  1112. if (IS_DEBUG_OSPF_EVENT)
  1113. zlog_debug ("ospf_abr_process_router_rt(): "
  1114. "This route has LS_INFINITY metric, skipping");
  1115. continue;
  1116. }
  1117. if (ospf->abr_type == OSPF_ABR_CISCO
  1118. || ospf->abr_type == OSPF_ABR_IBM)
  1119. if (!ospf_act_bb_connection (ospf)
  1120. && or->path_type != OSPF_PATH_INTRA_AREA)
  1121. {
  1122. if (IS_DEBUG_OSPF_EVENT)
  1123. zlog_debug("ospf_abr_process_network_rt(): ALT ABR: "
  1124. "No BB connection, skip not intra-area routes");
  1125. continue;
  1126. }
  1127. ospf_abr_announce_rtr (ospf, (struct prefix_ipv4 *) &rn->p, or);
  1128. }
  1129. }
  1130. if (IS_DEBUG_OSPF_EVENT)
  1131. zlog_debug ("ospf_abr_process_router_rt(): Stop");
  1132. }
  1133. static void
  1134. ospf_abr_unapprove_translates (struct ospf *ospf) /* For NSSA Translations */
  1135. {
  1136. struct ospf_lsa *lsa;
  1137. struct route_node *rn;
  1138. if (IS_DEBUG_OSPF_NSSA)
  1139. zlog_debug ("ospf_abr_unapprove_translates(): Start");
  1140. /* NSSA Translator is not checked, because it may have gone away,
  1141. and we would want to flush any residuals anyway */
  1142. LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
  1143. if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
  1144. {
  1145. UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
  1146. if (IS_DEBUG_OSPF_NSSA)
  1147. zlog_debug ("ospf_abr_unapprove_translates(): "
  1148. "approved unset on link id %s",
  1149. inet_ntoa (lsa->data->id));
  1150. }
  1151. if (IS_DEBUG_OSPF_NSSA)
  1152. zlog_debug ("ospf_abr_unapprove_translates(): Stop");
  1153. }
  1154. static void
  1155. ospf_abr_unapprove_summaries (struct ospf *ospf)
  1156. {
  1157. struct listnode *node;
  1158. struct ospf_area *area;
  1159. struct route_node *rn;
  1160. struct ospf_lsa *lsa;
  1161. if (IS_DEBUG_OSPF_EVENT)
  1162. zlog_debug ("ospf_abr_unapprove_summaries(): Start");
  1163. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  1164. {
  1165. if (IS_DEBUG_OSPF_EVENT)
  1166. zlog_debug ("ospf_abr_unapprove_summaries(): "
  1167. "considering area %s",
  1168. inet_ntoa (area->area_id));
  1169. LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
  1170. if (ospf_lsa_is_self_originated (ospf, lsa))
  1171. {
  1172. if (IS_DEBUG_OSPF_EVENT)
  1173. zlog_debug ("ospf_abr_unapprove_summaries(): "
  1174. "approved unset on summary link id %s",
  1175. inet_ntoa (lsa->data->id));
  1176. UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
  1177. }
  1178. LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
  1179. if (ospf_lsa_is_self_originated (ospf, lsa))
  1180. {
  1181. if (IS_DEBUG_OSPF_EVENT)
  1182. zlog_debug ("ospf_abr_unapprove_summaries(): "
  1183. "approved unset on asbr-summary link id %s",
  1184. inet_ntoa (lsa->data->id));
  1185. UNSET_FLAG (lsa->flags, OSPF_LSA_APPROVED);
  1186. }
  1187. }
  1188. if (IS_DEBUG_OSPF_EVENT)
  1189. zlog_debug ("ospf_abr_unapprove_summaries(): Stop");
  1190. }
  1191. static void
  1192. ospf_abr_prepare_aggregates (struct ospf *ospf)
  1193. {
  1194. struct listnode *node;
  1195. struct route_node *rn;
  1196. struct ospf_area_range *range;
  1197. struct ospf_area *area;
  1198. if (IS_DEBUG_OSPF_EVENT)
  1199. zlog_debug ("ospf_abr_prepare_aggregates(): Start");
  1200. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  1201. {
  1202. for (rn = route_top (area->ranges); rn; rn = route_next (rn))
  1203. if ((range = rn->info) != NULL)
  1204. {
  1205. range->cost = 0;
  1206. range->specifics = 0;
  1207. }
  1208. }
  1209. if (IS_DEBUG_OSPF_EVENT)
  1210. zlog_debug ("ospf_abr_prepare_aggregates(): Stop");
  1211. }
  1212. static void
  1213. ospf_abr_announce_aggregates (struct ospf *ospf)
  1214. {
  1215. struct ospf_area *area, *ar;
  1216. struct ospf_area_range *range;
  1217. struct route_node *rn;
  1218. struct prefix p;
  1219. struct listnode *node, *n;
  1220. if (IS_DEBUG_OSPF_EVENT)
  1221. zlog_debug ("ospf_abr_announce_aggregates(): Start");
  1222. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  1223. {
  1224. if (IS_DEBUG_OSPF_EVENT)
  1225. zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
  1226. inet_ntoa (area->area_id));
  1227. for (rn = route_top (area->ranges); rn; rn = route_next (rn))
  1228. if ((range = rn->info))
  1229. {
  1230. if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
  1231. {
  1232. if (IS_DEBUG_OSPF_EVENT)
  1233. zlog_debug ("ospf_abr_announce_aggregates():"
  1234. " discarding suppress-ranges");
  1235. continue;
  1236. }
  1237. p.family = AF_INET;
  1238. p.u.prefix4 = range->addr;
  1239. p.prefixlen = range->masklen;
  1240. if (IS_DEBUG_OSPF_EVENT)
  1241. zlog_debug ("ospf_abr_announce_aggregates():"
  1242. " this is range: %s/%d",
  1243. inet_ntoa (p.u.prefix4), p.prefixlen);
  1244. if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
  1245. {
  1246. p.family = AF_INET;
  1247. p.u.prefix4 = range->subst_addr;
  1248. p.prefixlen = range->subst_masklen;
  1249. }
  1250. if (range->specifics)
  1251. {
  1252. if (IS_DEBUG_OSPF_EVENT)
  1253. zlog_debug ("ospf_abr_announce_aggregates(): active range");
  1254. for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
  1255. {
  1256. if (ar == area)
  1257. continue;
  1258. /* We do not check nexthops here, because
  1259. intra-area routes can be associated with
  1260. one area only */
  1261. /* backbone routes are not summarized
  1262. when announced into transit areas */
  1263. if (ospf_area_is_transit (ar) &&
  1264. OSPF_IS_AREA_BACKBONE (area))
  1265. {
  1266. if (IS_DEBUG_OSPF_EVENT)
  1267. zlog_debug ("ospf_abr_announce_aggregates(): Skipping "
  1268. "announcement of BB aggregate into"
  1269. " a transit area");
  1270. continue;
  1271. }
  1272. ospf_abr_announce_network_to_area ((struct prefix_ipv4 *)&p, range->cost, ar);
  1273. }
  1274. }
  1275. }
  1276. }
  1277. if (IS_DEBUG_OSPF_EVENT)
  1278. zlog_debug ("ospf_abr_announce_aggregates(): Stop");
  1279. }
  1280. static void
  1281. ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
  1282. {
  1283. struct listnode *node; /*, n; */
  1284. struct ospf_area *area; /*, *ar; */
  1285. struct route_node *rn;
  1286. struct ospf_area_range *range;
  1287. struct prefix_ipv4 p;
  1288. if (IS_DEBUG_OSPF_NSSA)
  1289. zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
  1290. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  1291. {
  1292. if (! area->NSSATranslatorState)
  1293. continue;
  1294. if (IS_DEBUG_OSPF_NSSA)
  1295. zlog_debug ("ospf_abr_send_nssa_aggregates(): looking at area %s",
  1296. inet_ntoa (area->area_id));
  1297. for (rn = route_top (area->ranges); rn; rn = route_next (rn))
  1298. {
  1299. if (rn->info == NULL)
  1300. continue;
  1301. range = rn->info;
  1302. if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
  1303. {
  1304. if (IS_DEBUG_OSPF_NSSA)
  1305. zlog_debug ("ospf_abr_send_nssa_aggregates():"
  1306. " discarding suppress-ranges");
  1307. continue;
  1308. }
  1309. p.family = AF_INET;
  1310. p.prefix = range->addr;
  1311. p.prefixlen = range->masklen;
  1312. if (IS_DEBUG_OSPF_NSSA)
  1313. zlog_debug ("ospf_abr_send_nssa_aggregates():"
  1314. " this is range: %s/%d",
  1315. inet_ntoa (p.prefix), p.prefixlen);
  1316. if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
  1317. {
  1318. p.family = AF_INET;
  1319. p.prefix = range->subst_addr;
  1320. p.prefixlen = range->subst_masklen;
  1321. }
  1322. if (range->specifics)
  1323. {
  1324. if (IS_DEBUG_OSPF_NSSA)
  1325. zlog_debug ("ospf_abr_send_nssa_aggregates(): active range");
  1326. /* Fetch LSA-Type-7 from aggregate prefix, and then
  1327. * translate, Install (as Type-5), Approve, and Flood
  1328. */
  1329. ospf_abr_translate_nssa_range (&p, range->cost);
  1330. }
  1331. } /* all area ranges*/
  1332. } /* all areas */
  1333. if (IS_DEBUG_OSPF_NSSA)
  1334. zlog_debug ("ospf_abr_send_nssa_aggregates(): Stop");
  1335. }
  1336. static void
  1337. ospf_abr_announce_stub_defaults (struct ospf *ospf)
  1338. {
  1339. struct listnode *node;
  1340. struct ospf_area *area;
  1341. struct prefix_ipv4 p;
  1342. if (! IS_OSPF_ABR (ospf))
  1343. return;
  1344. if (IS_DEBUG_OSPF_EVENT)
  1345. zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
  1346. p.family = AF_INET;
  1347. p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
  1348. p.prefixlen = 0;
  1349. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  1350. {
  1351. if (IS_DEBUG_OSPF_EVENT)
  1352. zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
  1353. inet_ntoa (area->area_id));
  1354. if ( (area->external_routing != OSPF_AREA_STUB)
  1355. && (area->external_routing != OSPF_AREA_NSSA)
  1356. )
  1357. continue;
  1358. if (OSPF_IS_AREA_BACKBONE (area))
  1359. continue; /* Sanity Check */
  1360. if (IS_DEBUG_OSPF_EVENT)
  1361. zlog_debug ("ospf_abr_announce_stub_defaults(): "
  1362. "announcing 0.0.0.0/0 to area %s",
  1363. inet_ntoa (area->area_id));
  1364. ospf_abr_announce_network_to_area (&p, area->default_cost, area);
  1365. }
  1366. if (IS_DEBUG_OSPF_EVENT)
  1367. zlog_debug ("ospf_abr_announce_stub_defaults(): Stop");
  1368. }
  1369. static int
  1370. ospf_abr_remove_unapproved_translates_apply (struct ospf *ospf,
  1371. struct ospf_lsa *lsa)
  1372. {
  1373. if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)
  1374. && ! CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
  1375. {
  1376. zlog_info ("ospf_abr_remove_unapproved_translates(): "
  1377. "removing unapproved translates, ID: %s",
  1378. inet_ntoa (lsa->data->id));
  1379. /* FLUSH THROUGHOUT AS */
  1380. ospf_lsa_flush_as (ospf, lsa);
  1381. /* DISCARD from LSDB */
  1382. }
  1383. return 0;
  1384. }
  1385. static void
  1386. ospf_abr_remove_unapproved_translates (struct ospf *ospf)
  1387. {
  1388. struct route_node *rn;
  1389. struct ospf_lsa *lsa;
  1390. /* All AREA PROCESS should have APPROVED necessary LSAs */
  1391. /* Remove any left over and not APPROVED */
  1392. if (IS_DEBUG_OSPF_NSSA)
  1393. zlog_debug ("ospf_abr_remove_unapproved_translates(): Start");
  1394. LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
  1395. ospf_abr_remove_unapproved_translates_apply (ospf, lsa);
  1396. if (IS_DEBUG_OSPF_NSSA)
  1397. zlog_debug ("ospf_abr_remove_unapproved_translates(): Stop");
  1398. }
  1399. static void
  1400. ospf_abr_remove_unapproved_summaries (struct ospf *ospf)
  1401. {
  1402. struct listnode *node;
  1403. struct ospf_area *area;
  1404. struct route_node *rn;
  1405. struct ospf_lsa *lsa;
  1406. if (IS_DEBUG_OSPF_EVENT)
  1407. zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
  1408. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  1409. {
  1410. if (IS_DEBUG_OSPF_EVENT)
  1411. zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
  1412. "looking at area %s", inet_ntoa (area->area_id));
  1413. LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
  1414. if (ospf_lsa_is_self_originated (ospf, lsa))
  1415. if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
  1416. ospf_lsa_flush_area (lsa, area);
  1417. LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
  1418. if (ospf_lsa_is_self_originated (ospf, lsa))
  1419. if (!CHECK_FLAG (lsa->flags, OSPF_LSA_APPROVED))
  1420. ospf_lsa_flush_area (lsa, area);
  1421. }
  1422. if (IS_DEBUG_OSPF_EVENT)
  1423. zlog_debug ("ospf_abr_remove_unapproved_summaries(): Stop");
  1424. }
  1425. static void
  1426. ospf_abr_manage_discard_routes (struct ospf *ospf)
  1427. {
  1428. struct listnode *node, *nnode;
  1429. struct route_node *rn;
  1430. struct ospf_area *area;
  1431. struct ospf_area_range *range;
  1432. for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
  1433. for (rn = route_top (area->ranges); rn; rn = route_next (rn))
  1434. if ((range = rn->info) != NULL)
  1435. if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
  1436. {
  1437. if (range->specifics)
  1438. ospf_add_discard_route (ospf->new_table, area,
  1439. (struct prefix_ipv4 *) &rn->p);
  1440. else
  1441. ospf_delete_discard_route (ospf->new_table,
  1442. (struct prefix_ipv4 *) &rn->p);
  1443. }
  1444. }
  1445. /* This is the function taking care about ABR NSSA, i.e. NSSA
  1446. Translator, -LSA aggregation and flooding. For all NSSAs
  1447. Any SELF-AS-LSA is in the Type-5 LSDB and Type-7 LSDB. These LSA's
  1448. are refreshed from the Type-5 LSDB, installed into the Type-7 LSDB
  1449. with the P-bit set.
  1450. Any received Type-5s are legal for an ABR, else illegal for IR.
  1451. Received Type-7s are installed, by area, with incoming P-bit. They
  1452. are flooded; if the Elected NSSA Translator, then P-bit off.
  1453. Additionally, this ABR will place "translated type-7's" into the
  1454. Type-5 LSDB in order to keep track of APPROVAL or not.
  1455. It will scan through every area, looking for Type-7 LSAs with P-Bit
  1456. SET. The Type-7's are either AS-FLOODED & 5-INSTALLED or
  1457. AGGREGATED. Later, the AGGREGATED LSAs are AS-FLOODED &
  1458. 5-INSTALLED.
  1459. 5-INSTALLED is into the Type-5 LSDB; Any UNAPPROVED Type-5 LSAs
  1460. left over are FLUSHED and DISCARDED.
  1461. For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
  1462. any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
  1463. static void
  1464. ospf_abr_nssa_task (struct ospf *ospf) /* called only if any_nssa */
  1465. {
  1466. if (IS_DEBUG_OSPF_NSSA)
  1467. zlog_debug ("Check for NSSA-ABR Tasks():");
  1468. if (! IS_OSPF_ABR (ospf))
  1469. return;
  1470. if (! ospf->anyNSSA)
  1471. return;
  1472. /* Each area must confirm TranslatorRole */
  1473. if (IS_DEBUG_OSPF_NSSA)
  1474. zlog_debug ("ospf_abr_nssa_task(): Start");
  1475. /* For all Global Entries flagged "local-translate", unset APPROVED */
  1476. if (IS_DEBUG_OSPF_NSSA)
  1477. zlog_debug ("ospf_abr_nssa_task(): unapprove translates");
  1478. ospf_abr_unapprove_translates (ospf);
  1479. /* RESET all Ranges in every Area, same as summaries */
  1480. if (IS_DEBUG_OSPF_NSSA)
  1481. zlog_debug ("ospf_abr_nssa_task(): NSSA initialize aggregates");
  1482. ospf_abr_prepare_aggregates (ospf); /*TURNED OFF just for now */
  1483. /* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
  1484. * Aggregate as Type-7
  1485. * Install or Approve in Type-5 Global LSDB
  1486. */
  1487. if (IS_DEBUG_OSPF_NSSA)
  1488. zlog_debug ("ospf_abr_nssa_task(): process translates");
  1489. ospf_abr_process_nssa_translates (ospf);
  1490. /* Translate/Send any "ranged" aggregates, and also 5-Install and
  1491. * Approve
  1492. * Scan Type-7's for aggregates, translate to Type-5's,
  1493. * Install/Flood/Approve
  1494. */
  1495. if (IS_DEBUG_OSPF_NSSA)
  1496. zlog_debug("ospf_abr_nssa_task(): send NSSA aggregates");
  1497. ospf_abr_send_nssa_aggregates (ospf); /*TURNED OFF FOR NOW */
  1498. /* Send any NSSA defaults as Type-5
  1499. *if (IS_DEBUG_OSPF_NSSA)
  1500. * zlog_debug ("ospf_abr_nssa_task(): announce nssa defaults");
  1501. *ospf_abr_announce_nssa_defaults (ospf);
  1502. * havnt a clue what above is supposed to do.
  1503. */
  1504. /* Flush any unapproved previous translates from Global Data Base */
  1505. if (IS_DEBUG_OSPF_NSSA)
  1506. zlog_debug ("ospf_abr_nssa_task(): remove unapproved translates");
  1507. ospf_abr_remove_unapproved_translates (ospf);
  1508. ospf_abr_manage_discard_routes (ospf); /* same as normal...discard */
  1509. if (IS_DEBUG_OSPF_NSSA)
  1510. zlog_debug ("ospf_abr_nssa_task(): Stop");
  1511. }
  1512. /* This is the function taking care about ABR stuff, i.e.
  1513. summary-LSA origination and flooding. */
  1514. void
  1515. ospf_abr_task (struct ospf *ospf)
  1516. {
  1517. if (IS_DEBUG_OSPF_EVENT)
  1518. zlog_debug ("ospf_abr_task(): Start");
  1519. if (ospf->new_table == NULL || ospf->new_rtrs == NULL)
  1520. {
  1521. if (IS_DEBUG_OSPF_EVENT)
  1522. zlog_debug ("ospf_abr_task(): Routing tables are not yet ready");
  1523. return;
  1524. }
  1525. if (IS_DEBUG_OSPF_EVENT)
  1526. zlog_debug ("ospf_abr_task(): unapprove summaries");
  1527. ospf_abr_unapprove_summaries (ospf);
  1528. if (IS_DEBUG_OSPF_EVENT)
  1529. zlog_debug ("ospf_abr_task(): prepare aggregates");
  1530. ospf_abr_prepare_aggregates (ospf);
  1531. if (IS_OSPF_ABR (ospf))
  1532. {
  1533. if (IS_DEBUG_OSPF_EVENT)
  1534. zlog_debug ("ospf_abr_task(): process network RT");
  1535. ospf_abr_process_network_rt (ospf, ospf->new_table);
  1536. if (IS_DEBUG_OSPF_EVENT)
  1537. zlog_debug ("ospf_abr_task(): process router RT");
  1538. ospf_abr_process_router_rt (ospf, ospf->new_rtrs);
  1539. if (IS_DEBUG_OSPF_EVENT)
  1540. zlog_debug ("ospf_abr_task(): announce aggregates");
  1541. ospf_abr_announce_aggregates (ospf);
  1542. if (IS_DEBUG_OSPF_EVENT)
  1543. zlog_debug ("ospf_abr_task(): announce stub defaults");
  1544. ospf_abr_announce_stub_defaults (ospf);
  1545. }
  1546. if (IS_DEBUG_OSPF_EVENT)
  1547. zlog_debug ("ospf_abr_task(): remove unapproved summaries");
  1548. ospf_abr_remove_unapproved_summaries (ospf);
  1549. ospf_abr_manage_discard_routes (ospf);
  1550. if (IS_DEBUG_OSPF_EVENT)
  1551. zlog_debug ("ospf_abr_task(): Stop");
  1552. }
  1553. static int
  1554. ospf_abr_task_timer (struct thread *thread)
  1555. {
  1556. struct ospf *ospf = THREAD_ARG (thread);
  1557. ospf->t_abr_task = 0;
  1558. if (IS_DEBUG_OSPF_EVENT)
  1559. zlog_debug ("Running ABR task on timer");
  1560. ospf_check_abr_status (ospf);
  1561. ospf_abr_nssa_check_status (ospf);
  1562. ospf_abr_task (ospf);
  1563. ospf_abr_nssa_task (ospf); /* if nssa-abr, then scan Type-7 LSDB */
  1564. return 0;
  1565. }
  1566. void
  1567. ospf_schedule_abr_task (struct ospf *ospf)
  1568. {
  1569. if (IS_DEBUG_OSPF_EVENT)
  1570. zlog_debug ("Scheduling ABR task");
  1571. if (ospf->t_abr_task == NULL)
  1572. ospf->t_abr_task = thread_add_timer (master, ospf_abr_task_timer,
  1573. ospf, OSPF_ABR_TASK_DELAY);
  1574. }