blob: 0470c5b9075cfc4832e2ec5fc53ed2c25d6f4a75 [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));
hassof390d2c2004-09-10 20:48:21 +0000584 if (!lsp)
585 {
586 /* FIXME: set lspdbol bit */
587 zlog_warn ("lsp_new(): out of memory");
588 return NULL;
589 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700590 /* FIXME: Should be minimal mtu? */
591 lsp->pdu = stream_new (1500);
jardineb5d44e2003-12-23 08:09:43 +0000592 if (LSP_FRAGMENT (lsp_id) == 0)
593 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000594 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
595 lsp->lsp_header = (struct isis_link_state_hdr *)
596 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
597
jardineb5d44e2003-12-23 08:09:43 +0000598 /* at first we fill the FIXED HEADER */
Josh Bailey3f045a02012-03-24 08:35:20 -0700599 (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
hassof390d2c2004-09-10 20:48:21 +0000600 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
601
jardineb5d44e2003-12-23 08:09:43 +0000602 /* now for the LSP HEADER */
603 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000604 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000605 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000606 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000607 lsp->lsp_header->seq_num = htonl (seq_num);
608 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
609 lsp->lsp_header->lsp_bits = lsp_bits;
610 lsp->level = level;
611 lsp->age_out = ZERO_AGE_LIFETIME;
612
paul9985f832005-02-09 15:51:56 +0000613 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000614
hassoc89c05d2005-09-04 21:36:36 +0000615 if (isis->debugs & DEBUG_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -0700616 zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
hassoc89c05d2005-09-04 21:36:36 +0000617 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
618 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -0700619 ntohl (lsp->lsp_header->pdu_len),
hassoc89c05d2005-09-04 21:36:36 +0000620 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000621
622 return lsp;
623}
624
625void
hassof390d2c2004-09-10 20:48:21 +0000626lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000627{
628 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700629 if (lsp->lsp_header->seq_num != 0)
630 {
631 isis_spf_schedule (lsp->area, lsp->level);
632#ifdef HAVE_IPV6
633 isis_spf_schedule6 (lsp->area, lsp->level);
634#endif
635 }
jardineb5d44e2003-12-23 08:09:43 +0000636}
637
638/*
639 * Build a list of LSPs with non-zero ht bounded by start and stop ids
640 */
hassof390d2c2004-09-10 20:48:21 +0000641void
642lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
643 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000644{
645 dnode_t *first, *last, *curr;
646
647 first = dict_lower_bound (lspdb, start_id);
648 if (!first)
649 return;
hassof390d2c2004-09-10 20:48:21 +0000650
jardineb5d44e2003-12-23 08:09:43 +0000651 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000652
jardineb5d44e2003-12-23 08:09:43 +0000653 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000654
655 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000656 listnode_add (list, first->dict_data);
657
hassof390d2c2004-09-10 20:48:21 +0000658 while (curr)
659 {
660 curr = dict_next (lspdb, curr);
661 if (curr &&
662 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
663 listnode_add (list, curr->dict_data);
664 if (curr == last)
665 break;
666 }
667
jardineb5d44e2003-12-23 08:09:43 +0000668 return;
669}
670
671/*
Josh Bailey3f045a02012-03-24 08:35:20 -0700672 * Build a list of num_lsps LSPs bounded by start_id and stop_id.
jardineb5d44e2003-12-23 08:09:43 +0000673 */
hassof390d2c2004-09-10 20:48:21 +0000674void
Josh Bailey3f045a02012-03-24 08:35:20 -0700675lsp_build_list (u_char * start_id, u_char * stop_id, u_char num_lsps,
hassof390d2c2004-09-10 20:48:21 +0000676 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000677{
Josh Bailey3f045a02012-03-24 08:35:20 -0700678 u_char count;
jardineb5d44e2003-12-23 08:09:43 +0000679 dnode_t *first, *last, *curr;
680
681 first = dict_lower_bound (lspdb, start_id);
682 if (!first)
683 return;
hassof390d2c2004-09-10 20:48:21 +0000684
jardineb5d44e2003-12-23 08:09:43 +0000685 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000686
jardineb5d44e2003-12-23 08:09:43 +0000687 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000688
jardineb5d44e2003-12-23 08:09:43 +0000689 listnode_add (list, first->dict_data);
Josh Bailey3f045a02012-03-24 08:35:20 -0700690 count = 1;
jardineb5d44e2003-12-23 08:09:43 +0000691
hassof390d2c2004-09-10 20:48:21 +0000692 while (curr)
693 {
694 curr = dict_next (lspdb, curr);
695 if (curr)
Josh Bailey3f045a02012-03-24 08:35:20 -0700696 {
697 listnode_add (list, curr->dict_data);
698 count++;
699 }
700 if (count == num_lsps || curr == last)
701 break;
hassof390d2c2004-09-10 20:48:21 +0000702 }
703
jardineb5d44e2003-12-23 08:09:43 +0000704 return;
705}
706
707/*
708 * Build a list of LSPs with SSN flag set for the given circuit
709 */
710void
Josh Bailey3f045a02012-03-24 08:35:20 -0700711lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps,
712 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000713{
714 dnode_t *dnode, *next;
715 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -0700716 u_char count = 0;
hassof390d2c2004-09-10 20:48:21 +0000717
jardineb5d44e2003-12-23 08:09:43 +0000718 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000719 while (dnode != NULL)
720 {
721 next = dict_next (lspdb, dnode);
722 lsp = dnode_get (dnode);
723 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -0700724 {
725 listnode_add (list, lsp);
726 ++count;
727 }
728 if (count == num_lsps)
729 break;
hassof390d2c2004-09-10 20:48:21 +0000730 dnode = next;
731 }
732
jardineb5d44e2003-12-23 08:09:43 +0000733 return;
734}
735
hasso92365882005-01-18 13:53:33 +0000736static void
jardineb5d44e2003-12-23 08:09:43 +0000737lsp_set_time (struct isis_lsp *lsp)
738{
739 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000740
741 if (lsp->lsp_header->rem_lifetime == 0)
742 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700743 if (lsp->age_out > 0)
744 lsp->age_out--;
hassof390d2c2004-09-10 20:48:21 +0000745 return;
746 }
jardineb5d44e2003-12-23 08:09:43 +0000747
hassof390d2c2004-09-10 20:48:21 +0000748 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000749 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
750}
751
hasso92365882005-01-18 13:53:33 +0000752static void
hassof390d2c2004-09-10 20:48:21 +0000753lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000754{
755 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000756 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000757
758 if (dynhost)
759 dyn = dynhn_find_by_id (lsp_id);
760 else
761 dyn = NULL;
762
763 if (dyn)
Josh Bailey3f045a02012-03-24 08:35:20 -0700764 sprintf ((char *)id, "%.14s", dyn->name.name);
765 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
766 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000767 else
hassof390d2c2004-09-10 20:48:21 +0000768 memcpy (id, sysid_print (lsp_id), 15);
hassof390d2c2004-09-10 20:48:21 +0000769 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000770 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000771 LSP_FRAGMENT (lsp_id));
772 else
hassof7c43dc2004-09-26 16:24:14 +0000773 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000774}
775
hassof390d2c2004-09-10 20:48:21 +0000776/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000777const char *
hassof390d2c2004-09-10 20:48:21 +0000778lsp_bits2string (u_char * lsp_bits)
779{
780 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000781
hassof390d2c2004-09-10 20:48:21 +0000782 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000783 return " none";
784
785 /* we only focus on the default metric */
786 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000787 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000788
789 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000790 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000791
hassof390d2c2004-09-10 20:48:21 +0000792 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
793
jardineb5d44e2003-12-23 08:09:43 +0000794 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000795
hassof390d2c2004-09-10 20:48:21 +0000796 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000797}
798
799/* this function prints the lsp on show isis database */
Josh Bailey3f045a02012-03-24 08:35:20 -0700800void
801lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000802{
jardineb5d44e2003-12-23 08:09:43 +0000803 u_char LSPid[255];
Josh Bailey3f045a02012-03-24 08:35:20 -0700804 char age_out[8];
jardineb5d44e2003-12-23 08:09:43 +0000805
806 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700807 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
808 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len));
809 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
810 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
hassof390d2c2004-09-10 20:48:21 +0000811 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
Josh Bailey3f045a02012-03-24 08:35:20 -0700812 {
813 snprintf (age_out, 8, "(%u)", lsp->age_out);
814 age_out[7] = '\0';
815 vty_out (vty, "%7s ", age_out);
816 }
jardineb5d44e2003-12-23 08:09:43 +0000817 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700818 vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime));
819 vty_out (vty, "%s%s",
820 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000821}
822
Josh Bailey3f045a02012-03-24 08:35:20 -0700823void
824lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000825{
jardineb5d44e2003-12-23 08:09:43 +0000826 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000827 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000828 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000829 struct is_neigh *is_neigh;
830 struct te_is_neigh *te_is_neigh;
831 struct ipv4_reachability *ipv4_reach;
832 struct in_addr *ipv4_addr;
833 struct te_ipv4_reachability *te_ipv4_reach;
834#ifdef HAVE_IPV6
835 struct ipv6_reachability *ipv6_reach;
836 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000837 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000838#endif
839 u_char LSPid[255];
840 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000841 u_char ipv4_reach_prefix[20];
842 u_char ipv4_reach_mask[20];
843 u_char ipv4_address[20];
844
845 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700846 lsp_print (lsp, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000847
848 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000849 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000850 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000851 {
hasso1cd80842004-10-07 20:07:40 +0000852 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000853 isonet_print (area_addr->area_addr, area_addr->addr_len),
854 VTY_NEWLINE);
855 }
paul1eb8ef22005-04-07 07:30:20 +0000856
jardineb5d44e2003-12-23 08:09:43 +0000857 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000858 if (lsp->tlv_data.nlpids)
859 {
860 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
861 {
862 switch (lsp->tlv_data.nlpids->nlpids[i])
863 {
864 case NLPID_IP:
865 case NLPID_IPV6:
Josh Bailey3f045a02012-03-24 08:35:20 -0700866 vty_out (vty, " NLPID : 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000867 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
868 break;
869 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700870 vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000871 break;
872 }
873 }
874 }
jardineb5d44e2003-12-23 08:09:43 +0000875
876 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000877 if (lsp->tlv_data.hostname)
878 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700879 bzero (hostname, sizeof (hostname));
hassof390d2c2004-09-10 20:48:21 +0000880 memcpy (hostname, lsp->tlv_data.hostname->name,
881 lsp->tlv_data.hostname->namelen);
Josh Bailey3f045a02012-03-24 08:35:20 -0700882 vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000883 }
hassof390d2c2004-09-10 20:48:21 +0000884
Josh Bailey3f045a02012-03-24 08:35:20 -0700885 /* authentication tlv */
886 if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED)
887 {
888 if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5)
889 vty_out (vty, " Auth type : md5%s", VTY_NEWLINE);
890 else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT)
891 vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE);
892 }
hassof390d2c2004-09-10 20:48:21 +0000893
hasso1cd80842004-10-07 20:07:40 +0000894 /* TE router id */
895 if (lsp->tlv_data.router_id)
896 {
897 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
898 sizeof (ipv4_address));
Josh Bailey3f045a02012-03-24 08:35:20 -0700899 vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE);
hasso1cd80842004-10-07 20:07:40 +0000900 }
901
Josh Bailey3f045a02012-03-24 08:35:20 -0700902 if (lsp->tlv_data.ipv4_addrs)
903 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
904 {
905 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
906 vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE);
907 }
908
hasso1cd80842004-10-07 20:07:40 +0000909 /* for the IS neighbor tlv */
910 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000911 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000912 {
913 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700914 vty_out (vty, " Metric : %-8d IS : %s%s",
hasso1cd80842004-10-07 20:07:40 +0000915 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
916 }
hasso1cd80842004-10-07 20:07:40 +0000917
jardineb5d44e2003-12-23 08:09:43 +0000918 /* for the internal reachable tlv */
919 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000920 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
921 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000922 {
923 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
924 sizeof (ipv4_reach_prefix));
925 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
926 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700927 vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000928 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
929 ipv4_reach_mask, VTY_NEWLINE);
930 }
hasso2097cd82003-12-23 11:51:08 +0000931
932 /* for the external reachable tlv */
933 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000934 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
935 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000936 {
937 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
938 sizeof (ipv4_reach_prefix));
939 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
940 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700941 vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000942 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
943 ipv4_reach_mask, VTY_NEWLINE);
944 }
paul1eb8ef22005-04-07 07:30:20 +0000945
hasso2097cd82003-12-23 11:51:08 +0000946 /* IPv6 tlv */
947#ifdef HAVE_IPV6
948 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000949 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000950 {
951 memset (&in6, 0, sizeof (in6));
952 memcpy (in6.s6_addr, ipv6_reach->prefix,
953 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000954 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
David Lamparter6db3ef62015-03-03 09:07:43 +0100955 if ((ipv6_reach->control_info &
hassof390d2c2004-09-10 20:48:21 +0000956 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
Josh Bailey3f045a02012-03-24 08:35:20 -0700957 vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000958 ntohl (ipv6_reach->metric),
959 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000960 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700961 vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000962 ntohl (ipv6_reach->metric),
963 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000964 }
965#endif
paul1eb8ef22005-04-07 07:30:20 +0000966
hasso1cd80842004-10-07 20:07:40 +0000967 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000968 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000969 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000970 {
hassof390d2c2004-09-10 20:48:21 +0000971 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700972 vty_out (vty, " Metric : %-8d IS-Extended : %s%s",
973 GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000974 }
jardineb5d44e2003-12-23 08:09:43 +0000975
hasso1cd80842004-10-07 20:07:40 +0000976 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000977 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000978 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
979 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000980 {
hasso1cd80842004-10-07 20:07:40 +0000981 /* FIXME: There should be better way to output this stuff. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700982 vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000983 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000984 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
985 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000986 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000987 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700988 vty_out (vty, "%s", VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000989
hassof390d2c2004-09-10 20:48:21 +0000990 return;
jardineb5d44e2003-12-23 08:09:43 +0000991}
992
993/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000994int
995lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000996{
997
hassof390d2c2004-09-10 20:48:21 +0000998 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000999 int lsp_count = 0;
1000
hassof390d2c2004-09-10 20:48:21 +00001001 if (detail == ISIS_UI_LEVEL_BRIEF)
1002 {
1003 while (node != NULL)
1004 {
1005 /* I think it is unnecessary, so I comment it out */
1006 /* dict_contains (lspdb, node); */
1007 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001008 lsp_print (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001009 node = next;
1010 lsp_count++;
1011 }
jardineb5d44e2003-12-23 08:09:43 +00001012 }
hassof390d2c2004-09-10 20:48:21 +00001013 else if (detail == ISIS_UI_LEVEL_DETAIL)
1014 {
1015 while (node != NULL)
1016 {
1017 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001018 lsp_print_detail (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001019 node = next;
1020 lsp_count++;
1021 }
jardineb5d44e2003-12-23 08:09:43 +00001022 }
jardineb5d44e2003-12-23 08:09:43 +00001023
1024 return lsp_count;
1025}
1026
jardineb5d44e2003-12-23 08:09:43 +00001027#define FRAG_THOLD(S,T) \
Josh Bailey3f045a02012-03-24 08:35:20 -07001028 ((STREAM_SIZE(S)*T)/100)
jardineb5d44e2003-12-23 08:09:43 +00001029
1030/* stream*, area->lsp_frag_threshold, increment */
1031#define FRAG_NEEDED(S,T,I) \
1032 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1033
hassoaa4376e2005-09-26 17:39:48 +00001034/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
1035 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +00001036static void
jardineb5d44e2003-12-23 08:09:43 +00001037lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001038 int tlvsize, int frag_thold,
1039 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001040{
1041 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001042
jardineb5d44e2003-12-23 08:09:43 +00001043 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001044 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1045 {
1046 tlv_build_func (*from, lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07001047 if (listcount (*to) != 0)
1048 {
1049 struct listnode *node, *nextnode;
1050 void *elem;
1051
1052 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1053 {
1054 listnode_add (*to, elem);
1055 list_delete_node (*from, node);
1056 }
1057 }
1058 else
1059 {
1060 list_free (*to);
1061 *to = *from;
1062 *from = NULL;
1063 }
jardineb5d44e2003-12-23 08:09:43 +00001064 }
hassof390d2c2004-09-10 20:48:21 +00001065 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1066 {
1067 /* fit all we can */
1068 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1069 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
Josh Bailey3f045a02012-03-24 08:35:20 -07001070 count = count / tlvsize;
1071 if (count > (int)listcount (*from))
1072 count = listcount (*from);
hassof390d2c2004-09-10 20:48:21 +00001073 for (i = 0; i < count; i++)
1074 {
paul1eb8ef22005-04-07 07:30:20 +00001075 listnode_add (*to, listgetdata (listhead (*from)));
1076 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001077 }
1078 tlv_build_func (*to, lsp->pdu);
1079 }
paul9985f832005-02-09 15:51:56 +00001080 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001081 return;
1082}
1083
Josh Bailey3f045a02012-03-24 08:35:20 -07001084static u_int16_t
1085lsp_rem_lifetime (struct isis_area *area, int level)
1086{
1087 u_int16_t rem_lifetime;
1088
1089 /* Add jitter to configured LSP lifetime */
1090 rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1],
1091 MAX_AGE_JITTER);
1092
1093 /* No jitter if the max refresh will be less than configure gen interval */
1094 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1095 rem_lifetime = area->max_lsp_lifetime[level - 1];
1096
1097 return rem_lifetime;
1098}
1099
1100static u_int16_t
1101lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1102{
1103 struct isis_area *area = lsp->area;
1104 int level = lsp->level;
1105 u_int16_t refresh_time;
1106
1107 /* Add jitter to LSP refresh time */
1108 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1109 MAX_LSP_GEN_JITTER);
1110
1111 /* RFC 4444 : make sure the refresh time is at least less than 300
1112 * of the remaining lifetime and more than gen interval */
1113 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1114 refresh_time > (rem_lifetime - 300))
1115 refresh_time = rem_lifetime - 300;
1116
1117 assert (area->lsp_gen_interval[level - 1] < refresh_time);
1118
1119 return refresh_time;
1120}
1121
hasso92365882005-01-18 13:53:33 +00001122static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001123lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1124 int level)
jardineb5d44e2003-12-23 08:09:43 +00001125{
1126 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001127 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1128
jardineb5d44e2003-12-23 08:09:43 +00001129 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1130 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001131 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001132 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001133 if (lsp)
1134 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001135 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001136 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001137 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001138 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001139 lsp = lsp_new (frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001140 lsp_bits_generate (level, area->overload_bit,
1141 area->attached_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001142 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001143 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001144 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001145 listnode_add (lsp0->lspu.frags, lsp);
1146 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001147 return lsp;
1148}
1149
1150/*
1151 * Builds the LSP data part. This func creates a new frag whenever
1152 * area->lsp_frag_threshold is exceeded.
1153 */
hasso92365882005-01-18 13:53:33 +00001154static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001155lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001156{
1157 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001158 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001159 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001160 int level = lsp->level;
1161 struct isis_circuit *circuit;
1162 struct prefix_ipv4 *ipv4;
1163 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001164 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001165 struct isis_adjacency *nei;
1166#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001167 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001168 struct ipv6_reachability *ip6reach;
1169#endif /* HAVE_IPV6 */
1170 struct tlvs tlv_data;
1171 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001172 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001173 uint32_t expected = 0, found = 0;
1174 uint32_t metric;
1175 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1176 int retval = ISIS_OK;
1177
1178 /*
1179 * Building the zero lsp
1180 */
1181 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1182
1183 /* Reset stream endp. Stream is always there and on every LSP refresh only
1184 * TLV part of it is overwritten. So we must seek past header we will not
1185 * touch. */
1186 stream_reset (lsp->pdu);
1187 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1188
1189 /*
1190 * Add the authentication info if its present
1191 */
1192 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001193
1194 /*
1195 * First add the tlvs related to area
1196 */
hassof390d2c2004-09-10 20:48:21 +00001197
jardineb5d44e2003-12-23 08:09:43 +00001198 /* Area addresses */
1199 if (lsp->tlv_data.area_addrs == NULL)
1200 lsp->tlv_data.area_addrs = list_new ();
1201 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001202 if (listcount (lsp->tlv_data.area_addrs) > 0)
1203 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1204
jardineb5d44e2003-12-23 08:09:43 +00001205 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001206 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001207#ifdef HAVE_IPV6
1208 || area->ipv6_circuits > 0
1209#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001210 )
jardineb5d44e2003-12-23 08:09:43 +00001211 {
hassoaac372f2005-09-01 17:52:33 +00001212 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001213 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001214 if (area->ip_circuits > 0)
1215 {
1216 lsp->tlv_data.nlpids->count++;
1217 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1218 }
jardineb5d44e2003-12-23 08:09:43 +00001219#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001220 if (area->ipv6_circuits > 0)
1221 {
1222 lsp->tlv_data.nlpids->count++;
1223 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1224 NLPID_IPV6;
1225 }
jardineb5d44e2003-12-23 08:09:43 +00001226#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001227 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001228 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001229
jardineb5d44e2003-12-23 08:09:43 +00001230 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001231 if (area->dynhostname)
1232 {
1233 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1234 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001235
hassof390d2c2004-09-10 20:48:21 +00001236 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1237 strlen (unix_hostname ()));
1238 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
Josh Bailey3f045a02012-03-24 08:35:20 -07001239 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001240 }
jardineb5d44e2003-12-23 08:09:43 +00001241
hasso81ad8f62005-09-26 17:58:24 +00001242 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1243 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1244 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001245 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001246 {
hasso18a6dce2004-10-03 18:18:34 +00001247 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001248 {
1249 lsp->tlv_data.ipv4_addrs = list_new ();
1250 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1251 }
hasso18a6dce2004-10-03 18:18:34 +00001252
1253 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001254 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001255 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001256 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001257
hasso81ad8f62005-09-26 17:58:24 +00001258 /* Exactly same data is put into TE router ID TLV, but only if new style
1259 * TLV's are in use. */
1260 if (area->newmetric)
1261 {
1262 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1263 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001264 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1265 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1266 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001267 }
hasso18a6dce2004-10-03 18:18:34 +00001268 }
hassof1082d12005-09-19 04:23:34 +00001269
hasso81ad8f62005-09-26 17:58:24 +00001270 memset (&tlv_data, 0, sizeof (struct tlvs));
1271
hassof1082d12005-09-19 04:23:34 +00001272#ifdef TOPOLOGY_GENERATE
1273 /* If topology exists (and we create topology for level 1 only), create
1274 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001275 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001276 {
1277 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001278 {
1279 tlv_data.is_neighs = list_new ();
1280 tlv_data.is_neighs->del = free_tlv;
1281 }
hasso3fdb2dd2005-09-28 18:45:54 +00001282 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001283
1284 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1285 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1286 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1287 is_neigh->metrics.metric_default = 0x01;
1288 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1289 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1290 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1291 listnode_add (tlv_data.is_neighs, is_neigh);
1292 }
1293#endif /* TOPOLOGY_GENERATE */
1294
hasso18a6dce2004-10-03 18:18:34 +00001295 /*
jardineb5d44e2003-12-23 08:09:43 +00001296 * Then build lists of tlvs related to circuits
1297 */
hasso3fdb2dd2005-09-28 18:45:54 +00001298 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001299 {
hassof390d2c2004-09-10 20:48:21 +00001300 if (circuit->state != C_STATE_UP)
1301 continue;
jardineb5d44e2003-12-23 08:09:43 +00001302
hassof390d2c2004-09-10 20:48:21 +00001303 /*
1304 * Add IPv4 internal reachability of this circuit
1305 */
1306 if (circuit->ip_router && circuit->ip_addrs &&
1307 circuit->ip_addrs->count > 0)
1308 {
hassoaa4376e2005-09-26 17:39:48 +00001309 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001310 {
hassoaa4376e2005-09-26 17:39:48 +00001311 if (tlv_data.ipv4_int_reachs == NULL)
1312 {
1313 tlv_data.ipv4_int_reachs = list_new ();
1314 tlv_data.ipv4_int_reachs->del = free_tlv;
1315 }
hasso3fdb2dd2005-09-28 18:45:54 +00001316 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001317 {
1318 ipreach =
1319 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1320 ipreach->metrics = circuit->metrics[level - 1];
1321 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1322 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1323 (ipv4->prefix.s_addr));
1324 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1325 }
hassof390d2c2004-09-10 20:48:21 +00001326 }
hassoaa4376e2005-09-26 17:39:48 +00001327 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001328 {
hassoaa4376e2005-09-26 17:39:48 +00001329 if (tlv_data.te_ipv4_reachs == NULL)
1330 {
1331 tlv_data.te_ipv4_reachs = list_new ();
1332 tlv_data.te_ipv4_reachs->del = free_tlv;
1333 }
hasso3fdb2dd2005-09-28 18:45:54 +00001334 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001335 {
1336 /* FIXME All this assumes that we have no sub TLVs. */
1337 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1338 sizeof (struct te_ipv4_reachability) +
1339 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001340
1341 if (area->oldmetric)
1342 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1343 else
1344 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1345
hassoaa4376e2005-09-26 17:39:48 +00001346 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1347 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1348 (ipv4->prefixlen + 7)/8);
1349 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1350 }
hassof390d2c2004-09-10 20:48:21 +00001351 }
hassof390d2c2004-09-10 20:48:21 +00001352 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001353
jardineb5d44e2003-12-23 08:09:43 +00001354#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001355 /*
1356 * Add IPv6 reachability of this circuit
1357 */
1358 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1359 circuit->ipv6_non_link->count > 0)
1360 {
1361
1362 if (tlv_data.ipv6_reachs == NULL)
1363 {
1364 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001365 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001366 }
hasso3fdb2dd2005-09-28 18:45:54 +00001367 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001368 {
hassof390d2c2004-09-10 20:48:21 +00001369 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001370 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001371
1372 if (area->oldmetric)
1373 ip6reach->metric =
1374 htonl (circuit->metrics[level - 1].metric_default);
1375 else
1376 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1377
hassof390d2c2004-09-10 20:48:21 +00001378 ip6reach->control_info = 0;
1379 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001380 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1381 apply_mask_ipv6 (ip6prefix);
1382 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1383 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001384 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1385 }
1386 }
1387#endif /* HAVE_IPV6 */
1388
1389 switch (circuit->circ_type)
1390 {
1391 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001392 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001393 {
hassoaa4376e2005-09-26 17:39:48 +00001394 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001395 {
hassoaa4376e2005-09-26 17:39:48 +00001396 if (tlv_data.is_neighs == NULL)
1397 {
1398 tlv_data.is_neighs = list_new ();
1399 tlv_data.is_neighs->del = free_tlv;
1400 }
1401 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001402 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001403 memcpy (is_neigh->neigh_id,
1404 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1405 else
1406 memcpy (is_neigh->neigh_id,
1407 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1408 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001409 if (!memcmp (is_neigh->neigh_id, zero_id,
1410 ISIS_SYS_ID_LEN + 1))
1411 XFREE (MTYPE_ISIS_TLV, is_neigh);
1412 else
1413 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001414 }
hassoaa4376e2005-09-26 17:39:48 +00001415 if (area->newmetric)
1416 {
hassoaa4376e2005-09-26 17:39:48 +00001417 if (tlv_data.te_is_neighs == NULL)
1418 {
1419 tlv_data.te_is_neighs = list_new ();
1420 tlv_data.te_is_neighs->del = free_tlv;
1421 }
1422 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1423 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001424 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001425 memcpy (te_is_neigh->neigh_id,
1426 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1427 else
1428 memcpy (te_is_neigh->neigh_id,
1429 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001430 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001431 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001432 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001433 metric = circuit->te_metric[level - 1];
1434 SET_TE_METRIC(te_is_neigh, metric);
1435 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1436 ISIS_SYS_ID_LEN + 1))
1437 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1438 else
1439 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
hassoaa4376e2005-09-26 17:39:48 +00001440 }
hassof390d2c2004-09-10 20:48:21 +00001441 }
1442 break;
1443 case CIRCUIT_T_P2P:
1444 nei = circuit->u.p2p.neighbor;
1445 if (nei && (level & nei->circuit_t))
1446 {
hassoaa4376e2005-09-26 17:39:48 +00001447 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001448 {
hassoaa4376e2005-09-26 17:39:48 +00001449 if (tlv_data.is_neighs == NULL)
1450 {
1451 tlv_data.is_neighs = list_new ();
1452 tlv_data.is_neighs->del = free_tlv;
1453 }
1454 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1455 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1456 is_neigh->metrics = circuit->metrics[level - 1];
1457 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001458 }
hassoaa4376e2005-09-26 17:39:48 +00001459 if (area->newmetric)
1460 {
1461 uint32_t metric;
1462
1463 if (tlv_data.te_is_neighs == NULL)
1464 {
1465 tlv_data.te_is_neighs = list_new ();
1466 tlv_data.te_is_neighs->del = free_tlv;
1467 }
1468 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1469 sizeof (struct te_is_neigh));
1470 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001471 metric = circuit->te_metric[level - 1];
1472 SET_TE_METRIC(te_is_neigh, metric);
hassoaa4376e2005-09-26 17:39:48 +00001473 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1474 }
hassof390d2c2004-09-10 20:48:21 +00001475 }
1476 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001477 case CIRCUIT_T_LOOPBACK:
1478 break;
hassof390d2c2004-09-10 20:48:21 +00001479 default:
1480 zlog_warn ("lsp_area_create: unknown circuit type");
1481 }
1482 }
1483
1484 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1485 {
1486 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1487 lsp->tlv_data.ipv4_int_reachs = list_new ();
1488 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1489 &lsp->tlv_data.ipv4_int_reachs,
1490 IPV4_REACH_LEN, area->lsp_frag_threshold,
1491 tlv_add_ipv4_reachs);
1492 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1493 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1494 lsp0, area, level);
1495 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001496
hassoaa4376e2005-09-26 17:39:48 +00001497 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1498 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1499 * TLVs (sub TLVs!). */
1500 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1501 {
1502 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1503 lsp->tlv_data.te_ipv4_reachs = list_new ();
1504 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1505 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001506 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1507 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001508 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1509 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1510 lsp0, area, level);
1511 }
hassof390d2c2004-09-10 20:48:21 +00001512
1513#ifdef HAVE_IPV6
1514 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1515 {
1516 if (lsp->tlv_data.ipv6_reachs == NULL)
1517 lsp->tlv_data.ipv6_reachs = list_new ();
1518 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1519 &lsp->tlv_data.ipv6_reachs,
1520 IPV6_REACH_LEN, area->lsp_frag_threshold,
1521 tlv_add_ipv6_reachs);
1522 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1523 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1524 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001525 }
1526#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001527
1528 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1529 {
1530 if (lsp->tlv_data.is_neighs == NULL)
1531 lsp->tlv_data.is_neighs = list_new ();
1532 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1533 &lsp->tlv_data.is_neighs,
1534 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1535 tlv_add_is_neighs);
1536 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1537 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1538 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001539 }
jardineb5d44e2003-12-23 08:09:43 +00001540
hassoaa4376e2005-09-26 17:39:48 +00001541 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1542 {
1543 if (lsp->tlv_data.te_is_neighs == NULL)
1544 lsp->tlv_data.te_is_neighs = list_new ();
1545 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1546 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1547 tlv_add_te_is_neighs);
1548 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1549 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1550 lsp0, area, level);
1551 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001552 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001553
1554 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001555
1556 /* Validate the LSP */
1557 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1558 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1559 stream_get_endp (lsp->pdu) -
1560 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1561 &expected, &found, &tlv_data, NULL);
1562 assert (retval == ISIS_OK);
1563
jardineb5d44e2003-12-23 08:09:43 +00001564 return;
1565}
jardineb5d44e2003-12-23 08:09:43 +00001566
1567/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001568 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001569 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001570int
1571lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001572{
jardineb5d44e2003-12-23 08:09:43 +00001573 struct isis_lsp *oldlsp, *newlsp;
1574 u_int32_t seq_num = 0;
1575 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001576 u_int16_t rem_lifetime, refresh_time;
1577
1578 if ((area == NULL) || (area->is_type & level) != level)
1579 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001580
1581 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1582 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1583
1584 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001585 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1586 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001587 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001588 /* FIXME: we should actually initiate a purge */
1589 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1590 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1591 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001592 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001593 rem_lifetime = lsp_rem_lifetime (area, level);
1594 newlsp = lsp_new (lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001595 area->is_type | area->overload_bit | area->attached_bit,
1596 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001597 newlsp->area = area;
1598 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001599
Josh Bailey3f045a02012-03-24 08:35:20 -07001600 lsp_insert (newlsp, area->lspdb[level - 1]);
1601 /* build_lsp_data (newlsp, area); */
1602 lsp_build (newlsp, area);
1603 /* time to calculate our checksum */
1604 lsp_seqnum_update (newlsp);
1605 lsp_set_all_srmflags (newlsp);
1606
1607 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
1608 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
1609 if (level == IS_LEVEL_1)
1610 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1611 lsp_l1_refresh, area, refresh_time);
1612 else if (level == IS_LEVEL_2)
1613 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1614 lsp_l2_refresh, area, refresh_time);
1615
1616 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001617 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001618 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1619 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1620 area->area_tag, level,
1621 rawlspid_print (newlsp->lsp_header->lsp_id),
1622 ntohl (newlsp->lsp_header->pdu_len),
1623 ntohl (newlsp->lsp_header->seq_num),
1624 ntohs (newlsp->lsp_header->checksum),
1625 ntohs (newlsp->lsp_header->rem_lifetime),
1626 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001627 }
jardineb5d44e2003-12-23 08:09:43 +00001628
1629 return ISIS_OK;
1630}
1631
1632/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001633 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001634 */
hasso92365882005-01-18 13:53:33 +00001635static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001636lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001637{
David Lampartere8aca322012-11-27 01:10:30 +00001638 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001639 struct isis_lsp *lsp, *frag;
1640 struct listnode *node;
1641 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001642 u_int16_t rem_lifetime, refresh_time;
1643
1644 if ((area == NULL) || (area->is_type & level) != level)
1645 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001646
David Lampartere8aca322012-11-27 01:10:30 +00001647 lspdb = area->lspdb[level - 1];
1648
jardineb5d44e2003-12-23 08:09:43 +00001649 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1650 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001651
jardineb5d44e2003-12-23 08:09:43 +00001652 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001653
hassof390d2c2004-09-10 20:48:21 +00001654 if (!lsp)
1655 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001656 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1657 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001658 return ISIS_ERROR;
1659 }
1660
1661 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001662 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001663 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1664 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001665 rem_lifetime = lsp_rem_lifetime (area, level);
1666 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001667 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001668
Josh Bailey3f045a02012-03-24 08:35:20 -07001669 lsp->last_generated = time (NULL);
1670 lsp_set_all_srmflags (lsp);
1671 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1672 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001673 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001674 area->overload_bit,
1675 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001676 /* Set the lifetime values of all the fragments to the same value,
1677 * so that no fragment expires before the lsp is refreshed.
1678 */
1679 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1680 lsp_set_all_srmflags (frag);
1681 }
1682
1683 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1684 if (level == IS_LEVEL_1)
1685 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1686 lsp_l1_refresh, area, refresh_time);
1687 else if (level == IS_LEVEL_2)
1688 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1689 lsp_l2_refresh, area, refresh_time);
1690
hassof390d2c2004-09-10 20:48:21 +00001691 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1692 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001693 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
1694 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1695 area->area_tag, level,
1696 rawlspid_print (lsp->lsp_header->lsp_id),
1697 ntohl (lsp->lsp_header->pdu_len),
1698 ntohl (lsp->lsp_header->seq_num),
1699 ntohs (lsp->lsp_header->checksum),
1700 ntohs (lsp->lsp_header->rem_lifetime),
1701 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001702 }
jardineb5d44e2003-12-23 08:09:43 +00001703
jardineb5d44e2003-12-23 08:09:43 +00001704 return ISIS_OK;
1705}
1706
jardineb5d44e2003-12-23 08:09:43 +00001707/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001708 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00001709 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001710static int
1711lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001712{
1713 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001714
1715 area = THREAD_ARG (thread);
1716 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001717
jardineb5d44e2003-12-23 08:09:43 +00001718 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001719 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00001720
Josh Bailey3f045a02012-03-24 08:35:20 -07001721 if ((area->is_type & IS_LEVEL_1) == 0)
1722 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001723
Josh Bailey3f045a02012-03-24 08:35:20 -07001724 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00001725}
1726
Josh Bailey3f045a02012-03-24 08:35:20 -07001727static int
1728lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001729{
1730 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001731
1732 area = THREAD_ARG (thread);
1733 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001734
jardineb5d44e2003-12-23 08:09:43 +00001735 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001736 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001737
Josh Bailey3f045a02012-03-24 08:35:20 -07001738 if ((area->is_type & IS_LEVEL_2) == 0)
1739 return ISIS_ERROR;
1740
1741 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00001742}
1743
hassof390d2c2004-09-10 20:48:21 +00001744int
Josh Bailey3f045a02012-03-24 08:35:20 -07001745lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00001746{
1747 struct isis_lsp *lsp;
1748 u_char id[ISIS_SYS_ID_LEN + 2];
1749 time_t now, diff;
Josh Bailey3f045a02012-03-24 08:35:20 -07001750 struct listnode *cnode;
1751 struct isis_circuit *circuit;
1752 int lvl;
1753
1754 if (area == NULL)
1755 return ISIS_ERROR;
1756
hassof390d2c2004-09-10 20:48:21 +00001757 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1758 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001759 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001760
1761 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00001762 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001763 if (!((level & lvl) && (area->is_type & lvl)))
1764 continue;
1765
1766 if (area->lsp_regenerate_pending[lvl - 1])
1767 continue;
1768
1769 lsp = lsp_search (id, area->lspdb[lvl - 1]);
1770 if (!lsp)
1771 continue;
1772
hassof390d2c2004-09-10 20:48:21 +00001773 /*
1774 * Throttle avoidance
1775 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001776 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00001777 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07001778 if (diff < area->lsp_gen_interval[lvl - 1])
1779 {
1780 area->lsp_regenerate_pending[lvl - 1] = 1;
1781 if (lvl == IS_LEVEL_1)
1782 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1783 lsp_l1_refresh, area,
1784 area->lsp_gen_interval[lvl - 1] - diff);
1785 else if (lvl == IS_LEVEL_2)
1786 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1787 lsp_l2_refresh, area,
1788 area->lsp_gen_interval[lvl - 1] - diff);
1789 }
hassof390d2c2004-09-10 20:48:21 +00001790 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001791 {
Michael Zinggbe62b172012-10-26 11:18:19 +02001792 /*
1793 * lsps are not regenerated if lsp_regenerate function is called
1794 * directly. However if the lsp_regenerate call is queued for
1795 * later execution it works.
1796 */
1797 area->lsp_regenerate_pending[lvl - 1] = 1;
1798 if (lvl == IS_LEVEL_1)
1799 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1800 lsp_l1_refresh, area, 0);
1801 else if (lvl == IS_LEVEL_2)
1802 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1803 lsp_l2_refresh, area, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07001804 }
hassof390d2c2004-09-10 20:48:21 +00001805 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001806
1807 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00001808 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001809 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
1810 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00001811 }
1812
1813 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001814}
1815
1816/*
1817 * Funcs for pseudonode LSPs
1818 */
1819
1820/*
1821 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1822 */
hasso92365882005-01-18 13:53:33 +00001823static void
hassof390d2c2004-09-10 20:48:21 +00001824lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1825 int level)
jardineb5d44e2003-12-23 08:09:43 +00001826{
1827 struct isis_adjacency *adj;
1828 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001829 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001830 struct es_neigh *es_neigh;
1831 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001832 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +00001833
jardineb5d44e2003-12-23 08:09:43 +00001834 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07001835 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001836 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
1837 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00001838
1839 /*
1840 * add self to IS neighbours
1841 */
hassoaa4376e2005-09-26 17:39:48 +00001842 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001843 {
hassoaa4376e2005-09-26 17:39:48 +00001844 if (lsp->tlv_data.is_neighs == NULL)
1845 {
1846 lsp->tlv_data.is_neighs = list_new ();
1847 lsp->tlv_data.is_neighs->del = free_tlv;
1848 }
1849 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001850
hassoaa4376e2005-09-26 17:39:48 +00001851 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1852 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1853 }
1854 if (circuit->area->newmetric)
1855 {
1856 if (lsp->tlv_data.te_is_neighs == NULL)
1857 {
1858 lsp->tlv_data.te_is_neighs = list_new ();
1859 lsp->tlv_data.te_is_neighs->del = free_tlv;
1860 }
1861 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1862
1863 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1864 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1865 }
hassof390d2c2004-09-10 20:48:21 +00001866
1867 adj_list = list_new ();
1868 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1869
hasso3fdb2dd2005-09-28 18:45:54 +00001870 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001871 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001872 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00001873 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001874 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1875 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00001876 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001877 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00001878 {
1879 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00001880 if (circuit->area->oldmetric)
1881 {
1882 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001883
hassoaa4376e2005-09-26 17:39:48 +00001884 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1885 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1886 }
1887 if (circuit->area->newmetric)
1888 {
1889 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1890 sizeof (struct te_is_neigh));
1891 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1892 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1893 }
hassof390d2c2004-09-10 20:48:21 +00001894 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001895 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00001896 {
1897 /* an ES neigbour add it, if we are building level 1 LSP */
1898 /* FIXME: the tlv-format is hard to use here */
1899 if (lsp->tlv_data.es_neighs == NULL)
1900 {
1901 lsp->tlv_data.es_neighs = list_new ();
1902 lsp->tlv_data.es_neighs->del = free_tlv;
1903 }
paul15935e92005-05-03 09:27:23 +00001904 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1905
hassof390d2c2004-09-10 20:48:21 +00001906 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001907 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001908 }
1909 }
jardineb5d44e2003-12-23 08:09:43 +00001910 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001911 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00001912
hassoc0fb2a52005-09-03 16:29:40 +00001913 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001914 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001915 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1916
jardineb5d44e2003-12-23 08:09:43 +00001917 /*
1918 * Add the authentication info if it's present
1919 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001920 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001921
1922 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1923 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1924
hassoaa4376e2005-09-26 17:39:48 +00001925 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
1926 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
1927
jardineb5d44e2003-12-23 08:09:43 +00001928 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1929 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1930
paul9985f832005-02-09 15:51:56 +00001931 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001932
Josh Bailey3f045a02012-03-24 08:35:20 -07001933 /* Recompute authentication and checksum information */
1934 lsp_auth_update (lsp);
1935 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
1936 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00001937
1938 return;
1939}
1940
Josh Bailey3f045a02012-03-24 08:35:20 -07001941int
1942lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00001943{
1944 dict_t *lspdb = circuit->area->lspdb[level - 1];
1945 struct isis_lsp *lsp;
1946 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001947 u_int16_t rem_lifetime, refresh_time;
1948
1949 if ((circuit->is_type & level) != level ||
1950 (circuit->state != C_STATE_UP) ||
1951 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
1952 (circuit->u.bc.is_dr[level - 1] == 0))
1953 return ISIS_ERROR;
1954
1955 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1956 LSP_FRAGMENT (lsp_id) = 0;
1957 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1958
1959 /*
1960 * If for some reason have a pseudo LSP in the db already -> regenerate
1961 */
1962 if (lsp_search (lsp_id, lspdb))
1963 return lsp_regenerate_schedule_pseudo (circuit, level);
1964
1965 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
1966 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001967 lsp = lsp_new (lsp_id, rem_lifetime, 1,
1968 circuit->area->is_type | circuit->area->attached_bit,
1969 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001970 lsp->area = circuit->area;
1971
1972 lsp_build_pseudo (lsp, circuit, level);
1973
1974 lsp->own_lsp = 1;
1975 lsp_insert (lsp, lspdb);
1976 lsp_set_all_srmflags (lsp);
1977
1978 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1979 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1980 circuit->lsp_regenerate_pending[level - 1] = 0;
1981 if (level == IS_LEVEL_1)
1982 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1983 lsp_l1_refresh_pseudo, circuit, refresh_time);
1984 else if (level == IS_LEVEL_2)
1985 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1986 lsp_l2_refresh_pseudo, circuit, refresh_time);
1987
1988 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1989 {
1990 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
1991 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
1992 circuit->area->area_tag, level,
1993 rawlspid_print (lsp->lsp_header->lsp_id),
1994 ntohl (lsp->lsp_header->pdu_len),
1995 ntohl (lsp->lsp_header->seq_num),
1996 ntohs (lsp->lsp_header->checksum),
1997 ntohs (lsp->lsp_header->rem_lifetime),
1998 refresh_time);
1999 }
2000
2001 return ISIS_OK;
2002}
2003
2004static int
2005lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2006{
2007 dict_t *lspdb = circuit->area->lspdb[level - 1];
2008 struct isis_lsp *lsp;
2009 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2010 u_int16_t rem_lifetime, refresh_time;
2011
2012 if ((circuit->is_type & level) != level ||
2013 (circuit->state != C_STATE_UP) ||
2014 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2015 (circuit->u.bc.is_dr[level - 1] == 0))
2016 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002017
jardineb5d44e2003-12-23 08:09:43 +00002018 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002019 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2020 LSP_FRAGMENT (lsp_id) = 0;
2021
jardineb5d44e2003-12-23 08:09:43 +00002022 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002023
2024 if (!lsp)
2025 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002026 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2027 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002028 return ISIS_ERROR;
2029 }
2030 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002031
2032 lsp_build_pseudo (lsp, circuit, level);
2033
Josh Bailey3f045a02012-03-24 08:35:20 -07002034 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002035 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2036 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002037 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2038 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002039 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002040 lsp->last_generated = time (NULL);
2041 lsp_set_all_srmflags (lsp);
2042
2043 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2044 if (level == IS_LEVEL_1)
2045 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2046 lsp_l1_refresh_pseudo, circuit, refresh_time);
2047 else if (level == IS_LEVEL_2)
2048 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2049 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002050
2051 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2052 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002053 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2054 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2055 circuit->area->area_tag, level,
2056 rawlspid_print (lsp->lsp_header->lsp_id),
2057 ntohl (lsp->lsp_header->pdu_len),
2058 ntohl (lsp->lsp_header->seq_num),
2059 ntohs (lsp->lsp_header->checksum),
2060 ntohs (lsp->lsp_header->rem_lifetime),
2061 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002062 }
jardineb5d44e2003-12-23 08:09:43 +00002063
jardineb5d44e2003-12-23 08:09:43 +00002064 return ISIS_OK;
2065}
2066
Josh Bailey3f045a02012-03-24 08:35:20 -07002067/*
2068 * Something has changed or periodic refresh -> regenerate pseudo LSP
2069 */
2070static int
jardineb5d44e2003-12-23 08:09:43 +00002071lsp_l1_refresh_pseudo (struct thread *thread)
2072{
2073 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002074 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002075
hassof390d2c2004-09-10 20:48:21 +00002076 circuit = THREAD_ARG (thread);
2077
hasso13c48f72004-09-10 21:19:13 +00002078 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002079 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002080
Josh Bailey3f045a02012-03-24 08:35:20 -07002081 if ((circuit->u.bc.is_dr[0] == 0) ||
2082 (circuit->is_type & IS_LEVEL_1) == 0)
2083 {
2084 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2085 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2086 LSP_FRAGMENT (id) = 0;
2087 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2088 return ISIS_ERROR;
2089 }
hassof390d2c2004-09-10 20:48:21 +00002090
Josh Bailey3f045a02012-03-24 08:35:20 -07002091 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002092}
2093
Josh Bailey3f045a02012-03-24 08:35:20 -07002094static int
jardineb5d44e2003-12-23 08:09:43 +00002095lsp_l2_refresh_pseudo (struct thread *thread)
2096{
2097 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002098 u_char id[ISIS_SYS_ID_LEN + 2];
2099
hassof390d2c2004-09-10 20:48:21 +00002100 circuit = THREAD_ARG (thread);
2101
hasso13c48f72004-09-10 21:19:13 +00002102 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002103 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002104
Josh Bailey3f045a02012-03-24 08:35:20 -07002105 if ((circuit->u.bc.is_dr[1] == 0) ||
2106 (circuit->is_type & IS_LEVEL_2) == 0)
2107 {
2108 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2109 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2110 LSP_FRAGMENT (id) = 0;
2111 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2112 return ISIS_ERROR;
2113 }
jardineb5d44e2003-12-23 08:09:43 +00002114
Josh Bailey3f045a02012-03-24 08:35:20 -07002115 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002116}
2117
hassof390d2c2004-09-10 20:48:21 +00002118int
Josh Bailey3f045a02012-03-24 08:35:20 -07002119lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002120{
2121 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002122 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2123 time_t now, diff;
2124 int lvl;
jardineb5d44e2003-12-23 08:09:43 +00002125
Josh Bailey3f045a02012-03-24 08:35:20 -07002126 if (circuit == NULL ||
2127 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2128 circuit->state != C_STATE_UP)
2129 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002130
Josh Bailey3f045a02012-03-24 08:35:20 -07002131 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2132 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2133 LSP_FRAGMENT (lsp_id) = 0;
2134 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002135
Josh Bailey3f045a02012-03-24 08:35:20 -07002136 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2137 {
2138 if (!((level & lvl) && (circuit->is_type & lvl)))
2139 continue;
jardineb5d44e2003-12-23 08:09:43 +00002140
Josh Bailey3f045a02012-03-24 08:35:20 -07002141 if (circuit->u.bc.is_dr[lvl - 1] == 0 ||
2142 circuit->lsp_regenerate_pending[lvl - 1])
2143 continue;
hassof390d2c2004-09-10 20:48:21 +00002144
Josh Bailey3f045a02012-03-24 08:35:20 -07002145 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2146 if (!lsp)
2147 continue;
jardineb5d44e2003-12-23 08:09:43 +00002148
Josh Bailey3f045a02012-03-24 08:35:20 -07002149 /*
2150 * Throttle avoidance
2151 */
2152 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2153 diff = now - lsp->last_generated;
2154 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2155 {
2156 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2157 if (lvl == IS_LEVEL_1)
2158 THREAD_TIMER_ON (master,
2159 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2160 lsp_l1_refresh_pseudo, circuit,
2161 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2162 else if (lvl == IS_LEVEL_2)
2163 THREAD_TIMER_ON (master,
2164 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2165 lsp_l2_refresh_pseudo, circuit,
2166 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2167 }
2168 else
2169 {
2170 lsp_regenerate_pseudo (circuit, lvl);
2171 }
2172 }
jardineb5d44e2003-12-23 08:09:43 +00002173
Josh Bailey3f045a02012-03-24 08:35:20 -07002174 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002175}
2176
jardineb5d44e2003-12-23 08:09:43 +00002177/*
2178 * Walk through LSPs for an area
2179 * - set remaining lifetime
2180 * - set LSPs with SRMflag set for sending
2181 */
hassof390d2c2004-09-10 20:48:21 +00002182int
jardineb5d44e2003-12-23 08:09:43 +00002183lsp_tick (struct thread *thread)
2184{
2185 struct isis_area *area;
2186 struct isis_circuit *circuit;
2187 struct isis_lsp *lsp;
2188 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002189 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002190 dnode_t *dnode, *dnode_next;
2191 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002192 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002193
2194 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002195
jardineb5d44e2003-12-23 08:09:43 +00002196 area = THREAD_ARG (thread);
2197 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002198 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002199 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002200
2201 /*
2202 * Build a list of LSPs with (any) SRMflag set
2203 * and removed the ones that have aged out
2204 */
hassof390d2c2004-09-10 20:48:21 +00002205 for (level = 0; level < ISIS_LEVELS; level++)
2206 {
2207 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002208 {
2209 for (dnode = dict_first (area->lspdb[level]);
2210 dnode != NULL; dnode = dnode_next)
2211 {
2212 dnode_next = dict_next (area->lspdb[level], dnode);
2213 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002214
Josh Bailey3f045a02012-03-24 08:35:20 -07002215 /*
2216 * The lsp rem_lifetime is kept at 0 for MaxAge or
2217 * ZeroAgeLifetime depending on explicit purge or
2218 * natural age out. So schedule spf only once when
2219 * the first time rem_lifetime becomes 0.
2220 */
2221 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2222 lsp_set_time (lsp);
2223
2224 /*
2225 * Schedule may run spf which should be done only after
2226 * the lsp rem_lifetime becomes 0 for the first time.
2227 * ISO 10589 - 7.3.16.4 first paragraph.
2228 */
2229 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2230 {
2231 /* 7.3.16.4 a) set SRM flags on all */
2232 lsp_set_all_srmflags (lsp);
2233 /* 7.3.16.4 b) retain only the header FIXME */
2234 /* 7.3.16.4 c) record the time to purge FIXME */
2235 /* run/schedule spf */
2236 /* isis_spf_schedule is called inside lsp_destroy() below;
2237 * so it is not needed here. */
2238 /* isis_spf_schedule (lsp->area, lsp->level); */
2239 }
2240
2241 if (lsp->age_out == 0)
2242 {
2243 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2244 area->area_tag,
2245 lsp->level,
2246 rawlspid_print (lsp->lsp_header->lsp_id),
2247 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002248#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002249 if (lsp->from_topology)
2250 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002251#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002252 lsp_destroy (lsp);
2253 lsp = NULL;
2254 dict_delete_free (area->lspdb[level], dnode);
2255 }
2256 else if (flags_any_set (lsp->SRMflags))
2257 listnode_add (lsp_list, lsp);
2258 }
jardineb5d44e2003-12-23 08:09:43 +00002259
Josh Bailey3f045a02012-03-24 08:35:20 -07002260 /*
2261 * Send LSPs on circuits indicated by the SRMflags
2262 */
2263 if (listcount (lsp_list) > 0)
2264 {
paul1eb8ef22005-04-07 07:30:20 +00002265 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002266 {
2267 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2268 if (circuit->lsp_queue == NULL ||
2269 diff < MIN_LSP_TRANS_INTERVAL)
2270 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002271 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002272 {
2273 if (circuit->upadjcount[lsp->level - 1] &&
2274 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2275 {
2276 /* Add the lsp only if it is not already in lsp
2277 * queue */
2278 if (! listnode_lookup (circuit->lsp_queue, lsp))
2279 {
2280 listnode_add (circuit->lsp_queue, lsp);
2281 thread_add_event (master, send_lsp, circuit, 0);
2282 }
2283 }
2284 }
2285 }
2286 list_delete_all_node (lsp_list);
2287 }
2288 }
jardineb5d44e2003-12-23 08:09:43 +00002289 }
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 list_delete (lsp_list);
2292
2293 return ISIS_OK;
2294}
2295
jardineb5d44e2003-12-23 08:09:43 +00002296void
Josh Bailey3f045a02012-03-24 08:35:20 -07002297lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002298{
2299 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002300 u_int16_t seq_num;
2301 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002302
jardineb5d44e2003-12-23 08:09:43 +00002303 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002304 if (!lsp)
2305 return;
hassof390d2c2004-09-10 20:48:21 +00002306
Josh Bailey3f045a02012-03-24 08:35:20 -07002307 /* store old values */
2308 seq_num = lsp->lsp_header->seq_num;
2309 lsp_bits = lsp->lsp_header->lsp_bits;
2310
2311 /* reset stream */
2312 lsp_clear_data (lsp);
2313 stream_reset (lsp->pdu);
2314
2315 /* update header */
2316 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2317 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2318 lsp->lsp_header->checksum = 0;
2319 lsp->lsp_header->seq_num = seq_num;
2320 lsp->lsp_header->rem_lifetime = 0;
2321 lsp->lsp_header->lsp_bits = lsp_bits;
2322 lsp->level = level;
2323 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2324 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2325
2326 /*
2327 * Add and update the authentication info if its present
2328 */
2329 lsp_auth_add (lsp);
2330 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2331 lsp_auth_update (lsp);
2332 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2333 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2334
2335 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002336
jardineb5d44e2003-12-23 08:09:43 +00002337 return;
2338}
2339
2340/*
2341 * Purge own LSP that is received and we don't have.
2342 * -> Do as in 7.3.16.4
2343 */
2344void
hassof390d2c2004-09-10 20:48:21 +00002345lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2346 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002347{
2348 struct isis_lsp *lsp;
2349
2350 /*
2351 * We need to create the LSP to be purged
2352 */
hassoaac372f2005-09-01 17:52:33 +00002353 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002354 lsp->area = area;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002355 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ?
2356 IS_LEVEL_1 : IS_LEVEL_2;
Josh Bailey3f045a02012-03-24 08:35:20 -07002357 /* FIXME: Should be minimal mtu? */
2358 lsp->pdu = stream_new (1500);
hassof390d2c2004-09-10 20:48:21 +00002359 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002360 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002361 : L2_LINK_STATE);
2362 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2363 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002364 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002365 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002366
jardineb5d44e2003-12-23 08:09:43 +00002367 /*
jardineb5d44e2003-12-23 08:09:43 +00002368 * Set the remaining lifetime to 0
2369 */
2370 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002371
2372 /*
2373 * Add and update the authentication info if its present
2374 */
2375 lsp_auth_add (lsp);
2376 lsp_auth_update (lsp);
2377
2378 /*
2379 * Update the PDU length to header plus any authentication TLV.
2380 */
2381 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2382
jardineb5d44e2003-12-23 08:09:43 +00002383 /*
2384 * Put the lsp into LSPdb
2385 */
hassof390d2c2004-09-10 20:48:21 +00002386 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002387
2388 /*
2389 * Send in to whole area
2390 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002391 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002392
jardineb5d44e2003-12-23 08:09:43 +00002393 return;
2394}
2395
Josh Bailey3f045a02012-03-24 08:35:20 -07002396void lsp_set_all_srmflags (struct isis_lsp *lsp)
2397{
2398 struct listnode *node;
2399 struct isis_circuit *circuit;
2400
2401 assert (lsp);
2402
2403 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2404
2405 if (lsp->area)
2406 {
2407 struct list *circuit_list = lsp->area->circuit_list;
2408 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2409 {
2410 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2411 }
2412 }
2413}
2414
jardineb5d44e2003-12-23 08:09:43 +00002415#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002416static int
jardineb5d44e2003-12-23 08:09:43 +00002417top_lsp_refresh (struct thread *thread)
2418{
hassof390d2c2004-09-10 20:48:21 +00002419 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002420 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002421
2422 lsp = THREAD_ARG (thread);
2423 assert (lsp);
2424
2425 lsp->t_lsp_top_ref = NULL;
2426
hassof1082d12005-09-19 04:23:34 +00002427 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002428
Josh Bailey3f045a02012-03-24 08:35:20 -07002429 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002430 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2431 {
hasso529d65b2004-12-24 00:14:50 +00002432 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2433 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002434 }
hassod3d74742005-09-28 18:30:51 +00002435 /* Refresh dynamic hostname in the cache. */
2436 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2437 IS_LEVEL_1);
2438
David Lampartera47c5832012-06-21 09:55:38 +02002439 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002440 lsp->area->overload_bit,
2441 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002442 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2443 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002444
David Lamparterf50ee932015-03-04 07:13:38 +01002445 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002446 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002447 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002448
2449 return ISIS_OK;
2450}
2451
2452void
2453generate_topology_lsps (struct isis_area *area)
2454{
2455 struct listnode *node;
2456 int i, max = 0;
2457 struct arc *arc;
2458 u_char lspid[ISIS_SYS_ID_LEN + 2];
2459 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002460 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002461
2462 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002463 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002464 {
2465 if (arc->from_node > max)
2466 max = arc->from_node;
2467 if (arc->to_node > max)
2468 max = arc->to_node;
2469 }
jardineb5d44e2003-12-23 08:09:43 +00002470
hassof390d2c2004-09-10 20:48:21 +00002471 for (i = 1; i < (max + 1); i++)
2472 {
2473 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2474 LSP_PSEUDO_ID (lspid) = 0x00;
2475 LSP_FRAGMENT (lspid) = 0x00;
2476 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2477 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002478
Josh Bailey3f045a02012-03-24 08:35:20 -07002479 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002480 lsp = lsp_new (lspid, rem_lifetime, 1, IS_LEVEL_1 | area->overload_bit
2481 | area->attached_bit, 0, 1);
hassof1082d12005-09-19 04:23:34 +00002482 if (!lsp)
2483 return;
hassof1082d12005-09-19 04:23:34 +00002484 lsp->area = area;
Josh Bailey3f045a02012-03-24 08:35:20 -07002485 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002486
hassof1082d12005-09-19 04:23:34 +00002487 /* Creating LSP data based on topology info. */
2488 build_topology_lsp_data (lsp, area, i);
2489 /* Checksum is also calculated here. */
2490 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002491 /* Take care of inserting dynamic hostname into cache. */
2492 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002493
Josh Bailey3f045a02012-03-24 08:35:20 -07002494 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002495 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002496 refresh_time);
2497 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002498 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002499 }
jardineb5d44e2003-12-23 08:09:43 +00002500}
2501
2502void
2503remove_topology_lsps (struct isis_area *area)
2504{
2505 struct isis_lsp *lsp;
2506 dnode_t *dnode, *dnode_next;
2507
2508 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002509 while (dnode != NULL)
2510 {
2511 dnode_next = dict_next (area->lspdb[0], dnode);
2512 lsp = dnode_get (dnode);
2513 if (lsp->from_topology)
2514 {
2515 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2516 lsp_destroy (lsp);
2517 dict_delete (area->lspdb[0], dnode);
2518 }
2519 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002520 }
jardineb5d44e2003-12-23 08:09:43 +00002521}
2522
2523void
hassof390d2c2004-09-10 20:48:21 +00002524build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002525 int lsp_top_num)
2526{
hasso3fdb2dd2005-09-28 18:45:54 +00002527 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002528 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002529 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002530 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002531 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002532 struct tlvs tlv_data;
2533 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002534
hassof1082d12005-09-19 04:23:34 +00002535 /* Add area addresses. FIXME: Is it needed at all? */
2536 if (lsp->tlv_data.area_addrs == NULL)
2537 lsp->tlv_data.area_addrs = list_new ();
2538 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002539
hassof1082d12005-09-19 04:23:34 +00002540 if (lsp->tlv_data.nlpids == NULL)
2541 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2542 lsp->tlv_data.nlpids->count = 1;
2543 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002544
hassof1082d12005-09-19 04:23:34 +00002545 if (area->dynhostname)
2546 {
2547 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2548 sizeof (struct hostname));
2549 memset (buff, 0x00, 200);
2550 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2551 "feedme", lsp_top_num);
2552 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2553 lsp->tlv_data.hostname->namelen = strlen (buff);
2554 }
2555
2556 if (lsp->tlv_data.nlpids)
2557 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2558 if (lsp->tlv_data.hostname)
2559 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2560 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2561 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2562
2563 memset (&tlv_data, 0, sizeof (struct tlvs));
2564 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002565 {
2566 tlv_data.is_neighs = list_new ();
2567 tlv_data.is_neighs->del = free_tlv;
2568 }
hassof1082d12005-09-19 04:23:34 +00002569
2570 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002571 if (lsp_top_num == 1)
2572 {
hasso3fdb2dd2005-09-28 18:45:54 +00002573 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002574
hassof390d2c2004-09-10 20:48:21 +00002575 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002576 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002577 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2578 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002579 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2580 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2581 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002582 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002583 }
hassof390d2c2004-09-10 20:48:21 +00002584
hassof1082d12005-09-19 04:23:34 +00002585 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002586 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002587 {
hassof1082d12005-09-19 04:23:34 +00002588 int to_lsp = 0;
2589
2590 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2591 continue;
2592
2593 if (lsp_top_num == arc->from_node)
2594 to_lsp = arc->to_node;
2595 else
2596 to_lsp = arc->from_node;
2597
hasso9551eea2005-09-28 18:26:25 +00002598 if (area->oldmetric)
2599 {
2600 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002601
hasso9551eea2005-09-28 18:26:25 +00002602 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2603 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2604 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2605 is_neigh->metrics.metric_default = arc->distance;
2606 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2607 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2608 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2609 listnode_add (tlv_data.is_neighs, is_neigh);
2610 }
2611
2612 if (area->newmetric)
2613 {
hasso9551eea2005-09-28 18:26:25 +00002614 if (tlv_data.te_is_neighs == NULL)
2615 {
2616 tlv_data.te_is_neighs = list_new ();
2617 tlv_data.te_is_neighs->del = free_tlv;
2618 }
2619 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2620 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2621 ISIS_SYS_ID_LEN);
2622 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2623 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07002624 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00002625 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2626 }
hassof390d2c2004-09-10 20:48:21 +00002627 }
hassof1082d12005-09-19 04:23:34 +00002628
2629 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2630 {
2631 if (lsp->tlv_data.is_neighs == NULL)
2632 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002633 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002634 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2635 tlv_add_is_neighs);
2636 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2637 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2638 lsp0, area, IS_LEVEL_1);
2639 }
2640
hasso9551eea2005-09-28 18:26:25 +00002641 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2642 {
2643 if (lsp->tlv_data.te_is_neighs == NULL)
2644 lsp->tlv_data.te_is_neighs = list_new ();
2645 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2646 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2647 tlv_add_te_is_neighs);
2648 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2649 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2650 lsp0, area, IS_LEVEL_1);
2651 }
2652
hassof1082d12005-09-19 04:23:34 +00002653 free_tlvs (&tlv_data);
2654 return;
jardineb5d44e2003-12-23 08:09:43 +00002655}
2656#endif /* TOPOLOGY_GENERATE */