blob: 2b478b16925e40586f50acde6d9f3c0eb529769b [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 */
Christian Franke9dfcca62015-11-10 18:32:11 +01001090 /* N.B. this calucation is acceptable since rem_lifetime is in [332,65535] at
1091 * this point */
Josh Bailey3f045a02012-03-24 08:35:20 -07001092 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1093 rem_lifetime = area->max_lsp_lifetime[level - 1];
1094
1095 return rem_lifetime;
1096}
1097
1098static u_int16_t
1099lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1100{
1101 struct isis_area *area = lsp->area;
1102 int level = lsp->level;
1103 u_int16_t refresh_time;
1104
1105 /* Add jitter to LSP refresh time */
1106 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1107 MAX_LSP_GEN_JITTER);
1108
1109 /* RFC 4444 : make sure the refresh time is at least less than 300
1110 * of the remaining lifetime and more than gen interval */
1111 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1112 refresh_time > (rem_lifetime - 300))
1113 refresh_time = rem_lifetime - 300;
1114
Christian Franke9dfcca62015-11-10 18:32:11 +01001115 /* In cornercases, refresh_time might be <= lsp_gen_interval, however
1116 * we accept this violation to satisfy refresh_time <= rem_lifetime - 300 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001117
1118 return refresh_time;
1119}
1120
hasso92365882005-01-18 13:53:33 +00001121static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001122lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1123 int level)
jardineb5d44e2003-12-23 08:09:43 +00001124{
1125 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001126 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1127
jardineb5d44e2003-12-23 08:09:43 +00001128 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1129 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001130 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001131 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001132 if (lsp)
1133 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001134 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001135 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001136 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001137 }
Christian Frankef1fc1db2015-11-10 18:43:31 +01001138 lsp = lsp_new (area, frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001139 lsp_bits_generate (level, area->overload_bit,
1140 area->attached_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001141 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001142 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001143 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001144 listnode_add (lsp0->lspu.frags, lsp);
1145 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001146 return lsp;
1147}
1148
1149/*
1150 * Builds the LSP data part. This func creates a new frag whenever
1151 * area->lsp_frag_threshold is exceeded.
1152 */
hasso92365882005-01-18 13:53:33 +00001153static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001154lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001155{
1156 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001157 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001158 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001159 int level = lsp->level;
1160 struct isis_circuit *circuit;
1161 struct prefix_ipv4 *ipv4;
1162 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001163 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001164 struct isis_adjacency *nei;
1165#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001166 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001167 struct ipv6_reachability *ip6reach;
1168#endif /* HAVE_IPV6 */
1169 struct tlvs tlv_data;
1170 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001171 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001172 uint32_t expected = 0, found = 0;
1173 uint32_t metric;
1174 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1175 int retval = ISIS_OK;
Christian Franke80a8f722015-11-12 14:21:47 +01001176 char buf[BUFSIZ];
1177
1178 lsp_debug("ISIS (%s): Constructing local system LSP for level %d", area->area_tag, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001179
1180 /*
1181 * Building the zero lsp
1182 */
1183 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1184
1185 /* Reset stream endp. Stream is always there and on every LSP refresh only
1186 * TLV part of it is overwritten. So we must seek past header we will not
1187 * touch. */
1188 stream_reset (lsp->pdu);
1189 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1190
1191 /*
1192 * Add the authentication info if its present
1193 */
1194 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001195
1196 /*
1197 * First add the tlvs related to area
1198 */
hassof390d2c2004-09-10 20:48:21 +00001199
jardineb5d44e2003-12-23 08:09:43 +00001200 /* Area addresses */
1201 if (lsp->tlv_data.area_addrs == NULL)
1202 lsp->tlv_data.area_addrs = list_new ();
1203 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001204 if (listcount (lsp->tlv_data.area_addrs) > 0)
1205 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1206
jardineb5d44e2003-12-23 08:09:43 +00001207 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001208 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001209#ifdef HAVE_IPV6
1210 || area->ipv6_circuits > 0
1211#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001212 )
jardineb5d44e2003-12-23 08:09:43 +00001213 {
hassoaac372f2005-09-01 17:52:33 +00001214 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001215 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001216 if (area->ip_circuits > 0)
1217 {
Christian Franke80a8f722015-11-12 14:21:47 +01001218 lsp_debug("ISIS (%s): Found IPv4 circuit, adding IPv4 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001219 lsp->tlv_data.nlpids->count++;
1220 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1221 }
jardineb5d44e2003-12-23 08:09:43 +00001222#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001223 if (area->ipv6_circuits > 0)
1224 {
Christian Franke80a8f722015-11-12 14:21:47 +01001225 lsp_debug("ISIS (%s): Found IPv6 circuit, adding IPv6 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001226 lsp->tlv_data.nlpids->count++;
1227 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1228 NLPID_IPV6;
1229 }
jardineb5d44e2003-12-23 08:09:43 +00001230#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001231 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001232 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001233
jardineb5d44e2003-12-23 08:09:43 +00001234 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001235 if (area->dynhostname)
1236 {
Christian Frankef35169e2015-11-12 14:09:08 +01001237 const char *hostname = unix_hostname();
1238 size_t hostname_len = strlen(hostname);
1239
hassof390d2c2004-09-10 20:48:21 +00001240 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1241 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001242
Christian Frankef35169e2015-11-12 14:09:08 +01001243 strncpy((char *)lsp->tlv_data.hostname->name, hostname,
1244 sizeof(lsp->tlv_data.hostname->name));
1245 if (hostname_len <= MAX_TLV_LEN)
1246 lsp->tlv_data.hostname->namelen = hostname_len;
1247 else
1248 lsp->tlv_data.hostname->namelen = MAX_TLV_LEN;
1249
Christian Franke80a8f722015-11-12 14:21:47 +01001250 lsp_debug("ISIS (%s): Adding dynamic hostname '%.*s'", area->area_tag,
1251 lsp->tlv_data.hostname->namelen, lsp->tlv_data.hostname->name);
Josh Bailey3f045a02012-03-24 08:35:20 -07001252 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001253 }
Christian Franke80a8f722015-11-12 14:21:47 +01001254 else
1255 {
1256 lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)", area->area_tag);
1257 }
jardineb5d44e2003-12-23 08:09:43 +00001258
hasso81ad8f62005-09-26 17:58:24 +00001259 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1260 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1261 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001262 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001263 {
Christian Franke80a8f722015-11-12 14:21:47 +01001264 inet_ntop(AF_INET, &isis->router_id, buf, sizeof(buf));
1265 lsp_debug("ISIS (%s): Adding router ID %s as IPv4 tlv.", area->area_tag, buf);
hasso18a6dce2004-10-03 18:18:34 +00001266 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001267 {
1268 lsp->tlv_data.ipv4_addrs = list_new ();
1269 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1270 }
hasso18a6dce2004-10-03 18:18:34 +00001271
1272 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001273 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001274 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001275 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001276
hasso81ad8f62005-09-26 17:58:24 +00001277 /* Exactly same data is put into TE router ID TLV, but only if new style
1278 * TLV's are in use. */
1279 if (area->newmetric)
1280 {
Christian Franke80a8f722015-11-12 14:21:47 +01001281 lsp_debug("ISIS (%s): Adding router ID also as TE router ID tlv.", area->area_tag);
hasso81ad8f62005-09-26 17:58:24 +00001282 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1283 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001284 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1285 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1286 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001287 }
hasso18a6dce2004-10-03 18:18:34 +00001288 }
Christian Franke80a8f722015-11-12 14:21:47 +01001289 else
1290 {
1291 lsp_debug("ISIS (%s): Router ID is unset. Not adding tlv.", area->area_tag);
1292 }
hassof1082d12005-09-19 04:23:34 +00001293
hasso81ad8f62005-09-26 17:58:24 +00001294 memset (&tlv_data, 0, sizeof (struct tlvs));
1295
hassof1082d12005-09-19 04:23:34 +00001296#ifdef TOPOLOGY_GENERATE
1297 /* If topology exists (and we create topology for level 1 only), create
1298 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001299 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001300 {
1301 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001302 {
1303 tlv_data.is_neighs = list_new ();
1304 tlv_data.is_neighs->del = free_tlv;
1305 }
hasso3fdb2dd2005-09-28 18:45:54 +00001306 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001307
1308 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1309 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1310 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1311 is_neigh->metrics.metric_default = 0x01;
1312 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1313 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1314 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1315 listnode_add (tlv_data.is_neighs, is_neigh);
1316 }
1317#endif /* TOPOLOGY_GENERATE */
1318
Christian Franke80a8f722015-11-12 14:21:47 +01001319 lsp_debug("ISIS (%s): Adding circuit specific information.", area->area_tag);
1320
hasso18a6dce2004-10-03 18:18:34 +00001321 /*
jardineb5d44e2003-12-23 08:09:43 +00001322 * Then build lists of tlvs related to circuits
1323 */
hasso3fdb2dd2005-09-28 18:45:54 +00001324 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001325 {
Christian Franke80a8f722015-11-12 14:21:47 +01001326 if (!circuit->interface)
1327 lsp_debug("ISIS (%s): Processing %s circuit %p with unknown interface",
1328 area->area_tag, circuit_type2string(circuit->circ_type), circuit);
1329 else
1330 lsp_debug("ISIS (%s): Processing %s circuit %s",
1331 area->area_tag, circuit_type2string(circuit->circ_type), circuit->interface->name);
1332
hassof390d2c2004-09-10 20:48:21 +00001333 if (circuit->state != C_STATE_UP)
Christian Franke80a8f722015-11-12 14:21:47 +01001334 {
1335 lsp_debug("ISIS (%s): Circuit is not up, ignoring.", area->area_tag);
1336 continue;
1337 }
jardineb5d44e2003-12-23 08:09:43 +00001338
hassof390d2c2004-09-10 20:48:21 +00001339 /*
1340 * Add IPv4 internal reachability of this circuit
1341 */
1342 if (circuit->ip_router && circuit->ip_addrs &&
1343 circuit->ip_addrs->count > 0)
1344 {
Christian Franke80a8f722015-11-12 14:21:47 +01001345 lsp_debug("ISIS (%s): Circuit has IPv4 active, adding respective TLVs.", area->area_tag);
hassoaa4376e2005-09-26 17:39:48 +00001346 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001347 {
hassoaa4376e2005-09-26 17:39:48 +00001348 if (tlv_data.ipv4_int_reachs == NULL)
1349 {
1350 tlv_data.ipv4_int_reachs = list_new ();
1351 tlv_data.ipv4_int_reachs->del = free_tlv;
1352 }
hasso3fdb2dd2005-09-28 18:45:54 +00001353 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001354 {
1355 ipreach =
1356 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1357 ipreach->metrics = circuit->metrics[level - 1];
1358 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1359 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1360 (ipv4->prefix.s_addr));
Christian Franke80a8f722015-11-12 14:21:47 +01001361 inet_ntop(AF_INET, &ipreach->prefix.s_addr, buf, sizeof(buf));
1362 lsp_debug("ISIS (%s): Adding old-style IP reachability for %s/%d",
1363 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001364 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1365 }
hassof390d2c2004-09-10 20:48:21 +00001366 }
hassoaa4376e2005-09-26 17:39:48 +00001367 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001368 {
hassoaa4376e2005-09-26 17:39:48 +00001369 if (tlv_data.te_ipv4_reachs == NULL)
1370 {
1371 tlv_data.te_ipv4_reachs = list_new ();
1372 tlv_data.te_ipv4_reachs->del = free_tlv;
1373 }
hasso3fdb2dd2005-09-28 18:45:54 +00001374 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001375 {
1376 /* FIXME All this assumes that we have no sub TLVs. */
1377 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1378 sizeof (struct te_ipv4_reachability) +
1379 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001380
1381 if (area->oldmetric)
1382 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1383 else
1384 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1385
hassoaa4376e2005-09-26 17:39:48 +00001386 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1387 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1388 (ipv4->prefixlen + 7)/8);
Christian Franke80a8f722015-11-12 14:21:47 +01001389 inet_ntop(AF_INET, &ipv4->prefix.s_addr, buf, sizeof(buf));
1390 lsp_debug("ISIS (%s): Adding te-style IP reachability for %s/%d",
1391 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001392 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1393 }
hassof390d2c2004-09-10 20:48:21 +00001394 }
hassof390d2c2004-09-10 20:48:21 +00001395 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001396
jardineb5d44e2003-12-23 08:09:43 +00001397#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001398 /*
1399 * Add IPv6 reachability of this circuit
1400 */
1401 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1402 circuit->ipv6_non_link->count > 0)
1403 {
1404
1405 if (tlv_data.ipv6_reachs == NULL)
1406 {
1407 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001408 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001409 }
hasso3fdb2dd2005-09-28 18:45:54 +00001410 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001411 {
hassof390d2c2004-09-10 20:48:21 +00001412 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001413 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001414
1415 if (area->oldmetric)
1416 ip6reach->metric =
1417 htonl (circuit->metrics[level - 1].metric_default);
1418 else
1419 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1420
hassof390d2c2004-09-10 20:48:21 +00001421 ip6reach->control_info = 0;
1422 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001423 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1424 apply_mask_ipv6 (ip6prefix);
Christian Franke80a8f722015-11-12 14:21:47 +01001425
1426 inet_ntop(AF_INET6, &ip6prefix->prefix.s6_addr, buf, sizeof(buf));
1427 lsp_debug("ISIS (%s): Adding IPv6 reachability for %s/%d",
1428 area->area_tag, buf, ipv6->prefixlen);
1429
hasso67851572004-09-21 14:17:04 +00001430 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1431 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001432 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1433 }
1434 }
1435#endif /* HAVE_IPV6 */
1436
1437 switch (circuit->circ_type)
1438 {
1439 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001440 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001441 {
hassoaa4376e2005-09-26 17:39:48 +00001442 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001443 {
hassoaa4376e2005-09-26 17:39:48 +00001444 if (tlv_data.is_neighs == NULL)
1445 {
1446 tlv_data.is_neighs = list_new ();
1447 tlv_data.is_neighs->del = free_tlv;
1448 }
1449 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001450 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001451 memcpy (is_neigh->neigh_id,
1452 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1453 else
1454 memcpy (is_neigh->neigh_id,
1455 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1456 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001457 if (!memcmp (is_neigh->neigh_id, zero_id,
1458 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001459 {
1460 XFREE (MTYPE_ISIS_TLV, is_neigh);
1461 lsp_debug("ISIS (%s): No DIS for circuit, not adding old-style IS neighbor.",
1462 area->area_tag);
1463 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001464 else
Christian Franke80a8f722015-11-12 14:21:47 +01001465 {
1466 listnode_add (tlv_data.is_neighs, is_neigh);
1467 lsp_debug("ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
1468 area->area_tag, sysid_print(is_neigh->neigh_id),
1469 LSP_PSEUDO_ID(is_neigh->neigh_id));
1470 }
hassof390d2c2004-09-10 20:48:21 +00001471 }
hassoaa4376e2005-09-26 17:39:48 +00001472 if (area->newmetric)
1473 {
hassoaa4376e2005-09-26 17:39:48 +00001474 if (tlv_data.te_is_neighs == NULL)
1475 {
1476 tlv_data.te_is_neighs = list_new ();
1477 tlv_data.te_is_neighs->del = free_tlv;
1478 }
1479 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1480 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001481 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001482 memcpy (te_is_neigh->neigh_id,
1483 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1484 else
1485 memcpy (te_is_neigh->neigh_id,
1486 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001487 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001488 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001489 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001490 metric = circuit->te_metric[level - 1];
1491 SET_TE_METRIC(te_is_neigh, metric);
1492 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1493 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001494 {
1495 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1496 lsp_debug("ISIS (%s): No DIS for circuit, not adding te-style IS neighbor.",
1497 area->area_tag);
1498 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001499 else
Christian Franke80a8f722015-11-12 14:21:47 +01001500 {
1501 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1502 lsp_debug("ISIS (%s): Adding DIS %s.%02x as te-style neighbor",
1503 area->area_tag, sysid_print(te_is_neigh->neigh_id),
1504 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
1505 }
hassoaa4376e2005-09-26 17:39:48 +00001506 }
hassof390d2c2004-09-10 20:48:21 +00001507 }
Christian Franke80a8f722015-11-12 14:21:47 +01001508 else
1509 {
1510 lsp_debug("ISIS (%s): Circuit is not active for current level. Not adding IS neighbors",
1511 area->area_tag);
1512 }
hassof390d2c2004-09-10 20:48:21 +00001513 break;
1514 case CIRCUIT_T_P2P:
1515 nei = circuit->u.p2p.neighbor;
1516 if (nei && (level & nei->circuit_t))
1517 {
hassoaa4376e2005-09-26 17:39:48 +00001518 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001519 {
hassoaa4376e2005-09-26 17:39:48 +00001520 if (tlv_data.is_neighs == NULL)
1521 {
1522 tlv_data.is_neighs = list_new ();
1523 tlv_data.is_neighs->del = free_tlv;
1524 }
1525 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1526 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1527 is_neigh->metrics = circuit->metrics[level - 1];
1528 listnode_add (tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001529 lsp_debug("ISIS (%s): Adding old-style is reach for %s", area->area_tag,
1530 sysid_print(is_neigh->neigh_id));
hassof390d2c2004-09-10 20:48:21 +00001531 }
hassoaa4376e2005-09-26 17:39:48 +00001532 if (area->newmetric)
1533 {
1534 uint32_t metric;
1535
1536 if (tlv_data.te_is_neighs == NULL)
1537 {
1538 tlv_data.te_is_neighs = list_new ();
1539 tlv_data.te_is_neighs->del = free_tlv;
1540 }
1541 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1542 sizeof (struct te_is_neigh));
1543 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001544 metric = circuit->te_metric[level - 1];
1545 SET_TE_METRIC(te_is_neigh, metric);
hassoaa4376e2005-09-26 17:39:48 +00001546 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001547 lsp_debug("ISIS (%s): Adding te-style is reach for %s", area->area_tag,
1548 sysid_print(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001549 }
hassof390d2c2004-09-10 20:48:21 +00001550 }
Christian Franke80a8f722015-11-12 14:21:47 +01001551 else
1552 {
1553 lsp_debug("ISIS (%s): No adjacency for given level on this circuit. Not adding IS neighbors",
1554 area->area_tag);
1555 }
hassof390d2c2004-09-10 20:48:21 +00001556 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001557 case CIRCUIT_T_LOOPBACK:
1558 break;
hassof390d2c2004-09-10 20:48:21 +00001559 default:
1560 zlog_warn ("lsp_area_create: unknown circuit type");
1561 }
1562 }
1563
Christian Franke80a8f722015-11-12 14:21:47 +01001564 lsp_debug("ISIS (%s): LSP construction is complete. Serializing...", area->area_tag);
1565
hassof390d2c2004-09-10 20:48:21 +00001566 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1567 {
1568 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1569 lsp->tlv_data.ipv4_int_reachs = list_new ();
1570 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1571 &lsp->tlv_data.ipv4_int_reachs,
1572 IPV4_REACH_LEN, area->lsp_frag_threshold,
1573 tlv_add_ipv4_reachs);
1574 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1575 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1576 lsp0, area, level);
1577 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001578
hassoaa4376e2005-09-26 17:39:48 +00001579 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1580 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1581 * TLVs (sub TLVs!). */
1582 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1583 {
1584 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1585 lsp->tlv_data.te_ipv4_reachs = list_new ();
1586 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1587 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001588 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1589 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001590 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1591 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1592 lsp0, area, level);
1593 }
hassof390d2c2004-09-10 20:48:21 +00001594
1595#ifdef HAVE_IPV6
1596 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1597 {
1598 if (lsp->tlv_data.ipv6_reachs == NULL)
1599 lsp->tlv_data.ipv6_reachs = list_new ();
1600 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1601 &lsp->tlv_data.ipv6_reachs,
1602 IPV6_REACH_LEN, area->lsp_frag_threshold,
1603 tlv_add_ipv6_reachs);
1604 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1605 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1606 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001607 }
1608#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001609
1610 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1611 {
1612 if (lsp->tlv_data.is_neighs == NULL)
1613 lsp->tlv_data.is_neighs = list_new ();
1614 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1615 &lsp->tlv_data.is_neighs,
1616 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1617 tlv_add_is_neighs);
1618 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1619 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1620 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001621 }
jardineb5d44e2003-12-23 08:09:43 +00001622
hassoaa4376e2005-09-26 17:39:48 +00001623 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1624 {
1625 if (lsp->tlv_data.te_is_neighs == NULL)
1626 lsp->tlv_data.te_is_neighs = list_new ();
1627 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1628 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1629 tlv_add_te_is_neighs);
1630 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1631 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1632 lsp0, area, level);
1633 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001634 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001635
1636 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001637
1638 /* Validate the LSP */
1639 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1640 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1641 stream_get_endp (lsp->pdu) -
1642 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1643 &expected, &found, &tlv_data, NULL);
1644 assert (retval == ISIS_OK);
1645
jardineb5d44e2003-12-23 08:09:43 +00001646 return;
1647}
jardineb5d44e2003-12-23 08:09:43 +00001648
1649/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001650 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001651 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001652int
1653lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001654{
jardineb5d44e2003-12-23 08:09:43 +00001655 struct isis_lsp *oldlsp, *newlsp;
1656 u_int32_t seq_num = 0;
1657 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001658 u_int16_t rem_lifetime, refresh_time;
1659
1660 if ((area == NULL) || (area->is_type & level) != level)
1661 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001662
1663 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1664 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1665
1666 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001667 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1668 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001669 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001670 /* FIXME: we should actually initiate a purge */
1671 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1672 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1673 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001674 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001675 rem_lifetime = lsp_rem_lifetime (area, level);
Christian Frankef1fc1db2015-11-10 18:43:31 +01001676 newlsp = lsp_new (area, lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001677 area->is_type | area->overload_bit | area->attached_bit,
1678 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001679 newlsp->area = area;
1680 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001681
Josh Bailey3f045a02012-03-24 08:35:20 -07001682 lsp_insert (newlsp, area->lspdb[level - 1]);
1683 /* build_lsp_data (newlsp, area); */
1684 lsp_build (newlsp, area);
1685 /* time to calculate our checksum */
1686 lsp_seqnum_update (newlsp);
Christian Franke61010c32015-11-10 18:43:34 +01001687 newlsp->last_generated = time(NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001688 lsp_set_all_srmflags (newlsp);
1689
1690 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
Christian Franke61010c32015-11-10 18:43:34 +01001691
Josh Bailey3f045a02012-03-24 08:35:20 -07001692 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
Christian Franke61010c32015-11-10 18:43:34 +01001693 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001694 if (level == IS_LEVEL_1)
1695 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1696 lsp_l1_refresh, area, refresh_time);
1697 else if (level == IS_LEVEL_2)
1698 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1699 lsp_l2_refresh, area, refresh_time);
1700
1701 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001702 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001703 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1704 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1705 area->area_tag, level,
1706 rawlspid_print (newlsp->lsp_header->lsp_id),
1707 ntohl (newlsp->lsp_header->pdu_len),
1708 ntohl (newlsp->lsp_header->seq_num),
1709 ntohs (newlsp->lsp_header->checksum),
1710 ntohs (newlsp->lsp_header->rem_lifetime),
1711 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001712 }
Christian Franke61010c32015-11-10 18:43:34 +01001713 sched_debug("ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
1714 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001715
1716 return ISIS_OK;
1717}
1718
1719/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001720 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001721 */
hasso92365882005-01-18 13:53:33 +00001722static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001723lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001724{
David Lampartere8aca322012-11-27 01:10:30 +00001725 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001726 struct isis_lsp *lsp, *frag;
1727 struct listnode *node;
1728 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001729 u_int16_t rem_lifetime, refresh_time;
1730
1731 if ((area == NULL) || (area->is_type & level) != level)
1732 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001733
David Lampartere8aca322012-11-27 01:10:30 +00001734 lspdb = area->lspdb[level - 1];
1735
jardineb5d44e2003-12-23 08:09:43 +00001736 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1737 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001738
jardineb5d44e2003-12-23 08:09:43 +00001739 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001740
hassof390d2c2004-09-10 20:48:21 +00001741 if (!lsp)
1742 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001743 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1744 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001745 return ISIS_ERROR;
1746 }
1747
1748 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001749 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001750 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1751 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001752 rem_lifetime = lsp_rem_lifetime (area, level);
1753 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001754 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001755
Josh Bailey3f045a02012-03-24 08:35:20 -07001756 lsp->last_generated = time (NULL);
1757 lsp_set_all_srmflags (lsp);
1758 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1759 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001760 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001761 area->overload_bit,
1762 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001763 /* Set the lifetime values of all the fragments to the same value,
1764 * so that no fragment expires before the lsp is refreshed.
1765 */
1766 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1767 lsp_set_all_srmflags (frag);
1768 }
1769
1770 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1771 if (level == IS_LEVEL_1)
1772 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1773 lsp_l1_refresh, area, refresh_time);
1774 else if (level == IS_LEVEL_2)
1775 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1776 lsp_l2_refresh, area, refresh_time);
Christian Franke61010c32015-11-10 18:43:34 +01001777 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001778
hassof390d2c2004-09-10 20:48:21 +00001779 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1780 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001781 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
1782 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1783 area->area_tag, level,
1784 rawlspid_print (lsp->lsp_header->lsp_id),
1785 ntohl (lsp->lsp_header->pdu_len),
1786 ntohl (lsp->lsp_header->seq_num),
1787 ntohs (lsp->lsp_header->checksum),
1788 ntohs (lsp->lsp_header->rem_lifetime),
1789 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001790 }
Christian Franke61010c32015-11-10 18:43:34 +01001791 sched_debug("ISIS (%s): Rebuilt L%d LSP. Set triggered regenerate to non-pending.",
1792 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001793
jardineb5d44e2003-12-23 08:09:43 +00001794 return ISIS_OK;
1795}
1796
jardineb5d44e2003-12-23 08:09:43 +00001797/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001798 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00001799 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001800static int
1801lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001802{
1803 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001804
1805 area = THREAD_ARG (thread);
1806 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001807
jardineb5d44e2003-12-23 08:09:43 +00001808 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001809 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00001810
Josh Bailey3f045a02012-03-24 08:35:20 -07001811 if ((area->is_type & IS_LEVEL_1) == 0)
1812 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001813
Christian Franke61010c32015-11-10 18:43:34 +01001814 sched_debug("ISIS (%s): LSP L1 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07001815 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00001816}
1817
Josh Bailey3f045a02012-03-24 08:35:20 -07001818static int
1819lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001820{
1821 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001822
1823 area = THREAD_ARG (thread);
1824 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001825
jardineb5d44e2003-12-23 08:09:43 +00001826 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001827 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001828
Josh Bailey3f045a02012-03-24 08:35:20 -07001829 if ((area->is_type & IS_LEVEL_2) == 0)
1830 return ISIS_ERROR;
1831
Christian Franke61010c32015-11-10 18:43:34 +01001832 sched_debug("ISIS (%s): LSP L2 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07001833 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00001834}
1835
hassof390d2c2004-09-10 20:48:21 +00001836int
Josh Bailey3f045a02012-03-24 08:35:20 -07001837lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00001838{
1839 struct isis_lsp *lsp;
1840 u_char id[ISIS_SYS_ID_LEN + 2];
1841 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01001842 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07001843 struct listnode *cnode;
1844 struct isis_circuit *circuit;
1845 int lvl;
1846
1847 if (area == NULL)
1848 return ISIS_ERROR;
1849
Christian Franke61010c32015-11-10 18:43:34 +01001850 sched_debug("ISIS (%s): Scheduling regeneration of %s LSPs, %sincluding PSNs",
1851 area->area_tag, circuit_t2string(level), all_pseudo ? "" : "not ");
1852
hassof390d2c2004-09-10 20:48:21 +00001853 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1854 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001855 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001856
1857 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00001858 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001859 if (!((level & lvl) && (area->is_type & lvl)))
1860 continue;
1861
Christian Franke61010c32015-11-10 18:43:34 +01001862 sched_debug("ISIS (%s): Checking whether L%d needs to be scheduled",
1863 area->area_tag, lvl);
1864
Josh Bailey3f045a02012-03-24 08:35:20 -07001865 if (area->lsp_regenerate_pending[lvl - 1])
Christian Franke61010c32015-11-10 18:43:34 +01001866 {
1867 struct timeval remain = thread_timer_remain(area->t_lsp_refresh[lvl - 1]);
1868 sched_debug("ISIS (%s): Regeneration is already pending, nothing todo."
1869 " (Due in %lld.%03lld seconds)", area->area_tag,
1870 (long long)remain.tv_sec, (long long)remain.tv_usec / 1000);
1871 continue;
1872 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001873
1874 lsp = lsp_search (id, area->lspdb[lvl - 1]);
1875 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01001876 {
1877 sched_debug("ISIS (%s): We do not have any LSPs to regenerate, nothing todo.",
1878 area->area_tag);
1879 continue;
1880 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001881
hassof390d2c2004-09-10 20:48:21 +00001882 /*
1883 * Throttle avoidance
1884 */
Christian Franke61010c32015-11-10 18:43:34 +01001885 sched_debug("ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
1886 area->area_tag, (long long)lsp->last_generated, (long long)now);
Josh Bailey3f045a02012-03-24 08:35:20 -07001887 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00001888 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07001889 if (diff < area->lsp_gen_interval[lvl - 1])
1890 {
Christian Franke61010c32015-11-10 18:43:34 +01001891 timeout = 1000 * (area->lsp_gen_interval[lvl - 1] - diff);
1892 sched_debug("ISIS (%s): Scheduling in %ld ms to match configured lsp_gen_interval",
1893 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07001894 }
hassof390d2c2004-09-10 20:48:21 +00001895 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001896 {
Michael Zinggbe62b172012-10-26 11:18:19 +02001897 /*
1898 * lsps are not regenerated if lsp_regenerate function is called
1899 * directly. However if the lsp_regenerate call is queued for
1900 * later execution it works.
1901 */
Christian Franke61010c32015-11-10 18:43:34 +01001902 timeout = 100;
1903 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
1904 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
1905 }
1906
1907 area->lsp_regenerate_pending[lvl - 1] = 1;
1908 if (lvl == IS_LEVEL_1)
1909 {
1910 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
1911 lsp_l1_refresh, area, timeout);
1912 }
1913 else if (lvl == IS_LEVEL_2)
1914 {
1915 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
1916 lsp_l2_refresh, area, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07001917 }
hassof390d2c2004-09-10 20:48:21 +00001918 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001919
1920 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00001921 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001922 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
1923 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00001924 }
1925
1926 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001927}
1928
1929/*
1930 * Funcs for pseudonode LSPs
1931 */
1932
1933/*
1934 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1935 */
hasso92365882005-01-18 13:53:33 +00001936static void
hassof390d2c2004-09-10 20:48:21 +00001937lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1938 int level)
jardineb5d44e2003-12-23 08:09:43 +00001939{
1940 struct isis_adjacency *adj;
1941 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001942 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001943 struct es_neigh *es_neigh;
1944 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001945 struct listnode *node;
Christian Franke80a8f722015-11-12 14:21:47 +01001946 struct isis_area *area = circuit->area;
1947
1948 lsp_debug("ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
1949 area->area_tag, rawlspid_print(lsp->lsp_header->lsp_id),
1950 circuit->interface->name, level);
hassof390d2c2004-09-10 20:48:21 +00001951
jardineb5d44e2003-12-23 08:09:43 +00001952 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07001953 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001954 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
1955 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00001956
1957 /*
1958 * add self to IS neighbours
1959 */
hassoaa4376e2005-09-26 17:39:48 +00001960 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001961 {
hassoaa4376e2005-09-26 17:39:48 +00001962 if (lsp->tlv_data.is_neighs == NULL)
1963 {
1964 lsp->tlv_data.is_neighs = list_new ();
1965 lsp->tlv_data.is_neighs->del = free_tlv;
1966 }
1967 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001968
hassoaa4376e2005-09-26 17:39:48 +00001969 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1970 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001971 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
1972 area->area_tag, sysid_print(is_neigh->neigh_id),
1973 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001974 }
1975 if (circuit->area->newmetric)
1976 {
1977 if (lsp->tlv_data.te_is_neighs == NULL)
1978 {
1979 lsp->tlv_data.te_is_neighs = list_new ();
1980 lsp->tlv_data.te_is_neighs->del = free_tlv;
1981 }
1982 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1983
1984 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1985 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001986 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
1987 area->area_tag, sysid_print(te_is_neigh->neigh_id),
1988 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001989 }
hassof390d2c2004-09-10 20:48:21 +00001990
1991 adj_list = list_new ();
1992 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1993
hasso3fdb2dd2005-09-28 18:45:54 +00001994 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001995 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001996 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00001997 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001998 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1999 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00002000 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07002001 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00002002 {
2003 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00002004 if (circuit->area->oldmetric)
2005 {
2006 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002007
hassoaa4376e2005-09-26 17:39:48 +00002008 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2009 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002010 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
2011 area->area_tag, sysid_print(is_neigh->neigh_id),
2012 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002013 }
2014 if (circuit->area->newmetric)
2015 {
2016 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
2017 sizeof (struct te_is_neigh));
2018 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2019 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002020 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
2021 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2022 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002023 }
hassof390d2c2004-09-10 20:48:21 +00002024 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002025 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00002026 {
2027 /* an ES neigbour add it, if we are building level 1 LSP */
2028 /* FIXME: the tlv-format is hard to use here */
2029 if (lsp->tlv_data.es_neighs == NULL)
2030 {
2031 lsp->tlv_data.es_neighs = list_new ();
2032 lsp->tlv_data.es_neighs->del = free_tlv;
2033 }
paul15935e92005-05-03 09:27:23 +00002034 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2035
hassof390d2c2004-09-10 20:48:21 +00002036 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00002037 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002038 lsp_debug("ISIS (%s): Adding %s as ES neighbor (peer)",
2039 area->area_tag, sysid_print(es_neigh->first_es_neigh));
hassof390d2c2004-09-10 20:48:21 +00002040 }
Christian Franke80a8f722015-11-12 14:21:47 +01002041 else
2042 {
2043 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not match",
2044 area->area_tag, sysid_print(adj->sysid));
2045 }
2046 }
2047 else
2048 {
2049 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not intersect",
2050 area->area_tag, sysid_print(adj->sysid));
hassof390d2c2004-09-10 20:48:21 +00002051 }
jardineb5d44e2003-12-23 08:09:43 +00002052 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002053 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00002054
Christian Franke80a8f722015-11-12 14:21:47 +01002055 lsp_debug("ISIS (%s): Pseudo LSP construction is complete.", area->area_tag);
2056
hassoc0fb2a52005-09-03 16:29:40 +00002057 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00002058 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00002059 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2060
jardineb5d44e2003-12-23 08:09:43 +00002061 /*
2062 * Add the authentication info if it's present
2063 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002064 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002065
2066 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2067 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2068
hassoaa4376e2005-09-26 17:39:48 +00002069 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
2070 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
2071
jardineb5d44e2003-12-23 08:09:43 +00002072 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2073 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2074
paul9985f832005-02-09 15:51:56 +00002075 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002076
Josh Bailey3f045a02012-03-24 08:35:20 -07002077 /* Recompute authentication and checksum information */
2078 lsp_auth_update (lsp);
2079 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2080 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00002081
2082 return;
2083}
2084
Josh Bailey3f045a02012-03-24 08:35:20 -07002085int
2086lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002087{
2088 dict_t *lspdb = circuit->area->lspdb[level - 1];
2089 struct isis_lsp *lsp;
2090 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07002091 u_int16_t rem_lifetime, refresh_time;
2092
2093 if ((circuit->is_type & level) != level ||
2094 (circuit->state != C_STATE_UP) ||
2095 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2096 (circuit->u.bc.is_dr[level - 1] == 0))
2097 return ISIS_ERROR;
2098
2099 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2100 LSP_FRAGMENT (lsp_id) = 0;
2101 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2102
2103 /*
2104 * If for some reason have a pseudo LSP in the db already -> regenerate
2105 */
2106 if (lsp_search (lsp_id, lspdb))
2107 return lsp_regenerate_schedule_pseudo (circuit, level);
2108
2109 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2110 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Christian Frankef1fc1db2015-11-10 18:43:31 +01002111 lsp = lsp_new (circuit->area, lsp_id, rem_lifetime, 1,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002112 circuit->area->is_type | circuit->area->attached_bit,
2113 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07002114 lsp->area = circuit->area;
2115
2116 lsp_build_pseudo (lsp, circuit, level);
2117
2118 lsp->own_lsp = 1;
2119 lsp_insert (lsp, lspdb);
2120 lsp_set_all_srmflags (lsp);
2121
2122 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2123 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
2124 circuit->lsp_regenerate_pending[level - 1] = 0;
2125 if (level == IS_LEVEL_1)
2126 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2127 lsp_l1_refresh_pseudo, circuit, refresh_time);
2128 else if (level == IS_LEVEL_2)
2129 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2130 lsp_l2_refresh_pseudo, circuit, refresh_time);
2131
2132 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2133 {
2134 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
2135 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2136 circuit->area->area_tag, level,
2137 rawlspid_print (lsp->lsp_header->lsp_id),
2138 ntohl (lsp->lsp_header->pdu_len),
2139 ntohl (lsp->lsp_header->seq_num),
2140 ntohs (lsp->lsp_header->checksum),
2141 ntohs (lsp->lsp_header->rem_lifetime),
2142 refresh_time);
2143 }
2144
2145 return ISIS_OK;
2146}
2147
2148static int
2149lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2150{
2151 dict_t *lspdb = circuit->area->lspdb[level - 1];
2152 struct isis_lsp *lsp;
2153 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2154 u_int16_t rem_lifetime, refresh_time;
2155
2156 if ((circuit->is_type & level) != level ||
2157 (circuit->state != C_STATE_UP) ||
2158 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2159 (circuit->u.bc.is_dr[level - 1] == 0))
2160 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002161
jardineb5d44e2003-12-23 08:09:43 +00002162 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002163 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2164 LSP_FRAGMENT (lsp_id) = 0;
2165
jardineb5d44e2003-12-23 08:09:43 +00002166 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002167
2168 if (!lsp)
2169 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002170 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2171 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002172 return ISIS_ERROR;
2173 }
2174 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002175
2176 lsp_build_pseudo (lsp, circuit, level);
2177
Josh Bailey3f045a02012-03-24 08:35:20 -07002178 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002179 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2180 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002181 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2182 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002183 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002184 lsp->last_generated = time (NULL);
2185 lsp_set_all_srmflags (lsp);
2186
2187 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2188 if (level == IS_LEVEL_1)
2189 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2190 lsp_l1_refresh_pseudo, circuit, refresh_time);
2191 else if (level == IS_LEVEL_2)
2192 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2193 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002194
2195 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2196 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002197 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2198 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2199 circuit->area->area_tag, level,
2200 rawlspid_print (lsp->lsp_header->lsp_id),
2201 ntohl (lsp->lsp_header->pdu_len),
2202 ntohl (lsp->lsp_header->seq_num),
2203 ntohs (lsp->lsp_header->checksum),
2204 ntohs (lsp->lsp_header->rem_lifetime),
2205 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002206 }
jardineb5d44e2003-12-23 08:09:43 +00002207
jardineb5d44e2003-12-23 08:09:43 +00002208 return ISIS_OK;
2209}
2210
Josh Bailey3f045a02012-03-24 08:35:20 -07002211/*
2212 * Something has changed or periodic refresh -> regenerate pseudo LSP
2213 */
2214static int
jardineb5d44e2003-12-23 08:09:43 +00002215lsp_l1_refresh_pseudo (struct thread *thread)
2216{
2217 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002218 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002219
hassof390d2c2004-09-10 20:48:21 +00002220 circuit = THREAD_ARG (thread);
2221
hasso13c48f72004-09-10 21:19:13 +00002222 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002223 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002224
Josh Bailey3f045a02012-03-24 08:35:20 -07002225 if ((circuit->u.bc.is_dr[0] == 0) ||
2226 (circuit->is_type & IS_LEVEL_1) == 0)
2227 {
2228 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2229 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2230 LSP_FRAGMENT (id) = 0;
2231 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2232 return ISIS_ERROR;
2233 }
hassof390d2c2004-09-10 20:48:21 +00002234
Josh Bailey3f045a02012-03-24 08:35:20 -07002235 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002236}
2237
Josh Bailey3f045a02012-03-24 08:35:20 -07002238static int
jardineb5d44e2003-12-23 08:09:43 +00002239lsp_l2_refresh_pseudo (struct thread *thread)
2240{
2241 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002242 u_char id[ISIS_SYS_ID_LEN + 2];
2243
hassof390d2c2004-09-10 20:48:21 +00002244 circuit = THREAD_ARG (thread);
2245
hasso13c48f72004-09-10 21:19:13 +00002246 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002247 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002248
Josh Bailey3f045a02012-03-24 08:35:20 -07002249 if ((circuit->u.bc.is_dr[1] == 0) ||
2250 (circuit->is_type & IS_LEVEL_2) == 0)
2251 {
2252 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2253 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2254 LSP_FRAGMENT (id) = 0;
2255 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2256 return ISIS_ERROR;
2257 }
jardineb5d44e2003-12-23 08:09:43 +00002258
Josh Bailey3f045a02012-03-24 08:35:20 -07002259 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002260}
2261
hassof390d2c2004-09-10 20:48:21 +00002262int
Josh Bailey3f045a02012-03-24 08:35:20 -07002263lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002264{
2265 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002266 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2267 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01002268 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07002269 int lvl;
Christian Franke61010c32015-11-10 18:43:34 +01002270 struct isis_area *area = circuit->area;
jardineb5d44e2003-12-23 08:09:43 +00002271
Josh Bailey3f045a02012-03-24 08:35:20 -07002272 if (circuit == NULL ||
2273 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2274 circuit->state != C_STATE_UP)
2275 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002276
Christian Franke61010c32015-11-10 18:43:34 +01002277 sched_debug("ISIS (%s): Scheduling regeneration of %s pseudo LSP for interface %s",
2278 area->area_tag, circuit_t2string(level), circuit->interface->name);
2279
Josh Bailey3f045a02012-03-24 08:35:20 -07002280 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2281 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2282 LSP_FRAGMENT (lsp_id) = 0;
2283 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002284
Josh Bailey3f045a02012-03-24 08:35:20 -07002285 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2286 {
Christian Franke61010c32015-11-10 18:43:34 +01002287 sched_debug("ISIS (%s): Checking whether L%d pseudo LSP needs to be scheduled",
2288 area->area_tag, lvl);
jardineb5d44e2003-12-23 08:09:43 +00002289
Christian Franke61010c32015-11-10 18:43:34 +01002290 if (!((level & lvl) && (circuit->is_type & lvl)))
2291 {
2292 sched_debug("ISIS (%s): Level is not active on circuit",
2293 area->area_tag);
2294 continue;
2295 }
2296
2297 if (circuit->u.bc.is_dr[lvl - 1] == 0)
2298 {
2299 sched_debug("ISIS (%s): This IS is not DR, nothing to do.",
2300 area->area_tag);
2301 continue;
2302 }
2303
2304 if (circuit->lsp_regenerate_pending[lvl - 1])
2305 {
2306 struct timeval remain =
2307 thread_timer_remain(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2308 sched_debug("ISIS (%s): Regenerate is already pending, nothing todo."
2309 " (Due in %lld.%03lld seconds)", area->area_tag,
2310 (long long)remain.tv_sec, (long long)remain.tv_usec/1000);
2311 continue;
2312 }
hassof390d2c2004-09-10 20:48:21 +00002313
Josh Bailey3f045a02012-03-24 08:35:20 -07002314 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2315 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002316 {
2317 sched_debug("ISIS (%s): Pseudonode LSP does not exist yet, nothing to regenerate.",
2318 area->area_tag);
2319 continue;
2320 }
jardineb5d44e2003-12-23 08:09:43 +00002321
Josh Bailey3f045a02012-03-24 08:35:20 -07002322 /*
2323 * Throttle avoidance
2324 */
Christian Franke61010c32015-11-10 18:43:34 +01002325 sched_debug("ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
2326 area->area_tag, (long long)lsp->last_generated, (long long) now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002327 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2328 diff = now - lsp->last_generated;
2329 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2330 {
Christian Franke61010c32015-11-10 18:43:34 +01002331 timeout = 1000 * (circuit->area->lsp_gen_interval[lvl - 1] - diff);
2332 sched_debug("ISIS (%s): Sechduling in %ld ms to match configured lsp_gen_interval",
2333 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002334 }
2335 else
2336 {
Christian Franke61010c32015-11-10 18:43:34 +01002337 timeout = 100;
2338 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2339 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2340 }
2341
2342 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2343
2344 if (lvl == IS_LEVEL_1)
2345 {
2346 THREAD_TIMER_MSEC_ON(master,
2347 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2348 lsp_l1_refresh_pseudo, circuit, timeout);
2349 }
2350 else if (lvl == IS_LEVEL_2)
2351 {
2352 THREAD_TIMER_MSEC_ON(master,
2353 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2354 lsp_l2_refresh_pseudo, circuit, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002355 }
2356 }
jardineb5d44e2003-12-23 08:09:43 +00002357
Josh Bailey3f045a02012-03-24 08:35:20 -07002358 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002359}
2360
jardineb5d44e2003-12-23 08:09:43 +00002361/*
2362 * Walk through LSPs for an area
2363 * - set remaining lifetime
2364 * - set LSPs with SRMflag set for sending
2365 */
hassof390d2c2004-09-10 20:48:21 +00002366int
jardineb5d44e2003-12-23 08:09:43 +00002367lsp_tick (struct thread *thread)
2368{
2369 struct isis_area *area;
2370 struct isis_circuit *circuit;
2371 struct isis_lsp *lsp;
2372 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002373 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002374 dnode_t *dnode, *dnode_next;
2375 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002376 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002377
2378 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002379
jardineb5d44e2003-12-23 08:09:43 +00002380 area = THREAD_ARG (thread);
2381 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002382 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002383 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002384
2385 /*
2386 * Build a list of LSPs with (any) SRMflag set
2387 * and removed the ones that have aged out
2388 */
hassof390d2c2004-09-10 20:48:21 +00002389 for (level = 0; level < ISIS_LEVELS; level++)
2390 {
2391 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002392 {
2393 for (dnode = dict_first (area->lspdb[level]);
2394 dnode != NULL; dnode = dnode_next)
2395 {
2396 dnode_next = dict_next (area->lspdb[level], dnode);
2397 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002398
Josh Bailey3f045a02012-03-24 08:35:20 -07002399 /*
2400 * The lsp rem_lifetime is kept at 0 for MaxAge or
2401 * ZeroAgeLifetime depending on explicit purge or
2402 * natural age out. So schedule spf only once when
2403 * the first time rem_lifetime becomes 0.
2404 */
2405 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2406 lsp_set_time (lsp);
2407
2408 /*
2409 * Schedule may run spf which should be done only after
2410 * the lsp rem_lifetime becomes 0 for the first time.
2411 * ISO 10589 - 7.3.16.4 first paragraph.
2412 */
2413 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2414 {
2415 /* 7.3.16.4 a) set SRM flags on all */
2416 lsp_set_all_srmflags (lsp);
2417 /* 7.3.16.4 b) retain only the header FIXME */
2418 /* 7.3.16.4 c) record the time to purge FIXME */
2419 /* run/schedule spf */
2420 /* isis_spf_schedule is called inside lsp_destroy() below;
2421 * so it is not needed here. */
2422 /* isis_spf_schedule (lsp->area, lsp->level); */
2423 }
2424
2425 if (lsp->age_out == 0)
2426 {
2427 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2428 area->area_tag,
2429 lsp->level,
2430 rawlspid_print (lsp->lsp_header->lsp_id),
2431 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002432#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002433 if (lsp->from_topology)
2434 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002435#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002436 lsp_destroy (lsp);
2437 lsp = NULL;
2438 dict_delete_free (area->lspdb[level], dnode);
2439 }
2440 else if (flags_any_set (lsp->SRMflags))
2441 listnode_add (lsp_list, lsp);
2442 }
jardineb5d44e2003-12-23 08:09:43 +00002443
Josh Bailey3f045a02012-03-24 08:35:20 -07002444 /*
2445 * Send LSPs on circuits indicated by the SRMflags
2446 */
2447 if (listcount (lsp_list) > 0)
2448 {
paul1eb8ef22005-04-07 07:30:20 +00002449 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002450 {
2451 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2452 if (circuit->lsp_queue == NULL ||
2453 diff < MIN_LSP_TRANS_INTERVAL)
2454 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002455 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002456 {
2457 if (circuit->upadjcount[lsp->level - 1] &&
2458 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2459 {
2460 /* Add the lsp only if it is not already in lsp
2461 * queue */
2462 if (! listnode_lookup (circuit->lsp_queue, lsp))
2463 {
2464 listnode_add (circuit->lsp_queue, lsp);
2465 thread_add_event (master, send_lsp, circuit, 0);
2466 }
2467 }
2468 }
2469 }
2470 list_delete_all_node (lsp_list);
2471 }
2472 }
jardineb5d44e2003-12-23 08:09:43 +00002473 }
jardineb5d44e2003-12-23 08:09:43 +00002474
2475 list_delete (lsp_list);
2476
2477 return ISIS_OK;
2478}
2479
jardineb5d44e2003-12-23 08:09:43 +00002480void
Josh Bailey3f045a02012-03-24 08:35:20 -07002481lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002482{
2483 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002484 u_int16_t seq_num;
2485 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002486
jardineb5d44e2003-12-23 08:09:43 +00002487 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002488 if (!lsp)
2489 return;
hassof390d2c2004-09-10 20:48:21 +00002490
Josh Bailey3f045a02012-03-24 08:35:20 -07002491 /* store old values */
2492 seq_num = lsp->lsp_header->seq_num;
2493 lsp_bits = lsp->lsp_header->lsp_bits;
2494
2495 /* reset stream */
2496 lsp_clear_data (lsp);
2497 stream_reset (lsp->pdu);
2498
2499 /* update header */
2500 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2501 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2502 lsp->lsp_header->checksum = 0;
2503 lsp->lsp_header->seq_num = seq_num;
2504 lsp->lsp_header->rem_lifetime = 0;
2505 lsp->lsp_header->lsp_bits = lsp_bits;
2506 lsp->level = level;
2507 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2508 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2509
2510 /*
2511 * Add and update the authentication info if its present
2512 */
2513 lsp_auth_add (lsp);
2514 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2515 lsp_auth_update (lsp);
2516 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2517 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2518
2519 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002520
jardineb5d44e2003-12-23 08:09:43 +00002521 return;
2522}
2523
2524/*
2525 * Purge own LSP that is received and we don't have.
2526 * -> Do as in 7.3.16.4
2527 */
2528void
Christian Franke749e87a2015-11-10 18:21:44 +01002529lsp_purge_non_exist (int level,
2530 struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +00002531 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002532{
2533 struct isis_lsp *lsp;
2534
2535 /*
2536 * We need to create the LSP to be purged
2537 */
hassoaac372f2005-09-01 17:52:33 +00002538 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002539 lsp->area = area;
Christian Franke749e87a2015-11-10 18:21:44 +01002540 lsp->level = level;
Christian Frankef1fc1db2015-11-10 18:43:31 +01002541 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
hassof390d2c2004-09-10 20:48:21 +00002542 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002543 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002544 : L2_LINK_STATE);
2545 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2546 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002547 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002548 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002549
jardineb5d44e2003-12-23 08:09:43 +00002550 /*
jardineb5d44e2003-12-23 08:09:43 +00002551 * Set the remaining lifetime to 0
2552 */
2553 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002554
2555 /*
2556 * Add and update the authentication info if its present
2557 */
2558 lsp_auth_add (lsp);
2559 lsp_auth_update (lsp);
2560
2561 /*
2562 * Update the PDU length to header plus any authentication TLV.
2563 */
2564 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2565
jardineb5d44e2003-12-23 08:09:43 +00002566 /*
2567 * Put the lsp into LSPdb
2568 */
hassof390d2c2004-09-10 20:48:21 +00002569 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002570
2571 /*
2572 * Send in to whole area
2573 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002574 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002575
jardineb5d44e2003-12-23 08:09:43 +00002576 return;
2577}
2578
Josh Bailey3f045a02012-03-24 08:35:20 -07002579void lsp_set_all_srmflags (struct isis_lsp *lsp)
2580{
2581 struct listnode *node;
2582 struct isis_circuit *circuit;
2583
2584 assert (lsp);
2585
2586 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2587
2588 if (lsp->area)
2589 {
2590 struct list *circuit_list = lsp->area->circuit_list;
2591 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2592 {
2593 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2594 }
2595 }
2596}
2597
jardineb5d44e2003-12-23 08:09:43 +00002598#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002599static int
jardineb5d44e2003-12-23 08:09:43 +00002600top_lsp_refresh (struct thread *thread)
2601{
hassof390d2c2004-09-10 20:48:21 +00002602 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002603 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002604
2605 lsp = THREAD_ARG (thread);
2606 assert (lsp);
2607
2608 lsp->t_lsp_top_ref = NULL;
2609
hassof1082d12005-09-19 04:23:34 +00002610 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002611
Josh Bailey3f045a02012-03-24 08:35:20 -07002612 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002613 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2614 {
hasso529d65b2004-12-24 00:14:50 +00002615 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2616 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002617 }
hassod3d74742005-09-28 18:30:51 +00002618 /* Refresh dynamic hostname in the cache. */
2619 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2620 IS_LEVEL_1);
2621
David Lampartera47c5832012-06-21 09:55:38 +02002622 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002623 lsp->area->overload_bit,
2624 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002625 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2626 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002627
David Lamparterf50ee932015-03-04 07:13:38 +01002628 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002629 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002630 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002631
2632 return ISIS_OK;
2633}
2634
2635void
2636generate_topology_lsps (struct isis_area *area)
2637{
2638 struct listnode *node;
2639 int i, max = 0;
2640 struct arc *arc;
2641 u_char lspid[ISIS_SYS_ID_LEN + 2];
2642 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002643 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002644
2645 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002646 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002647 {
2648 if (arc->from_node > max)
2649 max = arc->from_node;
2650 if (arc->to_node > max)
2651 max = arc->to_node;
2652 }
jardineb5d44e2003-12-23 08:09:43 +00002653
hassof390d2c2004-09-10 20:48:21 +00002654 for (i = 1; i < (max + 1); i++)
2655 {
2656 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2657 LSP_PSEUDO_ID (lspid) = 0x00;
2658 LSP_FRAGMENT (lspid) = 0x00;
2659 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2660 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002661
Josh Bailey3f045a02012-03-24 08:35:20 -07002662 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Christian Frankef1fc1db2015-11-10 18:43:31 +01002663 lsp = lsp_new (area, lspid, rem_lifetime, 1,
2664 IS_LEVEL_1 | area->overload_bit | area->attached_bit,
2665 0, 1);
hassof1082d12005-09-19 04:23:34 +00002666 if (!lsp)
2667 return;
Josh Bailey3f045a02012-03-24 08:35:20 -07002668 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002669
hassof1082d12005-09-19 04:23:34 +00002670 /* Creating LSP data based on topology info. */
2671 build_topology_lsp_data (lsp, area, i);
2672 /* Checksum is also calculated here. */
2673 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002674 /* Take care of inserting dynamic hostname into cache. */
2675 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002676
Josh Bailey3f045a02012-03-24 08:35:20 -07002677 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002678 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002679 refresh_time);
2680 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002681 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002682 }
jardineb5d44e2003-12-23 08:09:43 +00002683}
2684
2685void
2686remove_topology_lsps (struct isis_area *area)
2687{
2688 struct isis_lsp *lsp;
2689 dnode_t *dnode, *dnode_next;
2690
2691 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002692 while (dnode != NULL)
2693 {
2694 dnode_next = dict_next (area->lspdb[0], dnode);
2695 lsp = dnode_get (dnode);
2696 if (lsp->from_topology)
2697 {
2698 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2699 lsp_destroy (lsp);
2700 dict_delete (area->lspdb[0], dnode);
2701 }
2702 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002703 }
jardineb5d44e2003-12-23 08:09:43 +00002704}
2705
2706void
hassof390d2c2004-09-10 20:48:21 +00002707build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002708 int lsp_top_num)
2709{
hasso3fdb2dd2005-09-28 18:45:54 +00002710 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002711 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002712 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002713 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002714 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002715 struct tlvs tlv_data;
2716 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002717
hassof1082d12005-09-19 04:23:34 +00002718 /* Add area addresses. FIXME: Is it needed at all? */
2719 if (lsp->tlv_data.area_addrs == NULL)
2720 lsp->tlv_data.area_addrs = list_new ();
2721 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002722
hassof1082d12005-09-19 04:23:34 +00002723 if (lsp->tlv_data.nlpids == NULL)
2724 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2725 lsp->tlv_data.nlpids->count = 1;
2726 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002727
hassof1082d12005-09-19 04:23:34 +00002728 if (area->dynhostname)
2729 {
2730 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2731 sizeof (struct hostname));
2732 memset (buff, 0x00, 200);
2733 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2734 "feedme", lsp_top_num);
2735 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2736 lsp->tlv_data.hostname->namelen = strlen (buff);
2737 }
2738
2739 if (lsp->tlv_data.nlpids)
2740 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2741 if (lsp->tlv_data.hostname)
2742 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2743 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2744 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2745
2746 memset (&tlv_data, 0, sizeof (struct tlvs));
2747 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002748 {
2749 tlv_data.is_neighs = list_new ();
2750 tlv_data.is_neighs->del = free_tlv;
2751 }
hassof1082d12005-09-19 04:23:34 +00002752
2753 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002754 if (lsp_top_num == 1)
2755 {
hasso3fdb2dd2005-09-28 18:45:54 +00002756 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002757
hassof390d2c2004-09-10 20:48:21 +00002758 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002759 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002760 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2761 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002762 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2763 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2764 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002765 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002766 }
hassof390d2c2004-09-10 20:48:21 +00002767
hassof1082d12005-09-19 04:23:34 +00002768 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002769 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002770 {
hassof1082d12005-09-19 04:23:34 +00002771 int to_lsp = 0;
2772
2773 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2774 continue;
2775
2776 if (lsp_top_num == arc->from_node)
2777 to_lsp = arc->to_node;
2778 else
2779 to_lsp = arc->from_node;
2780
hasso9551eea2005-09-28 18:26:25 +00002781 if (area->oldmetric)
2782 {
2783 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002784
hasso9551eea2005-09-28 18:26:25 +00002785 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2786 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2787 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2788 is_neigh->metrics.metric_default = arc->distance;
2789 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2790 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2791 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2792 listnode_add (tlv_data.is_neighs, is_neigh);
2793 }
2794
2795 if (area->newmetric)
2796 {
hasso9551eea2005-09-28 18:26:25 +00002797 if (tlv_data.te_is_neighs == NULL)
2798 {
2799 tlv_data.te_is_neighs = list_new ();
2800 tlv_data.te_is_neighs->del = free_tlv;
2801 }
2802 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2803 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2804 ISIS_SYS_ID_LEN);
2805 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2806 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07002807 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00002808 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2809 }
hassof390d2c2004-09-10 20:48:21 +00002810 }
hassof1082d12005-09-19 04:23:34 +00002811
2812 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2813 {
2814 if (lsp->tlv_data.is_neighs == NULL)
2815 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002816 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002817 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2818 tlv_add_is_neighs);
2819 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2820 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2821 lsp0, area, IS_LEVEL_1);
2822 }
2823
hasso9551eea2005-09-28 18:26:25 +00002824 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2825 {
2826 if (lsp->tlv_data.te_is_neighs == NULL)
2827 lsp->tlv_data.te_is_neighs = list_new ();
2828 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2829 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2830 tlv_add_te_is_neighs);
2831 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2832 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2833 lsp0, area, IS_LEVEL_1);
2834 }
2835
hassof1082d12005-09-19 04:23:34 +00002836 free_tlvs (&tlv_data);
2837 return;
jardineb5d44e2003-12-23 08:09:43 +00002838}
2839#endif /* TOPOLOGY_GENERATE */