blob: dc18aa025d44d4969424b96011f2565555b9802d [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_lsp.c
3 * LSP processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
paul15935e92005-05-03 09:27:23 +000023
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "linklist.h"
27#include "thread.h"
28#include "vty.h"
29#include "stream.h"
30#include "memory.h"
31#include "log.h"
32#include "prefix.h"
33#include "command.h"
34#include "hash.h"
35#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010036#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070037#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000038
39#include "isisd/dict.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_circuit.h"
44#include "isisd/isisd.h"
45#include "isisd/isis_tlv.h"
46#include "isisd/isis_lsp.h"
47#include "isisd/isis_pdu.h"
48#include "isisd/isis_dynhn.h"
49#include "isisd/isis_misc.h"
jardineb5d44e2003-12-23 08:09:43 +000050#include "isisd/isis_csm.h"
51#include "isisd/isis_adjacency.h"
52#include "isisd/isis_spf.h"
53
54#ifdef TOPOLOGY_GENERATE
55#include "spgrid.h"
56#endif
57
hasso73d1aea2004-09-24 10:45:28 +000058/* staticly assigned vars for printing purposes */
59char lsp_bits_string[200]; /* FIXME: enough ? */
60
Josh Bailey3f045a02012-03-24 08:35:20 -070061static int lsp_l1_refresh (struct thread *thread);
62static int lsp_l2_refresh (struct thread *thread);
63static int lsp_l1_refresh_pseudo (struct thread *thread);
64static int lsp_l2_refresh_pseudo (struct thread *thread);
65
hassof390d2c2004-09-10 20:48:21 +000066int
67lsp_id_cmp (u_char * id1, u_char * id2)
68{
jardineb5d44e2003-12-23 08:09:43 +000069 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
70}
71
72dict_t *
hassof390d2c2004-09-10 20:48:21 +000073lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000074{
75 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000076
77 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
78
jardineb5d44e2003-12-23 08:09:43 +000079 return dict;
80}
81
82struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000083lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000084{
85 dnode_t *node;
86
hassof390d2c2004-09-10 20:48:21 +000087#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000088 dnode_t *dn;
89
hasso529d65b2004-12-24 00:14:50 +000090 zlog_debug ("searching db");
hassof390d2c2004-09-10 20:48:21 +000091 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
92 {
Josh Bailey3f045a02012-03-24 08:35:20 -070093 zlog_debug ("%s\t%pX", rawlspid_print ((u_char *) dnode_getkey (dn)),
hasso529d65b2004-12-24 00:14:50 +000094 dnode_get (dn));
hassof390d2c2004-09-10 20:48:21 +000095 }
jardineb5d44e2003-12-23 08:09:43 +000096#endif /* EXTREME DEBUG */
97
98 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +000099
jardineb5d44e2003-12-23 08:09:43 +0000100 if (node)
hassof390d2c2004-09-10 20:48:21 +0000101 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000102
103 return NULL;
104}
105
hasso92365882005-01-18 13:53:33 +0000106static void
jardineb5d44e2003-12-23 08:09:43 +0000107lsp_clear_data (struct isis_lsp *lsp)
108{
109 if (!lsp)
110 return;
hassof390d2c2004-09-10 20:48:21 +0000111
Josh Bailey3f045a02012-03-24 08:35:20 -0700112 if (lsp->tlv_data.hostname)
113 isis_dynhn_remove (lsp->lsp_header->lsp_id);
114
hassof390d2c2004-09-10 20:48:21 +0000115 if (lsp->own_lsp)
116 {
117 if (lsp->tlv_data.nlpids)
Josh Bailey3f045a02012-03-24 08:35:20 -0700118 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
hassof390d2c2004-09-10 20:48:21 +0000119 if (lsp->tlv_data.hostname)
Josh Bailey3f045a02012-03-24 08:35:20 -0700120 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
121 if (lsp->tlv_data.router_id)
122 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.router_id);
hassof390d2c2004-09-10 20:48:21 +0000123 }
jardineb5d44e2003-12-23 08:09:43 +0000124
Josh Bailey3f045a02012-03-24 08:35:20 -0700125 free_tlvs (&lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000126}
127
hasso92365882005-01-18 13:53:33 +0000128static void
jardineb5d44e2003-12-23 08:09:43 +0000129lsp_destroy (struct isis_lsp *lsp)
130{
Josh Bailey3f045a02012-03-24 08:35:20 -0700131 struct listnode *cnode, *lnode, *lnnode;
132 struct isis_lsp *lsp_in_list;
133 struct isis_circuit *circuit;
134
jardineb5d44e2003-12-23 08:09:43 +0000135 if (!lsp)
136 return;
hassof390d2c2004-09-10 20:48:21 +0000137
Josh Bailey3f045a02012-03-24 08:35:20 -0700138 for (ALL_LIST_ELEMENTS_RO (lsp->area->circuit_list, cnode, circuit))
139 {
140 if (circuit->lsp_queue == NULL)
141 continue;
142 for (ALL_LIST_ELEMENTS (circuit->lsp_queue, lnode, lnnode, lsp_in_list))
143 if (lsp_in_list == lsp)
144 list_delete_node(circuit->lsp_queue, lnode);
145 }
146 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags);
147 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
148
jardineb5d44e2003-12-23 08:09:43 +0000149 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000150
151 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
152 {
jardineb5d44e2003-12-23 08:09:43 +0000153 list_delete (lsp->lspu.frags);
Josh Bailey3f045a02012-03-24 08:35:20 -0700154 lsp->lspu.frags = NULL;
hassof390d2c2004-09-10 20:48:21 +0000155 }
156
Josh Bailey3f045a02012-03-24 08:35:20 -0700157 isis_spf_schedule (lsp->area, lsp->level);
158#ifdef HAVE_IPV6
159 isis_spf_schedule6 (lsp->area, lsp->level);
160#endif
161
jardineb5d44e2003-12-23 08:09:43 +0000162 if (lsp->pdu)
163 stream_free (lsp->pdu);
164 XFREE (MTYPE_ISIS_LSP, lsp);
165}
166
hassof390d2c2004-09-10 20:48:21 +0000167void
168lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000169{
170 dnode_t *dnode, *next;
171 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000172
jardineb5d44e2003-12-23 08:09:43 +0000173 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000174 while (dnode)
175 {
176 next = dict_next (lspdb, dnode);
177 lsp = dnode_get (dnode);
178 lsp_destroy (lsp);
179 dict_delete_free (lspdb, dnode);
180 dnode = next;
181 }
182
jardineb5d44e2003-12-23 08:09:43 +0000183 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000184
jardineb5d44e2003-12-23 08:09:43 +0000185 return;
186}
187
188/*
189 * Remove all the frags belonging to the given lsp
190 */
hasso92365882005-01-18 13:53:33 +0000191static void
hassof390d2c2004-09-10 20:48:21 +0000192lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000193{
194 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000195 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000196 struct isis_lsp *lsp;
197
paul1eb8ef22005-04-07 07:30:20 +0000198 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000199 {
hassof390d2c2004-09-10 20:48:21 +0000200 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
201 lsp_destroy (lsp);
202 dnode_destroy (dict_delete (lspdb, dnode));
203 }
204
jardineb5d44e2003-12-23 08:09:43 +0000205 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000206
jardineb5d44e2003-12-23 08:09:43 +0000207 return;
208}
209
210void
hassof390d2c2004-09-10 20:48:21 +0000211lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000212{
213 dnode_t *node;
214 struct isis_lsp *lsp;
215
216 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000217 if (node)
218 {
219 node = dict_delete (lspdb, node);
220 lsp = dnode_get (node);
221 /*
222 * If this is a zero lsp, remove all the frags now
223 */
224 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
225 {
226 if (lsp->lspu.frags)
227 lsp_remove_frags (lsp->lspu.frags, lspdb);
228 }
229 else
230 {
231 /*
232 * else just remove this frag, from the zero lsps' frag list
233 */
234 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
235 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
236 }
237 lsp_destroy (lsp);
238 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000239 }
jardineb5d44e2003-12-23 08:09:43 +0000240}
241
242/*
243 * Compares a LSP to given values
244 * Params are given in net order
245 */
hassof390d2c2004-09-10 20:48:21 +0000246int
247lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000248 u_int16_t checksum, u_int16_t rem_lifetime)
249{
hassof390d2c2004-09-10 20:48:21 +0000250 /* no point in double ntohl on seqnum */
251 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000252 lsp->lsp_header->checksum == checksum &&
253 /*comparing with 0, no need to do ntohl */
254 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000255 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
256 {
257 if (isis->debugs & DEBUG_SNP_PACKETS)
258 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700259 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000260 " lifetime %us",
261 areatag,
262 rawlspid_print (lsp->lsp_header->lsp_id),
263 ntohl (lsp->lsp_header->seq_num),
264 ntohs (lsp->lsp_header->checksum),
265 ntohs (lsp->lsp_header->rem_lifetime));
266 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
267 " cksum 0x%04x, lifetime %us",
268 areatag,
269 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000270 }
271 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000272 }
jardineb5d44e2003-12-23 08:09:43 +0000273
hassof390d2c2004-09-10 20:48:21 +0000274 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
275 {
276 if (isis->debugs & DEBUG_SNP_PACKETS)
277 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700278 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000279 " lifetime %us",
280 areatag,
281 rawlspid_print (lsp->lsp_header->lsp_id),
282 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
283 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
284 "cksum 0x%04x, lifetime %us",
285 areatag,
286 ntohl (lsp->lsp_header->seq_num),
287 ntohs (lsp->lsp_header->checksum),
288 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000289 }
290 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000291 }
hassof390d2c2004-09-10 20:48:21 +0000292 if (isis->debugs & DEBUG_SNP_PACKETS)
293 {
hasso529d65b2004-12-24 00:14:50 +0000294 zlog_debug
Josh Bailey3f045a02012-03-24 08:35:20 -0700295 ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
hassof390d2c2004-09-10 20:48:21 +0000296 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
297 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000298 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
299 " cksum 0x%04x, lifetime %us", areatag,
300 ntohl (lsp->lsp_header->seq_num),
301 ntohs (lsp->lsp_header->checksum),
302 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000303 }
jardineb5d44e2003-12-23 08:09:43 +0000304
305 return LSP_OLDER;
306}
307
Josh Bailey3f045a02012-03-24 08:35:20 -0700308static void
309lsp_auth_add (struct isis_lsp *lsp)
310{
311 struct isis_passwd *passwd;
312 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
313
314 /*
315 * Add the authentication info if its present
316 */
317 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
318 (passwd = &lsp->area->domain_passwd);
319 switch (passwd->type)
320 {
321 /* Cleartext */
322 case ISIS_PASSWD_TYPE_CLEARTXT:
323 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
324 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
325 break;
326
327 /* HMAC MD5 */
328 case ISIS_PASSWD_TYPE_HMAC_MD5:
329 /* Remember where TLV is written so we can later
330 * overwrite the MD5 hash */
331 lsp->auth_tlv_offset = stream_get_endp (lsp->pdu);
332 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
333 lsp->tlv_data.auth_info.type = ISIS_PASSWD_TYPE_HMAC_MD5;
334 lsp->tlv_data.auth_info.len = ISIS_AUTH_MD5_SIZE;
335 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
336 ISIS_AUTH_MD5_SIZE);
337 tlv_add_authinfo (passwd->type, ISIS_AUTH_MD5_SIZE, hmac_md5_hash,
338 lsp->pdu);
339 break;
340
341 default:
342 break;
343 }
344}
345
346static void
347lsp_auth_update (struct isis_lsp *lsp)
348{
349 struct isis_passwd *passwd;
350 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
351 uint16_t checksum, rem_lifetime;
352
353 /* For HMAC MD5 we need to recompute the md5 hash and store it */
354 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
355 (passwd = &lsp->area->domain_passwd);
356 if (passwd->type != ISIS_PASSWD_TYPE_HMAC_MD5)
357 return;
358
359 /*
360 * In transient conditions (when net is configured where authentication
361 * config and lsp regenerate schedule is not yet run), there could be
362 * an own_lsp with auth_tlv_offset set to 0. In such a case, simply
363 * return, when lsp_regenerate is run, lsp will have auth tlv.
364 */
365 if (lsp->auth_tlv_offset == 0)
366 return;
367
368 /*
369 * RFC 5304 set auth value, checksum and remaining lifetime to zero
370 * before computation and reset to old values after computation.
371 */
372 checksum = lsp->lsp_header->checksum;
373 rem_lifetime = lsp->lsp_header->rem_lifetime;
374 lsp->lsp_header->checksum = 0;
375 lsp->lsp_header->rem_lifetime = 0;
376 /* Set the authentication value as well to zero */
377 memset (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
378 0, ISIS_AUTH_MD5_SIZE);
379 /* Compute autentication value */
380 hmac_md5 (STREAM_DATA (lsp->pdu), stream_get_endp(lsp->pdu),
381 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +0100382 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -0700383 /* Copy the hash into the stream */
384 memcpy (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
385 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
386 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
387 ISIS_AUTH_MD5_SIZE);
388 /* Copy back the checksum and remaining lifetime */
389 lsp->lsp_header->checksum = checksum;
390 lsp->lsp_header->rem_lifetime = rem_lifetime;
391}
392
hassof390d2c2004-09-10 20:48:21 +0000393void
jardineb5d44e2003-12-23 08:09:43 +0000394lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
395{
396 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000397
jardineb5d44e2003-12-23 08:09:43 +0000398 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
399 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
400 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700401 newseq = seq_num + 1;
hassof390d2c2004-09-10 20:48:21 +0000402
jardineb5d44e2003-12-23 08:09:43 +0000403 lsp->lsp_header->seq_num = htonl (newseq);
Josh Bailey3f045a02012-03-24 08:35:20 -0700404
405 /* Recompute authentication and checksum information */
406 lsp_auth_update (lsp);
407 /* ISO 10589 - 7.3.11 Generation of the checksum
408 * The checksum shall be computed over all fields in the LSP which appear
409 * after the Remaining Lifetime field. This field (and those appearing
410 * before it) are excluded so that the LSP may be aged by systems without
411 * requiring recomputation.
412 */
413 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
414 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
415
416 isis_spf_schedule (lsp->area, lsp->level);
417#ifdef HAVE_IPV6
418 isis_spf_schedule6 (lsp->area, lsp->level);
419#endif
jardineb5d44e2003-12-23 08:09:43 +0000420
421 return;
422}
423
424/*
425 * Genetates checksum for LSP and its frags
426 */
hasso92365882005-01-18 13:53:33 +0000427static void
jardineb5d44e2003-12-23 08:09:43 +0000428lsp_seqnum_update (struct isis_lsp *lsp0)
429{
430 struct isis_lsp *lsp;
hasso3fdb2dd2005-09-28 18:45:54 +0000431 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000432
jardineb5d44e2003-12-23 08:09:43 +0000433 lsp_inc_seqnum (lsp0, 0);
434
435 if (!lsp0->lspu.frags)
436 return;
437
hasso3fdb2dd2005-09-28 18:45:54 +0000438 for (ALL_LIST_ELEMENTS_RO (lsp0->lspu.frags, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +0000439 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000440
jardineb5d44e2003-12-23 08:09:43 +0000441 return;
442}
443
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700444static u_int8_t
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700445lsp_bits_generate (int level, int overload_bit, int attached_bit)
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700446{
447 u_int8_t lsp_bits = 0;
448 if (level == IS_LEVEL_1)
449 lsp_bits = IS_LEVEL_1;
450 else
451 lsp_bits = IS_LEVEL_1_AND_2;
452 if (overload_bit)
453 lsp_bits |= overload_bit;
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700454 if (attached_bit)
455 lsp_bits |= attached_bit;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700456 return lsp_bits;
457}
458
hasso92365882005-01-18 13:53:33 +0000459static void
hassof390d2c2004-09-10 20:48:21 +0000460lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
Josh Bailey3f045a02012-03-24 08:35:20 -0700461 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000462{
hassof390d2c2004-09-10 20:48:21 +0000463 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000464 int retval;
hassof390d2c2004-09-10 20:48:21 +0000465
Josh Bailey3f045a02012-03-24 08:35:20 -0700466 /* free the old lsp data */
467 lsp_clear_data (lsp);
468
jardineb5d44e2003-12-23 08:09:43 +0000469 /* copying only the relevant part of our stream */
Josh Bailey3f045a02012-03-24 08:35:20 -0700470 if (lsp->pdu != NULL)
471 stream_free (lsp->pdu);
paul15935e92005-05-03 09:27:23 +0000472 lsp->pdu = stream_dup (stream);
Josh Bailey3f045a02012-03-24 08:35:20 -0700473
jardineb5d44e2003-12-23 08:09:43 +0000474 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000475 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
476 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
477 ISIS_FIXED_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -0700478 lsp->area = area;
479 lsp->level = level;
jardineb5d44e2003-12-23 08:09:43 +0000480 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000481 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000482 /*
483 * Get LSP data i.e. TLVs
484 */
485 expected |= TLVFLAG_AUTH_INFO;
486 expected |= TLVFLAG_AREA_ADDRS;
487 expected |= TLVFLAG_IS_NEIGHS;
jardineb5d44e2003-12-23 08:09:43 +0000488 expected |= TLVFLAG_NLPID;
489 if (area->dynhostname)
490 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000491 if (area->newmetric)
492 {
493 expected |= TLVFLAG_TE_IS_NEIGHS;
494 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
495 expected |= TLVFLAG_TE_ROUTER_ID;
496 }
jardineb5d44e2003-12-23 08:09:43 +0000497 expected |= TLVFLAG_IPV4_ADDR;
498 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
499 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
500#ifdef HAVE_IPV6
501 expected |= TLVFLAG_IPV6_ADDR;
502 expected |= TLVFLAG_IPV6_REACHABILITY;
503#endif /* HAVE_IPV6 */
504
Josh Bailey3f045a02012-03-24 08:35:20 -0700505 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
506 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
507 ntohs (lsp->lsp_header->pdu_len) -
508 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
509 &expected, &found, &lsp->tlv_data,
510 NULL);
511 if (retval != ISIS_OK)
hassof390d2c2004-09-10 20:48:21 +0000512 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700513 zlog_warn ("Could not parse LSP");
514 return;
515 }
516
517 if ((found & TLVFLAG_DYN_HOSTNAME) && (area->dynhostname))
518 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700519 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
520 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
521 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : IS_LEVEL_1);
hassof390d2c2004-09-10 20:48:21 +0000522 }
jardineb5d44e2003-12-23 08:09:43 +0000523
Josh Bailey3f045a02012-03-24 08:35:20 -0700524 return;
jardineb5d44e2003-12-23 08:09:43 +0000525}
526
527void
Josh Bailey3f045a02012-03-24 08:35:20 -0700528lsp_update (struct isis_lsp *lsp, struct stream *stream,
529 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000530{
hasso4eda93a2005-09-18 17:51:02 +0000531 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000532
Josh Bailey3f045a02012-03-24 08:35:20 -0700533 /* Remove old LSP from database. This is required since the
534 * lsp_update_data will free the lsp->pdu (which has the key, lsp_id)
535 * and will update it with the new data in the stream. */
hasso4eda93a2005-09-18 17:51:02 +0000536 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
537 if (dnode)
538 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000539
jardineb5d44e2003-12-23 08:09:43 +0000540 /* rebuild the lsp data */
Josh Bailey3f045a02012-03-24 08:35:20 -0700541 lsp_update_data (lsp, stream, area, level);
jardineb5d44e2003-12-23 08:09:43 +0000542
Josh Bailey3f045a02012-03-24 08:35:20 -0700543 /* insert the lsp back into the database */
544 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000545}
546
jardineb5d44e2003-12-23 08:09:43 +0000547/* creation of LSP directly from what we received */
548struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000549lsp_new_from_stream_ptr (struct stream *stream,
550 u_int16_t pdu_len, struct isis_lsp *lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -0700551 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000552{
553 struct isis_lsp *lsp;
554
hassoaac372f2005-09-01 17:52:33 +0000555 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -0700556 lsp_update_data (lsp, stream, area, level);
hassof390d2c2004-09-10 20:48:21 +0000557
558 if (lsp0 == NULL)
559 {
560 /*
561 * zero lsp -> create the list for fragments
562 */
563 lsp->lspu.frags = list_new ();
564 }
565 else
566 {
567 /*
568 * a fragment -> set the backpointer and add this to zero lsps frag list
569 */
570 lsp->lspu.zero_lsp = lsp0;
571 listnode_add (lsp0->lspu.frags, lsp);
572 }
573
jardineb5d44e2003-12-23 08:09:43 +0000574 return lsp;
575}
576
577struct isis_lsp *
Christian Frankef1fc1db2015-11-10 18:43:31 +0100578lsp_new(struct isis_area *area, u_char * lsp_id,
579 u_int16_t rem_lifetime, u_int32_t seq_num,
580 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000581{
582 struct isis_lsp *lsp;
583
hassoaac372f2005-09-01 17:52:33 +0000584 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Christian Frankef1fc1db2015-11-10 18:43:31 +0100585 lsp->area = area;
Christian Franke390f16e2015-11-10 18:04:44 +0100586
Christian Frankef1fc1db2015-11-10 18:43:31 +0100587 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
jardineb5d44e2003-12-23 08:09:43 +0000588 if (LSP_FRAGMENT (lsp_id) == 0)
589 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000590 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
591 lsp->lsp_header = (struct isis_link_state_hdr *)
592 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
593
jardineb5d44e2003-12-23 08:09:43 +0000594 /* at first we fill the FIXED HEADER */
Josh Bailey3f045a02012-03-24 08:35:20 -0700595 (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
hassof390d2c2004-09-10 20:48:21 +0000596 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
597
jardineb5d44e2003-12-23 08:09:43 +0000598 /* now for the LSP HEADER */
599 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000600 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000601 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000602 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000603 lsp->lsp_header->seq_num = htonl (seq_num);
604 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
605 lsp->lsp_header->lsp_bits = lsp_bits;
606 lsp->level = level;
607 lsp->age_out = ZERO_AGE_LIFETIME;
608
paul9985f832005-02-09 15:51:56 +0000609 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000610
hassoc89c05d2005-09-04 21:36:36 +0000611 if (isis->debugs & DEBUG_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -0700612 zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
hassoc89c05d2005-09-04 21:36:36 +0000613 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
614 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -0700615 ntohl (lsp->lsp_header->pdu_len),
hassoc89c05d2005-09-04 21:36:36 +0000616 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000617
618 return lsp;
619}
620
621void
hassof390d2c2004-09-10 20:48:21 +0000622lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000623{
624 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700625 if (lsp->lsp_header->seq_num != 0)
626 {
627 isis_spf_schedule (lsp->area, lsp->level);
628#ifdef HAVE_IPV6
629 isis_spf_schedule6 (lsp->area, lsp->level);
630#endif
631 }
jardineb5d44e2003-12-23 08:09:43 +0000632}
633
634/*
635 * Build a list of LSPs with non-zero ht bounded by start and stop ids
636 */
hassof390d2c2004-09-10 20:48:21 +0000637void
638lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
639 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000640{
641 dnode_t *first, *last, *curr;
642
643 first = dict_lower_bound (lspdb, start_id);
644 if (!first)
645 return;
hassof390d2c2004-09-10 20:48:21 +0000646
jardineb5d44e2003-12-23 08:09:43 +0000647 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000648
jardineb5d44e2003-12-23 08:09:43 +0000649 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000650
651 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000652 listnode_add (list, first->dict_data);
653
hassof390d2c2004-09-10 20:48:21 +0000654 while (curr)
655 {
656 curr = dict_next (lspdb, curr);
657 if (curr &&
658 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
659 listnode_add (list, curr->dict_data);
660 if (curr == last)
661 break;
662 }
663
jardineb5d44e2003-12-23 08:09:43 +0000664 return;
665}
666
667/*
Josh Bailey3f045a02012-03-24 08:35:20 -0700668 * Build a list of num_lsps LSPs bounded by start_id and stop_id.
jardineb5d44e2003-12-23 08:09:43 +0000669 */
hassof390d2c2004-09-10 20:48:21 +0000670void
Josh Bailey3f045a02012-03-24 08:35:20 -0700671lsp_build_list (u_char * start_id, u_char * stop_id, u_char num_lsps,
hassof390d2c2004-09-10 20:48:21 +0000672 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000673{
Josh Bailey3f045a02012-03-24 08:35:20 -0700674 u_char count;
jardineb5d44e2003-12-23 08:09:43 +0000675 dnode_t *first, *last, *curr;
676
677 first = dict_lower_bound (lspdb, start_id);
678 if (!first)
679 return;
hassof390d2c2004-09-10 20:48:21 +0000680
jardineb5d44e2003-12-23 08:09:43 +0000681 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000682
jardineb5d44e2003-12-23 08:09:43 +0000683 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000684
jardineb5d44e2003-12-23 08:09:43 +0000685 listnode_add (list, first->dict_data);
Josh Bailey3f045a02012-03-24 08:35:20 -0700686 count = 1;
jardineb5d44e2003-12-23 08:09:43 +0000687
hassof390d2c2004-09-10 20:48:21 +0000688 while (curr)
689 {
690 curr = dict_next (lspdb, curr);
691 if (curr)
Josh Bailey3f045a02012-03-24 08:35:20 -0700692 {
693 listnode_add (list, curr->dict_data);
694 count++;
695 }
696 if (count == num_lsps || curr == last)
697 break;
hassof390d2c2004-09-10 20:48:21 +0000698 }
699
jardineb5d44e2003-12-23 08:09:43 +0000700 return;
701}
702
703/*
704 * Build a list of LSPs with SSN flag set for the given circuit
705 */
706void
Josh Bailey3f045a02012-03-24 08:35:20 -0700707lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps,
708 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000709{
710 dnode_t *dnode, *next;
711 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -0700712 u_char count = 0;
hassof390d2c2004-09-10 20:48:21 +0000713
jardineb5d44e2003-12-23 08:09:43 +0000714 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000715 while (dnode != NULL)
716 {
717 next = dict_next (lspdb, dnode);
718 lsp = dnode_get (dnode);
719 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -0700720 {
721 listnode_add (list, lsp);
722 ++count;
723 }
724 if (count == num_lsps)
725 break;
hassof390d2c2004-09-10 20:48:21 +0000726 dnode = next;
727 }
728
jardineb5d44e2003-12-23 08:09:43 +0000729 return;
730}
731
hasso92365882005-01-18 13:53:33 +0000732static void
jardineb5d44e2003-12-23 08:09:43 +0000733lsp_set_time (struct isis_lsp *lsp)
734{
735 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000736
737 if (lsp->lsp_header->rem_lifetime == 0)
738 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700739 if (lsp->age_out > 0)
740 lsp->age_out--;
hassof390d2c2004-09-10 20:48:21 +0000741 return;
742 }
jardineb5d44e2003-12-23 08:09:43 +0000743
hassof390d2c2004-09-10 20:48:21 +0000744 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000745 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
746}
747
hasso92365882005-01-18 13:53:33 +0000748static void
hassof390d2c2004-09-10 20:48:21 +0000749lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000750{
751 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000752 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000753
754 if (dynhost)
755 dyn = dynhn_find_by_id (lsp_id);
756 else
757 dyn = NULL;
758
759 if (dyn)
Josh Bailey3f045a02012-03-24 08:35:20 -0700760 sprintf ((char *)id, "%.14s", dyn->name.name);
761 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
762 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000763 else
hassof390d2c2004-09-10 20:48:21 +0000764 memcpy (id, sysid_print (lsp_id), 15);
hassof390d2c2004-09-10 20:48:21 +0000765 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000766 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000767 LSP_FRAGMENT (lsp_id));
768 else
hassof7c43dc2004-09-26 16:24:14 +0000769 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000770}
771
hassof390d2c2004-09-10 20:48:21 +0000772/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000773const char *
hassof390d2c2004-09-10 20:48:21 +0000774lsp_bits2string (u_char * lsp_bits)
775{
776 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000777
hassof390d2c2004-09-10 20:48:21 +0000778 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000779 return " none";
780
781 /* we only focus on the default metric */
782 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000783 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000784
785 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000786 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000787
hassof390d2c2004-09-10 20:48:21 +0000788 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
789
jardineb5d44e2003-12-23 08:09:43 +0000790 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000791
hassof390d2c2004-09-10 20:48:21 +0000792 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000793}
794
795/* this function prints the lsp on show isis database */
Josh Bailey3f045a02012-03-24 08:35:20 -0700796void
797lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000798{
jardineb5d44e2003-12-23 08:09:43 +0000799 u_char LSPid[255];
Josh Bailey3f045a02012-03-24 08:35:20 -0700800 char age_out[8];
jardineb5d44e2003-12-23 08:09:43 +0000801
802 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700803 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
804 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len));
805 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
806 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
hassof390d2c2004-09-10 20:48:21 +0000807 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
Josh Bailey3f045a02012-03-24 08:35:20 -0700808 {
809 snprintf (age_out, 8, "(%u)", lsp->age_out);
810 age_out[7] = '\0';
811 vty_out (vty, "%7s ", age_out);
812 }
jardineb5d44e2003-12-23 08:09:43 +0000813 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700814 vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime));
815 vty_out (vty, "%s%s",
816 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000817}
818
Josh Bailey3f045a02012-03-24 08:35:20 -0700819void
820lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000821{
jardineb5d44e2003-12-23 08:09:43 +0000822 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000823 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000824 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000825 struct is_neigh *is_neigh;
826 struct te_is_neigh *te_is_neigh;
827 struct ipv4_reachability *ipv4_reach;
828 struct in_addr *ipv4_addr;
829 struct te_ipv4_reachability *te_ipv4_reach;
830#ifdef HAVE_IPV6
831 struct ipv6_reachability *ipv6_reach;
832 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000833 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000834#endif
835 u_char LSPid[255];
836 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000837 u_char ipv4_reach_prefix[20];
838 u_char ipv4_reach_mask[20];
839 u_char ipv4_address[20];
840
841 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700842 lsp_print (lsp, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000843
844 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000845 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000846 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000847 {
hasso1cd80842004-10-07 20:07:40 +0000848 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000849 isonet_print (area_addr->area_addr, area_addr->addr_len),
850 VTY_NEWLINE);
851 }
paul1eb8ef22005-04-07 07:30:20 +0000852
jardineb5d44e2003-12-23 08:09:43 +0000853 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000854 if (lsp->tlv_data.nlpids)
855 {
856 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
857 {
858 switch (lsp->tlv_data.nlpids->nlpids[i])
859 {
860 case NLPID_IP:
861 case NLPID_IPV6:
Josh Bailey3f045a02012-03-24 08:35:20 -0700862 vty_out (vty, " NLPID : 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000863 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
864 break;
865 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700866 vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000867 break;
868 }
869 }
870 }
jardineb5d44e2003-12-23 08:09:43 +0000871
872 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000873 if (lsp->tlv_data.hostname)
874 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700875 bzero (hostname, sizeof (hostname));
hassof390d2c2004-09-10 20:48:21 +0000876 memcpy (hostname, lsp->tlv_data.hostname->name,
877 lsp->tlv_data.hostname->namelen);
Josh Bailey3f045a02012-03-24 08:35:20 -0700878 vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000879 }
hassof390d2c2004-09-10 20:48:21 +0000880
Josh Bailey3f045a02012-03-24 08:35:20 -0700881 /* authentication tlv */
882 if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED)
883 {
884 if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5)
885 vty_out (vty, " Auth type : md5%s", VTY_NEWLINE);
886 else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT)
887 vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE);
888 }
hassof390d2c2004-09-10 20:48:21 +0000889
hasso1cd80842004-10-07 20:07:40 +0000890 /* TE router id */
891 if (lsp->tlv_data.router_id)
892 {
893 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
894 sizeof (ipv4_address));
Josh Bailey3f045a02012-03-24 08:35:20 -0700895 vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE);
hasso1cd80842004-10-07 20:07:40 +0000896 }
897
Josh Bailey3f045a02012-03-24 08:35:20 -0700898 if (lsp->tlv_data.ipv4_addrs)
899 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
900 {
901 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
902 vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE);
903 }
904
hasso1cd80842004-10-07 20:07:40 +0000905 /* for the IS neighbor tlv */
906 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000907 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000908 {
909 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700910 vty_out (vty, " Metric : %-8d IS : %s%s",
hasso1cd80842004-10-07 20:07:40 +0000911 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
912 }
hasso1cd80842004-10-07 20:07:40 +0000913
jardineb5d44e2003-12-23 08:09:43 +0000914 /* for the internal reachable tlv */
915 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000916 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
917 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000918 {
919 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
920 sizeof (ipv4_reach_prefix));
921 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
922 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700923 vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000924 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
925 ipv4_reach_mask, VTY_NEWLINE);
926 }
hasso2097cd82003-12-23 11:51:08 +0000927
928 /* for the external reachable tlv */
929 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000930 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
931 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000932 {
933 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
934 sizeof (ipv4_reach_prefix));
935 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
936 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700937 vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000938 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
939 ipv4_reach_mask, VTY_NEWLINE);
940 }
paul1eb8ef22005-04-07 07:30:20 +0000941
hasso2097cd82003-12-23 11:51:08 +0000942 /* IPv6 tlv */
943#ifdef HAVE_IPV6
944 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000945 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000946 {
947 memset (&in6, 0, sizeof (in6));
948 memcpy (in6.s6_addr, ipv6_reach->prefix,
949 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000950 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
David Lamparter6db3ef62015-03-03 09:07:43 +0100951 if ((ipv6_reach->control_info &
hassof390d2c2004-09-10 20:48:21 +0000952 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
Josh Bailey3f045a02012-03-24 08:35:20 -0700953 vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000954 ntohl (ipv6_reach->metric),
955 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000956 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700957 vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000958 ntohl (ipv6_reach->metric),
959 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000960 }
961#endif
paul1eb8ef22005-04-07 07:30:20 +0000962
hasso1cd80842004-10-07 20:07:40 +0000963 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000964 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000965 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000966 {
hassof390d2c2004-09-10 20:48:21 +0000967 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700968 vty_out (vty, " Metric : %-8d IS-Extended : %s%s",
969 GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000970 }
jardineb5d44e2003-12-23 08:09:43 +0000971
hasso1cd80842004-10-07 20:07:40 +0000972 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000973 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000974 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
975 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000976 {
hasso1cd80842004-10-07 20:07:40 +0000977 /* FIXME: There should be better way to output this stuff. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700978 vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000979 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000980 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
981 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000982 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000983 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700984 vty_out (vty, "%s", VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000985
hassof390d2c2004-09-10 20:48:21 +0000986 return;
jardineb5d44e2003-12-23 08:09:43 +0000987}
988
989/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000990int
991lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000992{
993
hassof390d2c2004-09-10 20:48:21 +0000994 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000995 int lsp_count = 0;
996
hassof390d2c2004-09-10 20:48:21 +0000997 if (detail == ISIS_UI_LEVEL_BRIEF)
998 {
999 while (node != NULL)
1000 {
1001 /* I think it is unnecessary, so I comment it out */
1002 /* dict_contains (lspdb, node); */
1003 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001004 lsp_print (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001005 node = next;
1006 lsp_count++;
1007 }
jardineb5d44e2003-12-23 08:09:43 +00001008 }
hassof390d2c2004-09-10 20:48:21 +00001009 else if (detail == ISIS_UI_LEVEL_DETAIL)
1010 {
1011 while (node != NULL)
1012 {
1013 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001014 lsp_print_detail (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001015 node = next;
1016 lsp_count++;
1017 }
jardineb5d44e2003-12-23 08:09:43 +00001018 }
jardineb5d44e2003-12-23 08:09:43 +00001019
1020 return lsp_count;
1021}
1022
jardineb5d44e2003-12-23 08:09:43 +00001023#define FRAG_THOLD(S,T) \
Josh Bailey3f045a02012-03-24 08:35:20 -07001024 ((STREAM_SIZE(S)*T)/100)
jardineb5d44e2003-12-23 08:09:43 +00001025
1026/* stream*, area->lsp_frag_threshold, increment */
1027#define FRAG_NEEDED(S,T,I) \
1028 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1029
hassoaa4376e2005-09-26 17:39:48 +00001030/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
1031 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +00001032static void
jardineb5d44e2003-12-23 08:09:43 +00001033lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001034 int tlvsize, int frag_thold,
1035 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001036{
1037 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001038
jardineb5d44e2003-12-23 08:09:43 +00001039 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001040 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1041 {
1042 tlv_build_func (*from, lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07001043 if (listcount (*to) != 0)
1044 {
1045 struct listnode *node, *nextnode;
1046 void *elem;
1047
1048 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1049 {
1050 listnode_add (*to, elem);
1051 list_delete_node (*from, node);
1052 }
1053 }
1054 else
1055 {
1056 list_free (*to);
1057 *to = *from;
1058 *from = NULL;
1059 }
jardineb5d44e2003-12-23 08:09:43 +00001060 }
hassof390d2c2004-09-10 20:48:21 +00001061 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1062 {
1063 /* fit all we can */
1064 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1065 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
Josh Bailey3f045a02012-03-24 08:35:20 -07001066 count = count / tlvsize;
1067 if (count > (int)listcount (*from))
1068 count = listcount (*from);
hassof390d2c2004-09-10 20:48:21 +00001069 for (i = 0; i < count; i++)
1070 {
paul1eb8ef22005-04-07 07:30:20 +00001071 listnode_add (*to, listgetdata (listhead (*from)));
1072 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001073 }
1074 tlv_build_func (*to, lsp->pdu);
1075 }
paul9985f832005-02-09 15:51:56 +00001076 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001077 return;
1078}
1079
Josh Bailey3f045a02012-03-24 08:35:20 -07001080static u_int16_t
1081lsp_rem_lifetime (struct isis_area *area, int level)
1082{
1083 u_int16_t rem_lifetime;
1084
1085 /* Add jitter to configured LSP lifetime */
1086 rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1],
1087 MAX_AGE_JITTER);
1088
1089 /* No jitter if the max refresh will be less than configure gen interval */
1090 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1091 rem_lifetime = area->max_lsp_lifetime[level - 1];
1092
1093 return rem_lifetime;
1094}
1095
1096static u_int16_t
1097lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1098{
1099 struct isis_area *area = lsp->area;
1100 int level = lsp->level;
1101 u_int16_t refresh_time;
1102
1103 /* Add jitter to LSP refresh time */
1104 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1105 MAX_LSP_GEN_JITTER);
1106
1107 /* RFC 4444 : make sure the refresh time is at least less than 300
1108 * of the remaining lifetime and more than gen interval */
1109 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1110 refresh_time > (rem_lifetime - 300))
1111 refresh_time = rem_lifetime - 300;
1112
1113 assert (area->lsp_gen_interval[level - 1] < refresh_time);
1114
1115 return refresh_time;
1116}
1117
hasso92365882005-01-18 13:53:33 +00001118static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001119lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1120 int level)
jardineb5d44e2003-12-23 08:09:43 +00001121{
1122 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001123 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1124
jardineb5d44e2003-12-23 08:09:43 +00001125 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1126 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001127 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001128 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001129 if (lsp)
1130 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001131 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001132 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001133 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001134 }
Christian Frankef1fc1db2015-11-10 18:43:31 +01001135 lsp = lsp_new (area, frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001136 lsp_bits_generate (level, area->overload_bit,
1137 area->attached_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001138 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001139 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001140 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001141 listnode_add (lsp0->lspu.frags, lsp);
1142 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001143 return lsp;
1144}
1145
1146/*
1147 * Builds the LSP data part. This func creates a new frag whenever
1148 * area->lsp_frag_threshold is exceeded.
1149 */
hasso92365882005-01-18 13:53:33 +00001150static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001151lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001152{
1153 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001154 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001155 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001156 int level = lsp->level;
1157 struct isis_circuit *circuit;
1158 struct prefix_ipv4 *ipv4;
1159 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001160 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001161 struct isis_adjacency *nei;
1162#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001163 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001164 struct ipv6_reachability *ip6reach;
1165#endif /* HAVE_IPV6 */
1166 struct tlvs tlv_data;
1167 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001168 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001169 uint32_t expected = 0, found = 0;
1170 uint32_t metric;
1171 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1172 int retval = ISIS_OK;
1173
1174 /*
1175 * Building the zero lsp
1176 */
1177 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1178
1179 /* Reset stream endp. Stream is always there and on every LSP refresh only
1180 * TLV part of it is overwritten. So we must seek past header we will not
1181 * touch. */
1182 stream_reset (lsp->pdu);
1183 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1184
1185 /*
1186 * Add the authentication info if its present
1187 */
1188 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001189
1190 /*
1191 * First add the tlvs related to area
1192 */
hassof390d2c2004-09-10 20:48:21 +00001193
jardineb5d44e2003-12-23 08:09:43 +00001194 /* Area addresses */
1195 if (lsp->tlv_data.area_addrs == NULL)
1196 lsp->tlv_data.area_addrs = list_new ();
1197 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001198 if (listcount (lsp->tlv_data.area_addrs) > 0)
1199 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1200
jardineb5d44e2003-12-23 08:09:43 +00001201 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001202 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001203#ifdef HAVE_IPV6
1204 || area->ipv6_circuits > 0
1205#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001206 )
jardineb5d44e2003-12-23 08:09:43 +00001207 {
hassoaac372f2005-09-01 17:52:33 +00001208 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001209 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001210 if (area->ip_circuits > 0)
1211 {
1212 lsp->tlv_data.nlpids->count++;
1213 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1214 }
jardineb5d44e2003-12-23 08:09:43 +00001215#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001216 if (area->ipv6_circuits > 0)
1217 {
1218 lsp->tlv_data.nlpids->count++;
1219 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1220 NLPID_IPV6;
1221 }
jardineb5d44e2003-12-23 08:09:43 +00001222#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001223 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001224 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001225
jardineb5d44e2003-12-23 08:09:43 +00001226 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001227 if (area->dynhostname)
1228 {
Christian Frankef35169e2015-11-12 14:09:08 +01001229 const char *hostname = unix_hostname();
1230 size_t hostname_len = strlen(hostname);
1231
hassof390d2c2004-09-10 20:48:21 +00001232 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1233 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001234
Christian Frankef35169e2015-11-12 14:09:08 +01001235 strncpy((char *)lsp->tlv_data.hostname->name, hostname,
1236 sizeof(lsp->tlv_data.hostname->name));
1237 if (hostname_len <= MAX_TLV_LEN)
1238 lsp->tlv_data.hostname->namelen = hostname_len;
1239 else
1240 lsp->tlv_data.hostname->namelen = MAX_TLV_LEN;
1241
Josh Bailey3f045a02012-03-24 08:35:20 -07001242 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001243 }
jardineb5d44e2003-12-23 08:09:43 +00001244
hasso81ad8f62005-09-26 17:58:24 +00001245 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1246 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1247 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001248 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001249 {
hasso18a6dce2004-10-03 18:18:34 +00001250 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001251 {
1252 lsp->tlv_data.ipv4_addrs = list_new ();
1253 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1254 }
hasso18a6dce2004-10-03 18:18:34 +00001255
1256 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001257 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001258 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001259 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001260
hasso81ad8f62005-09-26 17:58:24 +00001261 /* Exactly same data is put into TE router ID TLV, but only if new style
1262 * TLV's are in use. */
1263 if (area->newmetric)
1264 {
1265 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1266 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001267 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1268 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1269 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001270 }
hasso18a6dce2004-10-03 18:18:34 +00001271 }
hassof1082d12005-09-19 04:23:34 +00001272
hasso81ad8f62005-09-26 17:58:24 +00001273 memset (&tlv_data, 0, sizeof (struct tlvs));
1274
hassof1082d12005-09-19 04:23:34 +00001275#ifdef TOPOLOGY_GENERATE
1276 /* If topology exists (and we create topology for level 1 only), create
1277 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001278 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001279 {
1280 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001281 {
1282 tlv_data.is_neighs = list_new ();
1283 tlv_data.is_neighs->del = free_tlv;
1284 }
hasso3fdb2dd2005-09-28 18:45:54 +00001285 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001286
1287 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1288 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1289 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1290 is_neigh->metrics.metric_default = 0x01;
1291 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1292 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1293 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1294 listnode_add (tlv_data.is_neighs, is_neigh);
1295 }
1296#endif /* TOPOLOGY_GENERATE */
1297
hasso18a6dce2004-10-03 18:18:34 +00001298 /*
jardineb5d44e2003-12-23 08:09:43 +00001299 * Then build lists of tlvs related to circuits
1300 */
hasso3fdb2dd2005-09-28 18:45:54 +00001301 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001302 {
hassof390d2c2004-09-10 20:48:21 +00001303 if (circuit->state != C_STATE_UP)
1304 continue;
jardineb5d44e2003-12-23 08:09:43 +00001305
hassof390d2c2004-09-10 20:48:21 +00001306 /*
1307 * Add IPv4 internal reachability of this circuit
1308 */
1309 if (circuit->ip_router && circuit->ip_addrs &&
1310 circuit->ip_addrs->count > 0)
1311 {
hassoaa4376e2005-09-26 17:39:48 +00001312 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001313 {
hassoaa4376e2005-09-26 17:39:48 +00001314 if (tlv_data.ipv4_int_reachs == NULL)
1315 {
1316 tlv_data.ipv4_int_reachs = list_new ();
1317 tlv_data.ipv4_int_reachs->del = free_tlv;
1318 }
hasso3fdb2dd2005-09-28 18:45:54 +00001319 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001320 {
1321 ipreach =
1322 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1323 ipreach->metrics = circuit->metrics[level - 1];
1324 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1325 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1326 (ipv4->prefix.s_addr));
1327 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1328 }
hassof390d2c2004-09-10 20:48:21 +00001329 }
hassoaa4376e2005-09-26 17:39:48 +00001330 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001331 {
hassoaa4376e2005-09-26 17:39:48 +00001332 if (tlv_data.te_ipv4_reachs == NULL)
1333 {
1334 tlv_data.te_ipv4_reachs = list_new ();
1335 tlv_data.te_ipv4_reachs->del = free_tlv;
1336 }
hasso3fdb2dd2005-09-28 18:45:54 +00001337 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001338 {
1339 /* FIXME All this assumes that we have no sub TLVs. */
1340 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1341 sizeof (struct te_ipv4_reachability) +
1342 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001343
1344 if (area->oldmetric)
1345 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1346 else
1347 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1348
hassoaa4376e2005-09-26 17:39:48 +00001349 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1350 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1351 (ipv4->prefixlen + 7)/8);
1352 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1353 }
hassof390d2c2004-09-10 20:48:21 +00001354 }
hassof390d2c2004-09-10 20:48:21 +00001355 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001356
jardineb5d44e2003-12-23 08:09:43 +00001357#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001358 /*
1359 * Add IPv6 reachability of this circuit
1360 */
1361 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1362 circuit->ipv6_non_link->count > 0)
1363 {
1364
1365 if (tlv_data.ipv6_reachs == NULL)
1366 {
1367 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001368 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001369 }
hasso3fdb2dd2005-09-28 18:45:54 +00001370 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001371 {
hassof390d2c2004-09-10 20:48:21 +00001372 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001373 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001374
1375 if (area->oldmetric)
1376 ip6reach->metric =
1377 htonl (circuit->metrics[level - 1].metric_default);
1378 else
1379 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1380
hassof390d2c2004-09-10 20:48:21 +00001381 ip6reach->control_info = 0;
1382 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001383 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1384 apply_mask_ipv6 (ip6prefix);
1385 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1386 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001387 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1388 }
1389 }
1390#endif /* HAVE_IPV6 */
1391
1392 switch (circuit->circ_type)
1393 {
1394 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001395 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001396 {
hassoaa4376e2005-09-26 17:39:48 +00001397 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001398 {
hassoaa4376e2005-09-26 17:39:48 +00001399 if (tlv_data.is_neighs == NULL)
1400 {
1401 tlv_data.is_neighs = list_new ();
1402 tlv_data.is_neighs->del = free_tlv;
1403 }
1404 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001405 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001406 memcpy (is_neigh->neigh_id,
1407 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1408 else
1409 memcpy (is_neigh->neigh_id,
1410 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1411 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001412 if (!memcmp (is_neigh->neigh_id, zero_id,
1413 ISIS_SYS_ID_LEN + 1))
1414 XFREE (MTYPE_ISIS_TLV, is_neigh);
1415 else
1416 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001417 }
hassoaa4376e2005-09-26 17:39:48 +00001418 if (area->newmetric)
1419 {
hassoaa4376e2005-09-26 17:39:48 +00001420 if (tlv_data.te_is_neighs == NULL)
1421 {
1422 tlv_data.te_is_neighs = list_new ();
1423 tlv_data.te_is_neighs->del = free_tlv;
1424 }
1425 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1426 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001427 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001428 memcpy (te_is_neigh->neigh_id,
1429 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1430 else
1431 memcpy (te_is_neigh->neigh_id,
1432 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001433 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001434 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001435 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001436 metric = circuit->te_metric[level - 1];
1437 SET_TE_METRIC(te_is_neigh, metric);
1438 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1439 ISIS_SYS_ID_LEN + 1))
1440 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1441 else
1442 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
hassoaa4376e2005-09-26 17:39:48 +00001443 }
hassof390d2c2004-09-10 20:48:21 +00001444 }
1445 break;
1446 case CIRCUIT_T_P2P:
1447 nei = circuit->u.p2p.neighbor;
1448 if (nei && (level & nei->circuit_t))
1449 {
hassoaa4376e2005-09-26 17:39:48 +00001450 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001451 {
hassoaa4376e2005-09-26 17:39:48 +00001452 if (tlv_data.is_neighs == NULL)
1453 {
1454 tlv_data.is_neighs = list_new ();
1455 tlv_data.is_neighs->del = free_tlv;
1456 }
1457 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1458 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1459 is_neigh->metrics = circuit->metrics[level - 1];
1460 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001461 }
hassoaa4376e2005-09-26 17:39:48 +00001462 if (area->newmetric)
1463 {
1464 uint32_t metric;
1465
1466 if (tlv_data.te_is_neighs == NULL)
1467 {
1468 tlv_data.te_is_neighs = list_new ();
1469 tlv_data.te_is_neighs->del = free_tlv;
1470 }
1471 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1472 sizeof (struct te_is_neigh));
1473 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001474 metric = circuit->te_metric[level - 1];
1475 SET_TE_METRIC(te_is_neigh, metric);
hassoaa4376e2005-09-26 17:39:48 +00001476 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1477 }
hassof390d2c2004-09-10 20:48:21 +00001478 }
1479 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001480 case CIRCUIT_T_LOOPBACK:
1481 break;
hassof390d2c2004-09-10 20:48:21 +00001482 default:
1483 zlog_warn ("lsp_area_create: unknown circuit type");
1484 }
1485 }
1486
1487 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1488 {
1489 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1490 lsp->tlv_data.ipv4_int_reachs = list_new ();
1491 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1492 &lsp->tlv_data.ipv4_int_reachs,
1493 IPV4_REACH_LEN, area->lsp_frag_threshold,
1494 tlv_add_ipv4_reachs);
1495 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1496 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1497 lsp0, area, level);
1498 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001499
hassoaa4376e2005-09-26 17:39:48 +00001500 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1501 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1502 * TLVs (sub TLVs!). */
1503 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1504 {
1505 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1506 lsp->tlv_data.te_ipv4_reachs = list_new ();
1507 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1508 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001509 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1510 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001511 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1512 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1513 lsp0, area, level);
1514 }
hassof390d2c2004-09-10 20:48:21 +00001515
1516#ifdef HAVE_IPV6
1517 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1518 {
1519 if (lsp->tlv_data.ipv6_reachs == NULL)
1520 lsp->tlv_data.ipv6_reachs = list_new ();
1521 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1522 &lsp->tlv_data.ipv6_reachs,
1523 IPV6_REACH_LEN, area->lsp_frag_threshold,
1524 tlv_add_ipv6_reachs);
1525 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1526 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1527 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001528 }
1529#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001530
1531 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1532 {
1533 if (lsp->tlv_data.is_neighs == NULL)
1534 lsp->tlv_data.is_neighs = list_new ();
1535 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1536 &lsp->tlv_data.is_neighs,
1537 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1538 tlv_add_is_neighs);
1539 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1540 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1541 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001542 }
jardineb5d44e2003-12-23 08:09:43 +00001543
hassoaa4376e2005-09-26 17:39:48 +00001544 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1545 {
1546 if (lsp->tlv_data.te_is_neighs == NULL)
1547 lsp->tlv_data.te_is_neighs = list_new ();
1548 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1549 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1550 tlv_add_te_is_neighs);
1551 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1552 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1553 lsp0, area, level);
1554 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001555 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001556
1557 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001558
1559 /* Validate the LSP */
1560 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1561 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1562 stream_get_endp (lsp->pdu) -
1563 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1564 &expected, &found, &tlv_data, NULL);
1565 assert (retval == ISIS_OK);
1566
jardineb5d44e2003-12-23 08:09:43 +00001567 return;
1568}
jardineb5d44e2003-12-23 08:09:43 +00001569
1570/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001571 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001572 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001573int
1574lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001575{
jardineb5d44e2003-12-23 08:09:43 +00001576 struct isis_lsp *oldlsp, *newlsp;
1577 u_int32_t seq_num = 0;
1578 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001579 u_int16_t rem_lifetime, refresh_time;
1580
1581 if ((area == NULL) || (area->is_type & level) != level)
1582 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001583
1584 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1585 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1586
1587 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001588 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1589 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001590 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001591 /* FIXME: we should actually initiate a purge */
1592 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1593 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1594 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001595 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001596 rem_lifetime = lsp_rem_lifetime (area, level);
Christian Frankef1fc1db2015-11-10 18:43:31 +01001597 newlsp = lsp_new (area, lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001598 area->is_type | area->overload_bit | area->attached_bit,
1599 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001600 newlsp->area = area;
1601 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001602
Josh Bailey3f045a02012-03-24 08:35:20 -07001603 lsp_insert (newlsp, area->lspdb[level - 1]);
1604 /* build_lsp_data (newlsp, area); */
1605 lsp_build (newlsp, area);
1606 /* time to calculate our checksum */
1607 lsp_seqnum_update (newlsp);
1608 lsp_set_all_srmflags (newlsp);
1609
1610 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
1611 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
1612 if (level == IS_LEVEL_1)
1613 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1614 lsp_l1_refresh, area, refresh_time);
1615 else if (level == IS_LEVEL_2)
1616 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1617 lsp_l2_refresh, area, refresh_time);
1618
1619 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001620 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001621 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1622 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1623 area->area_tag, level,
1624 rawlspid_print (newlsp->lsp_header->lsp_id),
1625 ntohl (newlsp->lsp_header->pdu_len),
1626 ntohl (newlsp->lsp_header->seq_num),
1627 ntohs (newlsp->lsp_header->checksum),
1628 ntohs (newlsp->lsp_header->rem_lifetime),
1629 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001630 }
jardineb5d44e2003-12-23 08:09:43 +00001631
1632 return ISIS_OK;
1633}
1634
1635/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001636 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001637 */
hasso92365882005-01-18 13:53:33 +00001638static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001639lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001640{
David Lampartere8aca322012-11-27 01:10:30 +00001641 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001642 struct isis_lsp *lsp, *frag;
1643 struct listnode *node;
1644 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001645 u_int16_t rem_lifetime, refresh_time;
1646
1647 if ((area == NULL) || (area->is_type & level) != level)
1648 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001649
David Lampartere8aca322012-11-27 01:10:30 +00001650 lspdb = area->lspdb[level - 1];
1651
jardineb5d44e2003-12-23 08:09:43 +00001652 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1653 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001654
jardineb5d44e2003-12-23 08:09:43 +00001655 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001656
hassof390d2c2004-09-10 20:48:21 +00001657 if (!lsp)
1658 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001659 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1660 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001661 return ISIS_ERROR;
1662 }
1663
1664 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001665 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001666 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1667 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001668 rem_lifetime = lsp_rem_lifetime (area, level);
1669 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001670 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001671
Josh Bailey3f045a02012-03-24 08:35:20 -07001672 lsp->last_generated = time (NULL);
1673 lsp_set_all_srmflags (lsp);
1674 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1675 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001676 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001677 area->overload_bit,
1678 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001679 /* Set the lifetime values of all the fragments to the same value,
1680 * so that no fragment expires before the lsp is refreshed.
1681 */
1682 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1683 lsp_set_all_srmflags (frag);
1684 }
1685
1686 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1687 if (level == IS_LEVEL_1)
1688 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1689 lsp_l1_refresh, area, refresh_time);
1690 else if (level == IS_LEVEL_2)
1691 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1692 lsp_l2_refresh, area, refresh_time);
1693
hassof390d2c2004-09-10 20:48:21 +00001694 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1695 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001696 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
1697 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1698 area->area_tag, level,
1699 rawlspid_print (lsp->lsp_header->lsp_id),
1700 ntohl (lsp->lsp_header->pdu_len),
1701 ntohl (lsp->lsp_header->seq_num),
1702 ntohs (lsp->lsp_header->checksum),
1703 ntohs (lsp->lsp_header->rem_lifetime),
1704 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001705 }
jardineb5d44e2003-12-23 08:09:43 +00001706
jardineb5d44e2003-12-23 08:09:43 +00001707 return ISIS_OK;
1708}
1709
jardineb5d44e2003-12-23 08:09:43 +00001710/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001711 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00001712 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001713static int
1714lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001715{
1716 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001717
1718 area = THREAD_ARG (thread);
1719 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001720
jardineb5d44e2003-12-23 08:09:43 +00001721 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001722 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00001723
Josh Bailey3f045a02012-03-24 08:35:20 -07001724 if ((area->is_type & IS_LEVEL_1) == 0)
1725 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001726
Josh Bailey3f045a02012-03-24 08:35:20 -07001727 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00001728}
1729
Josh Bailey3f045a02012-03-24 08:35:20 -07001730static int
1731lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001732{
1733 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001734
1735 area = THREAD_ARG (thread);
1736 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001737
jardineb5d44e2003-12-23 08:09:43 +00001738 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001739 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001740
Josh Bailey3f045a02012-03-24 08:35:20 -07001741 if ((area->is_type & IS_LEVEL_2) == 0)
1742 return ISIS_ERROR;
1743
1744 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00001745}
1746
hassof390d2c2004-09-10 20:48:21 +00001747int
Josh Bailey3f045a02012-03-24 08:35:20 -07001748lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00001749{
1750 struct isis_lsp *lsp;
1751 u_char id[ISIS_SYS_ID_LEN + 2];
1752 time_t now, diff;
Josh Bailey3f045a02012-03-24 08:35:20 -07001753 struct listnode *cnode;
1754 struct isis_circuit *circuit;
1755 int lvl;
1756
1757 if (area == NULL)
1758 return ISIS_ERROR;
1759
hassof390d2c2004-09-10 20:48:21 +00001760 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1761 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001762 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001763
1764 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00001765 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001766 if (!((level & lvl) && (area->is_type & lvl)))
1767 continue;
1768
1769 if (area->lsp_regenerate_pending[lvl - 1])
1770 continue;
1771
1772 lsp = lsp_search (id, area->lspdb[lvl - 1]);
1773 if (!lsp)
1774 continue;
1775
hassof390d2c2004-09-10 20:48:21 +00001776 /*
1777 * Throttle avoidance
1778 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001779 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00001780 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07001781 if (diff < area->lsp_gen_interval[lvl - 1])
1782 {
1783 area->lsp_regenerate_pending[lvl - 1] = 1;
1784 if (lvl == IS_LEVEL_1)
1785 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1786 lsp_l1_refresh, area,
1787 area->lsp_gen_interval[lvl - 1] - diff);
1788 else if (lvl == IS_LEVEL_2)
1789 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1790 lsp_l2_refresh, area,
1791 area->lsp_gen_interval[lvl - 1] - diff);
1792 }
hassof390d2c2004-09-10 20:48:21 +00001793 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001794 {
Michael Zinggbe62b172012-10-26 11:18:19 +02001795 /*
1796 * lsps are not regenerated if lsp_regenerate function is called
1797 * directly. However if the lsp_regenerate call is queued for
1798 * later execution it works.
1799 */
1800 area->lsp_regenerate_pending[lvl - 1] = 1;
1801 if (lvl == IS_LEVEL_1)
1802 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1803 lsp_l1_refresh, area, 0);
1804 else if (lvl == IS_LEVEL_2)
1805 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1806 lsp_l2_refresh, area, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07001807 }
hassof390d2c2004-09-10 20:48:21 +00001808 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001809
1810 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00001811 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001812 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
1813 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00001814 }
1815
1816 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001817}
1818
1819/*
1820 * Funcs for pseudonode LSPs
1821 */
1822
1823/*
1824 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1825 */
hasso92365882005-01-18 13:53:33 +00001826static void
hassof390d2c2004-09-10 20:48:21 +00001827lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1828 int level)
jardineb5d44e2003-12-23 08:09:43 +00001829{
1830 struct isis_adjacency *adj;
1831 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001832 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001833 struct es_neigh *es_neigh;
1834 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001835 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +00001836
jardineb5d44e2003-12-23 08:09:43 +00001837 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07001838 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001839 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
1840 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00001841
1842 /*
1843 * add self to IS neighbours
1844 */
hassoaa4376e2005-09-26 17:39:48 +00001845 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001846 {
hassoaa4376e2005-09-26 17:39:48 +00001847 if (lsp->tlv_data.is_neighs == NULL)
1848 {
1849 lsp->tlv_data.is_neighs = list_new ();
1850 lsp->tlv_data.is_neighs->del = free_tlv;
1851 }
1852 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001853
hassoaa4376e2005-09-26 17:39:48 +00001854 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1855 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1856 }
1857 if (circuit->area->newmetric)
1858 {
1859 if (lsp->tlv_data.te_is_neighs == NULL)
1860 {
1861 lsp->tlv_data.te_is_neighs = list_new ();
1862 lsp->tlv_data.te_is_neighs->del = free_tlv;
1863 }
1864 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1865
1866 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1867 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1868 }
hassof390d2c2004-09-10 20:48:21 +00001869
1870 adj_list = list_new ();
1871 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1872
hasso3fdb2dd2005-09-28 18:45:54 +00001873 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001874 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001875 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00001876 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001877 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1878 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00001879 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001880 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00001881 {
1882 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00001883 if (circuit->area->oldmetric)
1884 {
1885 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001886
hassoaa4376e2005-09-26 17:39:48 +00001887 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1888 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1889 }
1890 if (circuit->area->newmetric)
1891 {
1892 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1893 sizeof (struct te_is_neigh));
1894 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1895 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1896 }
hassof390d2c2004-09-10 20:48:21 +00001897 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001898 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00001899 {
1900 /* an ES neigbour add it, if we are building level 1 LSP */
1901 /* FIXME: the tlv-format is hard to use here */
1902 if (lsp->tlv_data.es_neighs == NULL)
1903 {
1904 lsp->tlv_data.es_neighs = list_new ();
1905 lsp->tlv_data.es_neighs->del = free_tlv;
1906 }
paul15935e92005-05-03 09:27:23 +00001907 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1908
hassof390d2c2004-09-10 20:48:21 +00001909 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001910 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001911 }
1912 }
jardineb5d44e2003-12-23 08:09:43 +00001913 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001914 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00001915
hassoc0fb2a52005-09-03 16:29:40 +00001916 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001917 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001918 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1919
jardineb5d44e2003-12-23 08:09:43 +00001920 /*
1921 * Add the authentication info if it's present
1922 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001923 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001924
1925 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1926 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1927
hassoaa4376e2005-09-26 17:39:48 +00001928 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
1929 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
1930
jardineb5d44e2003-12-23 08:09:43 +00001931 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1932 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1933
paul9985f832005-02-09 15:51:56 +00001934 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001935
Josh Bailey3f045a02012-03-24 08:35:20 -07001936 /* Recompute authentication and checksum information */
1937 lsp_auth_update (lsp);
1938 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
1939 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00001940
1941 return;
1942}
1943
Josh Bailey3f045a02012-03-24 08:35:20 -07001944int
1945lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00001946{
1947 dict_t *lspdb = circuit->area->lspdb[level - 1];
1948 struct isis_lsp *lsp;
1949 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001950 u_int16_t rem_lifetime, refresh_time;
1951
1952 if ((circuit->is_type & level) != level ||
1953 (circuit->state != C_STATE_UP) ||
1954 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
1955 (circuit->u.bc.is_dr[level - 1] == 0))
1956 return ISIS_ERROR;
1957
1958 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1959 LSP_FRAGMENT (lsp_id) = 0;
1960 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1961
1962 /*
1963 * If for some reason have a pseudo LSP in the db already -> regenerate
1964 */
1965 if (lsp_search (lsp_id, lspdb))
1966 return lsp_regenerate_schedule_pseudo (circuit, level);
1967
1968 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
1969 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Christian Frankef1fc1db2015-11-10 18:43:31 +01001970 lsp = lsp_new (circuit->area, lsp_id, rem_lifetime, 1,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001971 circuit->area->is_type | circuit->area->attached_bit,
1972 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001973 lsp->area = circuit->area;
1974
1975 lsp_build_pseudo (lsp, circuit, level);
1976
1977 lsp->own_lsp = 1;
1978 lsp_insert (lsp, lspdb);
1979 lsp_set_all_srmflags (lsp);
1980
1981 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1982 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1983 circuit->lsp_regenerate_pending[level - 1] = 0;
1984 if (level == IS_LEVEL_1)
1985 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1986 lsp_l1_refresh_pseudo, circuit, refresh_time);
1987 else if (level == IS_LEVEL_2)
1988 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1989 lsp_l2_refresh_pseudo, circuit, refresh_time);
1990
1991 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1992 {
1993 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
1994 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
1995 circuit->area->area_tag, level,
1996 rawlspid_print (lsp->lsp_header->lsp_id),
1997 ntohl (lsp->lsp_header->pdu_len),
1998 ntohl (lsp->lsp_header->seq_num),
1999 ntohs (lsp->lsp_header->checksum),
2000 ntohs (lsp->lsp_header->rem_lifetime),
2001 refresh_time);
2002 }
2003
2004 return ISIS_OK;
2005}
2006
2007static int
2008lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2009{
2010 dict_t *lspdb = circuit->area->lspdb[level - 1];
2011 struct isis_lsp *lsp;
2012 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2013 u_int16_t rem_lifetime, refresh_time;
2014
2015 if ((circuit->is_type & level) != level ||
2016 (circuit->state != C_STATE_UP) ||
2017 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2018 (circuit->u.bc.is_dr[level - 1] == 0))
2019 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002020
jardineb5d44e2003-12-23 08:09:43 +00002021 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002022 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2023 LSP_FRAGMENT (lsp_id) = 0;
2024
jardineb5d44e2003-12-23 08:09:43 +00002025 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002026
2027 if (!lsp)
2028 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002029 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2030 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002031 return ISIS_ERROR;
2032 }
2033 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002034
2035 lsp_build_pseudo (lsp, circuit, level);
2036
Josh Bailey3f045a02012-03-24 08:35:20 -07002037 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002038 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2039 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002040 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2041 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002042 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002043 lsp->last_generated = time (NULL);
2044 lsp_set_all_srmflags (lsp);
2045
2046 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2047 if (level == IS_LEVEL_1)
2048 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2049 lsp_l1_refresh_pseudo, circuit, refresh_time);
2050 else if (level == IS_LEVEL_2)
2051 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2052 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002053
2054 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2055 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002056 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2057 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2058 circuit->area->area_tag, level,
2059 rawlspid_print (lsp->lsp_header->lsp_id),
2060 ntohl (lsp->lsp_header->pdu_len),
2061 ntohl (lsp->lsp_header->seq_num),
2062 ntohs (lsp->lsp_header->checksum),
2063 ntohs (lsp->lsp_header->rem_lifetime),
2064 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002065 }
jardineb5d44e2003-12-23 08:09:43 +00002066
jardineb5d44e2003-12-23 08:09:43 +00002067 return ISIS_OK;
2068}
2069
Josh Bailey3f045a02012-03-24 08:35:20 -07002070/*
2071 * Something has changed or periodic refresh -> regenerate pseudo LSP
2072 */
2073static int
jardineb5d44e2003-12-23 08:09:43 +00002074lsp_l1_refresh_pseudo (struct thread *thread)
2075{
2076 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002077 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002078
hassof390d2c2004-09-10 20:48:21 +00002079 circuit = THREAD_ARG (thread);
2080
hasso13c48f72004-09-10 21:19:13 +00002081 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002082 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002083
Josh Bailey3f045a02012-03-24 08:35:20 -07002084 if ((circuit->u.bc.is_dr[0] == 0) ||
2085 (circuit->is_type & IS_LEVEL_1) == 0)
2086 {
2087 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2088 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2089 LSP_FRAGMENT (id) = 0;
2090 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2091 return ISIS_ERROR;
2092 }
hassof390d2c2004-09-10 20:48:21 +00002093
Josh Bailey3f045a02012-03-24 08:35:20 -07002094 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002095}
2096
Josh Bailey3f045a02012-03-24 08:35:20 -07002097static int
jardineb5d44e2003-12-23 08:09:43 +00002098lsp_l2_refresh_pseudo (struct thread *thread)
2099{
2100 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002101 u_char id[ISIS_SYS_ID_LEN + 2];
2102
hassof390d2c2004-09-10 20:48:21 +00002103 circuit = THREAD_ARG (thread);
2104
hasso13c48f72004-09-10 21:19:13 +00002105 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002106 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002107
Josh Bailey3f045a02012-03-24 08:35:20 -07002108 if ((circuit->u.bc.is_dr[1] == 0) ||
2109 (circuit->is_type & IS_LEVEL_2) == 0)
2110 {
2111 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2112 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2113 LSP_FRAGMENT (id) = 0;
2114 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2115 return ISIS_ERROR;
2116 }
jardineb5d44e2003-12-23 08:09:43 +00002117
Josh Bailey3f045a02012-03-24 08:35:20 -07002118 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002119}
2120
hassof390d2c2004-09-10 20:48:21 +00002121int
Josh Bailey3f045a02012-03-24 08:35:20 -07002122lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002123{
2124 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002125 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2126 time_t now, diff;
2127 int lvl;
jardineb5d44e2003-12-23 08:09:43 +00002128
Josh Bailey3f045a02012-03-24 08:35:20 -07002129 if (circuit == NULL ||
2130 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2131 circuit->state != C_STATE_UP)
2132 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002133
Josh Bailey3f045a02012-03-24 08:35:20 -07002134 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2135 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2136 LSP_FRAGMENT (lsp_id) = 0;
2137 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002138
Josh Bailey3f045a02012-03-24 08:35:20 -07002139 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2140 {
2141 if (!((level & lvl) && (circuit->is_type & lvl)))
2142 continue;
jardineb5d44e2003-12-23 08:09:43 +00002143
Josh Bailey3f045a02012-03-24 08:35:20 -07002144 if (circuit->u.bc.is_dr[lvl - 1] == 0 ||
2145 circuit->lsp_regenerate_pending[lvl - 1])
2146 continue;
hassof390d2c2004-09-10 20:48:21 +00002147
Josh Bailey3f045a02012-03-24 08:35:20 -07002148 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2149 if (!lsp)
2150 continue;
jardineb5d44e2003-12-23 08:09:43 +00002151
Josh Bailey3f045a02012-03-24 08:35:20 -07002152 /*
2153 * Throttle avoidance
2154 */
2155 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2156 diff = now - lsp->last_generated;
2157 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2158 {
2159 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2160 if (lvl == IS_LEVEL_1)
2161 THREAD_TIMER_ON (master,
2162 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2163 lsp_l1_refresh_pseudo, circuit,
2164 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2165 else if (lvl == IS_LEVEL_2)
2166 THREAD_TIMER_ON (master,
2167 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2168 lsp_l2_refresh_pseudo, circuit,
2169 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2170 }
2171 else
2172 {
2173 lsp_regenerate_pseudo (circuit, lvl);
2174 }
2175 }
jardineb5d44e2003-12-23 08:09:43 +00002176
Josh Bailey3f045a02012-03-24 08:35:20 -07002177 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002178}
2179
jardineb5d44e2003-12-23 08:09:43 +00002180/*
2181 * Walk through LSPs for an area
2182 * - set remaining lifetime
2183 * - set LSPs with SRMflag set for sending
2184 */
hassof390d2c2004-09-10 20:48:21 +00002185int
jardineb5d44e2003-12-23 08:09:43 +00002186lsp_tick (struct thread *thread)
2187{
2188 struct isis_area *area;
2189 struct isis_circuit *circuit;
2190 struct isis_lsp *lsp;
2191 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002192 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002193 dnode_t *dnode, *dnode_next;
2194 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002195 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002196
2197 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002198
jardineb5d44e2003-12-23 08:09:43 +00002199 area = THREAD_ARG (thread);
2200 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002201 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002202 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002203
2204 /*
2205 * Build a list of LSPs with (any) SRMflag set
2206 * and removed the ones that have aged out
2207 */
hassof390d2c2004-09-10 20:48:21 +00002208 for (level = 0; level < ISIS_LEVELS; level++)
2209 {
2210 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002211 {
2212 for (dnode = dict_first (area->lspdb[level]);
2213 dnode != NULL; dnode = dnode_next)
2214 {
2215 dnode_next = dict_next (area->lspdb[level], dnode);
2216 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002217
Josh Bailey3f045a02012-03-24 08:35:20 -07002218 /*
2219 * The lsp rem_lifetime is kept at 0 for MaxAge or
2220 * ZeroAgeLifetime depending on explicit purge or
2221 * natural age out. So schedule spf only once when
2222 * the first time rem_lifetime becomes 0.
2223 */
2224 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2225 lsp_set_time (lsp);
2226
2227 /*
2228 * Schedule may run spf which should be done only after
2229 * the lsp rem_lifetime becomes 0 for the first time.
2230 * ISO 10589 - 7.3.16.4 first paragraph.
2231 */
2232 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2233 {
2234 /* 7.3.16.4 a) set SRM flags on all */
2235 lsp_set_all_srmflags (lsp);
2236 /* 7.3.16.4 b) retain only the header FIXME */
2237 /* 7.3.16.4 c) record the time to purge FIXME */
2238 /* run/schedule spf */
2239 /* isis_spf_schedule is called inside lsp_destroy() below;
2240 * so it is not needed here. */
2241 /* isis_spf_schedule (lsp->area, lsp->level); */
2242 }
2243
2244 if (lsp->age_out == 0)
2245 {
2246 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2247 area->area_tag,
2248 lsp->level,
2249 rawlspid_print (lsp->lsp_header->lsp_id),
2250 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002251#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002252 if (lsp->from_topology)
2253 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002254#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002255 lsp_destroy (lsp);
2256 lsp = NULL;
2257 dict_delete_free (area->lspdb[level], dnode);
2258 }
2259 else if (flags_any_set (lsp->SRMflags))
2260 listnode_add (lsp_list, lsp);
2261 }
jardineb5d44e2003-12-23 08:09:43 +00002262
Josh Bailey3f045a02012-03-24 08:35:20 -07002263 /*
2264 * Send LSPs on circuits indicated by the SRMflags
2265 */
2266 if (listcount (lsp_list) > 0)
2267 {
paul1eb8ef22005-04-07 07:30:20 +00002268 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002269 {
2270 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2271 if (circuit->lsp_queue == NULL ||
2272 diff < MIN_LSP_TRANS_INTERVAL)
2273 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002274 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002275 {
2276 if (circuit->upadjcount[lsp->level - 1] &&
2277 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2278 {
2279 /* Add the lsp only if it is not already in lsp
2280 * queue */
2281 if (! listnode_lookup (circuit->lsp_queue, lsp))
2282 {
2283 listnode_add (circuit->lsp_queue, lsp);
2284 thread_add_event (master, send_lsp, circuit, 0);
2285 }
2286 }
2287 }
2288 }
2289 list_delete_all_node (lsp_list);
2290 }
2291 }
jardineb5d44e2003-12-23 08:09:43 +00002292 }
jardineb5d44e2003-12-23 08:09:43 +00002293
2294 list_delete (lsp_list);
2295
2296 return ISIS_OK;
2297}
2298
jardineb5d44e2003-12-23 08:09:43 +00002299void
Josh Bailey3f045a02012-03-24 08:35:20 -07002300lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002301{
2302 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002303 u_int16_t seq_num;
2304 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002305
jardineb5d44e2003-12-23 08:09:43 +00002306 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002307 if (!lsp)
2308 return;
hassof390d2c2004-09-10 20:48:21 +00002309
Josh Bailey3f045a02012-03-24 08:35:20 -07002310 /* store old values */
2311 seq_num = lsp->lsp_header->seq_num;
2312 lsp_bits = lsp->lsp_header->lsp_bits;
2313
2314 /* reset stream */
2315 lsp_clear_data (lsp);
2316 stream_reset (lsp->pdu);
2317
2318 /* update header */
2319 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2320 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2321 lsp->lsp_header->checksum = 0;
2322 lsp->lsp_header->seq_num = seq_num;
2323 lsp->lsp_header->rem_lifetime = 0;
2324 lsp->lsp_header->lsp_bits = lsp_bits;
2325 lsp->level = level;
2326 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2327 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2328
2329 /*
2330 * Add and update the authentication info if its present
2331 */
2332 lsp_auth_add (lsp);
2333 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2334 lsp_auth_update (lsp);
2335 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2336 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2337
2338 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002339
jardineb5d44e2003-12-23 08:09:43 +00002340 return;
2341}
2342
2343/*
2344 * Purge own LSP that is received and we don't have.
2345 * -> Do as in 7.3.16.4
2346 */
2347void
hassof390d2c2004-09-10 20:48:21 +00002348lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2349 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002350{
2351 struct isis_lsp *lsp;
2352
2353 /*
2354 * We need to create the LSP to be purged
2355 */
hassoaac372f2005-09-01 17:52:33 +00002356 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002357 lsp->area = area;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002358 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ?
2359 IS_LEVEL_1 : IS_LEVEL_2;
Christian Frankef1fc1db2015-11-10 18:43:31 +01002360 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
hassof390d2c2004-09-10 20:48:21 +00002361 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002362 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002363 : L2_LINK_STATE);
2364 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2365 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002366 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002367 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002368
jardineb5d44e2003-12-23 08:09:43 +00002369 /*
jardineb5d44e2003-12-23 08:09:43 +00002370 * Set the remaining lifetime to 0
2371 */
2372 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002373
2374 /*
2375 * Add and update the authentication info if its present
2376 */
2377 lsp_auth_add (lsp);
2378 lsp_auth_update (lsp);
2379
2380 /*
2381 * Update the PDU length to header plus any authentication TLV.
2382 */
2383 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2384
jardineb5d44e2003-12-23 08:09:43 +00002385 /*
2386 * Put the lsp into LSPdb
2387 */
hassof390d2c2004-09-10 20:48:21 +00002388 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002389
2390 /*
2391 * Send in to whole area
2392 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002393 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002394
jardineb5d44e2003-12-23 08:09:43 +00002395 return;
2396}
2397
Josh Bailey3f045a02012-03-24 08:35:20 -07002398void lsp_set_all_srmflags (struct isis_lsp *lsp)
2399{
2400 struct listnode *node;
2401 struct isis_circuit *circuit;
2402
2403 assert (lsp);
2404
2405 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2406
2407 if (lsp->area)
2408 {
2409 struct list *circuit_list = lsp->area->circuit_list;
2410 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2411 {
2412 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2413 }
2414 }
2415}
2416
jardineb5d44e2003-12-23 08:09:43 +00002417#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002418static int
jardineb5d44e2003-12-23 08:09:43 +00002419top_lsp_refresh (struct thread *thread)
2420{
hassof390d2c2004-09-10 20:48:21 +00002421 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002422 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002423
2424 lsp = THREAD_ARG (thread);
2425 assert (lsp);
2426
2427 lsp->t_lsp_top_ref = NULL;
2428
hassof1082d12005-09-19 04:23:34 +00002429 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002430
Josh Bailey3f045a02012-03-24 08:35:20 -07002431 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002432 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2433 {
hasso529d65b2004-12-24 00:14:50 +00002434 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2435 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002436 }
hassod3d74742005-09-28 18:30:51 +00002437 /* Refresh dynamic hostname in the cache. */
2438 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2439 IS_LEVEL_1);
2440
David Lampartera47c5832012-06-21 09:55:38 +02002441 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002442 lsp->area->overload_bit,
2443 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002444 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2445 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002446
David Lamparterf50ee932015-03-04 07:13:38 +01002447 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002448 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002449 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002450
2451 return ISIS_OK;
2452}
2453
2454void
2455generate_topology_lsps (struct isis_area *area)
2456{
2457 struct listnode *node;
2458 int i, max = 0;
2459 struct arc *arc;
2460 u_char lspid[ISIS_SYS_ID_LEN + 2];
2461 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002462 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002463
2464 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002465 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002466 {
2467 if (arc->from_node > max)
2468 max = arc->from_node;
2469 if (arc->to_node > max)
2470 max = arc->to_node;
2471 }
jardineb5d44e2003-12-23 08:09:43 +00002472
hassof390d2c2004-09-10 20:48:21 +00002473 for (i = 1; i < (max + 1); i++)
2474 {
2475 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2476 LSP_PSEUDO_ID (lspid) = 0x00;
2477 LSP_FRAGMENT (lspid) = 0x00;
2478 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2479 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002480
Josh Bailey3f045a02012-03-24 08:35:20 -07002481 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Christian Frankef1fc1db2015-11-10 18:43:31 +01002482 lsp = lsp_new (area, lspid, rem_lifetime, 1,
2483 IS_LEVEL_1 | area->overload_bit | area->attached_bit,
2484 0, 1);
hassof1082d12005-09-19 04:23:34 +00002485 if (!lsp)
2486 return;
Josh Bailey3f045a02012-03-24 08:35:20 -07002487 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002488
hassof1082d12005-09-19 04:23:34 +00002489 /* Creating LSP data based on topology info. */
2490 build_topology_lsp_data (lsp, area, i);
2491 /* Checksum is also calculated here. */
2492 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002493 /* Take care of inserting dynamic hostname into cache. */
2494 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002495
Josh Bailey3f045a02012-03-24 08:35:20 -07002496 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002497 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002498 refresh_time);
2499 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002500 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002501 }
jardineb5d44e2003-12-23 08:09:43 +00002502}
2503
2504void
2505remove_topology_lsps (struct isis_area *area)
2506{
2507 struct isis_lsp *lsp;
2508 dnode_t *dnode, *dnode_next;
2509
2510 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002511 while (dnode != NULL)
2512 {
2513 dnode_next = dict_next (area->lspdb[0], dnode);
2514 lsp = dnode_get (dnode);
2515 if (lsp->from_topology)
2516 {
2517 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2518 lsp_destroy (lsp);
2519 dict_delete (area->lspdb[0], dnode);
2520 }
2521 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002522 }
jardineb5d44e2003-12-23 08:09:43 +00002523}
2524
2525void
hassof390d2c2004-09-10 20:48:21 +00002526build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002527 int lsp_top_num)
2528{
hasso3fdb2dd2005-09-28 18:45:54 +00002529 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002530 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002531 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002532 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002533 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002534 struct tlvs tlv_data;
2535 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002536
hassof1082d12005-09-19 04:23:34 +00002537 /* Add area addresses. FIXME: Is it needed at all? */
2538 if (lsp->tlv_data.area_addrs == NULL)
2539 lsp->tlv_data.area_addrs = list_new ();
2540 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002541
hassof1082d12005-09-19 04:23:34 +00002542 if (lsp->tlv_data.nlpids == NULL)
2543 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2544 lsp->tlv_data.nlpids->count = 1;
2545 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002546
hassof1082d12005-09-19 04:23:34 +00002547 if (area->dynhostname)
2548 {
2549 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2550 sizeof (struct hostname));
2551 memset (buff, 0x00, 200);
2552 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2553 "feedme", lsp_top_num);
2554 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2555 lsp->tlv_data.hostname->namelen = strlen (buff);
2556 }
2557
2558 if (lsp->tlv_data.nlpids)
2559 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2560 if (lsp->tlv_data.hostname)
2561 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2562 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2563 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2564
2565 memset (&tlv_data, 0, sizeof (struct tlvs));
2566 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002567 {
2568 tlv_data.is_neighs = list_new ();
2569 tlv_data.is_neighs->del = free_tlv;
2570 }
hassof1082d12005-09-19 04:23:34 +00002571
2572 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002573 if (lsp_top_num == 1)
2574 {
hasso3fdb2dd2005-09-28 18:45:54 +00002575 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002576
hassof390d2c2004-09-10 20:48:21 +00002577 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002578 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002579 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2580 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002581 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2582 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2583 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002584 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002585 }
hassof390d2c2004-09-10 20:48:21 +00002586
hassof1082d12005-09-19 04:23:34 +00002587 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002588 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002589 {
hassof1082d12005-09-19 04:23:34 +00002590 int to_lsp = 0;
2591
2592 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2593 continue;
2594
2595 if (lsp_top_num == arc->from_node)
2596 to_lsp = arc->to_node;
2597 else
2598 to_lsp = arc->from_node;
2599
hasso9551eea2005-09-28 18:26:25 +00002600 if (area->oldmetric)
2601 {
2602 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002603
hasso9551eea2005-09-28 18:26:25 +00002604 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2605 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2606 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2607 is_neigh->metrics.metric_default = arc->distance;
2608 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2609 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2610 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2611 listnode_add (tlv_data.is_neighs, is_neigh);
2612 }
2613
2614 if (area->newmetric)
2615 {
hasso9551eea2005-09-28 18:26:25 +00002616 if (tlv_data.te_is_neighs == NULL)
2617 {
2618 tlv_data.te_is_neighs = list_new ();
2619 tlv_data.te_is_neighs->del = free_tlv;
2620 }
2621 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2622 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2623 ISIS_SYS_ID_LEN);
2624 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2625 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07002626 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00002627 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2628 }
hassof390d2c2004-09-10 20:48:21 +00002629 }
hassof1082d12005-09-19 04:23:34 +00002630
2631 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2632 {
2633 if (lsp->tlv_data.is_neighs == NULL)
2634 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002635 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002636 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2637 tlv_add_is_neighs);
2638 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2639 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2640 lsp0, area, IS_LEVEL_1);
2641 }
2642
hasso9551eea2005-09-28 18:26:25 +00002643 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2644 {
2645 if (lsp->tlv_data.te_is_neighs == NULL)
2646 lsp->tlv_data.te_is_neighs = list_new ();
2647 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2648 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2649 tlv_add_te_is_neighs);
2650 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2651 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2652 lsp0, area, IS_LEVEL_1);
2653 }
2654
hassof1082d12005-09-19 04:23:34 +00002655 free_tlvs (&tlv_data);
2656 return;
jardineb5d44e2003-12-23 08:09:43 +00002657}
2658#endif /* TOPOLOGY_GENERATE */