ospf_opaque.c 62 KB

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