blob: 8f7fc0a02b605007388c2d9f95301b13324e9363 [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 *
hassof390d2c2004-09-10 20:48:21 +0000578lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
579 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000580{
581 struct isis_lsp *lsp;
582
hassoaac372f2005-09-01 17:52:33 +0000583 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Christian Franke390f16e2015-11-10 18:04:44 +0100584
Josh Bailey3f045a02012-03-24 08:35:20 -0700585 /* FIXME: Should be minimal mtu? */
586 lsp->pdu = stream_new (1500);
jardineb5d44e2003-12-23 08:09:43 +0000587 if (LSP_FRAGMENT (lsp_id) == 0)
588 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000589 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
590 lsp->lsp_header = (struct isis_link_state_hdr *)
591 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
592
jardineb5d44e2003-12-23 08:09:43 +0000593 /* at first we fill the FIXED HEADER */
Josh Bailey3f045a02012-03-24 08:35:20 -0700594 (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
hassof390d2c2004-09-10 20:48:21 +0000595 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
596
jardineb5d44e2003-12-23 08:09:43 +0000597 /* now for the LSP HEADER */
598 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000599 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000600 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000601 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000602 lsp->lsp_header->seq_num = htonl (seq_num);
603 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
604 lsp->lsp_header->lsp_bits = lsp_bits;
605 lsp->level = level;
606 lsp->age_out = ZERO_AGE_LIFETIME;
607
paul9985f832005-02-09 15:51:56 +0000608 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000609
hassoc89c05d2005-09-04 21:36:36 +0000610 if (isis->debugs & DEBUG_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -0700611 zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
hassoc89c05d2005-09-04 21:36:36 +0000612 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
613 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -0700614 ntohl (lsp->lsp_header->pdu_len),
hassoc89c05d2005-09-04 21:36:36 +0000615 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000616
617 return lsp;
618}
619
620void
hassof390d2c2004-09-10 20:48:21 +0000621lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000622{
623 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700624 if (lsp->lsp_header->seq_num != 0)
625 {
626 isis_spf_schedule (lsp->area, lsp->level);
627#ifdef HAVE_IPV6
628 isis_spf_schedule6 (lsp->area, lsp->level);
629#endif
630 }
jardineb5d44e2003-12-23 08:09:43 +0000631}
632
633/*
634 * Build a list of LSPs with non-zero ht bounded by start and stop ids
635 */
hassof390d2c2004-09-10 20:48:21 +0000636void
637lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
638 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000639{
640 dnode_t *first, *last, *curr;
641
642 first = dict_lower_bound (lspdb, start_id);
643 if (!first)
644 return;
hassof390d2c2004-09-10 20:48:21 +0000645
jardineb5d44e2003-12-23 08:09:43 +0000646 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000647
jardineb5d44e2003-12-23 08:09:43 +0000648 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000649
650 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000651 listnode_add (list, first->dict_data);
652
hassof390d2c2004-09-10 20:48:21 +0000653 while (curr)
654 {
655 curr = dict_next (lspdb, curr);
656 if (curr &&
657 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
658 listnode_add (list, curr->dict_data);
659 if (curr == last)
660 break;
661 }
662
jardineb5d44e2003-12-23 08:09:43 +0000663 return;
664}
665
666/*
Josh Bailey3f045a02012-03-24 08:35:20 -0700667 * Build a list of num_lsps LSPs bounded by start_id and stop_id.
jardineb5d44e2003-12-23 08:09:43 +0000668 */
hassof390d2c2004-09-10 20:48:21 +0000669void
Josh Bailey3f045a02012-03-24 08:35:20 -0700670lsp_build_list (u_char * start_id, u_char * stop_id, u_char num_lsps,
hassof390d2c2004-09-10 20:48:21 +0000671 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000672{
Josh Bailey3f045a02012-03-24 08:35:20 -0700673 u_char count;
jardineb5d44e2003-12-23 08:09:43 +0000674 dnode_t *first, *last, *curr;
675
676 first = dict_lower_bound (lspdb, start_id);
677 if (!first)
678 return;
hassof390d2c2004-09-10 20:48:21 +0000679
jardineb5d44e2003-12-23 08:09:43 +0000680 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000681
jardineb5d44e2003-12-23 08:09:43 +0000682 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000683
jardineb5d44e2003-12-23 08:09:43 +0000684 listnode_add (list, first->dict_data);
Josh Bailey3f045a02012-03-24 08:35:20 -0700685 count = 1;
jardineb5d44e2003-12-23 08:09:43 +0000686
hassof390d2c2004-09-10 20:48:21 +0000687 while (curr)
688 {
689 curr = dict_next (lspdb, curr);
690 if (curr)
Josh Bailey3f045a02012-03-24 08:35:20 -0700691 {
692 listnode_add (list, curr->dict_data);
693 count++;
694 }
695 if (count == num_lsps || curr == last)
696 break;
hassof390d2c2004-09-10 20:48:21 +0000697 }
698
jardineb5d44e2003-12-23 08:09:43 +0000699 return;
700}
701
702/*
703 * Build a list of LSPs with SSN flag set for the given circuit
704 */
705void
Josh Bailey3f045a02012-03-24 08:35:20 -0700706lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps,
707 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000708{
709 dnode_t *dnode, *next;
710 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -0700711 u_char count = 0;
hassof390d2c2004-09-10 20:48:21 +0000712
jardineb5d44e2003-12-23 08:09:43 +0000713 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000714 while (dnode != NULL)
715 {
716 next = dict_next (lspdb, dnode);
717 lsp = dnode_get (dnode);
718 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -0700719 {
720 listnode_add (list, lsp);
721 ++count;
722 }
723 if (count == num_lsps)
724 break;
hassof390d2c2004-09-10 20:48:21 +0000725 dnode = next;
726 }
727
jardineb5d44e2003-12-23 08:09:43 +0000728 return;
729}
730
hasso92365882005-01-18 13:53:33 +0000731static void
jardineb5d44e2003-12-23 08:09:43 +0000732lsp_set_time (struct isis_lsp *lsp)
733{
734 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000735
736 if (lsp->lsp_header->rem_lifetime == 0)
737 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700738 if (lsp->age_out > 0)
739 lsp->age_out--;
hassof390d2c2004-09-10 20:48:21 +0000740 return;
741 }
jardineb5d44e2003-12-23 08:09:43 +0000742
hassof390d2c2004-09-10 20:48:21 +0000743 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000744 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
745}
746
hasso92365882005-01-18 13:53:33 +0000747static void
hassof390d2c2004-09-10 20:48:21 +0000748lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000749{
750 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000751 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000752
753 if (dynhost)
754 dyn = dynhn_find_by_id (lsp_id);
755 else
756 dyn = NULL;
757
758 if (dyn)
Josh Bailey3f045a02012-03-24 08:35:20 -0700759 sprintf ((char *)id, "%.14s", dyn->name.name);
760 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
761 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000762 else
hassof390d2c2004-09-10 20:48:21 +0000763 memcpy (id, sysid_print (lsp_id), 15);
hassof390d2c2004-09-10 20:48:21 +0000764 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000765 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000766 LSP_FRAGMENT (lsp_id));
767 else
hassof7c43dc2004-09-26 16:24:14 +0000768 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000769}
770
hassof390d2c2004-09-10 20:48:21 +0000771/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000772const char *
hassof390d2c2004-09-10 20:48:21 +0000773lsp_bits2string (u_char * lsp_bits)
774{
775 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000776
hassof390d2c2004-09-10 20:48:21 +0000777 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000778 return " none";
779
780 /* we only focus on the default metric */
781 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000782 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000783
784 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000785 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000786
hassof390d2c2004-09-10 20:48:21 +0000787 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
788
jardineb5d44e2003-12-23 08:09:43 +0000789 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000790
hassof390d2c2004-09-10 20:48:21 +0000791 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000792}
793
794/* this function prints the lsp on show isis database */
Josh Bailey3f045a02012-03-24 08:35:20 -0700795void
796lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000797{
jardineb5d44e2003-12-23 08:09:43 +0000798 u_char LSPid[255];
Josh Bailey3f045a02012-03-24 08:35:20 -0700799 char age_out[8];
jardineb5d44e2003-12-23 08:09:43 +0000800
801 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700802 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
803 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len));
804 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
805 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
hassof390d2c2004-09-10 20:48:21 +0000806 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
Josh Bailey3f045a02012-03-24 08:35:20 -0700807 {
808 snprintf (age_out, 8, "(%u)", lsp->age_out);
809 age_out[7] = '\0';
810 vty_out (vty, "%7s ", age_out);
811 }
jardineb5d44e2003-12-23 08:09:43 +0000812 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700813 vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime));
814 vty_out (vty, "%s%s",
815 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000816}
817
Josh Bailey3f045a02012-03-24 08:35:20 -0700818void
819lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000820{
jardineb5d44e2003-12-23 08:09:43 +0000821 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000822 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000823 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000824 struct is_neigh *is_neigh;
825 struct te_is_neigh *te_is_neigh;
826 struct ipv4_reachability *ipv4_reach;
827 struct in_addr *ipv4_addr;
828 struct te_ipv4_reachability *te_ipv4_reach;
829#ifdef HAVE_IPV6
830 struct ipv6_reachability *ipv6_reach;
831 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000832 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000833#endif
834 u_char LSPid[255];
835 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000836 u_char ipv4_reach_prefix[20];
837 u_char ipv4_reach_mask[20];
838 u_char ipv4_address[20];
839
840 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700841 lsp_print (lsp, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000842
843 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000844 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000845 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000846 {
hasso1cd80842004-10-07 20:07:40 +0000847 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000848 isonet_print (area_addr->area_addr, area_addr->addr_len),
849 VTY_NEWLINE);
850 }
paul1eb8ef22005-04-07 07:30:20 +0000851
jardineb5d44e2003-12-23 08:09:43 +0000852 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000853 if (lsp->tlv_data.nlpids)
854 {
855 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
856 {
857 switch (lsp->tlv_data.nlpids->nlpids[i])
858 {
859 case NLPID_IP:
860 case NLPID_IPV6:
Josh Bailey3f045a02012-03-24 08:35:20 -0700861 vty_out (vty, " NLPID : 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000862 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
863 break;
864 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700865 vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000866 break;
867 }
868 }
869 }
jardineb5d44e2003-12-23 08:09:43 +0000870
871 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000872 if (lsp->tlv_data.hostname)
873 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700874 bzero (hostname, sizeof (hostname));
hassof390d2c2004-09-10 20:48:21 +0000875 memcpy (hostname, lsp->tlv_data.hostname->name,
876 lsp->tlv_data.hostname->namelen);
Josh Bailey3f045a02012-03-24 08:35:20 -0700877 vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000878 }
hassof390d2c2004-09-10 20:48:21 +0000879
Josh Bailey3f045a02012-03-24 08:35:20 -0700880 /* authentication tlv */
881 if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED)
882 {
883 if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5)
884 vty_out (vty, " Auth type : md5%s", VTY_NEWLINE);
885 else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT)
886 vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE);
887 }
hassof390d2c2004-09-10 20:48:21 +0000888
hasso1cd80842004-10-07 20:07:40 +0000889 /* TE router id */
890 if (lsp->tlv_data.router_id)
891 {
892 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
893 sizeof (ipv4_address));
Josh Bailey3f045a02012-03-24 08:35:20 -0700894 vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE);
hasso1cd80842004-10-07 20:07:40 +0000895 }
896
Josh Bailey3f045a02012-03-24 08:35:20 -0700897 if (lsp->tlv_data.ipv4_addrs)
898 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
899 {
900 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
901 vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE);
902 }
903
hasso1cd80842004-10-07 20:07:40 +0000904 /* for the IS neighbor tlv */
905 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000906 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000907 {
908 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700909 vty_out (vty, " Metric : %-8d IS : %s%s",
hasso1cd80842004-10-07 20:07:40 +0000910 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
911 }
hasso1cd80842004-10-07 20:07:40 +0000912
jardineb5d44e2003-12-23 08:09:43 +0000913 /* for the internal reachable tlv */
914 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000915 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
916 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000917 {
918 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
919 sizeof (ipv4_reach_prefix));
920 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
921 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700922 vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000923 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
924 ipv4_reach_mask, VTY_NEWLINE);
925 }
hasso2097cd82003-12-23 11:51:08 +0000926
927 /* for the external reachable tlv */
928 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000929 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
930 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000931 {
932 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
933 sizeof (ipv4_reach_prefix));
934 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
935 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700936 vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000937 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
938 ipv4_reach_mask, VTY_NEWLINE);
939 }
paul1eb8ef22005-04-07 07:30:20 +0000940
hasso2097cd82003-12-23 11:51:08 +0000941 /* IPv6 tlv */
942#ifdef HAVE_IPV6
943 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000944 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000945 {
946 memset (&in6, 0, sizeof (in6));
947 memcpy (in6.s6_addr, ipv6_reach->prefix,
948 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000949 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
David Lamparter6db3ef62015-03-03 09:07:43 +0100950 if ((ipv6_reach->control_info &
hassof390d2c2004-09-10 20:48:21 +0000951 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
Josh Bailey3f045a02012-03-24 08:35:20 -0700952 vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000953 ntohl (ipv6_reach->metric),
954 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000955 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700956 vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000957 ntohl (ipv6_reach->metric),
958 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000959 }
960#endif
paul1eb8ef22005-04-07 07:30:20 +0000961
hasso1cd80842004-10-07 20:07:40 +0000962 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000963 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000964 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000965 {
hassof390d2c2004-09-10 20:48:21 +0000966 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700967 vty_out (vty, " Metric : %-8d IS-Extended : %s%s",
968 GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000969 }
jardineb5d44e2003-12-23 08:09:43 +0000970
hasso1cd80842004-10-07 20:07:40 +0000971 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000972 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000973 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
974 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000975 {
hasso1cd80842004-10-07 20:07:40 +0000976 /* FIXME: There should be better way to output this stuff. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700977 vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000978 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000979 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
980 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000981 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000982 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700983 vty_out (vty, "%s", VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000984
hassof390d2c2004-09-10 20:48:21 +0000985 return;
jardineb5d44e2003-12-23 08:09:43 +0000986}
987
988/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000989int
990lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000991{
992
hassof390d2c2004-09-10 20:48:21 +0000993 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000994 int lsp_count = 0;
995
hassof390d2c2004-09-10 20:48:21 +0000996 if (detail == ISIS_UI_LEVEL_BRIEF)
997 {
998 while (node != NULL)
999 {
1000 /* I think it is unnecessary, so I comment it out */
1001 /* dict_contains (lspdb, node); */
1002 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001003 lsp_print (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001004 node = next;
1005 lsp_count++;
1006 }
jardineb5d44e2003-12-23 08:09:43 +00001007 }
hassof390d2c2004-09-10 20:48:21 +00001008 else if (detail == ISIS_UI_LEVEL_DETAIL)
1009 {
1010 while (node != NULL)
1011 {
1012 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001013 lsp_print_detail (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001014 node = next;
1015 lsp_count++;
1016 }
jardineb5d44e2003-12-23 08:09:43 +00001017 }
jardineb5d44e2003-12-23 08:09:43 +00001018
1019 return lsp_count;
1020}
1021
jardineb5d44e2003-12-23 08:09:43 +00001022#define FRAG_THOLD(S,T) \
Josh Bailey3f045a02012-03-24 08:35:20 -07001023 ((STREAM_SIZE(S)*T)/100)
jardineb5d44e2003-12-23 08:09:43 +00001024
1025/* stream*, area->lsp_frag_threshold, increment */
1026#define FRAG_NEEDED(S,T,I) \
1027 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1028
hassoaa4376e2005-09-26 17:39:48 +00001029/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
1030 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +00001031static void
jardineb5d44e2003-12-23 08:09:43 +00001032lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001033 int tlvsize, int frag_thold,
1034 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001035{
1036 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001037
jardineb5d44e2003-12-23 08:09:43 +00001038 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001039 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1040 {
1041 tlv_build_func (*from, lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07001042 if (listcount (*to) != 0)
1043 {
1044 struct listnode *node, *nextnode;
1045 void *elem;
1046
1047 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1048 {
1049 listnode_add (*to, elem);
1050 list_delete_node (*from, node);
1051 }
1052 }
1053 else
1054 {
1055 list_free (*to);
1056 *to = *from;
1057 *from = NULL;
1058 }
jardineb5d44e2003-12-23 08:09:43 +00001059 }
hassof390d2c2004-09-10 20:48:21 +00001060 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1061 {
1062 /* fit all we can */
1063 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1064 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
Josh Bailey3f045a02012-03-24 08:35:20 -07001065 count = count / tlvsize;
1066 if (count > (int)listcount (*from))
1067 count = listcount (*from);
hassof390d2c2004-09-10 20:48:21 +00001068 for (i = 0; i < count; i++)
1069 {
paul1eb8ef22005-04-07 07:30:20 +00001070 listnode_add (*to, listgetdata (listhead (*from)));
1071 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001072 }
1073 tlv_build_func (*to, lsp->pdu);
1074 }
paul9985f832005-02-09 15:51:56 +00001075 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001076 return;
1077}
1078
Josh Bailey3f045a02012-03-24 08:35:20 -07001079static u_int16_t
1080lsp_rem_lifetime (struct isis_area *area, int level)
1081{
1082 u_int16_t rem_lifetime;
1083
1084 /* Add jitter to configured LSP lifetime */
1085 rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1],
1086 MAX_AGE_JITTER);
1087
1088 /* No jitter if the max refresh will be less than configure gen interval */
1089 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1090 rem_lifetime = area->max_lsp_lifetime[level - 1];
1091
1092 return rem_lifetime;
1093}
1094
1095static u_int16_t
1096lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1097{
1098 struct isis_area *area = lsp->area;
1099 int level = lsp->level;
1100 u_int16_t refresh_time;
1101
1102 /* Add jitter to LSP refresh time */
1103 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1104 MAX_LSP_GEN_JITTER);
1105
1106 /* RFC 4444 : make sure the refresh time is at least less than 300
1107 * of the remaining lifetime and more than gen interval */
1108 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1109 refresh_time > (rem_lifetime - 300))
1110 refresh_time = rem_lifetime - 300;
1111
1112 assert (area->lsp_gen_interval[level - 1] < refresh_time);
1113
1114 return refresh_time;
1115}
1116
hasso92365882005-01-18 13:53:33 +00001117static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001118lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1119 int level)
jardineb5d44e2003-12-23 08:09:43 +00001120{
1121 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001122 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1123
jardineb5d44e2003-12-23 08:09:43 +00001124 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1125 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001126 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001127 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001128 if (lsp)
1129 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001130 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001131 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001132 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001133 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001134 lsp = lsp_new (frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001135 lsp_bits_generate (level, area->overload_bit,
1136 area->attached_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001137 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001138 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001139 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001140 listnode_add (lsp0->lspu.frags, lsp);
1141 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001142 return lsp;
1143}
1144
1145/*
1146 * Builds the LSP data part. This func creates a new frag whenever
1147 * area->lsp_frag_threshold is exceeded.
1148 */
hasso92365882005-01-18 13:53:33 +00001149static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001150lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001151{
1152 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001153 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001154 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001155 int level = lsp->level;
1156 struct isis_circuit *circuit;
1157 struct prefix_ipv4 *ipv4;
1158 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001159 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001160 struct isis_adjacency *nei;
1161#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001162 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001163 struct ipv6_reachability *ip6reach;
1164#endif /* HAVE_IPV6 */
1165 struct tlvs tlv_data;
1166 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001167 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001168 uint32_t expected = 0, found = 0;
1169 uint32_t metric;
1170 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1171 int retval = ISIS_OK;
1172
1173 /*
1174 * Building the zero lsp
1175 */
1176 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1177
1178 /* Reset stream endp. Stream is always there and on every LSP refresh only
1179 * TLV part of it is overwritten. So we must seek past header we will not
1180 * touch. */
1181 stream_reset (lsp->pdu);
1182 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1183
1184 /*
1185 * Add the authentication info if its present
1186 */
1187 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001188
1189 /*
1190 * First add the tlvs related to area
1191 */
hassof390d2c2004-09-10 20:48:21 +00001192
jardineb5d44e2003-12-23 08:09:43 +00001193 /* Area addresses */
1194 if (lsp->tlv_data.area_addrs == NULL)
1195 lsp->tlv_data.area_addrs = list_new ();
1196 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001197 if (listcount (lsp->tlv_data.area_addrs) > 0)
1198 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1199
jardineb5d44e2003-12-23 08:09:43 +00001200 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001201 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001202#ifdef HAVE_IPV6
1203 || area->ipv6_circuits > 0
1204#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001205 )
jardineb5d44e2003-12-23 08:09:43 +00001206 {
hassoaac372f2005-09-01 17:52:33 +00001207 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001208 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001209 if (area->ip_circuits > 0)
1210 {
1211 lsp->tlv_data.nlpids->count++;
1212 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1213 }
jardineb5d44e2003-12-23 08:09:43 +00001214#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001215 if (area->ipv6_circuits > 0)
1216 {
1217 lsp->tlv_data.nlpids->count++;
1218 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1219 NLPID_IPV6;
1220 }
jardineb5d44e2003-12-23 08:09:43 +00001221#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001222 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001223 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001224
jardineb5d44e2003-12-23 08:09:43 +00001225 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001226 if (area->dynhostname)
1227 {
1228 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1229 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001230
hassof390d2c2004-09-10 20:48:21 +00001231 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1232 strlen (unix_hostname ()));
1233 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
Josh Bailey3f045a02012-03-24 08:35:20 -07001234 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001235 }
jardineb5d44e2003-12-23 08:09:43 +00001236
hasso81ad8f62005-09-26 17:58:24 +00001237 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1238 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1239 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001240 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001241 {
hasso18a6dce2004-10-03 18:18:34 +00001242 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001243 {
1244 lsp->tlv_data.ipv4_addrs = list_new ();
1245 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1246 }
hasso18a6dce2004-10-03 18:18:34 +00001247
1248 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001249 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001250 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001251 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001252
hasso81ad8f62005-09-26 17:58:24 +00001253 /* Exactly same data is put into TE router ID TLV, but only if new style
1254 * TLV's are in use. */
1255 if (area->newmetric)
1256 {
1257 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1258 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001259 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1260 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1261 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001262 }
hasso18a6dce2004-10-03 18:18:34 +00001263 }
hassof1082d12005-09-19 04:23:34 +00001264
hasso81ad8f62005-09-26 17:58:24 +00001265 memset (&tlv_data, 0, sizeof (struct tlvs));
1266
hassof1082d12005-09-19 04:23:34 +00001267#ifdef TOPOLOGY_GENERATE
1268 /* If topology exists (and we create topology for level 1 only), create
1269 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001270 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001271 {
1272 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001273 {
1274 tlv_data.is_neighs = list_new ();
1275 tlv_data.is_neighs->del = free_tlv;
1276 }
hasso3fdb2dd2005-09-28 18:45:54 +00001277 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001278
1279 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1280 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1281 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1282 is_neigh->metrics.metric_default = 0x01;
1283 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1284 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1285 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1286 listnode_add (tlv_data.is_neighs, is_neigh);
1287 }
1288#endif /* TOPOLOGY_GENERATE */
1289
hasso18a6dce2004-10-03 18:18:34 +00001290 /*
jardineb5d44e2003-12-23 08:09:43 +00001291 * Then build lists of tlvs related to circuits
1292 */
hasso3fdb2dd2005-09-28 18:45:54 +00001293 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001294 {
hassof390d2c2004-09-10 20:48:21 +00001295 if (circuit->state != C_STATE_UP)
1296 continue;
jardineb5d44e2003-12-23 08:09:43 +00001297
hassof390d2c2004-09-10 20:48:21 +00001298 /*
1299 * Add IPv4 internal reachability of this circuit
1300 */
1301 if (circuit->ip_router && circuit->ip_addrs &&
1302 circuit->ip_addrs->count > 0)
1303 {
hassoaa4376e2005-09-26 17:39:48 +00001304 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001305 {
hassoaa4376e2005-09-26 17:39:48 +00001306 if (tlv_data.ipv4_int_reachs == NULL)
1307 {
1308 tlv_data.ipv4_int_reachs = list_new ();
1309 tlv_data.ipv4_int_reachs->del = free_tlv;
1310 }
hasso3fdb2dd2005-09-28 18:45:54 +00001311 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001312 {
1313 ipreach =
1314 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1315 ipreach->metrics = circuit->metrics[level - 1];
1316 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1317 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1318 (ipv4->prefix.s_addr));
1319 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1320 }
hassof390d2c2004-09-10 20:48:21 +00001321 }
hassoaa4376e2005-09-26 17:39:48 +00001322 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001323 {
hassoaa4376e2005-09-26 17:39:48 +00001324 if (tlv_data.te_ipv4_reachs == NULL)
1325 {
1326 tlv_data.te_ipv4_reachs = list_new ();
1327 tlv_data.te_ipv4_reachs->del = free_tlv;
1328 }
hasso3fdb2dd2005-09-28 18:45:54 +00001329 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001330 {
1331 /* FIXME All this assumes that we have no sub TLVs. */
1332 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1333 sizeof (struct te_ipv4_reachability) +
1334 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001335
1336 if (area->oldmetric)
1337 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1338 else
1339 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1340
hassoaa4376e2005-09-26 17:39:48 +00001341 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1342 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1343 (ipv4->prefixlen + 7)/8);
1344 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1345 }
hassof390d2c2004-09-10 20:48:21 +00001346 }
hassof390d2c2004-09-10 20:48:21 +00001347 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001348
jardineb5d44e2003-12-23 08:09:43 +00001349#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001350 /*
1351 * Add IPv6 reachability of this circuit
1352 */
1353 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1354 circuit->ipv6_non_link->count > 0)
1355 {
1356
1357 if (tlv_data.ipv6_reachs == NULL)
1358 {
1359 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001360 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001361 }
hasso3fdb2dd2005-09-28 18:45:54 +00001362 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001363 {
hassof390d2c2004-09-10 20:48:21 +00001364 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001365 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001366
1367 if (area->oldmetric)
1368 ip6reach->metric =
1369 htonl (circuit->metrics[level - 1].metric_default);
1370 else
1371 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1372
hassof390d2c2004-09-10 20:48:21 +00001373 ip6reach->control_info = 0;
1374 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001375 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1376 apply_mask_ipv6 (ip6prefix);
1377 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1378 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001379 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1380 }
1381 }
1382#endif /* HAVE_IPV6 */
1383
1384 switch (circuit->circ_type)
1385 {
1386 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001387 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001388 {
hassoaa4376e2005-09-26 17:39:48 +00001389 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001390 {
hassoaa4376e2005-09-26 17:39:48 +00001391 if (tlv_data.is_neighs == NULL)
1392 {
1393 tlv_data.is_neighs = list_new ();
1394 tlv_data.is_neighs->del = free_tlv;
1395 }
1396 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001397 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001398 memcpy (is_neigh->neigh_id,
1399 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1400 else
1401 memcpy (is_neigh->neigh_id,
1402 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1403 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001404 if (!memcmp (is_neigh->neigh_id, zero_id,
1405 ISIS_SYS_ID_LEN + 1))
1406 XFREE (MTYPE_ISIS_TLV, is_neigh);
1407 else
1408 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001409 }
hassoaa4376e2005-09-26 17:39:48 +00001410 if (area->newmetric)
1411 {
hassoaa4376e2005-09-26 17:39:48 +00001412 if (tlv_data.te_is_neighs == NULL)
1413 {
1414 tlv_data.te_is_neighs = list_new ();
1415 tlv_data.te_is_neighs->del = free_tlv;
1416 }
1417 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1418 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001419 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001420 memcpy (te_is_neigh->neigh_id,
1421 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1422 else
1423 memcpy (te_is_neigh->neigh_id,
1424 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001425 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001426 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001427 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001428 metric = circuit->te_metric[level - 1];
1429 SET_TE_METRIC(te_is_neigh, metric);
1430 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1431 ISIS_SYS_ID_LEN + 1))
1432 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1433 else
1434 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
hassoaa4376e2005-09-26 17:39:48 +00001435 }
hassof390d2c2004-09-10 20:48:21 +00001436 }
1437 break;
1438 case CIRCUIT_T_P2P:
1439 nei = circuit->u.p2p.neighbor;
1440 if (nei && (level & nei->circuit_t))
1441 {
hassoaa4376e2005-09-26 17:39:48 +00001442 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001443 {
hassoaa4376e2005-09-26 17:39:48 +00001444 if (tlv_data.is_neighs == NULL)
1445 {
1446 tlv_data.is_neighs = list_new ();
1447 tlv_data.is_neighs->del = free_tlv;
1448 }
1449 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1450 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1451 is_neigh->metrics = circuit->metrics[level - 1];
1452 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001453 }
hassoaa4376e2005-09-26 17:39:48 +00001454 if (area->newmetric)
1455 {
1456 uint32_t metric;
1457
1458 if (tlv_data.te_is_neighs == NULL)
1459 {
1460 tlv_data.te_is_neighs = list_new ();
1461 tlv_data.te_is_neighs->del = free_tlv;
1462 }
1463 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1464 sizeof (struct te_is_neigh));
1465 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001466 metric = circuit->te_metric[level - 1];
1467 SET_TE_METRIC(te_is_neigh, metric);
hassoaa4376e2005-09-26 17:39:48 +00001468 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1469 }
hassof390d2c2004-09-10 20:48:21 +00001470 }
1471 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001472 case CIRCUIT_T_LOOPBACK:
1473 break;
hassof390d2c2004-09-10 20:48:21 +00001474 default:
1475 zlog_warn ("lsp_area_create: unknown circuit type");
1476 }
1477 }
1478
1479 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1480 {
1481 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1482 lsp->tlv_data.ipv4_int_reachs = list_new ();
1483 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1484 &lsp->tlv_data.ipv4_int_reachs,
1485 IPV4_REACH_LEN, area->lsp_frag_threshold,
1486 tlv_add_ipv4_reachs);
1487 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1488 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1489 lsp0, area, level);
1490 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001491
hassoaa4376e2005-09-26 17:39:48 +00001492 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1493 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1494 * TLVs (sub TLVs!). */
1495 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1496 {
1497 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1498 lsp->tlv_data.te_ipv4_reachs = list_new ();
1499 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1500 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001501 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1502 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001503 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1504 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1505 lsp0, area, level);
1506 }
hassof390d2c2004-09-10 20:48:21 +00001507
1508#ifdef HAVE_IPV6
1509 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1510 {
1511 if (lsp->tlv_data.ipv6_reachs == NULL)
1512 lsp->tlv_data.ipv6_reachs = list_new ();
1513 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1514 &lsp->tlv_data.ipv6_reachs,
1515 IPV6_REACH_LEN, area->lsp_frag_threshold,
1516 tlv_add_ipv6_reachs);
1517 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1518 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1519 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001520 }
1521#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001522
1523 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1524 {
1525 if (lsp->tlv_data.is_neighs == NULL)
1526 lsp->tlv_data.is_neighs = list_new ();
1527 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1528 &lsp->tlv_data.is_neighs,
1529 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1530 tlv_add_is_neighs);
1531 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1532 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1533 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001534 }
jardineb5d44e2003-12-23 08:09:43 +00001535
hassoaa4376e2005-09-26 17:39:48 +00001536 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1537 {
1538 if (lsp->tlv_data.te_is_neighs == NULL)
1539 lsp->tlv_data.te_is_neighs = list_new ();
1540 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1541 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1542 tlv_add_te_is_neighs);
1543 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1544 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1545 lsp0, area, level);
1546 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001547 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001548
1549 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001550
1551 /* Validate the LSP */
1552 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1553 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1554 stream_get_endp (lsp->pdu) -
1555 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1556 &expected, &found, &tlv_data, NULL);
1557 assert (retval == ISIS_OK);
1558
jardineb5d44e2003-12-23 08:09:43 +00001559 return;
1560}
jardineb5d44e2003-12-23 08:09:43 +00001561
1562/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001563 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001564 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001565int
1566lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001567{
jardineb5d44e2003-12-23 08:09:43 +00001568 struct isis_lsp *oldlsp, *newlsp;
1569 u_int32_t seq_num = 0;
1570 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001571 u_int16_t rem_lifetime, refresh_time;
1572
1573 if ((area == NULL) || (area->is_type & level) != level)
1574 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001575
1576 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1577 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1578
1579 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001580 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1581 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001582 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001583 /* FIXME: we should actually initiate a purge */
1584 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1585 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1586 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001587 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001588 rem_lifetime = lsp_rem_lifetime (area, level);
1589 newlsp = lsp_new (lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001590 area->is_type | area->overload_bit | area->attached_bit,
1591 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001592 newlsp->area = area;
1593 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001594
Josh Bailey3f045a02012-03-24 08:35:20 -07001595 lsp_insert (newlsp, area->lspdb[level - 1]);
1596 /* build_lsp_data (newlsp, area); */
1597 lsp_build (newlsp, area);
1598 /* time to calculate our checksum */
1599 lsp_seqnum_update (newlsp);
1600 lsp_set_all_srmflags (newlsp);
1601
1602 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
1603 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
1604 if (level == IS_LEVEL_1)
1605 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1606 lsp_l1_refresh, area, refresh_time);
1607 else if (level == IS_LEVEL_2)
1608 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1609 lsp_l2_refresh, area, refresh_time);
1610
1611 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001612 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001613 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1614 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1615 area->area_tag, level,
1616 rawlspid_print (newlsp->lsp_header->lsp_id),
1617 ntohl (newlsp->lsp_header->pdu_len),
1618 ntohl (newlsp->lsp_header->seq_num),
1619 ntohs (newlsp->lsp_header->checksum),
1620 ntohs (newlsp->lsp_header->rem_lifetime),
1621 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001622 }
jardineb5d44e2003-12-23 08:09:43 +00001623
1624 return ISIS_OK;
1625}
1626
1627/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001628 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001629 */
hasso92365882005-01-18 13:53:33 +00001630static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001631lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001632{
David Lampartere8aca322012-11-27 01:10:30 +00001633 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001634 struct isis_lsp *lsp, *frag;
1635 struct listnode *node;
1636 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001637 u_int16_t rem_lifetime, refresh_time;
1638
1639 if ((area == NULL) || (area->is_type & level) != level)
1640 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001641
David Lampartere8aca322012-11-27 01:10:30 +00001642 lspdb = area->lspdb[level - 1];
1643
jardineb5d44e2003-12-23 08:09:43 +00001644 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1645 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001646
jardineb5d44e2003-12-23 08:09:43 +00001647 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001648
hassof390d2c2004-09-10 20:48:21 +00001649 if (!lsp)
1650 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001651 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1652 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001653 return ISIS_ERROR;
1654 }
1655
1656 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001657 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001658 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1659 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001660 rem_lifetime = lsp_rem_lifetime (area, level);
1661 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001662 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001663
Josh Bailey3f045a02012-03-24 08:35:20 -07001664 lsp->last_generated = time (NULL);
1665 lsp_set_all_srmflags (lsp);
1666 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1667 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001668 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001669 area->overload_bit,
1670 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001671 /* Set the lifetime values of all the fragments to the same value,
1672 * so that no fragment expires before the lsp is refreshed.
1673 */
1674 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1675 lsp_set_all_srmflags (frag);
1676 }
1677
1678 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1679 if (level == IS_LEVEL_1)
1680 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1681 lsp_l1_refresh, area, refresh_time);
1682 else if (level == IS_LEVEL_2)
1683 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1684 lsp_l2_refresh, area, refresh_time);
1685
hassof390d2c2004-09-10 20:48:21 +00001686 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1687 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001688 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
1689 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1690 area->area_tag, level,
1691 rawlspid_print (lsp->lsp_header->lsp_id),
1692 ntohl (lsp->lsp_header->pdu_len),
1693 ntohl (lsp->lsp_header->seq_num),
1694 ntohs (lsp->lsp_header->checksum),
1695 ntohs (lsp->lsp_header->rem_lifetime),
1696 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001697 }
jardineb5d44e2003-12-23 08:09:43 +00001698
jardineb5d44e2003-12-23 08:09:43 +00001699 return ISIS_OK;
1700}
1701
jardineb5d44e2003-12-23 08:09:43 +00001702/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001703 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00001704 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001705static int
1706lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001707{
1708 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001709
1710 area = THREAD_ARG (thread);
1711 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001712
jardineb5d44e2003-12-23 08:09:43 +00001713 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001714 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00001715
Josh Bailey3f045a02012-03-24 08:35:20 -07001716 if ((area->is_type & IS_LEVEL_1) == 0)
1717 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001718
Josh Bailey3f045a02012-03-24 08:35:20 -07001719 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00001720}
1721
Josh Bailey3f045a02012-03-24 08:35:20 -07001722static int
1723lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001724{
1725 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001726
1727 area = THREAD_ARG (thread);
1728 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001729
jardineb5d44e2003-12-23 08:09:43 +00001730 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001731 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001732
Josh Bailey3f045a02012-03-24 08:35:20 -07001733 if ((area->is_type & IS_LEVEL_2) == 0)
1734 return ISIS_ERROR;
1735
1736 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00001737}
1738
hassof390d2c2004-09-10 20:48:21 +00001739int
Josh Bailey3f045a02012-03-24 08:35:20 -07001740lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00001741{
1742 struct isis_lsp *lsp;
1743 u_char id[ISIS_SYS_ID_LEN + 2];
1744 time_t now, diff;
Josh Bailey3f045a02012-03-24 08:35:20 -07001745 struct listnode *cnode;
1746 struct isis_circuit *circuit;
1747 int lvl;
1748
1749 if (area == NULL)
1750 return ISIS_ERROR;
1751
hassof390d2c2004-09-10 20:48:21 +00001752 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1753 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001754 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001755
1756 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00001757 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001758 if (!((level & lvl) && (area->is_type & lvl)))
1759 continue;
1760
1761 if (area->lsp_regenerate_pending[lvl - 1])
1762 continue;
1763
1764 lsp = lsp_search (id, area->lspdb[lvl - 1]);
1765 if (!lsp)
1766 continue;
1767
hassof390d2c2004-09-10 20:48:21 +00001768 /*
1769 * Throttle avoidance
1770 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001771 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00001772 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07001773 if (diff < area->lsp_gen_interval[lvl - 1])
1774 {
1775 area->lsp_regenerate_pending[lvl - 1] = 1;
1776 if (lvl == IS_LEVEL_1)
1777 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1778 lsp_l1_refresh, area,
1779 area->lsp_gen_interval[lvl - 1] - diff);
1780 else if (lvl == IS_LEVEL_2)
1781 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1782 lsp_l2_refresh, area,
1783 area->lsp_gen_interval[lvl - 1] - diff);
1784 }
hassof390d2c2004-09-10 20:48:21 +00001785 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001786 {
Michael Zinggbe62b172012-10-26 11:18:19 +02001787 /*
1788 * lsps are not regenerated if lsp_regenerate function is called
1789 * directly. However if the lsp_regenerate call is queued for
1790 * later execution it works.
1791 */
1792 area->lsp_regenerate_pending[lvl - 1] = 1;
1793 if (lvl == IS_LEVEL_1)
1794 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1795 lsp_l1_refresh, area, 0);
1796 else if (lvl == IS_LEVEL_2)
1797 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1798 lsp_l2_refresh, area, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07001799 }
hassof390d2c2004-09-10 20:48:21 +00001800 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001801
1802 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00001803 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001804 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
1805 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00001806 }
1807
1808 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001809}
1810
1811/*
1812 * Funcs for pseudonode LSPs
1813 */
1814
1815/*
1816 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1817 */
hasso92365882005-01-18 13:53:33 +00001818static void
hassof390d2c2004-09-10 20:48:21 +00001819lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1820 int level)
jardineb5d44e2003-12-23 08:09:43 +00001821{
1822 struct isis_adjacency *adj;
1823 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001824 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001825 struct es_neigh *es_neigh;
1826 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001827 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +00001828
jardineb5d44e2003-12-23 08:09:43 +00001829 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07001830 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001831 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
1832 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00001833
1834 /*
1835 * add self to IS neighbours
1836 */
hassoaa4376e2005-09-26 17:39:48 +00001837 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001838 {
hassoaa4376e2005-09-26 17:39:48 +00001839 if (lsp->tlv_data.is_neighs == NULL)
1840 {
1841 lsp->tlv_data.is_neighs = list_new ();
1842 lsp->tlv_data.is_neighs->del = free_tlv;
1843 }
1844 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001845
hassoaa4376e2005-09-26 17:39:48 +00001846 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1847 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1848 }
1849 if (circuit->area->newmetric)
1850 {
1851 if (lsp->tlv_data.te_is_neighs == NULL)
1852 {
1853 lsp->tlv_data.te_is_neighs = list_new ();
1854 lsp->tlv_data.te_is_neighs->del = free_tlv;
1855 }
1856 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1857
1858 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1859 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1860 }
hassof390d2c2004-09-10 20:48:21 +00001861
1862 adj_list = list_new ();
1863 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1864
hasso3fdb2dd2005-09-28 18:45:54 +00001865 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001866 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001867 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00001868 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001869 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1870 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00001871 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001872 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00001873 {
1874 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00001875 if (circuit->area->oldmetric)
1876 {
1877 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001878
hassoaa4376e2005-09-26 17:39:48 +00001879 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1880 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1881 }
1882 if (circuit->area->newmetric)
1883 {
1884 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1885 sizeof (struct te_is_neigh));
1886 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1887 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1888 }
hassof390d2c2004-09-10 20:48:21 +00001889 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001890 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00001891 {
1892 /* an ES neigbour add it, if we are building level 1 LSP */
1893 /* FIXME: the tlv-format is hard to use here */
1894 if (lsp->tlv_data.es_neighs == NULL)
1895 {
1896 lsp->tlv_data.es_neighs = list_new ();
1897 lsp->tlv_data.es_neighs->del = free_tlv;
1898 }
paul15935e92005-05-03 09:27:23 +00001899 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1900
hassof390d2c2004-09-10 20:48:21 +00001901 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001902 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001903 }
1904 }
jardineb5d44e2003-12-23 08:09:43 +00001905 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001906 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00001907
hassoc0fb2a52005-09-03 16:29:40 +00001908 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001909 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001910 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1911
jardineb5d44e2003-12-23 08:09:43 +00001912 /*
1913 * Add the authentication info if it's present
1914 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001915 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001916
1917 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1918 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1919
hassoaa4376e2005-09-26 17:39:48 +00001920 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
1921 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
1922
jardineb5d44e2003-12-23 08:09:43 +00001923 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1924 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1925
paul9985f832005-02-09 15:51:56 +00001926 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001927
Josh Bailey3f045a02012-03-24 08:35:20 -07001928 /* Recompute authentication and checksum information */
1929 lsp_auth_update (lsp);
1930 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
1931 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00001932
1933 return;
1934}
1935
Josh Bailey3f045a02012-03-24 08:35:20 -07001936int
1937lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00001938{
1939 dict_t *lspdb = circuit->area->lspdb[level - 1];
1940 struct isis_lsp *lsp;
1941 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001942 u_int16_t rem_lifetime, refresh_time;
1943
1944 if ((circuit->is_type & level) != level ||
1945 (circuit->state != C_STATE_UP) ||
1946 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
1947 (circuit->u.bc.is_dr[level - 1] == 0))
1948 return ISIS_ERROR;
1949
1950 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1951 LSP_FRAGMENT (lsp_id) = 0;
1952 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1953
1954 /*
1955 * If for some reason have a pseudo LSP in the db already -> regenerate
1956 */
1957 if (lsp_search (lsp_id, lspdb))
1958 return lsp_regenerate_schedule_pseudo (circuit, level);
1959
1960 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
1961 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001962 lsp = lsp_new (lsp_id, rem_lifetime, 1,
1963 circuit->area->is_type | circuit->area->attached_bit,
1964 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001965 lsp->area = circuit->area;
1966
1967 lsp_build_pseudo (lsp, circuit, level);
1968
1969 lsp->own_lsp = 1;
1970 lsp_insert (lsp, lspdb);
1971 lsp_set_all_srmflags (lsp);
1972
1973 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1974 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1975 circuit->lsp_regenerate_pending[level - 1] = 0;
1976 if (level == IS_LEVEL_1)
1977 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1978 lsp_l1_refresh_pseudo, circuit, refresh_time);
1979 else if (level == IS_LEVEL_2)
1980 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1981 lsp_l2_refresh_pseudo, circuit, refresh_time);
1982
1983 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1984 {
1985 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
1986 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
1987 circuit->area->area_tag, level,
1988 rawlspid_print (lsp->lsp_header->lsp_id),
1989 ntohl (lsp->lsp_header->pdu_len),
1990 ntohl (lsp->lsp_header->seq_num),
1991 ntohs (lsp->lsp_header->checksum),
1992 ntohs (lsp->lsp_header->rem_lifetime),
1993 refresh_time);
1994 }
1995
1996 return ISIS_OK;
1997}
1998
1999static int
2000lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2001{
2002 dict_t *lspdb = circuit->area->lspdb[level - 1];
2003 struct isis_lsp *lsp;
2004 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2005 u_int16_t rem_lifetime, refresh_time;
2006
2007 if ((circuit->is_type & level) != level ||
2008 (circuit->state != C_STATE_UP) ||
2009 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2010 (circuit->u.bc.is_dr[level - 1] == 0))
2011 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002012
jardineb5d44e2003-12-23 08:09:43 +00002013 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002014 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2015 LSP_FRAGMENT (lsp_id) = 0;
2016
jardineb5d44e2003-12-23 08:09:43 +00002017 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002018
2019 if (!lsp)
2020 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002021 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2022 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002023 return ISIS_ERROR;
2024 }
2025 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002026
2027 lsp_build_pseudo (lsp, circuit, level);
2028
Josh Bailey3f045a02012-03-24 08:35:20 -07002029 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002030 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2031 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002032 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2033 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002034 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002035 lsp->last_generated = time (NULL);
2036 lsp_set_all_srmflags (lsp);
2037
2038 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2039 if (level == IS_LEVEL_1)
2040 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2041 lsp_l1_refresh_pseudo, circuit, refresh_time);
2042 else if (level == IS_LEVEL_2)
2043 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2044 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002045
2046 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2047 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002048 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2049 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2050 circuit->area->area_tag, level,
2051 rawlspid_print (lsp->lsp_header->lsp_id),
2052 ntohl (lsp->lsp_header->pdu_len),
2053 ntohl (lsp->lsp_header->seq_num),
2054 ntohs (lsp->lsp_header->checksum),
2055 ntohs (lsp->lsp_header->rem_lifetime),
2056 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002057 }
jardineb5d44e2003-12-23 08:09:43 +00002058
jardineb5d44e2003-12-23 08:09:43 +00002059 return ISIS_OK;
2060}
2061
Josh Bailey3f045a02012-03-24 08:35:20 -07002062/*
2063 * Something has changed or periodic refresh -> regenerate pseudo LSP
2064 */
2065static int
jardineb5d44e2003-12-23 08:09:43 +00002066lsp_l1_refresh_pseudo (struct thread *thread)
2067{
2068 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002069 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002070
hassof390d2c2004-09-10 20:48:21 +00002071 circuit = THREAD_ARG (thread);
2072
hasso13c48f72004-09-10 21:19:13 +00002073 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002074 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002075
Josh Bailey3f045a02012-03-24 08:35:20 -07002076 if ((circuit->u.bc.is_dr[0] == 0) ||
2077 (circuit->is_type & IS_LEVEL_1) == 0)
2078 {
2079 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2080 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2081 LSP_FRAGMENT (id) = 0;
2082 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2083 return ISIS_ERROR;
2084 }
hassof390d2c2004-09-10 20:48:21 +00002085
Josh Bailey3f045a02012-03-24 08:35:20 -07002086 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002087}
2088
Josh Bailey3f045a02012-03-24 08:35:20 -07002089static int
jardineb5d44e2003-12-23 08:09:43 +00002090lsp_l2_refresh_pseudo (struct thread *thread)
2091{
2092 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002093 u_char id[ISIS_SYS_ID_LEN + 2];
2094
hassof390d2c2004-09-10 20:48:21 +00002095 circuit = THREAD_ARG (thread);
2096
hasso13c48f72004-09-10 21:19:13 +00002097 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002098 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002099
Josh Bailey3f045a02012-03-24 08:35:20 -07002100 if ((circuit->u.bc.is_dr[1] == 0) ||
2101 (circuit->is_type & IS_LEVEL_2) == 0)
2102 {
2103 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2104 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2105 LSP_FRAGMENT (id) = 0;
2106 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2107 return ISIS_ERROR;
2108 }
jardineb5d44e2003-12-23 08:09:43 +00002109
Josh Bailey3f045a02012-03-24 08:35:20 -07002110 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002111}
2112
hassof390d2c2004-09-10 20:48:21 +00002113int
Josh Bailey3f045a02012-03-24 08:35:20 -07002114lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002115{
2116 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002117 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2118 time_t now, diff;
2119 int lvl;
jardineb5d44e2003-12-23 08:09:43 +00002120
Josh Bailey3f045a02012-03-24 08:35:20 -07002121 if (circuit == NULL ||
2122 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2123 circuit->state != C_STATE_UP)
2124 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002125
Josh Bailey3f045a02012-03-24 08:35:20 -07002126 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2127 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2128 LSP_FRAGMENT (lsp_id) = 0;
2129 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002130
Josh Bailey3f045a02012-03-24 08:35:20 -07002131 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2132 {
2133 if (!((level & lvl) && (circuit->is_type & lvl)))
2134 continue;
jardineb5d44e2003-12-23 08:09:43 +00002135
Josh Bailey3f045a02012-03-24 08:35:20 -07002136 if (circuit->u.bc.is_dr[lvl - 1] == 0 ||
2137 circuit->lsp_regenerate_pending[lvl - 1])
2138 continue;
hassof390d2c2004-09-10 20:48:21 +00002139
Josh Bailey3f045a02012-03-24 08:35:20 -07002140 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2141 if (!lsp)
2142 continue;
jardineb5d44e2003-12-23 08:09:43 +00002143
Josh Bailey3f045a02012-03-24 08:35:20 -07002144 /*
2145 * Throttle avoidance
2146 */
2147 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2148 diff = now - lsp->last_generated;
2149 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2150 {
2151 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2152 if (lvl == IS_LEVEL_1)
2153 THREAD_TIMER_ON (master,
2154 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2155 lsp_l1_refresh_pseudo, circuit,
2156 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2157 else if (lvl == IS_LEVEL_2)
2158 THREAD_TIMER_ON (master,
2159 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2160 lsp_l2_refresh_pseudo, circuit,
2161 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2162 }
2163 else
2164 {
2165 lsp_regenerate_pseudo (circuit, lvl);
2166 }
2167 }
jardineb5d44e2003-12-23 08:09:43 +00002168
Josh Bailey3f045a02012-03-24 08:35:20 -07002169 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002170}
2171
jardineb5d44e2003-12-23 08:09:43 +00002172/*
2173 * Walk through LSPs for an area
2174 * - set remaining lifetime
2175 * - set LSPs with SRMflag set for sending
2176 */
hassof390d2c2004-09-10 20:48:21 +00002177int
jardineb5d44e2003-12-23 08:09:43 +00002178lsp_tick (struct thread *thread)
2179{
2180 struct isis_area *area;
2181 struct isis_circuit *circuit;
2182 struct isis_lsp *lsp;
2183 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002184 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002185 dnode_t *dnode, *dnode_next;
2186 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002187 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002188
2189 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002190
jardineb5d44e2003-12-23 08:09:43 +00002191 area = THREAD_ARG (thread);
2192 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002193 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002194 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002195
2196 /*
2197 * Build a list of LSPs with (any) SRMflag set
2198 * and removed the ones that have aged out
2199 */
hassof390d2c2004-09-10 20:48:21 +00002200 for (level = 0; level < ISIS_LEVELS; level++)
2201 {
2202 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002203 {
2204 for (dnode = dict_first (area->lspdb[level]);
2205 dnode != NULL; dnode = dnode_next)
2206 {
2207 dnode_next = dict_next (area->lspdb[level], dnode);
2208 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002209
Josh Bailey3f045a02012-03-24 08:35:20 -07002210 /*
2211 * The lsp rem_lifetime is kept at 0 for MaxAge or
2212 * ZeroAgeLifetime depending on explicit purge or
2213 * natural age out. So schedule spf only once when
2214 * the first time rem_lifetime becomes 0.
2215 */
2216 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2217 lsp_set_time (lsp);
2218
2219 /*
2220 * Schedule may run spf which should be done only after
2221 * the lsp rem_lifetime becomes 0 for the first time.
2222 * ISO 10589 - 7.3.16.4 first paragraph.
2223 */
2224 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2225 {
2226 /* 7.3.16.4 a) set SRM flags on all */
2227 lsp_set_all_srmflags (lsp);
2228 /* 7.3.16.4 b) retain only the header FIXME */
2229 /* 7.3.16.4 c) record the time to purge FIXME */
2230 /* run/schedule spf */
2231 /* isis_spf_schedule is called inside lsp_destroy() below;
2232 * so it is not needed here. */
2233 /* isis_spf_schedule (lsp->area, lsp->level); */
2234 }
2235
2236 if (lsp->age_out == 0)
2237 {
2238 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2239 area->area_tag,
2240 lsp->level,
2241 rawlspid_print (lsp->lsp_header->lsp_id),
2242 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002243#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002244 if (lsp->from_topology)
2245 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002246#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002247 lsp_destroy (lsp);
2248 lsp = NULL;
2249 dict_delete_free (area->lspdb[level], dnode);
2250 }
2251 else if (flags_any_set (lsp->SRMflags))
2252 listnode_add (lsp_list, lsp);
2253 }
jardineb5d44e2003-12-23 08:09:43 +00002254
Josh Bailey3f045a02012-03-24 08:35:20 -07002255 /*
2256 * Send LSPs on circuits indicated by the SRMflags
2257 */
2258 if (listcount (lsp_list) > 0)
2259 {
paul1eb8ef22005-04-07 07:30:20 +00002260 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002261 {
2262 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2263 if (circuit->lsp_queue == NULL ||
2264 diff < MIN_LSP_TRANS_INTERVAL)
2265 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002266 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002267 {
2268 if (circuit->upadjcount[lsp->level - 1] &&
2269 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2270 {
2271 /* Add the lsp only if it is not already in lsp
2272 * queue */
2273 if (! listnode_lookup (circuit->lsp_queue, lsp))
2274 {
2275 listnode_add (circuit->lsp_queue, lsp);
2276 thread_add_event (master, send_lsp, circuit, 0);
2277 }
2278 }
2279 }
2280 }
2281 list_delete_all_node (lsp_list);
2282 }
2283 }
jardineb5d44e2003-12-23 08:09:43 +00002284 }
jardineb5d44e2003-12-23 08:09:43 +00002285
2286 list_delete (lsp_list);
2287
2288 return ISIS_OK;
2289}
2290
jardineb5d44e2003-12-23 08:09:43 +00002291void
Josh Bailey3f045a02012-03-24 08:35:20 -07002292lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002293{
2294 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002295 u_int16_t seq_num;
2296 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002297
jardineb5d44e2003-12-23 08:09:43 +00002298 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002299 if (!lsp)
2300 return;
hassof390d2c2004-09-10 20:48:21 +00002301
Josh Bailey3f045a02012-03-24 08:35:20 -07002302 /* store old values */
2303 seq_num = lsp->lsp_header->seq_num;
2304 lsp_bits = lsp->lsp_header->lsp_bits;
2305
2306 /* reset stream */
2307 lsp_clear_data (lsp);
2308 stream_reset (lsp->pdu);
2309
2310 /* update header */
2311 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2312 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2313 lsp->lsp_header->checksum = 0;
2314 lsp->lsp_header->seq_num = seq_num;
2315 lsp->lsp_header->rem_lifetime = 0;
2316 lsp->lsp_header->lsp_bits = lsp_bits;
2317 lsp->level = level;
2318 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2319 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2320
2321 /*
2322 * Add and update the authentication info if its present
2323 */
2324 lsp_auth_add (lsp);
2325 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2326 lsp_auth_update (lsp);
2327 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2328 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2329
2330 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002331
jardineb5d44e2003-12-23 08:09:43 +00002332 return;
2333}
2334
2335/*
2336 * Purge own LSP that is received and we don't have.
2337 * -> Do as in 7.3.16.4
2338 */
2339void
hassof390d2c2004-09-10 20:48:21 +00002340lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2341 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002342{
2343 struct isis_lsp *lsp;
2344
2345 /*
2346 * We need to create the LSP to be purged
2347 */
hassoaac372f2005-09-01 17:52:33 +00002348 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002349 lsp->area = area;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002350 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ?
2351 IS_LEVEL_1 : IS_LEVEL_2;
Josh Bailey3f045a02012-03-24 08:35:20 -07002352 /* FIXME: Should be minimal mtu? */
2353 lsp->pdu = stream_new (1500);
hassof390d2c2004-09-10 20:48:21 +00002354 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002355 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002356 : L2_LINK_STATE);
2357 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2358 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002359 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002360 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002361
jardineb5d44e2003-12-23 08:09:43 +00002362 /*
jardineb5d44e2003-12-23 08:09:43 +00002363 * Set the remaining lifetime to 0
2364 */
2365 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002366
2367 /*
2368 * Add and update the authentication info if its present
2369 */
2370 lsp_auth_add (lsp);
2371 lsp_auth_update (lsp);
2372
2373 /*
2374 * Update the PDU length to header plus any authentication TLV.
2375 */
2376 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2377
jardineb5d44e2003-12-23 08:09:43 +00002378 /*
2379 * Put the lsp into LSPdb
2380 */
hassof390d2c2004-09-10 20:48:21 +00002381 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002382
2383 /*
2384 * Send in to whole area
2385 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002386 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002387
jardineb5d44e2003-12-23 08:09:43 +00002388 return;
2389}
2390
Josh Bailey3f045a02012-03-24 08:35:20 -07002391void lsp_set_all_srmflags (struct isis_lsp *lsp)
2392{
2393 struct listnode *node;
2394 struct isis_circuit *circuit;
2395
2396 assert (lsp);
2397
2398 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2399
2400 if (lsp->area)
2401 {
2402 struct list *circuit_list = lsp->area->circuit_list;
2403 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2404 {
2405 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2406 }
2407 }
2408}
2409
jardineb5d44e2003-12-23 08:09:43 +00002410#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002411static int
jardineb5d44e2003-12-23 08:09:43 +00002412top_lsp_refresh (struct thread *thread)
2413{
hassof390d2c2004-09-10 20:48:21 +00002414 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002415 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002416
2417 lsp = THREAD_ARG (thread);
2418 assert (lsp);
2419
2420 lsp->t_lsp_top_ref = NULL;
2421
hassof1082d12005-09-19 04:23:34 +00002422 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002423
Josh Bailey3f045a02012-03-24 08:35:20 -07002424 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002425 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2426 {
hasso529d65b2004-12-24 00:14:50 +00002427 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2428 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002429 }
hassod3d74742005-09-28 18:30:51 +00002430 /* Refresh dynamic hostname in the cache. */
2431 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2432 IS_LEVEL_1);
2433
David Lampartera47c5832012-06-21 09:55:38 +02002434 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002435 lsp->area->overload_bit,
2436 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002437 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2438 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002439
David Lamparterf50ee932015-03-04 07:13:38 +01002440 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002441 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002442 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002443
2444 return ISIS_OK;
2445}
2446
2447void
2448generate_topology_lsps (struct isis_area *area)
2449{
2450 struct listnode *node;
2451 int i, max = 0;
2452 struct arc *arc;
2453 u_char lspid[ISIS_SYS_ID_LEN + 2];
2454 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002455 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002456
2457 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002458 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002459 {
2460 if (arc->from_node > max)
2461 max = arc->from_node;
2462 if (arc->to_node > max)
2463 max = arc->to_node;
2464 }
jardineb5d44e2003-12-23 08:09:43 +00002465
hassof390d2c2004-09-10 20:48:21 +00002466 for (i = 1; i < (max + 1); i++)
2467 {
2468 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2469 LSP_PSEUDO_ID (lspid) = 0x00;
2470 LSP_FRAGMENT (lspid) = 0x00;
2471 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2472 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002473
Josh Bailey3f045a02012-03-24 08:35:20 -07002474 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002475 lsp = lsp_new (lspid, rem_lifetime, 1, IS_LEVEL_1 | area->overload_bit
2476 | area->attached_bit, 0, 1);
hassof1082d12005-09-19 04:23:34 +00002477 if (!lsp)
2478 return;
hassof1082d12005-09-19 04:23:34 +00002479 lsp->area = area;
Josh Bailey3f045a02012-03-24 08:35:20 -07002480 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002481
hassof1082d12005-09-19 04:23:34 +00002482 /* Creating LSP data based on topology info. */
2483 build_topology_lsp_data (lsp, area, i);
2484 /* Checksum is also calculated here. */
2485 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002486 /* Take care of inserting dynamic hostname into cache. */
2487 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002488
Josh Bailey3f045a02012-03-24 08:35:20 -07002489 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002490 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002491 refresh_time);
2492 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002493 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002494 }
jardineb5d44e2003-12-23 08:09:43 +00002495}
2496
2497void
2498remove_topology_lsps (struct isis_area *area)
2499{
2500 struct isis_lsp *lsp;
2501 dnode_t *dnode, *dnode_next;
2502
2503 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002504 while (dnode != NULL)
2505 {
2506 dnode_next = dict_next (area->lspdb[0], dnode);
2507 lsp = dnode_get (dnode);
2508 if (lsp->from_topology)
2509 {
2510 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2511 lsp_destroy (lsp);
2512 dict_delete (area->lspdb[0], dnode);
2513 }
2514 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002515 }
jardineb5d44e2003-12-23 08:09:43 +00002516}
2517
2518void
hassof390d2c2004-09-10 20:48:21 +00002519build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002520 int lsp_top_num)
2521{
hasso3fdb2dd2005-09-28 18:45:54 +00002522 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002523 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002524 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002525 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002526 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002527 struct tlvs tlv_data;
2528 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002529
hassof1082d12005-09-19 04:23:34 +00002530 /* Add area addresses. FIXME: Is it needed at all? */
2531 if (lsp->tlv_data.area_addrs == NULL)
2532 lsp->tlv_data.area_addrs = list_new ();
2533 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002534
hassof1082d12005-09-19 04:23:34 +00002535 if (lsp->tlv_data.nlpids == NULL)
2536 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2537 lsp->tlv_data.nlpids->count = 1;
2538 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002539
hassof1082d12005-09-19 04:23:34 +00002540 if (area->dynhostname)
2541 {
2542 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2543 sizeof (struct hostname));
2544 memset (buff, 0x00, 200);
2545 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2546 "feedme", lsp_top_num);
2547 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2548 lsp->tlv_data.hostname->namelen = strlen (buff);
2549 }
2550
2551 if (lsp->tlv_data.nlpids)
2552 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2553 if (lsp->tlv_data.hostname)
2554 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2555 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2556 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2557
2558 memset (&tlv_data, 0, sizeof (struct tlvs));
2559 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002560 {
2561 tlv_data.is_neighs = list_new ();
2562 tlv_data.is_neighs->del = free_tlv;
2563 }
hassof1082d12005-09-19 04:23:34 +00002564
2565 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002566 if (lsp_top_num == 1)
2567 {
hasso3fdb2dd2005-09-28 18:45:54 +00002568 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002569
hassof390d2c2004-09-10 20:48:21 +00002570 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002571 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002572 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2573 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002574 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2575 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2576 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002577 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002578 }
hassof390d2c2004-09-10 20:48:21 +00002579
hassof1082d12005-09-19 04:23:34 +00002580 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002581 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002582 {
hassof1082d12005-09-19 04:23:34 +00002583 int to_lsp = 0;
2584
2585 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2586 continue;
2587
2588 if (lsp_top_num == arc->from_node)
2589 to_lsp = arc->to_node;
2590 else
2591 to_lsp = arc->from_node;
2592
hasso9551eea2005-09-28 18:26:25 +00002593 if (area->oldmetric)
2594 {
2595 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002596
hasso9551eea2005-09-28 18:26:25 +00002597 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2598 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2599 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2600 is_neigh->metrics.metric_default = arc->distance;
2601 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2602 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2603 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2604 listnode_add (tlv_data.is_neighs, is_neigh);
2605 }
2606
2607 if (area->newmetric)
2608 {
hasso9551eea2005-09-28 18:26:25 +00002609 if (tlv_data.te_is_neighs == NULL)
2610 {
2611 tlv_data.te_is_neighs = list_new ();
2612 tlv_data.te_is_neighs->del = free_tlv;
2613 }
2614 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2615 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2616 ISIS_SYS_ID_LEN);
2617 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2618 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07002619 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00002620 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2621 }
hassof390d2c2004-09-10 20:48:21 +00002622 }
hassof1082d12005-09-19 04:23:34 +00002623
2624 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2625 {
2626 if (lsp->tlv_data.is_neighs == NULL)
2627 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002628 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002629 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2630 tlv_add_is_neighs);
2631 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2632 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2633 lsp0, area, IS_LEVEL_1);
2634 }
2635
hasso9551eea2005-09-28 18:26:25 +00002636 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2637 {
2638 if (lsp->tlv_data.te_is_neighs == NULL)
2639 lsp->tlv_data.te_is_neighs = list_new ();
2640 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2641 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2642 tlv_add_te_is_neighs);
2643 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2644 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2645 lsp0, area, IS_LEVEL_1);
2646 }
2647
hassof1082d12005-09-19 04:23:34 +00002648 free_tlvs (&tlv_data);
2649 return;
jardineb5d44e2003-12-23 08:09:43 +00002650}
2651#endif /* TOPOLOGY_GENERATE */