blob: 9ac0221488fae0918213bf112fd5e8d72062a59b [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
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
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
paul15935e92005-05-03 09:27:23 +000023
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "linklist.h"
27#include "thread.h"
28#include "vty.h"
29#include "stream.h"
30#include "memory.h"
31#include "log.h"
32#include "prefix.h"
33#include "command.h"
34#include "hash.h"
35#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010036#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070037#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000038
39#include "isisd/dict.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_circuit.h"
44#include "isisd/isisd.h"
45#include "isisd/isis_tlv.h"
46#include "isisd/isis_lsp.h"
47#include "isisd/isis_pdu.h"
48#include "isisd/isis_dynhn.h"
49#include "isisd/isis_misc.h"
jardineb5d44e2003-12-23 08:09:43 +000050#include "isisd/isis_csm.h"
51#include "isisd/isis_adjacency.h"
52#include "isisd/isis_spf.h"
53
54#ifdef TOPOLOGY_GENERATE
55#include "spgrid.h"
56#endif
57
hasso73d1aea2004-09-24 10:45:28 +000058/* staticly assigned vars for printing purposes */
59char lsp_bits_string[200]; /* FIXME: enough ? */
60
Josh Bailey3f045a02012-03-24 08:35:20 -070061static int lsp_l1_refresh (struct thread *thread);
62static int lsp_l2_refresh (struct thread *thread);
63static int lsp_l1_refresh_pseudo (struct thread *thread);
64static int lsp_l2_refresh_pseudo (struct thread *thread);
65
hassof390d2c2004-09-10 20:48:21 +000066int
67lsp_id_cmp (u_char * id1, u_char * id2)
68{
jardineb5d44e2003-12-23 08:09:43 +000069 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
70}
71
72dict_t *
hassof390d2c2004-09-10 20:48:21 +000073lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000074{
75 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000076
77 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
78
jardineb5d44e2003-12-23 08:09:43 +000079 return dict;
80}
81
82struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000083lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000084{
85 dnode_t *node;
86
hassof390d2c2004-09-10 20:48:21 +000087#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000088 dnode_t *dn;
89
hasso529d65b2004-12-24 00:14:50 +000090 zlog_debug ("searching db");
hassof390d2c2004-09-10 20:48:21 +000091 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
92 {
Josh Bailey3f045a02012-03-24 08:35:20 -070093 zlog_debug ("%s\t%pX", rawlspid_print ((u_char *) dnode_getkey (dn)),
hasso529d65b2004-12-24 00:14:50 +000094 dnode_get (dn));
hassof390d2c2004-09-10 20:48:21 +000095 }
jardineb5d44e2003-12-23 08:09:43 +000096#endif /* EXTREME DEBUG */
97
98 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +000099
jardineb5d44e2003-12-23 08:09:43 +0000100 if (node)
hassof390d2c2004-09-10 20:48:21 +0000101 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000102
103 return NULL;
104}
105
hasso92365882005-01-18 13:53:33 +0000106static void
jardineb5d44e2003-12-23 08:09:43 +0000107lsp_clear_data (struct isis_lsp *lsp)
108{
109 if (!lsp)
110 return;
hassof390d2c2004-09-10 20:48:21 +0000111
Josh Bailey3f045a02012-03-24 08:35:20 -0700112 if (lsp->tlv_data.hostname)
113 isis_dynhn_remove (lsp->lsp_header->lsp_id);
114
hassof390d2c2004-09-10 20:48:21 +0000115 if (lsp->own_lsp)
116 {
117 if (lsp->tlv_data.nlpids)
Josh Bailey3f045a02012-03-24 08:35:20 -0700118 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
hassof390d2c2004-09-10 20:48:21 +0000119 if (lsp->tlv_data.hostname)
Josh Bailey3f045a02012-03-24 08:35:20 -0700120 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
121 if (lsp->tlv_data.router_id)
122 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.router_id);
hassof390d2c2004-09-10 20:48:21 +0000123 }
jardineb5d44e2003-12-23 08:09:43 +0000124
Josh Bailey3f045a02012-03-24 08:35:20 -0700125 free_tlvs (&lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000126}
127
hasso92365882005-01-18 13:53:33 +0000128static void
jardineb5d44e2003-12-23 08:09:43 +0000129lsp_destroy (struct isis_lsp *lsp)
130{
Josh Bailey3f045a02012-03-24 08:35:20 -0700131 struct listnode *cnode, *lnode, *lnnode;
132 struct isis_lsp *lsp_in_list;
133 struct isis_circuit *circuit;
134
jardineb5d44e2003-12-23 08:09:43 +0000135 if (!lsp)
136 return;
hassof390d2c2004-09-10 20:48:21 +0000137
Josh Bailey3f045a02012-03-24 08:35:20 -0700138 for (ALL_LIST_ELEMENTS_RO (lsp->area->circuit_list, cnode, circuit))
139 {
140 if (circuit->lsp_queue == NULL)
141 continue;
142 for (ALL_LIST_ELEMENTS (circuit->lsp_queue, lnode, lnnode, lsp_in_list))
143 if (lsp_in_list == lsp)
144 list_delete_node(circuit->lsp_queue, lnode);
145 }
146 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags);
147 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
148
jardineb5d44e2003-12-23 08:09:43 +0000149 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000150
151 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
152 {
jardineb5d44e2003-12-23 08:09:43 +0000153 list_delete (lsp->lspu.frags);
Josh Bailey3f045a02012-03-24 08:35:20 -0700154 lsp->lspu.frags = NULL;
hassof390d2c2004-09-10 20:48:21 +0000155 }
156
Josh Bailey3f045a02012-03-24 08:35:20 -0700157 isis_spf_schedule (lsp->area, lsp->level);
158#ifdef HAVE_IPV6
159 isis_spf_schedule6 (lsp->area, lsp->level);
160#endif
161
jardineb5d44e2003-12-23 08:09:43 +0000162 if (lsp->pdu)
163 stream_free (lsp->pdu);
164 XFREE (MTYPE_ISIS_LSP, lsp);
165}
166
hassof390d2c2004-09-10 20:48:21 +0000167void
168lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000169{
170 dnode_t *dnode, *next;
171 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000172
jardineb5d44e2003-12-23 08:09:43 +0000173 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000174 while (dnode)
175 {
176 next = dict_next (lspdb, dnode);
177 lsp = dnode_get (dnode);
178 lsp_destroy (lsp);
179 dict_delete_free (lspdb, dnode);
180 dnode = next;
181 }
182
jardineb5d44e2003-12-23 08:09:43 +0000183 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000184
jardineb5d44e2003-12-23 08:09:43 +0000185 return;
186}
187
188/*
189 * Remove all the frags belonging to the given lsp
190 */
hasso92365882005-01-18 13:53:33 +0000191static void
hassof390d2c2004-09-10 20:48:21 +0000192lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000193{
194 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000195 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000196 struct isis_lsp *lsp;
197
paul1eb8ef22005-04-07 07:30:20 +0000198 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000199 {
hassof390d2c2004-09-10 20:48:21 +0000200 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
201 lsp_destroy (lsp);
202 dnode_destroy (dict_delete (lspdb, dnode));
203 }
204
jardineb5d44e2003-12-23 08:09:43 +0000205 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000206
jardineb5d44e2003-12-23 08:09:43 +0000207 return;
208}
209
210void
hassof390d2c2004-09-10 20:48:21 +0000211lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000212{
213 dnode_t *node;
214 struct isis_lsp *lsp;
215
216 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000217 if (node)
218 {
219 node = dict_delete (lspdb, node);
220 lsp = dnode_get (node);
221 /*
222 * If this is a zero lsp, remove all the frags now
223 */
224 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
225 {
226 if (lsp->lspu.frags)
227 lsp_remove_frags (lsp->lspu.frags, lspdb);
228 }
229 else
230 {
231 /*
232 * else just remove this frag, from the zero lsps' frag list
233 */
234 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
235 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
236 }
237 lsp_destroy (lsp);
238 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000239 }
jardineb5d44e2003-12-23 08:09:43 +0000240}
241
242/*
243 * Compares a LSP to given values
244 * Params are given in net order
245 */
hassof390d2c2004-09-10 20:48:21 +0000246int
247lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000248 u_int16_t checksum, u_int16_t rem_lifetime)
249{
hassof390d2c2004-09-10 20:48:21 +0000250 /* no point in double ntohl on seqnum */
251 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000252 lsp->lsp_header->checksum == checksum &&
253 /*comparing with 0, no need to do ntohl */
254 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000255 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
256 {
257 if (isis->debugs & DEBUG_SNP_PACKETS)
258 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700259 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000260 " lifetime %us",
261 areatag,
262 rawlspid_print (lsp->lsp_header->lsp_id),
263 ntohl (lsp->lsp_header->seq_num),
264 ntohs (lsp->lsp_header->checksum),
265 ntohs (lsp->lsp_header->rem_lifetime));
266 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
267 " cksum 0x%04x, lifetime %us",
268 areatag,
269 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000270 }
271 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000272 }
jardineb5d44e2003-12-23 08:09:43 +0000273
hassof390d2c2004-09-10 20:48:21 +0000274 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
275 {
276 if (isis->debugs & DEBUG_SNP_PACKETS)
277 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700278 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000279 " lifetime %us",
280 areatag,
281 rawlspid_print (lsp->lsp_header->lsp_id),
282 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
283 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
284 "cksum 0x%04x, lifetime %us",
285 areatag,
286 ntohl (lsp->lsp_header->seq_num),
287 ntohs (lsp->lsp_header->checksum),
288 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000289 }
290 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000291 }
hassof390d2c2004-09-10 20:48:21 +0000292 if (isis->debugs & DEBUG_SNP_PACKETS)
293 {
hasso529d65b2004-12-24 00:14:50 +0000294 zlog_debug
Josh Bailey3f045a02012-03-24 08:35:20 -0700295 ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
hassof390d2c2004-09-10 20:48:21 +0000296 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
297 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000298 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
299 " cksum 0x%04x, lifetime %us", areatag,
300 ntohl (lsp->lsp_header->seq_num),
301 ntohs (lsp->lsp_header->checksum),
302 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000303 }
jardineb5d44e2003-12-23 08:09:43 +0000304
305 return LSP_OLDER;
306}
307
Josh Bailey3f045a02012-03-24 08:35:20 -0700308static void
309lsp_auth_add (struct isis_lsp *lsp)
310{
311 struct isis_passwd *passwd;
312 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
313
314 /*
315 * Add the authentication info if its present
316 */
317 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
318 (passwd = &lsp->area->domain_passwd);
319 switch (passwd->type)
320 {
321 /* Cleartext */
322 case ISIS_PASSWD_TYPE_CLEARTXT:
323 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
324 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
325 break;
326
327 /* HMAC MD5 */
328 case ISIS_PASSWD_TYPE_HMAC_MD5:
329 /* Remember where TLV is written so we can later
330 * overwrite the MD5 hash */
331 lsp->auth_tlv_offset = stream_get_endp (lsp->pdu);
332 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
333 lsp->tlv_data.auth_info.type = ISIS_PASSWD_TYPE_HMAC_MD5;
334 lsp->tlv_data.auth_info.len = ISIS_AUTH_MD5_SIZE;
335 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
336 ISIS_AUTH_MD5_SIZE);
337 tlv_add_authinfo (passwd->type, ISIS_AUTH_MD5_SIZE, hmac_md5_hash,
338 lsp->pdu);
339 break;
340
341 default:
342 break;
343 }
344}
345
346static void
347lsp_auth_update (struct isis_lsp *lsp)
348{
349 struct isis_passwd *passwd;
350 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
351 uint16_t checksum, rem_lifetime;
352
353 /* For HMAC MD5 we need to recompute the md5 hash and store it */
354 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
355 (passwd = &lsp->area->domain_passwd);
356 if (passwd->type != ISIS_PASSWD_TYPE_HMAC_MD5)
357 return;
358
359 /*
360 * In transient conditions (when net is configured where authentication
361 * config and lsp regenerate schedule is not yet run), there could be
362 * an own_lsp with auth_tlv_offset set to 0. In such a case, simply
363 * return, when lsp_regenerate is run, lsp will have auth tlv.
364 */
365 if (lsp->auth_tlv_offset == 0)
366 return;
367
368 /*
369 * RFC 5304 set auth value, checksum and remaining lifetime to zero
370 * before computation and reset to old values after computation.
371 */
372 checksum = lsp->lsp_header->checksum;
373 rem_lifetime = lsp->lsp_header->rem_lifetime;
374 lsp->lsp_header->checksum = 0;
375 lsp->lsp_header->rem_lifetime = 0;
376 /* Set the authentication value as well to zero */
377 memset (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
378 0, ISIS_AUTH_MD5_SIZE);
379 /* Compute autentication value */
380 hmac_md5 (STREAM_DATA (lsp->pdu), stream_get_endp(lsp->pdu),
381 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +0100382 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -0700383 /* Copy the hash into the stream */
384 memcpy (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
385 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
386 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
387 ISIS_AUTH_MD5_SIZE);
388 /* Copy back the checksum and remaining lifetime */
389 lsp->lsp_header->checksum = checksum;
390 lsp->lsp_header->rem_lifetime = rem_lifetime;
391}
392
hassof390d2c2004-09-10 20:48:21 +0000393void
jardineb5d44e2003-12-23 08:09:43 +0000394lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
395{
396 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000397
jardineb5d44e2003-12-23 08:09:43 +0000398 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
399 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
400 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700401 newseq = seq_num + 1;
hassof390d2c2004-09-10 20:48:21 +0000402
jardineb5d44e2003-12-23 08:09:43 +0000403 lsp->lsp_header->seq_num = htonl (newseq);
Josh Bailey3f045a02012-03-24 08:35:20 -0700404
405 /* Recompute authentication and checksum information */
406 lsp_auth_update (lsp);
407 /* ISO 10589 - 7.3.11 Generation of the checksum
408 * The checksum shall be computed over all fields in the LSP which appear
409 * after the Remaining Lifetime field. This field (and those appearing
410 * before it) are excluded so that the LSP may be aged by systems without
411 * requiring recomputation.
412 */
413 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
414 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
415
416 isis_spf_schedule (lsp->area, lsp->level);
417#ifdef HAVE_IPV6
418 isis_spf_schedule6 (lsp->area, lsp->level);
419#endif
jardineb5d44e2003-12-23 08:09:43 +0000420
421 return;
422}
423
424/*
425 * Genetates checksum for LSP and its frags
426 */
hasso92365882005-01-18 13:53:33 +0000427static void
jardineb5d44e2003-12-23 08:09:43 +0000428lsp_seqnum_update (struct isis_lsp *lsp0)
429{
430 struct isis_lsp *lsp;
hasso3fdb2dd2005-09-28 18:45:54 +0000431 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000432
jardineb5d44e2003-12-23 08:09:43 +0000433 lsp_inc_seqnum (lsp0, 0);
434
435 if (!lsp0->lspu.frags)
436 return;
437
hasso3fdb2dd2005-09-28 18:45:54 +0000438 for (ALL_LIST_ELEMENTS_RO (lsp0->lspu.frags, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +0000439 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000440
jardineb5d44e2003-12-23 08:09:43 +0000441 return;
442}
443
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700444static u_int8_t
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700445lsp_bits_generate (int level, int overload_bit, int attached_bit)
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700446{
447 u_int8_t lsp_bits = 0;
448 if (level == IS_LEVEL_1)
449 lsp_bits = IS_LEVEL_1;
450 else
451 lsp_bits = IS_LEVEL_1_AND_2;
452 if (overload_bit)
453 lsp_bits |= overload_bit;
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700454 if (attached_bit)
455 lsp_bits |= attached_bit;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700456 return lsp_bits;
457}
458
hasso92365882005-01-18 13:53:33 +0000459static void
hassof390d2c2004-09-10 20:48:21 +0000460lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
Josh Bailey3f045a02012-03-24 08:35:20 -0700461 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000462{
hassof390d2c2004-09-10 20:48:21 +0000463 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000464 int retval;
hassof390d2c2004-09-10 20:48:21 +0000465
Josh Bailey3f045a02012-03-24 08:35:20 -0700466 /* free the old lsp data */
467 lsp_clear_data (lsp);
468
jardineb5d44e2003-12-23 08:09:43 +0000469 /* copying only the relevant part of our stream */
Josh Bailey3f045a02012-03-24 08:35:20 -0700470 if (lsp->pdu != NULL)
471 stream_free (lsp->pdu);
paul15935e92005-05-03 09:27:23 +0000472 lsp->pdu = stream_dup (stream);
Josh Bailey3f045a02012-03-24 08:35:20 -0700473
jardineb5d44e2003-12-23 08:09:43 +0000474 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000475 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
476 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
477 ISIS_FIXED_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -0700478 lsp->area = area;
479 lsp->level = level;
jardineb5d44e2003-12-23 08:09:43 +0000480 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000481 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000482 /*
483 * Get LSP data i.e. TLVs
484 */
485 expected |= TLVFLAG_AUTH_INFO;
486 expected |= TLVFLAG_AREA_ADDRS;
487 expected |= TLVFLAG_IS_NEIGHS;
jardineb5d44e2003-12-23 08:09:43 +0000488 expected |= TLVFLAG_NLPID;
489 if (area->dynhostname)
490 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000491 if (area->newmetric)
492 {
493 expected |= TLVFLAG_TE_IS_NEIGHS;
494 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
495 expected |= TLVFLAG_TE_ROUTER_ID;
496 }
jardineb5d44e2003-12-23 08:09:43 +0000497 expected |= TLVFLAG_IPV4_ADDR;
498 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
499 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
500#ifdef HAVE_IPV6
501 expected |= TLVFLAG_IPV6_ADDR;
502 expected |= TLVFLAG_IPV6_REACHABILITY;
503#endif /* HAVE_IPV6 */
504
Josh Bailey3f045a02012-03-24 08:35:20 -0700505 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
506 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
507 ntohs (lsp->lsp_header->pdu_len) -
508 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
509 &expected, &found, &lsp->tlv_data,
510 NULL);
511 if (retval != ISIS_OK)
hassof390d2c2004-09-10 20:48:21 +0000512 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700513 zlog_warn ("Could not parse LSP");
514 return;
515 }
516
517 if ((found & TLVFLAG_DYN_HOSTNAME) && (area->dynhostname))
518 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700519 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
520 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
521 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : IS_LEVEL_1);
hassof390d2c2004-09-10 20:48:21 +0000522 }
jardineb5d44e2003-12-23 08:09:43 +0000523
Josh Bailey3f045a02012-03-24 08:35:20 -0700524 return;
jardineb5d44e2003-12-23 08:09:43 +0000525}
526
527void
Josh Bailey3f045a02012-03-24 08:35:20 -0700528lsp_update (struct isis_lsp *lsp, struct stream *stream,
529 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000530{
hasso4eda93a2005-09-18 17:51:02 +0000531 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000532
Josh Bailey3f045a02012-03-24 08:35:20 -0700533 /* Remove old LSP from database. This is required since the
534 * lsp_update_data will free the lsp->pdu (which has the key, lsp_id)
535 * and will update it with the new data in the stream. */
hasso4eda93a2005-09-18 17:51:02 +0000536 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
537 if (dnode)
538 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000539
jardineb5d44e2003-12-23 08:09:43 +0000540 /* rebuild the lsp data */
Josh Bailey3f045a02012-03-24 08:35:20 -0700541 lsp_update_data (lsp, stream, area, level);
jardineb5d44e2003-12-23 08:09:43 +0000542
Josh Bailey3f045a02012-03-24 08:35:20 -0700543 /* insert the lsp back into the database */
544 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000545}
546
jardineb5d44e2003-12-23 08:09:43 +0000547/* creation of LSP directly from what we received */
548struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000549lsp_new_from_stream_ptr (struct stream *stream,
550 u_int16_t pdu_len, struct isis_lsp *lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -0700551 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000552{
553 struct isis_lsp *lsp;
554
hassoaac372f2005-09-01 17:52:33 +0000555 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -0700556 lsp_update_data (lsp, stream, area, level);
hassof390d2c2004-09-10 20:48:21 +0000557
558 if (lsp0 == NULL)
559 {
560 /*
561 * zero lsp -> create the list for fragments
562 */
563 lsp->lspu.frags = list_new ();
564 }
565 else
566 {
567 /*
568 * a fragment -> set the backpointer and add this to zero lsps frag list
569 */
570 lsp->lspu.zero_lsp = lsp0;
571 listnode_add (lsp0->lspu.frags, lsp);
572 }
573
jardineb5d44e2003-12-23 08:09:43 +0000574 return lsp;
575}
576
577struct isis_lsp *
Christian Frankef1fc1db2015-11-10 18:43:31 +0100578lsp_new(struct isis_area *area, u_char * lsp_id,
579 u_int16_t rem_lifetime, u_int32_t seq_num,
580 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000581{
582 struct isis_lsp *lsp;
583
hassoaac372f2005-09-01 17:52:33 +0000584 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Christian Frankef1fc1db2015-11-10 18:43:31 +0100585 lsp->area = area;
Christian Franke390f16e2015-11-10 18:04:44 +0100586
Christian Frankef1fc1db2015-11-10 18:43:31 +0100587 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
jardineb5d44e2003-12-23 08:09:43 +0000588 if (LSP_FRAGMENT (lsp_id) == 0)
589 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000590 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
591 lsp->lsp_header = (struct isis_link_state_hdr *)
592 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
593
jardineb5d44e2003-12-23 08:09:43 +0000594 /* at first we fill the FIXED HEADER */
Josh Bailey3f045a02012-03-24 08:35:20 -0700595 (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
hassof390d2c2004-09-10 20:48:21 +0000596 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
597
jardineb5d44e2003-12-23 08:09:43 +0000598 /* now for the LSP HEADER */
599 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000600 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000601 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000602 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000603 lsp->lsp_header->seq_num = htonl (seq_num);
604 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
605 lsp->lsp_header->lsp_bits = lsp_bits;
606 lsp->level = level;
607 lsp->age_out = ZERO_AGE_LIFETIME;
608
paul9985f832005-02-09 15:51:56 +0000609 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000610
hassoc89c05d2005-09-04 21:36:36 +0000611 if (isis->debugs & DEBUG_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -0700612 zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
hassoc89c05d2005-09-04 21:36:36 +0000613 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
614 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -0700615 ntohl (lsp->lsp_header->pdu_len),
hassoc89c05d2005-09-04 21:36:36 +0000616 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000617
618 return lsp;
619}
620
621void
hassof390d2c2004-09-10 20:48:21 +0000622lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000623{
624 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700625 if (lsp->lsp_header->seq_num != 0)
626 {
627 isis_spf_schedule (lsp->area, lsp->level);
628#ifdef HAVE_IPV6
629 isis_spf_schedule6 (lsp->area, lsp->level);
630#endif
631 }
jardineb5d44e2003-12-23 08:09:43 +0000632}
633
634/*
635 * Build a list of LSPs with non-zero ht bounded by start and stop ids
636 */
hassof390d2c2004-09-10 20:48:21 +0000637void
638lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
639 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000640{
641 dnode_t *first, *last, *curr;
642
643 first = dict_lower_bound (lspdb, start_id);
644 if (!first)
645 return;
hassof390d2c2004-09-10 20:48:21 +0000646
jardineb5d44e2003-12-23 08:09:43 +0000647 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000648
jardineb5d44e2003-12-23 08:09:43 +0000649 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000650
651 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000652 listnode_add (list, first->dict_data);
653
hassof390d2c2004-09-10 20:48:21 +0000654 while (curr)
655 {
656 curr = dict_next (lspdb, curr);
657 if (curr &&
658 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
659 listnode_add (list, curr->dict_data);
660 if (curr == last)
661 break;
662 }
663
jardineb5d44e2003-12-23 08:09:43 +0000664 return;
665}
666
667/*
Josh Bailey3f045a02012-03-24 08:35:20 -0700668 * Build a list of num_lsps LSPs bounded by start_id and stop_id.
jardineb5d44e2003-12-23 08:09:43 +0000669 */
hassof390d2c2004-09-10 20:48:21 +0000670void
Josh Bailey3f045a02012-03-24 08:35:20 -0700671lsp_build_list (u_char * start_id, u_char * stop_id, u_char num_lsps,
hassof390d2c2004-09-10 20:48:21 +0000672 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000673{
Josh Bailey3f045a02012-03-24 08:35:20 -0700674 u_char count;
jardineb5d44e2003-12-23 08:09:43 +0000675 dnode_t *first, *last, *curr;
676
677 first = dict_lower_bound (lspdb, start_id);
678 if (!first)
679 return;
hassof390d2c2004-09-10 20:48:21 +0000680
jardineb5d44e2003-12-23 08:09:43 +0000681 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000682
jardineb5d44e2003-12-23 08:09:43 +0000683 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000684
jardineb5d44e2003-12-23 08:09:43 +0000685 listnode_add (list, first->dict_data);
Josh Bailey3f045a02012-03-24 08:35:20 -0700686 count = 1;
jardineb5d44e2003-12-23 08:09:43 +0000687
hassof390d2c2004-09-10 20:48:21 +0000688 while (curr)
689 {
690 curr = dict_next (lspdb, curr);
691 if (curr)
Josh Bailey3f045a02012-03-24 08:35:20 -0700692 {
693 listnode_add (list, curr->dict_data);
694 count++;
695 }
696 if (count == num_lsps || curr == last)
697 break;
hassof390d2c2004-09-10 20:48:21 +0000698 }
699
jardineb5d44e2003-12-23 08:09:43 +0000700 return;
701}
702
703/*
704 * Build a list of LSPs with SSN flag set for the given circuit
705 */
706void
Josh Bailey3f045a02012-03-24 08:35:20 -0700707lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps,
708 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000709{
710 dnode_t *dnode, *next;
711 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -0700712 u_char count = 0;
hassof390d2c2004-09-10 20:48:21 +0000713
jardineb5d44e2003-12-23 08:09:43 +0000714 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000715 while (dnode != NULL)
716 {
717 next = dict_next (lspdb, dnode);
718 lsp = dnode_get (dnode);
719 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -0700720 {
721 listnode_add (list, lsp);
722 ++count;
723 }
724 if (count == num_lsps)
725 break;
hassof390d2c2004-09-10 20:48:21 +0000726 dnode = next;
727 }
728
jardineb5d44e2003-12-23 08:09:43 +0000729 return;
730}
731
hasso92365882005-01-18 13:53:33 +0000732static void
jardineb5d44e2003-12-23 08:09:43 +0000733lsp_set_time (struct isis_lsp *lsp)
734{
735 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000736
737 if (lsp->lsp_header->rem_lifetime == 0)
738 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700739 if (lsp->age_out > 0)
740 lsp->age_out--;
hassof390d2c2004-09-10 20:48:21 +0000741 return;
742 }
jardineb5d44e2003-12-23 08:09:43 +0000743
hassof390d2c2004-09-10 20:48:21 +0000744 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000745 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
746}
747
hasso92365882005-01-18 13:53:33 +0000748static void
hassof390d2c2004-09-10 20:48:21 +0000749lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000750{
751 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000752 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000753
754 if (dynhost)
755 dyn = dynhn_find_by_id (lsp_id);
756 else
757 dyn = NULL;
758
759 if (dyn)
Josh Bailey3f045a02012-03-24 08:35:20 -0700760 sprintf ((char *)id, "%.14s", dyn->name.name);
761 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
762 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000763 else
hassof390d2c2004-09-10 20:48:21 +0000764 memcpy (id, sysid_print (lsp_id), 15);
hassof390d2c2004-09-10 20:48:21 +0000765 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000766 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000767 LSP_FRAGMENT (lsp_id));
768 else
hassof7c43dc2004-09-26 16:24:14 +0000769 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000770}
771
hassof390d2c2004-09-10 20:48:21 +0000772/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000773const char *
hassof390d2c2004-09-10 20:48:21 +0000774lsp_bits2string (u_char * lsp_bits)
775{
776 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000777
hassof390d2c2004-09-10 20:48:21 +0000778 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000779 return " none";
780
781 /* we only focus on the default metric */
782 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000783 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000784
785 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000786 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000787
hassof390d2c2004-09-10 20:48:21 +0000788 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
789
jardineb5d44e2003-12-23 08:09:43 +0000790 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000791
hassof390d2c2004-09-10 20:48:21 +0000792 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000793}
794
795/* this function prints the lsp on show isis database */
Josh Bailey3f045a02012-03-24 08:35:20 -0700796void
797lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000798{
jardineb5d44e2003-12-23 08:09:43 +0000799 u_char LSPid[255];
Josh Bailey3f045a02012-03-24 08:35:20 -0700800 char age_out[8];
jardineb5d44e2003-12-23 08:09:43 +0000801
802 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700803 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
804 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len));
805 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
806 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
hassof390d2c2004-09-10 20:48:21 +0000807 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
Josh Bailey3f045a02012-03-24 08:35:20 -0700808 {
809 snprintf (age_out, 8, "(%u)", lsp->age_out);
810 age_out[7] = '\0';
811 vty_out (vty, "%7s ", age_out);
812 }
jardineb5d44e2003-12-23 08:09:43 +0000813 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700814 vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime));
815 vty_out (vty, "%s%s",
816 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000817}
818
Josh Bailey3f045a02012-03-24 08:35:20 -0700819void
820lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000821{
jardineb5d44e2003-12-23 08:09:43 +0000822 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000823 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000824 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000825 struct is_neigh *is_neigh;
826 struct te_is_neigh *te_is_neigh;
827 struct ipv4_reachability *ipv4_reach;
828 struct in_addr *ipv4_addr;
829 struct te_ipv4_reachability *te_ipv4_reach;
830#ifdef HAVE_IPV6
831 struct ipv6_reachability *ipv6_reach;
832 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000833 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000834#endif
835 u_char LSPid[255];
836 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000837 u_char ipv4_reach_prefix[20];
838 u_char ipv4_reach_mask[20];
839 u_char ipv4_address[20];
840
841 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700842 lsp_print (lsp, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000843
844 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000845 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000846 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000847 {
hasso1cd80842004-10-07 20:07:40 +0000848 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000849 isonet_print (area_addr->area_addr, area_addr->addr_len),
850 VTY_NEWLINE);
851 }
paul1eb8ef22005-04-07 07:30:20 +0000852
jardineb5d44e2003-12-23 08:09:43 +0000853 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000854 if (lsp->tlv_data.nlpids)
855 {
856 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
857 {
858 switch (lsp->tlv_data.nlpids->nlpids[i])
859 {
860 case NLPID_IP:
861 case NLPID_IPV6:
Josh Bailey3f045a02012-03-24 08:35:20 -0700862 vty_out (vty, " NLPID : 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000863 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
864 break;
865 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700866 vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000867 break;
868 }
869 }
870 }
jardineb5d44e2003-12-23 08:09:43 +0000871
872 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000873 if (lsp->tlv_data.hostname)
874 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700875 bzero (hostname, sizeof (hostname));
hassof390d2c2004-09-10 20:48:21 +0000876 memcpy (hostname, lsp->tlv_data.hostname->name,
877 lsp->tlv_data.hostname->namelen);
Josh Bailey3f045a02012-03-24 08:35:20 -0700878 vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000879 }
hassof390d2c2004-09-10 20:48:21 +0000880
Josh Bailey3f045a02012-03-24 08:35:20 -0700881 /* authentication tlv */
882 if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED)
883 {
884 if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5)
885 vty_out (vty, " Auth type : md5%s", VTY_NEWLINE);
886 else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT)
887 vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE);
888 }
hassof390d2c2004-09-10 20:48:21 +0000889
hasso1cd80842004-10-07 20:07:40 +0000890 /* TE router id */
891 if (lsp->tlv_data.router_id)
892 {
893 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
894 sizeof (ipv4_address));
Josh Bailey3f045a02012-03-24 08:35:20 -0700895 vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE);
hasso1cd80842004-10-07 20:07:40 +0000896 }
897
Josh Bailey3f045a02012-03-24 08:35:20 -0700898 if (lsp->tlv_data.ipv4_addrs)
899 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
900 {
901 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
902 vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE);
903 }
904
hasso1cd80842004-10-07 20:07:40 +0000905 /* for the IS neighbor tlv */
906 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000907 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000908 {
909 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700910 vty_out (vty, " Metric : %-8d IS : %s%s",
hasso1cd80842004-10-07 20:07:40 +0000911 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
912 }
hasso1cd80842004-10-07 20:07:40 +0000913
jardineb5d44e2003-12-23 08:09:43 +0000914 /* for the internal reachable tlv */
915 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000916 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
917 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000918 {
919 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
920 sizeof (ipv4_reach_prefix));
921 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
922 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700923 vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000924 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
925 ipv4_reach_mask, VTY_NEWLINE);
926 }
hasso2097cd82003-12-23 11:51:08 +0000927
928 /* for the external reachable tlv */
929 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000930 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
931 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000932 {
933 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
934 sizeof (ipv4_reach_prefix));
935 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
936 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700937 vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000938 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
939 ipv4_reach_mask, VTY_NEWLINE);
940 }
paul1eb8ef22005-04-07 07:30:20 +0000941
hasso2097cd82003-12-23 11:51:08 +0000942 /* IPv6 tlv */
943#ifdef HAVE_IPV6
944 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000945 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000946 {
947 memset (&in6, 0, sizeof (in6));
948 memcpy (in6.s6_addr, ipv6_reach->prefix,
949 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000950 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
David Lamparter6db3ef62015-03-03 09:07:43 +0100951 if ((ipv6_reach->control_info &
hassof390d2c2004-09-10 20:48:21 +0000952 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
Josh Bailey3f045a02012-03-24 08:35:20 -0700953 vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000954 ntohl (ipv6_reach->metric),
955 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000956 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700957 vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000958 ntohl (ipv6_reach->metric),
959 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000960 }
961#endif
paul1eb8ef22005-04-07 07:30:20 +0000962
hasso1cd80842004-10-07 20:07:40 +0000963 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000964 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000965 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000966 {
hassof390d2c2004-09-10 20:48:21 +0000967 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700968 vty_out (vty, " Metric : %-8d IS-Extended : %s%s",
969 GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000970 }
jardineb5d44e2003-12-23 08:09:43 +0000971
hasso1cd80842004-10-07 20:07:40 +0000972 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000973 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000974 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
975 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000976 {
hasso1cd80842004-10-07 20:07:40 +0000977 /* FIXME: There should be better way to output this stuff. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700978 vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000979 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000980 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
981 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000982 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000983 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700984 vty_out (vty, "%s", VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000985
hassof390d2c2004-09-10 20:48:21 +0000986 return;
jardineb5d44e2003-12-23 08:09:43 +0000987}
988
989/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000990int
991lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000992{
993
hassof390d2c2004-09-10 20:48:21 +0000994 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000995 int lsp_count = 0;
996
hassof390d2c2004-09-10 20:48:21 +0000997 if (detail == ISIS_UI_LEVEL_BRIEF)
998 {
999 while (node != NULL)
1000 {
1001 /* I think it is unnecessary, so I comment it out */
1002 /* dict_contains (lspdb, node); */
1003 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001004 lsp_print (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001005 node = next;
1006 lsp_count++;
1007 }
jardineb5d44e2003-12-23 08:09:43 +00001008 }
hassof390d2c2004-09-10 20:48:21 +00001009 else if (detail == ISIS_UI_LEVEL_DETAIL)
1010 {
1011 while (node != NULL)
1012 {
1013 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001014 lsp_print_detail (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001015 node = next;
1016 lsp_count++;
1017 }
jardineb5d44e2003-12-23 08:09:43 +00001018 }
jardineb5d44e2003-12-23 08:09:43 +00001019
1020 return lsp_count;
1021}
1022
jardineb5d44e2003-12-23 08:09:43 +00001023#define FRAG_THOLD(S,T) \
Josh Bailey3f045a02012-03-24 08:35:20 -07001024 ((STREAM_SIZE(S)*T)/100)
jardineb5d44e2003-12-23 08:09:43 +00001025
1026/* stream*, area->lsp_frag_threshold, increment */
1027#define FRAG_NEEDED(S,T,I) \
1028 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1029
hassoaa4376e2005-09-26 17:39:48 +00001030/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
1031 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +00001032static void
jardineb5d44e2003-12-23 08:09:43 +00001033lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001034 int tlvsize, int frag_thold,
1035 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001036{
1037 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001038
jardineb5d44e2003-12-23 08:09:43 +00001039 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001040 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1041 {
1042 tlv_build_func (*from, lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07001043 if (listcount (*to) != 0)
1044 {
1045 struct listnode *node, *nextnode;
1046 void *elem;
1047
1048 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1049 {
1050 listnode_add (*to, elem);
1051 list_delete_node (*from, node);
1052 }
1053 }
1054 else
1055 {
1056 list_free (*to);
1057 *to = *from;
1058 *from = NULL;
1059 }
jardineb5d44e2003-12-23 08:09:43 +00001060 }
hassof390d2c2004-09-10 20:48:21 +00001061 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1062 {
1063 /* fit all we can */
1064 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1065 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
Josh Bailey3f045a02012-03-24 08:35:20 -07001066 count = count / tlvsize;
1067 if (count > (int)listcount (*from))
1068 count = listcount (*from);
hassof390d2c2004-09-10 20:48:21 +00001069 for (i = 0; i < count; i++)
1070 {
paul1eb8ef22005-04-07 07:30:20 +00001071 listnode_add (*to, listgetdata (listhead (*from)));
1072 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001073 }
1074 tlv_build_func (*to, lsp->pdu);
1075 }
paul9985f832005-02-09 15:51:56 +00001076 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001077 return;
1078}
1079
Josh Bailey3f045a02012-03-24 08:35:20 -07001080static u_int16_t
1081lsp_rem_lifetime (struct isis_area *area, int level)
1082{
1083 u_int16_t rem_lifetime;
1084
1085 /* Add jitter to configured LSP lifetime */
1086 rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1],
1087 MAX_AGE_JITTER);
1088
1089 /* No jitter if the max refresh will be less than configure gen interval */
1090 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1091 rem_lifetime = area->max_lsp_lifetime[level - 1];
1092
1093 return rem_lifetime;
1094}
1095
1096static u_int16_t
1097lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1098{
1099 struct isis_area *area = lsp->area;
1100 int level = lsp->level;
1101 u_int16_t refresh_time;
1102
1103 /* Add jitter to LSP refresh time */
1104 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1105 MAX_LSP_GEN_JITTER);
1106
1107 /* RFC 4444 : make sure the refresh time is at least less than 300
1108 * of the remaining lifetime and more than gen interval */
1109 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1110 refresh_time > (rem_lifetime - 300))
1111 refresh_time = rem_lifetime - 300;
1112
1113 assert (area->lsp_gen_interval[level - 1] < refresh_time);
1114
1115 return refresh_time;
1116}
1117
hasso92365882005-01-18 13:53:33 +00001118static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001119lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1120 int level)
jardineb5d44e2003-12-23 08:09:43 +00001121{
1122 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001123 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1124
jardineb5d44e2003-12-23 08:09:43 +00001125 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1126 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001127 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001128 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001129 if (lsp)
1130 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001131 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001132 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001133 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001134 }
Christian Frankef1fc1db2015-11-10 18:43:31 +01001135 lsp = lsp_new (area, frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001136 lsp_bits_generate (level, area->overload_bit,
1137 area->attached_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001138 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001139 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001140 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001141 listnode_add (lsp0->lspu.frags, lsp);
1142 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001143 return lsp;
1144}
1145
1146/*
1147 * Builds the LSP data part. This func creates a new frag whenever
1148 * area->lsp_frag_threshold is exceeded.
1149 */
hasso92365882005-01-18 13:53:33 +00001150static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001151lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001152{
1153 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001154 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001155 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001156 int level = lsp->level;
1157 struct isis_circuit *circuit;
1158 struct prefix_ipv4 *ipv4;
1159 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001160 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001161 struct isis_adjacency *nei;
1162#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001163 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001164 struct ipv6_reachability *ip6reach;
1165#endif /* HAVE_IPV6 */
1166 struct tlvs tlv_data;
1167 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001168 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001169 uint32_t expected = 0, found = 0;
1170 uint32_t metric;
1171 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1172 int retval = ISIS_OK;
Christian Franke80a8f722015-11-12 14:21:47 +01001173 char buf[BUFSIZ];
1174
1175 lsp_debug("ISIS (%s): Constructing local system LSP for level %d", area->area_tag, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001176
1177 /*
1178 * Building the zero lsp
1179 */
1180 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1181
1182 /* Reset stream endp. Stream is always there and on every LSP refresh only
1183 * TLV part of it is overwritten. So we must seek past header we will not
1184 * touch. */
1185 stream_reset (lsp->pdu);
1186 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1187
1188 /*
1189 * Add the authentication info if its present
1190 */
1191 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001192
1193 /*
1194 * First add the tlvs related to area
1195 */
hassof390d2c2004-09-10 20:48:21 +00001196
jardineb5d44e2003-12-23 08:09:43 +00001197 /* Area addresses */
1198 if (lsp->tlv_data.area_addrs == NULL)
1199 lsp->tlv_data.area_addrs = list_new ();
1200 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001201 if (listcount (lsp->tlv_data.area_addrs) > 0)
1202 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1203
jardineb5d44e2003-12-23 08:09:43 +00001204 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001205 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001206#ifdef HAVE_IPV6
1207 || area->ipv6_circuits > 0
1208#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001209 )
jardineb5d44e2003-12-23 08:09:43 +00001210 {
hassoaac372f2005-09-01 17:52:33 +00001211 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001212 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001213 if (area->ip_circuits > 0)
1214 {
Christian Franke80a8f722015-11-12 14:21:47 +01001215 lsp_debug("ISIS (%s): Found IPv4 circuit, adding IPv4 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001216 lsp->tlv_data.nlpids->count++;
1217 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1218 }
jardineb5d44e2003-12-23 08:09:43 +00001219#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001220 if (area->ipv6_circuits > 0)
1221 {
Christian Franke80a8f722015-11-12 14:21:47 +01001222 lsp_debug("ISIS (%s): Found IPv6 circuit, adding IPv6 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001223 lsp->tlv_data.nlpids->count++;
1224 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1225 NLPID_IPV6;
1226 }
jardineb5d44e2003-12-23 08:09:43 +00001227#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001228 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001229 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001230
jardineb5d44e2003-12-23 08:09:43 +00001231 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001232 if (area->dynhostname)
1233 {
Christian Frankef35169e2015-11-12 14:09:08 +01001234 const char *hostname = unix_hostname();
1235 size_t hostname_len = strlen(hostname);
1236
hassof390d2c2004-09-10 20:48:21 +00001237 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1238 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001239
Christian Frankef35169e2015-11-12 14:09:08 +01001240 strncpy((char *)lsp->tlv_data.hostname->name, hostname,
1241 sizeof(lsp->tlv_data.hostname->name));
1242 if (hostname_len <= MAX_TLV_LEN)
1243 lsp->tlv_data.hostname->namelen = hostname_len;
1244 else
1245 lsp->tlv_data.hostname->namelen = MAX_TLV_LEN;
1246
Christian Franke80a8f722015-11-12 14:21:47 +01001247 lsp_debug("ISIS (%s): Adding dynamic hostname '%.*s'", area->area_tag,
1248 lsp->tlv_data.hostname->namelen, lsp->tlv_data.hostname->name);
Josh Bailey3f045a02012-03-24 08:35:20 -07001249 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001250 }
Christian Franke80a8f722015-11-12 14:21:47 +01001251 else
1252 {
1253 lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)", area->area_tag);
1254 }
jardineb5d44e2003-12-23 08:09:43 +00001255
hasso81ad8f62005-09-26 17:58:24 +00001256 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1257 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1258 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001259 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001260 {
Christian Franke80a8f722015-11-12 14:21:47 +01001261 inet_ntop(AF_INET, &isis->router_id, buf, sizeof(buf));
1262 lsp_debug("ISIS (%s): Adding router ID %s as IPv4 tlv.", area->area_tag, buf);
hasso18a6dce2004-10-03 18:18:34 +00001263 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001264 {
1265 lsp->tlv_data.ipv4_addrs = list_new ();
1266 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1267 }
hasso18a6dce2004-10-03 18:18:34 +00001268
1269 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001270 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001271 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001272 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001273
hasso81ad8f62005-09-26 17:58:24 +00001274 /* Exactly same data is put into TE router ID TLV, but only if new style
1275 * TLV's are in use. */
1276 if (area->newmetric)
1277 {
Christian Franke80a8f722015-11-12 14:21:47 +01001278 lsp_debug("ISIS (%s): Adding router ID also as TE router ID tlv.", area->area_tag);
hasso81ad8f62005-09-26 17:58:24 +00001279 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1280 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001281 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1282 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1283 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001284 }
hasso18a6dce2004-10-03 18:18:34 +00001285 }
Christian Franke80a8f722015-11-12 14:21:47 +01001286 else
1287 {
1288 lsp_debug("ISIS (%s): Router ID is unset. Not adding tlv.", area->area_tag);
1289 }
hassof1082d12005-09-19 04:23:34 +00001290
hasso81ad8f62005-09-26 17:58:24 +00001291 memset (&tlv_data, 0, sizeof (struct tlvs));
1292
hassof1082d12005-09-19 04:23:34 +00001293#ifdef TOPOLOGY_GENERATE
1294 /* If topology exists (and we create topology for level 1 only), create
1295 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001296 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001297 {
1298 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001299 {
1300 tlv_data.is_neighs = list_new ();
1301 tlv_data.is_neighs->del = free_tlv;
1302 }
hasso3fdb2dd2005-09-28 18:45:54 +00001303 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001304
1305 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1306 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1307 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1308 is_neigh->metrics.metric_default = 0x01;
1309 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1310 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1311 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1312 listnode_add (tlv_data.is_neighs, is_neigh);
1313 }
1314#endif /* TOPOLOGY_GENERATE */
1315
Christian Franke80a8f722015-11-12 14:21:47 +01001316 lsp_debug("ISIS (%s): Adding circuit specific information.", area->area_tag);
1317
hasso18a6dce2004-10-03 18:18:34 +00001318 /*
jardineb5d44e2003-12-23 08:09:43 +00001319 * Then build lists of tlvs related to circuits
1320 */
hasso3fdb2dd2005-09-28 18:45:54 +00001321 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001322 {
Christian Franke80a8f722015-11-12 14:21:47 +01001323 if (!circuit->interface)
1324 lsp_debug("ISIS (%s): Processing %s circuit %p with unknown interface",
1325 area->area_tag, circuit_type2string(circuit->circ_type), circuit);
1326 else
1327 lsp_debug("ISIS (%s): Processing %s circuit %s",
1328 area->area_tag, circuit_type2string(circuit->circ_type), circuit->interface->name);
1329
hassof390d2c2004-09-10 20:48:21 +00001330 if (circuit->state != C_STATE_UP)
Christian Franke80a8f722015-11-12 14:21:47 +01001331 {
1332 lsp_debug("ISIS (%s): Circuit is not up, ignoring.", area->area_tag);
1333 continue;
1334 }
jardineb5d44e2003-12-23 08:09:43 +00001335
hassof390d2c2004-09-10 20:48:21 +00001336 /*
1337 * Add IPv4 internal reachability of this circuit
1338 */
1339 if (circuit->ip_router && circuit->ip_addrs &&
1340 circuit->ip_addrs->count > 0)
1341 {
Christian Franke80a8f722015-11-12 14:21:47 +01001342 lsp_debug("ISIS (%s): Circuit has IPv4 active, adding respective TLVs.", area->area_tag);
hassoaa4376e2005-09-26 17:39:48 +00001343 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001344 {
hassoaa4376e2005-09-26 17:39:48 +00001345 if (tlv_data.ipv4_int_reachs == NULL)
1346 {
1347 tlv_data.ipv4_int_reachs = list_new ();
1348 tlv_data.ipv4_int_reachs->del = free_tlv;
1349 }
hasso3fdb2dd2005-09-28 18:45:54 +00001350 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001351 {
1352 ipreach =
1353 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1354 ipreach->metrics = circuit->metrics[level - 1];
1355 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1356 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1357 (ipv4->prefix.s_addr));
Christian Franke80a8f722015-11-12 14:21:47 +01001358 inet_ntop(AF_INET, &ipreach->prefix.s_addr, buf, sizeof(buf));
1359 lsp_debug("ISIS (%s): Adding old-style IP reachability for %s/%d",
1360 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001361 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1362 }
hassof390d2c2004-09-10 20:48:21 +00001363 }
hassoaa4376e2005-09-26 17:39:48 +00001364 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001365 {
hassoaa4376e2005-09-26 17:39:48 +00001366 if (tlv_data.te_ipv4_reachs == NULL)
1367 {
1368 tlv_data.te_ipv4_reachs = list_new ();
1369 tlv_data.te_ipv4_reachs->del = free_tlv;
1370 }
hasso3fdb2dd2005-09-28 18:45:54 +00001371 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001372 {
1373 /* FIXME All this assumes that we have no sub TLVs. */
1374 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1375 sizeof (struct te_ipv4_reachability) +
1376 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001377
1378 if (area->oldmetric)
1379 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1380 else
1381 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1382
hassoaa4376e2005-09-26 17:39:48 +00001383 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1384 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1385 (ipv4->prefixlen + 7)/8);
Christian Franke80a8f722015-11-12 14:21:47 +01001386 inet_ntop(AF_INET, &ipv4->prefix.s_addr, buf, sizeof(buf));
1387 lsp_debug("ISIS (%s): Adding te-style IP reachability for %s/%d",
1388 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001389 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1390 }
hassof390d2c2004-09-10 20:48:21 +00001391 }
hassof390d2c2004-09-10 20:48:21 +00001392 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001393
jardineb5d44e2003-12-23 08:09:43 +00001394#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001395 /*
1396 * Add IPv6 reachability of this circuit
1397 */
1398 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1399 circuit->ipv6_non_link->count > 0)
1400 {
1401
1402 if (tlv_data.ipv6_reachs == NULL)
1403 {
1404 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001405 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001406 }
hasso3fdb2dd2005-09-28 18:45:54 +00001407 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001408 {
hassof390d2c2004-09-10 20:48:21 +00001409 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001410 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001411
1412 if (area->oldmetric)
1413 ip6reach->metric =
1414 htonl (circuit->metrics[level - 1].metric_default);
1415 else
1416 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1417
hassof390d2c2004-09-10 20:48:21 +00001418 ip6reach->control_info = 0;
1419 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001420 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1421 apply_mask_ipv6 (ip6prefix);
Christian Franke80a8f722015-11-12 14:21:47 +01001422
1423 inet_ntop(AF_INET6, &ip6prefix->prefix.s6_addr, buf, sizeof(buf));
1424 lsp_debug("ISIS (%s): Adding IPv6 reachability for %s/%d",
1425 area->area_tag, buf, ipv6->prefixlen);
1426
hasso67851572004-09-21 14:17:04 +00001427 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1428 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001429 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1430 }
1431 }
1432#endif /* HAVE_IPV6 */
1433
1434 switch (circuit->circ_type)
1435 {
1436 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001437 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001438 {
hassoaa4376e2005-09-26 17:39:48 +00001439 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001440 {
hassoaa4376e2005-09-26 17:39:48 +00001441 if (tlv_data.is_neighs == NULL)
1442 {
1443 tlv_data.is_neighs = list_new ();
1444 tlv_data.is_neighs->del = free_tlv;
1445 }
1446 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001447 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001448 memcpy (is_neigh->neigh_id,
1449 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1450 else
1451 memcpy (is_neigh->neigh_id,
1452 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1453 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001454 if (!memcmp (is_neigh->neigh_id, zero_id,
1455 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001456 {
1457 XFREE (MTYPE_ISIS_TLV, is_neigh);
1458 lsp_debug("ISIS (%s): No DIS for circuit, not adding old-style IS neighbor.",
1459 area->area_tag);
1460 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001461 else
Christian Franke80a8f722015-11-12 14:21:47 +01001462 {
1463 listnode_add (tlv_data.is_neighs, is_neigh);
1464 lsp_debug("ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
1465 area->area_tag, sysid_print(is_neigh->neigh_id),
1466 LSP_PSEUDO_ID(is_neigh->neigh_id));
1467 }
hassof390d2c2004-09-10 20:48:21 +00001468 }
hassoaa4376e2005-09-26 17:39:48 +00001469 if (area->newmetric)
1470 {
hassoaa4376e2005-09-26 17:39:48 +00001471 if (tlv_data.te_is_neighs == NULL)
1472 {
1473 tlv_data.te_is_neighs = list_new ();
1474 tlv_data.te_is_neighs->del = free_tlv;
1475 }
1476 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1477 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001478 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001479 memcpy (te_is_neigh->neigh_id,
1480 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1481 else
1482 memcpy (te_is_neigh->neigh_id,
1483 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001484 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001485 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001486 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001487 metric = circuit->te_metric[level - 1];
1488 SET_TE_METRIC(te_is_neigh, metric);
1489 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1490 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001491 {
1492 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1493 lsp_debug("ISIS (%s): No DIS for circuit, not adding te-style IS neighbor.",
1494 area->area_tag);
1495 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001496 else
Christian Franke80a8f722015-11-12 14:21:47 +01001497 {
1498 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1499 lsp_debug("ISIS (%s): Adding DIS %s.%02x as te-style neighbor",
1500 area->area_tag, sysid_print(te_is_neigh->neigh_id),
1501 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
1502 }
hassoaa4376e2005-09-26 17:39:48 +00001503 }
hassof390d2c2004-09-10 20:48:21 +00001504 }
Christian Franke80a8f722015-11-12 14:21:47 +01001505 else
1506 {
1507 lsp_debug("ISIS (%s): Circuit is not active for current level. Not adding IS neighbors",
1508 area->area_tag);
1509 }
hassof390d2c2004-09-10 20:48:21 +00001510 break;
1511 case CIRCUIT_T_P2P:
1512 nei = circuit->u.p2p.neighbor;
1513 if (nei && (level & nei->circuit_t))
1514 {
hassoaa4376e2005-09-26 17:39:48 +00001515 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001516 {
hassoaa4376e2005-09-26 17:39:48 +00001517 if (tlv_data.is_neighs == NULL)
1518 {
1519 tlv_data.is_neighs = list_new ();
1520 tlv_data.is_neighs->del = free_tlv;
1521 }
1522 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1523 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1524 is_neigh->metrics = circuit->metrics[level - 1];
1525 listnode_add (tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001526 lsp_debug("ISIS (%s): Adding old-style is reach for %s", area->area_tag,
1527 sysid_print(is_neigh->neigh_id));
hassof390d2c2004-09-10 20:48:21 +00001528 }
hassoaa4376e2005-09-26 17:39:48 +00001529 if (area->newmetric)
1530 {
1531 uint32_t metric;
1532
1533 if (tlv_data.te_is_neighs == NULL)
1534 {
1535 tlv_data.te_is_neighs = list_new ();
1536 tlv_data.te_is_neighs->del = free_tlv;
1537 }
1538 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1539 sizeof (struct te_is_neigh));
1540 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001541 metric = circuit->te_metric[level - 1];
1542 SET_TE_METRIC(te_is_neigh, metric);
hassoaa4376e2005-09-26 17:39:48 +00001543 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001544 lsp_debug("ISIS (%s): Adding te-style is reach for %s", area->area_tag,
1545 sysid_print(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001546 }
hassof390d2c2004-09-10 20:48:21 +00001547 }
Christian Franke80a8f722015-11-12 14:21:47 +01001548 else
1549 {
1550 lsp_debug("ISIS (%s): No adjacency for given level on this circuit. Not adding IS neighbors",
1551 area->area_tag);
1552 }
hassof390d2c2004-09-10 20:48:21 +00001553 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001554 case CIRCUIT_T_LOOPBACK:
1555 break;
hassof390d2c2004-09-10 20:48:21 +00001556 default:
1557 zlog_warn ("lsp_area_create: unknown circuit type");
1558 }
1559 }
1560
Christian Franke80a8f722015-11-12 14:21:47 +01001561 lsp_debug("ISIS (%s): LSP construction is complete. Serializing...", area->area_tag);
1562
hassof390d2c2004-09-10 20:48:21 +00001563 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1564 {
1565 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1566 lsp->tlv_data.ipv4_int_reachs = list_new ();
1567 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1568 &lsp->tlv_data.ipv4_int_reachs,
1569 IPV4_REACH_LEN, area->lsp_frag_threshold,
1570 tlv_add_ipv4_reachs);
1571 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1572 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1573 lsp0, area, level);
1574 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001575
hassoaa4376e2005-09-26 17:39:48 +00001576 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1577 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1578 * TLVs (sub TLVs!). */
1579 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1580 {
1581 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1582 lsp->tlv_data.te_ipv4_reachs = list_new ();
1583 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1584 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001585 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1586 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001587 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1588 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1589 lsp0, area, level);
1590 }
hassof390d2c2004-09-10 20:48:21 +00001591
1592#ifdef HAVE_IPV6
1593 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1594 {
1595 if (lsp->tlv_data.ipv6_reachs == NULL)
1596 lsp->tlv_data.ipv6_reachs = list_new ();
1597 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1598 &lsp->tlv_data.ipv6_reachs,
1599 IPV6_REACH_LEN, area->lsp_frag_threshold,
1600 tlv_add_ipv6_reachs);
1601 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1602 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1603 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001604 }
1605#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001606
1607 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1608 {
1609 if (lsp->tlv_data.is_neighs == NULL)
1610 lsp->tlv_data.is_neighs = list_new ();
1611 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1612 &lsp->tlv_data.is_neighs,
1613 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1614 tlv_add_is_neighs);
1615 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1616 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1617 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001618 }
jardineb5d44e2003-12-23 08:09:43 +00001619
hassoaa4376e2005-09-26 17:39:48 +00001620 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1621 {
1622 if (lsp->tlv_data.te_is_neighs == NULL)
1623 lsp->tlv_data.te_is_neighs = list_new ();
1624 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1625 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1626 tlv_add_te_is_neighs);
1627 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1628 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1629 lsp0, area, level);
1630 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001631 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001632
1633 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001634
1635 /* Validate the LSP */
1636 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1637 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1638 stream_get_endp (lsp->pdu) -
1639 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1640 &expected, &found, &tlv_data, NULL);
1641 assert (retval == ISIS_OK);
1642
jardineb5d44e2003-12-23 08:09:43 +00001643 return;
1644}
jardineb5d44e2003-12-23 08:09:43 +00001645
1646/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001647 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001648 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001649int
1650lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001651{
jardineb5d44e2003-12-23 08:09:43 +00001652 struct isis_lsp *oldlsp, *newlsp;
1653 u_int32_t seq_num = 0;
1654 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001655 u_int16_t rem_lifetime, refresh_time;
1656
1657 if ((area == NULL) || (area->is_type & level) != level)
1658 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001659
1660 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1661 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1662
1663 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001664 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1665 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001666 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001667 /* FIXME: we should actually initiate a purge */
1668 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1669 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1670 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001671 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001672 rem_lifetime = lsp_rem_lifetime (area, level);
Christian Frankef1fc1db2015-11-10 18:43:31 +01001673 newlsp = lsp_new (area, lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001674 area->is_type | area->overload_bit | area->attached_bit,
1675 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001676 newlsp->area = area;
1677 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001678
Josh Bailey3f045a02012-03-24 08:35:20 -07001679 lsp_insert (newlsp, area->lspdb[level - 1]);
1680 /* build_lsp_data (newlsp, area); */
1681 lsp_build (newlsp, area);
1682 /* time to calculate our checksum */
1683 lsp_seqnum_update (newlsp);
Christian Franke61010c32015-11-10 18:43:34 +01001684 newlsp->last_generated = time(NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001685 lsp_set_all_srmflags (newlsp);
1686
1687 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
Christian Franke61010c32015-11-10 18:43:34 +01001688
Josh Bailey3f045a02012-03-24 08:35:20 -07001689 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
Christian Franke61010c32015-11-10 18:43:34 +01001690 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001691 if (level == IS_LEVEL_1)
1692 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1693 lsp_l1_refresh, area, refresh_time);
1694 else if (level == IS_LEVEL_2)
1695 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1696 lsp_l2_refresh, area, refresh_time);
1697
1698 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001699 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001700 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1701 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1702 area->area_tag, level,
1703 rawlspid_print (newlsp->lsp_header->lsp_id),
1704 ntohl (newlsp->lsp_header->pdu_len),
1705 ntohl (newlsp->lsp_header->seq_num),
1706 ntohs (newlsp->lsp_header->checksum),
1707 ntohs (newlsp->lsp_header->rem_lifetime),
1708 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001709 }
Christian Franke61010c32015-11-10 18:43:34 +01001710 sched_debug("ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
1711 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001712
1713 return ISIS_OK;
1714}
1715
1716/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001717 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001718 */
hasso92365882005-01-18 13:53:33 +00001719static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001720lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001721{
David Lampartere8aca322012-11-27 01:10:30 +00001722 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001723 struct isis_lsp *lsp, *frag;
1724 struct listnode *node;
1725 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001726 u_int16_t rem_lifetime, refresh_time;
1727
1728 if ((area == NULL) || (area->is_type & level) != level)
1729 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001730
David Lampartere8aca322012-11-27 01:10:30 +00001731 lspdb = area->lspdb[level - 1];
1732
jardineb5d44e2003-12-23 08:09:43 +00001733 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1734 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001735
jardineb5d44e2003-12-23 08:09:43 +00001736 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001737
hassof390d2c2004-09-10 20:48:21 +00001738 if (!lsp)
1739 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001740 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1741 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001742 return ISIS_ERROR;
1743 }
1744
1745 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001746 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001747 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1748 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001749 rem_lifetime = lsp_rem_lifetime (area, level);
1750 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001751 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001752
Josh Bailey3f045a02012-03-24 08:35:20 -07001753 lsp->last_generated = time (NULL);
1754 lsp_set_all_srmflags (lsp);
1755 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1756 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001757 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001758 area->overload_bit,
1759 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001760 /* Set the lifetime values of all the fragments to the same value,
1761 * so that no fragment expires before the lsp is refreshed.
1762 */
1763 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1764 lsp_set_all_srmflags (frag);
1765 }
1766
1767 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1768 if (level == IS_LEVEL_1)
1769 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1770 lsp_l1_refresh, area, refresh_time);
1771 else if (level == IS_LEVEL_2)
1772 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1773 lsp_l2_refresh, area, refresh_time);
Christian Franke61010c32015-11-10 18:43:34 +01001774 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001775
hassof390d2c2004-09-10 20:48:21 +00001776 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1777 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001778 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
1779 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1780 area->area_tag, level,
1781 rawlspid_print (lsp->lsp_header->lsp_id),
1782 ntohl (lsp->lsp_header->pdu_len),
1783 ntohl (lsp->lsp_header->seq_num),
1784 ntohs (lsp->lsp_header->checksum),
1785 ntohs (lsp->lsp_header->rem_lifetime),
1786 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001787 }
Christian Franke61010c32015-11-10 18:43:34 +01001788 sched_debug("ISIS (%s): Rebuilt L%d LSP. Set triggered regenerate to non-pending.",
1789 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001790
jardineb5d44e2003-12-23 08:09:43 +00001791 return ISIS_OK;
1792}
1793
jardineb5d44e2003-12-23 08:09:43 +00001794/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001795 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00001796 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001797static int
1798lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001799{
1800 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001801
1802 area = THREAD_ARG (thread);
1803 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001804
jardineb5d44e2003-12-23 08:09:43 +00001805 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001806 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00001807
Josh Bailey3f045a02012-03-24 08:35:20 -07001808 if ((area->is_type & IS_LEVEL_1) == 0)
1809 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001810
Christian Franke61010c32015-11-10 18:43:34 +01001811 sched_debug("ISIS (%s): LSP L1 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07001812 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00001813}
1814
Josh Bailey3f045a02012-03-24 08:35:20 -07001815static int
1816lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001817{
1818 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001819
1820 area = THREAD_ARG (thread);
1821 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001822
jardineb5d44e2003-12-23 08:09:43 +00001823 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001824 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001825
Josh Bailey3f045a02012-03-24 08:35:20 -07001826 if ((area->is_type & IS_LEVEL_2) == 0)
1827 return ISIS_ERROR;
1828
Christian Franke61010c32015-11-10 18:43:34 +01001829 sched_debug("ISIS (%s): LSP L2 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07001830 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00001831}
1832
hassof390d2c2004-09-10 20:48:21 +00001833int
Josh Bailey3f045a02012-03-24 08:35:20 -07001834lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00001835{
1836 struct isis_lsp *lsp;
1837 u_char id[ISIS_SYS_ID_LEN + 2];
1838 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01001839 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07001840 struct listnode *cnode;
1841 struct isis_circuit *circuit;
1842 int lvl;
1843
1844 if (area == NULL)
1845 return ISIS_ERROR;
1846
Christian Franke61010c32015-11-10 18:43:34 +01001847 sched_debug("ISIS (%s): Scheduling regeneration of %s LSPs, %sincluding PSNs",
1848 area->area_tag, circuit_t2string(level), all_pseudo ? "" : "not ");
1849
hassof390d2c2004-09-10 20:48:21 +00001850 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1851 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001852 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001853
1854 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00001855 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001856 if (!((level & lvl) && (area->is_type & lvl)))
1857 continue;
1858
Christian Franke61010c32015-11-10 18:43:34 +01001859 sched_debug("ISIS (%s): Checking whether L%d needs to be scheduled",
1860 area->area_tag, lvl);
1861
Josh Bailey3f045a02012-03-24 08:35:20 -07001862 if (area->lsp_regenerate_pending[lvl - 1])
Christian Franke61010c32015-11-10 18:43:34 +01001863 {
1864 struct timeval remain = thread_timer_remain(area->t_lsp_refresh[lvl - 1]);
1865 sched_debug("ISIS (%s): Regeneration is already pending, nothing todo."
1866 " (Due in %lld.%03lld seconds)", area->area_tag,
1867 (long long)remain.tv_sec, (long long)remain.tv_usec / 1000);
1868 continue;
1869 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001870
1871 lsp = lsp_search (id, area->lspdb[lvl - 1]);
1872 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01001873 {
1874 sched_debug("ISIS (%s): We do not have any LSPs to regenerate, nothing todo.",
1875 area->area_tag);
1876 continue;
1877 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001878
hassof390d2c2004-09-10 20:48:21 +00001879 /*
1880 * Throttle avoidance
1881 */
Christian Franke61010c32015-11-10 18:43:34 +01001882 sched_debug("ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
1883 area->area_tag, (long long)lsp->last_generated, (long long)now);
Josh Bailey3f045a02012-03-24 08:35:20 -07001884 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00001885 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07001886 if (diff < area->lsp_gen_interval[lvl - 1])
1887 {
Christian Franke61010c32015-11-10 18:43:34 +01001888 timeout = 1000 * (area->lsp_gen_interval[lvl - 1] - diff);
1889 sched_debug("ISIS (%s): Scheduling in %ld ms to match configured lsp_gen_interval",
1890 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07001891 }
hassof390d2c2004-09-10 20:48:21 +00001892 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001893 {
Michael Zinggbe62b172012-10-26 11:18:19 +02001894 /*
1895 * lsps are not regenerated if lsp_regenerate function is called
1896 * directly. However if the lsp_regenerate call is queued for
1897 * later execution it works.
1898 */
Christian Franke61010c32015-11-10 18:43:34 +01001899 timeout = 100;
1900 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
1901 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
1902 }
1903
1904 area->lsp_regenerate_pending[lvl - 1] = 1;
1905 if (lvl == IS_LEVEL_1)
1906 {
1907 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
1908 lsp_l1_refresh, area, timeout);
1909 }
1910 else if (lvl == IS_LEVEL_2)
1911 {
1912 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
1913 lsp_l2_refresh, area, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07001914 }
hassof390d2c2004-09-10 20:48:21 +00001915 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001916
1917 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00001918 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001919 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
1920 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00001921 }
1922
1923 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001924}
1925
1926/*
1927 * Funcs for pseudonode LSPs
1928 */
1929
1930/*
1931 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1932 */
hasso92365882005-01-18 13:53:33 +00001933static void
hassof390d2c2004-09-10 20:48:21 +00001934lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1935 int level)
jardineb5d44e2003-12-23 08:09:43 +00001936{
1937 struct isis_adjacency *adj;
1938 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001939 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001940 struct es_neigh *es_neigh;
1941 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001942 struct listnode *node;
Christian Franke80a8f722015-11-12 14:21:47 +01001943 struct isis_area *area = circuit->area;
1944
1945 lsp_debug("ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
1946 area->area_tag, rawlspid_print(lsp->lsp_header->lsp_id),
1947 circuit->interface->name, level);
hassof390d2c2004-09-10 20:48:21 +00001948
jardineb5d44e2003-12-23 08:09:43 +00001949 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07001950 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001951 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
1952 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00001953
1954 /*
1955 * add self to IS neighbours
1956 */
hassoaa4376e2005-09-26 17:39:48 +00001957 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001958 {
hassoaa4376e2005-09-26 17:39:48 +00001959 if (lsp->tlv_data.is_neighs == NULL)
1960 {
1961 lsp->tlv_data.is_neighs = list_new ();
1962 lsp->tlv_data.is_neighs->del = free_tlv;
1963 }
1964 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001965
hassoaa4376e2005-09-26 17:39:48 +00001966 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1967 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001968 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
1969 area->area_tag, sysid_print(is_neigh->neigh_id),
1970 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001971 }
1972 if (circuit->area->newmetric)
1973 {
1974 if (lsp->tlv_data.te_is_neighs == NULL)
1975 {
1976 lsp->tlv_data.te_is_neighs = list_new ();
1977 lsp->tlv_data.te_is_neighs->del = free_tlv;
1978 }
1979 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1980
1981 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1982 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001983 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
1984 area->area_tag, sysid_print(te_is_neigh->neigh_id),
1985 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001986 }
hassof390d2c2004-09-10 20:48:21 +00001987
1988 adj_list = list_new ();
1989 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1990
hasso3fdb2dd2005-09-28 18:45:54 +00001991 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001992 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001993 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00001994 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001995 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1996 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00001997 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001998 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00001999 {
2000 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00002001 if (circuit->area->oldmetric)
2002 {
2003 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002004
hassoaa4376e2005-09-26 17:39:48 +00002005 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2006 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002007 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
2008 area->area_tag, sysid_print(is_neigh->neigh_id),
2009 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002010 }
2011 if (circuit->area->newmetric)
2012 {
2013 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
2014 sizeof (struct te_is_neigh));
2015 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2016 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002017 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
2018 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2019 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002020 }
hassof390d2c2004-09-10 20:48:21 +00002021 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002022 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00002023 {
2024 /* an ES neigbour add it, if we are building level 1 LSP */
2025 /* FIXME: the tlv-format is hard to use here */
2026 if (lsp->tlv_data.es_neighs == NULL)
2027 {
2028 lsp->tlv_data.es_neighs = list_new ();
2029 lsp->tlv_data.es_neighs->del = free_tlv;
2030 }
paul15935e92005-05-03 09:27:23 +00002031 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2032
hassof390d2c2004-09-10 20:48:21 +00002033 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00002034 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002035 lsp_debug("ISIS (%s): Adding %s as ES neighbor (peer)",
2036 area->area_tag, sysid_print(es_neigh->first_es_neigh));
hassof390d2c2004-09-10 20:48:21 +00002037 }
Christian Franke80a8f722015-11-12 14:21:47 +01002038 else
2039 {
2040 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not match",
2041 area->area_tag, sysid_print(adj->sysid));
2042 }
2043 }
2044 else
2045 {
2046 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not intersect",
2047 area->area_tag, sysid_print(adj->sysid));
hassof390d2c2004-09-10 20:48:21 +00002048 }
jardineb5d44e2003-12-23 08:09:43 +00002049 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002050 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00002051
Christian Franke80a8f722015-11-12 14:21:47 +01002052 lsp_debug("ISIS (%s): Pseudo LSP construction is complete.", area->area_tag);
2053
hassoc0fb2a52005-09-03 16:29:40 +00002054 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00002055 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00002056 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2057
jardineb5d44e2003-12-23 08:09:43 +00002058 /*
2059 * Add the authentication info if it's present
2060 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002061 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002062
2063 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2064 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2065
hassoaa4376e2005-09-26 17:39:48 +00002066 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
2067 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
2068
jardineb5d44e2003-12-23 08:09:43 +00002069 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2070 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2071
paul9985f832005-02-09 15:51:56 +00002072 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002073
Josh Bailey3f045a02012-03-24 08:35:20 -07002074 /* Recompute authentication and checksum information */
2075 lsp_auth_update (lsp);
2076 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2077 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00002078
2079 return;
2080}
2081
Josh Bailey3f045a02012-03-24 08:35:20 -07002082int
2083lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002084{
2085 dict_t *lspdb = circuit->area->lspdb[level - 1];
2086 struct isis_lsp *lsp;
2087 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07002088 u_int16_t rem_lifetime, refresh_time;
2089
2090 if ((circuit->is_type & level) != level ||
2091 (circuit->state != C_STATE_UP) ||
2092 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2093 (circuit->u.bc.is_dr[level - 1] == 0))
2094 return ISIS_ERROR;
2095
2096 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2097 LSP_FRAGMENT (lsp_id) = 0;
2098 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2099
2100 /*
2101 * If for some reason have a pseudo LSP in the db already -> regenerate
2102 */
2103 if (lsp_search (lsp_id, lspdb))
2104 return lsp_regenerate_schedule_pseudo (circuit, level);
2105
2106 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2107 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Christian Frankef1fc1db2015-11-10 18:43:31 +01002108 lsp = lsp_new (circuit->area, lsp_id, rem_lifetime, 1,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002109 circuit->area->is_type | circuit->area->attached_bit,
2110 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07002111 lsp->area = circuit->area;
2112
2113 lsp_build_pseudo (lsp, circuit, level);
2114
2115 lsp->own_lsp = 1;
2116 lsp_insert (lsp, lspdb);
2117 lsp_set_all_srmflags (lsp);
2118
2119 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2120 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
2121 circuit->lsp_regenerate_pending[level - 1] = 0;
2122 if (level == IS_LEVEL_1)
2123 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2124 lsp_l1_refresh_pseudo, circuit, refresh_time);
2125 else if (level == IS_LEVEL_2)
2126 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2127 lsp_l2_refresh_pseudo, circuit, refresh_time);
2128
2129 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2130 {
2131 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
2132 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2133 circuit->area->area_tag, level,
2134 rawlspid_print (lsp->lsp_header->lsp_id),
2135 ntohl (lsp->lsp_header->pdu_len),
2136 ntohl (lsp->lsp_header->seq_num),
2137 ntohs (lsp->lsp_header->checksum),
2138 ntohs (lsp->lsp_header->rem_lifetime),
2139 refresh_time);
2140 }
2141
2142 return ISIS_OK;
2143}
2144
2145static int
2146lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2147{
2148 dict_t *lspdb = circuit->area->lspdb[level - 1];
2149 struct isis_lsp *lsp;
2150 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2151 u_int16_t rem_lifetime, refresh_time;
2152
2153 if ((circuit->is_type & level) != level ||
2154 (circuit->state != C_STATE_UP) ||
2155 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2156 (circuit->u.bc.is_dr[level - 1] == 0))
2157 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002158
jardineb5d44e2003-12-23 08:09:43 +00002159 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002160 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2161 LSP_FRAGMENT (lsp_id) = 0;
2162
jardineb5d44e2003-12-23 08:09:43 +00002163 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002164
2165 if (!lsp)
2166 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002167 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2168 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002169 return ISIS_ERROR;
2170 }
2171 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002172
2173 lsp_build_pseudo (lsp, circuit, level);
2174
Josh Bailey3f045a02012-03-24 08:35:20 -07002175 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002176 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2177 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002178 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2179 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002180 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002181 lsp->last_generated = time (NULL);
2182 lsp_set_all_srmflags (lsp);
2183
2184 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2185 if (level == IS_LEVEL_1)
2186 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2187 lsp_l1_refresh_pseudo, circuit, refresh_time);
2188 else if (level == IS_LEVEL_2)
2189 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2190 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002191
2192 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2193 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002194 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2195 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2196 circuit->area->area_tag, level,
2197 rawlspid_print (lsp->lsp_header->lsp_id),
2198 ntohl (lsp->lsp_header->pdu_len),
2199 ntohl (lsp->lsp_header->seq_num),
2200 ntohs (lsp->lsp_header->checksum),
2201 ntohs (lsp->lsp_header->rem_lifetime),
2202 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002203 }
jardineb5d44e2003-12-23 08:09:43 +00002204
jardineb5d44e2003-12-23 08:09:43 +00002205 return ISIS_OK;
2206}
2207
Josh Bailey3f045a02012-03-24 08:35:20 -07002208/*
2209 * Something has changed or periodic refresh -> regenerate pseudo LSP
2210 */
2211static int
jardineb5d44e2003-12-23 08:09:43 +00002212lsp_l1_refresh_pseudo (struct thread *thread)
2213{
2214 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002215 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002216
hassof390d2c2004-09-10 20:48:21 +00002217 circuit = THREAD_ARG (thread);
2218
hasso13c48f72004-09-10 21:19:13 +00002219 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002220 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002221
Josh Bailey3f045a02012-03-24 08:35:20 -07002222 if ((circuit->u.bc.is_dr[0] == 0) ||
2223 (circuit->is_type & IS_LEVEL_1) == 0)
2224 {
2225 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2226 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2227 LSP_FRAGMENT (id) = 0;
2228 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2229 return ISIS_ERROR;
2230 }
hassof390d2c2004-09-10 20:48:21 +00002231
Josh Bailey3f045a02012-03-24 08:35:20 -07002232 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002233}
2234
Josh Bailey3f045a02012-03-24 08:35:20 -07002235static int
jardineb5d44e2003-12-23 08:09:43 +00002236lsp_l2_refresh_pseudo (struct thread *thread)
2237{
2238 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002239 u_char id[ISIS_SYS_ID_LEN + 2];
2240
hassof390d2c2004-09-10 20:48:21 +00002241 circuit = THREAD_ARG (thread);
2242
hasso13c48f72004-09-10 21:19:13 +00002243 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002244 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002245
Josh Bailey3f045a02012-03-24 08:35:20 -07002246 if ((circuit->u.bc.is_dr[1] == 0) ||
2247 (circuit->is_type & IS_LEVEL_2) == 0)
2248 {
2249 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2250 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2251 LSP_FRAGMENT (id) = 0;
2252 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2253 return ISIS_ERROR;
2254 }
jardineb5d44e2003-12-23 08:09:43 +00002255
Josh Bailey3f045a02012-03-24 08:35:20 -07002256 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002257}
2258
hassof390d2c2004-09-10 20:48:21 +00002259int
Josh Bailey3f045a02012-03-24 08:35:20 -07002260lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002261{
2262 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002263 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2264 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01002265 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07002266 int lvl;
Christian Franke61010c32015-11-10 18:43:34 +01002267 struct isis_area *area = circuit->area;
jardineb5d44e2003-12-23 08:09:43 +00002268
Josh Bailey3f045a02012-03-24 08:35:20 -07002269 if (circuit == NULL ||
2270 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2271 circuit->state != C_STATE_UP)
2272 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002273
Christian Franke61010c32015-11-10 18:43:34 +01002274 sched_debug("ISIS (%s): Scheduling regeneration of %s pseudo LSP for interface %s",
2275 area->area_tag, circuit_t2string(level), circuit->interface->name);
2276
Josh Bailey3f045a02012-03-24 08:35:20 -07002277 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2278 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2279 LSP_FRAGMENT (lsp_id) = 0;
2280 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002281
Josh Bailey3f045a02012-03-24 08:35:20 -07002282 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2283 {
Christian Franke61010c32015-11-10 18:43:34 +01002284 sched_debug("ISIS (%s): Checking whether L%d pseudo LSP needs to be scheduled",
2285 area->area_tag, lvl);
jardineb5d44e2003-12-23 08:09:43 +00002286
Christian Franke61010c32015-11-10 18:43:34 +01002287 if (!((level & lvl) && (circuit->is_type & lvl)))
2288 {
2289 sched_debug("ISIS (%s): Level is not active on circuit",
2290 area->area_tag);
2291 continue;
2292 }
2293
2294 if (circuit->u.bc.is_dr[lvl - 1] == 0)
2295 {
2296 sched_debug("ISIS (%s): This IS is not DR, nothing to do.",
2297 area->area_tag);
2298 continue;
2299 }
2300
2301 if (circuit->lsp_regenerate_pending[lvl - 1])
2302 {
2303 struct timeval remain =
2304 thread_timer_remain(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2305 sched_debug("ISIS (%s): Regenerate is already pending, nothing todo."
2306 " (Due in %lld.%03lld seconds)", area->area_tag,
2307 (long long)remain.tv_sec, (long long)remain.tv_usec/1000);
2308 continue;
2309 }
hassof390d2c2004-09-10 20:48:21 +00002310
Josh Bailey3f045a02012-03-24 08:35:20 -07002311 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2312 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002313 {
2314 sched_debug("ISIS (%s): Pseudonode LSP does not exist yet, nothing to regenerate.",
2315 area->area_tag);
2316 continue;
2317 }
jardineb5d44e2003-12-23 08:09:43 +00002318
Josh Bailey3f045a02012-03-24 08:35:20 -07002319 /*
2320 * Throttle avoidance
2321 */
Christian Franke61010c32015-11-10 18:43:34 +01002322 sched_debug("ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
2323 area->area_tag, (long long)lsp->last_generated, (long long) now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002324 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2325 diff = now - lsp->last_generated;
2326 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2327 {
Christian Franke61010c32015-11-10 18:43:34 +01002328 timeout = 1000 * (circuit->area->lsp_gen_interval[lvl - 1] - diff);
2329 sched_debug("ISIS (%s): Sechduling in %ld ms to match configured lsp_gen_interval",
2330 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002331 }
2332 else
2333 {
Christian Franke61010c32015-11-10 18:43:34 +01002334 timeout = 100;
2335 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2336 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2337 }
2338
2339 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2340
2341 if (lvl == IS_LEVEL_1)
2342 {
2343 THREAD_TIMER_MSEC_ON(master,
2344 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2345 lsp_l1_refresh_pseudo, circuit, timeout);
2346 }
2347 else if (lvl == IS_LEVEL_2)
2348 {
2349 THREAD_TIMER_MSEC_ON(master,
2350 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2351 lsp_l2_refresh_pseudo, circuit, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002352 }
2353 }
jardineb5d44e2003-12-23 08:09:43 +00002354
Josh Bailey3f045a02012-03-24 08:35:20 -07002355 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002356}
2357
jardineb5d44e2003-12-23 08:09:43 +00002358/*
2359 * Walk through LSPs for an area
2360 * - set remaining lifetime
2361 * - set LSPs with SRMflag set for sending
2362 */
hassof390d2c2004-09-10 20:48:21 +00002363int
jardineb5d44e2003-12-23 08:09:43 +00002364lsp_tick (struct thread *thread)
2365{
2366 struct isis_area *area;
2367 struct isis_circuit *circuit;
2368 struct isis_lsp *lsp;
2369 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002370 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002371 dnode_t *dnode, *dnode_next;
2372 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002373 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002374
2375 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002376
jardineb5d44e2003-12-23 08:09:43 +00002377 area = THREAD_ARG (thread);
2378 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002379 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002380 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002381
2382 /*
2383 * Build a list of LSPs with (any) SRMflag set
2384 * and removed the ones that have aged out
2385 */
hassof390d2c2004-09-10 20:48:21 +00002386 for (level = 0; level < ISIS_LEVELS; level++)
2387 {
2388 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002389 {
2390 for (dnode = dict_first (area->lspdb[level]);
2391 dnode != NULL; dnode = dnode_next)
2392 {
2393 dnode_next = dict_next (area->lspdb[level], dnode);
2394 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002395
Josh Bailey3f045a02012-03-24 08:35:20 -07002396 /*
2397 * The lsp rem_lifetime is kept at 0 for MaxAge or
2398 * ZeroAgeLifetime depending on explicit purge or
2399 * natural age out. So schedule spf only once when
2400 * the first time rem_lifetime becomes 0.
2401 */
2402 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2403 lsp_set_time (lsp);
2404
2405 /*
2406 * Schedule may run spf which should be done only after
2407 * the lsp rem_lifetime becomes 0 for the first time.
2408 * ISO 10589 - 7.3.16.4 first paragraph.
2409 */
2410 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2411 {
2412 /* 7.3.16.4 a) set SRM flags on all */
2413 lsp_set_all_srmflags (lsp);
2414 /* 7.3.16.4 b) retain only the header FIXME */
2415 /* 7.3.16.4 c) record the time to purge FIXME */
2416 /* run/schedule spf */
2417 /* isis_spf_schedule is called inside lsp_destroy() below;
2418 * so it is not needed here. */
2419 /* isis_spf_schedule (lsp->area, lsp->level); */
2420 }
2421
2422 if (lsp->age_out == 0)
2423 {
2424 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2425 area->area_tag,
2426 lsp->level,
2427 rawlspid_print (lsp->lsp_header->lsp_id),
2428 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002429#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002430 if (lsp->from_topology)
2431 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002432#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002433 lsp_destroy (lsp);
2434 lsp = NULL;
2435 dict_delete_free (area->lspdb[level], dnode);
2436 }
2437 else if (flags_any_set (lsp->SRMflags))
2438 listnode_add (lsp_list, lsp);
2439 }
jardineb5d44e2003-12-23 08:09:43 +00002440
Josh Bailey3f045a02012-03-24 08:35:20 -07002441 /*
2442 * Send LSPs on circuits indicated by the SRMflags
2443 */
2444 if (listcount (lsp_list) > 0)
2445 {
paul1eb8ef22005-04-07 07:30:20 +00002446 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002447 {
2448 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2449 if (circuit->lsp_queue == NULL ||
2450 diff < MIN_LSP_TRANS_INTERVAL)
2451 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002452 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002453 {
2454 if (circuit->upadjcount[lsp->level - 1] &&
2455 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2456 {
2457 /* Add the lsp only if it is not already in lsp
2458 * queue */
2459 if (! listnode_lookup (circuit->lsp_queue, lsp))
2460 {
2461 listnode_add (circuit->lsp_queue, lsp);
2462 thread_add_event (master, send_lsp, circuit, 0);
2463 }
2464 }
2465 }
2466 }
2467 list_delete_all_node (lsp_list);
2468 }
2469 }
jardineb5d44e2003-12-23 08:09:43 +00002470 }
jardineb5d44e2003-12-23 08:09:43 +00002471
2472 list_delete (lsp_list);
2473
2474 return ISIS_OK;
2475}
2476
jardineb5d44e2003-12-23 08:09:43 +00002477void
Josh Bailey3f045a02012-03-24 08:35:20 -07002478lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002479{
2480 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002481 u_int16_t seq_num;
2482 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002483
jardineb5d44e2003-12-23 08:09:43 +00002484 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002485 if (!lsp)
2486 return;
hassof390d2c2004-09-10 20:48:21 +00002487
Josh Bailey3f045a02012-03-24 08:35:20 -07002488 /* store old values */
2489 seq_num = lsp->lsp_header->seq_num;
2490 lsp_bits = lsp->lsp_header->lsp_bits;
2491
2492 /* reset stream */
2493 lsp_clear_data (lsp);
2494 stream_reset (lsp->pdu);
2495
2496 /* update header */
2497 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2498 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2499 lsp->lsp_header->checksum = 0;
2500 lsp->lsp_header->seq_num = seq_num;
2501 lsp->lsp_header->rem_lifetime = 0;
2502 lsp->lsp_header->lsp_bits = lsp_bits;
2503 lsp->level = level;
2504 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2505 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2506
2507 /*
2508 * Add and update the authentication info if its present
2509 */
2510 lsp_auth_add (lsp);
2511 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2512 lsp_auth_update (lsp);
2513 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2514 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2515
2516 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002517
jardineb5d44e2003-12-23 08:09:43 +00002518 return;
2519}
2520
2521/*
2522 * Purge own LSP that is received and we don't have.
2523 * -> Do as in 7.3.16.4
2524 */
2525void
Christian Franke749e87a2015-11-10 18:21:44 +01002526lsp_purge_non_exist (int level,
2527 struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +00002528 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002529{
2530 struct isis_lsp *lsp;
2531
2532 /*
2533 * We need to create the LSP to be purged
2534 */
hassoaac372f2005-09-01 17:52:33 +00002535 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002536 lsp->area = area;
Christian Franke749e87a2015-11-10 18:21:44 +01002537 lsp->level = level;
Christian Frankef1fc1db2015-11-10 18:43:31 +01002538 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
hassof390d2c2004-09-10 20:48:21 +00002539 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002540 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002541 : L2_LINK_STATE);
2542 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2543 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002544 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002545 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002546
jardineb5d44e2003-12-23 08:09:43 +00002547 /*
jardineb5d44e2003-12-23 08:09:43 +00002548 * Set the remaining lifetime to 0
2549 */
2550 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002551
2552 /*
2553 * Add and update the authentication info if its present
2554 */
2555 lsp_auth_add (lsp);
2556 lsp_auth_update (lsp);
2557
2558 /*
2559 * Update the PDU length to header plus any authentication TLV.
2560 */
2561 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2562
jardineb5d44e2003-12-23 08:09:43 +00002563 /*
2564 * Put the lsp into LSPdb
2565 */
hassof390d2c2004-09-10 20:48:21 +00002566 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002567
2568 /*
2569 * Send in to whole area
2570 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002571 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002572
jardineb5d44e2003-12-23 08:09:43 +00002573 return;
2574}
2575
Josh Bailey3f045a02012-03-24 08:35:20 -07002576void lsp_set_all_srmflags (struct isis_lsp *lsp)
2577{
2578 struct listnode *node;
2579 struct isis_circuit *circuit;
2580
2581 assert (lsp);
2582
2583 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2584
2585 if (lsp->area)
2586 {
2587 struct list *circuit_list = lsp->area->circuit_list;
2588 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2589 {
2590 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2591 }
2592 }
2593}
2594
jardineb5d44e2003-12-23 08:09:43 +00002595#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002596static int
jardineb5d44e2003-12-23 08:09:43 +00002597top_lsp_refresh (struct thread *thread)
2598{
hassof390d2c2004-09-10 20:48:21 +00002599 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002600 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002601
2602 lsp = THREAD_ARG (thread);
2603 assert (lsp);
2604
2605 lsp->t_lsp_top_ref = NULL;
2606
hassof1082d12005-09-19 04:23:34 +00002607 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002608
Josh Bailey3f045a02012-03-24 08:35:20 -07002609 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002610 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2611 {
hasso529d65b2004-12-24 00:14:50 +00002612 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2613 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002614 }
hassod3d74742005-09-28 18:30:51 +00002615 /* Refresh dynamic hostname in the cache. */
2616 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2617 IS_LEVEL_1);
2618
David Lampartera47c5832012-06-21 09:55:38 +02002619 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002620 lsp->area->overload_bit,
2621 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002622 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2623 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002624
David Lamparterf50ee932015-03-04 07:13:38 +01002625 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002626 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002627 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002628
2629 return ISIS_OK;
2630}
2631
2632void
2633generate_topology_lsps (struct isis_area *area)
2634{
2635 struct listnode *node;
2636 int i, max = 0;
2637 struct arc *arc;
2638 u_char lspid[ISIS_SYS_ID_LEN + 2];
2639 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002640 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002641
2642 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002643 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002644 {
2645 if (arc->from_node > max)
2646 max = arc->from_node;
2647 if (arc->to_node > max)
2648 max = arc->to_node;
2649 }
jardineb5d44e2003-12-23 08:09:43 +00002650
hassof390d2c2004-09-10 20:48:21 +00002651 for (i = 1; i < (max + 1); i++)
2652 {
2653 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2654 LSP_PSEUDO_ID (lspid) = 0x00;
2655 LSP_FRAGMENT (lspid) = 0x00;
2656 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2657 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002658
Josh Bailey3f045a02012-03-24 08:35:20 -07002659 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Christian Frankef1fc1db2015-11-10 18:43:31 +01002660 lsp = lsp_new (area, lspid, rem_lifetime, 1,
2661 IS_LEVEL_1 | area->overload_bit | area->attached_bit,
2662 0, 1);
hassof1082d12005-09-19 04:23:34 +00002663 if (!lsp)
2664 return;
Josh Bailey3f045a02012-03-24 08:35:20 -07002665 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002666
hassof1082d12005-09-19 04:23:34 +00002667 /* Creating LSP data based on topology info. */
2668 build_topology_lsp_data (lsp, area, i);
2669 /* Checksum is also calculated here. */
2670 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002671 /* Take care of inserting dynamic hostname into cache. */
2672 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002673
Josh Bailey3f045a02012-03-24 08:35:20 -07002674 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002675 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002676 refresh_time);
2677 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002678 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002679 }
jardineb5d44e2003-12-23 08:09:43 +00002680}
2681
2682void
2683remove_topology_lsps (struct isis_area *area)
2684{
2685 struct isis_lsp *lsp;
2686 dnode_t *dnode, *dnode_next;
2687
2688 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002689 while (dnode != NULL)
2690 {
2691 dnode_next = dict_next (area->lspdb[0], dnode);
2692 lsp = dnode_get (dnode);
2693 if (lsp->from_topology)
2694 {
2695 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2696 lsp_destroy (lsp);
2697 dict_delete (area->lspdb[0], dnode);
2698 }
2699 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002700 }
jardineb5d44e2003-12-23 08:09:43 +00002701}
2702
2703void
hassof390d2c2004-09-10 20:48:21 +00002704build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002705 int lsp_top_num)
2706{
hasso3fdb2dd2005-09-28 18:45:54 +00002707 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002708 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002709 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002710 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002711 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002712 struct tlvs tlv_data;
2713 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002714
hassof1082d12005-09-19 04:23:34 +00002715 /* Add area addresses. FIXME: Is it needed at all? */
2716 if (lsp->tlv_data.area_addrs == NULL)
2717 lsp->tlv_data.area_addrs = list_new ();
2718 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002719
hassof1082d12005-09-19 04:23:34 +00002720 if (lsp->tlv_data.nlpids == NULL)
2721 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2722 lsp->tlv_data.nlpids->count = 1;
2723 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002724
hassof1082d12005-09-19 04:23:34 +00002725 if (area->dynhostname)
2726 {
2727 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2728 sizeof (struct hostname));
2729 memset (buff, 0x00, 200);
2730 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2731 "feedme", lsp_top_num);
2732 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2733 lsp->tlv_data.hostname->namelen = strlen (buff);
2734 }
2735
2736 if (lsp->tlv_data.nlpids)
2737 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2738 if (lsp->tlv_data.hostname)
2739 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2740 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2741 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2742
2743 memset (&tlv_data, 0, sizeof (struct tlvs));
2744 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002745 {
2746 tlv_data.is_neighs = list_new ();
2747 tlv_data.is_neighs->del = free_tlv;
2748 }
hassof1082d12005-09-19 04:23:34 +00002749
2750 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002751 if (lsp_top_num == 1)
2752 {
hasso3fdb2dd2005-09-28 18:45:54 +00002753 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002754
hassof390d2c2004-09-10 20:48:21 +00002755 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002756 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002757 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2758 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002759 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2760 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2761 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002762 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002763 }
hassof390d2c2004-09-10 20:48:21 +00002764
hassof1082d12005-09-19 04:23:34 +00002765 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002766 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002767 {
hassof1082d12005-09-19 04:23:34 +00002768 int to_lsp = 0;
2769
2770 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2771 continue;
2772
2773 if (lsp_top_num == arc->from_node)
2774 to_lsp = arc->to_node;
2775 else
2776 to_lsp = arc->from_node;
2777
hasso9551eea2005-09-28 18:26:25 +00002778 if (area->oldmetric)
2779 {
2780 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002781
hasso9551eea2005-09-28 18:26:25 +00002782 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2783 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2784 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2785 is_neigh->metrics.metric_default = arc->distance;
2786 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2787 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2788 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2789 listnode_add (tlv_data.is_neighs, is_neigh);
2790 }
2791
2792 if (area->newmetric)
2793 {
hasso9551eea2005-09-28 18:26:25 +00002794 if (tlv_data.te_is_neighs == NULL)
2795 {
2796 tlv_data.te_is_neighs = list_new ();
2797 tlv_data.te_is_neighs->del = free_tlv;
2798 }
2799 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2800 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2801 ISIS_SYS_ID_LEN);
2802 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2803 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07002804 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00002805 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2806 }
hassof390d2c2004-09-10 20:48:21 +00002807 }
hassof1082d12005-09-19 04:23:34 +00002808
2809 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2810 {
2811 if (lsp->tlv_data.is_neighs == NULL)
2812 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002813 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002814 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2815 tlv_add_is_neighs);
2816 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2817 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2818 lsp0, area, IS_LEVEL_1);
2819 }
2820
hasso9551eea2005-09-28 18:26:25 +00002821 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2822 {
2823 if (lsp->tlv_data.te_is_neighs == NULL)
2824 lsp->tlv_data.te_is_neighs = list_new ();
2825 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2826 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2827 tlv_add_te_is_neighs);
2828 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2829 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2830 lsp0, area, IS_LEVEL_1);
2831 }
2832
hassof1082d12005-09-19 04:23:34 +00002833 free_tlvs (&tlv_data);
2834 return;
jardineb5d44e2003-12-23 08:09:43 +00002835}
2836#endif /* TOPOLOGY_GENERATE */