ospf_opaque.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174
  1. /*
  2. * This is an implementation of rfc2370.
  3. * Copyright (C) 2001 KDD R&D Laboratories, Inc.
  4. * http://www.kddlabs.co.jp/
  5. *
  6. * This file is part of GNU Zebra.
  7. *
  8. * GNU Zebra is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * GNU Zebra is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  20. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. * 02111-1307, USA.
  22. */
  23. /***** MTYPE definitions are not reflected to "memory.h" yet. *****/
  24. #define MTYPE_OSPF_OPAQUE_FUNCTAB MTYPE_TMP
  25. #define MTYPE_OPAQUE_INFO_PER_TYPE MTYPE_TMP
  26. #define MTYPE_OPAQUE_INFO_PER_ID MTYPE_TMP
  27. #include <zebra.h>
  28. #include "linklist.h"
  29. #include "prefix.h"
  30. #include "if.h"
  31. #include "table.h"
  32. #include "memory.h"
  33. #include "command.h"
  34. #include "vty.h"
  35. #include "stream.h"
  36. #include "log.h"
  37. #include "thread.h"
  38. #include "hash.h"
  39. #include "sockunion.h" /* for inet_aton() */
  40. #include "ospfd/ospfd.h"
  41. #include "ospfd/ospf_interface.h"
  42. #include "ospfd/ospf_ism.h"
  43. #include "ospfd/ospf_asbr.h"
  44. #include "ospfd/ospf_lsa.h"
  45. #include "ospfd/ospf_lsdb.h"
  46. #include "ospfd/ospf_neighbor.h"
  47. #include "ospfd/ospf_nsm.h"
  48. #include "ospfd/ospf_flood.h"
  49. #include "ospfd/ospf_packet.h"
  50. #include "ospfd/ospf_spf.h"
  51. #include "ospfd/ospf_dump.h"
  52. #include "ospfd/ospf_route.h"
  53. #include "ospfd/ospf_ase.h"
  54. #include "ospfd/ospf_zebra.h"
  55. /*------------------------------------------------------------------------*
  56. * Followings are initialize/terminate functions for Opaque-LSAs handling.
  57. *------------------------------------------------------------------------*/
  58. #include "ospfd/ospf_te.h"
  59. #ifdef SUPPORT_OSPF_API
  60. int ospf_apiserver_init (void);
  61. void ospf_apiserver_term (void);
  62. /* Init apiserver? It's disabled by default. */
  63. int ospf_apiserver_enable;
  64. #endif /* SUPPORT_OSPF_API */
  65. static void ospf_opaque_register_vty (void);
  66. static void ospf_opaque_funclist_init (void);
  67. static void ospf_opaque_funclist_term (void);
  68. static void free_opaque_info_per_type (void *val);
  69. static void free_opaque_info_per_id (void *val);
  70. static int ospf_opaque_lsa_install_hook (struct ospf_lsa *lsa);
  71. static int ospf_opaque_lsa_delete_hook (struct ospf_lsa *lsa);
  72. void
  73. ospf_opaque_init (void)
  74. {
  75. ospf_opaque_register_vty ();
  76. ospf_opaque_funclist_init ();
  77. if (ospf_mpls_te_init () != 0)
  78. exit (1);
  79. #ifdef SUPPORT_OSPF_API
  80. if ((ospf_apiserver_enable) && (ospf_apiserver_init () != 0))
  81. exit (1);
  82. #endif /* SUPPORT_OSPF_API */
  83. return;
  84. }
  85. void
  86. ospf_opaque_term (void)
  87. {
  88. ospf_mpls_te_term ();
  89. #ifdef SUPPORT_OSPF_API
  90. ospf_apiserver_term ();
  91. #endif /* SUPPORT_OSPF_API */
  92. ospf_opaque_funclist_term ();
  93. return;
  94. }
  95. int
  96. ospf_opaque_type9_lsa_init (struct ospf_interface *oi)
  97. {
  98. if (oi->opaque_lsa_self != NULL)
  99. list_delete (oi->opaque_lsa_self);
  100. oi->opaque_lsa_self = list_new ();
  101. oi->opaque_lsa_self->del = free_opaque_info_per_type;
  102. oi->t_opaque_lsa_self = NULL;
  103. return 0;
  104. }
  105. void
  106. ospf_opaque_type9_lsa_term (struct ospf_interface *oi)
  107. {
  108. OSPF_TIMER_OFF (oi->t_opaque_lsa_self);
  109. if (oi->opaque_lsa_self != NULL)
  110. list_delete (oi->opaque_lsa_self);
  111. oi->opaque_lsa_self = NULL;
  112. return;
  113. }
  114. int
  115. ospf_opaque_type10_lsa_init (struct ospf_area *area)
  116. {
  117. if (area->opaque_lsa_self != NULL)
  118. list_delete (area->opaque_lsa_self);
  119. area->opaque_lsa_self = list_new ();
  120. area->opaque_lsa_self->del = free_opaque_info_per_type;
  121. area->t_opaque_lsa_self = NULL;
  122. #ifdef MONITOR_LSDB_CHANGE
  123. area->lsdb->new_lsa_hook = ospf_opaque_lsa_install_hook;
  124. area->lsdb->del_lsa_hook = ospf_opaque_lsa_delete_hook;
  125. #endif /* MONITOR_LSDB_CHANGE */
  126. return 0;
  127. }
  128. void
  129. ospf_opaque_type10_lsa_term (struct ospf_area *area)
  130. {
  131. #ifdef MONITOR_LSDB_CHANGE
  132. area->lsdb->new_lsa_hook =
  133. area->lsdb->del_lsa_hook = NULL;
  134. #endif /* MONITOR_LSDB_CHANGE */
  135. OSPF_TIMER_OFF (area->t_opaque_lsa_self);
  136. if (area->opaque_lsa_self != NULL)
  137. list_delete (area->opaque_lsa_self);
  138. area->opaque_lsa_self = NULL;
  139. return;
  140. }
  141. int
  142. ospf_opaque_type11_lsa_init (struct ospf *top)
  143. {
  144. if (top->opaque_lsa_self != NULL)
  145. list_delete (top->opaque_lsa_self);
  146. top->opaque_lsa_self = list_new ();
  147. top->opaque_lsa_self->del = free_opaque_info_per_type;
  148. top->t_opaque_lsa_self = NULL;
  149. #ifdef MONITOR_LSDB_CHANGE
  150. top->lsdb->new_lsa_hook = ospf_opaque_lsa_install_hook;
  151. top->lsdb->del_lsa_hook = ospf_opaque_lsa_delete_hook;
  152. #endif /* MONITOR_LSDB_CHANGE */
  153. return 0;
  154. }
  155. void
  156. ospf_opaque_type11_lsa_term (struct ospf *top)
  157. {
  158. #ifdef MONITOR_LSDB_CHANGE
  159. top->lsdb->new_lsa_hook =
  160. top->lsdb->del_lsa_hook = NULL;
  161. #endif /* MONITOR_LSDB_CHANGE */
  162. OSPF_TIMER_OFF (top->t_opaque_lsa_self);
  163. if (top->opaque_lsa_self != NULL)
  164. list_delete (top->opaque_lsa_self);
  165. top->opaque_lsa_self = NULL;
  166. return;
  167. }
  168. static const char *
  169. ospf_opaque_type_name (u_char opaque_type)
  170. {
  171. const char *name = "Unknown";
  172. switch (opaque_type)
  173. {
  174. case OPAQUE_TYPE_WILDCARD: /* This is a special assignment! */
  175. name = "Wildcard";
  176. break;
  177. case OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA:
  178. name = "Traffic Engineering LSA";
  179. break;
  180. case OPAQUE_TYPE_SYCAMORE_OPTICAL_TOPOLOGY_DESC:
  181. name = "Sycamore optical topology description";
  182. break;
  183. case OPAQUE_TYPE_GRACE_LSA:
  184. name = "Grace-LSA";
  185. break;
  186. default:
  187. if (OPAQUE_TYPE_RANGE_UNASSIGNED (opaque_type))
  188. name = "Unassigned";
  189. else
  190. {
  191. u_int32_t bigger_range = opaque_type;
  192. /*
  193. * Get around type-limits warning: comparison is always true due to limited range of data type
  194. */
  195. if (OPAQUE_TYPE_RANGE_RESERVED (bigger_range))
  196. name = "Private/Experimental";
  197. }
  198. break;
  199. }
  200. return name;
  201. }
  202. /*------------------------------------------------------------------------*
  203. * Followings are management functions to store user specified callbacks.
  204. *------------------------------------------------------------------------*/
  205. struct opaque_info_per_type; /* Forward declaration. */
  206. struct ospf_opaque_functab
  207. {
  208. u_char opaque_type;
  209. struct opaque_info_per_type *oipt;
  210. int (* new_if_hook)(struct interface *ifp);
  211. int (* del_if_hook)(struct interface *ifp);
  212. void (* ism_change_hook)(struct ospf_interface *oi, int old_status);
  213. void (* nsm_change_hook)(struct ospf_neighbor *nbr, int old_status);
  214. void (* config_write_router)(struct vty *vty);
  215. void (* config_write_if )(struct vty *vty, struct interface *ifp);
  216. void (* config_write_debug )(struct vty *vty);
  217. void (* show_opaque_info )(struct vty *vty, struct ospf_lsa *lsa);
  218. int (* lsa_originator)(void *arg);
  219. struct ospf_lsa *(* lsa_refresher )(struct ospf_lsa *lsa);
  220. int (* new_lsa_hook)(struct ospf_lsa *lsa);
  221. int (* del_lsa_hook)(struct ospf_lsa *lsa);
  222. };
  223. /* Handle LSA-9/10/11 altogether. */
  224. static struct list *ospf_opaque_wildcard_funclist;
  225. static struct list *ospf_opaque_type9_funclist;
  226. static struct list *ospf_opaque_type10_funclist;
  227. static struct list *ospf_opaque_type11_funclist;
  228. static void
  229. ospf_opaque_del_functab (void *val)
  230. {
  231. XFREE (MTYPE_OSPF_OPAQUE_FUNCTAB, val);
  232. return;
  233. }
  234. static void
  235. ospf_opaque_funclist_init (void)
  236. {
  237. struct list *funclist;
  238. funclist = ospf_opaque_wildcard_funclist = list_new ();
  239. funclist->del = ospf_opaque_del_functab;
  240. funclist = ospf_opaque_type9_funclist = list_new ();
  241. funclist->del = ospf_opaque_del_functab;
  242. funclist = ospf_opaque_type10_funclist = list_new ();
  243. funclist->del = ospf_opaque_del_functab;
  244. funclist = ospf_opaque_type11_funclist = list_new ();
  245. funclist->del = ospf_opaque_del_functab;
  246. return;
  247. }
  248. static void
  249. ospf_opaque_funclist_term (void)
  250. {
  251. struct list *funclist;
  252. funclist = ospf_opaque_wildcard_funclist;
  253. list_delete (funclist);
  254. funclist = ospf_opaque_type9_funclist;
  255. list_delete (funclist);
  256. funclist = ospf_opaque_type10_funclist;
  257. list_delete (funclist);
  258. funclist = ospf_opaque_type11_funclist;
  259. list_delete (funclist);
  260. return;
  261. }
  262. static struct list *
  263. ospf_get_opaque_funclist (u_char lsa_type)
  264. {
  265. struct list *funclist = NULL;
  266. switch (lsa_type)
  267. {
  268. case OPAQUE_TYPE_WILDCARD:
  269. /* XXX
  270. * This is an ugly trick to handle type-9/10/11 LSA altogether.
  271. * Yes, "OPAQUE_TYPE_WILDCARD (value 0)" is not an LSA-type, nor
  272. * an officially assigned opaque-type.
  273. * Though it is possible that the value might be officially used
  274. * in the future, we use it internally as a special label, for now.
  275. */
  276. funclist = ospf_opaque_wildcard_funclist;
  277. break;
  278. case OSPF_OPAQUE_LINK_LSA:
  279. funclist = ospf_opaque_type9_funclist;
  280. break;
  281. case OSPF_OPAQUE_AREA_LSA:
  282. funclist = ospf_opaque_type10_funclist;
  283. break;
  284. case OSPF_OPAQUE_AS_LSA:
  285. funclist = ospf_opaque_type11_funclist;
  286. break;
  287. default:
  288. zlog_warn ("ospf_get_opaque_funclist: Unexpected LSA-type(%u)", lsa_type);
  289. break;
  290. }
  291. return funclist;
  292. }
  293. /* XXX: such a huge argument list can /not/ be healthy... */
  294. int
  295. ospf_register_opaque_functab (
  296. u_char lsa_type,
  297. u_char opaque_type,
  298. int (* new_if_hook)(struct interface *ifp),
  299. int (* del_if_hook)(struct interface *ifp),
  300. void (* ism_change_hook)(struct ospf_interface *oi, int old_status),
  301. void (* nsm_change_hook)(struct ospf_neighbor *nbr, int old_status),
  302. void (* config_write_router)(struct vty *vty),
  303. void (* config_write_if )(struct vty *vty, struct interface *ifp),
  304. void (* config_write_debug )(struct vty *vty),
  305. void (* show_opaque_info )(struct vty *vty, struct ospf_lsa *lsa),
  306. int (* lsa_originator)(void *arg),
  307. struct ospf_lsa *(* lsa_refresher )(struct ospf_lsa *lsa),
  308. int (* new_lsa_hook)(struct ospf_lsa *lsa),
  309. int (* del_lsa_hook)(struct ospf_lsa *lsa))
  310. {
  311. struct list *funclist;
  312. struct ospf_opaque_functab *new;
  313. int rc = -1;
  314. if ((funclist = ospf_get_opaque_funclist (lsa_type)) == NULL)
  315. {
  316. zlog_warn ("ospf_register_opaque_functab: Cannot get funclist"
  317. " for Type-%u LSAs?",
  318. lsa_type);
  319. goto out;
  320. }
  321. else
  322. {
  323. struct listnode *node, *nnode;
  324. struct ospf_opaque_functab *functab;
  325. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  326. if (functab->opaque_type == opaque_type)
  327. {
  328. zlog_warn ("ospf_register_opaque_functab: Duplicated entry?:"
  329. " lsa_type(%u), opaque_type(%u)",
  330. lsa_type, opaque_type);
  331. goto out;
  332. }
  333. }
  334. if ((new = XCALLOC (MTYPE_OSPF_OPAQUE_FUNCTAB,
  335. sizeof (struct ospf_opaque_functab))) == NULL)
  336. {
  337. zlog_warn ("ospf_register_opaque_functab: XMALLOC: %s",
  338. safe_strerror (errno));
  339. goto out;
  340. }
  341. new->opaque_type = opaque_type;
  342. new->oipt = NULL;
  343. new->new_if_hook = new_if_hook;
  344. new->del_if_hook = del_if_hook;
  345. new->ism_change_hook = ism_change_hook;
  346. new->nsm_change_hook = nsm_change_hook;
  347. new->config_write_router = config_write_router;
  348. new->config_write_if = config_write_if;
  349. new->config_write_debug = config_write_debug;
  350. new->show_opaque_info = show_opaque_info;
  351. new->lsa_originator = lsa_originator;
  352. new->lsa_refresher = lsa_refresher;
  353. new->new_lsa_hook = new_lsa_hook;
  354. new->del_lsa_hook = del_lsa_hook;
  355. listnode_add (funclist, new);
  356. rc = 0;
  357. out:
  358. return rc;
  359. }
  360. void
  361. ospf_delete_opaque_functab (u_char lsa_type, u_char opaque_type)
  362. {
  363. struct list *funclist;
  364. struct listnode *node, *nnode;
  365. struct ospf_opaque_functab *functab;
  366. if ((funclist = ospf_get_opaque_funclist (lsa_type)) != NULL)
  367. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  368. {
  369. if (functab->opaque_type == opaque_type)
  370. {
  371. /* Cleanup internal control information, if it still remains. */
  372. if (functab->oipt != NULL)
  373. free_opaque_info_per_type (functab->oipt);
  374. /* Dequeue listnode entry from the list. */
  375. listnode_delete (funclist, functab);
  376. /* Avoid misjudgement in the next lookup. */
  377. if (listcount (funclist) == 0)
  378. funclist->head = funclist->tail = NULL;
  379. XFREE (MTYPE_OSPF_OPAQUE_FUNCTAB, functab);
  380. break;
  381. }
  382. }
  383. return;
  384. }
  385. static struct ospf_opaque_functab *
  386. ospf_opaque_functab_lookup (struct ospf_lsa *lsa)
  387. {
  388. struct list *funclist;
  389. struct listnode *node;
  390. struct ospf_opaque_functab *functab;
  391. u_char key = GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr));
  392. if ((funclist = ospf_get_opaque_funclist (lsa->data->type)) != NULL)
  393. for (ALL_LIST_ELEMENTS_RO (funclist, node, functab))
  394. if (functab->opaque_type == key)
  395. return functab;
  396. return NULL;
  397. }
  398. /*------------------------------------------------------------------------*
  399. * Followings are management functions for self-originated LSA entries.
  400. *------------------------------------------------------------------------*/
  401. /*
  402. * Opaque-LSA control information per opaque-type.
  403. * Single Opaque-Type may have multiple instances; each of them will be
  404. * identified by their opaque-id.
  405. */
  406. struct opaque_info_per_type
  407. {
  408. u_char lsa_type;
  409. u_char opaque_type;
  410. enum { PROC_NORMAL, PROC_SUSPEND } status;
  411. /*
  412. * Thread for (re-)origination scheduling for this opaque-type.
  413. *
  414. * Initial origination of Opaque-LSAs is controlled by generic
  415. * Opaque-LSA handling module so that same opaque-type entries are
  416. * called all at once when certain conditions are met.
  417. * However, there might be cases that some Opaque-LSA clients need
  418. * to (re-)originate their own Opaque-LSAs out-of-sync with others.
  419. * This thread is prepared for that specific purpose.
  420. */
  421. struct thread *t_opaque_lsa_self;
  422. /*
  423. * Backpointer to an "owner" which is LSA-type dependent.
  424. * type-9: struct ospf_interface
  425. * type-10: struct ospf_area
  426. * type-11: struct ospf
  427. */
  428. void *owner;
  429. /* Collection of callback functions for this opaque-type. */
  430. struct ospf_opaque_functab *functab;
  431. /* List of Opaque-LSA control informations per opaque-id. */
  432. struct list *id_list;
  433. };
  434. /* Opaque-LSA control information per opaque-id. */
  435. struct opaque_info_per_id
  436. {
  437. u_int32_t opaque_id;
  438. /* Thread for refresh/flush scheduling for this opaque-type/id. */
  439. struct thread *t_opaque_lsa_self;
  440. /* Backpointer to Opaque-LSA control information per opaque-type. */
  441. struct opaque_info_per_type *opqctl_type;
  442. /* Here comes an actual Opaque-LSA entry for this opaque-type/id. */
  443. struct ospf_lsa *lsa;
  444. };
  445. static struct opaque_info_per_type *register_opaque_info_per_type (struct ospf_opaque_functab *functab, struct ospf_lsa *new);
  446. static struct opaque_info_per_type *lookup_opaque_info_by_type (struct ospf_lsa *lsa);
  447. static struct opaque_info_per_id *register_opaque_info_per_id (struct opaque_info_per_type *oipt, struct ospf_lsa *new);
  448. static struct opaque_info_per_id *lookup_opaque_info_by_id (struct opaque_info_per_type *oipt, struct ospf_lsa *lsa);
  449. static struct opaque_info_per_id *register_opaque_lsa (struct ospf_lsa *new);
  450. static struct opaque_info_per_type *
  451. register_opaque_info_per_type (struct ospf_opaque_functab *functab,
  452. struct ospf_lsa *new)
  453. {
  454. struct ospf *top;
  455. struct opaque_info_per_type *oipt;
  456. if ((oipt = XCALLOC (MTYPE_OPAQUE_INFO_PER_TYPE,
  457. sizeof (struct opaque_info_per_type))) == NULL)
  458. {
  459. zlog_warn ("register_opaque_info_per_type: XMALLOC: %s", safe_strerror (errno));
  460. goto out;
  461. }
  462. switch (new->data->type)
  463. {
  464. case OSPF_OPAQUE_LINK_LSA:
  465. oipt->owner = new->oi;
  466. listnode_add (new->oi->opaque_lsa_self, oipt);
  467. break;
  468. case OSPF_OPAQUE_AREA_LSA:
  469. oipt->owner = new->area;
  470. listnode_add (new->area->opaque_lsa_self, oipt);
  471. break;
  472. case OSPF_OPAQUE_AS_LSA:
  473. top = ospf_lookup ();
  474. if (new->area != NULL && (top = new->area->ospf) == NULL)
  475. {
  476. free_opaque_info_per_type ((void *) oipt);
  477. oipt = NULL;
  478. goto out; /* This case may not exist. */
  479. }
  480. oipt->owner = top;
  481. listnode_add (top->opaque_lsa_self, oipt);
  482. break;
  483. default:
  484. zlog_warn ("register_opaque_info_per_type: Unexpected LSA-type(%u)", new->data->type);
  485. free_opaque_info_per_type ((void *) oipt);
  486. oipt = NULL;
  487. goto out; /* This case may not exist. */
  488. }
  489. oipt->lsa_type = new->data->type;
  490. oipt->opaque_type = GET_OPAQUE_TYPE (ntohl (new->data->id.s_addr));
  491. oipt->status = PROC_NORMAL;
  492. oipt->t_opaque_lsa_self = NULL;
  493. oipt->functab = functab;
  494. functab->oipt = oipt;
  495. oipt->id_list = list_new ();
  496. oipt->id_list->del = free_opaque_info_per_id;
  497. out:
  498. return oipt;
  499. }
  500. static void
  501. free_opaque_info_per_type (void *val)
  502. {
  503. struct opaque_info_per_type *oipt = (struct opaque_info_per_type *) val;
  504. struct opaque_info_per_id *oipi;
  505. struct ospf_lsa *lsa;
  506. struct listnode *node, *nnode;
  507. /* Control information per opaque-id may still exist. */
  508. for (ALL_LIST_ELEMENTS (oipt->id_list, node, nnode, oipi))
  509. {
  510. if ((lsa = oipi->lsa) == NULL)
  511. continue;
  512. if (IS_LSA_MAXAGE (lsa))
  513. continue;
  514. ospf_opaque_lsa_flush_schedule (lsa);
  515. }
  516. /* Remove "oipt" from its owner's self-originated LSA list. */
  517. switch (oipt->lsa_type)
  518. {
  519. case OSPF_OPAQUE_LINK_LSA:
  520. {
  521. struct ospf_interface *oi = (struct ospf_interface *)(oipt->owner);
  522. listnode_delete (oi->opaque_lsa_self, oipt);
  523. break;
  524. }
  525. case OSPF_OPAQUE_AREA_LSA:
  526. {
  527. struct ospf_area *area = (struct ospf_area *)(oipt->owner);
  528. listnode_delete (area->opaque_lsa_self, oipt);
  529. break;
  530. }
  531. case OSPF_OPAQUE_AS_LSA:
  532. {
  533. struct ospf *top = (struct ospf *)(oipt->owner);
  534. listnode_delete (top->opaque_lsa_self, oipt);
  535. break;
  536. }
  537. default:
  538. zlog_warn ("free_opaque_info_per_type: Unexpected LSA-type(%u)", oipt->lsa_type);
  539. break; /* This case may not exist. */
  540. }
  541. OSPF_TIMER_OFF (oipt->t_opaque_lsa_self);
  542. list_delete (oipt->id_list);
  543. XFREE (MTYPE_OPAQUE_INFO_PER_TYPE, oipt);
  544. return;
  545. }
  546. static struct opaque_info_per_type *
  547. lookup_opaque_info_by_type (struct ospf_lsa *lsa)
  548. {
  549. struct ospf *top;
  550. struct ospf_area *area;
  551. struct ospf_interface *oi;
  552. struct list *listtop = NULL;
  553. struct listnode *node, *nnode;
  554. struct opaque_info_per_type *oipt = NULL;
  555. u_char key = GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr));
  556. switch (lsa->data->type)
  557. {
  558. case OSPF_OPAQUE_LINK_LSA:
  559. if ((oi = lsa->oi) != NULL)
  560. listtop = oi->opaque_lsa_self;
  561. else
  562. zlog_warn ("Type-9 Opaque-LSA: Reference to OI is missing?");
  563. break;
  564. case OSPF_OPAQUE_AREA_LSA:
  565. if ((area = lsa->area) != NULL)
  566. listtop = area->opaque_lsa_self;
  567. else
  568. zlog_warn ("Type-10 Opaque-LSA: Reference to AREA is missing?");
  569. break;
  570. case OSPF_OPAQUE_AS_LSA:
  571. top = ospf_lookup ();
  572. if ((area = lsa->area) != NULL && (top = area->ospf) == NULL)
  573. {
  574. zlog_warn ("Type-11 Opaque-LSA: Reference to OSPF is missing?");
  575. break; /* Unlikely to happen. */
  576. }
  577. listtop = top->opaque_lsa_self;
  578. break;
  579. default:
  580. zlog_warn ("lookup_opaque_info_by_type: Unexpected LSA-type(%u)", lsa->data->type);
  581. break;
  582. }
  583. if (listtop != NULL)
  584. for (ALL_LIST_ELEMENTS (listtop, node, nnode, oipt))
  585. if (oipt->opaque_type == key)
  586. return oipt;
  587. return NULL;
  588. }
  589. static struct opaque_info_per_id *
  590. register_opaque_info_per_id (struct opaque_info_per_type *oipt,
  591. struct ospf_lsa *new)
  592. {
  593. struct opaque_info_per_id *oipi;
  594. if ((oipi = XCALLOC (MTYPE_OPAQUE_INFO_PER_ID,
  595. sizeof (struct opaque_info_per_id))) == NULL)
  596. {
  597. zlog_warn ("register_opaque_info_per_id: XMALLOC: %s", safe_strerror (errno));
  598. goto out;
  599. }
  600. oipi->opaque_id = GET_OPAQUE_ID (ntohl (new->data->id.s_addr));
  601. oipi->t_opaque_lsa_self = NULL;
  602. oipi->opqctl_type = oipt;
  603. oipi->lsa = ospf_lsa_lock (new);
  604. listnode_add (oipt->id_list, oipi);
  605. out:
  606. return oipi;
  607. }
  608. static void
  609. free_opaque_info_per_id (void *val)
  610. {
  611. struct opaque_info_per_id *oipi = (struct opaque_info_per_id *) val;
  612. OSPF_TIMER_OFF (oipi->t_opaque_lsa_self);
  613. if (oipi->lsa != NULL)
  614. ospf_lsa_unlock (&oipi->lsa);
  615. XFREE (MTYPE_OPAQUE_INFO_PER_ID, oipi);
  616. return;
  617. }
  618. static struct opaque_info_per_id *
  619. lookup_opaque_info_by_id (struct opaque_info_per_type *oipt,
  620. struct ospf_lsa *lsa)
  621. {
  622. struct listnode *node, *nnode;
  623. struct opaque_info_per_id *oipi;
  624. u_int32_t key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr));
  625. for (ALL_LIST_ELEMENTS (oipt->id_list, node, nnode, oipi))
  626. if (oipi->opaque_id == key)
  627. return oipi;
  628. return NULL;
  629. }
  630. static struct opaque_info_per_id *
  631. register_opaque_lsa (struct ospf_lsa *new)
  632. {
  633. struct ospf_opaque_functab *functab;
  634. struct opaque_info_per_type *oipt;
  635. struct opaque_info_per_id *oipi = NULL;
  636. if ((functab = ospf_opaque_functab_lookup (new)) == NULL)
  637. goto out;
  638. if ((oipt = lookup_opaque_info_by_type (new)) == NULL
  639. && (oipt = register_opaque_info_per_type (functab, new)) == NULL)
  640. goto out;
  641. if ((oipi = register_opaque_info_per_id (oipt, new)) == NULL)
  642. goto out;
  643. out:
  644. return oipi;
  645. }
  646. /*------------------------------------------------------------------------*
  647. * Followings are (vty) configuration functions for Opaque-LSAs handling.
  648. *------------------------------------------------------------------------*/
  649. DEFUN (capability_opaque,
  650. capability_opaque_cmd,
  651. "capability opaque",
  652. "Enable specific OSPF feature\n"
  653. "Opaque LSA\n")
  654. {
  655. struct ospf *ospf = (struct ospf *) vty->index;
  656. /* Turn on the "master switch" of opaque-lsa capability. */
  657. if (!CHECK_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE))
  658. {
  659. if (IS_DEBUG_OSPF_EVENT)
  660. zlog_debug ("Opaque capability: OFF -> ON");
  661. SET_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE);
  662. ospf_renegotiate_optional_capabilities (ospf);
  663. }
  664. return CMD_SUCCESS;
  665. }
  666. ALIAS (capability_opaque,
  667. ospf_opaque_capable_cmd,
  668. "ospf opaque-lsa",
  669. "OSPF specific commands\n"
  670. "Enable the Opaque-LSA capability (rfc2370)\n")
  671. DEFUN (no_capability_opaque,
  672. no_capability_opaque_cmd,
  673. "no capability opaque",
  674. NO_STR
  675. "Enable specific OSPF feature\n"
  676. "Opaque LSA\n")
  677. {
  678. struct ospf *ospf = (struct ospf *) vty->index;
  679. /* Turn off the "master switch" of opaque-lsa capability. */
  680. if (CHECK_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE))
  681. {
  682. if (IS_DEBUG_OSPF_EVENT)
  683. zlog_debug ("Opaque capability: ON -> OFF");
  684. UNSET_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE);
  685. ospf_renegotiate_optional_capabilities (ospf);
  686. }
  687. return CMD_SUCCESS;
  688. }
  689. ALIAS (no_capability_opaque,
  690. no_ospf_opaque_capable_cmd,
  691. "no ospf opaque-lsa",
  692. NO_STR
  693. "OSPF specific commands\n"
  694. "Disable the Opaque-LSA capability (rfc2370)\n")
  695. static void
  696. ospf_opaque_register_vty (void)
  697. {
  698. install_element (OSPF_NODE, &capability_opaque_cmd);
  699. install_element (OSPF_NODE, &no_capability_opaque_cmd);
  700. install_element (OSPF_NODE, &ospf_opaque_capable_cmd);
  701. install_element (OSPF_NODE, &no_ospf_opaque_capable_cmd);
  702. return;
  703. }
  704. /*------------------------------------------------------------------------*
  705. * Followings are collection of user-registered function callers.
  706. *------------------------------------------------------------------------*/
  707. static int
  708. opaque_lsa_new_if_callback (struct list *funclist, struct interface *ifp)
  709. {
  710. struct listnode *node, *nnode;
  711. struct ospf_opaque_functab *functab;
  712. int rc = -1;
  713. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  714. if (functab->new_if_hook != NULL)
  715. if ((* functab->new_if_hook)(ifp) != 0)
  716. goto out;
  717. rc = 0;
  718. out:
  719. return rc;
  720. }
  721. static int
  722. opaque_lsa_del_if_callback (struct list *funclist, struct interface *ifp)
  723. {
  724. struct listnode *node, *nnode;
  725. struct ospf_opaque_functab *functab;
  726. int rc = -1;
  727. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  728. if (functab->del_if_hook != NULL)
  729. if ((* functab->del_if_hook)(ifp) != 0)
  730. goto out;
  731. rc = 0;
  732. out:
  733. return rc;
  734. }
  735. static void
  736. opaque_lsa_ism_change_callback (struct list *funclist,
  737. struct ospf_interface *oi, int old_status)
  738. {
  739. struct listnode *node, *nnode;
  740. struct ospf_opaque_functab *functab;
  741. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  742. if (functab->ism_change_hook != NULL)
  743. (* functab->ism_change_hook)(oi, old_status);
  744. return;
  745. }
  746. static void
  747. opaque_lsa_nsm_change_callback (struct list *funclist,
  748. struct ospf_neighbor *nbr, int old_status)
  749. {
  750. struct listnode *node, *nnode;
  751. struct ospf_opaque_functab *functab;
  752. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  753. if (functab->nsm_change_hook != NULL)
  754. (* functab->nsm_change_hook)(nbr, old_status);
  755. return;
  756. }
  757. static void
  758. opaque_lsa_config_write_router_callback (struct list *funclist,
  759. struct vty *vty)
  760. {
  761. struct listnode *node, *nnode;
  762. struct ospf_opaque_functab *functab;
  763. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  764. if (functab->config_write_router != NULL)
  765. (* functab->config_write_router)(vty);
  766. return;
  767. }
  768. static void
  769. opaque_lsa_config_write_if_callback (struct list *funclist,
  770. struct vty *vty, struct interface *ifp)
  771. {
  772. struct listnode *node, *nnode;
  773. struct ospf_opaque_functab *functab;
  774. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  775. if (functab->config_write_if != NULL)
  776. (* functab->config_write_if)(vty, ifp);
  777. return;
  778. }
  779. static void
  780. opaque_lsa_config_write_debug_callback (struct list *funclist, struct vty *vty)
  781. {
  782. struct listnode *node, *nnode;
  783. struct ospf_opaque_functab *functab;
  784. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  785. if (functab->config_write_debug != NULL)
  786. (* functab->config_write_debug)(vty);
  787. return;
  788. }
  789. static int
  790. opaque_lsa_originate_callback (struct list *funclist, void *lsa_type_dependent)
  791. {
  792. struct listnode *node, *nnode;
  793. struct ospf_opaque_functab *functab;
  794. int rc = -1;
  795. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  796. if (functab->lsa_originator != NULL)
  797. if ((* functab->lsa_originator)(lsa_type_dependent) != 0)
  798. goto out;
  799. rc = 0;
  800. out:
  801. return rc;
  802. }
  803. static int
  804. new_lsa_callback (struct list *funclist, struct ospf_lsa *lsa)
  805. {
  806. struct listnode *node, *nnode;
  807. struct ospf_opaque_functab *functab;
  808. int rc = -1;
  809. /* This function handles ALL types of LSAs, not only opaque ones. */
  810. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  811. if (functab->new_lsa_hook != NULL)
  812. if ((* functab->new_lsa_hook)(lsa) != 0)
  813. goto out;
  814. rc = 0;
  815. out:
  816. return rc;
  817. }
  818. static int
  819. del_lsa_callback (struct list *funclist, struct ospf_lsa *lsa)
  820. {
  821. struct listnode *node, *nnode;
  822. struct ospf_opaque_functab *functab;
  823. int rc = -1;
  824. /* This function handles ALL types of LSAs, not only opaque ones. */
  825. for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab))
  826. if (functab->del_lsa_hook != NULL)
  827. if ((* functab->del_lsa_hook)(lsa) != 0)
  828. goto out;
  829. rc = 0;
  830. out:
  831. return rc;
  832. }
  833. /*------------------------------------------------------------------------*
  834. * Followings are glue functions to call Opaque-LSA specific processing.
  835. *------------------------------------------------------------------------*/
  836. int
  837. ospf_opaque_new_if (struct interface *ifp)
  838. {
  839. struct list *funclist;
  840. int rc = -1;
  841. funclist = ospf_opaque_wildcard_funclist;
  842. if (opaque_lsa_new_if_callback (funclist, ifp) != 0)
  843. goto out;
  844. funclist = ospf_opaque_type9_funclist;
  845. if (opaque_lsa_new_if_callback (funclist, ifp) != 0)
  846. goto out;
  847. funclist = ospf_opaque_type10_funclist;
  848. if (opaque_lsa_new_if_callback (funclist, ifp) != 0)
  849. goto out;
  850. funclist = ospf_opaque_type11_funclist;
  851. if (opaque_lsa_new_if_callback (funclist, ifp) != 0)
  852. goto out;
  853. rc = 0;
  854. out:
  855. return rc;
  856. }
  857. int
  858. ospf_opaque_del_if (struct interface *ifp)
  859. {
  860. struct list *funclist;
  861. int rc = -1;
  862. funclist = ospf_opaque_wildcard_funclist;
  863. if (opaque_lsa_del_if_callback (funclist, ifp) != 0)
  864. goto out;
  865. funclist = ospf_opaque_type9_funclist;
  866. if (opaque_lsa_del_if_callback (funclist, ifp) != 0)
  867. goto out;
  868. funclist = ospf_opaque_type10_funclist;
  869. if (opaque_lsa_del_if_callback (funclist, ifp) != 0)
  870. goto out;
  871. funclist = ospf_opaque_type11_funclist;
  872. if (opaque_lsa_del_if_callback (funclist, ifp) != 0)
  873. goto out;
  874. rc = 0;
  875. out:
  876. return rc;
  877. }
  878. void
  879. ospf_opaque_ism_change (struct ospf_interface *oi, int old_status)
  880. {
  881. struct list *funclist;
  882. funclist = ospf_opaque_wildcard_funclist;
  883. opaque_lsa_ism_change_callback (funclist, oi, old_status);
  884. funclist = ospf_opaque_type9_funclist;
  885. opaque_lsa_ism_change_callback (funclist, oi, old_status);
  886. funclist = ospf_opaque_type10_funclist;
  887. opaque_lsa_ism_change_callback (funclist, oi, old_status);
  888. funclist = ospf_opaque_type11_funclist;
  889. opaque_lsa_ism_change_callback (funclist, oi, old_status);
  890. return;
  891. }
  892. void
  893. ospf_opaque_nsm_change (struct ospf_neighbor *nbr, int old_state)
  894. {
  895. struct ospf *top;
  896. struct list *funclist;
  897. if ((top = oi_to_top (nbr->oi)) == NULL)
  898. goto out;
  899. if (old_state != NSM_Full && nbr->state == NSM_Full)
  900. {
  901. if (CHECK_FLAG (nbr->options, OSPF_OPTION_O))
  902. {
  903. if (! CHECK_FLAG (top->opaque, OPAQUE_OPERATION_READY_BIT))
  904. {
  905. if (IS_DEBUG_OSPF_EVENT)
  906. zlog_debug ("Opaque-LSA: Now get operational!");
  907. SET_FLAG (top->opaque, OPAQUE_OPERATION_READY_BIT);
  908. }
  909. ospf_opaque_lsa_originate_schedule (nbr->oi, NULL);
  910. }
  911. }
  912. else
  913. if (old_state == NSM_Full && nbr->state != NSM_Full)
  914. {
  915. #ifdef NOTYET
  916. /*
  917. * If no more opaque-capable full-state neighbor remains in the
  918. * flooding scope which corresponds to Opaque-LSA type, periodic
  919. * LS flooding should be stopped.
  920. */
  921. #endif /* NOTYET */
  922. ;
  923. }
  924. funclist = ospf_opaque_wildcard_funclist;
  925. opaque_lsa_nsm_change_callback (funclist, nbr, old_state);
  926. funclist = ospf_opaque_type9_funclist;
  927. opaque_lsa_nsm_change_callback (funclist, nbr, old_state);
  928. funclist = ospf_opaque_type10_funclist;
  929. opaque_lsa_nsm_change_callback (funclist, nbr, old_state);
  930. funclist = ospf_opaque_type11_funclist;
  931. opaque_lsa_nsm_change_callback (funclist, nbr, old_state);
  932. out:
  933. return;
  934. }
  935. void
  936. ospf_opaque_config_write_router (struct vty *vty, struct ospf *ospf)
  937. {
  938. struct list *funclist;
  939. if (CHECK_FLAG (ospf->config, OSPF_OPAQUE_CAPABLE))
  940. vty_out (vty, " capability opaque%s", VTY_NEWLINE);
  941. funclist = ospf_opaque_wildcard_funclist;
  942. opaque_lsa_config_write_router_callback (funclist, vty);
  943. funclist = ospf_opaque_type9_funclist;
  944. opaque_lsa_config_write_router_callback (funclist, vty);
  945. funclist = ospf_opaque_type10_funclist;
  946. opaque_lsa_config_write_router_callback (funclist, vty);
  947. funclist = ospf_opaque_type11_funclist;
  948. opaque_lsa_config_write_router_callback (funclist, vty);
  949. return;
  950. }
  951. void
  952. ospf_opaque_config_write_if (struct vty *vty, struct interface *ifp)
  953. {
  954. struct list *funclist;
  955. funclist = ospf_opaque_wildcard_funclist;
  956. opaque_lsa_config_write_if_callback (funclist, vty, ifp);
  957. funclist = ospf_opaque_type9_funclist;
  958. opaque_lsa_config_write_if_callback (funclist, vty, ifp);
  959. funclist = ospf_opaque_type10_funclist;
  960. opaque_lsa_config_write_if_callback (funclist, vty, ifp);
  961. funclist = ospf_opaque_type11_funclist;
  962. opaque_lsa_config_write_if_callback (funclist, vty, ifp);
  963. return;
  964. }
  965. void
  966. ospf_opaque_config_write_debug (struct vty *vty)
  967. {
  968. struct list *funclist;
  969. funclist = ospf_opaque_wildcard_funclist;
  970. opaque_lsa_config_write_debug_callback (funclist, vty);
  971. funclist = ospf_opaque_type9_funclist;
  972. opaque_lsa_config_write_debug_callback (funclist, vty);
  973. funclist = ospf_opaque_type10_funclist;
  974. opaque_lsa_config_write_debug_callback (funclist, vty);
  975. funclist = ospf_opaque_type11_funclist;
  976. opaque_lsa_config_write_debug_callback (funclist, vty);
  977. return;
  978. }
  979. void
  980. show_opaque_info_detail (struct vty *vty, struct ospf_lsa *lsa)
  981. {
  982. struct lsa_header *lsah = (struct lsa_header *) lsa->data;
  983. u_int32_t lsid = ntohl (lsah->id.s_addr);
  984. u_char opaque_type = GET_OPAQUE_TYPE (lsid);
  985. u_int32_t opaque_id = GET_OPAQUE_ID (lsid);
  986. struct ospf_opaque_functab *functab;
  987. /* Switch output functionality by vty address. */
  988. if (vty != NULL)
  989. {
  990. vty_out (vty, " Opaque-Type %u (%s)%s", opaque_type,
  991. ospf_opaque_type_name (opaque_type), VTY_NEWLINE);
  992. vty_out (vty, " Opaque-ID 0x%x%s", opaque_id, VTY_NEWLINE);
  993. vty_out (vty, " Opaque-Info: %u octets of data%s%s",
  994. ntohs (lsah->length) - OSPF_LSA_HEADER_SIZE,
  995. VALID_OPAQUE_INFO_LEN(lsah) ? "" : "(Invalid length?)",
  996. VTY_NEWLINE);
  997. }
  998. else
  999. {
  1000. zlog_debug (" Opaque-Type %u (%s)", opaque_type,
  1001. ospf_opaque_type_name (opaque_type));
  1002. zlog_debug (" Opaque-ID 0x%x", opaque_id);
  1003. zlog_debug (" Opaque-Info: %u octets of data%s",
  1004. ntohs (lsah->length) - OSPF_LSA_HEADER_SIZE,
  1005. VALID_OPAQUE_INFO_LEN(lsah) ? "" : "(Invalid length?)");
  1006. }
  1007. /* Call individual output functions. */
  1008. if ((functab = ospf_opaque_functab_lookup (lsa)) != NULL)
  1009. if (functab->show_opaque_info != NULL)
  1010. (* functab->show_opaque_info)(vty, lsa);
  1011. return;
  1012. }
  1013. void
  1014. ospf_opaque_lsa_dump (struct stream *s, u_int16_t length)
  1015. {
  1016. struct ospf_lsa lsa;
  1017. lsa.data = (struct lsa_header *) STREAM_PNT (s);
  1018. show_opaque_info_detail (NULL, &lsa);
  1019. return;
  1020. }
  1021. static int
  1022. ospf_opaque_lsa_install_hook (struct ospf_lsa *lsa)
  1023. {
  1024. struct list *funclist;
  1025. int rc = -1;
  1026. /*
  1027. * Some Opaque-LSA user may want to monitor every LSA installation
  1028. * into the LSDB, regardless with target LSA type.
  1029. */
  1030. funclist = ospf_opaque_wildcard_funclist;
  1031. if (new_lsa_callback (funclist, lsa) != 0)
  1032. goto out;
  1033. funclist = ospf_opaque_type9_funclist;
  1034. if (new_lsa_callback (funclist, lsa) != 0)
  1035. goto out;
  1036. funclist = ospf_opaque_type10_funclist;
  1037. if (new_lsa_callback (funclist, lsa) != 0)
  1038. goto out;
  1039. funclist = ospf_opaque_type11_funclist;
  1040. if (new_lsa_callback (funclist, lsa) != 0)
  1041. goto out;
  1042. rc = 0;
  1043. out:
  1044. return rc;
  1045. }
  1046. static int
  1047. ospf_opaque_lsa_delete_hook (struct ospf_lsa *lsa)
  1048. {
  1049. struct list *funclist;
  1050. int rc = -1;
  1051. /*
  1052. * Some Opaque-LSA user may want to monitor every LSA deletion
  1053. * from the LSDB, regardless with target LSA type.
  1054. */
  1055. funclist = ospf_opaque_wildcard_funclist;
  1056. if (del_lsa_callback (funclist, lsa) != 0)
  1057. goto out;
  1058. funclist = ospf_opaque_type9_funclist;
  1059. if (del_lsa_callback (funclist, lsa) != 0)
  1060. goto out;
  1061. funclist = ospf_opaque_type10_funclist;
  1062. if (del_lsa_callback (funclist, lsa) != 0)
  1063. goto out;
  1064. funclist = ospf_opaque_type11_funclist;
  1065. if (del_lsa_callback (funclist, lsa) != 0)
  1066. goto out;
  1067. rc = 0;
  1068. out:
  1069. return rc;
  1070. }
  1071. /*------------------------------------------------------------------------*
  1072. * Followings are Opaque-LSA origination/refresh management functions.
  1073. *------------------------------------------------------------------------*/
  1074. static int ospf_opaque_type9_lsa_originate (struct thread *t);
  1075. static int ospf_opaque_type10_lsa_originate (struct thread *t);
  1076. static int ospf_opaque_type11_lsa_originate (struct thread *t);
  1077. static void ospf_opaque_lsa_reoriginate_resume (struct list *listtop, void *arg);
  1078. void
  1079. ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0)
  1080. {
  1081. struct ospf *top;
  1082. struct ospf_area *area;
  1083. struct listnode *node, *nnode;
  1084. struct opaque_info_per_type *oipt;
  1085. int delay = 0;
  1086. if ((top = oi_to_top (oi)) == NULL || (area = oi->area) == NULL)
  1087. {
  1088. zlog_warn ("ospf_opaque_lsa_originate_schedule: Invalid argument?");
  1089. goto out;
  1090. }
  1091. /* It may not a right time to schedule origination now. */
  1092. if (! CHECK_FLAG (top->opaque, OPAQUE_OPERATION_READY_BIT))
  1093. {
  1094. if (IS_DEBUG_OSPF_EVENT)
  1095. zlog_debug ("ospf_opaque_lsa_originate_schedule: Not operational.");
  1096. goto out; /* This is not an error. */
  1097. }
  1098. if (delay0 != NULL)
  1099. delay = *delay0;
  1100. /*
  1101. * There might be some entries that have been waiting for triggering
  1102. * of per opaque-type re-origination get resumed.
  1103. */
  1104. ospf_opaque_lsa_reoriginate_resume ( oi->opaque_lsa_self, (void *) oi);
  1105. ospf_opaque_lsa_reoriginate_resume (area->opaque_lsa_self, (void *) area);
  1106. ospf_opaque_lsa_reoriginate_resume ( top->opaque_lsa_self, (void *) top);
  1107. /*
  1108. * Now, schedule origination of all Opaque-LSAs per opaque-type.
  1109. */
  1110. if (! list_isempty (ospf_opaque_type9_funclist)
  1111. && list_isempty (oi->opaque_lsa_self)
  1112. && oi->t_opaque_lsa_self == NULL)
  1113. {
  1114. if (IS_DEBUG_OSPF_EVENT)
  1115. zlog_debug ("Schedule Type-9 Opaque-LSA origination in %d ms later.", delay);
  1116. oi->t_opaque_lsa_self =
  1117. thread_add_timer_msec (master, ospf_opaque_type9_lsa_originate, oi, delay);
  1118. delay += top->min_ls_interval;
  1119. }
  1120. if (! list_isempty (ospf_opaque_type10_funclist)
  1121. && list_isempty (area->opaque_lsa_self)
  1122. && area->t_opaque_lsa_self == NULL)
  1123. {
  1124. /*
  1125. * One AREA may contain multiple OIs, but above 2nd and 3rd
  1126. * conditions prevent from scheduling the originate function
  1127. * again and again.
  1128. */
  1129. if (IS_DEBUG_OSPF_EVENT)
  1130. zlog_debug ("Schedule Type-10 Opaque-LSA origination in %d ms later.", delay);
  1131. area->t_opaque_lsa_self =
  1132. thread_add_timer_msec (master, ospf_opaque_type10_lsa_originate,
  1133. area, delay);
  1134. delay += top->min_ls_interval;
  1135. }
  1136. if (! list_isempty (ospf_opaque_type11_funclist)
  1137. && list_isempty (top->opaque_lsa_self)
  1138. && top->t_opaque_lsa_self == NULL)
  1139. {
  1140. /*
  1141. * One OSPF may contain multiple AREAs, but above 2nd and 3rd
  1142. * conditions prevent from scheduling the originate function
  1143. * again and again.
  1144. */
  1145. if (IS_DEBUG_OSPF_EVENT)
  1146. zlog_debug ("Schedule Type-11 Opaque-LSA origination in %d ms later.", delay);
  1147. top->t_opaque_lsa_self =
  1148. thread_add_timer_msec (master, ospf_opaque_type11_lsa_originate,
  1149. top, delay);
  1150. delay += top->min_ls_interval;
  1151. }
  1152. /*
  1153. * Following section treats a special situation that this node's
  1154. * opaque capability has changed as "ON -> OFF -> ON".
  1155. */
  1156. if (! list_isempty (ospf_opaque_type9_funclist)
  1157. && ! list_isempty (oi->opaque_lsa_self))
  1158. {
  1159. for (ALL_LIST_ELEMENTS (oi->opaque_lsa_self, node, nnode, oipt))
  1160. {
  1161. /*
  1162. * removed the test for
  1163. * (! list_isempty (oipt->id_list)) * Handler is already active. *
  1164. * because opaque cababilities ON -> OFF -> ON result in list_isempty (oipt->id_list)
  1165. * not being empty.
  1166. */
  1167. if (oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */
  1168. || oipt->status == PROC_SUSPEND) /* Cannot originate now. */
  1169. continue;
  1170. ospf_opaque_lsa_reoriginate_schedule ((void *) oi,
  1171. OSPF_OPAQUE_LINK_LSA, oipt->opaque_type);
  1172. }
  1173. }
  1174. if (! list_isempty (ospf_opaque_type10_funclist)
  1175. && ! list_isempty (area->opaque_lsa_self))
  1176. {
  1177. for (ALL_LIST_ELEMENTS (area->opaque_lsa_self, node, nnode, oipt))
  1178. {
  1179. /*
  1180. * removed the test for
  1181. * (! list_isempty (oipt->id_list)) * Handler is already active. *
  1182. * because opaque cababilities ON -> OFF -> ON result in list_isempty (oipt->id_list)
  1183. * not being empty.
  1184. */
  1185. if (oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */
  1186. || oipt->status == PROC_SUSPEND) /* Cannot originate now. */
  1187. continue;
  1188. ospf_opaque_lsa_reoriginate_schedule ((void *) area,
  1189. OSPF_OPAQUE_AREA_LSA, oipt->opaque_type);
  1190. }
  1191. }
  1192. if (! list_isempty (ospf_opaque_type11_funclist)
  1193. && ! list_isempty (top->opaque_lsa_self))
  1194. {
  1195. for (ALL_LIST_ELEMENTS (top->opaque_lsa_self, node, nnode, oipt))
  1196. {
  1197. /*
  1198. * removed the test for
  1199. * (! list_isempty (oipt->id_list)) * Handler is already active. *
  1200. * because opaque cababilities ON -> OFF -> ON result in list_isempty (oipt->id_list)
  1201. * not being empty.
  1202. */
  1203. if (oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */
  1204. || oipt->status == PROC_SUSPEND) /* Cannot originate now. */
  1205. continue;
  1206. ospf_opaque_lsa_reoriginate_schedule ((void *) top,
  1207. OSPF_OPAQUE_AS_LSA, oipt->opaque_type);
  1208. }
  1209. }
  1210. if (delay0 != NULL)
  1211. *delay0 = delay;
  1212. out:
  1213. return;
  1214. }
  1215. static int
  1216. ospf_opaque_type9_lsa_originate (struct thread *t)
  1217. {
  1218. struct ospf_interface *oi;
  1219. int rc;
  1220. oi = THREAD_ARG (t);
  1221. oi->t_opaque_lsa_self = NULL;
  1222. if (IS_DEBUG_OSPF_EVENT)
  1223. zlog_debug ("Timer[Type9-LSA]: Originate Opaque-LSAs for OI %s",
  1224. IF_NAME (oi));
  1225. rc = opaque_lsa_originate_callback (ospf_opaque_type9_funclist, oi);
  1226. return rc;
  1227. }
  1228. static int
  1229. ospf_opaque_type10_lsa_originate (struct thread *t)
  1230. {
  1231. struct ospf_area *area;
  1232. int rc;
  1233. area = THREAD_ARG (t);
  1234. area->t_opaque_lsa_self = NULL;
  1235. if (IS_DEBUG_OSPF_EVENT)
  1236. zlog_debug ("Timer[Type10-LSA]: Originate Opaque-LSAs for Area %s",
  1237. inet_ntoa (area->area_id));
  1238. rc = opaque_lsa_originate_callback (ospf_opaque_type10_funclist, area);
  1239. return rc;
  1240. }
  1241. static int
  1242. ospf_opaque_type11_lsa_originate (struct thread *t)
  1243. {
  1244. struct ospf *top;
  1245. int rc;
  1246. top = THREAD_ARG (t);
  1247. top->t_opaque_lsa_self = NULL;
  1248. if (IS_DEBUG_OSPF_EVENT)
  1249. zlog_debug ("Timer[Type11-LSA]: Originate AS-External Opaque-LSAs");
  1250. rc = opaque_lsa_originate_callback (ospf_opaque_type11_funclist, top);
  1251. return rc;
  1252. }
  1253. static void
  1254. ospf_opaque_lsa_reoriginate_resume (struct list *listtop, void *arg)
  1255. {
  1256. struct listnode *node, *nnode;
  1257. struct opaque_info_per_type *oipt;
  1258. struct ospf_opaque_functab *functab;
  1259. if (listtop == NULL)
  1260. goto out;
  1261. /*
  1262. * Pickup oipt entries those which in SUSPEND status, and give
  1263. * them a chance to start re-origination now.
  1264. */
  1265. for (ALL_LIST_ELEMENTS (listtop, node, nnode, oipt))
  1266. {
  1267. if (oipt->status != PROC_SUSPEND)
  1268. continue;
  1269. oipt->status = PROC_NORMAL;
  1270. if ((functab = oipt->functab) == NULL
  1271. || functab->lsa_originator == NULL)
  1272. continue;
  1273. if ((* functab->lsa_originator)(arg) != 0)
  1274. {
  1275. zlog_warn ("ospf_opaque_lsa_reoriginate_resume: Failed (opaque-type=%u)", oipt->opaque_type);
  1276. continue;
  1277. }
  1278. }
  1279. out:
  1280. return;
  1281. }
  1282. struct ospf_lsa *
  1283. ospf_opaque_lsa_install (struct ospf_lsa *lsa, int rt_recalc)
  1284. {
  1285. struct ospf_lsa *new = NULL;
  1286. struct opaque_info_per_type *oipt;
  1287. struct opaque_info_per_id *oipi;
  1288. struct ospf *top;
  1289. /* Don't take "rt_recalc" into consideration for now. *//* XXX */
  1290. if (! IS_LSA_SELF (lsa))
  1291. {
  1292. new = lsa; /* Don't touch this LSA. */
  1293. goto out;
  1294. }
  1295. if (IS_DEBUG_OSPF (lsa, LSA_INSTALL))
  1296. zlog_debug ("Install Type-%u Opaque-LSA: [opaque-type=%u, opaque-id=%x]", lsa->data->type, GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)), GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr)));
  1297. /* Replace the existing lsa with the new one. */
  1298. if ((oipt = lookup_opaque_info_by_type (lsa)) != NULL
  1299. && (oipi = lookup_opaque_info_by_id (oipt, lsa)) != NULL)
  1300. {
  1301. ospf_lsa_unlock (&oipi->lsa);
  1302. oipi->lsa = ospf_lsa_lock (lsa);
  1303. }
  1304. /* Register the new lsa entry and get its control info. */
  1305. else
  1306. if ((oipi = register_opaque_lsa (lsa)) == NULL)
  1307. {
  1308. zlog_warn ("ospf_opaque_lsa_install: register_opaque_lsa() ?");
  1309. goto out;
  1310. }
  1311. /*
  1312. * Make use of a common mechanism (ospf_lsa_refresh_walker)
  1313. * for periodic refresh of self-originated Opaque-LSAs.
  1314. */
  1315. switch (lsa->data->type)
  1316. {
  1317. case OSPF_OPAQUE_LINK_LSA:
  1318. if ((top = oi_to_top (lsa->oi)) == NULL)
  1319. {
  1320. /* Above conditions must have passed. */
  1321. zlog_warn ("ospf_opaque_lsa_install: Sonmething wrong?");
  1322. goto out;
  1323. }
  1324. break;
  1325. case OSPF_OPAQUE_AREA_LSA:
  1326. if (lsa->area == NULL || (top = lsa->area->ospf) == NULL)
  1327. {
  1328. /* Above conditions must have passed. */
  1329. zlog_warn ("ospf_opaque_lsa_install: Sonmething wrong?");
  1330. goto out;
  1331. }
  1332. break;
  1333. case OSPF_OPAQUE_AS_LSA:
  1334. top = ospf_lookup ();
  1335. if (lsa->area != NULL && (top = lsa->area->ospf) == NULL)
  1336. {
  1337. /* Above conditions must have passed. */
  1338. zlog_warn ("ospf_opaque_lsa_install: Sonmething wrong?");
  1339. goto out;
  1340. }
  1341. break;
  1342. default:
  1343. zlog_warn ("ospf_opaque_lsa_install: Unexpected LSA-type(%u)", lsa->data->type);
  1344. goto out;
  1345. }
  1346. ospf_refresher_register_lsa (top, lsa);
  1347. new = lsa;
  1348. out:
  1349. return new;
  1350. }
  1351. struct ospf_lsa *
  1352. ospf_opaque_lsa_refresh (struct ospf_lsa *lsa)
  1353. {
  1354. struct ospf *ospf;
  1355. struct ospf_opaque_functab *functab;
  1356. struct ospf_lsa *new = NULL;
  1357. ospf = ospf_lookup ();
  1358. if ((functab = ospf_opaque_functab_lookup (lsa)) == NULL
  1359. || functab->lsa_refresher == NULL)
  1360. {
  1361. /*
  1362. * Though this LSA seems to have originated on this node, the
  1363. * handling module for this "lsa-type and opaque-type" was
  1364. * already deleted sometime ago.
  1365. * Anyway, this node still has a responsibility to flush this
  1366. * LSA from the routing domain.
  1367. */
  1368. if (IS_DEBUG_OSPF_EVENT)
  1369. zlog_debug ("LSA[Type%d:%s]: Flush stray Opaque-LSA", lsa->data->type, inet_ntoa (lsa->data->id));
  1370. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
  1371. ospf_lsa_flush (ospf, lsa);
  1372. }
  1373. else
  1374. new = (* functab->lsa_refresher)(lsa);
  1375. return new;
  1376. }
  1377. /*------------------------------------------------------------------------*
  1378. * Followings are re-origination/refresh/flush operations of Opaque-LSAs,
  1379. * triggered by external interventions (vty session, signaling, etc).
  1380. *------------------------------------------------------------------------*/
  1381. #define OSPF_OPAQUE_TIMER_ON(T,F,L,V) \
  1382. if (!(T)) \
  1383. (T) = thread_add_timer_msec (master, (F), (L), (V))
  1384. static struct ospf_lsa *pseudo_lsa (struct ospf_interface *oi, struct ospf_area *area, u_char lsa_type, u_char opaque_type);
  1385. static int ospf_opaque_type9_lsa_reoriginate_timer (struct thread *t);
  1386. static int ospf_opaque_type10_lsa_reoriginate_timer (struct thread *t);
  1387. static int ospf_opaque_type11_lsa_reoriginate_timer (struct thread *t);
  1388. static int ospf_opaque_lsa_refresh_timer (struct thread *t);
  1389. void
  1390. ospf_opaque_lsa_reoriginate_schedule (void *lsa_type_dependent,
  1391. u_char lsa_type, u_char opaque_type)
  1392. {
  1393. struct ospf *top;
  1394. struct ospf_area dummy, *area = NULL;
  1395. struct ospf_interface *oi = NULL;
  1396. struct ospf_lsa *lsa;
  1397. struct opaque_info_per_type *oipt;
  1398. int (*func) (struct thread * t) = NULL;
  1399. int delay;
  1400. switch (lsa_type)
  1401. {
  1402. case OSPF_OPAQUE_LINK_LSA:
  1403. if ((oi = (struct ospf_interface *) lsa_type_dependent) == NULL)
  1404. {
  1405. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule:"
  1406. " Type-9 Opaque-LSA: Invalid parameter?");
  1407. goto out;
  1408. }
  1409. if ((top = oi_to_top (oi)) == NULL)
  1410. {
  1411. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule: OI(%s) -> TOP?",
  1412. IF_NAME (oi));
  1413. goto out;
  1414. }
  1415. if (!list_isempty (ospf_opaque_type9_funclist)
  1416. && list_isempty (oi->opaque_lsa_self)
  1417. && oi->t_opaque_lsa_self != NULL)
  1418. {
  1419. zlog_warn ("Type-9 Opaque-LSA (opaque_type=%u):"
  1420. " Common origination for OI(%s) has already started",
  1421. opaque_type, IF_NAME (oi));
  1422. goto out;
  1423. }
  1424. func = ospf_opaque_type9_lsa_reoriginate_timer;
  1425. break;
  1426. case OSPF_OPAQUE_AREA_LSA:
  1427. if ((area = (struct ospf_area *) lsa_type_dependent) == NULL)
  1428. {
  1429. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule:"
  1430. " Type-10 Opaque-LSA: Invalid parameter?");
  1431. goto out;
  1432. }
  1433. if ((top = area->ospf) == NULL)
  1434. {
  1435. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule:"
  1436. " AREA(%s) -> TOP?", inet_ntoa (area->area_id));
  1437. goto out;
  1438. }
  1439. if (!list_isempty (ospf_opaque_type10_funclist)
  1440. && list_isempty (area->opaque_lsa_self)
  1441. && area->t_opaque_lsa_self != NULL)
  1442. {
  1443. zlog_warn ("Type-10 Opaque-LSA (opaque_type=%u):"
  1444. " Common origination for AREA(%s) has already started",
  1445. opaque_type, inet_ntoa (area->area_id));
  1446. goto out;
  1447. }
  1448. func = ospf_opaque_type10_lsa_reoriginate_timer;
  1449. break;
  1450. case OSPF_OPAQUE_AS_LSA:
  1451. if ((top = (struct ospf *) lsa_type_dependent) == NULL)
  1452. {
  1453. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule:"
  1454. " Type-11 Opaque-LSA: Invalid parameter?");
  1455. goto out;
  1456. }
  1457. if (!list_isempty (ospf_opaque_type11_funclist)
  1458. && list_isempty (top->opaque_lsa_self)
  1459. && top->t_opaque_lsa_self != NULL)
  1460. {
  1461. zlog_warn ("Type-11 Opaque-LSA (opaque_type=%u):"
  1462. " Common origination has already started", opaque_type);
  1463. goto out;
  1464. }
  1465. /* Fake "area" to pass "ospf" to a lookup function later. */
  1466. dummy.ospf = top;
  1467. area = &dummy;
  1468. func = ospf_opaque_type11_lsa_reoriginate_timer;
  1469. break;
  1470. default:
  1471. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule:"
  1472. " Unexpected LSA-type(%u)",
  1473. lsa_type);
  1474. goto out;
  1475. }
  1476. /* It may not a right time to schedule reorigination now. */
  1477. if (!CHECK_FLAG (top->opaque, OPAQUE_OPERATION_READY_BIT))
  1478. {
  1479. if (IS_DEBUG_OSPF_EVENT)
  1480. zlog_debug ("ospf_opaque_lsa_reoriginate_schedule: Not operational.");
  1481. goto out; /* This is not an error. */
  1482. }
  1483. /* Generate a dummy lsa to be passed for a lookup function. */
  1484. lsa = pseudo_lsa (oi, area, lsa_type, opaque_type);
  1485. if ((oipt = lookup_opaque_info_by_type (lsa)) == NULL)
  1486. {
  1487. struct ospf_opaque_functab *functab;
  1488. if ((functab = ospf_opaque_functab_lookup (lsa)) == NULL)
  1489. {
  1490. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule:"
  1491. " No associated function?: lsa_type(%u),"
  1492. " opaque_type(%u)",
  1493. lsa_type, opaque_type);
  1494. goto out;
  1495. }
  1496. if ((oipt = register_opaque_info_per_type (functab, lsa)) == NULL)
  1497. {
  1498. zlog_warn ("ospf_opaque_lsa_reoriginate_schedule:"
  1499. " Cannot get a control info?: lsa_type(%u),"
  1500. " opaque_type(%u)",
  1501. lsa_type, opaque_type);
  1502. goto out;
  1503. }
  1504. }
  1505. if (oipt->t_opaque_lsa_self != NULL)
  1506. {
  1507. if (IS_DEBUG_OSPF_EVENT)
  1508. zlog_debug ("Type-%u Opaque-LSA has already scheduled to"
  1509. " RE-ORIGINATE: [opaque-type=%u]",
  1510. lsa_type, GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)));
  1511. goto out;
  1512. }
  1513. /*
  1514. * Different from initial origination time, in which various conditions
  1515. * (opaque capability, neighbor status etc) are assured by caller of
  1516. * the originating function "ospf_opaque_lsa_originate_schedule ()",
  1517. * it is highly possible that these conditions might not be satisfied
  1518. * at the time of re-origination function is to be called.
  1519. */
  1520. delay = top->min_ls_interval; /* XXX */
  1521. if (IS_DEBUG_OSPF_EVENT)
  1522. zlog_debug ("Schedule Type-%u Opaque-LSA to RE-ORIGINATE in %d"
  1523. " ms later: [opaque-type=%u]",
  1524. lsa_type, delay,
  1525. GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)));
  1526. OSPF_OPAQUE_TIMER_ON (oipt->t_opaque_lsa_self, func, oipt, delay);
  1527. out:
  1528. return;
  1529. }
  1530. static struct ospf_lsa *
  1531. pseudo_lsa (struct ospf_interface *oi, struct ospf_area *area,
  1532. u_char lsa_type, u_char opaque_type)
  1533. {
  1534. static struct ospf_lsa lsa = { 0 };
  1535. static struct lsa_header lsah = { 0 };
  1536. u_int32_t tmp;
  1537. lsa.oi = oi;
  1538. lsa.area = area;
  1539. lsa.data = &lsah;
  1540. lsah.type = lsa_type;
  1541. tmp = SET_OPAQUE_LSID (opaque_type, 0); /* Opaque-ID is unused here. */
  1542. lsah.id.s_addr = htonl (tmp);
  1543. return &lsa;
  1544. }
  1545. static int
  1546. ospf_opaque_type9_lsa_reoriginate_timer (struct thread *t)
  1547. {
  1548. struct opaque_info_per_type *oipt;
  1549. struct ospf_opaque_functab *functab;
  1550. struct ospf *top;
  1551. struct ospf_interface *oi;
  1552. int rc = -1;
  1553. oipt = THREAD_ARG (t);
  1554. oipt->t_opaque_lsa_self = NULL;
  1555. if ((functab = oipt->functab) == NULL
  1556. || functab->lsa_originator == NULL)
  1557. {
  1558. zlog_warn ("ospf_opaque_type9_lsa_reoriginate_timer: No associated function?");
  1559. goto out;
  1560. }
  1561. oi = (struct ospf_interface *) oipt->owner;
  1562. if ((top = oi_to_top (oi)) == NULL)
  1563. {
  1564. zlog_warn ("ospf_opaque_type9_lsa_reoriginate_timer: Something wrong?");
  1565. goto out;
  1566. }
  1567. if (! CHECK_FLAG (top->config, OSPF_OPAQUE_CAPABLE)
  1568. || ! ospf_if_is_enable (oi)
  1569. || ospf_nbr_count_opaque_capable (oi) == 0)
  1570. {
  1571. if (IS_DEBUG_OSPF_EVENT)
  1572. zlog_debug ("Suspend re-origination of Type-9 Opaque-LSAs (opaque-type=%u) for a while...", oipt->opaque_type);
  1573. oipt->status = PROC_SUSPEND;
  1574. rc = 0;
  1575. goto out;
  1576. }
  1577. if (IS_DEBUG_OSPF_EVENT)
  1578. zlog_debug ("Timer[Type9-LSA]: Re-originate Opaque-LSAs (opaque-type=%u) for OI (%s)", oipt->opaque_type, IF_NAME (oi));
  1579. rc = (* functab->lsa_originator)(oi);
  1580. out:
  1581. return rc;
  1582. }
  1583. static int
  1584. ospf_opaque_type10_lsa_reoriginate_timer (struct thread *t)
  1585. {
  1586. struct opaque_info_per_type *oipt;
  1587. struct ospf_opaque_functab *functab;
  1588. struct listnode *node, *nnode;
  1589. struct ospf *top;
  1590. struct ospf_area *area;
  1591. struct ospf_interface *oi;
  1592. int n, rc = -1;
  1593. oipt = THREAD_ARG (t);
  1594. oipt->t_opaque_lsa_self = NULL;
  1595. if ((functab = oipt->functab) == NULL
  1596. || functab->lsa_originator == NULL)
  1597. {
  1598. zlog_warn ("ospf_opaque_type10_lsa_reoriginate_timer: No associated function?");
  1599. goto out;
  1600. }
  1601. area = (struct ospf_area *) oipt->owner;
  1602. if (area == NULL || (top = area->ospf) == NULL)
  1603. {
  1604. zlog_warn ("ospf_opaque_type10_lsa_reoriginate_timer: Something wrong?");
  1605. goto out;
  1606. }
  1607. /* There must be at least one "opaque-capable, full-state" neighbor. */
  1608. n = 0;
  1609. for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi))
  1610. {
  1611. if ((n = ospf_nbr_count_opaque_capable (oi)) > 0)
  1612. break;
  1613. }
  1614. if (n == 0 || ! CHECK_FLAG (top->config, OSPF_OPAQUE_CAPABLE))
  1615. {
  1616. if (IS_DEBUG_OSPF_EVENT)
  1617. zlog_debug ("Suspend re-origination of Type-10 Opaque-LSAs"
  1618. " (opaque-type=%u) for a while...",
  1619. oipt->opaque_type);
  1620. oipt->status = PROC_SUSPEND;
  1621. rc = 0;
  1622. goto out;
  1623. }
  1624. if (IS_DEBUG_OSPF_EVENT)
  1625. zlog_debug ("Timer[Type10-LSA]: Re-originate Opaque-LSAs"
  1626. " (opaque-type=%u) for Area %s",
  1627. oipt->opaque_type, inet_ntoa (area->area_id));
  1628. rc = (* functab->lsa_originator)(area);
  1629. out:
  1630. return rc;
  1631. }
  1632. static int
  1633. ospf_opaque_type11_lsa_reoriginate_timer (struct thread *t)
  1634. {
  1635. struct opaque_info_per_type *oipt;
  1636. struct ospf_opaque_functab *functab;
  1637. struct ospf *top;
  1638. int rc = -1;
  1639. oipt = THREAD_ARG (t);
  1640. oipt->t_opaque_lsa_self = NULL;
  1641. if ((functab = oipt->functab) == NULL
  1642. || functab->lsa_originator == NULL)
  1643. {
  1644. zlog_warn ("ospf_opaque_type11_lsa_reoriginate_timer:"
  1645. " No associated function?");
  1646. goto out;
  1647. }
  1648. if ((top = (struct ospf *) oipt->owner) == NULL)
  1649. {
  1650. zlog_warn ("ospf_opaque_type11_lsa_reoriginate_timer: Something wrong?");
  1651. goto out;
  1652. }
  1653. if (! CHECK_FLAG (top->config, OSPF_OPAQUE_CAPABLE))
  1654. {
  1655. if (IS_DEBUG_OSPF_EVENT)
  1656. zlog_debug ("Suspend re-origination of Type-11 Opaque-LSAs (opaque-type=%u) for a while...", oipt->opaque_type);
  1657. oipt->status = PROC_SUSPEND;
  1658. rc = 0;
  1659. goto out;
  1660. }
  1661. if (IS_DEBUG_OSPF_EVENT)
  1662. zlog_debug ("Timer[Type11-LSA]: Re-originate Opaque-LSAs (opaque-type=%u).", oipt->opaque_type);
  1663. rc = (* functab->lsa_originator)(top);
  1664. out:
  1665. return rc;
  1666. }
  1667. void
  1668. ospf_opaque_lsa_refresh_schedule (struct ospf_lsa *lsa0)
  1669. {
  1670. struct opaque_info_per_type *oipt;
  1671. struct opaque_info_per_id *oipi;
  1672. struct ospf_lsa *lsa;
  1673. int delay;
  1674. if ((oipt = lookup_opaque_info_by_type (lsa0)) == NULL
  1675. || (oipi = lookup_opaque_info_by_id (oipt, lsa0)) == NULL)
  1676. {
  1677. zlog_warn ("ospf_opaque_lsa_refresh_schedule: Invalid parameter?");
  1678. goto out;
  1679. }
  1680. /* Given "lsa0" and current "oipi->lsa" may different, but harmless. */
  1681. if ((lsa = oipi->lsa) == NULL)
  1682. {
  1683. zlog_warn ("ospf_opaque_lsa_refresh_schedule: Something wrong?");
  1684. goto out;
  1685. }
  1686. if (oipi->t_opaque_lsa_self != NULL)
  1687. {
  1688. if (IS_DEBUG_OSPF_EVENT)
  1689. zlog_debug ("Type-%u Opaque-LSA has already scheduled to REFRESH: [opaque-type=%u, opaque-id=%x]", lsa->data->type, GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)), GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr)));
  1690. goto out;
  1691. }
  1692. /* Delete this lsa from neighbor retransmit-list. */
  1693. switch (lsa->data->type)
  1694. {
  1695. case OSPF_OPAQUE_LINK_LSA:
  1696. case OSPF_OPAQUE_AREA_LSA:
  1697. ospf_ls_retransmit_delete_nbr_area (lsa->area, lsa);
  1698. break;
  1699. case OSPF_OPAQUE_AS_LSA:
  1700. ospf_ls_retransmit_delete_nbr_as (lsa0->area->ospf, lsa);
  1701. break;
  1702. default:
  1703. zlog_warn ("ospf_opaque_lsa_refresh_schedule: Unexpected LSA-type(%u)", lsa->data->type);
  1704. goto out;
  1705. }
  1706. delay = ospf_lsa_refresh_delay (lsa);
  1707. if (IS_DEBUG_OSPF_EVENT)
  1708. zlog_debug ("Schedule Type-%u Opaque-LSA to REFRESH in %d sec later: [opaque-type=%u, opaque-id=%x]", lsa->data->type, delay, GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)), GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr)));
  1709. OSPF_OPAQUE_TIMER_ON (oipi->t_opaque_lsa_self,
  1710. ospf_opaque_lsa_refresh_timer, oipi, delay * 1000);
  1711. out:
  1712. return;
  1713. }
  1714. static int
  1715. ospf_opaque_lsa_refresh_timer (struct thread *t)
  1716. {
  1717. struct opaque_info_per_id *oipi;
  1718. struct ospf_opaque_functab *functab;
  1719. struct ospf_lsa *lsa;
  1720. if (IS_DEBUG_OSPF_EVENT)
  1721. zlog_debug ("Timer[Opaque-LSA]: (Opaque-LSA Refresh expire)");
  1722. oipi = THREAD_ARG (t);
  1723. oipi->t_opaque_lsa_self = NULL;
  1724. if ((lsa = oipi->lsa) != NULL)
  1725. if ((functab = oipi->opqctl_type->functab) != NULL)
  1726. if (functab->lsa_refresher != NULL)
  1727. (* functab->lsa_refresher)(lsa);
  1728. return 0;
  1729. }
  1730. void
  1731. ospf_opaque_lsa_flush_schedule (struct ospf_lsa *lsa0)
  1732. {
  1733. struct opaque_info_per_type *oipt;
  1734. struct opaque_info_per_id *oipi;
  1735. struct ospf_lsa *lsa;
  1736. if ((oipt = lookup_opaque_info_by_type (lsa0)) == NULL
  1737. || (oipi = lookup_opaque_info_by_id (oipt, lsa0)) == NULL)
  1738. {
  1739. zlog_warn ("ospf_opaque_lsa_flush_schedule: Invalid parameter?");
  1740. goto out;
  1741. }
  1742. /* Given "lsa0" and current "oipi->lsa" may different, but harmless. */
  1743. if ((lsa = oipi->lsa) == NULL)
  1744. {
  1745. zlog_warn ("ospf_opaque_lsa_flush_schedule: Something wrong?");
  1746. goto out;
  1747. }
  1748. /* Delete this lsa from neighbor retransmit-list. */
  1749. switch (lsa->data->type)
  1750. {
  1751. case OSPF_OPAQUE_LINK_LSA:
  1752. case OSPF_OPAQUE_AREA_LSA:
  1753. ospf_ls_retransmit_delete_nbr_area (lsa->area, lsa);
  1754. break;
  1755. case OSPF_OPAQUE_AS_LSA:
  1756. ospf_ls_retransmit_delete_nbr_as (lsa0->area->ospf, lsa);
  1757. break;
  1758. default:
  1759. zlog_warn ("ospf_opaque_lsa_flush_schedule: Unexpected LSA-type(%u)", lsa->data->type);
  1760. goto out;
  1761. }
  1762. /* Dequeue listnode entry from the list. */
  1763. listnode_delete (oipt->id_list, oipi);
  1764. /* Avoid misjudgement in the next lookup. */
  1765. if (listcount (oipt->id_list) == 0)
  1766. oipt->id_list->head = oipt->id_list->tail = NULL;
  1767. /* Disassociate internal control information with the given lsa. */
  1768. free_opaque_info_per_id ((void *) oipi);
  1769. /* Force given lsa's age to MaxAge. */
  1770. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
  1771. if (IS_DEBUG_OSPF_EVENT)
  1772. zlog_debug ("Schedule Type-%u Opaque-LSA to FLUSH: [opaque-type=%u, opaque-id=%x]", lsa->data->type, GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)), GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr)));
  1773. /* This lsa will be flushed and removed eventually. */
  1774. ospf_lsa_flush (lsa0->area->ospf, lsa);
  1775. out:
  1776. return;
  1777. }
  1778. void
  1779. ospf_opaque_self_originated_lsa_received (struct ospf_neighbor *nbr,
  1780. struct ospf_lsa *lsa)
  1781. {
  1782. struct ospf *top;
  1783. if ((top = oi_to_top (nbr->oi)) == NULL)
  1784. return;
  1785. /*
  1786. * Since these LSA entries are not yet installed into corresponding
  1787. * LSDB, just flush them without calling ospf_ls_maxage() afterward.
  1788. */
  1789. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
  1790. switch (lsa->data->type)
  1791. {
  1792. case OSPF_OPAQUE_LINK_LSA:
  1793. ospf_flood_through_area (nbr->oi->area, NULL/*inbr*/, lsa);
  1794. break;
  1795. case OSPF_OPAQUE_AREA_LSA:
  1796. ospf_flood_through_area (nbr->oi->area, NULL/*inbr*/, lsa);
  1797. break;
  1798. case OSPF_OPAQUE_AS_LSA:
  1799. ospf_flood_through_as (top, NULL/*inbr*/, lsa);
  1800. break;
  1801. default:
  1802. zlog_warn ("ospf_opaque_self_originated_lsa_received: Unexpected LSA-type(%u)", lsa->data->type);
  1803. return;
  1804. }
  1805. ospf_lsa_discard (lsa); /* List "lsas" will be deleted by caller. */
  1806. }
  1807. /*------------------------------------------------------------------------*
  1808. * Followings are util functions; probably be used by Opaque-LSAs only...
  1809. *------------------------------------------------------------------------*/
  1810. void
  1811. htonf (float *src, float *dst)
  1812. {
  1813. u_int32_t lu1, lu2;
  1814. memcpy (&lu1, src, sizeof (u_int32_t));
  1815. lu2 = htonl (lu1);
  1816. memcpy (dst, &lu2, sizeof (u_int32_t));
  1817. return;
  1818. }
  1819. void
  1820. ntohf (float *src, float *dst)
  1821. {
  1822. u_int32_t lu1, lu2;
  1823. memcpy (&lu1, src, sizeof (u_int32_t));
  1824. lu2 = ntohl (lu1);
  1825. memcpy (dst, &lu2, sizeof (u_int32_t));
  1826. return;
  1827. }
  1828. struct ospf *
  1829. oi_to_top (struct ospf_interface *oi)
  1830. {
  1831. struct ospf *top = NULL;
  1832. struct ospf_area *area;
  1833. if (oi == NULL || (area = oi->area) == NULL || (top = area->ospf) == NULL)
  1834. zlog_warn ("Broken relationship for \"OI -> AREA -> OSPF\"?");
  1835. return top;
  1836. }