blob: 9032de4f4f6428a51baeb663653efe0d3c111d35 [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
Christian Frankeacf98652015-11-12 14:24:22 +01008 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
jardineb5d44e2003-12-23 08:09:43 +00009 *
10 * This program is free software; you can redistribute it and/or modify it
Christian Frankeacf98652015-11-12 14:24:22 +010011 * under the terms of the GNU General Public License as published by the Free
jardineb5d44e2003-12-23 08:09:43 +000012 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
paul15935e92005-05-03 09:27:23 +000024
jardineb5d44e2003-12-23 08:09:43 +000025#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000026
27#include "linklist.h"
28#include "thread.h"
29#include "vty.h"
30#include "stream.h"
31#include "memory.h"
32#include "log.h"
33#include "prefix.h"
34#include "command.h"
35#include "hash.h"
36#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010037#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070038#include "md5.h"
Christian Frankeacf98652015-11-12 14:24:22 +010039#include "table.h"
jardineb5d44e2003-12-23 08:09:43 +000040
41#include "isisd/dict.h"
42#include "isisd/isis_constants.h"
43#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070044#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000045#include "isisd/isis_circuit.h"
46#include "isisd/isisd.h"
47#include "isisd/isis_tlv.h"
48#include "isisd/isis_lsp.h"
49#include "isisd/isis_pdu.h"
50#include "isisd/isis_dynhn.h"
51#include "isisd/isis_misc.h"
jardineb5d44e2003-12-23 08:09:43 +000052#include "isisd/isis_csm.h"
53#include "isisd/isis_adjacency.h"
54#include "isisd/isis_spf.h"
Olivier Dugeon4f593572016-04-19 19:03:05 +020055#include "isisd/isis_te.h"
jardineb5d44e2003-12-23 08:09:43 +000056
57#ifdef TOPOLOGY_GENERATE
58#include "spgrid.h"
59#endif
60
hasso73d1aea2004-09-24 10:45:28 +000061/* staticly assigned vars for printing purposes */
62char lsp_bits_string[200]; /* FIXME: enough ? */
63
Josh Bailey3f045a02012-03-24 08:35:20 -070064static int lsp_l1_refresh (struct thread *thread);
65static int lsp_l2_refresh (struct thread *thread);
66static int lsp_l1_refresh_pseudo (struct thread *thread);
67static int lsp_l2_refresh_pseudo (struct thread *thread);
68
hassof390d2c2004-09-10 20:48:21 +000069int
70lsp_id_cmp (u_char * id1, u_char * id2)
71{
jardineb5d44e2003-12-23 08:09:43 +000072 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
73}
74
75dict_t *
hassof390d2c2004-09-10 20:48:21 +000076lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000077{
78 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000079
80 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
81
jardineb5d44e2003-12-23 08:09:43 +000082 return dict;
83}
84
85struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000086lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000087{
88 dnode_t *node;
89
hassof390d2c2004-09-10 20:48:21 +000090#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000091 dnode_t *dn;
92
hasso529d65b2004-12-24 00:14:50 +000093 zlog_debug ("searching db");
hassof390d2c2004-09-10 20:48:21 +000094 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
95 {
Josh Bailey3f045a02012-03-24 08:35:20 -070096 zlog_debug ("%s\t%pX", rawlspid_print ((u_char *) dnode_getkey (dn)),
hasso529d65b2004-12-24 00:14:50 +000097 dnode_get (dn));
hassof390d2c2004-09-10 20:48:21 +000098 }
jardineb5d44e2003-12-23 08:09:43 +000099#endif /* EXTREME DEBUG */
100
101 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000102
jardineb5d44e2003-12-23 08:09:43 +0000103 if (node)
hassof390d2c2004-09-10 20:48:21 +0000104 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000105
106 return NULL;
107}
108
hasso92365882005-01-18 13:53:33 +0000109static void
jardineb5d44e2003-12-23 08:09:43 +0000110lsp_clear_data (struct isis_lsp *lsp)
111{
112 if (!lsp)
113 return;
hassof390d2c2004-09-10 20:48:21 +0000114
Josh Bailey3f045a02012-03-24 08:35:20 -0700115 if (lsp->tlv_data.hostname)
116 isis_dynhn_remove (lsp->lsp_header->lsp_id);
117
hassof390d2c2004-09-10 20:48:21 +0000118 if (lsp->own_lsp)
119 {
120 if (lsp->tlv_data.nlpids)
Josh Bailey3f045a02012-03-24 08:35:20 -0700121 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
hassof390d2c2004-09-10 20:48:21 +0000122 if (lsp->tlv_data.hostname)
Josh Bailey3f045a02012-03-24 08:35:20 -0700123 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
124 if (lsp->tlv_data.router_id)
125 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.router_id);
hassof390d2c2004-09-10 20:48:21 +0000126 }
jardineb5d44e2003-12-23 08:09:43 +0000127
Josh Bailey3f045a02012-03-24 08:35:20 -0700128 free_tlvs (&lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000129}
130
hasso92365882005-01-18 13:53:33 +0000131static void
jardineb5d44e2003-12-23 08:09:43 +0000132lsp_destroy (struct isis_lsp *lsp)
133{
Josh Bailey3f045a02012-03-24 08:35:20 -0700134 struct listnode *cnode, *lnode, *lnnode;
135 struct isis_lsp *lsp_in_list;
136 struct isis_circuit *circuit;
137
jardineb5d44e2003-12-23 08:09:43 +0000138 if (!lsp)
139 return;
hassof390d2c2004-09-10 20:48:21 +0000140
boris yakubova0a661f2013-04-26 14:38:34 -0400141 if (lsp->area->circuit_list) {
142 for (ALL_LIST_ELEMENTS_RO (lsp->area->circuit_list, cnode, circuit))
143 {
144 if (circuit->lsp_queue == NULL)
145 continue;
146 for (ALL_LIST_ELEMENTS (circuit->lsp_queue, lnode, lnnode, lsp_in_list))
147 if (lsp_in_list == lsp)
148 list_delete_node(circuit->lsp_queue, lnode);
149 }
150 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700151 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags);
152 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
153
jardineb5d44e2003-12-23 08:09:43 +0000154 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000155
156 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
157 {
jardineb5d44e2003-12-23 08:09:43 +0000158 list_delete (lsp->lspu.frags);
Josh Bailey3f045a02012-03-24 08:35:20 -0700159 lsp->lspu.frags = NULL;
hassof390d2c2004-09-10 20:48:21 +0000160 }
161
Josh Bailey3f045a02012-03-24 08:35:20 -0700162 isis_spf_schedule (lsp->area, lsp->level);
163#ifdef HAVE_IPV6
164 isis_spf_schedule6 (lsp->area, lsp->level);
165#endif
166
jardineb5d44e2003-12-23 08:09:43 +0000167 if (lsp->pdu)
168 stream_free (lsp->pdu);
169 XFREE (MTYPE_ISIS_LSP, lsp);
170}
171
hassof390d2c2004-09-10 20:48:21 +0000172void
173lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000174{
175 dnode_t *dnode, *next;
176 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000177
jardineb5d44e2003-12-23 08:09:43 +0000178 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000179 while (dnode)
180 {
181 next = dict_next (lspdb, dnode);
182 lsp = dnode_get (dnode);
183 lsp_destroy (lsp);
184 dict_delete_free (lspdb, dnode);
185 dnode = next;
186 }
187
jardineb5d44e2003-12-23 08:09:43 +0000188 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000189
jardineb5d44e2003-12-23 08:09:43 +0000190 return;
191}
192
193/*
194 * Remove all the frags belonging to the given lsp
195 */
hasso92365882005-01-18 13:53:33 +0000196static void
hassof390d2c2004-09-10 20:48:21 +0000197lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000198{
199 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000200 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000201 struct isis_lsp *lsp;
202
paul1eb8ef22005-04-07 07:30:20 +0000203 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000204 {
hassof390d2c2004-09-10 20:48:21 +0000205 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
206 lsp_destroy (lsp);
207 dnode_destroy (dict_delete (lspdb, dnode));
208 }
209
jardineb5d44e2003-12-23 08:09:43 +0000210 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000211
jardineb5d44e2003-12-23 08:09:43 +0000212 return;
213}
214
215void
hassof390d2c2004-09-10 20:48:21 +0000216lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000217{
218 dnode_t *node;
219 struct isis_lsp *lsp;
220
221 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000222 if (node)
223 {
224 node = dict_delete (lspdb, node);
225 lsp = dnode_get (node);
226 /*
227 * If this is a zero lsp, remove all the frags now
228 */
229 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
230 {
231 if (lsp->lspu.frags)
232 lsp_remove_frags (lsp->lspu.frags, lspdb);
233 }
234 else
235 {
236 /*
237 * else just remove this frag, from the zero lsps' frag list
238 */
239 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
240 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
241 }
242 lsp_destroy (lsp);
243 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000244 }
jardineb5d44e2003-12-23 08:09:43 +0000245}
246
247/*
248 * Compares a LSP to given values
249 * Params are given in net order
250 */
hassof390d2c2004-09-10 20:48:21 +0000251int
252lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000253 u_int16_t checksum, u_int16_t rem_lifetime)
254{
hassof390d2c2004-09-10 20:48:21 +0000255 /* no point in double ntohl on seqnum */
256 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000257 lsp->lsp_header->checksum == checksum &&
258 /*comparing with 0, no need to do ntohl */
259 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000260 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
261 {
262 if (isis->debugs & DEBUG_SNP_PACKETS)
263 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700264 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000265 " lifetime %us",
266 areatag,
267 rawlspid_print (lsp->lsp_header->lsp_id),
268 ntohl (lsp->lsp_header->seq_num),
269 ntohs (lsp->lsp_header->checksum),
270 ntohs (lsp->lsp_header->rem_lifetime));
271 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
272 " cksum 0x%04x, lifetime %us",
273 areatag,
274 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000275 }
276 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000277 }
jardineb5d44e2003-12-23 08:09:43 +0000278
Christian Franke80d6b4e2015-11-10 18:33:15 +0100279 /*
280 * LSPs with identical checksums should only be treated as newer if:
281 * a) The current LSP has a remaining lifetime != 0 and the other LSP has a
282 * remaining lifetime == 0. In this case, we should participate in the purge
283 * and should not treat the current LSP with remaining lifetime == 0 as older.
284 * b) The LSP has an incorrect checksum. In this case, we need to react as given
285 * in 7.3.16.2.
286 */
287 if (ntohl (seq_num) > ntohl (lsp->lsp_header->seq_num)
288 || (ntohl(seq_num) == ntohl(lsp->lsp_header->seq_num)
289 && ( (lsp->lsp_header->rem_lifetime != 0
290 && rem_lifetime == 0)
291 || lsp->lsp_header->checksum != checksum)))
hassof390d2c2004-09-10 20:48:21 +0000292 {
293 if (isis->debugs & DEBUG_SNP_PACKETS)
294 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700295 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000296 " lifetime %us",
297 areatag,
298 rawlspid_print (lsp->lsp_header->lsp_id),
299 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
300 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
301 "cksum 0x%04x, lifetime %us",
302 areatag,
303 ntohl (lsp->lsp_header->seq_num),
304 ntohs (lsp->lsp_header->checksum),
305 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000306 }
307 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000308 }
hassof390d2c2004-09-10 20:48:21 +0000309 if (isis->debugs & DEBUG_SNP_PACKETS)
310 {
hasso529d65b2004-12-24 00:14:50 +0000311 zlog_debug
Josh Bailey3f045a02012-03-24 08:35:20 -0700312 ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
hassof390d2c2004-09-10 20:48:21 +0000313 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
314 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000315 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
316 " cksum 0x%04x, lifetime %us", areatag,
317 ntohl (lsp->lsp_header->seq_num),
318 ntohs (lsp->lsp_header->checksum),
319 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000320 }
jardineb5d44e2003-12-23 08:09:43 +0000321
322 return LSP_OLDER;
323}
324
Josh Bailey3f045a02012-03-24 08:35:20 -0700325static void
326lsp_auth_add (struct isis_lsp *lsp)
327{
328 struct isis_passwd *passwd;
329 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
330
331 /*
332 * Add the authentication info if its present
333 */
334 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
335 (passwd = &lsp->area->domain_passwd);
336 switch (passwd->type)
337 {
338 /* Cleartext */
339 case ISIS_PASSWD_TYPE_CLEARTXT:
340 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
341 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
342 break;
343
344 /* HMAC MD5 */
345 case ISIS_PASSWD_TYPE_HMAC_MD5:
346 /* Remember where TLV is written so we can later
347 * overwrite the MD5 hash */
348 lsp->auth_tlv_offset = stream_get_endp (lsp->pdu);
349 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
350 lsp->tlv_data.auth_info.type = ISIS_PASSWD_TYPE_HMAC_MD5;
351 lsp->tlv_data.auth_info.len = ISIS_AUTH_MD5_SIZE;
352 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
353 ISIS_AUTH_MD5_SIZE);
354 tlv_add_authinfo (passwd->type, ISIS_AUTH_MD5_SIZE, hmac_md5_hash,
355 lsp->pdu);
356 break;
357
358 default:
359 break;
360 }
361}
362
363static void
364lsp_auth_update (struct isis_lsp *lsp)
365{
366 struct isis_passwd *passwd;
367 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
368 uint16_t checksum, rem_lifetime;
369
370 /* For HMAC MD5 we need to recompute the md5 hash and store it */
371 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
372 (passwd = &lsp->area->domain_passwd);
373 if (passwd->type != ISIS_PASSWD_TYPE_HMAC_MD5)
374 return;
375
376 /*
377 * In transient conditions (when net is configured where authentication
378 * config and lsp regenerate schedule is not yet run), there could be
379 * an own_lsp with auth_tlv_offset set to 0. In such a case, simply
380 * return, when lsp_regenerate is run, lsp will have auth tlv.
381 */
382 if (lsp->auth_tlv_offset == 0)
383 return;
384
385 /*
386 * RFC 5304 set auth value, checksum and remaining lifetime to zero
387 * before computation and reset to old values after computation.
388 */
389 checksum = lsp->lsp_header->checksum;
390 rem_lifetime = lsp->lsp_header->rem_lifetime;
391 lsp->lsp_header->checksum = 0;
392 lsp->lsp_header->rem_lifetime = 0;
393 /* Set the authentication value as well to zero */
394 memset (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
395 0, ISIS_AUTH_MD5_SIZE);
396 /* Compute autentication value */
397 hmac_md5 (STREAM_DATA (lsp->pdu), stream_get_endp(lsp->pdu),
398 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +0100399 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -0700400 /* Copy the hash into the stream */
401 memcpy (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
402 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
403 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
404 ISIS_AUTH_MD5_SIZE);
405 /* Copy back the checksum and remaining lifetime */
406 lsp->lsp_header->checksum = checksum;
407 lsp->lsp_header->rem_lifetime = rem_lifetime;
408}
409
hassof390d2c2004-09-10 20:48:21 +0000410void
jardineb5d44e2003-12-23 08:09:43 +0000411lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
412{
413 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000414
jardineb5d44e2003-12-23 08:09:43 +0000415 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
416 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
417 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700418 newseq = seq_num + 1;
hassof390d2c2004-09-10 20:48:21 +0000419
jardineb5d44e2003-12-23 08:09:43 +0000420 lsp->lsp_header->seq_num = htonl (newseq);
Josh Bailey3f045a02012-03-24 08:35:20 -0700421
422 /* Recompute authentication and checksum information */
423 lsp_auth_update (lsp);
424 /* ISO 10589 - 7.3.11 Generation of the checksum
425 * The checksum shall be computed over all fields in the LSP which appear
426 * after the Remaining Lifetime field. This field (and those appearing
427 * before it) are excluded so that the LSP may be aged by systems without
428 * requiring recomputation.
429 */
430 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
431 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
432
433 isis_spf_schedule (lsp->area, lsp->level);
434#ifdef HAVE_IPV6
435 isis_spf_schedule6 (lsp->area, lsp->level);
436#endif
jardineb5d44e2003-12-23 08:09:43 +0000437
438 return;
439}
440
441/*
442 * Genetates checksum for LSP and its frags
443 */
hasso92365882005-01-18 13:53:33 +0000444static void
jardineb5d44e2003-12-23 08:09:43 +0000445lsp_seqnum_update (struct isis_lsp *lsp0)
446{
447 struct isis_lsp *lsp;
hasso3fdb2dd2005-09-28 18:45:54 +0000448 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000449
jardineb5d44e2003-12-23 08:09:43 +0000450 lsp_inc_seqnum (lsp0, 0);
451
452 if (!lsp0->lspu.frags)
453 return;
454
hasso3fdb2dd2005-09-28 18:45:54 +0000455 for (ALL_LIST_ELEMENTS_RO (lsp0->lspu.frags, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +0000456 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000457
jardineb5d44e2003-12-23 08:09:43 +0000458 return;
459}
460
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700461static u_int8_t
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700462lsp_bits_generate (int level, int overload_bit, int attached_bit)
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700463{
464 u_int8_t lsp_bits = 0;
465 if (level == IS_LEVEL_1)
466 lsp_bits = IS_LEVEL_1;
467 else
468 lsp_bits = IS_LEVEL_1_AND_2;
469 if (overload_bit)
470 lsp_bits |= overload_bit;
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700471 if (attached_bit)
472 lsp_bits |= attached_bit;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700473 return lsp_bits;
474}
475
hasso92365882005-01-18 13:53:33 +0000476static void
hassof390d2c2004-09-10 20:48:21 +0000477lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
Josh Bailey3f045a02012-03-24 08:35:20 -0700478 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000479{
hassof390d2c2004-09-10 20:48:21 +0000480 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000481 int retval;
hassof390d2c2004-09-10 20:48:21 +0000482
Josh Bailey3f045a02012-03-24 08:35:20 -0700483 /* free the old lsp data */
484 lsp_clear_data (lsp);
485
jardineb5d44e2003-12-23 08:09:43 +0000486 /* copying only the relevant part of our stream */
Josh Bailey3f045a02012-03-24 08:35:20 -0700487 if (lsp->pdu != NULL)
488 stream_free (lsp->pdu);
paul15935e92005-05-03 09:27:23 +0000489 lsp->pdu = stream_dup (stream);
Josh Bailey3f045a02012-03-24 08:35:20 -0700490
jardineb5d44e2003-12-23 08:09:43 +0000491 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000492 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
493 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
494 ISIS_FIXED_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -0700495 lsp->area = area;
496 lsp->level = level;
jardineb5d44e2003-12-23 08:09:43 +0000497 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000498 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000499 /*
500 * Get LSP data i.e. TLVs
501 */
502 expected |= TLVFLAG_AUTH_INFO;
503 expected |= TLVFLAG_AREA_ADDRS;
504 expected |= TLVFLAG_IS_NEIGHS;
jardineb5d44e2003-12-23 08:09:43 +0000505 expected |= TLVFLAG_NLPID;
506 if (area->dynhostname)
507 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000508 if (area->newmetric)
509 {
510 expected |= TLVFLAG_TE_IS_NEIGHS;
511 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
512 expected |= TLVFLAG_TE_ROUTER_ID;
513 }
jardineb5d44e2003-12-23 08:09:43 +0000514 expected |= TLVFLAG_IPV4_ADDR;
515 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
516 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
517#ifdef HAVE_IPV6
518 expected |= TLVFLAG_IPV6_ADDR;
519 expected |= TLVFLAG_IPV6_REACHABILITY;
520#endif /* HAVE_IPV6 */
521
Josh Bailey3f045a02012-03-24 08:35:20 -0700522 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
523 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
524 ntohs (lsp->lsp_header->pdu_len) -
525 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
526 &expected, &found, &lsp->tlv_data,
527 NULL);
528 if (retval != ISIS_OK)
hassof390d2c2004-09-10 20:48:21 +0000529 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700530 zlog_warn ("Could not parse LSP");
531 return;
532 }
533
534 if ((found & TLVFLAG_DYN_HOSTNAME) && (area->dynhostname))
535 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700536 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
537 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
538 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : IS_LEVEL_1);
hassof390d2c2004-09-10 20:48:21 +0000539 }
jardineb5d44e2003-12-23 08:09:43 +0000540
Josh Bailey3f045a02012-03-24 08:35:20 -0700541 return;
jardineb5d44e2003-12-23 08:09:43 +0000542}
543
544void
Josh Bailey3f045a02012-03-24 08:35:20 -0700545lsp_update (struct isis_lsp *lsp, struct stream *stream,
546 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000547{
hasso4eda93a2005-09-18 17:51:02 +0000548 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000549
Josh Bailey3f045a02012-03-24 08:35:20 -0700550 /* Remove old LSP from database. This is required since the
551 * lsp_update_data will free the lsp->pdu (which has the key, lsp_id)
552 * and will update it with the new data in the stream. */
hasso4eda93a2005-09-18 17:51:02 +0000553 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
554 if (dnode)
555 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000556
jardineb5d44e2003-12-23 08:09:43 +0000557 /* rebuild the lsp data */
Josh Bailey3f045a02012-03-24 08:35:20 -0700558 lsp_update_data (lsp, stream, area, level);
jardineb5d44e2003-12-23 08:09:43 +0000559
Josh Bailey3f045a02012-03-24 08:35:20 -0700560 /* insert the lsp back into the database */
561 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000562}
563
jardineb5d44e2003-12-23 08:09:43 +0000564/* creation of LSP directly from what we received */
565struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000566lsp_new_from_stream_ptr (struct stream *stream,
567 u_int16_t pdu_len, struct isis_lsp *lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -0700568 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000569{
570 struct isis_lsp *lsp;
571
hassoaac372f2005-09-01 17:52:33 +0000572 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -0700573 lsp_update_data (lsp, stream, area, level);
hassof390d2c2004-09-10 20:48:21 +0000574
575 if (lsp0 == NULL)
576 {
577 /*
578 * zero lsp -> create the list for fragments
579 */
580 lsp->lspu.frags = list_new ();
581 }
582 else
583 {
584 /*
585 * a fragment -> set the backpointer and add this to zero lsps frag list
586 */
587 lsp->lspu.zero_lsp = lsp0;
588 listnode_add (lsp0->lspu.frags, lsp);
589 }
590
jardineb5d44e2003-12-23 08:09:43 +0000591 return lsp;
592}
593
594struct isis_lsp *
Christian Frankef1fc1db2015-11-10 18:43:31 +0100595lsp_new(struct isis_area *area, u_char * lsp_id,
596 u_int16_t rem_lifetime, u_int32_t seq_num,
597 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000598{
599 struct isis_lsp *lsp;
600
hassoaac372f2005-09-01 17:52:33 +0000601 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Christian Frankef1fc1db2015-11-10 18:43:31 +0100602 lsp->area = area;
Christian Franke390f16e2015-11-10 18:04:44 +0100603
Christian Frankef1fc1db2015-11-10 18:43:31 +0100604 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
jardineb5d44e2003-12-23 08:09:43 +0000605 if (LSP_FRAGMENT (lsp_id) == 0)
606 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000607 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
608 lsp->lsp_header = (struct isis_link_state_hdr *)
609 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
610
jardineb5d44e2003-12-23 08:09:43 +0000611 /* at first we fill the FIXED HEADER */
Josh Bailey3f045a02012-03-24 08:35:20 -0700612 (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
hassof390d2c2004-09-10 20:48:21 +0000613 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
614
jardineb5d44e2003-12-23 08:09:43 +0000615 /* now for the LSP HEADER */
616 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000617 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000618 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000619 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000620 lsp->lsp_header->seq_num = htonl (seq_num);
621 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
622 lsp->lsp_header->lsp_bits = lsp_bits;
623 lsp->level = level;
624 lsp->age_out = ZERO_AGE_LIFETIME;
625
paul9985f832005-02-09 15:51:56 +0000626 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000627
hassoc89c05d2005-09-04 21:36:36 +0000628 if (isis->debugs & DEBUG_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -0700629 zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
hassoc89c05d2005-09-04 21:36:36 +0000630 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
631 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -0700632 ntohl (lsp->lsp_header->pdu_len),
hassoc89c05d2005-09-04 21:36:36 +0000633 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000634
635 return lsp;
636}
637
638void
hassof390d2c2004-09-10 20:48:21 +0000639lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000640{
641 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700642 if (lsp->lsp_header->seq_num != 0)
643 {
644 isis_spf_schedule (lsp->area, lsp->level);
645#ifdef HAVE_IPV6
646 isis_spf_schedule6 (lsp->area, lsp->level);
647#endif
648 }
jardineb5d44e2003-12-23 08:09:43 +0000649}
650
651/*
652 * Build a list of LSPs with non-zero ht bounded by start and stop ids
653 */
hassof390d2c2004-09-10 20:48:21 +0000654void
655lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
656 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000657{
658 dnode_t *first, *last, *curr;
659
660 first = dict_lower_bound (lspdb, start_id);
661 if (!first)
662 return;
hassof390d2c2004-09-10 20:48:21 +0000663
jardineb5d44e2003-12-23 08:09:43 +0000664 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000665
jardineb5d44e2003-12-23 08:09:43 +0000666 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000667
668 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000669 listnode_add (list, first->dict_data);
670
hassof390d2c2004-09-10 20:48:21 +0000671 while (curr)
672 {
673 curr = dict_next (lspdb, curr);
674 if (curr &&
675 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
676 listnode_add (list, curr->dict_data);
677 if (curr == last)
678 break;
679 }
680
jardineb5d44e2003-12-23 08:09:43 +0000681 return;
682}
683
684/*
Josh Bailey3f045a02012-03-24 08:35:20 -0700685 * Build a list of num_lsps LSPs bounded by start_id and stop_id.
jardineb5d44e2003-12-23 08:09:43 +0000686 */
hassof390d2c2004-09-10 20:48:21 +0000687void
Josh Bailey3f045a02012-03-24 08:35:20 -0700688lsp_build_list (u_char * start_id, u_char * stop_id, u_char num_lsps,
hassof390d2c2004-09-10 20:48:21 +0000689 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000690{
Josh Bailey3f045a02012-03-24 08:35:20 -0700691 u_char count;
jardineb5d44e2003-12-23 08:09:43 +0000692 dnode_t *first, *last, *curr;
693
694 first = dict_lower_bound (lspdb, start_id);
695 if (!first)
696 return;
hassof390d2c2004-09-10 20:48:21 +0000697
jardineb5d44e2003-12-23 08:09:43 +0000698 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000699
jardineb5d44e2003-12-23 08:09:43 +0000700 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000701
jardineb5d44e2003-12-23 08:09:43 +0000702 listnode_add (list, first->dict_data);
Josh Bailey3f045a02012-03-24 08:35:20 -0700703 count = 1;
jardineb5d44e2003-12-23 08:09:43 +0000704
hassof390d2c2004-09-10 20:48:21 +0000705 while (curr)
706 {
707 curr = dict_next (lspdb, curr);
708 if (curr)
Josh Bailey3f045a02012-03-24 08:35:20 -0700709 {
710 listnode_add (list, curr->dict_data);
711 count++;
712 }
713 if (count == num_lsps || curr == last)
714 break;
hassof390d2c2004-09-10 20:48:21 +0000715 }
716
jardineb5d44e2003-12-23 08:09:43 +0000717 return;
718}
719
720/*
721 * Build a list of LSPs with SSN flag set for the given circuit
722 */
723void
Josh Bailey3f045a02012-03-24 08:35:20 -0700724lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps,
725 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000726{
727 dnode_t *dnode, *next;
728 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -0700729 u_char count = 0;
hassof390d2c2004-09-10 20:48:21 +0000730
jardineb5d44e2003-12-23 08:09:43 +0000731 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000732 while (dnode != NULL)
733 {
734 next = dict_next (lspdb, dnode);
735 lsp = dnode_get (dnode);
736 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -0700737 {
738 listnode_add (list, lsp);
739 ++count;
740 }
741 if (count == num_lsps)
742 break;
hassof390d2c2004-09-10 20:48:21 +0000743 dnode = next;
744 }
745
jardineb5d44e2003-12-23 08:09:43 +0000746 return;
747}
748
hasso92365882005-01-18 13:53:33 +0000749static void
jardineb5d44e2003-12-23 08:09:43 +0000750lsp_set_time (struct isis_lsp *lsp)
751{
752 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000753
754 if (lsp->lsp_header->rem_lifetime == 0)
755 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700756 if (lsp->age_out > 0)
757 lsp->age_out--;
hassof390d2c2004-09-10 20:48:21 +0000758 return;
759 }
jardineb5d44e2003-12-23 08:09:43 +0000760
hassof390d2c2004-09-10 20:48:21 +0000761 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000762 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
763}
764
hasso92365882005-01-18 13:53:33 +0000765static void
hassof390d2c2004-09-10 20:48:21 +0000766lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000767{
768 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000769 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000770
771 if (dynhost)
772 dyn = dynhn_find_by_id (lsp_id);
773 else
774 dyn = NULL;
775
776 if (dyn)
Josh Bailey3f045a02012-03-24 08:35:20 -0700777 sprintf ((char *)id, "%.14s", dyn->name.name);
778 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
779 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000780 else
hassof390d2c2004-09-10 20:48:21 +0000781 memcpy (id, sysid_print (lsp_id), 15);
hassof390d2c2004-09-10 20:48:21 +0000782 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000783 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000784 LSP_FRAGMENT (lsp_id));
785 else
hassof7c43dc2004-09-26 16:24:14 +0000786 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000787}
788
hassof390d2c2004-09-10 20:48:21 +0000789/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000790const char *
hassof390d2c2004-09-10 20:48:21 +0000791lsp_bits2string (u_char * lsp_bits)
792{
793 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000794
hassof390d2c2004-09-10 20:48:21 +0000795 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000796 return " none";
797
798 /* we only focus on the default metric */
799 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000800 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000801
802 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000803 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000804
hassof390d2c2004-09-10 20:48:21 +0000805 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
806
jardineb5d44e2003-12-23 08:09:43 +0000807 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000808
hassof390d2c2004-09-10 20:48:21 +0000809 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000810}
811
812/* this function prints the lsp on show isis database */
Josh Bailey3f045a02012-03-24 08:35:20 -0700813void
814lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000815{
jardineb5d44e2003-12-23 08:09:43 +0000816 u_char LSPid[255];
Josh Bailey3f045a02012-03-24 08:35:20 -0700817 char age_out[8];
jardineb5d44e2003-12-23 08:09:43 +0000818
819 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700820 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
821 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len));
822 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
823 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
hassof390d2c2004-09-10 20:48:21 +0000824 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
Josh Bailey3f045a02012-03-24 08:35:20 -0700825 {
826 snprintf (age_out, 8, "(%u)", lsp->age_out);
827 age_out[7] = '\0';
828 vty_out (vty, "%7s ", age_out);
829 }
jardineb5d44e2003-12-23 08:09:43 +0000830 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700831 vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime));
832 vty_out (vty, "%s%s",
833 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000834}
835
Josh Bailey3f045a02012-03-24 08:35:20 -0700836void
837lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000838{
jardineb5d44e2003-12-23 08:09:43 +0000839 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000840 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000841 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000842 struct is_neigh *is_neigh;
843 struct te_is_neigh *te_is_neigh;
844 struct ipv4_reachability *ipv4_reach;
845 struct in_addr *ipv4_addr;
846 struct te_ipv4_reachability *te_ipv4_reach;
847#ifdef HAVE_IPV6
848 struct ipv6_reachability *ipv6_reach;
849 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000850 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000851#endif
852 u_char LSPid[255];
853 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000854 u_char ipv4_reach_prefix[20];
855 u_char ipv4_reach_mask[20];
856 u_char ipv4_address[20];
857
858 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700859 lsp_print (lsp, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000860
861 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000862 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000863 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000864 {
hasso1cd80842004-10-07 20:07:40 +0000865 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000866 isonet_print (area_addr->area_addr, area_addr->addr_len),
867 VTY_NEWLINE);
868 }
paul1eb8ef22005-04-07 07:30:20 +0000869
jardineb5d44e2003-12-23 08:09:43 +0000870 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000871 if (lsp->tlv_data.nlpids)
872 {
873 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
874 {
875 switch (lsp->tlv_data.nlpids->nlpids[i])
876 {
877 case NLPID_IP:
878 case NLPID_IPV6:
Josh Bailey3f045a02012-03-24 08:35:20 -0700879 vty_out (vty, " NLPID : 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000880 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
881 break;
882 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700883 vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000884 break;
885 }
886 }
887 }
jardineb5d44e2003-12-23 08:09:43 +0000888
889 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000890 if (lsp->tlv_data.hostname)
891 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700892 bzero (hostname, sizeof (hostname));
hassof390d2c2004-09-10 20:48:21 +0000893 memcpy (hostname, lsp->tlv_data.hostname->name,
894 lsp->tlv_data.hostname->namelen);
Josh Bailey3f045a02012-03-24 08:35:20 -0700895 vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000896 }
hassof390d2c2004-09-10 20:48:21 +0000897
Josh Bailey3f045a02012-03-24 08:35:20 -0700898 /* authentication tlv */
899 if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED)
900 {
901 if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5)
902 vty_out (vty, " Auth type : md5%s", VTY_NEWLINE);
903 else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT)
904 vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE);
905 }
hassof390d2c2004-09-10 20:48:21 +0000906
hasso1cd80842004-10-07 20:07:40 +0000907 /* TE router id */
908 if (lsp->tlv_data.router_id)
909 {
910 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
911 sizeof (ipv4_address));
Josh Bailey3f045a02012-03-24 08:35:20 -0700912 vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE);
hasso1cd80842004-10-07 20:07:40 +0000913 }
914
Josh Bailey3f045a02012-03-24 08:35:20 -0700915 if (lsp->tlv_data.ipv4_addrs)
916 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
917 {
918 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
919 vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE);
920 }
921
hasso1cd80842004-10-07 20:07:40 +0000922 /* for the IS neighbor tlv */
923 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000924 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000925 {
926 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700927 vty_out (vty, " Metric : %-8d IS : %s%s",
hasso1cd80842004-10-07 20:07:40 +0000928 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
929 }
hasso1cd80842004-10-07 20:07:40 +0000930
jardineb5d44e2003-12-23 08:09:43 +0000931 /* for the internal reachable tlv */
932 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000933 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
934 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000935 {
936 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
937 sizeof (ipv4_reach_prefix));
938 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
939 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700940 vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000941 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
942 ipv4_reach_mask, VTY_NEWLINE);
943 }
hasso2097cd82003-12-23 11:51:08 +0000944
945 /* for the external reachable tlv */
946 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000947 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
948 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000949 {
950 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
951 sizeof (ipv4_reach_prefix));
952 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
953 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700954 vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000955 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
956 ipv4_reach_mask, VTY_NEWLINE);
957 }
paul1eb8ef22005-04-07 07:30:20 +0000958
hasso2097cd82003-12-23 11:51:08 +0000959 /* IPv6 tlv */
960#ifdef HAVE_IPV6
961 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000962 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000963 {
964 memset (&in6, 0, sizeof (in6));
965 memcpy (in6.s6_addr, ipv6_reach->prefix,
966 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000967 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
David Lamparter6db3ef62015-03-03 09:07:43 +0100968 if ((ipv6_reach->control_info &
hassof390d2c2004-09-10 20:48:21 +0000969 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
Josh Bailey3f045a02012-03-24 08:35:20 -0700970 vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000971 ntohl (ipv6_reach->metric),
972 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000973 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700974 vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000975 ntohl (ipv6_reach->metric),
976 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000977 }
978#endif
paul1eb8ef22005-04-07 07:30:20 +0000979
hasso1cd80842004-10-07 20:07:40 +0000980 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000981 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000982 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000983 {
hassof390d2c2004-09-10 20:48:21 +0000984 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700985 vty_out (vty, " Metric : %-8d IS-Extended : %s%s",
986 GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE);
Olivier Dugeon4f593572016-04-19 19:03:05 +0200987 if (IS_MPLS_TE(isisMplsTE))
988 mpls_te_print_detail(vty, te_is_neigh);
hassof390d2c2004-09-10 20:48:21 +0000989 }
jardineb5d44e2003-12-23 08:09:43 +0000990
hasso1cd80842004-10-07 20:07:40 +0000991 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000992 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000993 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
994 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000995 {
hasso1cd80842004-10-07 20:07:40 +0000996 /* FIXME: There should be better way to output this stuff. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700997 vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000998 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000999 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
1000 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +00001001 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +00001002 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001003 vty_out (vty, "%s", VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +00001004
hassof390d2c2004-09-10 20:48:21 +00001005 return;
jardineb5d44e2003-12-23 08:09:43 +00001006}
1007
1008/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +00001009int
1010lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +00001011{
1012
hassof390d2c2004-09-10 20:48:21 +00001013 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +00001014 int lsp_count = 0;
1015
hassof390d2c2004-09-10 20:48:21 +00001016 if (detail == ISIS_UI_LEVEL_BRIEF)
1017 {
1018 while (node != NULL)
1019 {
1020 /* I think it is unnecessary, so I comment it out */
1021 /* dict_contains (lspdb, node); */
1022 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001023 lsp_print (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001024 node = next;
1025 lsp_count++;
1026 }
jardineb5d44e2003-12-23 08:09:43 +00001027 }
hassof390d2c2004-09-10 20:48:21 +00001028 else if (detail == ISIS_UI_LEVEL_DETAIL)
1029 {
1030 while (node != NULL)
1031 {
1032 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001033 lsp_print_detail (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001034 node = next;
1035 lsp_count++;
1036 }
jardineb5d44e2003-12-23 08:09:43 +00001037 }
jardineb5d44e2003-12-23 08:09:43 +00001038
1039 return lsp_count;
1040}
1041
jardineb5d44e2003-12-23 08:09:43 +00001042#define FRAG_THOLD(S,T) \
Josh Bailey3f045a02012-03-24 08:35:20 -07001043 ((STREAM_SIZE(S)*T)/100)
jardineb5d44e2003-12-23 08:09:43 +00001044
1045/* stream*, area->lsp_frag_threshold, increment */
1046#define FRAG_NEEDED(S,T,I) \
1047 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1048
hassoaa4376e2005-09-26 17:39:48 +00001049/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
1050 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +00001051static void
jardineb5d44e2003-12-23 08:09:43 +00001052lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001053 int tlvsize, int frag_thold,
1054 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001055{
1056 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001057
jardineb5d44e2003-12-23 08:09:43 +00001058 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001059 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1060 {
1061 tlv_build_func (*from, lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07001062 if (listcount (*to) != 0)
1063 {
1064 struct listnode *node, *nextnode;
1065 void *elem;
1066
1067 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1068 {
1069 listnode_add (*to, elem);
1070 list_delete_node (*from, node);
1071 }
1072 }
1073 else
1074 {
1075 list_free (*to);
1076 *to = *from;
1077 *from = NULL;
1078 }
jardineb5d44e2003-12-23 08:09:43 +00001079 }
hassof390d2c2004-09-10 20:48:21 +00001080 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1081 {
1082 /* fit all we can */
1083 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1084 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
Josh Bailey3f045a02012-03-24 08:35:20 -07001085 count = count / tlvsize;
1086 if (count > (int)listcount (*from))
1087 count = listcount (*from);
hassof390d2c2004-09-10 20:48:21 +00001088 for (i = 0; i < count; i++)
1089 {
paul1eb8ef22005-04-07 07:30:20 +00001090 listnode_add (*to, listgetdata (listhead (*from)));
1091 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001092 }
1093 tlv_build_func (*to, lsp->pdu);
1094 }
paul9985f832005-02-09 15:51:56 +00001095 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001096 return;
1097}
1098
Olivier Dugeon4f593572016-04-19 19:03:05 +02001099/* Process IS_NEIGHBOURS TLV with TE subTLVs */
1100static void
1101lsp_te_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to, int frag_thold)
1102{
1103 int count, size = 0;
1104 struct listnode *node, *nextnode;
1105 struct te_is_neigh *elem;
1106
1107 /* Start computing real size of TLVs */
1108 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1109 size = size + elem->sub_tlvs_length + IS_NEIGHBOURS_LEN;
1110
1111 /* can we fit all ? */
1112 if (!FRAG_NEEDED (lsp->pdu, frag_thold, size))
1113 {
1114 tlv_add_te_is_neighs (*from, lsp->pdu);
1115 if (listcount (*to) != 0)
1116 {
1117 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1118 {
1119 listnode_add (*to, elem);
1120 list_delete_node (*from, node);
1121 }
1122 }
1123 else
1124 {
1125 list_free (*to);
1126 *to = *from;
1127 *from = NULL;
1128 }
1129 }
1130 else
1131 {
1132 /* fit all we can */
1133 /* Compute remaining place in LSP PDU */
1134 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1135 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1136 /* Determine size of TE SubTLVs */
1137 elem = (struct te_is_neigh *)listgetdata ((struct listnode *)listhead (*from));
1138 count = count - elem->sub_tlvs_length - IS_NEIGHBOURS_LEN;
1139 if (count > 0)
1140 {
1141 while (count > 0)
1142 {
1143 listnode_add (*to, listgetdata ((struct listnode *)listhead (*from)));
1144 listnode_delete (*from, listgetdata ((struct listnode *)listhead (*from)));
1145
1146 elem = (struct te_is_neigh *)listgetdata ((struct listnode *)listhead (*from));
1147 count = count - elem->sub_tlvs_length - IS_NEIGHBOURS_LEN;
1148 }
1149
1150 tlv_add_te_is_neighs (*to, lsp->pdu);
1151 }
1152 }
1153 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
1154 return;
1155}
1156
Josh Bailey3f045a02012-03-24 08:35:20 -07001157static u_int16_t
1158lsp_rem_lifetime (struct isis_area *area, int level)
1159{
1160 u_int16_t rem_lifetime;
1161
1162 /* Add jitter to configured LSP lifetime */
1163 rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1],
1164 MAX_AGE_JITTER);
1165
1166 /* No jitter if the max refresh will be less than configure gen interval */
Christian Franke9dfcca62015-11-10 18:32:11 +01001167 /* N.B. this calucation is acceptable since rem_lifetime is in [332,65535] at
1168 * this point */
Josh Bailey3f045a02012-03-24 08:35:20 -07001169 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1170 rem_lifetime = area->max_lsp_lifetime[level - 1];
1171
1172 return rem_lifetime;
1173}
1174
1175static u_int16_t
1176lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1177{
1178 struct isis_area *area = lsp->area;
1179 int level = lsp->level;
1180 u_int16_t refresh_time;
1181
1182 /* Add jitter to LSP refresh time */
1183 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1184 MAX_LSP_GEN_JITTER);
1185
1186 /* RFC 4444 : make sure the refresh time is at least less than 300
1187 * of the remaining lifetime and more than gen interval */
1188 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1189 refresh_time > (rem_lifetime - 300))
1190 refresh_time = rem_lifetime - 300;
1191
Christian Franke9dfcca62015-11-10 18:32:11 +01001192 /* In cornercases, refresh_time might be <= lsp_gen_interval, however
1193 * we accept this violation to satisfy refresh_time <= rem_lifetime - 300 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001194
1195 return refresh_time;
1196}
1197
hasso92365882005-01-18 13:53:33 +00001198static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001199lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1200 int level)
jardineb5d44e2003-12-23 08:09:43 +00001201{
1202 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001203 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1204
jardineb5d44e2003-12-23 08:09:43 +00001205 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1206 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001207 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001208 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001209 if (lsp)
1210 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001211 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001212 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001213 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001214 }
Christian Frankef1fc1db2015-11-10 18:43:31 +01001215 lsp = lsp_new (area, frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001216 lsp_bits_generate (level, area->overload_bit,
1217 area->attached_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001218 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001219 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001220 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001221 listnode_add (lsp0->lspu.frags, lsp);
1222 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001223 return lsp;
1224}
1225
Christian Frankeacf98652015-11-12 14:24:22 +01001226static void
1227lsp_build_ext_reach_ipv4(struct isis_lsp *lsp, struct isis_area *area,
1228 struct tlvs *tlv_data)
1229{
1230 struct route_table *er_table;
1231 struct route_node *rn;
1232 struct prefix_ipv4 *ipv4;
1233 struct isis_ext_info *info;
1234 struct ipv4_reachability *ipreach;
1235 struct te_ipv4_reachability *te_ipreach;
1236
1237 er_table = get_ext_reach(area, AF_INET, lsp->level);
1238 if (!er_table)
1239 return;
1240
1241 for (rn = route_top(er_table); rn; rn = route_next(rn))
1242 {
1243 if (!rn->info)
1244 continue;
1245
1246 ipv4 = (struct prefix_ipv4*)&rn->p;
1247 info = rn->info;
1248 if (area->oldmetric)
1249 {
1250 if (tlv_data->ipv4_ext_reachs == NULL)
1251 {
1252 tlv_data->ipv4_ext_reachs = list_new();
1253 tlv_data->ipv4_ext_reachs->del = free_tlv;
1254 }
1255 ipreach = XMALLOC(MTYPE_ISIS_TLV, sizeof(*ipreach));
1256
1257 ipreach->prefix.s_addr = ipv4->prefix.s_addr;
1258 masklen2ip(ipv4->prefixlen, &ipreach->mask);
1259 ipreach->prefix.s_addr &= ipreach->mask.s_addr;
1260
1261 if ((info->metric & 0x3f) != info->metric)
1262 ipreach->metrics.metric_default = 0x3f;
1263 else
1264 ipreach->metrics.metric_default = info->metric;
1265 ipreach->metrics.metric_expense = METRICS_UNSUPPORTED;
1266 ipreach->metrics.metric_error = METRICS_UNSUPPORTED;
1267 ipreach->metrics.metric_delay = METRICS_UNSUPPORTED;
1268 listnode_add(tlv_data->ipv4_ext_reachs, ipreach);
1269 }
1270 if (area->newmetric)
1271 {
1272 if (tlv_data->te_ipv4_reachs == NULL)
1273 {
1274 tlv_data->te_ipv4_reachs = list_new();
1275 tlv_data->te_ipv4_reachs->del = free_tlv;
1276 }
1277 te_ipreach =
1278 XCALLOC(MTYPE_ISIS_TLV,
1279 sizeof(*te_ipreach) - 1 + PSIZE(ipv4->prefixlen));
1280 if (info->metric > MAX_WIDE_PATH_METRIC)
1281 te_ipreach->te_metric = htonl(MAX_WIDE_PATH_METRIC);
1282 else
1283 te_ipreach->te_metric = htonl(info->metric);
1284 te_ipreach->control = ipv4->prefixlen & 0x3f;
1285 memcpy(&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1286 PSIZE(ipv4->prefixlen));
1287 listnode_add(tlv_data->te_ipv4_reachs, te_ipreach);
1288 }
1289 }
1290}
1291
1292static void
1293lsp_build_ext_reach_ipv6(struct isis_lsp *lsp, struct isis_area *area,
1294 struct tlvs *tlv_data)
1295{
1296 struct route_table *er_table;
1297 struct route_node *rn;
1298 struct prefix_ipv6 *ipv6;
1299 struct isis_ext_info *info;
1300 struct ipv6_reachability *ip6reach;
1301
1302 er_table = get_ext_reach(area, AF_INET6, lsp->level);
1303 if (!er_table)
1304 return;
1305
1306 for (rn = route_top(er_table); rn; rn = route_next(rn))
1307 {
1308 if (!rn->info)
1309 continue;
1310
1311 ipv6 = (struct prefix_ipv6*)&rn->p;
1312 info = rn->info;
1313
1314 if (tlv_data->ipv6_reachs == NULL)
1315 {
1316 tlv_data->ipv6_reachs = list_new();
1317 tlv_data->ipv6_reachs->del = free_tlv;
1318 }
1319 ip6reach = XCALLOC(MTYPE_ISIS_TLV, sizeof(*ip6reach));
1320 if (info->metric > MAX_WIDE_PATH_METRIC)
1321 ip6reach->metric = htonl(MAX_WIDE_PATH_METRIC);
1322 else
1323 ip6reach->metric = htonl(info->metric);
1324 ip6reach->control_info = DISTRIBUTION_EXTERNAL;
1325 ip6reach->prefix_len = ipv6->prefixlen;
1326 memcpy(ip6reach->prefix, ipv6->prefix.s6_addr, sizeof(ip6reach->prefix));
1327 listnode_add(tlv_data->ipv6_reachs, ip6reach);
1328 }
1329}
1330
1331static void
1332lsp_build_ext_reach (struct isis_lsp *lsp, struct isis_area *area,
1333 struct tlvs *tlv_data)
1334{
1335 lsp_build_ext_reach_ipv4(lsp, area, tlv_data);
1336 lsp_build_ext_reach_ipv6(lsp, area, tlv_data);
1337}
1338
jardineb5d44e2003-12-23 08:09:43 +00001339/*
1340 * Builds the LSP data part. This func creates a new frag whenever
1341 * area->lsp_frag_threshold is exceeded.
1342 */
hasso92365882005-01-18 13:53:33 +00001343static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001344lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001345{
1346 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001347 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001348 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001349 int level = lsp->level;
1350 struct isis_circuit *circuit;
1351 struct prefix_ipv4 *ipv4;
1352 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001353 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001354 struct isis_adjacency *nei;
1355#ifdef HAVE_IPV6
Christian Frankee28718a2015-11-10 18:33:14 +01001356 struct prefix_ipv6 *ipv6, ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001357 struct ipv6_reachability *ip6reach;
1358#endif /* HAVE_IPV6 */
1359 struct tlvs tlv_data;
1360 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001361 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001362 uint32_t expected = 0, found = 0;
1363 uint32_t metric;
1364 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1365 int retval = ISIS_OK;
Christian Franke80a8f722015-11-12 14:21:47 +01001366 char buf[BUFSIZ];
1367
1368 lsp_debug("ISIS (%s): Constructing local system LSP for level %d", area->area_tag, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001369
1370 /*
1371 * Building the zero lsp
1372 */
1373 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1374
1375 /* Reset stream endp. Stream is always there and on every LSP refresh only
1376 * TLV part of it is overwritten. So we must seek past header we will not
1377 * touch. */
1378 stream_reset (lsp->pdu);
1379 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1380
1381 /*
1382 * Add the authentication info if its present
1383 */
1384 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001385
1386 /*
1387 * First add the tlvs related to area
1388 */
hassof390d2c2004-09-10 20:48:21 +00001389
jardineb5d44e2003-12-23 08:09:43 +00001390 /* Area addresses */
1391 if (lsp->tlv_data.area_addrs == NULL)
1392 lsp->tlv_data.area_addrs = list_new ();
1393 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001394 if (listcount (lsp->tlv_data.area_addrs) > 0)
1395 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1396
jardineb5d44e2003-12-23 08:09:43 +00001397 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001398 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001399#ifdef HAVE_IPV6
1400 || area->ipv6_circuits > 0
1401#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001402 )
jardineb5d44e2003-12-23 08:09:43 +00001403 {
hassoaac372f2005-09-01 17:52:33 +00001404 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001405 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001406 if (area->ip_circuits > 0)
1407 {
Christian Franke80a8f722015-11-12 14:21:47 +01001408 lsp_debug("ISIS (%s): Found IPv4 circuit, adding IPv4 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001409 lsp->tlv_data.nlpids->count++;
1410 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1411 }
jardineb5d44e2003-12-23 08:09:43 +00001412#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001413 if (area->ipv6_circuits > 0)
1414 {
Christian Franke80a8f722015-11-12 14:21:47 +01001415 lsp_debug("ISIS (%s): Found IPv6 circuit, adding IPv6 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001416 lsp->tlv_data.nlpids->count++;
1417 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1418 NLPID_IPV6;
1419 }
jardineb5d44e2003-12-23 08:09:43 +00001420#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001421 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001422 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001423
jardineb5d44e2003-12-23 08:09:43 +00001424 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001425 if (area->dynhostname)
1426 {
Christian Frankef35169e2015-11-12 14:09:08 +01001427 const char *hostname = unix_hostname();
1428 size_t hostname_len = strlen(hostname);
1429
hassof390d2c2004-09-10 20:48:21 +00001430 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1431 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001432
Christian Frankef35169e2015-11-12 14:09:08 +01001433 strncpy((char *)lsp->tlv_data.hostname->name, hostname,
1434 sizeof(lsp->tlv_data.hostname->name));
1435 if (hostname_len <= MAX_TLV_LEN)
1436 lsp->tlv_data.hostname->namelen = hostname_len;
1437 else
1438 lsp->tlv_data.hostname->namelen = MAX_TLV_LEN;
1439
Christian Franke80a8f722015-11-12 14:21:47 +01001440 lsp_debug("ISIS (%s): Adding dynamic hostname '%.*s'", area->area_tag,
1441 lsp->tlv_data.hostname->namelen, lsp->tlv_data.hostname->name);
Josh Bailey3f045a02012-03-24 08:35:20 -07001442 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001443 }
Christian Franke80a8f722015-11-12 14:21:47 +01001444 else
1445 {
1446 lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)", area->area_tag);
1447 }
jardineb5d44e2003-12-23 08:09:43 +00001448
hasso81ad8f62005-09-26 17:58:24 +00001449 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1450 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1451 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001452 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001453 {
Christian Franke80a8f722015-11-12 14:21:47 +01001454 inet_ntop(AF_INET, &isis->router_id, buf, sizeof(buf));
1455 lsp_debug("ISIS (%s): Adding router ID %s as IPv4 tlv.", area->area_tag, buf);
hasso18a6dce2004-10-03 18:18:34 +00001456 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001457 {
1458 lsp->tlv_data.ipv4_addrs = list_new ();
1459 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1460 }
hasso18a6dce2004-10-03 18:18:34 +00001461
1462 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001463 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001464 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001465 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001466
hasso81ad8f62005-09-26 17:58:24 +00001467 /* Exactly same data is put into TE router ID TLV, but only if new style
1468 * TLV's are in use. */
1469 if (area->newmetric)
1470 {
Christian Franke80a8f722015-11-12 14:21:47 +01001471 lsp_debug("ISIS (%s): Adding router ID also as TE router ID tlv.", area->area_tag);
hasso81ad8f62005-09-26 17:58:24 +00001472 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1473 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001474 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1475 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1476 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001477 }
hasso18a6dce2004-10-03 18:18:34 +00001478 }
Christian Franke80a8f722015-11-12 14:21:47 +01001479 else
1480 {
1481 lsp_debug("ISIS (%s): Router ID is unset. Not adding tlv.", area->area_tag);
1482 }
hassof1082d12005-09-19 04:23:34 +00001483
hasso81ad8f62005-09-26 17:58:24 +00001484 memset (&tlv_data, 0, sizeof (struct tlvs));
1485
hassof1082d12005-09-19 04:23:34 +00001486#ifdef TOPOLOGY_GENERATE
1487 /* If topology exists (and we create topology for level 1 only), create
1488 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001489 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001490 {
1491 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001492 {
1493 tlv_data.is_neighs = list_new ();
1494 tlv_data.is_neighs->del = free_tlv;
1495 }
hasso3fdb2dd2005-09-28 18:45:54 +00001496 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001497
1498 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1499 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1500 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1501 is_neigh->metrics.metric_default = 0x01;
1502 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1503 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1504 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1505 listnode_add (tlv_data.is_neighs, is_neigh);
1506 }
1507#endif /* TOPOLOGY_GENERATE */
1508
Christian Franke80a8f722015-11-12 14:21:47 +01001509 lsp_debug("ISIS (%s): Adding circuit specific information.", area->area_tag);
1510
hasso18a6dce2004-10-03 18:18:34 +00001511 /*
jardineb5d44e2003-12-23 08:09:43 +00001512 * Then build lists of tlvs related to circuits
1513 */
hasso3fdb2dd2005-09-28 18:45:54 +00001514 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001515 {
Christian Franke80a8f722015-11-12 14:21:47 +01001516 if (!circuit->interface)
1517 lsp_debug("ISIS (%s): Processing %s circuit %p with unknown interface",
1518 area->area_tag, circuit_type2string(circuit->circ_type), circuit);
1519 else
1520 lsp_debug("ISIS (%s): Processing %s circuit %s",
1521 area->area_tag, circuit_type2string(circuit->circ_type), circuit->interface->name);
1522
hassof390d2c2004-09-10 20:48:21 +00001523 if (circuit->state != C_STATE_UP)
Christian Franke80a8f722015-11-12 14:21:47 +01001524 {
1525 lsp_debug("ISIS (%s): Circuit is not up, ignoring.", area->area_tag);
1526 continue;
1527 }
jardineb5d44e2003-12-23 08:09:43 +00001528
hassof390d2c2004-09-10 20:48:21 +00001529 /*
1530 * Add IPv4 internal reachability of this circuit
1531 */
1532 if (circuit->ip_router && circuit->ip_addrs &&
1533 circuit->ip_addrs->count > 0)
1534 {
Christian Franke80a8f722015-11-12 14:21:47 +01001535 lsp_debug("ISIS (%s): Circuit has IPv4 active, adding respective TLVs.", area->area_tag);
hassoaa4376e2005-09-26 17:39:48 +00001536 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001537 {
hassoaa4376e2005-09-26 17:39:48 +00001538 if (tlv_data.ipv4_int_reachs == NULL)
1539 {
1540 tlv_data.ipv4_int_reachs = list_new ();
1541 tlv_data.ipv4_int_reachs->del = free_tlv;
1542 }
hasso3fdb2dd2005-09-28 18:45:54 +00001543 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001544 {
1545 ipreach =
1546 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1547 ipreach->metrics = circuit->metrics[level - 1];
1548 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1549 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1550 (ipv4->prefix.s_addr));
Christian Franke80a8f722015-11-12 14:21:47 +01001551 inet_ntop(AF_INET, &ipreach->prefix.s_addr, buf, sizeof(buf));
1552 lsp_debug("ISIS (%s): Adding old-style IP reachability for %s/%d",
1553 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001554 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1555 }
hassof390d2c2004-09-10 20:48:21 +00001556 }
hassoaa4376e2005-09-26 17:39:48 +00001557 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001558 {
hassoaa4376e2005-09-26 17:39:48 +00001559 if (tlv_data.te_ipv4_reachs == NULL)
1560 {
1561 tlv_data.te_ipv4_reachs = list_new ();
1562 tlv_data.te_ipv4_reachs->del = free_tlv;
1563 }
hasso3fdb2dd2005-09-28 18:45:54 +00001564 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001565 {
1566 /* FIXME All this assumes that we have no sub TLVs. */
1567 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1568 sizeof (struct te_ipv4_reachability) +
1569 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001570
1571 if (area->oldmetric)
1572 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1573 else
1574 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1575
hassoaa4376e2005-09-26 17:39:48 +00001576 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1577 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1578 (ipv4->prefixlen + 7)/8);
Christian Franke80a8f722015-11-12 14:21:47 +01001579 inet_ntop(AF_INET, &ipv4->prefix.s_addr, buf, sizeof(buf));
1580 lsp_debug("ISIS (%s): Adding te-style IP reachability for %s/%d",
1581 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001582 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1583 }
hassof390d2c2004-09-10 20:48:21 +00001584 }
hassof390d2c2004-09-10 20:48:21 +00001585 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001586
jardineb5d44e2003-12-23 08:09:43 +00001587#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001588 /*
1589 * Add IPv6 reachability of this circuit
1590 */
1591 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1592 circuit->ipv6_non_link->count > 0)
1593 {
1594
1595 if (tlv_data.ipv6_reachs == NULL)
1596 {
1597 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001598 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001599 }
hasso3fdb2dd2005-09-28 18:45:54 +00001600 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001601 {
hassof390d2c2004-09-10 20:48:21 +00001602 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001603 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001604
1605 if (area->oldmetric)
1606 ip6reach->metric =
1607 htonl (circuit->metrics[level - 1].metric_default);
1608 else
1609 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1610
hassof390d2c2004-09-10 20:48:21 +00001611 ip6reach->control_info = 0;
1612 ip6reach->prefix_len = ipv6->prefixlen;
Christian Frankee28718a2015-11-10 18:33:14 +01001613 memcpy(&ip6prefix, ipv6, sizeof(ip6prefix));
1614 apply_mask_ipv6(&ip6prefix);
Christian Franke80a8f722015-11-12 14:21:47 +01001615
Christian Frankee28718a2015-11-10 18:33:14 +01001616 inet_ntop(AF_INET6, &ip6prefix.prefix.s6_addr, buf, sizeof(buf));
Christian Franke80a8f722015-11-12 14:21:47 +01001617 lsp_debug("ISIS (%s): Adding IPv6 reachability for %s/%d",
1618 area->area_tag, buf, ipv6->prefixlen);
1619
Christian Frankee28718a2015-11-10 18:33:14 +01001620 memcpy (ip6reach->prefix, ip6prefix.prefix.s6_addr,
hasso67851572004-09-21 14:17:04 +00001621 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001622 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1623 }
1624 }
1625#endif /* HAVE_IPV6 */
1626
1627 switch (circuit->circ_type)
1628 {
1629 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001630 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001631 {
hassoaa4376e2005-09-26 17:39:48 +00001632 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001633 {
hassoaa4376e2005-09-26 17:39:48 +00001634 if (tlv_data.is_neighs == NULL)
1635 {
1636 tlv_data.is_neighs = list_new ();
1637 tlv_data.is_neighs->del = free_tlv;
1638 }
1639 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001640 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001641 memcpy (is_neigh->neigh_id,
1642 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1643 else
1644 memcpy (is_neigh->neigh_id,
1645 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1646 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001647 if (!memcmp (is_neigh->neigh_id, zero_id,
1648 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001649 {
1650 XFREE (MTYPE_ISIS_TLV, is_neigh);
1651 lsp_debug("ISIS (%s): No DIS for circuit, not adding old-style IS neighbor.",
1652 area->area_tag);
1653 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001654 else
Christian Franke80a8f722015-11-12 14:21:47 +01001655 {
1656 listnode_add (tlv_data.is_neighs, is_neigh);
1657 lsp_debug("ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
1658 area->area_tag, sysid_print(is_neigh->neigh_id),
1659 LSP_PSEUDO_ID(is_neigh->neigh_id));
1660 }
hassof390d2c2004-09-10 20:48:21 +00001661 }
hassoaa4376e2005-09-26 17:39:48 +00001662 if (area->newmetric)
1663 {
hassoaa4376e2005-09-26 17:39:48 +00001664 if (tlv_data.te_is_neighs == NULL)
1665 {
1666 tlv_data.te_is_neighs = list_new ();
1667 tlv_data.te_is_neighs->del = free_tlv;
1668 }
1669 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1670 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001671 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001672 memcpy (te_is_neigh->neigh_id,
1673 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1674 else
1675 memcpy (te_is_neigh->neigh_id,
1676 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001677 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001678 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001679 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001680 metric = circuit->te_metric[level - 1];
1681 SET_TE_METRIC(te_is_neigh, metric);
1682 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1683 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001684 {
1685 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1686 lsp_debug("ISIS (%s): No DIS for circuit, not adding te-style IS neighbor.",
1687 area->area_tag);
1688 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001689 else
Christian Franke80a8f722015-11-12 14:21:47 +01001690 {
Olivier Dugeon4f593572016-04-19 19:03:05 +02001691 /* Check if MPLS_TE is activate */
1692 if (IS_MPLS_TE(isisMplsTE) && HAS_LINK_PARAMS(circuit->interface))
1693 /* Add SubTLVs & Adjust real size of SubTLVs */
1694 te_is_neigh->sub_tlvs_length = add_te_subtlvs(te_is_neigh->sub_tlvs, circuit->mtc);
1695 else
1696 /* Or keep only TE metric with no SubTLVs if MPLS_TE is off */
1697 te_is_neigh->sub_tlvs_length = 0;
1698
Christian Franke80a8f722015-11-12 14:21:47 +01001699 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1700 lsp_debug("ISIS (%s): Adding DIS %s.%02x as te-style neighbor",
1701 area->area_tag, sysid_print(te_is_neigh->neigh_id),
1702 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
1703 }
hassoaa4376e2005-09-26 17:39:48 +00001704 }
hassof390d2c2004-09-10 20:48:21 +00001705 }
Christian Franke80a8f722015-11-12 14:21:47 +01001706 else
1707 {
1708 lsp_debug("ISIS (%s): Circuit is not active for current level. Not adding IS neighbors",
1709 area->area_tag);
1710 }
hassof390d2c2004-09-10 20:48:21 +00001711 break;
1712 case CIRCUIT_T_P2P:
1713 nei = circuit->u.p2p.neighbor;
1714 if (nei && (level & nei->circuit_t))
1715 {
hassoaa4376e2005-09-26 17:39:48 +00001716 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001717 {
hassoaa4376e2005-09-26 17:39:48 +00001718 if (tlv_data.is_neighs == NULL)
1719 {
1720 tlv_data.is_neighs = list_new ();
1721 tlv_data.is_neighs->del = free_tlv;
1722 }
1723 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1724 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1725 is_neigh->metrics = circuit->metrics[level - 1];
1726 listnode_add (tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001727 lsp_debug("ISIS (%s): Adding old-style is reach for %s", area->area_tag,
1728 sysid_print(is_neigh->neigh_id));
hassof390d2c2004-09-10 20:48:21 +00001729 }
hassoaa4376e2005-09-26 17:39:48 +00001730 if (area->newmetric)
1731 {
1732 uint32_t metric;
1733
1734 if (tlv_data.te_is_neighs == NULL)
1735 {
1736 tlv_data.te_is_neighs = list_new ();
1737 tlv_data.te_is_neighs->del = free_tlv;
1738 }
1739 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1740 sizeof (struct te_is_neigh));
1741 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001742 metric = circuit->te_metric[level - 1];
1743 SET_TE_METRIC(te_is_neigh, metric);
Olivier Dugeon4f593572016-04-19 19:03:05 +02001744 /* Check if MPLS_TE is activate */
1745 if (IS_MPLS_TE(isisMplsTE) && HAS_LINK_PARAMS(circuit->interface))
1746 /* Update Local and Remote IP address for MPLS TE circuit parameters */
1747 /* NOTE sure that it is the pertinent place for that updates */
1748 /* Local IP address could be updated in isis_circuit.c - isis_circuit_add_addr() */
1749 /* But, where update remote IP address ? in isis_pdu.c - process_p2p_hello() ? */
1750
1751 /* Add SubTLVs & Adjust real size of SubTLVs */
1752 te_is_neigh->sub_tlvs_length = add_te_subtlvs(te_is_neigh->sub_tlvs, circuit->mtc);
1753 else
1754 /* Or keep only TE metric with no SubTLVs if MPLS_TE is off */
1755 te_is_neigh->sub_tlvs_length = 0;
hassoaa4376e2005-09-26 17:39:48 +00001756 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001757 lsp_debug("ISIS (%s): Adding te-style is reach for %s", area->area_tag,
1758 sysid_print(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001759 }
hassof390d2c2004-09-10 20:48:21 +00001760 }
Christian Franke80a8f722015-11-12 14:21:47 +01001761 else
1762 {
1763 lsp_debug("ISIS (%s): No adjacency for given level on this circuit. Not adding IS neighbors",
1764 area->area_tag);
1765 }
hassof390d2c2004-09-10 20:48:21 +00001766 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001767 case CIRCUIT_T_LOOPBACK:
1768 break;
hassof390d2c2004-09-10 20:48:21 +00001769 default:
1770 zlog_warn ("lsp_area_create: unknown circuit type");
1771 }
1772 }
1773
Christian Frankeacf98652015-11-12 14:24:22 +01001774 lsp_build_ext_reach(lsp, area, &tlv_data);
1775
Christian Franke80a8f722015-11-12 14:21:47 +01001776 lsp_debug("ISIS (%s): LSP construction is complete. Serializing...", area->area_tag);
1777
hassof390d2c2004-09-10 20:48:21 +00001778 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1779 {
1780 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1781 lsp->tlv_data.ipv4_int_reachs = list_new ();
1782 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1783 &lsp->tlv_data.ipv4_int_reachs,
1784 IPV4_REACH_LEN, area->lsp_frag_threshold,
Christian Frankeacf98652015-11-12 14:24:22 +01001785 tlv_add_ipv4_int_reachs);
hassof390d2c2004-09-10 20:48:21 +00001786 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1787 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1788 lsp0, area, level);
1789 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001790
Christian Frankeacf98652015-11-12 14:24:22 +01001791 while (tlv_data.ipv4_ext_reachs && listcount (tlv_data.ipv4_ext_reachs))
1792 {
1793 if (lsp->tlv_data.ipv4_ext_reachs == NULL)
1794 lsp->tlv_data.ipv4_ext_reachs = list_new ();
1795 lsp_tlv_fit (lsp, &tlv_data.ipv4_ext_reachs,
1796 &lsp->tlv_data.ipv4_ext_reachs,
1797 IPV4_REACH_LEN, area->lsp_frag_threshold,
1798 tlv_add_ipv4_ext_reachs);
1799 if (tlv_data.ipv4_ext_reachs && listcount (tlv_data.ipv4_ext_reachs))
1800 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1801 lsp0, area, level);
1802 }
1803
hassoaa4376e2005-09-26 17:39:48 +00001804 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1805 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1806 * TLVs (sub TLVs!). */
1807 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1808 {
1809 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1810 lsp->tlv_data.te_ipv4_reachs = list_new ();
1811 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1812 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001813 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1814 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001815 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1816 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1817 lsp0, area, level);
1818 }
hassof390d2c2004-09-10 20:48:21 +00001819
1820#ifdef HAVE_IPV6
1821 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1822 {
1823 if (lsp->tlv_data.ipv6_reachs == NULL)
1824 lsp->tlv_data.ipv6_reachs = list_new ();
1825 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1826 &lsp->tlv_data.ipv6_reachs,
1827 IPV6_REACH_LEN, area->lsp_frag_threshold,
1828 tlv_add_ipv6_reachs);
1829 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1830 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1831 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001832 }
1833#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001834
1835 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1836 {
1837 if (lsp->tlv_data.is_neighs == NULL)
1838 lsp->tlv_data.is_neighs = list_new ();
1839 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1840 &lsp->tlv_data.is_neighs,
1841 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1842 tlv_add_is_neighs);
1843 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1844 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1845 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001846 }
jardineb5d44e2003-12-23 08:09:43 +00001847
hassoaa4376e2005-09-26 17:39:48 +00001848 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1849 {
1850 if (lsp->tlv_data.te_is_neighs == NULL)
1851 lsp->tlv_data.te_is_neighs = list_new ();
1852 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1853 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1854 tlv_add_te_is_neighs);
1855 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1856 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1857 lsp0, area, level);
1858 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001859 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001860
1861 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001862
1863 /* Validate the LSP */
1864 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1865 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1866 stream_get_endp (lsp->pdu) -
1867 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1868 &expected, &found, &tlv_data, NULL);
1869 assert (retval == ISIS_OK);
1870
jardineb5d44e2003-12-23 08:09:43 +00001871 return;
1872}
jardineb5d44e2003-12-23 08:09:43 +00001873
1874/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001875 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001876 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001877int
1878lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001879{
jardineb5d44e2003-12-23 08:09:43 +00001880 struct isis_lsp *oldlsp, *newlsp;
1881 u_int32_t seq_num = 0;
1882 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001883 u_int16_t rem_lifetime, refresh_time;
1884
1885 if ((area == NULL) || (area->is_type & level) != level)
1886 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001887
1888 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1889 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1890
1891 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001892 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1893 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001894 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001895 /* FIXME: we should actually initiate a purge */
1896 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1897 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1898 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001899 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001900 rem_lifetime = lsp_rem_lifetime (area, level);
Christian Frankef1fc1db2015-11-10 18:43:31 +01001901 newlsp = lsp_new (area, lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001902 area->is_type | area->overload_bit | area->attached_bit,
1903 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001904 newlsp->area = area;
1905 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001906
Josh Bailey3f045a02012-03-24 08:35:20 -07001907 lsp_insert (newlsp, area->lspdb[level - 1]);
1908 /* build_lsp_data (newlsp, area); */
1909 lsp_build (newlsp, area);
1910 /* time to calculate our checksum */
1911 lsp_seqnum_update (newlsp);
Christian Franke61010c32015-11-10 18:43:34 +01001912 newlsp->last_generated = time(NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001913 lsp_set_all_srmflags (newlsp);
1914
1915 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
Christian Franke61010c32015-11-10 18:43:34 +01001916
Josh Bailey3f045a02012-03-24 08:35:20 -07001917 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
Christian Franke61010c32015-11-10 18:43:34 +01001918 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001919 if (level == IS_LEVEL_1)
1920 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1921 lsp_l1_refresh, area, refresh_time);
1922 else if (level == IS_LEVEL_2)
1923 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1924 lsp_l2_refresh, area, refresh_time);
1925
1926 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001927 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001928 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1929 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1930 area->area_tag, level,
1931 rawlspid_print (newlsp->lsp_header->lsp_id),
1932 ntohl (newlsp->lsp_header->pdu_len),
1933 ntohl (newlsp->lsp_header->seq_num),
1934 ntohs (newlsp->lsp_header->checksum),
1935 ntohs (newlsp->lsp_header->rem_lifetime),
1936 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001937 }
Christian Franke61010c32015-11-10 18:43:34 +01001938 sched_debug("ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
1939 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001940
1941 return ISIS_OK;
1942}
1943
1944/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001945 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001946 */
hasso92365882005-01-18 13:53:33 +00001947static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001948lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001949{
David Lampartere8aca322012-11-27 01:10:30 +00001950 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001951 struct isis_lsp *lsp, *frag;
1952 struct listnode *node;
1953 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001954 u_int16_t rem_lifetime, refresh_time;
1955
1956 if ((area == NULL) || (area->is_type & level) != level)
1957 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001958
David Lampartere8aca322012-11-27 01:10:30 +00001959 lspdb = area->lspdb[level - 1];
1960
jardineb5d44e2003-12-23 08:09:43 +00001961 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1962 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001963
jardineb5d44e2003-12-23 08:09:43 +00001964 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001965
hassof390d2c2004-09-10 20:48:21 +00001966 if (!lsp)
1967 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001968 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1969 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001970 return ISIS_ERROR;
1971 }
1972
1973 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001974 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001975 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1976 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001977 rem_lifetime = lsp_rem_lifetime (area, level);
1978 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001979 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001980
Josh Bailey3f045a02012-03-24 08:35:20 -07001981 lsp->last_generated = time (NULL);
1982 lsp_set_all_srmflags (lsp);
1983 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1984 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001985 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001986 area->overload_bit,
1987 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001988 /* Set the lifetime values of all the fragments to the same value,
1989 * so that no fragment expires before the lsp is refreshed.
1990 */
1991 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1992 lsp_set_all_srmflags (frag);
1993 }
1994
1995 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1996 if (level == IS_LEVEL_1)
1997 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1998 lsp_l1_refresh, area, refresh_time);
1999 else if (level == IS_LEVEL_2)
2000 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
2001 lsp_l2_refresh, area, refresh_time);
Christian Franke61010c32015-11-10 18:43:34 +01002002 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002003
hassof390d2c2004-09-10 20:48:21 +00002004 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2005 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002006 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
2007 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
2008 area->area_tag, level,
2009 rawlspid_print (lsp->lsp_header->lsp_id),
2010 ntohl (lsp->lsp_header->pdu_len),
2011 ntohl (lsp->lsp_header->seq_num),
2012 ntohs (lsp->lsp_header->checksum),
2013 ntohs (lsp->lsp_header->rem_lifetime),
2014 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002015 }
Christian Franke61010c32015-11-10 18:43:34 +01002016 sched_debug("ISIS (%s): Rebuilt L%d LSP. Set triggered regenerate to non-pending.",
2017 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00002018
jardineb5d44e2003-12-23 08:09:43 +00002019 return ISIS_OK;
2020}
2021
jardineb5d44e2003-12-23 08:09:43 +00002022/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002023 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00002024 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002025static int
2026lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00002027{
2028 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00002029
2030 area = THREAD_ARG (thread);
2031 assert (area);
hassof390d2c2004-09-10 20:48:21 +00002032
jardineb5d44e2003-12-23 08:09:43 +00002033 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002034 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00002035
Josh Bailey3f045a02012-03-24 08:35:20 -07002036 if ((area->is_type & IS_LEVEL_1) == 0)
2037 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00002038
Christian Franke61010c32015-11-10 18:43:34 +01002039 sched_debug("ISIS (%s): LSP L1 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07002040 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002041}
2042
Josh Bailey3f045a02012-03-24 08:35:20 -07002043static int
2044lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00002045{
2046 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00002047
2048 area = THREAD_ARG (thread);
2049 assert (area);
hassof390d2c2004-09-10 20:48:21 +00002050
jardineb5d44e2003-12-23 08:09:43 +00002051 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002052 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00002053
Josh Bailey3f045a02012-03-24 08:35:20 -07002054 if ((area->is_type & IS_LEVEL_2) == 0)
2055 return ISIS_ERROR;
2056
Christian Franke61010c32015-11-10 18:43:34 +01002057 sched_debug("ISIS (%s): LSP L2 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07002058 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002059}
2060
hassof390d2c2004-09-10 20:48:21 +00002061int
Josh Bailey3f045a02012-03-24 08:35:20 -07002062lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00002063{
2064 struct isis_lsp *lsp;
2065 u_char id[ISIS_SYS_ID_LEN + 2];
2066 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01002067 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07002068 struct listnode *cnode;
2069 struct isis_circuit *circuit;
2070 int lvl;
2071
2072 if (area == NULL)
2073 return ISIS_ERROR;
2074
Christian Franke61010c32015-11-10 18:43:34 +01002075 sched_debug("ISIS (%s): Scheduling regeneration of %s LSPs, %sincluding PSNs",
2076 area->area_tag, circuit_t2string(level), all_pseudo ? "" : "not ");
2077
hassof390d2c2004-09-10 20:48:21 +00002078 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2079 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00002080 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07002081
2082 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00002083 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002084 if (!((level & lvl) && (area->is_type & lvl)))
2085 continue;
2086
Christian Franke61010c32015-11-10 18:43:34 +01002087 sched_debug("ISIS (%s): Checking whether L%d needs to be scheduled",
2088 area->area_tag, lvl);
2089
Josh Bailey3f045a02012-03-24 08:35:20 -07002090 if (area->lsp_regenerate_pending[lvl - 1])
Christian Franke61010c32015-11-10 18:43:34 +01002091 {
2092 struct timeval remain = thread_timer_remain(area->t_lsp_refresh[lvl - 1]);
2093 sched_debug("ISIS (%s): Regeneration is already pending, nothing todo."
2094 " (Due in %lld.%03lld seconds)", area->area_tag,
2095 (long long)remain.tv_sec, (long long)remain.tv_usec / 1000);
2096 continue;
2097 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002098
2099 lsp = lsp_search (id, area->lspdb[lvl - 1]);
2100 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002101 {
2102 sched_debug("ISIS (%s): We do not have any LSPs to regenerate, nothing todo.",
2103 area->area_tag);
2104 continue;
2105 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002106
hassof390d2c2004-09-10 20:48:21 +00002107 /*
2108 * Throttle avoidance
2109 */
Christian Franke61010c32015-11-10 18:43:34 +01002110 sched_debug("ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
2111 area->area_tag, (long long)lsp->last_generated, (long long)now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002112 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00002113 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07002114 if (diff < area->lsp_gen_interval[lvl - 1])
2115 {
Christian Franke61010c32015-11-10 18:43:34 +01002116 timeout = 1000 * (area->lsp_gen_interval[lvl - 1] - diff);
2117 sched_debug("ISIS (%s): Scheduling in %ld ms to match configured lsp_gen_interval",
2118 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002119 }
hassof390d2c2004-09-10 20:48:21 +00002120 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002121 {
Michael Zinggbe62b172012-10-26 11:18:19 +02002122 /*
2123 * lsps are not regenerated if lsp_regenerate function is called
2124 * directly. However if the lsp_regenerate call is queued for
2125 * later execution it works.
2126 */
Christian Franke61010c32015-11-10 18:43:34 +01002127 timeout = 100;
2128 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2129 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2130 }
2131
2132 area->lsp_regenerate_pending[lvl - 1] = 1;
2133 if (lvl == IS_LEVEL_1)
2134 {
2135 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
2136 lsp_l1_refresh, area, timeout);
2137 }
2138 else if (lvl == IS_LEVEL_2)
2139 {
2140 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
2141 lsp_l2_refresh, area, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002142 }
hassof390d2c2004-09-10 20:48:21 +00002143 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002144
2145 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00002146 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002147 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
2148 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00002149 }
2150
2151 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002152}
2153
2154/*
2155 * Funcs for pseudonode LSPs
2156 */
2157
2158/*
2159 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
2160 */
hasso92365882005-01-18 13:53:33 +00002161static void
hassof390d2c2004-09-10 20:48:21 +00002162lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
2163 int level)
jardineb5d44e2003-12-23 08:09:43 +00002164{
2165 struct isis_adjacency *adj;
2166 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00002167 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002168 struct es_neigh *es_neigh;
2169 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002170 struct listnode *node;
Christian Franke80a8f722015-11-12 14:21:47 +01002171 struct isis_area *area = circuit->area;
2172
2173 lsp_debug("ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
2174 area->area_tag, rawlspid_print(lsp->lsp_header->lsp_id),
2175 circuit->interface->name, level);
hassof390d2c2004-09-10 20:48:21 +00002176
jardineb5d44e2003-12-23 08:09:43 +00002177 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002178 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002179 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2180 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00002181
2182 /*
2183 * add self to IS neighbours
2184 */
hassoaa4376e2005-09-26 17:39:48 +00002185 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00002186 {
hassoaa4376e2005-09-26 17:39:48 +00002187 if (lsp->tlv_data.is_neighs == NULL)
2188 {
2189 lsp->tlv_data.is_neighs = list_new ();
2190 lsp->tlv_data.is_neighs->del = free_tlv;
2191 }
2192 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002193
hassoaa4376e2005-09-26 17:39:48 +00002194 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2195 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002196 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
2197 area->area_tag, sysid_print(is_neigh->neigh_id),
2198 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002199 }
2200 if (circuit->area->newmetric)
2201 {
2202 if (lsp->tlv_data.te_is_neighs == NULL)
2203 {
2204 lsp->tlv_data.te_is_neighs = list_new ();
2205 lsp->tlv_data.te_is_neighs->del = free_tlv;
2206 }
2207 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2208
2209 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2210 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002211 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
2212 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2213 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002214 }
hassof390d2c2004-09-10 20:48:21 +00002215
2216 adj_list = list_new ();
2217 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
2218
hasso3fdb2dd2005-09-28 18:45:54 +00002219 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00002220 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002221 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00002222 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002223 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
2224 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00002225 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07002226 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00002227 {
2228 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00002229 if (circuit->area->oldmetric)
2230 {
2231 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002232
hassoaa4376e2005-09-26 17:39:48 +00002233 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2234 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002235 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
2236 area->area_tag, sysid_print(is_neigh->neigh_id),
2237 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002238 }
2239 if (circuit->area->newmetric)
2240 {
2241 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
2242 sizeof (struct te_is_neigh));
2243 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2244 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002245 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
2246 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2247 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002248 }
hassof390d2c2004-09-10 20:48:21 +00002249 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002250 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00002251 {
2252 /* an ES neigbour add it, if we are building level 1 LSP */
2253 /* FIXME: the tlv-format is hard to use here */
2254 if (lsp->tlv_data.es_neighs == NULL)
2255 {
2256 lsp->tlv_data.es_neighs = list_new ();
2257 lsp->tlv_data.es_neighs->del = free_tlv;
2258 }
paul15935e92005-05-03 09:27:23 +00002259 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2260
hassof390d2c2004-09-10 20:48:21 +00002261 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00002262 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002263 lsp_debug("ISIS (%s): Adding %s as ES neighbor (peer)",
2264 area->area_tag, sysid_print(es_neigh->first_es_neigh));
hassof390d2c2004-09-10 20:48:21 +00002265 }
Christian Franke80a8f722015-11-12 14:21:47 +01002266 else
2267 {
2268 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not match",
2269 area->area_tag, sysid_print(adj->sysid));
2270 }
2271 }
2272 else
2273 {
2274 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not intersect",
2275 area->area_tag, sysid_print(adj->sysid));
hassof390d2c2004-09-10 20:48:21 +00002276 }
jardineb5d44e2003-12-23 08:09:43 +00002277 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002278 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00002279
Christian Franke80a8f722015-11-12 14:21:47 +01002280 lsp_debug("ISIS (%s): Pseudo LSP construction is complete.", area->area_tag);
2281
hassoc0fb2a52005-09-03 16:29:40 +00002282 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00002283 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00002284 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2285
jardineb5d44e2003-12-23 08:09:43 +00002286 /*
2287 * Add the authentication info if it's present
2288 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002289 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2292 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2293
hassoaa4376e2005-09-26 17:39:48 +00002294 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
2295 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
2296
jardineb5d44e2003-12-23 08:09:43 +00002297 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2298 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2299
paul9985f832005-02-09 15:51:56 +00002300 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002301
Josh Bailey3f045a02012-03-24 08:35:20 -07002302 /* Recompute authentication and checksum information */
2303 lsp_auth_update (lsp);
2304 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2305 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00002306
2307 return;
2308}
2309
Josh Bailey3f045a02012-03-24 08:35:20 -07002310int
2311lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002312{
2313 dict_t *lspdb = circuit->area->lspdb[level - 1];
2314 struct isis_lsp *lsp;
2315 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07002316 u_int16_t rem_lifetime, refresh_time;
2317
2318 if ((circuit->is_type & level) != level ||
2319 (circuit->state != C_STATE_UP) ||
2320 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2321 (circuit->u.bc.is_dr[level - 1] == 0))
2322 return ISIS_ERROR;
2323
2324 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2325 LSP_FRAGMENT (lsp_id) = 0;
2326 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2327
2328 /*
2329 * If for some reason have a pseudo LSP in the db already -> regenerate
2330 */
2331 if (lsp_search (lsp_id, lspdb))
2332 return lsp_regenerate_schedule_pseudo (circuit, level);
2333
2334 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2335 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Christian Frankef1fc1db2015-11-10 18:43:31 +01002336 lsp = lsp_new (circuit->area, lsp_id, rem_lifetime, 1,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002337 circuit->area->is_type | circuit->area->attached_bit,
2338 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07002339 lsp->area = circuit->area;
2340
2341 lsp_build_pseudo (lsp, circuit, level);
2342
2343 lsp->own_lsp = 1;
2344 lsp_insert (lsp, lspdb);
2345 lsp_set_all_srmflags (lsp);
2346
2347 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2348 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
2349 circuit->lsp_regenerate_pending[level - 1] = 0;
2350 if (level == IS_LEVEL_1)
2351 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2352 lsp_l1_refresh_pseudo, circuit, refresh_time);
2353 else if (level == IS_LEVEL_2)
2354 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2355 lsp_l2_refresh_pseudo, circuit, refresh_time);
2356
2357 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2358 {
2359 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
2360 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2361 circuit->area->area_tag, level,
2362 rawlspid_print (lsp->lsp_header->lsp_id),
2363 ntohl (lsp->lsp_header->pdu_len),
2364 ntohl (lsp->lsp_header->seq_num),
2365 ntohs (lsp->lsp_header->checksum),
2366 ntohs (lsp->lsp_header->rem_lifetime),
2367 refresh_time);
2368 }
2369
2370 return ISIS_OK;
2371}
2372
2373static int
2374lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2375{
2376 dict_t *lspdb = circuit->area->lspdb[level - 1];
2377 struct isis_lsp *lsp;
2378 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2379 u_int16_t rem_lifetime, refresh_time;
2380
2381 if ((circuit->is_type & level) != level ||
2382 (circuit->state != C_STATE_UP) ||
2383 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2384 (circuit->u.bc.is_dr[level - 1] == 0))
2385 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002386
jardineb5d44e2003-12-23 08:09:43 +00002387 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002388 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2389 LSP_FRAGMENT (lsp_id) = 0;
2390
jardineb5d44e2003-12-23 08:09:43 +00002391 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002392
2393 if (!lsp)
2394 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002395 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2396 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002397 return ISIS_ERROR;
2398 }
2399 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002400
2401 lsp_build_pseudo (lsp, circuit, level);
2402
Josh Bailey3f045a02012-03-24 08:35:20 -07002403 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002404 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2405 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002406 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2407 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002408 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002409 lsp->last_generated = time (NULL);
2410 lsp_set_all_srmflags (lsp);
2411
2412 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2413 if (level == IS_LEVEL_1)
2414 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2415 lsp_l1_refresh_pseudo, circuit, refresh_time);
2416 else if (level == IS_LEVEL_2)
2417 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2418 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002419
2420 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2421 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002422 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2423 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2424 circuit->area->area_tag, level,
2425 rawlspid_print (lsp->lsp_header->lsp_id),
2426 ntohl (lsp->lsp_header->pdu_len),
2427 ntohl (lsp->lsp_header->seq_num),
2428 ntohs (lsp->lsp_header->checksum),
2429 ntohs (lsp->lsp_header->rem_lifetime),
2430 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002431 }
jardineb5d44e2003-12-23 08:09:43 +00002432
jardineb5d44e2003-12-23 08:09:43 +00002433 return ISIS_OK;
2434}
2435
Josh Bailey3f045a02012-03-24 08:35:20 -07002436/*
2437 * Something has changed or periodic refresh -> regenerate pseudo LSP
2438 */
2439static int
jardineb5d44e2003-12-23 08:09:43 +00002440lsp_l1_refresh_pseudo (struct thread *thread)
2441{
2442 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002443 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002444
hassof390d2c2004-09-10 20:48:21 +00002445 circuit = THREAD_ARG (thread);
2446
hasso13c48f72004-09-10 21:19:13 +00002447 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002448 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002449
Josh Bailey3f045a02012-03-24 08:35:20 -07002450 if ((circuit->u.bc.is_dr[0] == 0) ||
2451 (circuit->is_type & IS_LEVEL_1) == 0)
2452 {
2453 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2454 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2455 LSP_FRAGMENT (id) = 0;
2456 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2457 return ISIS_ERROR;
2458 }
hassof390d2c2004-09-10 20:48:21 +00002459
Josh Bailey3f045a02012-03-24 08:35:20 -07002460 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002461}
2462
Josh Bailey3f045a02012-03-24 08:35:20 -07002463static int
jardineb5d44e2003-12-23 08:09:43 +00002464lsp_l2_refresh_pseudo (struct thread *thread)
2465{
2466 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002467 u_char id[ISIS_SYS_ID_LEN + 2];
2468
hassof390d2c2004-09-10 20:48:21 +00002469 circuit = THREAD_ARG (thread);
2470
hasso13c48f72004-09-10 21:19:13 +00002471 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002472 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002473
Josh Bailey3f045a02012-03-24 08:35:20 -07002474 if ((circuit->u.bc.is_dr[1] == 0) ||
2475 (circuit->is_type & IS_LEVEL_2) == 0)
2476 {
2477 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2478 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2479 LSP_FRAGMENT (id) = 0;
2480 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2481 return ISIS_ERROR;
2482 }
jardineb5d44e2003-12-23 08:09:43 +00002483
Josh Bailey3f045a02012-03-24 08:35:20 -07002484 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002485}
2486
hassof390d2c2004-09-10 20:48:21 +00002487int
Josh Bailey3f045a02012-03-24 08:35:20 -07002488lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002489{
2490 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002491 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2492 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01002493 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07002494 int lvl;
Christian Franke61010c32015-11-10 18:43:34 +01002495 struct isis_area *area = circuit->area;
jardineb5d44e2003-12-23 08:09:43 +00002496
Josh Bailey3f045a02012-03-24 08:35:20 -07002497 if (circuit == NULL ||
2498 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2499 circuit->state != C_STATE_UP)
2500 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002501
Christian Franke61010c32015-11-10 18:43:34 +01002502 sched_debug("ISIS (%s): Scheduling regeneration of %s pseudo LSP for interface %s",
2503 area->area_tag, circuit_t2string(level), circuit->interface->name);
2504
Josh Bailey3f045a02012-03-24 08:35:20 -07002505 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2506 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2507 LSP_FRAGMENT (lsp_id) = 0;
2508 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002509
Josh Bailey3f045a02012-03-24 08:35:20 -07002510 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2511 {
Christian Franke61010c32015-11-10 18:43:34 +01002512 sched_debug("ISIS (%s): Checking whether L%d pseudo LSP needs to be scheduled",
2513 area->area_tag, lvl);
jardineb5d44e2003-12-23 08:09:43 +00002514
Christian Franke61010c32015-11-10 18:43:34 +01002515 if (!((level & lvl) && (circuit->is_type & lvl)))
2516 {
2517 sched_debug("ISIS (%s): Level is not active on circuit",
2518 area->area_tag);
2519 continue;
2520 }
2521
2522 if (circuit->u.bc.is_dr[lvl - 1] == 0)
2523 {
2524 sched_debug("ISIS (%s): This IS is not DR, nothing to do.",
2525 area->area_tag);
2526 continue;
2527 }
2528
2529 if (circuit->lsp_regenerate_pending[lvl - 1])
2530 {
2531 struct timeval remain =
2532 thread_timer_remain(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2533 sched_debug("ISIS (%s): Regenerate is already pending, nothing todo."
2534 " (Due in %lld.%03lld seconds)", area->area_tag,
2535 (long long)remain.tv_sec, (long long)remain.tv_usec/1000);
2536 continue;
2537 }
hassof390d2c2004-09-10 20:48:21 +00002538
Josh Bailey3f045a02012-03-24 08:35:20 -07002539 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2540 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002541 {
2542 sched_debug("ISIS (%s): Pseudonode LSP does not exist yet, nothing to regenerate.",
2543 area->area_tag);
2544 continue;
2545 }
jardineb5d44e2003-12-23 08:09:43 +00002546
Josh Bailey3f045a02012-03-24 08:35:20 -07002547 /*
2548 * Throttle avoidance
2549 */
Christian Franke61010c32015-11-10 18:43:34 +01002550 sched_debug("ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
2551 area->area_tag, (long long)lsp->last_generated, (long long) now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002552 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2553 diff = now - lsp->last_generated;
2554 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2555 {
Christian Franke61010c32015-11-10 18:43:34 +01002556 timeout = 1000 * (circuit->area->lsp_gen_interval[lvl - 1] - diff);
2557 sched_debug("ISIS (%s): Sechduling in %ld ms to match configured lsp_gen_interval",
2558 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002559 }
2560 else
2561 {
Christian Franke61010c32015-11-10 18:43:34 +01002562 timeout = 100;
2563 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2564 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2565 }
2566
2567 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2568
2569 if (lvl == IS_LEVEL_1)
2570 {
2571 THREAD_TIMER_MSEC_ON(master,
2572 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2573 lsp_l1_refresh_pseudo, circuit, timeout);
2574 }
2575 else if (lvl == IS_LEVEL_2)
2576 {
2577 THREAD_TIMER_MSEC_ON(master,
2578 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2579 lsp_l2_refresh_pseudo, circuit, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002580 }
2581 }
jardineb5d44e2003-12-23 08:09:43 +00002582
Josh Bailey3f045a02012-03-24 08:35:20 -07002583 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002584}
2585
jardineb5d44e2003-12-23 08:09:43 +00002586/*
2587 * Walk through LSPs for an area
2588 * - set remaining lifetime
2589 * - set LSPs with SRMflag set for sending
2590 */
hassof390d2c2004-09-10 20:48:21 +00002591int
jardineb5d44e2003-12-23 08:09:43 +00002592lsp_tick (struct thread *thread)
2593{
2594 struct isis_area *area;
2595 struct isis_circuit *circuit;
2596 struct isis_lsp *lsp;
2597 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002598 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002599 dnode_t *dnode, *dnode_next;
2600 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002601 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002602
2603 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002604
jardineb5d44e2003-12-23 08:09:43 +00002605 area = THREAD_ARG (thread);
2606 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002607 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002608 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002609
2610 /*
2611 * Build a list of LSPs with (any) SRMflag set
2612 * and removed the ones that have aged out
2613 */
hassof390d2c2004-09-10 20:48:21 +00002614 for (level = 0; level < ISIS_LEVELS; level++)
2615 {
2616 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002617 {
2618 for (dnode = dict_first (area->lspdb[level]);
2619 dnode != NULL; dnode = dnode_next)
2620 {
2621 dnode_next = dict_next (area->lspdb[level], dnode);
2622 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002623
Josh Bailey3f045a02012-03-24 08:35:20 -07002624 /*
2625 * The lsp rem_lifetime is kept at 0 for MaxAge or
2626 * ZeroAgeLifetime depending on explicit purge or
2627 * natural age out. So schedule spf only once when
2628 * the first time rem_lifetime becomes 0.
2629 */
2630 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2631 lsp_set_time (lsp);
2632
2633 /*
2634 * Schedule may run spf which should be done only after
2635 * the lsp rem_lifetime becomes 0 for the first time.
2636 * ISO 10589 - 7.3.16.4 first paragraph.
2637 */
2638 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2639 {
2640 /* 7.3.16.4 a) set SRM flags on all */
2641 lsp_set_all_srmflags (lsp);
2642 /* 7.3.16.4 b) retain only the header FIXME */
2643 /* 7.3.16.4 c) record the time to purge FIXME */
2644 /* run/schedule spf */
2645 /* isis_spf_schedule is called inside lsp_destroy() below;
2646 * so it is not needed here. */
2647 /* isis_spf_schedule (lsp->area, lsp->level); */
2648 }
2649
2650 if (lsp->age_out == 0)
2651 {
2652 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2653 area->area_tag,
2654 lsp->level,
2655 rawlspid_print (lsp->lsp_header->lsp_id),
2656 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002657#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002658 if (lsp->from_topology)
2659 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002660#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002661 lsp_destroy (lsp);
2662 lsp = NULL;
2663 dict_delete_free (area->lspdb[level], dnode);
2664 }
2665 else if (flags_any_set (lsp->SRMflags))
2666 listnode_add (lsp_list, lsp);
2667 }
jardineb5d44e2003-12-23 08:09:43 +00002668
Josh Bailey3f045a02012-03-24 08:35:20 -07002669 /*
2670 * Send LSPs on circuits indicated by the SRMflags
2671 */
2672 if (listcount (lsp_list) > 0)
2673 {
paul1eb8ef22005-04-07 07:30:20 +00002674 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002675 {
2676 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2677 if (circuit->lsp_queue == NULL ||
2678 diff < MIN_LSP_TRANS_INTERVAL)
2679 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002680 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002681 {
2682 if (circuit->upadjcount[lsp->level - 1] &&
2683 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2684 {
2685 /* Add the lsp only if it is not already in lsp
2686 * queue */
2687 if (! listnode_lookup (circuit->lsp_queue, lsp))
2688 {
2689 listnode_add (circuit->lsp_queue, lsp);
2690 thread_add_event (master, send_lsp, circuit, 0);
2691 }
2692 }
2693 }
2694 }
2695 list_delete_all_node (lsp_list);
2696 }
2697 }
jardineb5d44e2003-12-23 08:09:43 +00002698 }
jardineb5d44e2003-12-23 08:09:43 +00002699
2700 list_delete (lsp_list);
2701
2702 return ISIS_OK;
2703}
2704
jardineb5d44e2003-12-23 08:09:43 +00002705void
Josh Bailey3f045a02012-03-24 08:35:20 -07002706lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002707{
2708 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002709 u_int16_t seq_num;
2710 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002711
jardineb5d44e2003-12-23 08:09:43 +00002712 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002713 if (!lsp)
2714 return;
hassof390d2c2004-09-10 20:48:21 +00002715
Josh Bailey3f045a02012-03-24 08:35:20 -07002716 /* store old values */
2717 seq_num = lsp->lsp_header->seq_num;
2718 lsp_bits = lsp->lsp_header->lsp_bits;
2719
2720 /* reset stream */
2721 lsp_clear_data (lsp);
2722 stream_reset (lsp->pdu);
2723
2724 /* update header */
2725 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2726 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2727 lsp->lsp_header->checksum = 0;
2728 lsp->lsp_header->seq_num = seq_num;
2729 lsp->lsp_header->rem_lifetime = 0;
2730 lsp->lsp_header->lsp_bits = lsp_bits;
2731 lsp->level = level;
2732 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2733 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2734
2735 /*
2736 * Add and update the authentication info if its present
2737 */
2738 lsp_auth_add (lsp);
2739 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2740 lsp_auth_update (lsp);
2741 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2742 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2743
2744 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002745
jardineb5d44e2003-12-23 08:09:43 +00002746 return;
2747}
2748
2749/*
2750 * Purge own LSP that is received and we don't have.
2751 * -> Do as in 7.3.16.4
2752 */
2753void
Christian Franke749e87a2015-11-10 18:21:44 +01002754lsp_purge_non_exist (int level,
2755 struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +00002756 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002757{
2758 struct isis_lsp *lsp;
2759
2760 /*
2761 * We need to create the LSP to be purged
2762 */
hassoaac372f2005-09-01 17:52:33 +00002763 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002764 lsp->area = area;
Christian Franke749e87a2015-11-10 18:21:44 +01002765 lsp->level = level;
Christian Frankef1fc1db2015-11-10 18:43:31 +01002766 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
hassof390d2c2004-09-10 20:48:21 +00002767 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002768 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002769 : L2_LINK_STATE);
2770 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2771 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002772 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002773 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002774
jardineb5d44e2003-12-23 08:09:43 +00002775 /*
jardineb5d44e2003-12-23 08:09:43 +00002776 * Set the remaining lifetime to 0
2777 */
2778 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002779
2780 /*
2781 * Add and update the authentication info if its present
2782 */
2783 lsp_auth_add (lsp);
2784 lsp_auth_update (lsp);
2785
2786 /*
2787 * Update the PDU length to header plus any authentication TLV.
2788 */
2789 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2790
jardineb5d44e2003-12-23 08:09:43 +00002791 /*
2792 * Put the lsp into LSPdb
2793 */
hassof390d2c2004-09-10 20:48:21 +00002794 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002795
2796 /*
2797 * Send in to whole area
2798 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002799 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002800
jardineb5d44e2003-12-23 08:09:43 +00002801 return;
2802}
2803
Josh Bailey3f045a02012-03-24 08:35:20 -07002804void lsp_set_all_srmflags (struct isis_lsp *lsp)
2805{
2806 struct listnode *node;
2807 struct isis_circuit *circuit;
2808
2809 assert (lsp);
2810
2811 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2812
2813 if (lsp->area)
2814 {
2815 struct list *circuit_list = lsp->area->circuit_list;
2816 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2817 {
2818 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2819 }
2820 }
2821}
2822
jardineb5d44e2003-12-23 08:09:43 +00002823#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002824static int
jardineb5d44e2003-12-23 08:09:43 +00002825top_lsp_refresh (struct thread *thread)
2826{
hassof390d2c2004-09-10 20:48:21 +00002827 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002828 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002829
2830 lsp = THREAD_ARG (thread);
2831 assert (lsp);
2832
2833 lsp->t_lsp_top_ref = NULL;
2834
hassof1082d12005-09-19 04:23:34 +00002835 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002836
Josh Bailey3f045a02012-03-24 08:35:20 -07002837 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002838 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2839 {
hasso529d65b2004-12-24 00:14:50 +00002840 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2841 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002842 }
hassod3d74742005-09-28 18:30:51 +00002843 /* Refresh dynamic hostname in the cache. */
2844 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2845 IS_LEVEL_1);
2846
David Lampartera47c5832012-06-21 09:55:38 +02002847 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002848 lsp->area->overload_bit,
2849 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002850 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2851 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002852
David Lamparterf50ee932015-03-04 07:13:38 +01002853 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002854 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002855 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002856
2857 return ISIS_OK;
2858}
2859
2860void
2861generate_topology_lsps (struct isis_area *area)
2862{
2863 struct listnode *node;
2864 int i, max = 0;
2865 struct arc *arc;
2866 u_char lspid[ISIS_SYS_ID_LEN + 2];
2867 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002868 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002869
2870 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002871 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002872 {
2873 if (arc->from_node > max)
2874 max = arc->from_node;
2875 if (arc->to_node > max)
2876 max = arc->to_node;
2877 }
jardineb5d44e2003-12-23 08:09:43 +00002878
hassof390d2c2004-09-10 20:48:21 +00002879 for (i = 1; i < (max + 1); i++)
2880 {
2881 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2882 LSP_PSEUDO_ID (lspid) = 0x00;
2883 LSP_FRAGMENT (lspid) = 0x00;
2884 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2885 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002886
Josh Bailey3f045a02012-03-24 08:35:20 -07002887 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Christian Frankef1fc1db2015-11-10 18:43:31 +01002888 lsp = lsp_new (area, lspid, rem_lifetime, 1,
2889 IS_LEVEL_1 | area->overload_bit | area->attached_bit,
2890 0, 1);
hassof1082d12005-09-19 04:23:34 +00002891 if (!lsp)
2892 return;
Josh Bailey3f045a02012-03-24 08:35:20 -07002893 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002894
hassof1082d12005-09-19 04:23:34 +00002895 /* Creating LSP data based on topology info. */
2896 build_topology_lsp_data (lsp, area, i);
2897 /* Checksum is also calculated here. */
2898 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002899 /* Take care of inserting dynamic hostname into cache. */
2900 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002901
Josh Bailey3f045a02012-03-24 08:35:20 -07002902 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002903 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002904 refresh_time);
2905 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002906 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002907 }
jardineb5d44e2003-12-23 08:09:43 +00002908}
2909
2910void
2911remove_topology_lsps (struct isis_area *area)
2912{
2913 struct isis_lsp *lsp;
2914 dnode_t *dnode, *dnode_next;
2915
2916 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002917 while (dnode != NULL)
2918 {
2919 dnode_next = dict_next (area->lspdb[0], dnode);
2920 lsp = dnode_get (dnode);
2921 if (lsp->from_topology)
2922 {
2923 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2924 lsp_destroy (lsp);
2925 dict_delete (area->lspdb[0], dnode);
2926 }
2927 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002928 }
jardineb5d44e2003-12-23 08:09:43 +00002929}
2930
2931void
hassof390d2c2004-09-10 20:48:21 +00002932build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002933 int lsp_top_num)
2934{
hasso3fdb2dd2005-09-28 18:45:54 +00002935 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002936 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002937 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002938 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002939 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002940 struct tlvs tlv_data;
2941 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002942
hassof1082d12005-09-19 04:23:34 +00002943 /* Add area addresses. FIXME: Is it needed at all? */
2944 if (lsp->tlv_data.area_addrs == NULL)
2945 lsp->tlv_data.area_addrs = list_new ();
2946 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002947
hassof1082d12005-09-19 04:23:34 +00002948 if (lsp->tlv_data.nlpids == NULL)
2949 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2950 lsp->tlv_data.nlpids->count = 1;
2951 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002952
hassof1082d12005-09-19 04:23:34 +00002953 if (area->dynhostname)
2954 {
2955 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2956 sizeof (struct hostname));
2957 memset (buff, 0x00, 200);
2958 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2959 "feedme", lsp_top_num);
2960 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2961 lsp->tlv_data.hostname->namelen = strlen (buff);
2962 }
2963
2964 if (lsp->tlv_data.nlpids)
2965 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2966 if (lsp->tlv_data.hostname)
2967 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2968 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2969 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2970
2971 memset (&tlv_data, 0, sizeof (struct tlvs));
2972 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002973 {
2974 tlv_data.is_neighs = list_new ();
2975 tlv_data.is_neighs->del = free_tlv;
2976 }
hassof1082d12005-09-19 04:23:34 +00002977
2978 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002979 if (lsp_top_num == 1)
2980 {
hasso3fdb2dd2005-09-28 18:45:54 +00002981 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002982
hassof390d2c2004-09-10 20:48:21 +00002983 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002984 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002985 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2986 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002987 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2988 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2989 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002990 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002991 }
hassof390d2c2004-09-10 20:48:21 +00002992
hassof1082d12005-09-19 04:23:34 +00002993 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002994 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002995 {
hassof1082d12005-09-19 04:23:34 +00002996 int to_lsp = 0;
2997
2998 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2999 continue;
3000
3001 if (lsp_top_num == arc->from_node)
3002 to_lsp = arc->to_node;
3003 else
3004 to_lsp = arc->from_node;
3005
hasso9551eea2005-09-28 18:26:25 +00003006 if (area->oldmetric)
3007 {
3008 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00003009
hasso9551eea2005-09-28 18:26:25 +00003010 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
3011 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
3012 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
3013 is_neigh->metrics.metric_default = arc->distance;
3014 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
3015 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
3016 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
3017 listnode_add (tlv_data.is_neighs, is_neigh);
3018 }
3019
3020 if (area->newmetric)
3021 {
hasso9551eea2005-09-28 18:26:25 +00003022 if (tlv_data.te_is_neighs == NULL)
3023 {
3024 tlv_data.te_is_neighs = list_new ();
3025 tlv_data.te_is_neighs->del = free_tlv;
3026 }
3027 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
3028 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
3029 ISIS_SYS_ID_LEN);
3030 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
3031 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07003032 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00003033 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
3034 }
hassof390d2c2004-09-10 20:48:21 +00003035 }
hassof1082d12005-09-19 04:23:34 +00003036
3037 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
3038 {
3039 if (lsp->tlv_data.is_neighs == NULL)
3040 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00003041 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00003042 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
3043 tlv_add_is_neighs);
3044 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
3045 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
3046 lsp0, area, IS_LEVEL_1);
3047 }
3048
hasso9551eea2005-09-28 18:26:25 +00003049 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
3050 {
3051 if (lsp->tlv_data.te_is_neighs == NULL)
3052 lsp->tlv_data.te_is_neighs = list_new ();
3053 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
3054 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
3055 tlv_add_te_is_neighs);
3056 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
3057 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
3058 lsp0, area, IS_LEVEL_1);
3059 }
3060
hassof1082d12005-09-19 04:23:34 +00003061 free_tlvs (&tlv_data);
3062 return;
jardineb5d44e2003-12-23 08:09:43 +00003063}
3064#endif /* TOPOLOGY_GENERATE */