blob: aac8451bfcb57b10df9a51ec8974f059565bd380 [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));
David Lamparterf2634132016-07-28 17:23:32 +02001547 ipreach->metrics.metric_default = circuit->metric[level - 1];
1548 ipreach->metrics.metric_expense = METRICS_UNSUPPORTED;
1549 ipreach->metrics.metric_error = METRICS_UNSUPPORTED;
1550 ipreach->metrics.metric_delay = METRICS_UNSUPPORTED;
hassoaa4376e2005-09-26 17:39:48 +00001551 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1552 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1553 (ipv4->prefix.s_addr));
Christian Franke80a8f722015-11-12 14:21:47 +01001554 inet_ntop(AF_INET, &ipreach->prefix.s_addr, buf, sizeof(buf));
1555 lsp_debug("ISIS (%s): Adding old-style IP reachability for %s/%d",
1556 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001557 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1558 }
hassof390d2c2004-09-10 20:48:21 +00001559 }
hassoaa4376e2005-09-26 17:39:48 +00001560 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001561 {
hassoaa4376e2005-09-26 17:39:48 +00001562 if (tlv_data.te_ipv4_reachs == NULL)
1563 {
1564 tlv_data.te_ipv4_reachs = list_new ();
1565 tlv_data.te_ipv4_reachs->del = free_tlv;
1566 }
hasso3fdb2dd2005-09-28 18:45:54 +00001567 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001568 {
1569 /* FIXME All this assumes that we have no sub TLVs. */
1570 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1571 sizeof (struct te_ipv4_reachability) +
1572 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001573
1574 if (area->oldmetric)
David Lamparterf2634132016-07-28 17:23:32 +02001575 te_ipreach->te_metric = htonl (circuit->metric[level - 1]);
hasso309ddb12005-09-26 18:06:47 +00001576 else
1577 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1578
hassoaa4376e2005-09-26 17:39:48 +00001579 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1580 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1581 (ipv4->prefixlen + 7)/8);
Christian Franke80a8f722015-11-12 14:21:47 +01001582 inet_ntop(AF_INET, &ipv4->prefix.s_addr, buf, sizeof(buf));
1583 lsp_debug("ISIS (%s): Adding te-style IP reachability for %s/%d",
1584 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001585 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1586 }
hassof390d2c2004-09-10 20:48:21 +00001587 }
hassof390d2c2004-09-10 20:48:21 +00001588 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001589
jardineb5d44e2003-12-23 08:09:43 +00001590#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001591 /*
1592 * Add IPv6 reachability of this circuit
1593 */
1594 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1595 circuit->ipv6_non_link->count > 0)
1596 {
1597
1598 if (tlv_data.ipv6_reachs == NULL)
1599 {
1600 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001601 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001602 }
hasso3fdb2dd2005-09-28 18:45:54 +00001603 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001604 {
hassof390d2c2004-09-10 20:48:21 +00001605 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001606 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001607
1608 if (area->oldmetric)
1609 ip6reach->metric =
David Lamparterf2634132016-07-28 17:23:32 +02001610 htonl (circuit->metric[level - 1]);
hasso309ddb12005-09-26 18:06:47 +00001611 else
1612 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1613
hassof390d2c2004-09-10 20:48:21 +00001614 ip6reach->control_info = 0;
1615 ip6reach->prefix_len = ipv6->prefixlen;
Christian Frankee28718a2015-11-10 18:33:14 +01001616 memcpy(&ip6prefix, ipv6, sizeof(ip6prefix));
1617 apply_mask_ipv6(&ip6prefix);
Christian Franke80a8f722015-11-12 14:21:47 +01001618
Christian Frankee28718a2015-11-10 18:33:14 +01001619 inet_ntop(AF_INET6, &ip6prefix.prefix.s6_addr, buf, sizeof(buf));
Christian Franke80a8f722015-11-12 14:21:47 +01001620 lsp_debug("ISIS (%s): Adding IPv6 reachability for %s/%d",
1621 area->area_tag, buf, ipv6->prefixlen);
1622
Christian Frankee28718a2015-11-10 18:33:14 +01001623 memcpy (ip6reach->prefix, ip6prefix.prefix.s6_addr,
hasso67851572004-09-21 14:17:04 +00001624 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001625 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1626 }
1627 }
1628#endif /* HAVE_IPV6 */
1629
1630 switch (circuit->circ_type)
1631 {
1632 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001633 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001634 {
hassoaa4376e2005-09-26 17:39:48 +00001635 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001636 {
hassoaa4376e2005-09-26 17:39:48 +00001637 if (tlv_data.is_neighs == NULL)
1638 {
1639 tlv_data.is_neighs = list_new ();
1640 tlv_data.is_neighs->del = free_tlv;
1641 }
1642 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001643 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001644 memcpy (is_neigh->neigh_id,
1645 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1646 else
1647 memcpy (is_neigh->neigh_id,
1648 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
David Lamparterf2634132016-07-28 17:23:32 +02001649 is_neigh->metrics.metric_default = circuit->metric[level - 1];
1650 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1651 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1652 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
Josh Bailey3f045a02012-03-24 08:35:20 -07001653 if (!memcmp (is_neigh->neigh_id, zero_id,
1654 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001655 {
1656 XFREE (MTYPE_ISIS_TLV, is_neigh);
1657 lsp_debug("ISIS (%s): No DIS for circuit, not adding old-style IS neighbor.",
1658 area->area_tag);
1659 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001660 else
Christian Franke80a8f722015-11-12 14:21:47 +01001661 {
1662 listnode_add (tlv_data.is_neighs, is_neigh);
1663 lsp_debug("ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
1664 area->area_tag, sysid_print(is_neigh->neigh_id),
1665 LSP_PSEUDO_ID(is_neigh->neigh_id));
1666 }
hassof390d2c2004-09-10 20:48:21 +00001667 }
hassoaa4376e2005-09-26 17:39:48 +00001668 if (area->newmetric)
1669 {
hassoaa4376e2005-09-26 17:39:48 +00001670 if (tlv_data.te_is_neighs == NULL)
1671 {
1672 tlv_data.te_is_neighs = list_new ();
1673 tlv_data.te_is_neighs->del = free_tlv;
1674 }
1675 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1676 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001677 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001678 memcpy (te_is_neigh->neigh_id,
1679 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1680 else
1681 memcpy (te_is_neigh->neigh_id,
1682 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001683 if (area->oldmetric)
David Lamparterf2634132016-07-28 17:23:32 +02001684 metric = circuit->metric[level - 1];
hasso309ddb12005-09-26 18:06:47 +00001685 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001686 metric = circuit->te_metric[level - 1];
1687 SET_TE_METRIC(te_is_neigh, metric);
1688 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1689 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001690 {
1691 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1692 lsp_debug("ISIS (%s): No DIS for circuit, not adding te-style IS neighbor.",
1693 area->area_tag);
1694 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001695 else
Christian Franke80a8f722015-11-12 14:21:47 +01001696 {
Olivier Dugeon4f593572016-04-19 19:03:05 +02001697 /* Check if MPLS_TE is activate */
1698 if (IS_MPLS_TE(isisMplsTE) && HAS_LINK_PARAMS(circuit->interface))
1699 /* Add SubTLVs & Adjust real size of SubTLVs */
1700 te_is_neigh->sub_tlvs_length = add_te_subtlvs(te_is_neigh->sub_tlvs, circuit->mtc);
1701 else
1702 /* Or keep only TE metric with no SubTLVs if MPLS_TE is off */
1703 te_is_neigh->sub_tlvs_length = 0;
1704
Christian Franke80a8f722015-11-12 14:21:47 +01001705 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1706 lsp_debug("ISIS (%s): Adding DIS %s.%02x as te-style neighbor",
1707 area->area_tag, sysid_print(te_is_neigh->neigh_id),
1708 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
1709 }
hassoaa4376e2005-09-26 17:39:48 +00001710 }
hassof390d2c2004-09-10 20:48:21 +00001711 }
Christian Franke80a8f722015-11-12 14:21:47 +01001712 else
1713 {
1714 lsp_debug("ISIS (%s): Circuit is not active for current level. Not adding IS neighbors",
1715 area->area_tag);
1716 }
hassof390d2c2004-09-10 20:48:21 +00001717 break;
1718 case CIRCUIT_T_P2P:
1719 nei = circuit->u.p2p.neighbor;
1720 if (nei && (level & nei->circuit_t))
1721 {
hassoaa4376e2005-09-26 17:39:48 +00001722 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001723 {
hassoaa4376e2005-09-26 17:39:48 +00001724 if (tlv_data.is_neighs == NULL)
1725 {
1726 tlv_data.is_neighs = list_new ();
1727 tlv_data.is_neighs->del = free_tlv;
1728 }
1729 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1730 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
David Lamparterf2634132016-07-28 17:23:32 +02001731 is_neigh->metrics.metric_default = circuit->metric[level - 1];
1732 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1733 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1734 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
hassoaa4376e2005-09-26 17:39:48 +00001735 listnode_add (tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001736 lsp_debug("ISIS (%s): Adding old-style is reach for %s", area->area_tag,
1737 sysid_print(is_neigh->neigh_id));
hassof390d2c2004-09-10 20:48:21 +00001738 }
hassoaa4376e2005-09-26 17:39:48 +00001739 if (area->newmetric)
1740 {
1741 uint32_t metric;
1742
1743 if (tlv_data.te_is_neighs == NULL)
1744 {
1745 tlv_data.te_is_neighs = list_new ();
1746 tlv_data.te_is_neighs->del = free_tlv;
1747 }
1748 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1749 sizeof (struct te_is_neigh));
1750 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001751 metric = circuit->te_metric[level - 1];
1752 SET_TE_METRIC(te_is_neigh, metric);
Olivier Dugeon4f593572016-04-19 19:03:05 +02001753 /* Check if MPLS_TE is activate */
1754 if (IS_MPLS_TE(isisMplsTE) && HAS_LINK_PARAMS(circuit->interface))
1755 /* Update Local and Remote IP address for MPLS TE circuit parameters */
1756 /* NOTE sure that it is the pertinent place for that updates */
1757 /* Local IP address could be updated in isis_circuit.c - isis_circuit_add_addr() */
1758 /* But, where update remote IP address ? in isis_pdu.c - process_p2p_hello() ? */
1759
1760 /* Add SubTLVs & Adjust real size of SubTLVs */
1761 te_is_neigh->sub_tlvs_length = add_te_subtlvs(te_is_neigh->sub_tlvs, circuit->mtc);
1762 else
1763 /* Or keep only TE metric with no SubTLVs if MPLS_TE is off */
1764 te_is_neigh->sub_tlvs_length = 0;
hassoaa4376e2005-09-26 17:39:48 +00001765 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001766 lsp_debug("ISIS (%s): Adding te-style is reach for %s", area->area_tag,
1767 sysid_print(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001768 }
hassof390d2c2004-09-10 20:48:21 +00001769 }
Christian Franke80a8f722015-11-12 14:21:47 +01001770 else
1771 {
1772 lsp_debug("ISIS (%s): No adjacency for given level on this circuit. Not adding IS neighbors",
1773 area->area_tag);
1774 }
hassof390d2c2004-09-10 20:48:21 +00001775 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001776 case CIRCUIT_T_LOOPBACK:
1777 break;
hassof390d2c2004-09-10 20:48:21 +00001778 default:
1779 zlog_warn ("lsp_area_create: unknown circuit type");
1780 }
1781 }
1782
Christian Frankeacf98652015-11-12 14:24:22 +01001783 lsp_build_ext_reach(lsp, area, &tlv_data);
1784
Christian Franke80a8f722015-11-12 14:21:47 +01001785 lsp_debug("ISIS (%s): LSP construction is complete. Serializing...", area->area_tag);
1786
hassof390d2c2004-09-10 20:48:21 +00001787 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1788 {
1789 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1790 lsp->tlv_data.ipv4_int_reachs = list_new ();
1791 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1792 &lsp->tlv_data.ipv4_int_reachs,
1793 IPV4_REACH_LEN, area->lsp_frag_threshold,
Christian Frankeacf98652015-11-12 14:24:22 +01001794 tlv_add_ipv4_int_reachs);
hassof390d2c2004-09-10 20:48:21 +00001795 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1796 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1797 lsp0, area, level);
1798 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001799
Christian Frankeacf98652015-11-12 14:24:22 +01001800 while (tlv_data.ipv4_ext_reachs && listcount (tlv_data.ipv4_ext_reachs))
1801 {
1802 if (lsp->tlv_data.ipv4_ext_reachs == NULL)
1803 lsp->tlv_data.ipv4_ext_reachs = list_new ();
1804 lsp_tlv_fit (lsp, &tlv_data.ipv4_ext_reachs,
1805 &lsp->tlv_data.ipv4_ext_reachs,
1806 IPV4_REACH_LEN, area->lsp_frag_threshold,
1807 tlv_add_ipv4_ext_reachs);
1808 if (tlv_data.ipv4_ext_reachs && listcount (tlv_data.ipv4_ext_reachs))
1809 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1810 lsp0, area, level);
1811 }
1812
hassoaa4376e2005-09-26 17:39:48 +00001813 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1814 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1815 * TLVs (sub TLVs!). */
1816 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1817 {
1818 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1819 lsp->tlv_data.te_ipv4_reachs = list_new ();
1820 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1821 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001822 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1823 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001824 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1825 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1826 lsp0, area, level);
1827 }
hassof390d2c2004-09-10 20:48:21 +00001828
1829#ifdef HAVE_IPV6
1830 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1831 {
1832 if (lsp->tlv_data.ipv6_reachs == NULL)
1833 lsp->tlv_data.ipv6_reachs = list_new ();
1834 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1835 &lsp->tlv_data.ipv6_reachs,
1836 IPV6_REACH_LEN, area->lsp_frag_threshold,
1837 tlv_add_ipv6_reachs);
1838 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1839 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1840 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001841 }
1842#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001843
1844 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1845 {
1846 if (lsp->tlv_data.is_neighs == NULL)
1847 lsp->tlv_data.is_neighs = list_new ();
1848 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1849 &lsp->tlv_data.is_neighs,
1850 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1851 tlv_add_is_neighs);
1852 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1853 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1854 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001855 }
jardineb5d44e2003-12-23 08:09:43 +00001856
hassoaa4376e2005-09-26 17:39:48 +00001857 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1858 {
1859 if (lsp->tlv_data.te_is_neighs == NULL)
1860 lsp->tlv_data.te_is_neighs = list_new ();
1861 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1862 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1863 tlv_add_te_is_neighs);
1864 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1865 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1866 lsp0, area, level);
1867 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001868 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001869
1870 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001871
1872 /* Validate the LSP */
1873 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1874 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1875 stream_get_endp (lsp->pdu) -
1876 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1877 &expected, &found, &tlv_data, NULL);
1878 assert (retval == ISIS_OK);
1879
jardineb5d44e2003-12-23 08:09:43 +00001880 return;
1881}
jardineb5d44e2003-12-23 08:09:43 +00001882
1883/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001884 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001885 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001886int
1887lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001888{
jardineb5d44e2003-12-23 08:09:43 +00001889 struct isis_lsp *oldlsp, *newlsp;
1890 u_int32_t seq_num = 0;
1891 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001892 u_int16_t rem_lifetime, refresh_time;
1893
1894 if ((area == NULL) || (area->is_type & level) != level)
1895 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001896
1897 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1898 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1899
1900 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001901 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1902 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001903 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001904 /* FIXME: we should actually initiate a purge */
1905 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1906 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1907 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001908 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001909 rem_lifetime = lsp_rem_lifetime (area, level);
Christian Frankef1fc1db2015-11-10 18:43:31 +01001910 newlsp = lsp_new (area, lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001911 area->is_type | area->overload_bit | area->attached_bit,
1912 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001913 newlsp->area = area;
1914 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001915
Josh Bailey3f045a02012-03-24 08:35:20 -07001916 lsp_insert (newlsp, area->lspdb[level - 1]);
1917 /* build_lsp_data (newlsp, area); */
1918 lsp_build (newlsp, area);
1919 /* time to calculate our checksum */
1920 lsp_seqnum_update (newlsp);
Christian Franke61010c32015-11-10 18:43:34 +01001921 newlsp->last_generated = time(NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001922 lsp_set_all_srmflags (newlsp);
1923
1924 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
Christian Franke61010c32015-11-10 18:43:34 +01001925
Josh Bailey3f045a02012-03-24 08:35:20 -07001926 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
Christian Franke61010c32015-11-10 18:43:34 +01001927 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001928 if (level == IS_LEVEL_1)
1929 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1930 lsp_l1_refresh, area, refresh_time);
1931 else if (level == IS_LEVEL_2)
1932 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1933 lsp_l2_refresh, area, refresh_time);
1934
1935 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001936 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001937 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1938 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1939 area->area_tag, level,
1940 rawlspid_print (newlsp->lsp_header->lsp_id),
1941 ntohl (newlsp->lsp_header->pdu_len),
1942 ntohl (newlsp->lsp_header->seq_num),
1943 ntohs (newlsp->lsp_header->checksum),
1944 ntohs (newlsp->lsp_header->rem_lifetime),
1945 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001946 }
Christian Franke61010c32015-11-10 18:43:34 +01001947 sched_debug("ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
1948 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001949
1950 return ISIS_OK;
1951}
1952
1953/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001954 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001955 */
hasso92365882005-01-18 13:53:33 +00001956static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001957lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001958{
David Lampartere8aca322012-11-27 01:10:30 +00001959 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001960 struct isis_lsp *lsp, *frag;
1961 struct listnode *node;
1962 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001963 u_int16_t rem_lifetime, refresh_time;
1964
1965 if ((area == NULL) || (area->is_type & level) != level)
1966 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001967
David Lampartere8aca322012-11-27 01:10:30 +00001968 lspdb = area->lspdb[level - 1];
1969
jardineb5d44e2003-12-23 08:09:43 +00001970 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1971 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001972
jardineb5d44e2003-12-23 08:09:43 +00001973 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001974
hassof390d2c2004-09-10 20:48:21 +00001975 if (!lsp)
1976 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001977 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1978 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001979 return ISIS_ERROR;
1980 }
1981
1982 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001983 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001984 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1985 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001986 rem_lifetime = lsp_rem_lifetime (area, level);
1987 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001988 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001989
Josh Bailey3f045a02012-03-24 08:35:20 -07001990 lsp->last_generated = time (NULL);
1991 lsp_set_all_srmflags (lsp);
1992 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1993 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001994 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001995 area->overload_bit,
1996 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001997 /* Set the lifetime values of all the fragments to the same value,
1998 * so that no fragment expires before the lsp is refreshed.
1999 */
2000 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
2001 lsp_set_all_srmflags (frag);
2002 }
2003
2004 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2005 if (level == IS_LEVEL_1)
2006 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
2007 lsp_l1_refresh, area, refresh_time);
2008 else if (level == IS_LEVEL_2)
2009 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
2010 lsp_l2_refresh, area, refresh_time);
Christian Franke61010c32015-11-10 18:43:34 +01002011 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002012
hassof390d2c2004-09-10 20:48:21 +00002013 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2014 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002015 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
2016 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
2017 area->area_tag, level,
2018 rawlspid_print (lsp->lsp_header->lsp_id),
2019 ntohl (lsp->lsp_header->pdu_len),
2020 ntohl (lsp->lsp_header->seq_num),
2021 ntohs (lsp->lsp_header->checksum),
2022 ntohs (lsp->lsp_header->rem_lifetime),
2023 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002024 }
Christian Franke61010c32015-11-10 18:43:34 +01002025 sched_debug("ISIS (%s): Rebuilt L%d LSP. Set triggered regenerate to non-pending.",
2026 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00002027
jardineb5d44e2003-12-23 08:09:43 +00002028 return ISIS_OK;
2029}
2030
jardineb5d44e2003-12-23 08:09:43 +00002031/*
Josh Bailey3f045a02012-03-24 08:35:20 -07002032 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00002033 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002034static int
2035lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00002036{
2037 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00002038
2039 area = THREAD_ARG (thread);
2040 assert (area);
hassof390d2c2004-09-10 20:48:21 +00002041
jardineb5d44e2003-12-23 08:09:43 +00002042 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002043 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00002044
Josh Bailey3f045a02012-03-24 08:35:20 -07002045 if ((area->is_type & IS_LEVEL_1) == 0)
2046 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00002047
Christian Franke61010c32015-11-10 18:43:34 +01002048 sched_debug("ISIS (%s): LSP L1 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07002049 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002050}
2051
Josh Bailey3f045a02012-03-24 08:35:20 -07002052static int
2053lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00002054{
2055 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00002056
2057 area = THREAD_ARG (thread);
2058 assert (area);
hassof390d2c2004-09-10 20:48:21 +00002059
jardineb5d44e2003-12-23 08:09:43 +00002060 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00002061 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00002062
Josh Bailey3f045a02012-03-24 08:35:20 -07002063 if ((area->is_type & IS_LEVEL_2) == 0)
2064 return ISIS_ERROR;
2065
Christian Franke61010c32015-11-10 18:43:34 +01002066 sched_debug("ISIS (%s): LSP L2 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07002067 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002068}
2069
hassof390d2c2004-09-10 20:48:21 +00002070int
Josh Bailey3f045a02012-03-24 08:35:20 -07002071lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00002072{
2073 struct isis_lsp *lsp;
2074 u_char id[ISIS_SYS_ID_LEN + 2];
2075 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01002076 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07002077 struct listnode *cnode;
2078 struct isis_circuit *circuit;
2079 int lvl;
2080
2081 if (area == NULL)
2082 return ISIS_ERROR;
2083
Christian Franke61010c32015-11-10 18:43:34 +01002084 sched_debug("ISIS (%s): Scheduling regeneration of %s LSPs, %sincluding PSNs",
2085 area->area_tag, circuit_t2string(level), all_pseudo ? "" : "not ");
2086
hassof390d2c2004-09-10 20:48:21 +00002087 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2088 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00002089 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07002090
2091 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00002092 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002093 if (!((level & lvl) && (area->is_type & lvl)))
2094 continue;
2095
Christian Franke61010c32015-11-10 18:43:34 +01002096 sched_debug("ISIS (%s): Checking whether L%d needs to be scheduled",
2097 area->area_tag, lvl);
2098
Josh Bailey3f045a02012-03-24 08:35:20 -07002099 if (area->lsp_regenerate_pending[lvl - 1])
Christian Franke61010c32015-11-10 18:43:34 +01002100 {
2101 struct timeval remain = thread_timer_remain(area->t_lsp_refresh[lvl - 1]);
2102 sched_debug("ISIS (%s): Regeneration is already pending, nothing todo."
2103 " (Due in %lld.%03lld seconds)", area->area_tag,
2104 (long long)remain.tv_sec, (long long)remain.tv_usec / 1000);
2105 continue;
2106 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002107
2108 lsp = lsp_search (id, area->lspdb[lvl - 1]);
2109 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002110 {
2111 sched_debug("ISIS (%s): We do not have any LSPs to regenerate, nothing todo.",
2112 area->area_tag);
2113 continue;
2114 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002115
hassof390d2c2004-09-10 20:48:21 +00002116 /*
2117 * Throttle avoidance
2118 */
Christian Franke61010c32015-11-10 18:43:34 +01002119 sched_debug("ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
2120 area->area_tag, (long long)lsp->last_generated, (long long)now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002121 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00002122 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07002123 if (diff < area->lsp_gen_interval[lvl - 1])
2124 {
Christian Franke61010c32015-11-10 18:43:34 +01002125 timeout = 1000 * (area->lsp_gen_interval[lvl - 1] - diff);
2126 sched_debug("ISIS (%s): Scheduling in %ld ms to match configured lsp_gen_interval",
2127 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002128 }
hassof390d2c2004-09-10 20:48:21 +00002129 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002130 {
Michael Zinggbe62b172012-10-26 11:18:19 +02002131 /*
2132 * lsps are not regenerated if lsp_regenerate function is called
2133 * directly. However if the lsp_regenerate call is queued for
2134 * later execution it works.
2135 */
Christian Franke61010c32015-11-10 18:43:34 +01002136 timeout = 100;
2137 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2138 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2139 }
2140
2141 area->lsp_regenerate_pending[lvl - 1] = 1;
2142 if (lvl == IS_LEVEL_1)
2143 {
2144 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
2145 lsp_l1_refresh, area, timeout);
2146 }
2147 else if (lvl == IS_LEVEL_2)
2148 {
2149 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
2150 lsp_l2_refresh, area, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002151 }
hassof390d2c2004-09-10 20:48:21 +00002152 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002153
2154 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00002155 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002156 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
2157 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00002158 }
2159
2160 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002161}
2162
2163/*
2164 * Funcs for pseudonode LSPs
2165 */
2166
2167/*
2168 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
2169 */
hasso92365882005-01-18 13:53:33 +00002170static void
hassof390d2c2004-09-10 20:48:21 +00002171lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
2172 int level)
jardineb5d44e2003-12-23 08:09:43 +00002173{
2174 struct isis_adjacency *adj;
2175 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00002176 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002177 struct es_neigh *es_neigh;
2178 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002179 struct listnode *node;
Christian Franke80a8f722015-11-12 14:21:47 +01002180 struct isis_area *area = circuit->area;
2181
2182 lsp_debug("ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
2183 area->area_tag, rawlspid_print(lsp->lsp_header->lsp_id),
2184 circuit->interface->name, level);
hassof390d2c2004-09-10 20:48:21 +00002185
jardineb5d44e2003-12-23 08:09:43 +00002186 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002187 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002188 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2189 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00002190
2191 /*
2192 * add self to IS neighbours
2193 */
hassoaa4376e2005-09-26 17:39:48 +00002194 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00002195 {
hassoaa4376e2005-09-26 17:39:48 +00002196 if (lsp->tlv_data.is_neighs == NULL)
2197 {
2198 lsp->tlv_data.is_neighs = list_new ();
2199 lsp->tlv_data.is_neighs->del = free_tlv;
2200 }
2201 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002202
hassoaa4376e2005-09-26 17:39:48 +00002203 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2204 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002205 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
2206 area->area_tag, sysid_print(is_neigh->neigh_id),
2207 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002208 }
2209 if (circuit->area->newmetric)
2210 {
2211 if (lsp->tlv_data.te_is_neighs == NULL)
2212 {
2213 lsp->tlv_data.te_is_neighs = list_new ();
2214 lsp->tlv_data.te_is_neighs->del = free_tlv;
2215 }
2216 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2217
2218 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2219 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002220 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
2221 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2222 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002223 }
hassof390d2c2004-09-10 20:48:21 +00002224
2225 adj_list = list_new ();
2226 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
2227
hasso3fdb2dd2005-09-28 18:45:54 +00002228 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00002229 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002230 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00002231 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002232 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
2233 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00002234 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07002235 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00002236 {
2237 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00002238 if (circuit->area->oldmetric)
2239 {
2240 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002241
hassoaa4376e2005-09-26 17:39:48 +00002242 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2243 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002244 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
2245 area->area_tag, sysid_print(is_neigh->neigh_id),
2246 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002247 }
2248 if (circuit->area->newmetric)
2249 {
2250 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
2251 sizeof (struct te_is_neigh));
2252 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2253 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002254 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
2255 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2256 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002257 }
hassof390d2c2004-09-10 20:48:21 +00002258 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002259 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00002260 {
2261 /* an ES neigbour add it, if we are building level 1 LSP */
2262 /* FIXME: the tlv-format is hard to use here */
2263 if (lsp->tlv_data.es_neighs == NULL)
2264 {
2265 lsp->tlv_data.es_neighs = list_new ();
2266 lsp->tlv_data.es_neighs->del = free_tlv;
2267 }
paul15935e92005-05-03 09:27:23 +00002268 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2269
hassof390d2c2004-09-10 20:48:21 +00002270 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00002271 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002272 lsp_debug("ISIS (%s): Adding %s as ES neighbor (peer)",
2273 area->area_tag, sysid_print(es_neigh->first_es_neigh));
hassof390d2c2004-09-10 20:48:21 +00002274 }
Christian Franke80a8f722015-11-12 14:21:47 +01002275 else
2276 {
2277 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not match",
2278 area->area_tag, sysid_print(adj->sysid));
2279 }
2280 }
2281 else
2282 {
2283 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not intersect",
2284 area->area_tag, sysid_print(adj->sysid));
hassof390d2c2004-09-10 20:48:21 +00002285 }
jardineb5d44e2003-12-23 08:09:43 +00002286 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002287 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00002288
Christian Franke80a8f722015-11-12 14:21:47 +01002289 lsp_debug("ISIS (%s): Pseudo LSP construction is complete.", area->area_tag);
2290
hassoc0fb2a52005-09-03 16:29:40 +00002291 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00002292 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00002293 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2294
jardineb5d44e2003-12-23 08:09:43 +00002295 /*
2296 * Add the authentication info if it's present
2297 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002298 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002299
2300 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2301 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2302
hassoaa4376e2005-09-26 17:39:48 +00002303 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
2304 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
2305
jardineb5d44e2003-12-23 08:09:43 +00002306 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2307 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2308
paul9985f832005-02-09 15:51:56 +00002309 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002310
Josh Bailey3f045a02012-03-24 08:35:20 -07002311 /* Recompute authentication and checksum information */
2312 lsp_auth_update (lsp);
2313 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2314 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00002315
2316 return;
2317}
2318
Josh Bailey3f045a02012-03-24 08:35:20 -07002319int
2320lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002321{
2322 dict_t *lspdb = circuit->area->lspdb[level - 1];
2323 struct isis_lsp *lsp;
2324 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07002325 u_int16_t rem_lifetime, refresh_time;
2326
2327 if ((circuit->is_type & level) != level ||
2328 (circuit->state != C_STATE_UP) ||
2329 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2330 (circuit->u.bc.is_dr[level - 1] == 0))
2331 return ISIS_ERROR;
2332
2333 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2334 LSP_FRAGMENT (lsp_id) = 0;
2335 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2336
2337 /*
2338 * If for some reason have a pseudo LSP in the db already -> regenerate
2339 */
2340 if (lsp_search (lsp_id, lspdb))
2341 return lsp_regenerate_schedule_pseudo (circuit, level);
2342
2343 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2344 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Christian Frankef1fc1db2015-11-10 18:43:31 +01002345 lsp = lsp_new (circuit->area, lsp_id, rem_lifetime, 1,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002346 circuit->area->is_type | circuit->area->attached_bit,
2347 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07002348 lsp->area = circuit->area;
2349
2350 lsp_build_pseudo (lsp, circuit, level);
2351
2352 lsp->own_lsp = 1;
2353 lsp_insert (lsp, lspdb);
2354 lsp_set_all_srmflags (lsp);
2355
2356 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2357 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
2358 circuit->lsp_regenerate_pending[level - 1] = 0;
2359 if (level == IS_LEVEL_1)
2360 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2361 lsp_l1_refresh_pseudo, circuit, refresh_time);
2362 else if (level == IS_LEVEL_2)
2363 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2364 lsp_l2_refresh_pseudo, circuit, refresh_time);
2365
2366 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2367 {
2368 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
2369 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2370 circuit->area->area_tag, level,
2371 rawlspid_print (lsp->lsp_header->lsp_id),
2372 ntohl (lsp->lsp_header->pdu_len),
2373 ntohl (lsp->lsp_header->seq_num),
2374 ntohs (lsp->lsp_header->checksum),
2375 ntohs (lsp->lsp_header->rem_lifetime),
2376 refresh_time);
2377 }
2378
2379 return ISIS_OK;
2380}
2381
2382static int
2383lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2384{
2385 dict_t *lspdb = circuit->area->lspdb[level - 1];
2386 struct isis_lsp *lsp;
2387 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2388 u_int16_t rem_lifetime, refresh_time;
2389
2390 if ((circuit->is_type & level) != level ||
2391 (circuit->state != C_STATE_UP) ||
2392 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2393 (circuit->u.bc.is_dr[level - 1] == 0))
2394 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002395
jardineb5d44e2003-12-23 08:09:43 +00002396 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002397 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2398 LSP_FRAGMENT (lsp_id) = 0;
2399
jardineb5d44e2003-12-23 08:09:43 +00002400 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002401
2402 if (!lsp)
2403 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002404 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2405 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002406 return ISIS_ERROR;
2407 }
2408 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002409
2410 lsp_build_pseudo (lsp, circuit, level);
2411
Josh Bailey3f045a02012-03-24 08:35:20 -07002412 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002413 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2414 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002415 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2416 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002417 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002418 lsp->last_generated = time (NULL);
2419 lsp_set_all_srmflags (lsp);
2420
2421 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2422 if (level == IS_LEVEL_1)
2423 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2424 lsp_l1_refresh_pseudo, circuit, refresh_time);
2425 else if (level == IS_LEVEL_2)
2426 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2427 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002428
2429 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2430 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002431 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2432 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2433 circuit->area->area_tag, level,
2434 rawlspid_print (lsp->lsp_header->lsp_id),
2435 ntohl (lsp->lsp_header->pdu_len),
2436 ntohl (lsp->lsp_header->seq_num),
2437 ntohs (lsp->lsp_header->checksum),
2438 ntohs (lsp->lsp_header->rem_lifetime),
2439 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002440 }
jardineb5d44e2003-12-23 08:09:43 +00002441
jardineb5d44e2003-12-23 08:09:43 +00002442 return ISIS_OK;
2443}
2444
Josh Bailey3f045a02012-03-24 08:35:20 -07002445/*
2446 * Something has changed or periodic refresh -> regenerate pseudo LSP
2447 */
2448static int
jardineb5d44e2003-12-23 08:09:43 +00002449lsp_l1_refresh_pseudo (struct thread *thread)
2450{
2451 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002452 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002453
hassof390d2c2004-09-10 20:48:21 +00002454 circuit = THREAD_ARG (thread);
2455
hasso13c48f72004-09-10 21:19:13 +00002456 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002457 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002458
Josh Bailey3f045a02012-03-24 08:35:20 -07002459 if ((circuit->u.bc.is_dr[0] == 0) ||
2460 (circuit->is_type & IS_LEVEL_1) == 0)
2461 {
2462 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2463 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2464 LSP_FRAGMENT (id) = 0;
2465 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2466 return ISIS_ERROR;
2467 }
hassof390d2c2004-09-10 20:48:21 +00002468
Josh Bailey3f045a02012-03-24 08:35:20 -07002469 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002470}
2471
Josh Bailey3f045a02012-03-24 08:35:20 -07002472static int
jardineb5d44e2003-12-23 08:09:43 +00002473lsp_l2_refresh_pseudo (struct thread *thread)
2474{
2475 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002476 u_char id[ISIS_SYS_ID_LEN + 2];
2477
hassof390d2c2004-09-10 20:48:21 +00002478 circuit = THREAD_ARG (thread);
2479
hasso13c48f72004-09-10 21:19:13 +00002480 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002481 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002482
Josh Bailey3f045a02012-03-24 08:35:20 -07002483 if ((circuit->u.bc.is_dr[1] == 0) ||
2484 (circuit->is_type & IS_LEVEL_2) == 0)
2485 {
2486 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2487 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2488 LSP_FRAGMENT (id) = 0;
2489 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2490 return ISIS_ERROR;
2491 }
jardineb5d44e2003-12-23 08:09:43 +00002492
Josh Bailey3f045a02012-03-24 08:35:20 -07002493 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002494}
2495
hassof390d2c2004-09-10 20:48:21 +00002496int
Josh Bailey3f045a02012-03-24 08:35:20 -07002497lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002498{
2499 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002500 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2501 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01002502 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07002503 int lvl;
Christian Franke61010c32015-11-10 18:43:34 +01002504 struct isis_area *area = circuit->area;
jardineb5d44e2003-12-23 08:09:43 +00002505
Josh Bailey3f045a02012-03-24 08:35:20 -07002506 if (circuit == NULL ||
2507 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2508 circuit->state != C_STATE_UP)
2509 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002510
Christian Franke61010c32015-11-10 18:43:34 +01002511 sched_debug("ISIS (%s): Scheduling regeneration of %s pseudo LSP for interface %s",
2512 area->area_tag, circuit_t2string(level), circuit->interface->name);
2513
Josh Bailey3f045a02012-03-24 08:35:20 -07002514 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2515 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2516 LSP_FRAGMENT (lsp_id) = 0;
2517 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002518
Josh Bailey3f045a02012-03-24 08:35:20 -07002519 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2520 {
Christian Franke61010c32015-11-10 18:43:34 +01002521 sched_debug("ISIS (%s): Checking whether L%d pseudo LSP needs to be scheduled",
2522 area->area_tag, lvl);
jardineb5d44e2003-12-23 08:09:43 +00002523
Christian Franke61010c32015-11-10 18:43:34 +01002524 if (!((level & lvl) && (circuit->is_type & lvl)))
2525 {
2526 sched_debug("ISIS (%s): Level is not active on circuit",
2527 area->area_tag);
2528 continue;
2529 }
2530
2531 if (circuit->u.bc.is_dr[lvl - 1] == 0)
2532 {
2533 sched_debug("ISIS (%s): This IS is not DR, nothing to do.",
2534 area->area_tag);
2535 continue;
2536 }
2537
2538 if (circuit->lsp_regenerate_pending[lvl - 1])
2539 {
2540 struct timeval remain =
2541 thread_timer_remain(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2542 sched_debug("ISIS (%s): Regenerate is already pending, nothing todo."
2543 " (Due in %lld.%03lld seconds)", area->area_tag,
2544 (long long)remain.tv_sec, (long long)remain.tv_usec/1000);
2545 continue;
2546 }
hassof390d2c2004-09-10 20:48:21 +00002547
Josh Bailey3f045a02012-03-24 08:35:20 -07002548 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2549 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002550 {
2551 sched_debug("ISIS (%s): Pseudonode LSP does not exist yet, nothing to regenerate.",
2552 area->area_tag);
2553 continue;
2554 }
jardineb5d44e2003-12-23 08:09:43 +00002555
Josh Bailey3f045a02012-03-24 08:35:20 -07002556 /*
2557 * Throttle avoidance
2558 */
Christian Franke61010c32015-11-10 18:43:34 +01002559 sched_debug("ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
2560 area->area_tag, (long long)lsp->last_generated, (long long) now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002561 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2562 diff = now - lsp->last_generated;
2563 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2564 {
Christian Franke61010c32015-11-10 18:43:34 +01002565 timeout = 1000 * (circuit->area->lsp_gen_interval[lvl - 1] - diff);
2566 sched_debug("ISIS (%s): Sechduling in %ld ms to match configured lsp_gen_interval",
2567 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002568 }
2569 else
2570 {
Christian Franke61010c32015-11-10 18:43:34 +01002571 timeout = 100;
2572 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2573 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2574 }
2575
2576 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2577
2578 if (lvl == IS_LEVEL_1)
2579 {
2580 THREAD_TIMER_MSEC_ON(master,
2581 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2582 lsp_l1_refresh_pseudo, circuit, timeout);
2583 }
2584 else if (lvl == IS_LEVEL_2)
2585 {
2586 THREAD_TIMER_MSEC_ON(master,
2587 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2588 lsp_l2_refresh_pseudo, circuit, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002589 }
2590 }
jardineb5d44e2003-12-23 08:09:43 +00002591
Josh Bailey3f045a02012-03-24 08:35:20 -07002592 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002593}
2594
jardineb5d44e2003-12-23 08:09:43 +00002595/*
2596 * Walk through LSPs for an area
2597 * - set remaining lifetime
2598 * - set LSPs with SRMflag set for sending
2599 */
hassof390d2c2004-09-10 20:48:21 +00002600int
jardineb5d44e2003-12-23 08:09:43 +00002601lsp_tick (struct thread *thread)
2602{
2603 struct isis_area *area;
2604 struct isis_circuit *circuit;
2605 struct isis_lsp *lsp;
2606 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002607 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002608 dnode_t *dnode, *dnode_next;
2609 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002610 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002611
2612 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002613
jardineb5d44e2003-12-23 08:09:43 +00002614 area = THREAD_ARG (thread);
2615 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002616 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002617 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002618
2619 /*
2620 * Build a list of LSPs with (any) SRMflag set
2621 * and removed the ones that have aged out
2622 */
hassof390d2c2004-09-10 20:48:21 +00002623 for (level = 0; level < ISIS_LEVELS; level++)
2624 {
2625 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002626 {
2627 for (dnode = dict_first (area->lspdb[level]);
2628 dnode != NULL; dnode = dnode_next)
2629 {
2630 dnode_next = dict_next (area->lspdb[level], dnode);
2631 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002632
Josh Bailey3f045a02012-03-24 08:35:20 -07002633 /*
2634 * The lsp rem_lifetime is kept at 0 for MaxAge or
2635 * ZeroAgeLifetime depending on explicit purge or
2636 * natural age out. So schedule spf only once when
2637 * the first time rem_lifetime becomes 0.
2638 */
2639 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2640 lsp_set_time (lsp);
2641
2642 /*
2643 * Schedule may run spf which should be done only after
2644 * the lsp rem_lifetime becomes 0 for the first time.
2645 * ISO 10589 - 7.3.16.4 first paragraph.
2646 */
2647 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2648 {
2649 /* 7.3.16.4 a) set SRM flags on all */
2650 lsp_set_all_srmflags (lsp);
2651 /* 7.3.16.4 b) retain only the header FIXME */
2652 /* 7.3.16.4 c) record the time to purge FIXME */
2653 /* run/schedule spf */
2654 /* isis_spf_schedule is called inside lsp_destroy() below;
2655 * so it is not needed here. */
2656 /* isis_spf_schedule (lsp->area, lsp->level); */
2657 }
2658
2659 if (lsp->age_out == 0)
2660 {
2661 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2662 area->area_tag,
2663 lsp->level,
2664 rawlspid_print (lsp->lsp_header->lsp_id),
2665 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002666#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002667 if (lsp->from_topology)
2668 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002669#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002670 lsp_destroy (lsp);
2671 lsp = NULL;
2672 dict_delete_free (area->lspdb[level], dnode);
2673 }
2674 else if (flags_any_set (lsp->SRMflags))
2675 listnode_add (lsp_list, lsp);
2676 }
jardineb5d44e2003-12-23 08:09:43 +00002677
Josh Bailey3f045a02012-03-24 08:35:20 -07002678 /*
2679 * Send LSPs on circuits indicated by the SRMflags
2680 */
2681 if (listcount (lsp_list) > 0)
2682 {
paul1eb8ef22005-04-07 07:30:20 +00002683 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002684 {
2685 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2686 if (circuit->lsp_queue == NULL ||
2687 diff < MIN_LSP_TRANS_INTERVAL)
2688 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002689 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002690 {
2691 if (circuit->upadjcount[lsp->level - 1] &&
2692 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2693 {
2694 /* Add the lsp only if it is not already in lsp
2695 * queue */
2696 if (! listnode_lookup (circuit->lsp_queue, lsp))
2697 {
2698 listnode_add (circuit->lsp_queue, lsp);
2699 thread_add_event (master, send_lsp, circuit, 0);
2700 }
2701 }
2702 }
2703 }
2704 list_delete_all_node (lsp_list);
2705 }
2706 }
jardineb5d44e2003-12-23 08:09:43 +00002707 }
jardineb5d44e2003-12-23 08:09:43 +00002708
2709 list_delete (lsp_list);
2710
2711 return ISIS_OK;
2712}
2713
jardineb5d44e2003-12-23 08:09:43 +00002714void
Josh Bailey3f045a02012-03-24 08:35:20 -07002715lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002716{
2717 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002718 u_int16_t seq_num;
2719 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002720
jardineb5d44e2003-12-23 08:09:43 +00002721 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002722 if (!lsp)
2723 return;
hassof390d2c2004-09-10 20:48:21 +00002724
Josh Bailey3f045a02012-03-24 08:35:20 -07002725 /* store old values */
2726 seq_num = lsp->lsp_header->seq_num;
2727 lsp_bits = lsp->lsp_header->lsp_bits;
2728
2729 /* reset stream */
2730 lsp_clear_data (lsp);
2731 stream_reset (lsp->pdu);
2732
2733 /* update header */
2734 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2735 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2736 lsp->lsp_header->checksum = 0;
2737 lsp->lsp_header->seq_num = seq_num;
2738 lsp->lsp_header->rem_lifetime = 0;
2739 lsp->lsp_header->lsp_bits = lsp_bits;
2740 lsp->level = level;
2741 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2742 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2743
2744 /*
2745 * Add and update the authentication info if its present
2746 */
2747 lsp_auth_add (lsp);
2748 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2749 lsp_auth_update (lsp);
2750 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2751 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2752
2753 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002754
jardineb5d44e2003-12-23 08:09:43 +00002755 return;
2756}
2757
2758/*
2759 * Purge own LSP that is received and we don't have.
2760 * -> Do as in 7.3.16.4
2761 */
2762void
Christian Franke749e87a2015-11-10 18:21:44 +01002763lsp_purge_non_exist (int level,
2764 struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +00002765 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002766{
2767 struct isis_lsp *lsp;
2768
2769 /*
2770 * We need to create the LSP to be purged
2771 */
hassoaac372f2005-09-01 17:52:33 +00002772 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002773 lsp->area = area;
Christian Franke749e87a2015-11-10 18:21:44 +01002774 lsp->level = level;
Christian Frankef1fc1db2015-11-10 18:43:31 +01002775 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
hassof390d2c2004-09-10 20:48:21 +00002776 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002777 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002778 : L2_LINK_STATE);
2779 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2780 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002781 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002782 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002783
jardineb5d44e2003-12-23 08:09:43 +00002784 /*
jardineb5d44e2003-12-23 08:09:43 +00002785 * Set the remaining lifetime to 0
2786 */
2787 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002788
2789 /*
2790 * Add and update the authentication info if its present
2791 */
2792 lsp_auth_add (lsp);
2793 lsp_auth_update (lsp);
2794
2795 /*
2796 * Update the PDU length to header plus any authentication TLV.
2797 */
2798 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2799
jardineb5d44e2003-12-23 08:09:43 +00002800 /*
2801 * Put the lsp into LSPdb
2802 */
hassof390d2c2004-09-10 20:48:21 +00002803 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002804
2805 /*
2806 * Send in to whole area
2807 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002808 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002809
jardineb5d44e2003-12-23 08:09:43 +00002810 return;
2811}
2812
Josh Bailey3f045a02012-03-24 08:35:20 -07002813void lsp_set_all_srmflags (struct isis_lsp *lsp)
2814{
2815 struct listnode *node;
2816 struct isis_circuit *circuit;
2817
2818 assert (lsp);
2819
2820 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2821
2822 if (lsp->area)
2823 {
2824 struct list *circuit_list = lsp->area->circuit_list;
2825 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2826 {
2827 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2828 }
2829 }
2830}
2831
jardineb5d44e2003-12-23 08:09:43 +00002832#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002833static int
jardineb5d44e2003-12-23 08:09:43 +00002834top_lsp_refresh (struct thread *thread)
2835{
hassof390d2c2004-09-10 20:48:21 +00002836 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002837 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002838
2839 lsp = THREAD_ARG (thread);
2840 assert (lsp);
2841
2842 lsp->t_lsp_top_ref = NULL;
2843
hassof1082d12005-09-19 04:23:34 +00002844 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002845
Josh Bailey3f045a02012-03-24 08:35:20 -07002846 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002847 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2848 {
hasso529d65b2004-12-24 00:14:50 +00002849 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2850 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002851 }
hassod3d74742005-09-28 18:30:51 +00002852 /* Refresh dynamic hostname in the cache. */
2853 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2854 IS_LEVEL_1);
2855
David Lampartera47c5832012-06-21 09:55:38 +02002856 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002857 lsp->area->overload_bit,
2858 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002859 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2860 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002861
David Lamparterf50ee932015-03-04 07:13:38 +01002862 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002863 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002864 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002865
2866 return ISIS_OK;
2867}
2868
2869void
2870generate_topology_lsps (struct isis_area *area)
2871{
2872 struct listnode *node;
2873 int i, max = 0;
2874 struct arc *arc;
2875 u_char lspid[ISIS_SYS_ID_LEN + 2];
2876 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002877 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002878
2879 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002880 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002881 {
2882 if (arc->from_node > max)
2883 max = arc->from_node;
2884 if (arc->to_node > max)
2885 max = arc->to_node;
2886 }
jardineb5d44e2003-12-23 08:09:43 +00002887
hassof390d2c2004-09-10 20:48:21 +00002888 for (i = 1; i < (max + 1); i++)
2889 {
2890 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2891 LSP_PSEUDO_ID (lspid) = 0x00;
2892 LSP_FRAGMENT (lspid) = 0x00;
2893 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2894 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002895
Josh Bailey3f045a02012-03-24 08:35:20 -07002896 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Christian Frankef1fc1db2015-11-10 18:43:31 +01002897 lsp = lsp_new (area, lspid, rem_lifetime, 1,
2898 IS_LEVEL_1 | area->overload_bit | area->attached_bit,
2899 0, 1);
hassof1082d12005-09-19 04:23:34 +00002900 if (!lsp)
2901 return;
Josh Bailey3f045a02012-03-24 08:35:20 -07002902 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002903
hassof1082d12005-09-19 04:23:34 +00002904 /* Creating LSP data based on topology info. */
2905 build_topology_lsp_data (lsp, area, i);
2906 /* Checksum is also calculated here. */
2907 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002908 /* Take care of inserting dynamic hostname into cache. */
2909 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002910
Josh Bailey3f045a02012-03-24 08:35:20 -07002911 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002912 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002913 refresh_time);
2914 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002915 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002916 }
jardineb5d44e2003-12-23 08:09:43 +00002917}
2918
2919void
2920remove_topology_lsps (struct isis_area *area)
2921{
2922 struct isis_lsp *lsp;
2923 dnode_t *dnode, *dnode_next;
2924
2925 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002926 while (dnode != NULL)
2927 {
2928 dnode_next = dict_next (area->lspdb[0], dnode);
2929 lsp = dnode_get (dnode);
2930 if (lsp->from_topology)
2931 {
2932 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2933 lsp_destroy (lsp);
2934 dict_delete (area->lspdb[0], dnode);
2935 }
2936 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002937 }
jardineb5d44e2003-12-23 08:09:43 +00002938}
2939
2940void
hassof390d2c2004-09-10 20:48:21 +00002941build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002942 int lsp_top_num)
2943{
hasso3fdb2dd2005-09-28 18:45:54 +00002944 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002945 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002946 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002947 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002948 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002949 struct tlvs tlv_data;
2950 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002951
hassof1082d12005-09-19 04:23:34 +00002952 /* Add area addresses. FIXME: Is it needed at all? */
2953 if (lsp->tlv_data.area_addrs == NULL)
2954 lsp->tlv_data.area_addrs = list_new ();
2955 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002956
hassof1082d12005-09-19 04:23:34 +00002957 if (lsp->tlv_data.nlpids == NULL)
2958 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2959 lsp->tlv_data.nlpids->count = 1;
2960 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002961
hassof1082d12005-09-19 04:23:34 +00002962 if (area->dynhostname)
2963 {
2964 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2965 sizeof (struct hostname));
2966 memset (buff, 0x00, 200);
2967 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2968 "feedme", lsp_top_num);
2969 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2970 lsp->tlv_data.hostname->namelen = strlen (buff);
2971 }
2972
2973 if (lsp->tlv_data.nlpids)
2974 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2975 if (lsp->tlv_data.hostname)
2976 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2977 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2978 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2979
2980 memset (&tlv_data, 0, sizeof (struct tlvs));
2981 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002982 {
2983 tlv_data.is_neighs = list_new ();
2984 tlv_data.is_neighs->del = free_tlv;
2985 }
hassof1082d12005-09-19 04:23:34 +00002986
2987 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002988 if (lsp_top_num == 1)
2989 {
hasso3fdb2dd2005-09-28 18:45:54 +00002990 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002991
hassof390d2c2004-09-10 20:48:21 +00002992 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002993 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002994 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2995 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002996 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2997 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2998 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002999 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00003000 }
hassof390d2c2004-09-10 20:48:21 +00003001
hassof1082d12005-09-19 04:23:34 +00003002 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00003003 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00003004 {
hassof1082d12005-09-19 04:23:34 +00003005 int to_lsp = 0;
3006
3007 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
3008 continue;
3009
3010 if (lsp_top_num == arc->from_node)
3011 to_lsp = arc->to_node;
3012 else
3013 to_lsp = arc->from_node;
3014
hasso9551eea2005-09-28 18:26:25 +00003015 if (area->oldmetric)
3016 {
3017 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00003018
hasso9551eea2005-09-28 18:26:25 +00003019 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
3020 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
3021 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
3022 is_neigh->metrics.metric_default = arc->distance;
3023 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
3024 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
3025 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
3026 listnode_add (tlv_data.is_neighs, is_neigh);
3027 }
3028
3029 if (area->newmetric)
3030 {
hasso9551eea2005-09-28 18:26:25 +00003031 if (tlv_data.te_is_neighs == NULL)
3032 {
3033 tlv_data.te_is_neighs = list_new ();
3034 tlv_data.te_is_neighs->del = free_tlv;
3035 }
3036 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
3037 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
3038 ISIS_SYS_ID_LEN);
3039 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
3040 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07003041 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00003042 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
3043 }
hassof390d2c2004-09-10 20:48:21 +00003044 }
hassof1082d12005-09-19 04:23:34 +00003045
3046 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
3047 {
3048 if (lsp->tlv_data.is_neighs == NULL)
3049 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00003050 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00003051 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
3052 tlv_add_is_neighs);
3053 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
3054 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
3055 lsp0, area, IS_LEVEL_1);
3056 }
3057
hasso9551eea2005-09-28 18:26:25 +00003058 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
3059 {
3060 if (lsp->tlv_data.te_is_neighs == NULL)
3061 lsp->tlv_data.te_is_neighs = list_new ();
3062 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
3063 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
3064 tlv_add_te_is_neighs);
3065 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
3066 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
3067 lsp0, area, IS_LEVEL_1);
3068 }
3069
hassof1082d12005-09-19 04:23:34 +00003070 free_tlvs (&tlv_data);
3071 return;
jardineb5d44e2003-12-23 08:09:43 +00003072}
3073#endif /* TOPOLOGY_GENERATE */