isis_lsp.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658
  1. /*
  2. * IS-IS Rout(e)ing protocol - isis_lsp.c
  3. * LSP processing
  4. *
  5. * Copyright (C) 2001,2002 Sampo Saaristo
  6. * Tampere University of Technology
  7. * Institute of Communications Engineering
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public Licenseas published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "linklist.h"
  24. #include "thread.h"
  25. #include "vty.h"
  26. #include "stream.h"
  27. #include "memory.h"
  28. #include "log.h"
  29. #include "prefix.h"
  30. #include "command.h"
  31. #include "hash.h"
  32. #include "if.h"
  33. #include "checksum.h"
  34. #include "md5.h"
  35. #include "isisd/dict.h"
  36. #include "isisd/isis_constants.h"
  37. #include "isisd/isis_common.h"
  38. #include "isisd/isis_flags.h"
  39. #include "isisd/isis_circuit.h"
  40. #include "isisd/isisd.h"
  41. #include "isisd/isis_tlv.h"
  42. #include "isisd/isis_lsp.h"
  43. #include "isisd/isis_pdu.h"
  44. #include "isisd/isis_dynhn.h"
  45. #include "isisd/isis_misc.h"
  46. #include "isisd/isis_csm.h"
  47. #include "isisd/isis_adjacency.h"
  48. #include "isisd/isis_spf.h"
  49. #ifdef TOPOLOGY_GENERATE
  50. #include "spgrid.h"
  51. #endif
  52. /* staticly assigned vars for printing purposes */
  53. char lsp_bits_string[200]; /* FIXME: enough ? */
  54. static int lsp_l1_refresh (struct thread *thread);
  55. static int lsp_l2_refresh (struct thread *thread);
  56. static int lsp_l1_refresh_pseudo (struct thread *thread);
  57. static int lsp_l2_refresh_pseudo (struct thread *thread);
  58. int
  59. lsp_id_cmp (u_char * id1, u_char * id2)
  60. {
  61. return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
  62. }
  63. dict_t *
  64. lsp_db_init (void)
  65. {
  66. dict_t *dict;
  67. dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
  68. return dict;
  69. }
  70. struct isis_lsp *
  71. lsp_search (u_char * id, dict_t * lspdb)
  72. {
  73. dnode_t *node;
  74. #ifdef EXTREME_DEBUG
  75. dnode_t *dn;
  76. zlog_debug ("searching db");
  77. for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
  78. {
  79. zlog_debug ("%s\t%pX", rawlspid_print ((u_char *) dnode_getkey (dn)),
  80. dnode_get (dn));
  81. }
  82. #endif /* EXTREME DEBUG */
  83. node = dict_lookup (lspdb, id);
  84. if (node)
  85. return (struct isis_lsp *) dnode_get (node);
  86. return NULL;
  87. }
  88. static void
  89. lsp_clear_data (struct isis_lsp *lsp)
  90. {
  91. if (!lsp)
  92. return;
  93. if (lsp->tlv_data.hostname)
  94. isis_dynhn_remove (lsp->lsp_header->lsp_id);
  95. if (lsp->own_lsp)
  96. {
  97. if (lsp->tlv_data.nlpids)
  98. XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
  99. if (lsp->tlv_data.hostname)
  100. XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
  101. if (lsp->tlv_data.router_id)
  102. XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.router_id);
  103. }
  104. free_tlvs (&lsp->tlv_data);
  105. }
  106. static void
  107. lsp_destroy (struct isis_lsp *lsp)
  108. {
  109. struct listnode *cnode, *lnode, *lnnode;
  110. struct isis_lsp *lsp_in_list;
  111. struct isis_circuit *circuit;
  112. if (!lsp)
  113. return;
  114. for (ALL_LIST_ELEMENTS_RO (lsp->area->circuit_list, cnode, circuit))
  115. {
  116. if (circuit->lsp_queue == NULL)
  117. continue;
  118. for (ALL_LIST_ELEMENTS (circuit->lsp_queue, lnode, lnnode, lsp_in_list))
  119. if (lsp_in_list == lsp)
  120. list_delete_node(circuit->lsp_queue, lnode);
  121. }
  122. ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags);
  123. ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
  124. lsp_clear_data (lsp);
  125. if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
  126. {
  127. list_delete (lsp->lspu.frags);
  128. lsp->lspu.frags = NULL;
  129. }
  130. isis_spf_schedule (lsp->area, lsp->level);
  131. #ifdef HAVE_IPV6
  132. isis_spf_schedule6 (lsp->area, lsp->level);
  133. #endif
  134. if (lsp->pdu)
  135. stream_free (lsp->pdu);
  136. XFREE (MTYPE_ISIS_LSP, lsp);
  137. }
  138. void
  139. lsp_db_destroy (dict_t * lspdb)
  140. {
  141. dnode_t *dnode, *next;
  142. struct isis_lsp *lsp;
  143. dnode = dict_first (lspdb);
  144. while (dnode)
  145. {
  146. next = dict_next (lspdb, dnode);
  147. lsp = dnode_get (dnode);
  148. lsp_destroy (lsp);
  149. dict_delete_free (lspdb, dnode);
  150. dnode = next;
  151. }
  152. dict_free (lspdb);
  153. return;
  154. }
  155. /*
  156. * Remove all the frags belonging to the given lsp
  157. */
  158. static void
  159. lsp_remove_frags (struct list *frags, dict_t * lspdb)
  160. {
  161. dnode_t *dnode;
  162. struct listnode *lnode, *lnnode;
  163. struct isis_lsp *lsp;
  164. for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
  165. {
  166. dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
  167. lsp_destroy (lsp);
  168. dnode_destroy (dict_delete (lspdb, dnode));
  169. }
  170. list_delete_all_node (frags);
  171. return;
  172. }
  173. void
  174. lsp_search_and_destroy (u_char * id, dict_t * lspdb)
  175. {
  176. dnode_t *node;
  177. struct isis_lsp *lsp;
  178. node = dict_lookup (lspdb, id);
  179. if (node)
  180. {
  181. node = dict_delete (lspdb, node);
  182. lsp = dnode_get (node);
  183. /*
  184. * If this is a zero lsp, remove all the frags now
  185. */
  186. if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
  187. {
  188. if (lsp->lspu.frags)
  189. lsp_remove_frags (lsp->lspu.frags, lspdb);
  190. }
  191. else
  192. {
  193. /*
  194. * else just remove this frag, from the zero lsps' frag list
  195. */
  196. if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
  197. listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
  198. }
  199. lsp_destroy (lsp);
  200. dnode_destroy (node);
  201. }
  202. }
  203. /*
  204. * Compares a LSP to given values
  205. * Params are given in net order
  206. */
  207. int
  208. lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
  209. u_int16_t checksum, u_int16_t rem_lifetime)
  210. {
  211. /* no point in double ntohl on seqnum */
  212. if (lsp->lsp_header->seq_num == seq_num &&
  213. lsp->lsp_header->checksum == checksum &&
  214. /*comparing with 0, no need to do ntohl */
  215. ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
  216. (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
  217. {
  218. if (isis->debugs & DEBUG_SNP_PACKETS)
  219. {
  220. zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
  221. " lifetime %us",
  222. areatag,
  223. rawlspid_print (lsp->lsp_header->lsp_id),
  224. ntohl (lsp->lsp_header->seq_num),
  225. ntohs (lsp->lsp_header->checksum),
  226. ntohs (lsp->lsp_header->rem_lifetime));
  227. zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
  228. " cksum 0x%04x, lifetime %us",
  229. areatag,
  230. ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
  231. }
  232. return LSP_EQUAL;
  233. }
  234. if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
  235. {
  236. if (isis->debugs & DEBUG_SNP_PACKETS)
  237. {
  238. zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
  239. " lifetime %us",
  240. areatag,
  241. rawlspid_print (lsp->lsp_header->lsp_id),
  242. ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
  243. zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
  244. "cksum 0x%04x, lifetime %us",
  245. areatag,
  246. ntohl (lsp->lsp_header->seq_num),
  247. ntohs (lsp->lsp_header->checksum),
  248. ntohs (lsp->lsp_header->rem_lifetime));
  249. }
  250. return LSP_NEWER;
  251. }
  252. if (isis->debugs & DEBUG_SNP_PACKETS)
  253. {
  254. zlog_debug
  255. ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
  256. areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
  257. ntohs (checksum), ntohs (rem_lifetime));
  258. zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
  259. " cksum 0x%04x, lifetime %us", areatag,
  260. ntohl (lsp->lsp_header->seq_num),
  261. ntohs (lsp->lsp_header->checksum),
  262. ntohs (lsp->lsp_header->rem_lifetime));
  263. }
  264. return LSP_OLDER;
  265. }
  266. static void
  267. lsp_auth_add (struct isis_lsp *lsp)
  268. {
  269. struct isis_passwd *passwd;
  270. unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
  271. /*
  272. * Add the authentication info if its present
  273. */
  274. (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
  275. (passwd = &lsp->area->domain_passwd);
  276. switch (passwd->type)
  277. {
  278. /* Cleartext */
  279. case ISIS_PASSWD_TYPE_CLEARTXT:
  280. memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
  281. tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
  282. break;
  283. /* HMAC MD5 */
  284. case ISIS_PASSWD_TYPE_HMAC_MD5:
  285. /* Remember where TLV is written so we can later
  286. * overwrite the MD5 hash */
  287. lsp->auth_tlv_offset = stream_get_endp (lsp->pdu);
  288. memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
  289. lsp->tlv_data.auth_info.type = ISIS_PASSWD_TYPE_HMAC_MD5;
  290. lsp->tlv_data.auth_info.len = ISIS_AUTH_MD5_SIZE;
  291. memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
  292. ISIS_AUTH_MD5_SIZE);
  293. tlv_add_authinfo (passwd->type, ISIS_AUTH_MD5_SIZE, hmac_md5_hash,
  294. lsp->pdu);
  295. break;
  296. default:
  297. break;
  298. }
  299. }
  300. static void
  301. lsp_auth_update (struct isis_lsp *lsp)
  302. {
  303. struct isis_passwd *passwd;
  304. unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
  305. uint16_t checksum, rem_lifetime;
  306. /* For HMAC MD5 we need to recompute the md5 hash and store it */
  307. (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
  308. (passwd = &lsp->area->domain_passwd);
  309. if (passwd->type != ISIS_PASSWD_TYPE_HMAC_MD5)
  310. return;
  311. /*
  312. * In transient conditions (when net is configured where authentication
  313. * config and lsp regenerate schedule is not yet run), there could be
  314. * an own_lsp with auth_tlv_offset set to 0. In such a case, simply
  315. * return, when lsp_regenerate is run, lsp will have auth tlv.
  316. */
  317. if (lsp->auth_tlv_offset == 0)
  318. return;
  319. /*
  320. * RFC 5304 set auth value, checksum and remaining lifetime to zero
  321. * before computation and reset to old values after computation.
  322. */
  323. checksum = lsp->lsp_header->checksum;
  324. rem_lifetime = lsp->lsp_header->rem_lifetime;
  325. lsp->lsp_header->checksum = 0;
  326. lsp->lsp_header->rem_lifetime = 0;
  327. /* Set the authentication value as well to zero */
  328. memset (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
  329. 0, ISIS_AUTH_MD5_SIZE);
  330. /* Compute autentication value */
  331. hmac_md5 (STREAM_DATA (lsp->pdu), stream_get_endp(lsp->pdu),
  332. (unsigned char *) &passwd->passwd, passwd->len,
  333. (unsigned char *) &hmac_md5_hash);
  334. /* Copy the hash into the stream */
  335. memcpy (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
  336. hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
  337. memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
  338. ISIS_AUTH_MD5_SIZE);
  339. /* Copy back the checksum and remaining lifetime */
  340. lsp->lsp_header->checksum = checksum;
  341. lsp->lsp_header->rem_lifetime = rem_lifetime;
  342. }
  343. void
  344. lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
  345. {
  346. u_int32_t newseq;
  347. if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
  348. newseq = ntohl (lsp->lsp_header->seq_num) + 1;
  349. else
  350. newseq = seq_num + 1;
  351. lsp->lsp_header->seq_num = htonl (newseq);
  352. /* Recompute authentication and checksum information */
  353. lsp_auth_update (lsp);
  354. /* ISO 10589 - 7.3.11 Generation of the checksum
  355. * The checksum shall be computed over all fields in the LSP which appear
  356. * after the Remaining Lifetime field. This field (and those appearing
  357. * before it) are excluded so that the LSP may be aged by systems without
  358. * requiring recomputation.
  359. */
  360. fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
  361. ntohs (lsp->lsp_header->pdu_len) - 12, 12);
  362. isis_spf_schedule (lsp->area, lsp->level);
  363. #ifdef HAVE_IPV6
  364. isis_spf_schedule6 (lsp->area, lsp->level);
  365. #endif
  366. return;
  367. }
  368. /*
  369. * Genetates checksum for LSP and its frags
  370. */
  371. static void
  372. lsp_seqnum_update (struct isis_lsp *lsp0)
  373. {
  374. struct isis_lsp *lsp;
  375. struct listnode *node;
  376. lsp_inc_seqnum (lsp0, 0);
  377. if (!lsp0->lspu.frags)
  378. return;
  379. for (ALL_LIST_ELEMENTS_RO (lsp0->lspu.frags, node, lsp))
  380. lsp_inc_seqnum (lsp, 0);
  381. return;
  382. }
  383. static u_int8_t
  384. lsp_bits_generate (int level, int overload_bit, int attached_bit)
  385. {
  386. u_int8_t lsp_bits = 0;
  387. if (level == IS_LEVEL_1)
  388. lsp_bits = IS_LEVEL_1;
  389. else
  390. lsp_bits = IS_LEVEL_1_AND_2;
  391. if (overload_bit)
  392. lsp_bits |= overload_bit;
  393. if (attached_bit)
  394. lsp_bits |= attached_bit;
  395. return lsp_bits;
  396. }
  397. static void
  398. lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
  399. struct isis_area *area, int level)
  400. {
  401. uint32_t expected = 0, found;
  402. int retval;
  403. /* free the old lsp data */
  404. lsp_clear_data (lsp);
  405. /* copying only the relevant part of our stream */
  406. if (lsp->pdu != NULL)
  407. stream_free (lsp->pdu);
  408. lsp->pdu = stream_dup (stream);
  409. /* setting pointers to the correct place */
  410. lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
  411. lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
  412. ISIS_FIXED_HDR_LEN);
  413. lsp->area = area;
  414. lsp->level = level;
  415. lsp->age_out = ZERO_AGE_LIFETIME;
  416. lsp->installed = time (NULL);
  417. /*
  418. * Get LSP data i.e. TLVs
  419. */
  420. expected |= TLVFLAG_AUTH_INFO;
  421. expected |= TLVFLAG_AREA_ADDRS;
  422. expected |= TLVFLAG_IS_NEIGHS;
  423. expected |= TLVFLAG_NLPID;
  424. if (area->dynhostname)
  425. expected |= TLVFLAG_DYN_HOSTNAME;
  426. if (area->newmetric)
  427. {
  428. expected |= TLVFLAG_TE_IS_NEIGHS;
  429. expected |= TLVFLAG_TE_IPV4_REACHABILITY;
  430. expected |= TLVFLAG_TE_ROUTER_ID;
  431. }
  432. expected |= TLVFLAG_IPV4_ADDR;
  433. expected |= TLVFLAG_IPV4_INT_REACHABILITY;
  434. expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
  435. #ifdef HAVE_IPV6
  436. expected |= TLVFLAG_IPV6_ADDR;
  437. expected |= TLVFLAG_IPV6_REACHABILITY;
  438. #endif /* HAVE_IPV6 */
  439. retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
  440. ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
  441. ntohs (lsp->lsp_header->pdu_len) -
  442. ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
  443. &expected, &found, &lsp->tlv_data,
  444. NULL);
  445. if (retval != ISIS_OK)
  446. {
  447. zlog_warn ("Could not parse LSP");
  448. return;
  449. }
  450. if ((found & TLVFLAG_DYN_HOSTNAME) && (area->dynhostname))
  451. {
  452. isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
  453. (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
  454. IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : IS_LEVEL_1);
  455. }
  456. return;
  457. }
  458. void
  459. lsp_update (struct isis_lsp *lsp, struct stream *stream,
  460. struct isis_area *area, int level)
  461. {
  462. dnode_t *dnode = NULL;
  463. /* Remove old LSP from database. This is required since the
  464. * lsp_update_data will free the lsp->pdu (which has the key, lsp_id)
  465. * and will update it with the new data in the stream. */
  466. dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
  467. if (dnode)
  468. dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
  469. /* rebuild the lsp data */
  470. lsp_update_data (lsp, stream, area, level);
  471. /* insert the lsp back into the database */
  472. lsp_insert (lsp, area->lspdb[level - 1]);
  473. }
  474. /* creation of LSP directly from what we received */
  475. struct isis_lsp *
  476. lsp_new_from_stream_ptr (struct stream *stream,
  477. u_int16_t pdu_len, struct isis_lsp *lsp0,
  478. struct isis_area *area, int level)
  479. {
  480. struct isis_lsp *lsp;
  481. lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
  482. lsp_update_data (lsp, stream, area, level);
  483. if (lsp0 == NULL)
  484. {
  485. /*
  486. * zero lsp -> create the list for fragments
  487. */
  488. lsp->lspu.frags = list_new ();
  489. }
  490. else
  491. {
  492. /*
  493. * a fragment -> set the backpointer and add this to zero lsps frag list
  494. */
  495. lsp->lspu.zero_lsp = lsp0;
  496. listnode_add (lsp0->lspu.frags, lsp);
  497. }
  498. return lsp;
  499. }
  500. struct isis_lsp *
  501. lsp_new(struct isis_area *area, u_char * lsp_id,
  502. u_int16_t rem_lifetime, u_int32_t seq_num,
  503. u_int8_t lsp_bits, u_int16_t checksum, int level)
  504. {
  505. struct isis_lsp *lsp;
  506. lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
  507. lsp->area = area;
  508. lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
  509. if (LSP_FRAGMENT (lsp_id) == 0)
  510. lsp->lspu.frags = list_new ();
  511. lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
  512. lsp->lsp_header = (struct isis_link_state_hdr *)
  513. (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
  514. /* at first we fill the FIXED HEADER */
  515. (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
  516. fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
  517. /* now for the LSP HEADER */
  518. /* Minimal LSP PDU size */
  519. lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  520. memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
  521. lsp->lsp_header->checksum = checksum; /* Provided in network order */
  522. lsp->lsp_header->seq_num = htonl (seq_num);
  523. lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
  524. lsp->lsp_header->lsp_bits = lsp_bits;
  525. lsp->level = level;
  526. lsp->age_out = ZERO_AGE_LIFETIME;
  527. stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  528. if (isis->debugs & DEBUG_EVENTS)
  529. zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
  530. sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
  531. LSP_FRAGMENT (lsp->lsp_header->lsp_id),
  532. ntohl (lsp->lsp_header->pdu_len),
  533. ntohl (lsp->lsp_header->seq_num));
  534. return lsp;
  535. }
  536. void
  537. lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
  538. {
  539. dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
  540. if (lsp->lsp_header->seq_num != 0)
  541. {
  542. isis_spf_schedule (lsp->area, lsp->level);
  543. #ifdef HAVE_IPV6
  544. isis_spf_schedule6 (lsp->area, lsp->level);
  545. #endif
  546. }
  547. }
  548. /*
  549. * Build a list of LSPs with non-zero ht bounded by start and stop ids
  550. */
  551. void
  552. lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
  553. struct list *list, dict_t * lspdb)
  554. {
  555. dnode_t *first, *last, *curr;
  556. first = dict_lower_bound (lspdb, start_id);
  557. if (!first)
  558. return;
  559. last = dict_upper_bound (lspdb, stop_id);
  560. curr = first;
  561. if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
  562. listnode_add (list, first->dict_data);
  563. while (curr)
  564. {
  565. curr = dict_next (lspdb, curr);
  566. if (curr &&
  567. ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
  568. listnode_add (list, curr->dict_data);
  569. if (curr == last)
  570. break;
  571. }
  572. return;
  573. }
  574. /*
  575. * Build a list of num_lsps LSPs bounded by start_id and stop_id.
  576. */
  577. void
  578. lsp_build_list (u_char * start_id, u_char * stop_id, u_char num_lsps,
  579. struct list *list, dict_t * lspdb)
  580. {
  581. u_char count;
  582. dnode_t *first, *last, *curr;
  583. first = dict_lower_bound (lspdb, start_id);
  584. if (!first)
  585. return;
  586. last = dict_upper_bound (lspdb, stop_id);
  587. curr = first;
  588. listnode_add (list, first->dict_data);
  589. count = 1;
  590. while (curr)
  591. {
  592. curr = dict_next (lspdb, curr);
  593. if (curr)
  594. {
  595. listnode_add (list, curr->dict_data);
  596. count++;
  597. }
  598. if (count == num_lsps || curr == last)
  599. break;
  600. }
  601. return;
  602. }
  603. /*
  604. * Build a list of LSPs with SSN flag set for the given circuit
  605. */
  606. void
  607. lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps,
  608. struct list *list, dict_t * lspdb)
  609. {
  610. dnode_t *dnode, *next;
  611. struct isis_lsp *lsp;
  612. u_char count = 0;
  613. dnode = dict_first (lspdb);
  614. while (dnode != NULL)
  615. {
  616. next = dict_next (lspdb, dnode);
  617. lsp = dnode_get (dnode);
  618. if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
  619. {
  620. listnode_add (list, lsp);
  621. ++count;
  622. }
  623. if (count == num_lsps)
  624. break;
  625. dnode = next;
  626. }
  627. return;
  628. }
  629. static void
  630. lsp_set_time (struct isis_lsp *lsp)
  631. {
  632. assert (lsp);
  633. if (lsp->lsp_header->rem_lifetime == 0)
  634. {
  635. if (lsp->age_out > 0)
  636. lsp->age_out--;
  637. return;
  638. }
  639. lsp->lsp_header->rem_lifetime =
  640. htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
  641. }
  642. static void
  643. lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
  644. {
  645. struct isis_dynhn *dyn = NULL;
  646. u_char id[SYSID_STRLEN];
  647. if (dynhost)
  648. dyn = dynhn_find_by_id (lsp_id);
  649. else
  650. dyn = NULL;
  651. if (dyn)
  652. sprintf ((char *)id, "%.14s", dyn->name.name);
  653. else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
  654. sprintf ((char *)id, "%.14s", unix_hostname ());
  655. else
  656. memcpy (id, sysid_print (lsp_id), 15);
  657. if (frag)
  658. sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
  659. LSP_FRAGMENT (lsp_id));
  660. else
  661. sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
  662. }
  663. /* Convert the lsp attribute bits to attribute string */
  664. const char *
  665. lsp_bits2string (u_char * lsp_bits)
  666. {
  667. char *pos = lsp_bits_string;
  668. if (!*lsp_bits)
  669. return " none";
  670. /* we only focus on the default metric */
  671. pos += sprintf (pos, "%d/",
  672. ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
  673. pos += sprintf (pos, "%d/",
  674. ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
  675. pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
  676. *(pos) = '\0';
  677. return lsp_bits_string;
  678. }
  679. /* this function prints the lsp on show isis database */
  680. void
  681. lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost)
  682. {
  683. u_char LSPid[255];
  684. char age_out[8];
  685. lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
  686. vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
  687. vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len));
  688. vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
  689. vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
  690. if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
  691. {
  692. snprintf (age_out, 8, "(%u)", lsp->age_out);
  693. age_out[7] = '\0';
  694. vty_out (vty, "%7s ", age_out);
  695. }
  696. else
  697. vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime));
  698. vty_out (vty, "%s%s",
  699. lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
  700. }
  701. void
  702. lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost)
  703. {
  704. struct area_addr *area_addr;
  705. int i;
  706. struct listnode *lnode;
  707. struct is_neigh *is_neigh;
  708. struct te_is_neigh *te_is_neigh;
  709. struct ipv4_reachability *ipv4_reach;
  710. struct in_addr *ipv4_addr;
  711. struct te_ipv4_reachability *te_ipv4_reach;
  712. #ifdef HAVE_IPV6
  713. struct ipv6_reachability *ipv6_reach;
  714. struct in6_addr in6;
  715. u_char buff[BUFSIZ];
  716. #endif
  717. u_char LSPid[255];
  718. u_char hostname[255];
  719. u_char ipv4_reach_prefix[20];
  720. u_char ipv4_reach_mask[20];
  721. u_char ipv4_address[20];
  722. lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
  723. lsp_print (lsp, vty, dynhost);
  724. /* for all area address */
  725. if (lsp->tlv_data.area_addrs)
  726. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
  727. {
  728. vty_out (vty, " Area Address: %s%s",
  729. isonet_print (area_addr->area_addr, area_addr->addr_len),
  730. VTY_NEWLINE);
  731. }
  732. /* for the nlpid tlv */
  733. if (lsp->tlv_data.nlpids)
  734. {
  735. for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
  736. {
  737. switch (lsp->tlv_data.nlpids->nlpids[i])
  738. {
  739. case NLPID_IP:
  740. case NLPID_IPV6:
  741. vty_out (vty, " NLPID : 0x%X%s",
  742. lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
  743. break;
  744. default:
  745. vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE);
  746. break;
  747. }
  748. }
  749. }
  750. /* for the hostname tlv */
  751. if (lsp->tlv_data.hostname)
  752. {
  753. bzero (hostname, sizeof (hostname));
  754. memcpy (hostname, lsp->tlv_data.hostname->name,
  755. lsp->tlv_data.hostname->namelen);
  756. vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE);
  757. }
  758. /* authentication tlv */
  759. if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED)
  760. {
  761. if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5)
  762. vty_out (vty, " Auth type : md5%s", VTY_NEWLINE);
  763. else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT)
  764. vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE);
  765. }
  766. /* TE router id */
  767. if (lsp->tlv_data.router_id)
  768. {
  769. memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
  770. sizeof (ipv4_address));
  771. vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE);
  772. }
  773. if (lsp->tlv_data.ipv4_addrs)
  774. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
  775. {
  776. memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
  777. vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE);
  778. }
  779. /* for the IS neighbor tlv */
  780. if (lsp->tlv_data.is_neighs)
  781. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
  782. {
  783. lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
  784. vty_out (vty, " Metric : %-8d IS : %s%s",
  785. is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
  786. }
  787. /* for the internal reachable tlv */
  788. if (lsp->tlv_data.ipv4_int_reachs)
  789. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
  790. ipv4_reach))
  791. {
  792. memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
  793. sizeof (ipv4_reach_prefix));
  794. memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
  795. sizeof (ipv4_reach_mask));
  796. vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s",
  797. ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
  798. ipv4_reach_mask, VTY_NEWLINE);
  799. }
  800. /* for the external reachable tlv */
  801. if (lsp->tlv_data.ipv4_ext_reachs)
  802. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
  803. ipv4_reach))
  804. {
  805. memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
  806. sizeof (ipv4_reach_prefix));
  807. memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
  808. sizeof (ipv4_reach_mask));
  809. vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s",
  810. ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
  811. ipv4_reach_mask, VTY_NEWLINE);
  812. }
  813. /* IPv6 tlv */
  814. #ifdef HAVE_IPV6
  815. if (lsp->tlv_data.ipv6_reachs)
  816. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
  817. {
  818. memset (&in6, 0, sizeof (in6));
  819. memcpy (in6.s6_addr, ipv6_reach->prefix,
  820. PSIZE (ipv6_reach->prefix_len));
  821. inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
  822. if ((ipv6_reach->control_info &
  823. CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
  824. vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s",
  825. ntohl (ipv6_reach->metric),
  826. buff, ipv6_reach->prefix_len, VTY_NEWLINE);
  827. else
  828. vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s",
  829. ntohl (ipv6_reach->metric),
  830. buff, ipv6_reach->prefix_len, VTY_NEWLINE);
  831. }
  832. #endif
  833. /* TE IS neighbor tlv */
  834. if (lsp->tlv_data.te_is_neighs)
  835. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
  836. {
  837. lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
  838. vty_out (vty, " Metric : %-8d IS-Extended : %s%s",
  839. GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE);
  840. }
  841. /* TE IPv4 tlv */
  842. if (lsp->tlv_data.te_ipv4_reachs)
  843. for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
  844. te_ipv4_reach))
  845. {
  846. /* FIXME: There should be better way to output this stuff. */
  847. vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s",
  848. ntohl (te_ipv4_reach->te_metric),
  849. inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
  850. te_ipv4_reach->control)),
  851. te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
  852. }
  853. vty_out (vty, "%s", VTY_NEWLINE);
  854. return;
  855. }
  856. /* print all the lsps info in the local lspdb */
  857. int
  858. lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
  859. {
  860. dnode_t *node = dict_first (lspdb), *next;
  861. int lsp_count = 0;
  862. if (detail == ISIS_UI_LEVEL_BRIEF)
  863. {
  864. while (node != NULL)
  865. {
  866. /* I think it is unnecessary, so I comment it out */
  867. /* dict_contains (lspdb, node); */
  868. next = dict_next (lspdb, node);
  869. lsp_print (dnode_get (node), vty, dynhost);
  870. node = next;
  871. lsp_count++;
  872. }
  873. }
  874. else if (detail == ISIS_UI_LEVEL_DETAIL)
  875. {
  876. while (node != NULL)
  877. {
  878. next = dict_next (lspdb, node);
  879. lsp_print_detail (dnode_get (node), vty, dynhost);
  880. node = next;
  881. lsp_count++;
  882. }
  883. }
  884. return lsp_count;
  885. }
  886. #define FRAG_THOLD(S,T) \
  887. ((STREAM_SIZE(S)*T)/100)
  888. /* stream*, area->lsp_frag_threshold, increment */
  889. #define FRAG_NEEDED(S,T,I) \
  890. (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
  891. /* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
  892. * variable length (TE TLVs, sub TLVs). */
  893. static void
  894. lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
  895. int tlvsize, int frag_thold,
  896. int tlv_build_func (struct list *, struct stream *))
  897. {
  898. int count, i;
  899. /* can we fit all ? */
  900. if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
  901. {
  902. tlv_build_func (*from, lsp->pdu);
  903. if (listcount (*to) != 0)
  904. {
  905. struct listnode *node, *nextnode;
  906. void *elem;
  907. for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
  908. {
  909. listnode_add (*to, elem);
  910. list_delete_node (*from, node);
  911. }
  912. }
  913. else
  914. {
  915. list_free (*to);
  916. *to = *from;
  917. *from = NULL;
  918. }
  919. }
  920. else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
  921. {
  922. /* fit all we can */
  923. count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
  924. (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
  925. count = count / tlvsize;
  926. if (count > (int)listcount (*from))
  927. count = listcount (*from);
  928. for (i = 0; i < count; i++)
  929. {
  930. listnode_add (*to, listgetdata (listhead (*from)));
  931. listnode_delete (*from, listgetdata (listhead (*from)));
  932. }
  933. tlv_build_func (*to, lsp->pdu);
  934. }
  935. lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
  936. return;
  937. }
  938. static u_int16_t
  939. lsp_rem_lifetime (struct isis_area *area, int level)
  940. {
  941. u_int16_t rem_lifetime;
  942. /* Add jitter to configured LSP lifetime */
  943. rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1],
  944. MAX_AGE_JITTER);
  945. /* No jitter if the max refresh will be less than configure gen interval */
  946. if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
  947. rem_lifetime = area->max_lsp_lifetime[level - 1];
  948. return rem_lifetime;
  949. }
  950. static u_int16_t
  951. lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
  952. {
  953. struct isis_area *area = lsp->area;
  954. int level = lsp->level;
  955. u_int16_t refresh_time;
  956. /* Add jitter to LSP refresh time */
  957. refresh_time = isis_jitter (area->lsp_refresh[level - 1],
  958. MAX_LSP_GEN_JITTER);
  959. /* RFC 4444 : make sure the refresh time is at least less than 300
  960. * of the remaining lifetime and more than gen interval */
  961. if (refresh_time <= area->lsp_gen_interval[level - 1] ||
  962. refresh_time > (rem_lifetime - 300))
  963. refresh_time = rem_lifetime - 300;
  964. assert (area->lsp_gen_interval[level - 1] < refresh_time);
  965. return refresh_time;
  966. }
  967. static struct isis_lsp *
  968. lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
  969. int level)
  970. {
  971. struct isis_lsp *lsp;
  972. u_char frag_id[ISIS_SYS_ID_LEN + 2];
  973. memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
  974. LSP_FRAGMENT (frag_id) = frag_num;
  975. /* FIXME add authentication TLV for fragment LSPs */
  976. lsp = lsp_search (frag_id, area->lspdb[level - 1]);
  977. if (lsp)
  978. {
  979. /* Clear the TLVs */
  980. lsp_clear_data (lsp);
  981. return lsp;
  982. }
  983. lsp = lsp_new (area, frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
  984. lsp_bits_generate (level, area->overload_bit,
  985. area->attached_bit), 0, level);
  986. lsp->area = area;
  987. lsp->own_lsp = 1;
  988. lsp_insert (lsp, area->lspdb[level - 1]);
  989. listnode_add (lsp0->lspu.frags, lsp);
  990. lsp->lspu.zero_lsp = lsp0;
  991. return lsp;
  992. }
  993. /*
  994. * Builds the LSP data part. This func creates a new frag whenever
  995. * area->lsp_frag_threshold is exceeded.
  996. */
  997. static void
  998. lsp_build (struct isis_lsp *lsp, struct isis_area *area)
  999. {
  1000. struct is_neigh *is_neigh;
  1001. struct te_is_neigh *te_is_neigh;
  1002. struct listnode *node, *ipnode;
  1003. int level = lsp->level;
  1004. struct isis_circuit *circuit;
  1005. struct prefix_ipv4 *ipv4;
  1006. struct ipv4_reachability *ipreach;
  1007. struct te_ipv4_reachability *te_ipreach;
  1008. struct isis_adjacency *nei;
  1009. #ifdef HAVE_IPV6
  1010. struct prefix_ipv6 *ipv6, *ip6prefix;
  1011. struct ipv6_reachability *ip6reach;
  1012. #endif /* HAVE_IPV6 */
  1013. struct tlvs tlv_data;
  1014. struct isis_lsp *lsp0 = lsp;
  1015. struct in_addr *routerid;
  1016. uint32_t expected = 0, found = 0;
  1017. uint32_t metric;
  1018. u_char zero_id[ISIS_SYS_ID_LEN + 1];
  1019. int retval = ISIS_OK;
  1020. /*
  1021. * Building the zero lsp
  1022. */
  1023. memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
  1024. /* Reset stream endp. Stream is always there and on every LSP refresh only
  1025. * TLV part of it is overwritten. So we must seek past header we will not
  1026. * touch. */
  1027. stream_reset (lsp->pdu);
  1028. stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  1029. /*
  1030. * Add the authentication info if its present
  1031. */
  1032. lsp_auth_add (lsp);
  1033. /*
  1034. * First add the tlvs related to area
  1035. */
  1036. /* Area addresses */
  1037. if (lsp->tlv_data.area_addrs == NULL)
  1038. lsp->tlv_data.area_addrs = list_new ();
  1039. list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
  1040. if (listcount (lsp->tlv_data.area_addrs) > 0)
  1041. tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
  1042. /* Protocols Supported */
  1043. if (area->ip_circuits > 0
  1044. #ifdef HAVE_IPV6
  1045. || area->ipv6_circuits > 0
  1046. #endif /* HAVE_IPV6 */
  1047. )
  1048. {
  1049. lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
  1050. lsp->tlv_data.nlpids->count = 0;
  1051. if (area->ip_circuits > 0)
  1052. {
  1053. lsp->tlv_data.nlpids->count++;
  1054. lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
  1055. }
  1056. #ifdef HAVE_IPV6
  1057. if (area->ipv6_circuits > 0)
  1058. {
  1059. lsp->tlv_data.nlpids->count++;
  1060. lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
  1061. NLPID_IPV6;
  1062. }
  1063. #endif /* HAVE_IPV6 */
  1064. tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
  1065. }
  1066. /* Dynamic Hostname */
  1067. if (area->dynhostname)
  1068. {
  1069. const char *hostname = unix_hostname();
  1070. size_t hostname_len = strlen(hostname);
  1071. lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
  1072. sizeof (struct hostname));
  1073. strncpy((char *)lsp->tlv_data.hostname->name, hostname,
  1074. sizeof(lsp->tlv_data.hostname->name));
  1075. if (hostname_len <= MAX_TLV_LEN)
  1076. lsp->tlv_data.hostname->namelen = hostname_len;
  1077. else
  1078. lsp->tlv_data.hostname->namelen = MAX_TLV_LEN;
  1079. tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
  1080. }
  1081. /* IPv4 address and TE router ID TLVs. In case of the first one we don't
  1082. * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
  1083. * LSP and this address is same as router id. */
  1084. if (isis->router_id != 0)
  1085. {
  1086. if (lsp->tlv_data.ipv4_addrs == NULL)
  1087. {
  1088. lsp->tlv_data.ipv4_addrs = list_new ();
  1089. lsp->tlv_data.ipv4_addrs->del = free_tlv;
  1090. }
  1091. routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
  1092. routerid->s_addr = isis->router_id;
  1093. listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
  1094. tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
  1095. /* Exactly same data is put into TE router ID TLV, but only if new style
  1096. * TLV's are in use. */
  1097. if (area->newmetric)
  1098. {
  1099. lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
  1100. sizeof (struct in_addr));
  1101. lsp->tlv_data.router_id->id.s_addr = isis->router_id;
  1102. tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
  1103. TE_ROUTER_ID);
  1104. }
  1105. }
  1106. memset (&tlv_data, 0, sizeof (struct tlvs));
  1107. #ifdef TOPOLOGY_GENERATE
  1108. /* If topology exists (and we create topology for level 1 only), create
  1109. * (hardcoded) link to topology. */
  1110. if (area->topology && level == IS_LEVEL_1)
  1111. {
  1112. if (tlv_data.is_neighs == NULL)
  1113. {
  1114. tlv_data.is_neighs = list_new ();
  1115. tlv_data.is_neighs->del = free_tlv;
  1116. }
  1117. is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  1118. memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
  1119. is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
  1120. is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
  1121. is_neigh->metrics.metric_default = 0x01;
  1122. is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
  1123. is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
  1124. is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
  1125. listnode_add (tlv_data.is_neighs, is_neigh);
  1126. }
  1127. #endif /* TOPOLOGY_GENERATE */
  1128. /*
  1129. * Then build lists of tlvs related to circuits
  1130. */
  1131. for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
  1132. {
  1133. if (circuit->state != C_STATE_UP)
  1134. continue;
  1135. /*
  1136. * Add IPv4 internal reachability of this circuit
  1137. */
  1138. if (circuit->ip_router && circuit->ip_addrs &&
  1139. circuit->ip_addrs->count > 0)
  1140. {
  1141. if (area->oldmetric)
  1142. {
  1143. if (tlv_data.ipv4_int_reachs == NULL)
  1144. {
  1145. tlv_data.ipv4_int_reachs = list_new ();
  1146. tlv_data.ipv4_int_reachs->del = free_tlv;
  1147. }
  1148. for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
  1149. {
  1150. ipreach =
  1151. XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
  1152. ipreach->metrics = circuit->metrics[level - 1];
  1153. masklen2ip (ipv4->prefixlen, &ipreach->mask);
  1154. ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
  1155. (ipv4->prefix.s_addr));
  1156. listnode_add (tlv_data.ipv4_int_reachs, ipreach);
  1157. }
  1158. }
  1159. if (area->newmetric)
  1160. {
  1161. if (tlv_data.te_ipv4_reachs == NULL)
  1162. {
  1163. tlv_data.te_ipv4_reachs = list_new ();
  1164. tlv_data.te_ipv4_reachs->del = free_tlv;
  1165. }
  1166. for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
  1167. {
  1168. /* FIXME All this assumes that we have no sub TLVs. */
  1169. te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
  1170. sizeof (struct te_ipv4_reachability) +
  1171. ((ipv4->prefixlen + 7)/8) - 1);
  1172. if (area->oldmetric)
  1173. te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
  1174. else
  1175. te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
  1176. te_ipreach->control = (ipv4->prefixlen & 0x3F);
  1177. memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
  1178. (ipv4->prefixlen + 7)/8);
  1179. listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
  1180. }
  1181. }
  1182. }
  1183. #ifdef HAVE_IPV6
  1184. /*
  1185. * Add IPv6 reachability of this circuit
  1186. */
  1187. if (circuit->ipv6_router && circuit->ipv6_non_link &&
  1188. circuit->ipv6_non_link->count > 0)
  1189. {
  1190. if (tlv_data.ipv6_reachs == NULL)
  1191. {
  1192. tlv_data.ipv6_reachs = list_new ();
  1193. tlv_data.ipv6_reachs->del = free_tlv;
  1194. }
  1195. for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
  1196. {
  1197. ip6reach =
  1198. XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
  1199. if (area->oldmetric)
  1200. ip6reach->metric =
  1201. htonl (circuit->metrics[level - 1].metric_default);
  1202. else
  1203. ip6reach->metric = htonl (circuit->te_metric[level - 1]);
  1204. ip6reach->control_info = 0;
  1205. ip6reach->prefix_len = ipv6->prefixlen;
  1206. memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
  1207. apply_mask_ipv6 (ip6prefix);
  1208. memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
  1209. sizeof (ip6reach->prefix));
  1210. listnode_add (tlv_data.ipv6_reachs, ip6reach);
  1211. }
  1212. }
  1213. #endif /* HAVE_IPV6 */
  1214. switch (circuit->circ_type)
  1215. {
  1216. case CIRCUIT_T_BROADCAST:
  1217. if (level & circuit->is_type)
  1218. {
  1219. if (area->oldmetric)
  1220. {
  1221. if (tlv_data.is_neighs == NULL)
  1222. {
  1223. tlv_data.is_neighs = list_new ();
  1224. tlv_data.is_neighs->del = free_tlv;
  1225. }
  1226. is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  1227. if (level == IS_LEVEL_1)
  1228. memcpy (is_neigh->neigh_id,
  1229. circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
  1230. else
  1231. memcpy (is_neigh->neigh_id,
  1232. circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
  1233. is_neigh->metrics = circuit->metrics[level - 1];
  1234. if (!memcmp (is_neigh->neigh_id, zero_id,
  1235. ISIS_SYS_ID_LEN + 1))
  1236. XFREE (MTYPE_ISIS_TLV, is_neigh);
  1237. else
  1238. listnode_add (tlv_data.is_neighs, is_neigh);
  1239. }
  1240. if (area->newmetric)
  1241. {
  1242. if (tlv_data.te_is_neighs == NULL)
  1243. {
  1244. tlv_data.te_is_neighs = list_new ();
  1245. tlv_data.te_is_neighs->del = free_tlv;
  1246. }
  1247. te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
  1248. sizeof (struct te_is_neigh));
  1249. if (level == IS_LEVEL_1)
  1250. memcpy (te_is_neigh->neigh_id,
  1251. circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
  1252. else
  1253. memcpy (te_is_neigh->neigh_id,
  1254. circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
  1255. if (area->oldmetric)
  1256. metric = circuit->metrics[level - 1].metric_default;
  1257. else
  1258. metric = circuit->te_metric[level - 1];
  1259. SET_TE_METRIC(te_is_neigh, metric);
  1260. if (!memcmp (te_is_neigh->neigh_id, zero_id,
  1261. ISIS_SYS_ID_LEN + 1))
  1262. XFREE (MTYPE_ISIS_TLV, te_is_neigh);
  1263. else
  1264. listnode_add (tlv_data.te_is_neighs, te_is_neigh);
  1265. }
  1266. }
  1267. break;
  1268. case CIRCUIT_T_P2P:
  1269. nei = circuit->u.p2p.neighbor;
  1270. if (nei && (level & nei->circuit_t))
  1271. {
  1272. if (area->oldmetric)
  1273. {
  1274. if (tlv_data.is_neighs == NULL)
  1275. {
  1276. tlv_data.is_neighs = list_new ();
  1277. tlv_data.is_neighs->del = free_tlv;
  1278. }
  1279. is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  1280. memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
  1281. is_neigh->metrics = circuit->metrics[level - 1];
  1282. listnode_add (tlv_data.is_neighs, is_neigh);
  1283. }
  1284. if (area->newmetric)
  1285. {
  1286. uint32_t metric;
  1287. if (tlv_data.te_is_neighs == NULL)
  1288. {
  1289. tlv_data.te_is_neighs = list_new ();
  1290. tlv_data.te_is_neighs->del = free_tlv;
  1291. }
  1292. te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
  1293. sizeof (struct te_is_neigh));
  1294. memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
  1295. metric = circuit->te_metric[level - 1];
  1296. SET_TE_METRIC(te_is_neigh, metric);
  1297. listnode_add (tlv_data.te_is_neighs, te_is_neigh);
  1298. }
  1299. }
  1300. break;
  1301. case CIRCUIT_T_LOOPBACK:
  1302. break;
  1303. default:
  1304. zlog_warn ("lsp_area_create: unknown circuit type");
  1305. }
  1306. }
  1307. while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
  1308. {
  1309. if (lsp->tlv_data.ipv4_int_reachs == NULL)
  1310. lsp->tlv_data.ipv4_int_reachs = list_new ();
  1311. lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
  1312. &lsp->tlv_data.ipv4_int_reachs,
  1313. IPV4_REACH_LEN, area->lsp_frag_threshold,
  1314. tlv_add_ipv4_reachs);
  1315. if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
  1316. lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
  1317. lsp0, area, level);
  1318. }
  1319. /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
  1320. * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
  1321. * TLVs (sub TLVs!). */
  1322. while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
  1323. {
  1324. if (lsp->tlv_data.te_ipv4_reachs == NULL)
  1325. lsp->tlv_data.te_ipv4_reachs = list_new ();
  1326. lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
  1327. &lsp->tlv_data.te_ipv4_reachs,
  1328. TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
  1329. tlv_add_te_ipv4_reachs);
  1330. if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
  1331. lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
  1332. lsp0, area, level);
  1333. }
  1334. #ifdef HAVE_IPV6
  1335. while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
  1336. {
  1337. if (lsp->tlv_data.ipv6_reachs == NULL)
  1338. lsp->tlv_data.ipv6_reachs = list_new ();
  1339. lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
  1340. &lsp->tlv_data.ipv6_reachs,
  1341. IPV6_REACH_LEN, area->lsp_frag_threshold,
  1342. tlv_add_ipv6_reachs);
  1343. if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
  1344. lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
  1345. lsp0, area, level);
  1346. }
  1347. #endif /* HAVE_IPV6 */
  1348. while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
  1349. {
  1350. if (lsp->tlv_data.is_neighs == NULL)
  1351. lsp->tlv_data.is_neighs = list_new ();
  1352. lsp_tlv_fit (lsp, &tlv_data.is_neighs,
  1353. &lsp->tlv_data.is_neighs,
  1354. IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
  1355. tlv_add_is_neighs);
  1356. if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
  1357. lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
  1358. lsp0, area, level);
  1359. }
  1360. while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
  1361. {
  1362. if (lsp->tlv_data.te_is_neighs == NULL)
  1363. lsp->tlv_data.te_is_neighs = list_new ();
  1364. lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
  1365. IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
  1366. tlv_add_te_is_neighs);
  1367. if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
  1368. lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
  1369. lsp0, area, level);
  1370. }
  1371. lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
  1372. free_tlvs (&tlv_data);
  1373. /* Validate the LSP */
  1374. retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
  1375. ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
  1376. stream_get_endp (lsp->pdu) -
  1377. ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
  1378. &expected, &found, &tlv_data, NULL);
  1379. assert (retval == ISIS_OK);
  1380. return;
  1381. }
  1382. /*
  1383. * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
  1384. */
  1385. int
  1386. lsp_generate (struct isis_area *area, int level)
  1387. {
  1388. struct isis_lsp *oldlsp, *newlsp;
  1389. u_int32_t seq_num = 0;
  1390. u_char lspid[ISIS_SYS_ID_LEN + 2];
  1391. u_int16_t rem_lifetime, refresh_time;
  1392. if ((area == NULL) || (area->is_type & level) != level)
  1393. return ISIS_ERROR;
  1394. memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
  1395. memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
  1396. /* only builds the lsp if the area shares the level */
  1397. oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
  1398. if (oldlsp)
  1399. {
  1400. /* FIXME: we should actually initiate a purge */
  1401. seq_num = ntohl (oldlsp->lsp_header->seq_num);
  1402. lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
  1403. area->lspdb[level - 1]);
  1404. }
  1405. rem_lifetime = lsp_rem_lifetime (area, level);
  1406. newlsp = lsp_new (area, lspid, rem_lifetime, seq_num,
  1407. area->is_type | area->overload_bit | area->attached_bit,
  1408. 0, level);
  1409. newlsp->area = area;
  1410. newlsp->own_lsp = 1;
  1411. lsp_insert (newlsp, area->lspdb[level - 1]);
  1412. /* build_lsp_data (newlsp, area); */
  1413. lsp_build (newlsp, area);
  1414. /* time to calculate our checksum */
  1415. lsp_seqnum_update (newlsp);
  1416. lsp_set_all_srmflags (newlsp);
  1417. refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
  1418. THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
  1419. if (level == IS_LEVEL_1)
  1420. THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
  1421. lsp_l1_refresh, area, refresh_time);
  1422. else if (level == IS_LEVEL_2)
  1423. THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
  1424. lsp_l2_refresh, area, refresh_time);
  1425. if (isis->debugs & DEBUG_UPDATE_PACKETS)
  1426. {
  1427. zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
  1428. "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
  1429. area->area_tag, level,
  1430. rawlspid_print (newlsp->lsp_header->lsp_id),
  1431. ntohl (newlsp->lsp_header->pdu_len),
  1432. ntohl (newlsp->lsp_header->seq_num),
  1433. ntohs (newlsp->lsp_header->checksum),
  1434. ntohs (newlsp->lsp_header->rem_lifetime),
  1435. refresh_time);
  1436. }
  1437. return ISIS_OK;
  1438. }
  1439. /*
  1440. * Search own LSPs, update holding time and set SRM
  1441. */
  1442. static int
  1443. lsp_regenerate (struct isis_area *area, int level)
  1444. {
  1445. dict_t *lspdb;
  1446. struct isis_lsp *lsp, *frag;
  1447. struct listnode *node;
  1448. u_char lspid[ISIS_SYS_ID_LEN + 2];
  1449. u_int16_t rem_lifetime, refresh_time;
  1450. if ((area == NULL) || (area->is_type & level) != level)
  1451. return ISIS_ERROR;
  1452. lspdb = area->lspdb[level - 1];
  1453. memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
  1454. memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
  1455. lsp = lsp_search (lspid, lspdb);
  1456. if (!lsp)
  1457. {
  1458. zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
  1459. area->area_tag, level);
  1460. return ISIS_ERROR;
  1461. }
  1462. lsp_clear_data (lsp);
  1463. lsp_build (lsp, area);
  1464. lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
  1465. area->attached_bit);
  1466. rem_lifetime = lsp_rem_lifetime (area, level);
  1467. lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
  1468. lsp_seqnum_update (lsp);
  1469. lsp->last_generated = time (NULL);
  1470. lsp_set_all_srmflags (lsp);
  1471. for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
  1472. {
  1473. frag->lsp_header->lsp_bits = lsp_bits_generate (level,
  1474. area->overload_bit,
  1475. area->attached_bit);
  1476. /* Set the lifetime values of all the fragments to the same value,
  1477. * so that no fragment expires before the lsp is refreshed.
  1478. */
  1479. frag->lsp_header->rem_lifetime = htons (rem_lifetime);
  1480. lsp_set_all_srmflags (frag);
  1481. }
  1482. refresh_time = lsp_refresh_time (lsp, rem_lifetime);
  1483. if (level == IS_LEVEL_1)
  1484. THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
  1485. lsp_l1_refresh, area, refresh_time);
  1486. else if (level == IS_LEVEL_2)
  1487. THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
  1488. lsp_l2_refresh, area, refresh_time);
  1489. if (isis->debugs & DEBUG_UPDATE_PACKETS)
  1490. {
  1491. zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
  1492. "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
  1493. area->area_tag, level,
  1494. rawlspid_print (lsp->lsp_header->lsp_id),
  1495. ntohl (lsp->lsp_header->pdu_len),
  1496. ntohl (lsp->lsp_header->seq_num),
  1497. ntohs (lsp->lsp_header->checksum),
  1498. ntohs (lsp->lsp_header->rem_lifetime),
  1499. refresh_time);
  1500. }
  1501. return ISIS_OK;
  1502. }
  1503. /*
  1504. * Something has changed or periodic refresh -> regenerate LSP
  1505. */
  1506. static int
  1507. lsp_l1_refresh (struct thread *thread)
  1508. {
  1509. struct isis_area *area;
  1510. area = THREAD_ARG (thread);
  1511. assert (area);
  1512. area->t_lsp_refresh[0] = NULL;
  1513. area->lsp_regenerate_pending[0] = 0;
  1514. if ((area->is_type & IS_LEVEL_1) == 0)
  1515. return ISIS_ERROR;
  1516. return lsp_regenerate (area, IS_LEVEL_1);
  1517. }
  1518. static int
  1519. lsp_l2_refresh (struct thread *thread)
  1520. {
  1521. struct isis_area *area;
  1522. area = THREAD_ARG (thread);
  1523. assert (area);
  1524. area->t_lsp_refresh[1] = NULL;
  1525. area->lsp_regenerate_pending[1] = 0;
  1526. if ((area->is_type & IS_LEVEL_2) == 0)
  1527. return ISIS_ERROR;
  1528. return lsp_regenerate (area, IS_LEVEL_2);
  1529. }
  1530. int
  1531. lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
  1532. {
  1533. struct isis_lsp *lsp;
  1534. u_char id[ISIS_SYS_ID_LEN + 2];
  1535. time_t now, diff;
  1536. struct listnode *cnode;
  1537. struct isis_circuit *circuit;
  1538. int lvl;
  1539. if (area == NULL)
  1540. return ISIS_ERROR;
  1541. memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
  1542. LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
  1543. now = time (NULL);
  1544. for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
  1545. {
  1546. if (!((level & lvl) && (area->is_type & lvl)))
  1547. continue;
  1548. if (area->lsp_regenerate_pending[lvl - 1])
  1549. continue;
  1550. lsp = lsp_search (id, area->lspdb[lvl - 1]);
  1551. if (!lsp)
  1552. continue;
  1553. /*
  1554. * Throttle avoidance
  1555. */
  1556. THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
  1557. diff = now - lsp->last_generated;
  1558. if (diff < area->lsp_gen_interval[lvl - 1])
  1559. {
  1560. area->lsp_regenerate_pending[lvl - 1] = 1;
  1561. if (lvl == IS_LEVEL_1)
  1562. THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
  1563. lsp_l1_refresh, area,
  1564. area->lsp_gen_interval[lvl - 1] - diff);
  1565. else if (lvl == IS_LEVEL_2)
  1566. THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
  1567. lsp_l2_refresh, area,
  1568. area->lsp_gen_interval[lvl - 1] - diff);
  1569. }
  1570. else
  1571. {
  1572. /*
  1573. * lsps are not regenerated if lsp_regenerate function is called
  1574. * directly. However if the lsp_regenerate call is queued for
  1575. * later execution it works.
  1576. */
  1577. area->lsp_regenerate_pending[lvl - 1] = 1;
  1578. if (lvl == IS_LEVEL_1)
  1579. THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
  1580. lsp_l1_refresh, area, 0);
  1581. else if (lvl == IS_LEVEL_2)
  1582. THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
  1583. lsp_l2_refresh, area, 0);
  1584. }
  1585. }
  1586. if (all_pseudo)
  1587. {
  1588. for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
  1589. lsp_regenerate_schedule_pseudo (circuit, level);
  1590. }
  1591. return ISIS_OK;
  1592. }
  1593. /*
  1594. * Funcs for pseudonode LSPs
  1595. */
  1596. /*
  1597. * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
  1598. */
  1599. static void
  1600. lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
  1601. int level)
  1602. {
  1603. struct isis_adjacency *adj;
  1604. struct is_neigh *is_neigh;
  1605. struct te_is_neigh *te_is_neigh;
  1606. struct es_neigh *es_neigh;
  1607. struct list *adj_list;
  1608. struct listnode *node;
  1609. lsp->level = level;
  1610. /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
  1611. lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
  1612. circuit->area->attached_bit);
  1613. /*
  1614. * add self to IS neighbours
  1615. */
  1616. if (circuit->area->oldmetric)
  1617. {
  1618. if (lsp->tlv_data.is_neighs == NULL)
  1619. {
  1620. lsp->tlv_data.is_neighs = list_new ();
  1621. lsp->tlv_data.is_neighs->del = free_tlv;
  1622. }
  1623. is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  1624. memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
  1625. listnode_add (lsp->tlv_data.is_neighs, is_neigh);
  1626. }
  1627. if (circuit->area->newmetric)
  1628. {
  1629. if (lsp->tlv_data.te_is_neighs == NULL)
  1630. {
  1631. lsp->tlv_data.te_is_neighs = list_new ();
  1632. lsp->tlv_data.te_is_neighs->del = free_tlv;
  1633. }
  1634. te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
  1635. memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
  1636. listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
  1637. }
  1638. adj_list = list_new ();
  1639. isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
  1640. for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
  1641. {
  1642. if (adj->level & level)
  1643. {
  1644. if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
  1645. (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
  1646. adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
  1647. (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
  1648. {
  1649. /* an IS neighbour -> add it */
  1650. if (circuit->area->oldmetric)
  1651. {
  1652. is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  1653. memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
  1654. listnode_add (lsp->tlv_data.is_neighs, is_neigh);
  1655. }
  1656. if (circuit->area->newmetric)
  1657. {
  1658. te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
  1659. sizeof (struct te_is_neigh));
  1660. memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
  1661. listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
  1662. }
  1663. }
  1664. else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
  1665. {
  1666. /* an ES neigbour add it, if we are building level 1 LSP */
  1667. /* FIXME: the tlv-format is hard to use here */
  1668. if (lsp->tlv_data.es_neighs == NULL)
  1669. {
  1670. lsp->tlv_data.es_neighs = list_new ();
  1671. lsp->tlv_data.es_neighs->del = free_tlv;
  1672. }
  1673. es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
  1674. memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
  1675. listnode_add (lsp->tlv_data.es_neighs, es_neigh);
  1676. }
  1677. }
  1678. }
  1679. list_delete (adj_list);
  1680. /* Reset endp of stream to overwrite only TLV part of it. */
  1681. stream_reset (lsp->pdu);
  1682. stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  1683. /*
  1684. * Add the authentication info if it's present
  1685. */
  1686. lsp_auth_add (lsp);
  1687. if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
  1688. tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
  1689. if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
  1690. tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
  1691. if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
  1692. tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
  1693. lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
  1694. /* Recompute authentication and checksum information */
  1695. lsp_auth_update (lsp);
  1696. fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
  1697. ntohs (lsp->lsp_header->pdu_len) - 12, 12);
  1698. return;
  1699. }
  1700. int
  1701. lsp_generate_pseudo (struct isis_circuit *circuit, int level)
  1702. {
  1703. dict_t *lspdb = circuit->area->lspdb[level - 1];
  1704. struct isis_lsp *lsp;
  1705. u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  1706. u_int16_t rem_lifetime, refresh_time;
  1707. if ((circuit->is_type & level) != level ||
  1708. (circuit->state != C_STATE_UP) ||
  1709. (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
  1710. (circuit->u.bc.is_dr[level - 1] == 0))
  1711. return ISIS_ERROR;
  1712. memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
  1713. LSP_FRAGMENT (lsp_id) = 0;
  1714. LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
  1715. /*
  1716. * If for some reason have a pseudo LSP in the db already -> regenerate
  1717. */
  1718. if (lsp_search (lsp_id, lspdb))
  1719. return lsp_regenerate_schedule_pseudo (circuit, level);
  1720. rem_lifetime = lsp_rem_lifetime (circuit->area, level);
  1721. /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
  1722. lsp = lsp_new (circuit->area, lsp_id, rem_lifetime, 1,
  1723. circuit->area->is_type | circuit->area->attached_bit,
  1724. 0, level);
  1725. lsp->area = circuit->area;
  1726. lsp_build_pseudo (lsp, circuit, level);
  1727. lsp->own_lsp = 1;
  1728. lsp_insert (lsp, lspdb);
  1729. lsp_set_all_srmflags (lsp);
  1730. refresh_time = lsp_refresh_time (lsp, rem_lifetime);
  1731. THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
  1732. circuit->lsp_regenerate_pending[level - 1] = 0;
  1733. if (level == IS_LEVEL_1)
  1734. THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
  1735. lsp_l1_refresh_pseudo, circuit, refresh_time);
  1736. else if (level == IS_LEVEL_2)
  1737. THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
  1738. lsp_l2_refresh_pseudo, circuit, refresh_time);
  1739. if (isis->debugs & DEBUG_UPDATE_PACKETS)
  1740. {
  1741. zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
  1742. "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
  1743. circuit->area->area_tag, level,
  1744. rawlspid_print (lsp->lsp_header->lsp_id),
  1745. ntohl (lsp->lsp_header->pdu_len),
  1746. ntohl (lsp->lsp_header->seq_num),
  1747. ntohs (lsp->lsp_header->checksum),
  1748. ntohs (lsp->lsp_header->rem_lifetime),
  1749. refresh_time);
  1750. }
  1751. return ISIS_OK;
  1752. }
  1753. static int
  1754. lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
  1755. {
  1756. dict_t *lspdb = circuit->area->lspdb[level - 1];
  1757. struct isis_lsp *lsp;
  1758. u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  1759. u_int16_t rem_lifetime, refresh_time;
  1760. if ((circuit->is_type & level) != level ||
  1761. (circuit->state != C_STATE_UP) ||
  1762. (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
  1763. (circuit->u.bc.is_dr[level - 1] == 0))
  1764. return ISIS_ERROR;
  1765. memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
  1766. LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
  1767. LSP_FRAGMENT (lsp_id) = 0;
  1768. lsp = lsp_search (lsp_id, lspdb);
  1769. if (!lsp)
  1770. {
  1771. zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
  1772. level, rawlspid_print (lsp_id));
  1773. return ISIS_ERROR;
  1774. }
  1775. lsp_clear_data (lsp);
  1776. lsp_build_pseudo (lsp, circuit, level);
  1777. /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
  1778. lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
  1779. circuit->area->attached_bit);
  1780. rem_lifetime = lsp_rem_lifetime (circuit->area, level);
  1781. lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
  1782. lsp_inc_seqnum (lsp, 0);
  1783. lsp->last_generated = time (NULL);
  1784. lsp_set_all_srmflags (lsp);
  1785. refresh_time = lsp_refresh_time (lsp, rem_lifetime);
  1786. if (level == IS_LEVEL_1)
  1787. THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
  1788. lsp_l1_refresh_pseudo, circuit, refresh_time);
  1789. else if (level == IS_LEVEL_2)
  1790. THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
  1791. lsp_l2_refresh_pseudo, circuit, refresh_time);
  1792. if (isis->debugs & DEBUG_UPDATE_PACKETS)
  1793. {
  1794. zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
  1795. "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
  1796. circuit->area->area_tag, level,
  1797. rawlspid_print (lsp->lsp_header->lsp_id),
  1798. ntohl (lsp->lsp_header->pdu_len),
  1799. ntohl (lsp->lsp_header->seq_num),
  1800. ntohs (lsp->lsp_header->checksum),
  1801. ntohs (lsp->lsp_header->rem_lifetime),
  1802. refresh_time);
  1803. }
  1804. return ISIS_OK;
  1805. }
  1806. /*
  1807. * Something has changed or periodic refresh -> regenerate pseudo LSP
  1808. */
  1809. static int
  1810. lsp_l1_refresh_pseudo (struct thread *thread)
  1811. {
  1812. struct isis_circuit *circuit;
  1813. u_char id[ISIS_SYS_ID_LEN + 2];
  1814. circuit = THREAD_ARG (thread);
  1815. circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
  1816. circuit->lsp_regenerate_pending[0] = 0;
  1817. if ((circuit->u.bc.is_dr[0] == 0) ||
  1818. (circuit->is_type & IS_LEVEL_1) == 0)
  1819. {
  1820. memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
  1821. LSP_PSEUDO_ID (id) = circuit->circuit_id;
  1822. LSP_FRAGMENT (id) = 0;
  1823. lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
  1824. return ISIS_ERROR;
  1825. }
  1826. return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
  1827. }
  1828. static int
  1829. lsp_l2_refresh_pseudo (struct thread *thread)
  1830. {
  1831. struct isis_circuit *circuit;
  1832. u_char id[ISIS_SYS_ID_LEN + 2];
  1833. circuit = THREAD_ARG (thread);
  1834. circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
  1835. circuit->lsp_regenerate_pending[1] = 0;
  1836. if ((circuit->u.bc.is_dr[1] == 0) ||
  1837. (circuit->is_type & IS_LEVEL_2) == 0)
  1838. {
  1839. memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
  1840. LSP_PSEUDO_ID (id) = circuit->circuit_id;
  1841. LSP_FRAGMENT (id) = 0;
  1842. lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
  1843. return ISIS_ERROR;
  1844. }
  1845. return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
  1846. }
  1847. int
  1848. lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
  1849. {
  1850. struct isis_lsp *lsp;
  1851. u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  1852. time_t now, diff;
  1853. int lvl;
  1854. if (circuit == NULL ||
  1855. circuit->circ_type != CIRCUIT_T_BROADCAST ||
  1856. circuit->state != C_STATE_UP)
  1857. return ISIS_OK;
  1858. memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
  1859. LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
  1860. LSP_FRAGMENT (lsp_id) = 0;
  1861. now = time (NULL);
  1862. for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
  1863. {
  1864. if (!((level & lvl) && (circuit->is_type & lvl)))
  1865. continue;
  1866. if (circuit->u.bc.is_dr[lvl - 1] == 0 ||
  1867. circuit->lsp_regenerate_pending[lvl - 1])
  1868. continue;
  1869. lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
  1870. if (!lsp)
  1871. continue;
  1872. /*
  1873. * Throttle avoidance
  1874. */
  1875. THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
  1876. diff = now - lsp->last_generated;
  1877. if (diff < circuit->area->lsp_gen_interval[lvl - 1])
  1878. {
  1879. circuit->lsp_regenerate_pending[lvl - 1] = 1;
  1880. if (lvl == IS_LEVEL_1)
  1881. THREAD_TIMER_ON (master,
  1882. circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
  1883. lsp_l1_refresh_pseudo, circuit,
  1884. circuit->area->lsp_gen_interval[lvl - 1] - diff);
  1885. else if (lvl == IS_LEVEL_2)
  1886. THREAD_TIMER_ON (master,
  1887. circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
  1888. lsp_l2_refresh_pseudo, circuit,
  1889. circuit->area->lsp_gen_interval[lvl - 1] - diff);
  1890. }
  1891. else
  1892. {
  1893. lsp_regenerate_pseudo (circuit, lvl);
  1894. }
  1895. }
  1896. return ISIS_OK;
  1897. }
  1898. /*
  1899. * Walk through LSPs for an area
  1900. * - set remaining lifetime
  1901. * - set LSPs with SRMflag set for sending
  1902. */
  1903. int
  1904. lsp_tick (struct thread *thread)
  1905. {
  1906. struct isis_area *area;
  1907. struct isis_circuit *circuit;
  1908. struct isis_lsp *lsp;
  1909. struct list *lsp_list;
  1910. struct listnode *lspnode, *cnode;
  1911. dnode_t *dnode, *dnode_next;
  1912. int level;
  1913. u_int16_t rem_lifetime;
  1914. lsp_list = list_new ();
  1915. area = THREAD_ARG (thread);
  1916. assert (area);
  1917. area->t_tick = NULL;
  1918. THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
  1919. /*
  1920. * Build a list of LSPs with (any) SRMflag set
  1921. * and removed the ones that have aged out
  1922. */
  1923. for (level = 0; level < ISIS_LEVELS; level++)
  1924. {
  1925. if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
  1926. {
  1927. for (dnode = dict_first (area->lspdb[level]);
  1928. dnode != NULL; dnode = dnode_next)
  1929. {
  1930. dnode_next = dict_next (area->lspdb[level], dnode);
  1931. lsp = dnode_get (dnode);
  1932. /*
  1933. * The lsp rem_lifetime is kept at 0 for MaxAge or
  1934. * ZeroAgeLifetime depending on explicit purge or
  1935. * natural age out. So schedule spf only once when
  1936. * the first time rem_lifetime becomes 0.
  1937. */
  1938. rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
  1939. lsp_set_time (lsp);
  1940. /*
  1941. * Schedule may run spf which should be done only after
  1942. * the lsp rem_lifetime becomes 0 for the first time.
  1943. * ISO 10589 - 7.3.16.4 first paragraph.
  1944. */
  1945. if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
  1946. {
  1947. /* 7.3.16.4 a) set SRM flags on all */
  1948. lsp_set_all_srmflags (lsp);
  1949. /* 7.3.16.4 b) retain only the header FIXME */
  1950. /* 7.3.16.4 c) record the time to purge FIXME */
  1951. /* run/schedule spf */
  1952. /* isis_spf_schedule is called inside lsp_destroy() below;
  1953. * so it is not needed here. */
  1954. /* isis_spf_schedule (lsp->area, lsp->level); */
  1955. }
  1956. if (lsp->age_out == 0)
  1957. {
  1958. zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
  1959. area->area_tag,
  1960. lsp->level,
  1961. rawlspid_print (lsp->lsp_header->lsp_id),
  1962. ntohl (lsp->lsp_header->seq_num));
  1963. #ifdef TOPOLOGY_GENERATE
  1964. if (lsp->from_topology)
  1965. THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
  1966. #endif /* TOPOLOGY_GENERATE */
  1967. lsp_destroy (lsp);
  1968. lsp = NULL;
  1969. dict_delete_free (area->lspdb[level], dnode);
  1970. }
  1971. else if (flags_any_set (lsp->SRMflags))
  1972. listnode_add (lsp_list, lsp);
  1973. }
  1974. /*
  1975. * Send LSPs on circuits indicated by the SRMflags
  1976. */
  1977. if (listcount (lsp_list) > 0)
  1978. {
  1979. for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
  1980. {
  1981. int diff = time (NULL) - circuit->lsp_queue_last_cleared;
  1982. if (circuit->lsp_queue == NULL ||
  1983. diff < MIN_LSP_TRANS_INTERVAL)
  1984. continue;
  1985. for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
  1986. {
  1987. if (circuit->upadjcount[lsp->level - 1] &&
  1988. ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
  1989. {
  1990. /* Add the lsp only if it is not already in lsp
  1991. * queue */
  1992. if (! listnode_lookup (circuit->lsp_queue, lsp))
  1993. {
  1994. listnode_add (circuit->lsp_queue, lsp);
  1995. thread_add_event (master, send_lsp, circuit, 0);
  1996. }
  1997. }
  1998. }
  1999. }
  2000. list_delete_all_node (lsp_list);
  2001. }
  2002. }
  2003. }
  2004. list_delete (lsp_list);
  2005. return ISIS_OK;
  2006. }
  2007. void
  2008. lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
  2009. {
  2010. struct isis_lsp *lsp;
  2011. u_int16_t seq_num;
  2012. u_int8_t lsp_bits;
  2013. lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
  2014. if (!lsp)
  2015. return;
  2016. /* store old values */
  2017. seq_num = lsp->lsp_header->seq_num;
  2018. lsp_bits = lsp->lsp_header->lsp_bits;
  2019. /* reset stream */
  2020. lsp_clear_data (lsp);
  2021. stream_reset (lsp->pdu);
  2022. /* update header */
  2023. lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  2024. memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
  2025. lsp->lsp_header->checksum = 0;
  2026. lsp->lsp_header->seq_num = seq_num;
  2027. lsp->lsp_header->rem_lifetime = 0;
  2028. lsp->lsp_header->lsp_bits = lsp_bits;
  2029. lsp->level = level;
  2030. lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
  2031. stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  2032. /*
  2033. * Add and update the authentication info if its present
  2034. */
  2035. lsp_auth_add (lsp);
  2036. lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
  2037. lsp_auth_update (lsp);
  2038. fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
  2039. ntohs (lsp->lsp_header->pdu_len) - 12, 12);
  2040. lsp_set_all_srmflags (lsp);
  2041. return;
  2042. }
  2043. /*
  2044. * Purge own LSP that is received and we don't have.
  2045. * -> Do as in 7.3.16.4
  2046. */
  2047. void
  2048. lsp_purge_non_exist (int level,
  2049. struct isis_link_state_hdr *lsp_hdr,
  2050. struct isis_area *area)
  2051. {
  2052. struct isis_lsp *lsp;
  2053. /*
  2054. * We need to create the LSP to be purged
  2055. */
  2056. lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
  2057. lsp->area = area;
  2058. lsp->level = level;
  2059. lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
  2060. lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
  2061. fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
  2062. : L2_LINK_STATE);
  2063. lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
  2064. ISIS_FIXED_HDR_LEN);
  2065. memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
  2066. stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  2067. /*
  2068. * Set the remaining lifetime to 0
  2069. */
  2070. lsp->lsp_header->rem_lifetime = 0;
  2071. /*
  2072. * Add and update the authentication info if its present
  2073. */
  2074. lsp_auth_add (lsp);
  2075. lsp_auth_update (lsp);
  2076. /*
  2077. * Update the PDU length to header plus any authentication TLV.
  2078. */
  2079. lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
  2080. /*
  2081. * Put the lsp into LSPdb
  2082. */
  2083. lsp_insert (lsp, area->lspdb[lsp->level - 1]);
  2084. /*
  2085. * Send in to whole area
  2086. */
  2087. lsp_set_all_srmflags (lsp);
  2088. return;
  2089. }
  2090. void lsp_set_all_srmflags (struct isis_lsp *lsp)
  2091. {
  2092. struct listnode *node;
  2093. struct isis_circuit *circuit;
  2094. assert (lsp);
  2095. ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
  2096. if (lsp->area)
  2097. {
  2098. struct list *circuit_list = lsp->area->circuit_list;
  2099. for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
  2100. {
  2101. ISIS_SET_FLAG(lsp->SRMflags, circuit);
  2102. }
  2103. }
  2104. }
  2105. #ifdef TOPOLOGY_GENERATE
  2106. static int
  2107. top_lsp_refresh (struct thread *thread)
  2108. {
  2109. struct isis_lsp *lsp;
  2110. u_int16_t rem_lifetime;
  2111. lsp = THREAD_ARG (thread);
  2112. assert (lsp);
  2113. lsp->t_lsp_top_ref = NULL;
  2114. lsp_seqnum_update (lsp);
  2115. lsp_set_all_srmflags (lsp);
  2116. if (isis->debugs & DEBUG_UPDATE_PACKETS)
  2117. {
  2118. zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
  2119. rawlspid_print (lsp->lsp_header->lsp_id));
  2120. }
  2121. /* Refresh dynamic hostname in the cache. */
  2122. isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
  2123. IS_LEVEL_1);
  2124. lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
  2125. lsp->area->overload_bit,
  2126. lsp->area->attached_bit);
  2127. rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
  2128. lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
  2129. /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
  2130. THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
  2131. lsp->area->lsp_refresh[0]);
  2132. return ISIS_OK;
  2133. }
  2134. void
  2135. generate_topology_lsps (struct isis_area *area)
  2136. {
  2137. struct listnode *node;
  2138. int i, max = 0;
  2139. struct arc *arc;
  2140. u_char lspid[ISIS_SYS_ID_LEN + 2];
  2141. struct isis_lsp *lsp;
  2142. u_int16_t rem_lifetime, refresh_time;
  2143. /* first we find the maximal node */
  2144. for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
  2145. {
  2146. if (arc->from_node > max)
  2147. max = arc->from_node;
  2148. if (arc->to_node > max)
  2149. max = arc->to_node;
  2150. }
  2151. for (i = 1; i < (max + 1); i++)
  2152. {
  2153. memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
  2154. LSP_PSEUDO_ID (lspid) = 0x00;
  2155. LSP_FRAGMENT (lspid) = 0x00;
  2156. lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
  2157. lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
  2158. rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
  2159. lsp = lsp_new (area, lspid, rem_lifetime, 1,
  2160. IS_LEVEL_1 | area->overload_bit | area->attached_bit,
  2161. 0, 1);
  2162. if (!lsp)
  2163. return;
  2164. lsp->from_topology = 1;
  2165. /* Creating LSP data based on topology info. */
  2166. build_topology_lsp_data (lsp, area, i);
  2167. /* Checksum is also calculated here. */
  2168. lsp_seqnum_update (lsp);
  2169. /* Take care of inserting dynamic hostname into cache. */
  2170. isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
  2171. refresh_time = lsp_refresh_time (lsp, rem_lifetime);
  2172. THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
  2173. refresh_time);
  2174. lsp_set_all_srmflags (lsp);
  2175. lsp_insert (lsp, area->lspdb[0]);
  2176. }
  2177. }
  2178. void
  2179. remove_topology_lsps (struct isis_area *area)
  2180. {
  2181. struct isis_lsp *lsp;
  2182. dnode_t *dnode, *dnode_next;
  2183. dnode = dict_first (area->lspdb[0]);
  2184. while (dnode != NULL)
  2185. {
  2186. dnode_next = dict_next (area->lspdb[0], dnode);
  2187. lsp = dnode_get (dnode);
  2188. if (lsp->from_topology)
  2189. {
  2190. THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
  2191. lsp_destroy (lsp);
  2192. dict_delete (area->lspdb[0], dnode);
  2193. }
  2194. dnode = dnode_next;
  2195. }
  2196. }
  2197. void
  2198. build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
  2199. int lsp_top_num)
  2200. {
  2201. struct listnode *node;
  2202. struct arc *arc;
  2203. struct is_neigh *is_neigh;
  2204. struct te_is_neigh *te_is_neigh;
  2205. char buff[200];
  2206. struct tlvs tlv_data;
  2207. struct isis_lsp *lsp0 = lsp;
  2208. /* Add area addresses. FIXME: Is it needed at all? */
  2209. if (lsp->tlv_data.area_addrs == NULL)
  2210. lsp->tlv_data.area_addrs = list_new ();
  2211. list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
  2212. if (lsp->tlv_data.nlpids == NULL)
  2213. lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
  2214. lsp->tlv_data.nlpids->count = 1;
  2215. lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
  2216. if (area->dynhostname)
  2217. {
  2218. lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
  2219. sizeof (struct hostname));
  2220. memset (buff, 0x00, 200);
  2221. sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
  2222. "feedme", lsp_top_num);
  2223. memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
  2224. lsp->tlv_data.hostname->namelen = strlen (buff);
  2225. }
  2226. if (lsp->tlv_data.nlpids)
  2227. tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
  2228. if (lsp->tlv_data.hostname)
  2229. tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
  2230. if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
  2231. tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
  2232. memset (&tlv_data, 0, sizeof (struct tlvs));
  2233. if (tlv_data.is_neighs == NULL)
  2234. {
  2235. tlv_data.is_neighs = list_new ();
  2236. tlv_data.is_neighs->del = free_tlv;
  2237. }
  2238. /* Add reachability for this IS for simulated 1. */
  2239. if (lsp_top_num == 1)
  2240. {
  2241. is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  2242. memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
  2243. LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
  2244. /* Metric MUST NOT be 0, unless it's not alias TLV. */
  2245. is_neigh->metrics.metric_default = 0x01;
  2246. is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
  2247. is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
  2248. is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
  2249. listnode_add (tlv_data.is_neighs, is_neigh);
  2250. }
  2251. /* Add IS reachabilities. */
  2252. for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
  2253. {
  2254. int to_lsp = 0;
  2255. if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
  2256. continue;
  2257. if (lsp_top_num == arc->from_node)
  2258. to_lsp = arc->to_node;
  2259. else
  2260. to_lsp = arc->from_node;
  2261. if (area->oldmetric)
  2262. {
  2263. is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  2264. memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
  2265. is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
  2266. is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
  2267. is_neigh->metrics.metric_default = arc->distance;
  2268. is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
  2269. is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
  2270. is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
  2271. listnode_add (tlv_data.is_neighs, is_neigh);
  2272. }
  2273. if (area->newmetric)
  2274. {
  2275. if (tlv_data.te_is_neighs == NULL)
  2276. {
  2277. tlv_data.te_is_neighs = list_new ();
  2278. tlv_data.te_is_neighs->del = free_tlv;
  2279. }
  2280. te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
  2281. memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
  2282. ISIS_SYS_ID_LEN);
  2283. te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
  2284. te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
  2285. SET_TE_METRIC(te_is_neigh, arc->distance);
  2286. listnode_add (tlv_data.te_is_neighs, te_is_neigh);
  2287. }
  2288. }
  2289. while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
  2290. {
  2291. if (lsp->tlv_data.is_neighs == NULL)
  2292. lsp->tlv_data.is_neighs = list_new ();
  2293. lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
  2294. IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
  2295. tlv_add_is_neighs);
  2296. if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
  2297. lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
  2298. lsp0, area, IS_LEVEL_1);
  2299. }
  2300. while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
  2301. {
  2302. if (lsp->tlv_data.te_is_neighs == NULL)
  2303. lsp->tlv_data.te_is_neighs = list_new ();
  2304. lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
  2305. IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
  2306. tlv_add_te_is_neighs);
  2307. if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
  2308. lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
  2309. lsp0, area, IS_LEVEL_1);
  2310. }
  2311. free_tlvs (&tlv_data);
  2312. return;
  2313. }
  2314. #endif /* TOPOLOGY_GENERATE */