blob: 7c64eaca177554a17cb2754ae430b225cff7704c [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"
55
56#ifdef TOPOLOGY_GENERATE
57#include "spgrid.h"
58#endif
59
hasso73d1aea2004-09-24 10:45:28 +000060/* staticly assigned vars for printing purposes */
61char lsp_bits_string[200]; /* FIXME: enough ? */
62
Josh Bailey3f045a02012-03-24 08:35:20 -070063static int lsp_l1_refresh (struct thread *thread);
64static int lsp_l2_refresh (struct thread *thread);
65static int lsp_l1_refresh_pseudo (struct thread *thread);
66static int lsp_l2_refresh_pseudo (struct thread *thread);
67
hassof390d2c2004-09-10 20:48:21 +000068int
69lsp_id_cmp (u_char * id1, u_char * id2)
70{
jardineb5d44e2003-12-23 08:09:43 +000071 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
72}
73
74dict_t *
hassof390d2c2004-09-10 20:48:21 +000075lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000076{
77 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000078
79 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
80
jardineb5d44e2003-12-23 08:09:43 +000081 return dict;
82}
83
84struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000085lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000086{
87 dnode_t *node;
88
hassof390d2c2004-09-10 20:48:21 +000089#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000090 dnode_t *dn;
91
hasso529d65b2004-12-24 00:14:50 +000092 zlog_debug ("searching db");
hassof390d2c2004-09-10 20:48:21 +000093 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
94 {
Josh Bailey3f045a02012-03-24 08:35:20 -070095 zlog_debug ("%s\t%pX", rawlspid_print ((u_char *) dnode_getkey (dn)),
hasso529d65b2004-12-24 00:14:50 +000096 dnode_get (dn));
hassof390d2c2004-09-10 20:48:21 +000097 }
jardineb5d44e2003-12-23 08:09:43 +000098#endif /* EXTREME DEBUG */
99
100 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000101
jardineb5d44e2003-12-23 08:09:43 +0000102 if (node)
hassof390d2c2004-09-10 20:48:21 +0000103 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000104
105 return NULL;
106}
107
hasso92365882005-01-18 13:53:33 +0000108static void
jardineb5d44e2003-12-23 08:09:43 +0000109lsp_clear_data (struct isis_lsp *lsp)
110{
111 if (!lsp)
112 return;
hassof390d2c2004-09-10 20:48:21 +0000113
Josh Bailey3f045a02012-03-24 08:35:20 -0700114 if (lsp->tlv_data.hostname)
115 isis_dynhn_remove (lsp->lsp_header->lsp_id);
116
hassof390d2c2004-09-10 20:48:21 +0000117 if (lsp->own_lsp)
118 {
119 if (lsp->tlv_data.nlpids)
Josh Bailey3f045a02012-03-24 08:35:20 -0700120 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
hassof390d2c2004-09-10 20:48:21 +0000121 if (lsp->tlv_data.hostname)
Josh Bailey3f045a02012-03-24 08:35:20 -0700122 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
123 if (lsp->tlv_data.router_id)
124 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.router_id);
hassof390d2c2004-09-10 20:48:21 +0000125 }
jardineb5d44e2003-12-23 08:09:43 +0000126
Josh Bailey3f045a02012-03-24 08:35:20 -0700127 free_tlvs (&lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000128}
129
hasso92365882005-01-18 13:53:33 +0000130static void
jardineb5d44e2003-12-23 08:09:43 +0000131lsp_destroy (struct isis_lsp *lsp)
132{
Josh Bailey3f045a02012-03-24 08:35:20 -0700133 struct listnode *cnode, *lnode, *lnnode;
134 struct isis_lsp *lsp_in_list;
135 struct isis_circuit *circuit;
136
jardineb5d44e2003-12-23 08:09:43 +0000137 if (!lsp)
138 return;
hassof390d2c2004-09-10 20:48:21 +0000139
Josh Bailey3f045a02012-03-24 08:35:20 -0700140 for (ALL_LIST_ELEMENTS_RO (lsp->area->circuit_list, cnode, circuit))
141 {
142 if (circuit->lsp_queue == NULL)
143 continue;
144 for (ALL_LIST_ELEMENTS (circuit->lsp_queue, lnode, lnnode, lsp_in_list))
145 if (lsp_in_list == lsp)
146 list_delete_node(circuit->lsp_queue, lnode);
147 }
148 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags);
149 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
150
jardineb5d44e2003-12-23 08:09:43 +0000151 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000152
153 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
154 {
jardineb5d44e2003-12-23 08:09:43 +0000155 list_delete (lsp->lspu.frags);
Josh Bailey3f045a02012-03-24 08:35:20 -0700156 lsp->lspu.frags = NULL;
hassof390d2c2004-09-10 20:48:21 +0000157 }
158
Josh Bailey3f045a02012-03-24 08:35:20 -0700159 isis_spf_schedule (lsp->area, lsp->level);
160#ifdef HAVE_IPV6
161 isis_spf_schedule6 (lsp->area, lsp->level);
162#endif
163
jardineb5d44e2003-12-23 08:09:43 +0000164 if (lsp->pdu)
165 stream_free (lsp->pdu);
166 XFREE (MTYPE_ISIS_LSP, lsp);
167}
168
hassof390d2c2004-09-10 20:48:21 +0000169void
170lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000171{
172 dnode_t *dnode, *next;
173 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000174
jardineb5d44e2003-12-23 08:09:43 +0000175 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000176 while (dnode)
177 {
178 next = dict_next (lspdb, dnode);
179 lsp = dnode_get (dnode);
180 lsp_destroy (lsp);
181 dict_delete_free (lspdb, dnode);
182 dnode = next;
183 }
184
jardineb5d44e2003-12-23 08:09:43 +0000185 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000186
jardineb5d44e2003-12-23 08:09:43 +0000187 return;
188}
189
190/*
191 * Remove all the frags belonging to the given lsp
192 */
hasso92365882005-01-18 13:53:33 +0000193static void
hassof390d2c2004-09-10 20:48:21 +0000194lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000195{
196 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000197 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000198 struct isis_lsp *lsp;
199
paul1eb8ef22005-04-07 07:30:20 +0000200 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000201 {
hassof390d2c2004-09-10 20:48:21 +0000202 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
203 lsp_destroy (lsp);
204 dnode_destroy (dict_delete (lspdb, dnode));
205 }
206
jardineb5d44e2003-12-23 08:09:43 +0000207 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000208
jardineb5d44e2003-12-23 08:09:43 +0000209 return;
210}
211
212void
hassof390d2c2004-09-10 20:48:21 +0000213lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000214{
215 dnode_t *node;
216 struct isis_lsp *lsp;
217
218 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000219 if (node)
220 {
221 node = dict_delete (lspdb, node);
222 lsp = dnode_get (node);
223 /*
224 * If this is a zero lsp, remove all the frags now
225 */
226 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
227 {
228 if (lsp->lspu.frags)
229 lsp_remove_frags (lsp->lspu.frags, lspdb);
230 }
231 else
232 {
233 /*
234 * else just remove this frag, from the zero lsps' frag list
235 */
236 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
237 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
238 }
239 lsp_destroy (lsp);
240 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000241 }
jardineb5d44e2003-12-23 08:09:43 +0000242}
243
244/*
245 * Compares a LSP to given values
246 * Params are given in net order
247 */
hassof390d2c2004-09-10 20:48:21 +0000248int
249lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000250 u_int16_t checksum, u_int16_t rem_lifetime)
251{
hassof390d2c2004-09-10 20:48:21 +0000252 /* no point in double ntohl on seqnum */
253 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000254 lsp->lsp_header->checksum == checksum &&
255 /*comparing with 0, no need to do ntohl */
256 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000257 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
258 {
259 if (isis->debugs & DEBUG_SNP_PACKETS)
260 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700261 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000262 " lifetime %us",
263 areatag,
264 rawlspid_print (lsp->lsp_header->lsp_id),
265 ntohl (lsp->lsp_header->seq_num),
266 ntohs (lsp->lsp_header->checksum),
267 ntohs (lsp->lsp_header->rem_lifetime));
268 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
269 " cksum 0x%04x, lifetime %us",
270 areatag,
271 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000272 }
273 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000274 }
jardineb5d44e2003-12-23 08:09:43 +0000275
hassof390d2c2004-09-10 20:48:21 +0000276 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
277 {
278 if (isis->debugs & DEBUG_SNP_PACKETS)
279 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700280 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000281 " lifetime %us",
282 areatag,
283 rawlspid_print (lsp->lsp_header->lsp_id),
284 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
285 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
286 "cksum 0x%04x, lifetime %us",
287 areatag,
288 ntohl (lsp->lsp_header->seq_num),
289 ntohs (lsp->lsp_header->checksum),
290 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000291 }
292 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000293 }
hassof390d2c2004-09-10 20:48:21 +0000294 if (isis->debugs & DEBUG_SNP_PACKETS)
295 {
hasso529d65b2004-12-24 00:14:50 +0000296 zlog_debug
Josh Bailey3f045a02012-03-24 08:35:20 -0700297 ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
hassof390d2c2004-09-10 20:48:21 +0000298 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
299 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000300 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
301 " cksum 0x%04x, lifetime %us", areatag,
302 ntohl (lsp->lsp_header->seq_num),
303 ntohs (lsp->lsp_header->checksum),
304 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000305 }
jardineb5d44e2003-12-23 08:09:43 +0000306
307 return LSP_OLDER;
308}
309
Josh Bailey3f045a02012-03-24 08:35:20 -0700310static void
311lsp_auth_add (struct isis_lsp *lsp)
312{
313 struct isis_passwd *passwd;
314 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
315
316 /*
317 * Add the authentication info if its present
318 */
319 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
320 (passwd = &lsp->area->domain_passwd);
321 switch (passwd->type)
322 {
323 /* Cleartext */
324 case ISIS_PASSWD_TYPE_CLEARTXT:
325 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
326 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
327 break;
328
329 /* HMAC MD5 */
330 case ISIS_PASSWD_TYPE_HMAC_MD5:
331 /* Remember where TLV is written so we can later
332 * overwrite the MD5 hash */
333 lsp->auth_tlv_offset = stream_get_endp (lsp->pdu);
334 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
335 lsp->tlv_data.auth_info.type = ISIS_PASSWD_TYPE_HMAC_MD5;
336 lsp->tlv_data.auth_info.len = ISIS_AUTH_MD5_SIZE;
337 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
338 ISIS_AUTH_MD5_SIZE);
339 tlv_add_authinfo (passwd->type, ISIS_AUTH_MD5_SIZE, hmac_md5_hash,
340 lsp->pdu);
341 break;
342
343 default:
344 break;
345 }
346}
347
348static void
349lsp_auth_update (struct isis_lsp *lsp)
350{
351 struct isis_passwd *passwd;
352 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
353 uint16_t checksum, rem_lifetime;
354
355 /* For HMAC MD5 we need to recompute the md5 hash and store it */
356 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
357 (passwd = &lsp->area->domain_passwd);
358 if (passwd->type != ISIS_PASSWD_TYPE_HMAC_MD5)
359 return;
360
361 /*
362 * In transient conditions (when net is configured where authentication
363 * config and lsp regenerate schedule is not yet run), there could be
364 * an own_lsp with auth_tlv_offset set to 0. In such a case, simply
365 * return, when lsp_regenerate is run, lsp will have auth tlv.
366 */
367 if (lsp->auth_tlv_offset == 0)
368 return;
369
370 /*
371 * RFC 5304 set auth value, checksum and remaining lifetime to zero
372 * before computation and reset to old values after computation.
373 */
374 checksum = lsp->lsp_header->checksum;
375 rem_lifetime = lsp->lsp_header->rem_lifetime;
376 lsp->lsp_header->checksum = 0;
377 lsp->lsp_header->rem_lifetime = 0;
378 /* Set the authentication value as well to zero */
379 memset (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
380 0, ISIS_AUTH_MD5_SIZE);
381 /* Compute autentication value */
382 hmac_md5 (STREAM_DATA (lsp->pdu), stream_get_endp(lsp->pdu),
383 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +0100384 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -0700385 /* Copy the hash into the stream */
386 memcpy (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
387 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
388 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
389 ISIS_AUTH_MD5_SIZE);
390 /* Copy back the checksum and remaining lifetime */
391 lsp->lsp_header->checksum = checksum;
392 lsp->lsp_header->rem_lifetime = rem_lifetime;
393}
394
hassof390d2c2004-09-10 20:48:21 +0000395void
jardineb5d44e2003-12-23 08:09:43 +0000396lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
397{
398 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000399
jardineb5d44e2003-12-23 08:09:43 +0000400 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
401 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
402 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700403 newseq = seq_num + 1;
hassof390d2c2004-09-10 20:48:21 +0000404
jardineb5d44e2003-12-23 08:09:43 +0000405 lsp->lsp_header->seq_num = htonl (newseq);
Josh Bailey3f045a02012-03-24 08:35:20 -0700406
407 /* Recompute authentication and checksum information */
408 lsp_auth_update (lsp);
409 /* ISO 10589 - 7.3.11 Generation of the checksum
410 * The checksum shall be computed over all fields in the LSP which appear
411 * after the Remaining Lifetime field. This field (and those appearing
412 * before it) are excluded so that the LSP may be aged by systems without
413 * requiring recomputation.
414 */
415 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
416 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
417
418 isis_spf_schedule (lsp->area, lsp->level);
419#ifdef HAVE_IPV6
420 isis_spf_schedule6 (lsp->area, lsp->level);
421#endif
jardineb5d44e2003-12-23 08:09:43 +0000422
423 return;
424}
425
426/*
427 * Genetates checksum for LSP and its frags
428 */
hasso92365882005-01-18 13:53:33 +0000429static void
jardineb5d44e2003-12-23 08:09:43 +0000430lsp_seqnum_update (struct isis_lsp *lsp0)
431{
432 struct isis_lsp *lsp;
hasso3fdb2dd2005-09-28 18:45:54 +0000433 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000434
jardineb5d44e2003-12-23 08:09:43 +0000435 lsp_inc_seqnum (lsp0, 0);
436
437 if (!lsp0->lspu.frags)
438 return;
439
hasso3fdb2dd2005-09-28 18:45:54 +0000440 for (ALL_LIST_ELEMENTS_RO (lsp0->lspu.frags, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +0000441 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000442
jardineb5d44e2003-12-23 08:09:43 +0000443 return;
444}
445
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700446static u_int8_t
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700447lsp_bits_generate (int level, int overload_bit, int attached_bit)
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700448{
449 u_int8_t lsp_bits = 0;
450 if (level == IS_LEVEL_1)
451 lsp_bits = IS_LEVEL_1;
452 else
453 lsp_bits = IS_LEVEL_1_AND_2;
454 if (overload_bit)
455 lsp_bits |= overload_bit;
Amritha Nambiarc8ee9402015-08-24 16:40:14 -0700456 if (attached_bit)
457 lsp_bits |= attached_bit;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700458 return lsp_bits;
459}
460
hasso92365882005-01-18 13:53:33 +0000461static void
hassof390d2c2004-09-10 20:48:21 +0000462lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
Josh Bailey3f045a02012-03-24 08:35:20 -0700463 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000464{
hassof390d2c2004-09-10 20:48:21 +0000465 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000466 int retval;
hassof390d2c2004-09-10 20:48:21 +0000467
Josh Bailey3f045a02012-03-24 08:35:20 -0700468 /* free the old lsp data */
469 lsp_clear_data (lsp);
470
jardineb5d44e2003-12-23 08:09:43 +0000471 /* copying only the relevant part of our stream */
Josh Bailey3f045a02012-03-24 08:35:20 -0700472 if (lsp->pdu != NULL)
473 stream_free (lsp->pdu);
paul15935e92005-05-03 09:27:23 +0000474 lsp->pdu = stream_dup (stream);
Josh Bailey3f045a02012-03-24 08:35:20 -0700475
jardineb5d44e2003-12-23 08:09:43 +0000476 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000477 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
478 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
479 ISIS_FIXED_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -0700480 lsp->area = area;
481 lsp->level = level;
jardineb5d44e2003-12-23 08:09:43 +0000482 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000483 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000484 /*
485 * Get LSP data i.e. TLVs
486 */
487 expected |= TLVFLAG_AUTH_INFO;
488 expected |= TLVFLAG_AREA_ADDRS;
489 expected |= TLVFLAG_IS_NEIGHS;
jardineb5d44e2003-12-23 08:09:43 +0000490 expected |= TLVFLAG_NLPID;
491 if (area->dynhostname)
492 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000493 if (area->newmetric)
494 {
495 expected |= TLVFLAG_TE_IS_NEIGHS;
496 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
497 expected |= TLVFLAG_TE_ROUTER_ID;
498 }
jardineb5d44e2003-12-23 08:09:43 +0000499 expected |= TLVFLAG_IPV4_ADDR;
500 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
501 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
502#ifdef HAVE_IPV6
503 expected |= TLVFLAG_IPV6_ADDR;
504 expected |= TLVFLAG_IPV6_REACHABILITY;
505#endif /* HAVE_IPV6 */
506
Josh Bailey3f045a02012-03-24 08:35:20 -0700507 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
508 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
509 ntohs (lsp->lsp_header->pdu_len) -
510 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
511 &expected, &found, &lsp->tlv_data,
512 NULL);
513 if (retval != ISIS_OK)
hassof390d2c2004-09-10 20:48:21 +0000514 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700515 zlog_warn ("Could not parse LSP");
516 return;
517 }
518
519 if ((found & TLVFLAG_DYN_HOSTNAME) && (area->dynhostname))
520 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700521 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
522 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
523 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : IS_LEVEL_1);
hassof390d2c2004-09-10 20:48:21 +0000524 }
jardineb5d44e2003-12-23 08:09:43 +0000525
Josh Bailey3f045a02012-03-24 08:35:20 -0700526 return;
jardineb5d44e2003-12-23 08:09:43 +0000527}
528
529void
Josh Bailey3f045a02012-03-24 08:35:20 -0700530lsp_update (struct isis_lsp *lsp, struct stream *stream,
531 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000532{
hasso4eda93a2005-09-18 17:51:02 +0000533 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000534
Josh Bailey3f045a02012-03-24 08:35:20 -0700535 /* Remove old LSP from database. This is required since the
536 * lsp_update_data will free the lsp->pdu (which has the key, lsp_id)
537 * and will update it with the new data in the stream. */
hasso4eda93a2005-09-18 17:51:02 +0000538 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
539 if (dnode)
540 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000541
jardineb5d44e2003-12-23 08:09:43 +0000542 /* rebuild the lsp data */
Josh Bailey3f045a02012-03-24 08:35:20 -0700543 lsp_update_data (lsp, stream, area, level);
jardineb5d44e2003-12-23 08:09:43 +0000544
Josh Bailey3f045a02012-03-24 08:35:20 -0700545 /* insert the lsp back into the database */
546 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000547}
548
jardineb5d44e2003-12-23 08:09:43 +0000549/* creation of LSP directly from what we received */
550struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000551lsp_new_from_stream_ptr (struct stream *stream,
552 u_int16_t pdu_len, struct isis_lsp *lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -0700553 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000554{
555 struct isis_lsp *lsp;
556
hassoaac372f2005-09-01 17:52:33 +0000557 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -0700558 lsp_update_data (lsp, stream, area, level);
hassof390d2c2004-09-10 20:48:21 +0000559
560 if (lsp0 == NULL)
561 {
562 /*
563 * zero lsp -> create the list for fragments
564 */
565 lsp->lspu.frags = list_new ();
566 }
567 else
568 {
569 /*
570 * a fragment -> set the backpointer and add this to zero lsps frag list
571 */
572 lsp->lspu.zero_lsp = lsp0;
573 listnode_add (lsp0->lspu.frags, lsp);
574 }
575
jardineb5d44e2003-12-23 08:09:43 +0000576 return lsp;
577}
578
579struct isis_lsp *
Christian Frankef1fc1db2015-11-10 18:43:31 +0100580lsp_new(struct isis_area *area, u_char * lsp_id,
581 u_int16_t rem_lifetime, u_int32_t seq_num,
582 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000583{
584 struct isis_lsp *lsp;
585
hassoaac372f2005-09-01 17:52:33 +0000586 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Christian Frankef1fc1db2015-11-10 18:43:31 +0100587 lsp->area = area;
Christian Franke390f16e2015-11-10 18:04:44 +0100588
Christian Frankef1fc1db2015-11-10 18:43:31 +0100589 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
jardineb5d44e2003-12-23 08:09:43 +0000590 if (LSP_FRAGMENT (lsp_id) == 0)
591 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000592 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
593 lsp->lsp_header = (struct isis_link_state_hdr *)
594 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
595
jardineb5d44e2003-12-23 08:09:43 +0000596 /* at first we fill the FIXED HEADER */
Josh Bailey3f045a02012-03-24 08:35:20 -0700597 (level == IS_LEVEL_1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
hassof390d2c2004-09-10 20:48:21 +0000598 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
599
jardineb5d44e2003-12-23 08:09:43 +0000600 /* now for the LSP HEADER */
601 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000602 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000603 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000604 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000605 lsp->lsp_header->seq_num = htonl (seq_num);
606 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
607 lsp->lsp_header->lsp_bits = lsp_bits;
608 lsp->level = level;
609 lsp->age_out = ZERO_AGE_LIFETIME;
610
paul9985f832005-02-09 15:51:56 +0000611 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000612
hassoc89c05d2005-09-04 21:36:36 +0000613 if (isis->debugs & DEBUG_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -0700614 zlog_debug ("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
hassoc89c05d2005-09-04 21:36:36 +0000615 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
616 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
Josh Bailey3f045a02012-03-24 08:35:20 -0700617 ntohl (lsp->lsp_header->pdu_len),
hassoc89c05d2005-09-04 21:36:36 +0000618 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000619
620 return lsp;
621}
622
623void
hassof390d2c2004-09-10 20:48:21 +0000624lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000625{
626 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -0700627 if (lsp->lsp_header->seq_num != 0)
628 {
629 isis_spf_schedule (lsp->area, lsp->level);
630#ifdef HAVE_IPV6
631 isis_spf_schedule6 (lsp->area, lsp->level);
632#endif
633 }
jardineb5d44e2003-12-23 08:09:43 +0000634}
635
636/*
637 * Build a list of LSPs with non-zero ht bounded by start and stop ids
638 */
hassof390d2c2004-09-10 20:48:21 +0000639void
640lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
641 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000642{
643 dnode_t *first, *last, *curr;
644
645 first = dict_lower_bound (lspdb, start_id);
646 if (!first)
647 return;
hassof390d2c2004-09-10 20:48:21 +0000648
jardineb5d44e2003-12-23 08:09:43 +0000649 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000650
jardineb5d44e2003-12-23 08:09:43 +0000651 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000652
653 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000654 listnode_add (list, first->dict_data);
655
hassof390d2c2004-09-10 20:48:21 +0000656 while (curr)
657 {
658 curr = dict_next (lspdb, curr);
659 if (curr &&
660 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
661 listnode_add (list, curr->dict_data);
662 if (curr == last)
663 break;
664 }
665
jardineb5d44e2003-12-23 08:09:43 +0000666 return;
667}
668
669/*
Josh Bailey3f045a02012-03-24 08:35:20 -0700670 * Build a list of num_lsps LSPs bounded by start_id and stop_id.
jardineb5d44e2003-12-23 08:09:43 +0000671 */
hassof390d2c2004-09-10 20:48:21 +0000672void
Josh Bailey3f045a02012-03-24 08:35:20 -0700673lsp_build_list (u_char * start_id, u_char * stop_id, u_char num_lsps,
hassof390d2c2004-09-10 20:48:21 +0000674 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000675{
Josh Bailey3f045a02012-03-24 08:35:20 -0700676 u_char count;
jardineb5d44e2003-12-23 08:09:43 +0000677 dnode_t *first, *last, *curr;
678
679 first = dict_lower_bound (lspdb, start_id);
680 if (!first)
681 return;
hassof390d2c2004-09-10 20:48:21 +0000682
jardineb5d44e2003-12-23 08:09:43 +0000683 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000684
jardineb5d44e2003-12-23 08:09:43 +0000685 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000686
jardineb5d44e2003-12-23 08:09:43 +0000687 listnode_add (list, first->dict_data);
Josh Bailey3f045a02012-03-24 08:35:20 -0700688 count = 1;
jardineb5d44e2003-12-23 08:09:43 +0000689
hassof390d2c2004-09-10 20:48:21 +0000690 while (curr)
691 {
692 curr = dict_next (lspdb, curr);
693 if (curr)
Josh Bailey3f045a02012-03-24 08:35:20 -0700694 {
695 listnode_add (list, curr->dict_data);
696 count++;
697 }
698 if (count == num_lsps || curr == last)
699 break;
hassof390d2c2004-09-10 20:48:21 +0000700 }
701
jardineb5d44e2003-12-23 08:09:43 +0000702 return;
703}
704
705/*
706 * Build a list of LSPs with SSN flag set for the given circuit
707 */
708void
Josh Bailey3f045a02012-03-24 08:35:20 -0700709lsp_build_list_ssn (struct isis_circuit *circuit, u_char num_lsps,
710 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000711{
712 dnode_t *dnode, *next;
713 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -0700714 u_char count = 0;
hassof390d2c2004-09-10 20:48:21 +0000715
jardineb5d44e2003-12-23 08:09:43 +0000716 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000717 while (dnode != NULL)
718 {
719 next = dict_next (lspdb, dnode);
720 lsp = dnode_get (dnode);
721 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -0700722 {
723 listnode_add (list, lsp);
724 ++count;
725 }
726 if (count == num_lsps)
727 break;
hassof390d2c2004-09-10 20:48:21 +0000728 dnode = next;
729 }
730
jardineb5d44e2003-12-23 08:09:43 +0000731 return;
732}
733
hasso92365882005-01-18 13:53:33 +0000734static void
jardineb5d44e2003-12-23 08:09:43 +0000735lsp_set_time (struct isis_lsp *lsp)
736{
737 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000738
739 if (lsp->lsp_header->rem_lifetime == 0)
740 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700741 if (lsp->age_out > 0)
742 lsp->age_out--;
hassof390d2c2004-09-10 20:48:21 +0000743 return;
744 }
jardineb5d44e2003-12-23 08:09:43 +0000745
hassof390d2c2004-09-10 20:48:21 +0000746 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000747 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
748}
749
hasso92365882005-01-18 13:53:33 +0000750static void
hassof390d2c2004-09-10 20:48:21 +0000751lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000752{
753 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000754 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000755
756 if (dynhost)
757 dyn = dynhn_find_by_id (lsp_id);
758 else
759 dyn = NULL;
760
761 if (dyn)
Josh Bailey3f045a02012-03-24 08:35:20 -0700762 sprintf ((char *)id, "%.14s", dyn->name.name);
763 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
764 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000765 else
hassof390d2c2004-09-10 20:48:21 +0000766 memcpy (id, sysid_print (lsp_id), 15);
hassof390d2c2004-09-10 20:48:21 +0000767 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000768 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000769 LSP_FRAGMENT (lsp_id));
770 else
hassof7c43dc2004-09-26 16:24:14 +0000771 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000772}
773
hassof390d2c2004-09-10 20:48:21 +0000774/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000775const char *
hassof390d2c2004-09-10 20:48:21 +0000776lsp_bits2string (u_char * lsp_bits)
777{
778 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000779
hassof390d2c2004-09-10 20:48:21 +0000780 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000781 return " none";
782
783 /* we only focus on the default metric */
784 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000785 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000786
787 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000788 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000789
hassof390d2c2004-09-10 20:48:21 +0000790 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
791
jardineb5d44e2003-12-23 08:09:43 +0000792 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000793
hassof390d2c2004-09-10 20:48:21 +0000794 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000795}
796
797/* this function prints the lsp on show isis database */
Josh Bailey3f045a02012-03-24 08:35:20 -0700798void
799lsp_print (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000800{
jardineb5d44e2003-12-23 08:09:43 +0000801 u_char LSPid[255];
Josh Bailey3f045a02012-03-24 08:35:20 -0700802 char age_out[8];
jardineb5d44e2003-12-23 08:09:43 +0000803
804 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700805 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
806 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->pdu_len));
807 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
808 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
hassof390d2c2004-09-10 20:48:21 +0000809 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
Josh Bailey3f045a02012-03-24 08:35:20 -0700810 {
811 snprintf (age_out, 8, "(%u)", lsp->age_out);
812 age_out[7] = '\0';
813 vty_out (vty, "%7s ", age_out);
814 }
jardineb5d44e2003-12-23 08:09:43 +0000815 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700816 vty_out (vty, " %5u ", ntohs (lsp->lsp_header->rem_lifetime));
817 vty_out (vty, "%s%s",
818 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000819}
820
Josh Bailey3f045a02012-03-24 08:35:20 -0700821void
822lsp_print_detail (struct isis_lsp *lsp, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000823{
jardineb5d44e2003-12-23 08:09:43 +0000824 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000825 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000826 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000827 struct is_neigh *is_neigh;
828 struct te_is_neigh *te_is_neigh;
829 struct ipv4_reachability *ipv4_reach;
830 struct in_addr *ipv4_addr;
831 struct te_ipv4_reachability *te_ipv4_reach;
832#ifdef HAVE_IPV6
833 struct ipv6_reachability *ipv6_reach;
834 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000835 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000836#endif
837 u_char LSPid[255];
838 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000839 u_char ipv4_reach_prefix[20];
840 u_char ipv4_reach_mask[20];
841 u_char ipv4_address[20];
842
843 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
Josh Bailey3f045a02012-03-24 08:35:20 -0700844 lsp_print (lsp, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000845
846 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000847 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000848 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000849 {
hasso1cd80842004-10-07 20:07:40 +0000850 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000851 isonet_print (area_addr->area_addr, area_addr->addr_len),
852 VTY_NEWLINE);
853 }
paul1eb8ef22005-04-07 07:30:20 +0000854
jardineb5d44e2003-12-23 08:09:43 +0000855 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000856 if (lsp->tlv_data.nlpids)
857 {
858 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
859 {
860 switch (lsp->tlv_data.nlpids->nlpids[i])
861 {
862 case NLPID_IP:
863 case NLPID_IPV6:
Josh Bailey3f045a02012-03-24 08:35:20 -0700864 vty_out (vty, " NLPID : 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000865 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
866 break;
867 default:
Josh Bailey3f045a02012-03-24 08:35:20 -0700868 vty_out (vty, " NLPID : %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000869 break;
870 }
871 }
872 }
jardineb5d44e2003-12-23 08:09:43 +0000873
874 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000875 if (lsp->tlv_data.hostname)
876 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700877 bzero (hostname, sizeof (hostname));
hassof390d2c2004-09-10 20:48:21 +0000878 memcpy (hostname, lsp->tlv_data.hostname->name,
879 lsp->tlv_data.hostname->namelen);
Josh Bailey3f045a02012-03-24 08:35:20 -0700880 vty_out (vty, " Hostname : %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000881 }
hassof390d2c2004-09-10 20:48:21 +0000882
Josh Bailey3f045a02012-03-24 08:35:20 -0700883 /* authentication tlv */
884 if (lsp->tlv_data.auth_info.type != ISIS_PASSWD_TYPE_UNUSED)
885 {
886 if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_HMAC_MD5)
887 vty_out (vty, " Auth type : md5%s", VTY_NEWLINE);
888 else if (lsp->tlv_data.auth_info.type == ISIS_PASSWD_TYPE_CLEARTXT)
889 vty_out (vty, " Auth type : clear text%s", VTY_NEWLINE);
890 }
hassof390d2c2004-09-10 20:48:21 +0000891
hasso1cd80842004-10-07 20:07:40 +0000892 /* TE router id */
893 if (lsp->tlv_data.router_id)
894 {
895 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
896 sizeof (ipv4_address));
Josh Bailey3f045a02012-03-24 08:35:20 -0700897 vty_out (vty, " Router ID : %s%s", ipv4_address, VTY_NEWLINE);
hasso1cd80842004-10-07 20:07:40 +0000898 }
899
Josh Bailey3f045a02012-03-24 08:35:20 -0700900 if (lsp->tlv_data.ipv4_addrs)
901 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
902 {
903 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
904 vty_out (vty, " IPv4 Address: %s%s", ipv4_address, VTY_NEWLINE);
905 }
906
hasso1cd80842004-10-07 20:07:40 +0000907 /* for the IS neighbor tlv */
908 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000909 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000910 {
911 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700912 vty_out (vty, " Metric : %-8d IS : %s%s",
hasso1cd80842004-10-07 20:07:40 +0000913 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
914 }
hasso1cd80842004-10-07 20:07:40 +0000915
jardineb5d44e2003-12-23 08:09:43 +0000916 /* for the internal reachable tlv */
917 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000918 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
919 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000920 {
921 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
922 sizeof (ipv4_reach_prefix));
923 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
924 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700925 vty_out (vty, " Metric : %-8d IPv4-Internal : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000926 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
927 ipv4_reach_mask, VTY_NEWLINE);
928 }
hasso2097cd82003-12-23 11:51:08 +0000929
930 /* for the external reachable tlv */
931 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000932 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
933 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000934 {
935 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
936 sizeof (ipv4_reach_prefix));
937 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
938 sizeof (ipv4_reach_mask));
Josh Bailey3f045a02012-03-24 08:35:20 -0700939 vty_out (vty, " Metric : %-8d IPv4-External : %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000940 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
941 ipv4_reach_mask, VTY_NEWLINE);
942 }
paul1eb8ef22005-04-07 07:30:20 +0000943
hasso2097cd82003-12-23 11:51:08 +0000944 /* IPv6 tlv */
945#ifdef HAVE_IPV6
946 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000947 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000948 {
949 memset (&in6, 0, sizeof (in6));
950 memcpy (in6.s6_addr, ipv6_reach->prefix,
951 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000952 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
David Lamparter6db3ef62015-03-03 09:07:43 +0100953 if ((ipv6_reach->control_info &
hassof390d2c2004-09-10 20:48:21 +0000954 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
Josh Bailey3f045a02012-03-24 08:35:20 -0700955 vty_out (vty, " Metric : %-8d IPv6-Internal : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000956 ntohl (ipv6_reach->metric),
957 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000958 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700959 vty_out (vty, " Metric : %-8d IPv6-External : %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000960 ntohl (ipv6_reach->metric),
961 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000962 }
963#endif
paul1eb8ef22005-04-07 07:30:20 +0000964
hasso1cd80842004-10-07 20:07:40 +0000965 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000966 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000967 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000968 {
hassof390d2c2004-09-10 20:48:21 +0000969 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -0700970 vty_out (vty, " Metric : %-8d IS-Extended : %s%s",
971 GET_TE_METRIC(te_is_neigh), LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000972 }
jardineb5d44e2003-12-23 08:09:43 +0000973
hasso1cd80842004-10-07 20:07:40 +0000974 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000975 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000976 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
977 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000978 {
hasso1cd80842004-10-07 20:07:40 +0000979 /* FIXME: There should be better way to output this stuff. */
Josh Bailey3f045a02012-03-24 08:35:20 -0700980 vty_out (vty, " Metric : %-8d IPv4-Extended : %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000981 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000982 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
983 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000984 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000985 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700986 vty_out (vty, "%s", VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000987
hassof390d2c2004-09-10 20:48:21 +0000988 return;
jardineb5d44e2003-12-23 08:09:43 +0000989}
990
991/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000992int
993lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000994{
995
hassof390d2c2004-09-10 20:48:21 +0000996 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000997 int lsp_count = 0;
998
hassof390d2c2004-09-10 20:48:21 +0000999 if (detail == ISIS_UI_LEVEL_BRIEF)
1000 {
1001 while (node != NULL)
1002 {
1003 /* I think it is unnecessary, so I comment it out */
1004 /* dict_contains (lspdb, node); */
1005 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001006 lsp_print (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001007 node = next;
1008 lsp_count++;
1009 }
jardineb5d44e2003-12-23 08:09:43 +00001010 }
hassof390d2c2004-09-10 20:48:21 +00001011 else if (detail == ISIS_UI_LEVEL_DETAIL)
1012 {
1013 while (node != NULL)
1014 {
1015 next = dict_next (lspdb, node);
Josh Bailey3f045a02012-03-24 08:35:20 -07001016 lsp_print_detail (dnode_get (node), vty, dynhost);
hassof390d2c2004-09-10 20:48:21 +00001017 node = next;
1018 lsp_count++;
1019 }
jardineb5d44e2003-12-23 08:09:43 +00001020 }
jardineb5d44e2003-12-23 08:09:43 +00001021
1022 return lsp_count;
1023}
1024
jardineb5d44e2003-12-23 08:09:43 +00001025#define FRAG_THOLD(S,T) \
Josh Bailey3f045a02012-03-24 08:35:20 -07001026 ((STREAM_SIZE(S)*T)/100)
jardineb5d44e2003-12-23 08:09:43 +00001027
1028/* stream*, area->lsp_frag_threshold, increment */
1029#define FRAG_NEEDED(S,T,I) \
1030 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1031
hassoaa4376e2005-09-26 17:39:48 +00001032/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
1033 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +00001034static void
jardineb5d44e2003-12-23 08:09:43 +00001035lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001036 int tlvsize, int frag_thold,
1037 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001038{
1039 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001040
jardineb5d44e2003-12-23 08:09:43 +00001041 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001042 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1043 {
1044 tlv_build_func (*from, lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07001045 if (listcount (*to) != 0)
1046 {
1047 struct listnode *node, *nextnode;
1048 void *elem;
1049
1050 for (ALL_LIST_ELEMENTS (*from, node, nextnode, elem))
1051 {
1052 listnode_add (*to, elem);
1053 list_delete_node (*from, node);
1054 }
1055 }
1056 else
1057 {
1058 list_free (*to);
1059 *to = *from;
1060 *from = NULL;
1061 }
jardineb5d44e2003-12-23 08:09:43 +00001062 }
hassof390d2c2004-09-10 20:48:21 +00001063 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1064 {
1065 /* fit all we can */
1066 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1067 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
Josh Bailey3f045a02012-03-24 08:35:20 -07001068 count = count / tlvsize;
1069 if (count > (int)listcount (*from))
1070 count = listcount (*from);
hassof390d2c2004-09-10 20:48:21 +00001071 for (i = 0; i < count; i++)
1072 {
paul1eb8ef22005-04-07 07:30:20 +00001073 listnode_add (*to, listgetdata (listhead (*from)));
1074 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001075 }
1076 tlv_build_func (*to, lsp->pdu);
1077 }
paul9985f832005-02-09 15:51:56 +00001078 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001079 return;
1080}
1081
Josh Bailey3f045a02012-03-24 08:35:20 -07001082static u_int16_t
1083lsp_rem_lifetime (struct isis_area *area, int level)
1084{
1085 u_int16_t rem_lifetime;
1086
1087 /* Add jitter to configured LSP lifetime */
1088 rem_lifetime = isis_jitter (area->max_lsp_lifetime[level - 1],
1089 MAX_AGE_JITTER);
1090
1091 /* No jitter if the max refresh will be less than configure gen interval */
Christian Franke9dfcca62015-11-10 18:32:11 +01001092 /* N.B. this calucation is acceptable since rem_lifetime is in [332,65535] at
1093 * this point */
Josh Bailey3f045a02012-03-24 08:35:20 -07001094 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1095 rem_lifetime = area->max_lsp_lifetime[level - 1];
1096
1097 return rem_lifetime;
1098}
1099
1100static u_int16_t
1101lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1102{
1103 struct isis_area *area = lsp->area;
1104 int level = lsp->level;
1105 u_int16_t refresh_time;
1106
1107 /* Add jitter to LSP refresh time */
1108 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1109 MAX_LSP_GEN_JITTER);
1110
1111 /* RFC 4444 : make sure the refresh time is at least less than 300
1112 * of the remaining lifetime and more than gen interval */
1113 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1114 refresh_time > (rem_lifetime - 300))
1115 refresh_time = rem_lifetime - 300;
1116
Christian Franke9dfcca62015-11-10 18:32:11 +01001117 /* In cornercases, refresh_time might be <= lsp_gen_interval, however
1118 * we accept this violation to satisfy refresh_time <= rem_lifetime - 300 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001119
1120 return refresh_time;
1121}
1122
hasso92365882005-01-18 13:53:33 +00001123static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001124lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1125 int level)
jardineb5d44e2003-12-23 08:09:43 +00001126{
1127 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001128 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1129
jardineb5d44e2003-12-23 08:09:43 +00001130 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1131 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001132 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001133 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001134 if (lsp)
1135 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001136 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001137 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001138 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001139 }
Christian Frankef1fc1db2015-11-10 18:43:31 +01001140 lsp = lsp_new (area, frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001141 lsp_bits_generate (level, area->overload_bit,
1142 area->attached_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001143 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001144 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001145 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001146 listnode_add (lsp0->lspu.frags, lsp);
1147 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001148 return lsp;
1149}
1150
Christian Frankeacf98652015-11-12 14:24:22 +01001151static void
1152lsp_build_ext_reach_ipv4(struct isis_lsp *lsp, struct isis_area *area,
1153 struct tlvs *tlv_data)
1154{
1155 struct route_table *er_table;
1156 struct route_node *rn;
1157 struct prefix_ipv4 *ipv4;
1158 struct isis_ext_info *info;
1159 struct ipv4_reachability *ipreach;
1160 struct te_ipv4_reachability *te_ipreach;
1161
1162 er_table = get_ext_reach(area, AF_INET, lsp->level);
1163 if (!er_table)
1164 return;
1165
1166 for (rn = route_top(er_table); rn; rn = route_next(rn))
1167 {
1168 if (!rn->info)
1169 continue;
1170
1171 ipv4 = (struct prefix_ipv4*)&rn->p;
1172 info = rn->info;
1173 if (area->oldmetric)
1174 {
1175 if (tlv_data->ipv4_ext_reachs == NULL)
1176 {
1177 tlv_data->ipv4_ext_reachs = list_new();
1178 tlv_data->ipv4_ext_reachs->del = free_tlv;
1179 }
1180 ipreach = XMALLOC(MTYPE_ISIS_TLV, sizeof(*ipreach));
1181
1182 ipreach->prefix.s_addr = ipv4->prefix.s_addr;
1183 masklen2ip(ipv4->prefixlen, &ipreach->mask);
1184 ipreach->prefix.s_addr &= ipreach->mask.s_addr;
1185
1186 if ((info->metric & 0x3f) != info->metric)
1187 ipreach->metrics.metric_default = 0x3f;
1188 else
1189 ipreach->metrics.metric_default = info->metric;
1190 ipreach->metrics.metric_expense = METRICS_UNSUPPORTED;
1191 ipreach->metrics.metric_error = METRICS_UNSUPPORTED;
1192 ipreach->metrics.metric_delay = METRICS_UNSUPPORTED;
1193 listnode_add(tlv_data->ipv4_ext_reachs, ipreach);
1194 }
1195 if (area->newmetric)
1196 {
1197 if (tlv_data->te_ipv4_reachs == NULL)
1198 {
1199 tlv_data->te_ipv4_reachs = list_new();
1200 tlv_data->te_ipv4_reachs->del = free_tlv;
1201 }
1202 te_ipreach =
1203 XCALLOC(MTYPE_ISIS_TLV,
1204 sizeof(*te_ipreach) - 1 + PSIZE(ipv4->prefixlen));
1205 if (info->metric > MAX_WIDE_PATH_METRIC)
1206 te_ipreach->te_metric = htonl(MAX_WIDE_PATH_METRIC);
1207 else
1208 te_ipreach->te_metric = htonl(info->metric);
1209 te_ipreach->control = ipv4->prefixlen & 0x3f;
1210 memcpy(&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1211 PSIZE(ipv4->prefixlen));
1212 listnode_add(tlv_data->te_ipv4_reachs, te_ipreach);
1213 }
1214 }
1215}
1216
1217static void
1218lsp_build_ext_reach_ipv6(struct isis_lsp *lsp, struct isis_area *area,
1219 struct tlvs *tlv_data)
1220{
1221 struct route_table *er_table;
1222 struct route_node *rn;
1223 struct prefix_ipv6 *ipv6;
1224 struct isis_ext_info *info;
1225 struct ipv6_reachability *ip6reach;
1226
1227 er_table = get_ext_reach(area, AF_INET6, lsp->level);
1228 if (!er_table)
1229 return;
1230
1231 for (rn = route_top(er_table); rn; rn = route_next(rn))
1232 {
1233 if (!rn->info)
1234 continue;
1235
1236 ipv6 = (struct prefix_ipv6*)&rn->p;
1237 info = rn->info;
1238
1239 if (tlv_data->ipv6_reachs == NULL)
1240 {
1241 tlv_data->ipv6_reachs = list_new();
1242 tlv_data->ipv6_reachs->del = free_tlv;
1243 }
1244 ip6reach = XCALLOC(MTYPE_ISIS_TLV, sizeof(*ip6reach));
1245 if (info->metric > MAX_WIDE_PATH_METRIC)
1246 ip6reach->metric = htonl(MAX_WIDE_PATH_METRIC);
1247 else
1248 ip6reach->metric = htonl(info->metric);
1249 ip6reach->control_info = DISTRIBUTION_EXTERNAL;
1250 ip6reach->prefix_len = ipv6->prefixlen;
1251 memcpy(ip6reach->prefix, ipv6->prefix.s6_addr, sizeof(ip6reach->prefix));
1252 listnode_add(tlv_data->ipv6_reachs, ip6reach);
1253 }
1254}
1255
1256static void
1257lsp_build_ext_reach (struct isis_lsp *lsp, struct isis_area *area,
1258 struct tlvs *tlv_data)
1259{
1260 lsp_build_ext_reach_ipv4(lsp, area, tlv_data);
1261 lsp_build_ext_reach_ipv6(lsp, area, tlv_data);
1262}
1263
jardineb5d44e2003-12-23 08:09:43 +00001264/*
1265 * Builds the LSP data part. This func creates a new frag whenever
1266 * area->lsp_frag_threshold is exceeded.
1267 */
hasso92365882005-01-18 13:53:33 +00001268static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001269lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001270{
1271 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001272 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001273 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001274 int level = lsp->level;
1275 struct isis_circuit *circuit;
1276 struct prefix_ipv4 *ipv4;
1277 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001278 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001279 struct isis_adjacency *nei;
1280#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001281 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001282 struct ipv6_reachability *ip6reach;
1283#endif /* HAVE_IPV6 */
1284 struct tlvs tlv_data;
1285 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001286 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001287 uint32_t expected = 0, found = 0;
1288 uint32_t metric;
1289 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1290 int retval = ISIS_OK;
Christian Franke80a8f722015-11-12 14:21:47 +01001291 char buf[BUFSIZ];
1292
1293 lsp_debug("ISIS (%s): Constructing local system LSP for level %d", area->area_tag, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001294
1295 /*
1296 * Building the zero lsp
1297 */
1298 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1299
1300 /* Reset stream endp. Stream is always there and on every LSP refresh only
1301 * TLV part of it is overwritten. So we must seek past header we will not
1302 * touch. */
1303 stream_reset (lsp->pdu);
1304 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1305
1306 /*
1307 * Add the authentication info if its present
1308 */
1309 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001310
1311 /*
1312 * First add the tlvs related to area
1313 */
hassof390d2c2004-09-10 20:48:21 +00001314
jardineb5d44e2003-12-23 08:09:43 +00001315 /* Area addresses */
1316 if (lsp->tlv_data.area_addrs == NULL)
1317 lsp->tlv_data.area_addrs = list_new ();
1318 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001319 if (listcount (lsp->tlv_data.area_addrs) > 0)
1320 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1321
jardineb5d44e2003-12-23 08:09:43 +00001322 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001323 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001324#ifdef HAVE_IPV6
1325 || area->ipv6_circuits > 0
1326#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001327 )
jardineb5d44e2003-12-23 08:09:43 +00001328 {
hassoaac372f2005-09-01 17:52:33 +00001329 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001330 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001331 if (area->ip_circuits > 0)
1332 {
Christian Franke80a8f722015-11-12 14:21:47 +01001333 lsp_debug("ISIS (%s): Found IPv4 circuit, adding IPv4 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001334 lsp->tlv_data.nlpids->count++;
1335 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1336 }
jardineb5d44e2003-12-23 08:09:43 +00001337#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001338 if (area->ipv6_circuits > 0)
1339 {
Christian Franke80a8f722015-11-12 14:21:47 +01001340 lsp_debug("ISIS (%s): Found IPv6 circuit, adding IPv6 to NLPIDs", area->area_tag);
hassof390d2c2004-09-10 20:48:21 +00001341 lsp->tlv_data.nlpids->count++;
1342 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1343 NLPID_IPV6;
1344 }
jardineb5d44e2003-12-23 08:09:43 +00001345#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001346 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001347 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001348
jardineb5d44e2003-12-23 08:09:43 +00001349 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001350 if (area->dynhostname)
1351 {
Christian Frankef35169e2015-11-12 14:09:08 +01001352 const char *hostname = unix_hostname();
1353 size_t hostname_len = strlen(hostname);
1354
hassof390d2c2004-09-10 20:48:21 +00001355 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1356 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001357
Christian Frankef35169e2015-11-12 14:09:08 +01001358 strncpy((char *)lsp->tlv_data.hostname->name, hostname,
1359 sizeof(lsp->tlv_data.hostname->name));
1360 if (hostname_len <= MAX_TLV_LEN)
1361 lsp->tlv_data.hostname->namelen = hostname_len;
1362 else
1363 lsp->tlv_data.hostname->namelen = MAX_TLV_LEN;
1364
Christian Franke80a8f722015-11-12 14:21:47 +01001365 lsp_debug("ISIS (%s): Adding dynamic hostname '%.*s'", area->area_tag,
1366 lsp->tlv_data.hostname->namelen, lsp->tlv_data.hostname->name);
Josh Bailey3f045a02012-03-24 08:35:20 -07001367 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001368 }
Christian Franke80a8f722015-11-12 14:21:47 +01001369 else
1370 {
1371 lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)", area->area_tag);
1372 }
jardineb5d44e2003-12-23 08:09:43 +00001373
hasso81ad8f62005-09-26 17:58:24 +00001374 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1375 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1376 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001377 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001378 {
Christian Franke80a8f722015-11-12 14:21:47 +01001379 inet_ntop(AF_INET, &isis->router_id, buf, sizeof(buf));
1380 lsp_debug("ISIS (%s): Adding router ID %s as IPv4 tlv.", area->area_tag, buf);
hasso18a6dce2004-10-03 18:18:34 +00001381 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001382 {
1383 lsp->tlv_data.ipv4_addrs = list_new ();
1384 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1385 }
hasso18a6dce2004-10-03 18:18:34 +00001386
1387 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001388 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001389 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001390 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001391
hasso81ad8f62005-09-26 17:58:24 +00001392 /* Exactly same data is put into TE router ID TLV, but only if new style
1393 * TLV's are in use. */
1394 if (area->newmetric)
1395 {
Christian Franke80a8f722015-11-12 14:21:47 +01001396 lsp_debug("ISIS (%s): Adding router ID also as TE router ID tlv.", area->area_tag);
hasso81ad8f62005-09-26 17:58:24 +00001397 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1398 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001399 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1400 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1401 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001402 }
hasso18a6dce2004-10-03 18:18:34 +00001403 }
Christian Franke80a8f722015-11-12 14:21:47 +01001404 else
1405 {
1406 lsp_debug("ISIS (%s): Router ID is unset. Not adding tlv.", area->area_tag);
1407 }
hassof1082d12005-09-19 04:23:34 +00001408
hasso81ad8f62005-09-26 17:58:24 +00001409 memset (&tlv_data, 0, sizeof (struct tlvs));
1410
hassof1082d12005-09-19 04:23:34 +00001411#ifdef TOPOLOGY_GENERATE
1412 /* If topology exists (and we create topology for level 1 only), create
1413 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001414 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001415 {
1416 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001417 {
1418 tlv_data.is_neighs = list_new ();
1419 tlv_data.is_neighs->del = free_tlv;
1420 }
hasso3fdb2dd2005-09-28 18:45:54 +00001421 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001422
1423 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1424 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1425 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1426 is_neigh->metrics.metric_default = 0x01;
1427 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1428 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1429 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1430 listnode_add (tlv_data.is_neighs, is_neigh);
1431 }
1432#endif /* TOPOLOGY_GENERATE */
1433
Christian Franke80a8f722015-11-12 14:21:47 +01001434 lsp_debug("ISIS (%s): Adding circuit specific information.", area->area_tag);
1435
hasso18a6dce2004-10-03 18:18:34 +00001436 /*
jardineb5d44e2003-12-23 08:09:43 +00001437 * Then build lists of tlvs related to circuits
1438 */
hasso3fdb2dd2005-09-28 18:45:54 +00001439 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001440 {
Christian Franke80a8f722015-11-12 14:21:47 +01001441 if (!circuit->interface)
1442 lsp_debug("ISIS (%s): Processing %s circuit %p with unknown interface",
1443 area->area_tag, circuit_type2string(circuit->circ_type), circuit);
1444 else
1445 lsp_debug("ISIS (%s): Processing %s circuit %s",
1446 area->area_tag, circuit_type2string(circuit->circ_type), circuit->interface->name);
1447
hassof390d2c2004-09-10 20:48:21 +00001448 if (circuit->state != C_STATE_UP)
Christian Franke80a8f722015-11-12 14:21:47 +01001449 {
1450 lsp_debug("ISIS (%s): Circuit is not up, ignoring.", area->area_tag);
1451 continue;
1452 }
jardineb5d44e2003-12-23 08:09:43 +00001453
hassof390d2c2004-09-10 20:48:21 +00001454 /*
1455 * Add IPv4 internal reachability of this circuit
1456 */
1457 if (circuit->ip_router && circuit->ip_addrs &&
1458 circuit->ip_addrs->count > 0)
1459 {
Christian Franke80a8f722015-11-12 14:21:47 +01001460 lsp_debug("ISIS (%s): Circuit has IPv4 active, adding respective TLVs.", area->area_tag);
hassoaa4376e2005-09-26 17:39:48 +00001461 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001462 {
hassoaa4376e2005-09-26 17:39:48 +00001463 if (tlv_data.ipv4_int_reachs == NULL)
1464 {
1465 tlv_data.ipv4_int_reachs = list_new ();
1466 tlv_data.ipv4_int_reachs->del = free_tlv;
1467 }
hasso3fdb2dd2005-09-28 18:45:54 +00001468 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001469 {
1470 ipreach =
1471 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1472 ipreach->metrics = circuit->metrics[level - 1];
1473 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1474 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1475 (ipv4->prefix.s_addr));
Christian Franke80a8f722015-11-12 14:21:47 +01001476 inet_ntop(AF_INET, &ipreach->prefix.s_addr, buf, sizeof(buf));
1477 lsp_debug("ISIS (%s): Adding old-style IP reachability for %s/%d",
1478 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001479 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1480 }
hassof390d2c2004-09-10 20:48:21 +00001481 }
hassoaa4376e2005-09-26 17:39:48 +00001482 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001483 {
hassoaa4376e2005-09-26 17:39:48 +00001484 if (tlv_data.te_ipv4_reachs == NULL)
1485 {
1486 tlv_data.te_ipv4_reachs = list_new ();
1487 tlv_data.te_ipv4_reachs->del = free_tlv;
1488 }
hasso3fdb2dd2005-09-28 18:45:54 +00001489 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001490 {
1491 /* FIXME All this assumes that we have no sub TLVs. */
1492 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1493 sizeof (struct te_ipv4_reachability) +
1494 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001495
1496 if (area->oldmetric)
1497 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1498 else
1499 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1500
hassoaa4376e2005-09-26 17:39:48 +00001501 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1502 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1503 (ipv4->prefixlen + 7)/8);
Christian Franke80a8f722015-11-12 14:21:47 +01001504 inet_ntop(AF_INET, &ipv4->prefix.s_addr, buf, sizeof(buf));
1505 lsp_debug("ISIS (%s): Adding te-style IP reachability for %s/%d",
1506 area->area_tag, buf, ipv4->prefixlen);
hassoaa4376e2005-09-26 17:39:48 +00001507 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1508 }
hassof390d2c2004-09-10 20:48:21 +00001509 }
hassof390d2c2004-09-10 20:48:21 +00001510 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001511
jardineb5d44e2003-12-23 08:09:43 +00001512#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001513 /*
1514 * Add IPv6 reachability of this circuit
1515 */
1516 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1517 circuit->ipv6_non_link->count > 0)
1518 {
1519
1520 if (tlv_data.ipv6_reachs == NULL)
1521 {
1522 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001523 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001524 }
hasso3fdb2dd2005-09-28 18:45:54 +00001525 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001526 {
hassof390d2c2004-09-10 20:48:21 +00001527 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001528 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001529
1530 if (area->oldmetric)
1531 ip6reach->metric =
1532 htonl (circuit->metrics[level - 1].metric_default);
1533 else
1534 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1535
hassof390d2c2004-09-10 20:48:21 +00001536 ip6reach->control_info = 0;
1537 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001538 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1539 apply_mask_ipv6 (ip6prefix);
Christian Franke80a8f722015-11-12 14:21:47 +01001540
1541 inet_ntop(AF_INET6, &ip6prefix->prefix.s6_addr, buf, sizeof(buf));
1542 lsp_debug("ISIS (%s): Adding IPv6 reachability for %s/%d",
1543 area->area_tag, buf, ipv6->prefixlen);
1544
hasso67851572004-09-21 14:17:04 +00001545 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1546 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001547 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1548 }
1549 }
1550#endif /* HAVE_IPV6 */
1551
1552 switch (circuit->circ_type)
1553 {
1554 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001555 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001556 {
hassoaa4376e2005-09-26 17:39:48 +00001557 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001558 {
hassoaa4376e2005-09-26 17:39:48 +00001559 if (tlv_data.is_neighs == NULL)
1560 {
1561 tlv_data.is_neighs = list_new ();
1562 tlv_data.is_neighs->del = free_tlv;
1563 }
1564 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001565 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001566 memcpy (is_neigh->neigh_id,
1567 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1568 else
1569 memcpy (is_neigh->neigh_id,
1570 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1571 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001572 if (!memcmp (is_neigh->neigh_id, zero_id,
1573 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001574 {
1575 XFREE (MTYPE_ISIS_TLV, is_neigh);
1576 lsp_debug("ISIS (%s): No DIS for circuit, not adding old-style IS neighbor.",
1577 area->area_tag);
1578 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001579 else
Christian Franke80a8f722015-11-12 14:21:47 +01001580 {
1581 listnode_add (tlv_data.is_neighs, is_neigh);
1582 lsp_debug("ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
1583 area->area_tag, sysid_print(is_neigh->neigh_id),
1584 LSP_PSEUDO_ID(is_neigh->neigh_id));
1585 }
hassof390d2c2004-09-10 20:48:21 +00001586 }
hassoaa4376e2005-09-26 17:39:48 +00001587 if (area->newmetric)
1588 {
hassoaa4376e2005-09-26 17:39:48 +00001589 if (tlv_data.te_is_neighs == NULL)
1590 {
1591 tlv_data.te_is_neighs = list_new ();
1592 tlv_data.te_is_neighs->del = free_tlv;
1593 }
1594 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1595 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001596 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001597 memcpy (te_is_neigh->neigh_id,
1598 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1599 else
1600 memcpy (te_is_neigh->neigh_id,
1601 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001602 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001603 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001604 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001605 metric = circuit->te_metric[level - 1];
1606 SET_TE_METRIC(te_is_neigh, metric);
1607 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1608 ISIS_SYS_ID_LEN + 1))
Christian Franke80a8f722015-11-12 14:21:47 +01001609 {
1610 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1611 lsp_debug("ISIS (%s): No DIS for circuit, not adding te-style IS neighbor.",
1612 area->area_tag);
1613 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001614 else
Christian Franke80a8f722015-11-12 14:21:47 +01001615 {
1616 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1617 lsp_debug("ISIS (%s): Adding DIS %s.%02x as te-style neighbor",
1618 area->area_tag, sysid_print(te_is_neigh->neigh_id),
1619 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
1620 }
hassoaa4376e2005-09-26 17:39:48 +00001621 }
hassof390d2c2004-09-10 20:48:21 +00001622 }
Christian Franke80a8f722015-11-12 14:21:47 +01001623 else
1624 {
1625 lsp_debug("ISIS (%s): Circuit is not active for current level. Not adding IS neighbors",
1626 area->area_tag);
1627 }
hassof390d2c2004-09-10 20:48:21 +00001628 break;
1629 case CIRCUIT_T_P2P:
1630 nei = circuit->u.p2p.neighbor;
1631 if (nei && (level & nei->circuit_t))
1632 {
hassoaa4376e2005-09-26 17:39:48 +00001633 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001634 {
hassoaa4376e2005-09-26 17:39:48 +00001635 if (tlv_data.is_neighs == NULL)
1636 {
1637 tlv_data.is_neighs = list_new ();
1638 tlv_data.is_neighs->del = free_tlv;
1639 }
1640 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1641 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1642 is_neigh->metrics = circuit->metrics[level - 1];
1643 listnode_add (tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001644 lsp_debug("ISIS (%s): Adding old-style is reach for %s", area->area_tag,
1645 sysid_print(is_neigh->neigh_id));
hassof390d2c2004-09-10 20:48:21 +00001646 }
hassoaa4376e2005-09-26 17:39:48 +00001647 if (area->newmetric)
1648 {
1649 uint32_t metric;
1650
1651 if (tlv_data.te_is_neighs == NULL)
1652 {
1653 tlv_data.te_is_neighs = list_new ();
1654 tlv_data.te_is_neighs->del = free_tlv;
1655 }
1656 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1657 sizeof (struct te_is_neigh));
1658 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001659 metric = circuit->te_metric[level - 1];
1660 SET_TE_METRIC(te_is_neigh, metric);
hassoaa4376e2005-09-26 17:39:48 +00001661 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01001662 lsp_debug("ISIS (%s): Adding te-style is reach for %s", area->area_tag,
1663 sysid_print(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00001664 }
hassof390d2c2004-09-10 20:48:21 +00001665 }
Christian Franke80a8f722015-11-12 14:21:47 +01001666 else
1667 {
1668 lsp_debug("ISIS (%s): No adjacency for given level on this circuit. Not adding IS neighbors",
1669 area->area_tag);
1670 }
hassof390d2c2004-09-10 20:48:21 +00001671 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001672 case CIRCUIT_T_LOOPBACK:
1673 break;
hassof390d2c2004-09-10 20:48:21 +00001674 default:
1675 zlog_warn ("lsp_area_create: unknown circuit type");
1676 }
1677 }
1678
Christian Frankeacf98652015-11-12 14:24:22 +01001679 lsp_build_ext_reach(lsp, area, &tlv_data);
1680
Christian Franke80a8f722015-11-12 14:21:47 +01001681 lsp_debug("ISIS (%s): LSP construction is complete. Serializing...", area->area_tag);
1682
hassof390d2c2004-09-10 20:48:21 +00001683 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1684 {
1685 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1686 lsp->tlv_data.ipv4_int_reachs = list_new ();
1687 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1688 &lsp->tlv_data.ipv4_int_reachs,
1689 IPV4_REACH_LEN, area->lsp_frag_threshold,
Christian Frankeacf98652015-11-12 14:24:22 +01001690 tlv_add_ipv4_int_reachs);
hassof390d2c2004-09-10 20:48:21 +00001691 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1692 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1693 lsp0, area, level);
1694 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001695
Christian Frankeacf98652015-11-12 14:24:22 +01001696 while (tlv_data.ipv4_ext_reachs && listcount (tlv_data.ipv4_ext_reachs))
1697 {
1698 if (lsp->tlv_data.ipv4_ext_reachs == NULL)
1699 lsp->tlv_data.ipv4_ext_reachs = list_new ();
1700 lsp_tlv_fit (lsp, &tlv_data.ipv4_ext_reachs,
1701 &lsp->tlv_data.ipv4_ext_reachs,
1702 IPV4_REACH_LEN, area->lsp_frag_threshold,
1703 tlv_add_ipv4_ext_reachs);
1704 if (tlv_data.ipv4_ext_reachs && listcount (tlv_data.ipv4_ext_reachs))
1705 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1706 lsp0, area, level);
1707 }
1708
hassoaa4376e2005-09-26 17:39:48 +00001709 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1710 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1711 * TLVs (sub TLVs!). */
1712 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1713 {
1714 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1715 lsp->tlv_data.te_ipv4_reachs = list_new ();
1716 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1717 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001718 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1719 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001720 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1721 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1722 lsp0, area, level);
1723 }
hassof390d2c2004-09-10 20:48:21 +00001724
1725#ifdef HAVE_IPV6
1726 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1727 {
1728 if (lsp->tlv_data.ipv6_reachs == NULL)
1729 lsp->tlv_data.ipv6_reachs = list_new ();
1730 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1731 &lsp->tlv_data.ipv6_reachs,
1732 IPV6_REACH_LEN, area->lsp_frag_threshold,
1733 tlv_add_ipv6_reachs);
1734 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1735 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1736 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001737 }
1738#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001739
1740 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1741 {
1742 if (lsp->tlv_data.is_neighs == NULL)
1743 lsp->tlv_data.is_neighs = list_new ();
1744 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1745 &lsp->tlv_data.is_neighs,
1746 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1747 tlv_add_is_neighs);
1748 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1749 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1750 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001751 }
jardineb5d44e2003-12-23 08:09:43 +00001752
hassoaa4376e2005-09-26 17:39:48 +00001753 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1754 {
1755 if (lsp->tlv_data.te_is_neighs == NULL)
1756 lsp->tlv_data.te_is_neighs = list_new ();
1757 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1758 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1759 tlv_add_te_is_neighs);
1760 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1761 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1762 lsp0, area, level);
1763 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001764 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001765
1766 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001767
1768 /* Validate the LSP */
1769 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1770 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1771 stream_get_endp (lsp->pdu) -
1772 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1773 &expected, &found, &tlv_data, NULL);
1774 assert (retval == ISIS_OK);
1775
jardineb5d44e2003-12-23 08:09:43 +00001776 return;
1777}
jardineb5d44e2003-12-23 08:09:43 +00001778
1779/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001780 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001781 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001782int
1783lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001784{
jardineb5d44e2003-12-23 08:09:43 +00001785 struct isis_lsp *oldlsp, *newlsp;
1786 u_int32_t seq_num = 0;
1787 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001788 u_int16_t rem_lifetime, refresh_time;
1789
1790 if ((area == NULL) || (area->is_type & level) != level)
1791 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001792
1793 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1794 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1795
1796 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001797 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1798 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001799 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001800 /* FIXME: we should actually initiate a purge */
1801 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1802 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1803 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001804 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001805 rem_lifetime = lsp_rem_lifetime (area, level);
Christian Frankef1fc1db2015-11-10 18:43:31 +01001806 newlsp = lsp_new (area, lspid, rem_lifetime, seq_num,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001807 area->is_type | area->overload_bit | area->attached_bit,
1808 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001809 newlsp->area = area;
1810 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001811
Josh Bailey3f045a02012-03-24 08:35:20 -07001812 lsp_insert (newlsp, area->lspdb[level - 1]);
1813 /* build_lsp_data (newlsp, area); */
1814 lsp_build (newlsp, area);
1815 /* time to calculate our checksum */
1816 lsp_seqnum_update (newlsp);
Christian Franke61010c32015-11-10 18:43:34 +01001817 newlsp->last_generated = time(NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001818 lsp_set_all_srmflags (newlsp);
1819
1820 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
Christian Franke61010c32015-11-10 18:43:34 +01001821
Josh Bailey3f045a02012-03-24 08:35:20 -07001822 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
Christian Franke61010c32015-11-10 18:43:34 +01001823 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001824 if (level == IS_LEVEL_1)
1825 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1826 lsp_l1_refresh, area, refresh_time);
1827 else if (level == IS_LEVEL_2)
1828 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1829 lsp_l2_refresh, area, refresh_time);
1830
1831 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001832 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001833 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1834 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1835 area->area_tag, level,
1836 rawlspid_print (newlsp->lsp_header->lsp_id),
1837 ntohl (newlsp->lsp_header->pdu_len),
1838 ntohl (newlsp->lsp_header->seq_num),
1839 ntohs (newlsp->lsp_header->checksum),
1840 ntohs (newlsp->lsp_header->rem_lifetime),
1841 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001842 }
Christian Franke61010c32015-11-10 18:43:34 +01001843 sched_debug("ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
1844 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001845
1846 return ISIS_OK;
1847}
1848
1849/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001850 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001851 */
hasso92365882005-01-18 13:53:33 +00001852static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001853lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001854{
David Lampartere8aca322012-11-27 01:10:30 +00001855 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001856 struct isis_lsp *lsp, *frag;
1857 struct listnode *node;
1858 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001859 u_int16_t rem_lifetime, refresh_time;
1860
1861 if ((area == NULL) || (area->is_type & level) != level)
1862 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001863
David Lampartere8aca322012-11-27 01:10:30 +00001864 lspdb = area->lspdb[level - 1];
1865
jardineb5d44e2003-12-23 08:09:43 +00001866 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1867 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001868
jardineb5d44e2003-12-23 08:09:43 +00001869 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001870
hassof390d2c2004-09-10 20:48:21 +00001871 if (!lsp)
1872 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001873 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1874 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001875 return ISIS_ERROR;
1876 }
1877
1878 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001879 lsp_build (lsp, area);
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001880 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit,
1881 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001882 rem_lifetime = lsp_rem_lifetime (area, level);
1883 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001884 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001885
Josh Bailey3f045a02012-03-24 08:35:20 -07001886 lsp->last_generated = time (NULL);
1887 lsp_set_all_srmflags (lsp);
1888 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1889 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001890 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07001891 area->overload_bit,
1892 area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001893 /* Set the lifetime values of all the fragments to the same value,
1894 * so that no fragment expires before the lsp is refreshed.
1895 */
1896 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1897 lsp_set_all_srmflags (frag);
1898 }
1899
1900 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1901 if (level == IS_LEVEL_1)
1902 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1903 lsp_l1_refresh, area, refresh_time);
1904 else if (level == IS_LEVEL_2)
1905 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1906 lsp_l2_refresh, area, refresh_time);
Christian Franke61010c32015-11-10 18:43:34 +01001907 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07001908
hassof390d2c2004-09-10 20:48:21 +00001909 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1910 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001911 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
1912 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1913 area->area_tag, level,
1914 rawlspid_print (lsp->lsp_header->lsp_id),
1915 ntohl (lsp->lsp_header->pdu_len),
1916 ntohl (lsp->lsp_header->seq_num),
1917 ntohs (lsp->lsp_header->checksum),
1918 ntohs (lsp->lsp_header->rem_lifetime),
1919 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001920 }
Christian Franke61010c32015-11-10 18:43:34 +01001921 sched_debug("ISIS (%s): Rebuilt L%d LSP. Set triggered regenerate to non-pending.",
1922 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001923
jardineb5d44e2003-12-23 08:09:43 +00001924 return ISIS_OK;
1925}
1926
jardineb5d44e2003-12-23 08:09:43 +00001927/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001928 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00001929 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001930static int
1931lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001932{
1933 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001934
1935 area = THREAD_ARG (thread);
1936 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001937
jardineb5d44e2003-12-23 08:09:43 +00001938 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001939 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00001940
Josh Bailey3f045a02012-03-24 08:35:20 -07001941 if ((area->is_type & IS_LEVEL_1) == 0)
1942 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001943
Christian Franke61010c32015-11-10 18:43:34 +01001944 sched_debug("ISIS (%s): LSP L1 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07001945 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00001946}
1947
Josh Bailey3f045a02012-03-24 08:35:20 -07001948static int
1949lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001950{
1951 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001952
1953 area = THREAD_ARG (thread);
1954 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001955
jardineb5d44e2003-12-23 08:09:43 +00001956 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001957 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001958
Josh Bailey3f045a02012-03-24 08:35:20 -07001959 if ((area->is_type & IS_LEVEL_2) == 0)
1960 return ISIS_ERROR;
1961
Christian Franke61010c32015-11-10 18:43:34 +01001962 sched_debug("ISIS (%s): LSP L2 refresh timer expired. Refreshing LSP...", area->area_tag);
Josh Bailey3f045a02012-03-24 08:35:20 -07001963 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00001964}
1965
hassof390d2c2004-09-10 20:48:21 +00001966int
Josh Bailey3f045a02012-03-24 08:35:20 -07001967lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00001968{
1969 struct isis_lsp *lsp;
1970 u_char id[ISIS_SYS_ID_LEN + 2];
1971 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01001972 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07001973 struct listnode *cnode;
1974 struct isis_circuit *circuit;
1975 int lvl;
1976
1977 if (area == NULL)
1978 return ISIS_ERROR;
1979
Christian Franke61010c32015-11-10 18:43:34 +01001980 sched_debug("ISIS (%s): Scheduling regeneration of %s LSPs, %sincluding PSNs",
1981 area->area_tag, circuit_t2string(level), all_pseudo ? "" : "not ");
1982
hassof390d2c2004-09-10 20:48:21 +00001983 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1984 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001985 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001986
1987 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00001988 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001989 if (!((level & lvl) && (area->is_type & lvl)))
1990 continue;
1991
Christian Franke61010c32015-11-10 18:43:34 +01001992 sched_debug("ISIS (%s): Checking whether L%d needs to be scheduled",
1993 area->area_tag, lvl);
1994
Josh Bailey3f045a02012-03-24 08:35:20 -07001995 if (area->lsp_regenerate_pending[lvl - 1])
Christian Franke61010c32015-11-10 18:43:34 +01001996 {
1997 struct timeval remain = thread_timer_remain(area->t_lsp_refresh[lvl - 1]);
1998 sched_debug("ISIS (%s): Regeneration is already pending, nothing todo."
1999 " (Due in %lld.%03lld seconds)", area->area_tag,
2000 (long long)remain.tv_sec, (long long)remain.tv_usec / 1000);
2001 continue;
2002 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002003
2004 lsp = lsp_search (id, area->lspdb[lvl - 1]);
2005 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002006 {
2007 sched_debug("ISIS (%s): We do not have any LSPs to regenerate, nothing todo.",
2008 area->area_tag);
2009 continue;
2010 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002011
hassof390d2c2004-09-10 20:48:21 +00002012 /*
2013 * Throttle avoidance
2014 */
Christian Franke61010c32015-11-10 18:43:34 +01002015 sched_debug("ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
2016 area->area_tag, (long long)lsp->last_generated, (long long)now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002017 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00002018 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07002019 if (diff < area->lsp_gen_interval[lvl - 1])
2020 {
Christian Franke61010c32015-11-10 18:43:34 +01002021 timeout = 1000 * (area->lsp_gen_interval[lvl - 1] - diff);
2022 sched_debug("ISIS (%s): Scheduling in %ld ms to match configured lsp_gen_interval",
2023 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002024 }
hassof390d2c2004-09-10 20:48:21 +00002025 else
Josh Bailey3f045a02012-03-24 08:35:20 -07002026 {
Michael Zinggbe62b172012-10-26 11:18:19 +02002027 /*
2028 * lsps are not regenerated if lsp_regenerate function is called
2029 * directly. However if the lsp_regenerate call is queued for
2030 * later execution it works.
2031 */
Christian Franke61010c32015-11-10 18:43:34 +01002032 timeout = 100;
2033 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2034 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2035 }
2036
2037 area->lsp_regenerate_pending[lvl - 1] = 1;
2038 if (lvl == IS_LEVEL_1)
2039 {
2040 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
2041 lsp_l1_refresh, area, timeout);
2042 }
2043 else if (lvl == IS_LEVEL_2)
2044 {
2045 THREAD_TIMER_MSEC_ON(master, area->t_lsp_refresh[lvl - 1],
2046 lsp_l2_refresh, area, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002047 }
hassof390d2c2004-09-10 20:48:21 +00002048 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002049
2050 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00002051 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002052 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
2053 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00002054 }
2055
2056 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002057}
2058
2059/*
2060 * Funcs for pseudonode LSPs
2061 */
2062
2063/*
2064 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
2065 */
hasso92365882005-01-18 13:53:33 +00002066static void
hassof390d2c2004-09-10 20:48:21 +00002067lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
2068 int level)
jardineb5d44e2003-12-23 08:09:43 +00002069{
2070 struct isis_adjacency *adj;
2071 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00002072 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002073 struct es_neigh *es_neigh;
2074 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002075 struct listnode *node;
Christian Franke80a8f722015-11-12 14:21:47 +01002076 struct isis_area *area = circuit->area;
2077
2078 lsp_debug("ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
2079 area->area_tag, rawlspid_print(lsp->lsp_header->lsp_id),
2080 circuit->interface->name, level);
hassof390d2c2004-09-10 20:48:21 +00002081
jardineb5d44e2003-12-23 08:09:43 +00002082 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002083 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002084 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2085 circuit->area->attached_bit);
jardineb5d44e2003-12-23 08:09:43 +00002086
2087 /*
2088 * add self to IS neighbours
2089 */
hassoaa4376e2005-09-26 17:39:48 +00002090 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00002091 {
hassoaa4376e2005-09-26 17:39:48 +00002092 if (lsp->tlv_data.is_neighs == NULL)
2093 {
2094 lsp->tlv_data.is_neighs = list_new ();
2095 lsp->tlv_data.is_neighs->del = free_tlv;
2096 }
2097 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002098
hassoaa4376e2005-09-26 17:39:48 +00002099 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2100 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002101 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
2102 area->area_tag, sysid_print(is_neigh->neigh_id),
2103 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002104 }
2105 if (circuit->area->newmetric)
2106 {
2107 if (lsp->tlv_data.te_is_neighs == NULL)
2108 {
2109 lsp->tlv_data.te_is_neighs = list_new ();
2110 lsp->tlv_data.te_is_neighs->del = free_tlv;
2111 }
2112 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2113
2114 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2115 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002116 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
2117 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2118 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002119 }
hassof390d2c2004-09-10 20:48:21 +00002120
2121 adj_list = list_new ();
2122 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
2123
hasso3fdb2dd2005-09-28 18:45:54 +00002124 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00002125 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002126 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00002127 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002128 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
2129 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00002130 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07002131 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00002132 {
2133 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00002134 if (circuit->area->oldmetric)
2135 {
2136 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00002137
hassoaa4376e2005-09-26 17:39:48 +00002138 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2139 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002140 lsp_debug("ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
2141 area->area_tag, sysid_print(is_neigh->neigh_id),
2142 LSP_PSEUDO_ID(is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002143 }
2144 if (circuit->area->newmetric)
2145 {
2146 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
2147 sizeof (struct te_is_neigh));
2148 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2149 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002150 lsp_debug("ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
2151 area->area_tag, sysid_print(te_is_neigh->neigh_id),
2152 LSP_PSEUDO_ID(te_is_neigh->neigh_id));
hassoaa4376e2005-09-26 17:39:48 +00002153 }
hassof390d2c2004-09-10 20:48:21 +00002154 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002155 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00002156 {
2157 /* an ES neigbour add it, if we are building level 1 LSP */
2158 /* FIXME: the tlv-format is hard to use here */
2159 if (lsp->tlv_data.es_neighs == NULL)
2160 {
2161 lsp->tlv_data.es_neighs = list_new ();
2162 lsp->tlv_data.es_neighs->del = free_tlv;
2163 }
paul15935e92005-05-03 09:27:23 +00002164 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2165
hassof390d2c2004-09-10 20:48:21 +00002166 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00002167 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
Christian Franke80a8f722015-11-12 14:21:47 +01002168 lsp_debug("ISIS (%s): Adding %s as ES neighbor (peer)",
2169 area->area_tag, sysid_print(es_neigh->first_es_neigh));
hassof390d2c2004-09-10 20:48:21 +00002170 }
Christian Franke80a8f722015-11-12 14:21:47 +01002171 else
2172 {
2173 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not match",
2174 area->area_tag, sysid_print(adj->sysid));
2175 }
2176 }
2177 else
2178 {
2179 lsp_debug("ISIS (%s): Ignoring neighbor %s, level does not intersect",
2180 area->area_tag, sysid_print(adj->sysid));
hassof390d2c2004-09-10 20:48:21 +00002181 }
jardineb5d44e2003-12-23 08:09:43 +00002182 }
Josh Bailey3f045a02012-03-24 08:35:20 -07002183 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00002184
Christian Franke80a8f722015-11-12 14:21:47 +01002185 lsp_debug("ISIS (%s): Pseudo LSP construction is complete.", area->area_tag);
2186
hassoc0fb2a52005-09-03 16:29:40 +00002187 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00002188 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00002189 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2190
jardineb5d44e2003-12-23 08:09:43 +00002191 /*
2192 * Add the authentication info if it's present
2193 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002194 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002195
2196 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2197 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2198
hassoaa4376e2005-09-26 17:39:48 +00002199 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
2200 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
2201
jardineb5d44e2003-12-23 08:09:43 +00002202 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2203 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2204
paul9985f832005-02-09 15:51:56 +00002205 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002206
Josh Bailey3f045a02012-03-24 08:35:20 -07002207 /* Recompute authentication and checksum information */
2208 lsp_auth_update (lsp);
2209 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2210 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00002211
2212 return;
2213}
2214
Josh Bailey3f045a02012-03-24 08:35:20 -07002215int
2216lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002217{
2218 dict_t *lspdb = circuit->area->lspdb[level - 1];
2219 struct isis_lsp *lsp;
2220 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07002221 u_int16_t rem_lifetime, refresh_time;
2222
2223 if ((circuit->is_type & level) != level ||
2224 (circuit->state != C_STATE_UP) ||
2225 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2226 (circuit->u.bc.is_dr[level - 1] == 0))
2227 return ISIS_ERROR;
2228
2229 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2230 LSP_FRAGMENT (lsp_id) = 0;
2231 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2232
2233 /*
2234 * If for some reason have a pseudo LSP in the db already -> regenerate
2235 */
2236 if (lsp_search (lsp_id, lspdb))
2237 return lsp_regenerate_schedule_pseudo (circuit, level);
2238
2239 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2240 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Christian Frankef1fc1db2015-11-10 18:43:31 +01002241 lsp = lsp_new (circuit->area, lsp_id, rem_lifetime, 1,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002242 circuit->area->is_type | circuit->area->attached_bit,
2243 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07002244 lsp->area = circuit->area;
2245
2246 lsp_build_pseudo (lsp, circuit, level);
2247
2248 lsp->own_lsp = 1;
2249 lsp_insert (lsp, lspdb);
2250 lsp_set_all_srmflags (lsp);
2251
2252 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2253 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
2254 circuit->lsp_regenerate_pending[level - 1] = 0;
2255 if (level == IS_LEVEL_1)
2256 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2257 lsp_l1_refresh_pseudo, circuit, refresh_time);
2258 else if (level == IS_LEVEL_2)
2259 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2260 lsp_l2_refresh_pseudo, circuit, refresh_time);
2261
2262 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2263 {
2264 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
2265 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2266 circuit->area->area_tag, level,
2267 rawlspid_print (lsp->lsp_header->lsp_id),
2268 ntohl (lsp->lsp_header->pdu_len),
2269 ntohl (lsp->lsp_header->seq_num),
2270 ntohs (lsp->lsp_header->checksum),
2271 ntohs (lsp->lsp_header->rem_lifetime),
2272 refresh_time);
2273 }
2274
2275 return ISIS_OK;
2276}
2277
2278static int
2279lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
2280{
2281 dict_t *lspdb = circuit->area->lspdb[level - 1];
2282 struct isis_lsp *lsp;
2283 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2284 u_int16_t rem_lifetime, refresh_time;
2285
2286 if ((circuit->is_type & level) != level ||
2287 (circuit->state != C_STATE_UP) ||
2288 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
2289 (circuit->u.bc.is_dr[level - 1] == 0))
2290 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00002291
jardineb5d44e2003-12-23 08:09:43 +00002292 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002293 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2294 LSP_FRAGMENT (lsp_id) = 0;
2295
jardineb5d44e2003-12-23 08:09:43 +00002296 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002297
2298 if (!lsp)
2299 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002300 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2301 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002302 return ISIS_ERROR;
2303 }
2304 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002305
2306 lsp_build_pseudo (lsp, circuit, level);
2307
Josh Bailey3f045a02012-03-24 08:35:20 -07002308 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002309 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0,
2310 circuit->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002311 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2312 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002313 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002314 lsp->last_generated = time (NULL);
2315 lsp_set_all_srmflags (lsp);
2316
2317 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2318 if (level == IS_LEVEL_1)
2319 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2320 lsp_l1_refresh_pseudo, circuit, refresh_time);
2321 else if (level == IS_LEVEL_2)
2322 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2323 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002324
2325 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2326 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002327 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2328 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2329 circuit->area->area_tag, level,
2330 rawlspid_print (lsp->lsp_header->lsp_id),
2331 ntohl (lsp->lsp_header->pdu_len),
2332 ntohl (lsp->lsp_header->seq_num),
2333 ntohs (lsp->lsp_header->checksum),
2334 ntohs (lsp->lsp_header->rem_lifetime),
2335 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002336 }
jardineb5d44e2003-12-23 08:09:43 +00002337
jardineb5d44e2003-12-23 08:09:43 +00002338 return ISIS_OK;
2339}
2340
Josh Bailey3f045a02012-03-24 08:35:20 -07002341/*
2342 * Something has changed or periodic refresh -> regenerate pseudo LSP
2343 */
2344static int
jardineb5d44e2003-12-23 08:09:43 +00002345lsp_l1_refresh_pseudo (struct thread *thread)
2346{
2347 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002348 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002349
hassof390d2c2004-09-10 20:48:21 +00002350 circuit = THREAD_ARG (thread);
2351
hasso13c48f72004-09-10 21:19:13 +00002352 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002353 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002354
Josh Bailey3f045a02012-03-24 08:35:20 -07002355 if ((circuit->u.bc.is_dr[0] == 0) ||
2356 (circuit->is_type & IS_LEVEL_1) == 0)
2357 {
2358 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2359 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2360 LSP_FRAGMENT (id) = 0;
2361 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2362 return ISIS_ERROR;
2363 }
hassof390d2c2004-09-10 20:48:21 +00002364
Josh Bailey3f045a02012-03-24 08:35:20 -07002365 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002366}
2367
Josh Bailey3f045a02012-03-24 08:35:20 -07002368static int
jardineb5d44e2003-12-23 08:09:43 +00002369lsp_l2_refresh_pseudo (struct thread *thread)
2370{
2371 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002372 u_char id[ISIS_SYS_ID_LEN + 2];
2373
hassof390d2c2004-09-10 20:48:21 +00002374 circuit = THREAD_ARG (thread);
2375
hasso13c48f72004-09-10 21:19:13 +00002376 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002377 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002378
Josh Bailey3f045a02012-03-24 08:35:20 -07002379 if ((circuit->u.bc.is_dr[1] == 0) ||
2380 (circuit->is_type & IS_LEVEL_2) == 0)
2381 {
2382 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2383 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2384 LSP_FRAGMENT (id) = 0;
2385 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2386 return ISIS_ERROR;
2387 }
jardineb5d44e2003-12-23 08:09:43 +00002388
Josh Bailey3f045a02012-03-24 08:35:20 -07002389 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002390}
2391
hassof390d2c2004-09-10 20:48:21 +00002392int
Josh Bailey3f045a02012-03-24 08:35:20 -07002393lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002394{
2395 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002396 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2397 time_t now, diff;
Christian Franke61010c32015-11-10 18:43:34 +01002398 long timeout;
Josh Bailey3f045a02012-03-24 08:35:20 -07002399 int lvl;
Christian Franke61010c32015-11-10 18:43:34 +01002400 struct isis_area *area = circuit->area;
jardineb5d44e2003-12-23 08:09:43 +00002401
Josh Bailey3f045a02012-03-24 08:35:20 -07002402 if (circuit == NULL ||
2403 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2404 circuit->state != C_STATE_UP)
2405 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002406
Christian Franke61010c32015-11-10 18:43:34 +01002407 sched_debug("ISIS (%s): Scheduling regeneration of %s pseudo LSP for interface %s",
2408 area->area_tag, circuit_t2string(level), circuit->interface->name);
2409
Josh Bailey3f045a02012-03-24 08:35:20 -07002410 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2411 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2412 LSP_FRAGMENT (lsp_id) = 0;
2413 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002414
Josh Bailey3f045a02012-03-24 08:35:20 -07002415 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2416 {
Christian Franke61010c32015-11-10 18:43:34 +01002417 sched_debug("ISIS (%s): Checking whether L%d pseudo LSP needs to be scheduled",
2418 area->area_tag, lvl);
jardineb5d44e2003-12-23 08:09:43 +00002419
Christian Franke61010c32015-11-10 18:43:34 +01002420 if (!((level & lvl) && (circuit->is_type & lvl)))
2421 {
2422 sched_debug("ISIS (%s): Level is not active on circuit",
2423 area->area_tag);
2424 continue;
2425 }
2426
2427 if (circuit->u.bc.is_dr[lvl - 1] == 0)
2428 {
2429 sched_debug("ISIS (%s): This IS is not DR, nothing to do.",
2430 area->area_tag);
2431 continue;
2432 }
2433
2434 if (circuit->lsp_regenerate_pending[lvl - 1])
2435 {
2436 struct timeval remain =
2437 thread_timer_remain(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2438 sched_debug("ISIS (%s): Regenerate is already pending, nothing todo."
2439 " (Due in %lld.%03lld seconds)", area->area_tag,
2440 (long long)remain.tv_sec, (long long)remain.tv_usec/1000);
2441 continue;
2442 }
hassof390d2c2004-09-10 20:48:21 +00002443
Josh Bailey3f045a02012-03-24 08:35:20 -07002444 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2445 if (!lsp)
Christian Franke61010c32015-11-10 18:43:34 +01002446 {
2447 sched_debug("ISIS (%s): Pseudonode LSP does not exist yet, nothing to regenerate.",
2448 area->area_tag);
2449 continue;
2450 }
jardineb5d44e2003-12-23 08:09:43 +00002451
Josh Bailey3f045a02012-03-24 08:35:20 -07002452 /*
2453 * Throttle avoidance
2454 */
Christian Franke61010c32015-11-10 18:43:34 +01002455 sched_debug("ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
2456 area->area_tag, (long long)lsp->last_generated, (long long) now);
Josh Bailey3f045a02012-03-24 08:35:20 -07002457 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2458 diff = now - lsp->last_generated;
2459 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2460 {
Christian Franke61010c32015-11-10 18:43:34 +01002461 timeout = 1000 * (circuit->area->lsp_gen_interval[lvl - 1] - diff);
2462 sched_debug("ISIS (%s): Sechduling in %ld ms to match configured lsp_gen_interval",
2463 area->area_tag, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002464 }
2465 else
2466 {
Christian Franke61010c32015-11-10 18:43:34 +01002467 timeout = 100;
2468 sched_debug("ISIS (%s): Last generation was more than lsp_gen_interval ago."
2469 " Scheduling for execution in %ld ms.", area->area_tag, timeout);
2470 }
2471
2472 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2473
2474 if (lvl == IS_LEVEL_1)
2475 {
2476 THREAD_TIMER_MSEC_ON(master,
2477 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2478 lsp_l1_refresh_pseudo, circuit, timeout);
2479 }
2480 else if (lvl == IS_LEVEL_2)
2481 {
2482 THREAD_TIMER_MSEC_ON(master,
2483 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2484 lsp_l2_refresh_pseudo, circuit, timeout);
Josh Bailey3f045a02012-03-24 08:35:20 -07002485 }
2486 }
jardineb5d44e2003-12-23 08:09:43 +00002487
Josh Bailey3f045a02012-03-24 08:35:20 -07002488 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002489}
2490
jardineb5d44e2003-12-23 08:09:43 +00002491/*
2492 * Walk through LSPs for an area
2493 * - set remaining lifetime
2494 * - set LSPs with SRMflag set for sending
2495 */
hassof390d2c2004-09-10 20:48:21 +00002496int
jardineb5d44e2003-12-23 08:09:43 +00002497lsp_tick (struct thread *thread)
2498{
2499 struct isis_area *area;
2500 struct isis_circuit *circuit;
2501 struct isis_lsp *lsp;
2502 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002503 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002504 dnode_t *dnode, *dnode_next;
2505 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002506 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002507
2508 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002509
jardineb5d44e2003-12-23 08:09:43 +00002510 area = THREAD_ARG (thread);
2511 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002512 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002513 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002514
2515 /*
2516 * Build a list of LSPs with (any) SRMflag set
2517 * and removed the ones that have aged out
2518 */
hassof390d2c2004-09-10 20:48:21 +00002519 for (level = 0; level < ISIS_LEVELS; level++)
2520 {
2521 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002522 {
2523 for (dnode = dict_first (area->lspdb[level]);
2524 dnode != NULL; dnode = dnode_next)
2525 {
2526 dnode_next = dict_next (area->lspdb[level], dnode);
2527 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002528
Josh Bailey3f045a02012-03-24 08:35:20 -07002529 /*
2530 * The lsp rem_lifetime is kept at 0 for MaxAge or
2531 * ZeroAgeLifetime depending on explicit purge or
2532 * natural age out. So schedule spf only once when
2533 * the first time rem_lifetime becomes 0.
2534 */
2535 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2536 lsp_set_time (lsp);
2537
2538 /*
2539 * Schedule may run spf which should be done only after
2540 * the lsp rem_lifetime becomes 0 for the first time.
2541 * ISO 10589 - 7.3.16.4 first paragraph.
2542 */
2543 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2544 {
2545 /* 7.3.16.4 a) set SRM flags on all */
2546 lsp_set_all_srmflags (lsp);
2547 /* 7.3.16.4 b) retain only the header FIXME */
2548 /* 7.3.16.4 c) record the time to purge FIXME */
2549 /* run/schedule spf */
2550 /* isis_spf_schedule is called inside lsp_destroy() below;
2551 * so it is not needed here. */
2552 /* isis_spf_schedule (lsp->area, lsp->level); */
2553 }
2554
2555 if (lsp->age_out == 0)
2556 {
2557 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2558 area->area_tag,
2559 lsp->level,
2560 rawlspid_print (lsp->lsp_header->lsp_id),
2561 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002562#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002563 if (lsp->from_topology)
2564 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002565#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002566 lsp_destroy (lsp);
2567 lsp = NULL;
2568 dict_delete_free (area->lspdb[level], dnode);
2569 }
2570 else if (flags_any_set (lsp->SRMflags))
2571 listnode_add (lsp_list, lsp);
2572 }
jardineb5d44e2003-12-23 08:09:43 +00002573
Josh Bailey3f045a02012-03-24 08:35:20 -07002574 /*
2575 * Send LSPs on circuits indicated by the SRMflags
2576 */
2577 if (listcount (lsp_list) > 0)
2578 {
paul1eb8ef22005-04-07 07:30:20 +00002579 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002580 {
2581 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2582 if (circuit->lsp_queue == NULL ||
2583 diff < MIN_LSP_TRANS_INTERVAL)
2584 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002585 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002586 {
2587 if (circuit->upadjcount[lsp->level - 1] &&
2588 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2589 {
2590 /* Add the lsp only if it is not already in lsp
2591 * queue */
2592 if (! listnode_lookup (circuit->lsp_queue, lsp))
2593 {
2594 listnode_add (circuit->lsp_queue, lsp);
2595 thread_add_event (master, send_lsp, circuit, 0);
2596 }
2597 }
2598 }
2599 }
2600 list_delete_all_node (lsp_list);
2601 }
2602 }
jardineb5d44e2003-12-23 08:09:43 +00002603 }
jardineb5d44e2003-12-23 08:09:43 +00002604
2605 list_delete (lsp_list);
2606
2607 return ISIS_OK;
2608}
2609
jardineb5d44e2003-12-23 08:09:43 +00002610void
Josh Bailey3f045a02012-03-24 08:35:20 -07002611lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002612{
2613 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002614 u_int16_t seq_num;
2615 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002616
jardineb5d44e2003-12-23 08:09:43 +00002617 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002618 if (!lsp)
2619 return;
hassof390d2c2004-09-10 20:48:21 +00002620
Josh Bailey3f045a02012-03-24 08:35:20 -07002621 /* store old values */
2622 seq_num = lsp->lsp_header->seq_num;
2623 lsp_bits = lsp->lsp_header->lsp_bits;
2624
2625 /* reset stream */
2626 lsp_clear_data (lsp);
2627 stream_reset (lsp->pdu);
2628
2629 /* update header */
2630 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2631 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2632 lsp->lsp_header->checksum = 0;
2633 lsp->lsp_header->seq_num = seq_num;
2634 lsp->lsp_header->rem_lifetime = 0;
2635 lsp->lsp_header->lsp_bits = lsp_bits;
2636 lsp->level = level;
2637 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2638 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2639
2640 /*
2641 * Add and update the authentication info if its present
2642 */
2643 lsp_auth_add (lsp);
2644 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2645 lsp_auth_update (lsp);
2646 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2647 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2648
2649 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002650
jardineb5d44e2003-12-23 08:09:43 +00002651 return;
2652}
2653
2654/*
2655 * Purge own LSP that is received and we don't have.
2656 * -> Do as in 7.3.16.4
2657 */
2658void
Christian Franke749e87a2015-11-10 18:21:44 +01002659lsp_purge_non_exist (int level,
2660 struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +00002661 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002662{
2663 struct isis_lsp *lsp;
2664
2665 /*
2666 * We need to create the LSP to be purged
2667 */
hassoaac372f2005-09-01 17:52:33 +00002668 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002669 lsp->area = area;
Christian Franke749e87a2015-11-10 18:21:44 +01002670 lsp->level = level;
Christian Frankef1fc1db2015-11-10 18:43:31 +01002671 lsp->pdu = stream_new(LLC_LEN + area->lsp_mtu);
hassof390d2c2004-09-10 20:48:21 +00002672 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002673 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002674 : L2_LINK_STATE);
2675 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2676 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002677 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002678 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002679
jardineb5d44e2003-12-23 08:09:43 +00002680 /*
jardineb5d44e2003-12-23 08:09:43 +00002681 * Set the remaining lifetime to 0
2682 */
2683 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002684
2685 /*
2686 * Add and update the authentication info if its present
2687 */
2688 lsp_auth_add (lsp);
2689 lsp_auth_update (lsp);
2690
2691 /*
2692 * Update the PDU length to header plus any authentication TLV.
2693 */
2694 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2695
jardineb5d44e2003-12-23 08:09:43 +00002696 /*
2697 * Put the lsp into LSPdb
2698 */
hassof390d2c2004-09-10 20:48:21 +00002699 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002700
2701 /*
2702 * Send in to whole area
2703 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002704 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002705
jardineb5d44e2003-12-23 08:09:43 +00002706 return;
2707}
2708
Josh Bailey3f045a02012-03-24 08:35:20 -07002709void lsp_set_all_srmflags (struct isis_lsp *lsp)
2710{
2711 struct listnode *node;
2712 struct isis_circuit *circuit;
2713
2714 assert (lsp);
2715
2716 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2717
2718 if (lsp->area)
2719 {
2720 struct list *circuit_list = lsp->area->circuit_list;
2721 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2722 {
2723 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2724 }
2725 }
2726}
2727
jardineb5d44e2003-12-23 08:09:43 +00002728#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002729static int
jardineb5d44e2003-12-23 08:09:43 +00002730top_lsp_refresh (struct thread *thread)
2731{
hassof390d2c2004-09-10 20:48:21 +00002732 struct isis_lsp *lsp;
David Lamparterf50ee932015-03-04 07:13:38 +01002733 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002734
2735 lsp = THREAD_ARG (thread);
2736 assert (lsp);
2737
2738 lsp->t_lsp_top_ref = NULL;
2739
hassof1082d12005-09-19 04:23:34 +00002740 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002741
Josh Bailey3f045a02012-03-24 08:35:20 -07002742 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002743 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2744 {
hasso529d65b2004-12-24 00:14:50 +00002745 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2746 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002747 }
hassod3d74742005-09-28 18:30:51 +00002748 /* Refresh dynamic hostname in the cache. */
2749 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2750 IS_LEVEL_1);
2751
David Lampartera47c5832012-06-21 09:55:38 +02002752 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Amritha Nambiarc8ee9402015-08-24 16:40:14 -07002753 lsp->area->overload_bit,
2754 lsp->area->attached_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002755 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2756 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002757
David Lamparterf50ee932015-03-04 07:13:38 +01002758 /* refresh_time = lsp_refresh_time (lsp, rem_lifetime); */
hassof390d2c2004-09-10 20:48:21 +00002759 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002760 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002761
2762 return ISIS_OK;
2763}
2764
2765void
2766generate_topology_lsps (struct isis_area *area)
2767{
2768 struct listnode *node;
2769 int i, max = 0;
2770 struct arc *arc;
2771 u_char lspid[ISIS_SYS_ID_LEN + 2];
2772 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002773 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002774
2775 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002776 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002777 {
2778 if (arc->from_node > max)
2779 max = arc->from_node;
2780 if (arc->to_node > max)
2781 max = arc->to_node;
2782 }
jardineb5d44e2003-12-23 08:09:43 +00002783
hassof390d2c2004-09-10 20:48:21 +00002784 for (i = 1; i < (max + 1); i++)
2785 {
2786 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2787 LSP_PSEUDO_ID (lspid) = 0x00;
2788 LSP_FRAGMENT (lspid) = 0x00;
2789 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2790 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002791
Josh Bailey3f045a02012-03-24 08:35:20 -07002792 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
Christian Frankef1fc1db2015-11-10 18:43:31 +01002793 lsp = lsp_new (area, lspid, rem_lifetime, 1,
2794 IS_LEVEL_1 | area->overload_bit | area->attached_bit,
2795 0, 1);
hassof1082d12005-09-19 04:23:34 +00002796 if (!lsp)
2797 return;
Josh Bailey3f045a02012-03-24 08:35:20 -07002798 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002799
hassof1082d12005-09-19 04:23:34 +00002800 /* Creating LSP data based on topology info. */
2801 build_topology_lsp_data (lsp, area, i);
2802 /* Checksum is also calculated here. */
2803 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002804 /* Take care of inserting dynamic hostname into cache. */
2805 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002806
Josh Bailey3f045a02012-03-24 08:35:20 -07002807 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002808 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002809 refresh_time);
2810 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002811 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002812 }
jardineb5d44e2003-12-23 08:09:43 +00002813}
2814
2815void
2816remove_topology_lsps (struct isis_area *area)
2817{
2818 struct isis_lsp *lsp;
2819 dnode_t *dnode, *dnode_next;
2820
2821 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002822 while (dnode != NULL)
2823 {
2824 dnode_next = dict_next (area->lspdb[0], dnode);
2825 lsp = dnode_get (dnode);
2826 if (lsp->from_topology)
2827 {
2828 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2829 lsp_destroy (lsp);
2830 dict_delete (area->lspdb[0], dnode);
2831 }
2832 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002833 }
jardineb5d44e2003-12-23 08:09:43 +00002834}
2835
2836void
hassof390d2c2004-09-10 20:48:21 +00002837build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002838 int lsp_top_num)
2839{
hasso3fdb2dd2005-09-28 18:45:54 +00002840 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002841 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002842 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002843 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002844 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002845 struct tlvs tlv_data;
2846 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002847
hassof1082d12005-09-19 04:23:34 +00002848 /* Add area addresses. FIXME: Is it needed at all? */
2849 if (lsp->tlv_data.area_addrs == NULL)
2850 lsp->tlv_data.area_addrs = list_new ();
2851 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002852
hassof1082d12005-09-19 04:23:34 +00002853 if (lsp->tlv_data.nlpids == NULL)
2854 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2855 lsp->tlv_data.nlpids->count = 1;
2856 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002857
hassof1082d12005-09-19 04:23:34 +00002858 if (area->dynhostname)
2859 {
2860 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2861 sizeof (struct hostname));
2862 memset (buff, 0x00, 200);
2863 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2864 "feedme", lsp_top_num);
2865 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2866 lsp->tlv_data.hostname->namelen = strlen (buff);
2867 }
2868
2869 if (lsp->tlv_data.nlpids)
2870 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2871 if (lsp->tlv_data.hostname)
2872 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2873 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2874 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2875
2876 memset (&tlv_data, 0, sizeof (struct tlvs));
2877 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002878 {
2879 tlv_data.is_neighs = list_new ();
2880 tlv_data.is_neighs->del = free_tlv;
2881 }
hassof1082d12005-09-19 04:23:34 +00002882
2883 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002884 if (lsp_top_num == 1)
2885 {
hasso3fdb2dd2005-09-28 18:45:54 +00002886 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002887
hassof390d2c2004-09-10 20:48:21 +00002888 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002889 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002890 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2891 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002892 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2893 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2894 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002895 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002896 }
hassof390d2c2004-09-10 20:48:21 +00002897
hassof1082d12005-09-19 04:23:34 +00002898 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002899 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002900 {
hassof1082d12005-09-19 04:23:34 +00002901 int to_lsp = 0;
2902
2903 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2904 continue;
2905
2906 if (lsp_top_num == arc->from_node)
2907 to_lsp = arc->to_node;
2908 else
2909 to_lsp = arc->from_node;
2910
hasso9551eea2005-09-28 18:26:25 +00002911 if (area->oldmetric)
2912 {
2913 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002914
hasso9551eea2005-09-28 18:26:25 +00002915 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2916 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2917 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2918 is_neigh->metrics.metric_default = arc->distance;
2919 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2920 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2921 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2922 listnode_add (tlv_data.is_neighs, is_neigh);
2923 }
2924
2925 if (area->newmetric)
2926 {
hasso9551eea2005-09-28 18:26:25 +00002927 if (tlv_data.te_is_neighs == NULL)
2928 {
2929 tlv_data.te_is_neighs = list_new ();
2930 tlv_data.te_is_neighs->del = free_tlv;
2931 }
2932 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2933 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2934 ISIS_SYS_ID_LEN);
2935 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2936 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07002937 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00002938 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2939 }
hassof390d2c2004-09-10 20:48:21 +00002940 }
hassof1082d12005-09-19 04:23:34 +00002941
2942 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2943 {
2944 if (lsp->tlv_data.is_neighs == NULL)
2945 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002946 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002947 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2948 tlv_add_is_neighs);
2949 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2950 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2951 lsp0, area, IS_LEVEL_1);
2952 }
2953
hasso9551eea2005-09-28 18:26:25 +00002954 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2955 {
2956 if (lsp->tlv_data.te_is_neighs == NULL)
2957 lsp->tlv_data.te_is_neighs = list_new ();
2958 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2959 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2960 tlv_add_te_is_neighs);
2961 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2962 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2963 lsp0, area, IS_LEVEL_1);
2964 }
2965
hassof1082d12005-09-19 04:23:34 +00002966 free_tlvs (&tlv_data);
2967 return;
jardineb5d44e2003-12-23 08:09:43 +00002968}
2969#endif /* TOPOLOGY_GENERATE */