blob: 4c09e7928f3fd24c622d5c078bb2222bc18cc964 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_lsp.c
3 * LSP processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
paul15935e92005-05-03 09:27:23 +000023
jardineb5d44e2003-12-23 08:09:43 +000024#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000025
26#include "linklist.h"
27#include "thread.h"
28#include "vty.h"
29#include "stream.h"
30#include "memory.h"
31#include "log.h"
32#include "prefix.h"
33#include "command.h"
34#include "hash.h"
35#include "if.h"
Jingjing Duan6a270cd2008-08-13 19:09:10 +010036#include "checksum.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070037#include "md5.h"
jardineb5d44e2003-12-23 08:09:43 +000038
39#include "isisd/dict.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070042#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000043#include "isisd/isis_circuit.h"
44#include "isisd/isisd.h"
45#include "isisd/isis_tlv.h"
46#include "isisd/isis_lsp.h"
47#include "isisd/isis_pdu.h"
48#include "isisd/isis_dynhn.h"
49#include "isisd/isis_misc.h"
jardineb5d44e2003-12-23 08:09:43 +000050#include "isisd/isis_csm.h"
51#include "isisd/isis_adjacency.h"
52#include "isisd/isis_spf.h"
53
54#ifdef TOPOLOGY_GENERATE
55#include "spgrid.h"
56#endif
57
hasso73d1aea2004-09-24 10:45:28 +000058/* staticly assigned vars for printing purposes */
59char lsp_bits_string[200]; /* FIXME: enough ? */
60
Josh Bailey3f045a02012-03-24 08:35:20 -070061static int lsp_l1_refresh (struct thread *thread);
62static int lsp_l2_refresh (struct thread *thread);
63static int lsp_l1_refresh_pseudo (struct thread *thread);
64static int lsp_l2_refresh_pseudo (struct thread *thread);
65
hassof390d2c2004-09-10 20:48:21 +000066int
67lsp_id_cmp (u_char * id1, u_char * id2)
68{
jardineb5d44e2003-12-23 08:09:43 +000069 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
70}
71
72dict_t *
hassof390d2c2004-09-10 20:48:21 +000073lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000074{
75 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000076
77 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
78
jardineb5d44e2003-12-23 08:09:43 +000079 return dict;
80}
81
82struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000083lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000084{
85 dnode_t *node;
86
hassof390d2c2004-09-10 20:48:21 +000087#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000088 dnode_t *dn;
89
hasso529d65b2004-12-24 00:14:50 +000090 zlog_debug ("searching db");
hassof390d2c2004-09-10 20:48:21 +000091 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
92 {
Josh Bailey3f045a02012-03-24 08:35:20 -070093 zlog_debug ("%s\t%pX", rawlspid_print ((u_char *) dnode_getkey (dn)),
hasso529d65b2004-12-24 00:14:50 +000094 dnode_get (dn));
hassof390d2c2004-09-10 20:48:21 +000095 }
jardineb5d44e2003-12-23 08:09:43 +000096#endif /* EXTREME DEBUG */
97
98 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +000099
jardineb5d44e2003-12-23 08:09:43 +0000100 if (node)
hassof390d2c2004-09-10 20:48:21 +0000101 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000102
103 return NULL;
104}
105
hasso92365882005-01-18 13:53:33 +0000106static void
jardineb5d44e2003-12-23 08:09:43 +0000107lsp_clear_data (struct isis_lsp *lsp)
108{
109 if (!lsp)
110 return;
hassof390d2c2004-09-10 20:48:21 +0000111
Josh Bailey3f045a02012-03-24 08:35:20 -0700112 if (lsp->tlv_data.hostname)
113 isis_dynhn_remove (lsp->lsp_header->lsp_id);
114
hassof390d2c2004-09-10 20:48:21 +0000115 if (lsp->own_lsp)
116 {
117 if (lsp->tlv_data.nlpids)
Josh Bailey3f045a02012-03-24 08:35:20 -0700118 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
hassof390d2c2004-09-10 20:48:21 +0000119 if (lsp->tlv_data.hostname)
Josh Bailey3f045a02012-03-24 08:35:20 -0700120 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
121 if (lsp->tlv_data.router_id)
122 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.router_id);
hassof390d2c2004-09-10 20:48:21 +0000123 }
jardineb5d44e2003-12-23 08:09:43 +0000124
Josh Bailey3f045a02012-03-24 08:35:20 -0700125 free_tlvs (&lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000126}
127
hasso92365882005-01-18 13:53:33 +0000128static void
jardineb5d44e2003-12-23 08:09:43 +0000129lsp_destroy (struct isis_lsp *lsp)
130{
Josh Bailey3f045a02012-03-24 08:35:20 -0700131 struct listnode *cnode, *lnode, *lnnode;
132 struct isis_lsp *lsp_in_list;
133 struct isis_circuit *circuit;
134
jardineb5d44e2003-12-23 08:09:43 +0000135 if (!lsp)
136 return;
hassof390d2c2004-09-10 20:48:21 +0000137
Josh Bailey3f045a02012-03-24 08:35:20 -0700138 for (ALL_LIST_ELEMENTS_RO (lsp->area->circuit_list, cnode, circuit))
139 {
140 if (circuit->lsp_queue == NULL)
141 continue;
142 for (ALL_LIST_ELEMENTS (circuit->lsp_queue, lnode, lnnode, lsp_in_list))
143 if (lsp_in_list == lsp)
144 list_delete_node(circuit->lsp_queue, lnode);
145 }
146 ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags);
147 ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
148
jardineb5d44e2003-12-23 08:09:43 +0000149 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000150
151 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
152 {
jardineb5d44e2003-12-23 08:09:43 +0000153 list_delete (lsp->lspu.frags);
Josh Bailey3f045a02012-03-24 08:35:20 -0700154 lsp->lspu.frags = NULL;
hassof390d2c2004-09-10 20:48:21 +0000155 }
156
Josh Bailey3f045a02012-03-24 08:35:20 -0700157 isis_spf_schedule (lsp->area, lsp->level);
158#ifdef HAVE_IPV6
159 isis_spf_schedule6 (lsp->area, lsp->level);
160#endif
161
jardineb5d44e2003-12-23 08:09:43 +0000162 if (lsp->pdu)
163 stream_free (lsp->pdu);
164 XFREE (MTYPE_ISIS_LSP, lsp);
165}
166
hassof390d2c2004-09-10 20:48:21 +0000167void
168lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000169{
170 dnode_t *dnode, *next;
171 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000172
jardineb5d44e2003-12-23 08:09:43 +0000173 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000174 while (dnode)
175 {
176 next = dict_next (lspdb, dnode);
177 lsp = dnode_get (dnode);
178 lsp_destroy (lsp);
179 dict_delete_free (lspdb, dnode);
180 dnode = next;
181 }
182
jardineb5d44e2003-12-23 08:09:43 +0000183 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000184
jardineb5d44e2003-12-23 08:09:43 +0000185 return;
186}
187
188/*
189 * Remove all the frags belonging to the given lsp
190 */
hasso92365882005-01-18 13:53:33 +0000191static void
hassof390d2c2004-09-10 20:48:21 +0000192lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000193{
194 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000195 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000196 struct isis_lsp *lsp;
197
paul1eb8ef22005-04-07 07:30:20 +0000198 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000199 {
hassof390d2c2004-09-10 20:48:21 +0000200 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
201 lsp_destroy (lsp);
202 dnode_destroy (dict_delete (lspdb, dnode));
203 }
204
jardineb5d44e2003-12-23 08:09:43 +0000205 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000206
jardineb5d44e2003-12-23 08:09:43 +0000207 return;
208}
209
210void
hassof390d2c2004-09-10 20:48:21 +0000211lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000212{
213 dnode_t *node;
214 struct isis_lsp *lsp;
215
216 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000217 if (node)
218 {
219 node = dict_delete (lspdb, node);
220 lsp = dnode_get (node);
221 /*
222 * If this is a zero lsp, remove all the frags now
223 */
224 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
225 {
226 if (lsp->lspu.frags)
227 lsp_remove_frags (lsp->lspu.frags, lspdb);
228 }
229 else
230 {
231 /*
232 * else just remove this frag, from the zero lsps' frag list
233 */
234 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
235 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
236 }
237 lsp_destroy (lsp);
238 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000239 }
jardineb5d44e2003-12-23 08:09:43 +0000240}
241
242/*
243 * Compares a LSP to given values
244 * Params are given in net order
245 */
hassof390d2c2004-09-10 20:48:21 +0000246int
247lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000248 u_int16_t checksum, u_int16_t rem_lifetime)
249{
hassof390d2c2004-09-10 20:48:21 +0000250 /* no point in double ntohl on seqnum */
251 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000252 lsp->lsp_header->checksum == checksum &&
253 /*comparing with 0, no need to do ntohl */
254 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000255 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
256 {
257 if (isis->debugs & DEBUG_SNP_PACKETS)
258 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700259 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000260 " lifetime %us",
261 areatag,
262 rawlspid_print (lsp->lsp_header->lsp_id),
263 ntohl (lsp->lsp_header->seq_num),
264 ntohs (lsp->lsp_header->checksum),
265 ntohs (lsp->lsp_header->rem_lifetime));
266 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
267 " cksum 0x%04x, lifetime %us",
268 areatag,
269 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000270 }
271 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000272 }
jardineb5d44e2003-12-23 08:09:43 +0000273
hassof390d2c2004-09-10 20:48:21 +0000274 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
275 {
276 if (isis->debugs & DEBUG_SNP_PACKETS)
277 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700278 zlog_debug ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x,"
hasso529d65b2004-12-24 00:14:50 +0000279 " lifetime %us",
280 areatag,
281 rawlspid_print (lsp->lsp_header->lsp_id),
282 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
283 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
284 "cksum 0x%04x, lifetime %us",
285 areatag,
286 ntohl (lsp->lsp_header->seq_num),
287 ntohs (lsp->lsp_header->checksum),
288 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000289 }
290 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000291 }
hassof390d2c2004-09-10 20:48:21 +0000292 if (isis->debugs & DEBUG_SNP_PACKETS)
293 {
hasso529d65b2004-12-24 00:14:50 +0000294 zlog_debug
Josh Bailey3f045a02012-03-24 08:35:20 -0700295 ("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
hassof390d2c2004-09-10 20:48:21 +0000296 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
297 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000298 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
299 " cksum 0x%04x, lifetime %us", areatag,
300 ntohl (lsp->lsp_header->seq_num),
301 ntohs (lsp->lsp_header->checksum),
302 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000303 }
jardineb5d44e2003-12-23 08:09:43 +0000304
305 return LSP_OLDER;
306}
307
Josh Bailey3f045a02012-03-24 08:35:20 -0700308static void
309lsp_auth_add (struct isis_lsp *lsp)
310{
311 struct isis_passwd *passwd;
312 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
313
314 /*
315 * Add the authentication info if its present
316 */
317 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
318 (passwd = &lsp->area->domain_passwd);
319 switch (passwd->type)
320 {
321 /* Cleartext */
322 case ISIS_PASSWD_TYPE_CLEARTXT:
323 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
324 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
325 break;
326
327 /* HMAC MD5 */
328 case ISIS_PASSWD_TYPE_HMAC_MD5:
329 /* Remember where TLV is written so we can later
330 * overwrite the MD5 hash */
331 lsp->auth_tlv_offset = stream_get_endp (lsp->pdu);
332 memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
333 lsp->tlv_data.auth_info.type = ISIS_PASSWD_TYPE_HMAC_MD5;
334 lsp->tlv_data.auth_info.len = ISIS_AUTH_MD5_SIZE;
335 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
336 ISIS_AUTH_MD5_SIZE);
337 tlv_add_authinfo (passwd->type, ISIS_AUTH_MD5_SIZE, hmac_md5_hash,
338 lsp->pdu);
339 break;
340
341 default:
342 break;
343 }
344}
345
346static void
347lsp_auth_update (struct isis_lsp *lsp)
348{
349 struct isis_passwd *passwd;
350 unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
351 uint16_t checksum, rem_lifetime;
352
353 /* For HMAC MD5 we need to recompute the md5 hash and store it */
354 (lsp->level == IS_LEVEL_1) ? (passwd = &lsp->area->area_passwd) :
355 (passwd = &lsp->area->domain_passwd);
356 if (passwd->type != ISIS_PASSWD_TYPE_HMAC_MD5)
357 return;
358
359 /*
360 * In transient conditions (when net is configured where authentication
361 * config and lsp regenerate schedule is not yet run), there could be
362 * an own_lsp with auth_tlv_offset set to 0. In such a case, simply
363 * return, when lsp_regenerate is run, lsp will have auth tlv.
364 */
365 if (lsp->auth_tlv_offset == 0)
366 return;
367
368 /*
369 * RFC 5304 set auth value, checksum and remaining lifetime to zero
370 * before computation and reset to old values after computation.
371 */
372 checksum = lsp->lsp_header->checksum;
373 rem_lifetime = lsp->lsp_header->rem_lifetime;
374 lsp->lsp_header->checksum = 0;
375 lsp->lsp_header->rem_lifetime = 0;
376 /* Set the authentication value as well to zero */
377 memset (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
378 0, ISIS_AUTH_MD5_SIZE);
379 /* Compute autentication value */
380 hmac_md5 (STREAM_DATA (lsp->pdu), stream_get_endp(lsp->pdu),
381 (unsigned char *) &passwd->passwd, passwd->len,
David Lamparter21401f32015-03-03 08:55:26 +0100382 (unsigned char *) &hmac_md5_hash);
Josh Bailey3f045a02012-03-24 08:35:20 -0700383 /* Copy the hash into the stream */
384 memcpy (STREAM_DATA (lsp->pdu) + lsp->auth_tlv_offset + 3,
385 hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
386 memcpy (&lsp->tlv_data.auth_info.passwd, hmac_md5_hash,
387 ISIS_AUTH_MD5_SIZE);
388 /* Copy back the checksum and remaining lifetime */
389 lsp->lsp_header->checksum = checksum;
390 lsp->lsp_header->rem_lifetime = rem_lifetime;
391}
392
hassof390d2c2004-09-10 20:48:21 +0000393void
jardineb5d44e2003-12-23 08:09:43 +0000394lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
395{
396 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000397
jardineb5d44e2003-12-23 08:09:43 +0000398 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
399 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
400 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700401 newseq = seq_num + 1;
hassof390d2c2004-09-10 20:48:21 +0000402
jardineb5d44e2003-12-23 08:09:43 +0000403 lsp->lsp_header->seq_num = htonl (newseq);
Josh Bailey3f045a02012-03-24 08:35:20 -0700404
405 /* Recompute authentication and checksum information */
406 lsp_auth_update (lsp);
407 /* ISO 10589 - 7.3.11 Generation of the checksum
408 * The checksum shall be computed over all fields in the LSP which appear
409 * after the Remaining Lifetime field. This field (and those appearing
410 * before it) are excluded so that the LSP may be aged by systems without
411 * requiring recomputation.
412 */
413 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
414 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
415
416 isis_spf_schedule (lsp->area, lsp->level);
417#ifdef HAVE_IPV6
418 isis_spf_schedule6 (lsp->area, lsp->level);
419#endif
jardineb5d44e2003-12-23 08:09:43 +0000420
421 return;
422}
423
424/*
425 * Genetates checksum for LSP and its frags
426 */
hasso92365882005-01-18 13:53:33 +0000427static void
jardineb5d44e2003-12-23 08:09:43 +0000428lsp_seqnum_update (struct isis_lsp *lsp0)
429{
430 struct isis_lsp *lsp;
hasso3fdb2dd2005-09-28 18:45:54 +0000431 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000432
jardineb5d44e2003-12-23 08:09:43 +0000433 lsp_inc_seqnum (lsp0, 0);
434
435 if (!lsp0->lspu.frags)
436 return;
437
hasso3fdb2dd2005-09-28 18:45:54 +0000438 for (ALL_LIST_ELEMENTS_RO (lsp0->lspu.frags, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +0000439 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000440
jardineb5d44e2003-12-23 08:09:43 +0000441 return;
442}
443
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700444static u_int8_t
445lsp_bits_generate (int level, int overload_bit)
446{
447 u_int8_t lsp_bits = 0;
448 if (level == IS_LEVEL_1)
449 lsp_bits = IS_LEVEL_1;
450 else
451 lsp_bits = IS_LEVEL_1_AND_2;
452 if (overload_bit)
453 lsp_bits |= overload_bit;
454 return lsp_bits;
455}
456
hasso92365882005-01-18 13:53:33 +0000457static void
hassof390d2c2004-09-10 20:48:21 +0000458lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
Josh Bailey3f045a02012-03-24 08:35:20 -0700459 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000460{
hassof390d2c2004-09-10 20:48:21 +0000461 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000462 int retval;
hassof390d2c2004-09-10 20:48:21 +0000463
Josh Bailey3f045a02012-03-24 08:35:20 -0700464 /* free the old lsp data */
465 lsp_clear_data (lsp);
466
jardineb5d44e2003-12-23 08:09:43 +0000467 /* copying only the relevant part of our stream */
Josh Bailey3f045a02012-03-24 08:35:20 -0700468 if (lsp->pdu != NULL)
469 stream_free (lsp->pdu);
paul15935e92005-05-03 09:27:23 +0000470 lsp->pdu = stream_dup (stream);
Josh Bailey3f045a02012-03-24 08:35:20 -0700471
jardineb5d44e2003-12-23 08:09:43 +0000472 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000473 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
474 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
475 ISIS_FIXED_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -0700476 lsp->area = area;
477 lsp->level = level;
jardineb5d44e2003-12-23 08:09:43 +0000478 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000479 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000480 /*
481 * Get LSP data i.e. TLVs
482 */
483 expected |= TLVFLAG_AUTH_INFO;
484 expected |= TLVFLAG_AREA_ADDRS;
485 expected |= TLVFLAG_IS_NEIGHS;
jardineb5d44e2003-12-23 08:09:43 +0000486 expected |= TLVFLAG_NLPID;
487 if (area->dynhostname)
488 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000489 if (area->newmetric)
490 {
491 expected |= TLVFLAG_TE_IS_NEIGHS;
492 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
493 expected |= TLVFLAG_TE_ROUTER_ID;
494 }
jardineb5d44e2003-12-23 08:09:43 +0000495 expected |= TLVFLAG_IPV4_ADDR;
496 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
497 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
498#ifdef HAVE_IPV6
499 expected |= TLVFLAG_IPV6_ADDR;
500 expected |= TLVFLAG_IPV6_REACHABILITY;
501#endif /* HAVE_IPV6 */
502
Josh Bailey3f045a02012-03-24 08:35:20 -0700503 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
504 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
505 ntohs (lsp->lsp_header->pdu_len) -
506 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
507 &expected, &found, &lsp->tlv_data,
508 NULL);
509 if (retval != ISIS_OK)
hassof390d2c2004-09-10 20:48:21 +0000510 {
Josh Bailey3f045a02012-03-24 08:35:20 -0700511 zlog_warn ("Could not parse LSP");
512 return;
513 }
514
515 if ((found & TLVFLAG_DYN_HOSTNAME) && (area->dynhostname))
516 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700517 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
518 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
519 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : IS_LEVEL_1);
hassof390d2c2004-09-10 20:48:21 +0000520 }
jardineb5d44e2003-12-23 08:09:43 +0000521
Josh Bailey3f045a02012-03-24 08:35:20 -0700522 return;
jardineb5d44e2003-12-23 08:09:43 +0000523}
524
525void
Josh Bailey3f045a02012-03-24 08:35:20 -0700526lsp_update (struct isis_lsp *lsp, struct stream *stream,
527 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000528{
hasso4eda93a2005-09-18 17:51:02 +0000529 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000530
Josh Bailey3f045a02012-03-24 08:35:20 -0700531 /* Remove old LSP from database. This is required since the
532 * lsp_update_data will free the lsp->pdu (which has the key, lsp_id)
533 * and will update it with the new data in the stream. */
hasso4eda93a2005-09-18 17:51:02 +0000534 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
535 if (dnode)
536 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000537
jardineb5d44e2003-12-23 08:09:43 +0000538 /* rebuild the lsp data */
Josh Bailey3f045a02012-03-24 08:35:20 -0700539 lsp_update_data (lsp, stream, area, level);
jardineb5d44e2003-12-23 08:09:43 +0000540
Josh Bailey3f045a02012-03-24 08:35:20 -0700541 /* insert the lsp back into the database */
542 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000543}
544
jardineb5d44e2003-12-23 08:09:43 +0000545/* creation of LSP directly from what we received */
546struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000547lsp_new_from_stream_ptr (struct stream *stream,
548 u_int16_t pdu_len, struct isis_lsp *lsp0,
Josh Bailey3f045a02012-03-24 08:35:20 -0700549 struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000550{
551 struct isis_lsp *lsp;
552
hassoaac372f2005-09-01 17:52:33 +0000553 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -0700554 lsp_update_data (lsp, stream, area, level);
hassof390d2c2004-09-10 20:48:21 +0000555
556 if (lsp0 == NULL)
557 {
558 /*
559 * zero lsp -> create the list for fragments
560 */
561 lsp->lspu.frags = list_new ();
562 }
563 else
564 {
565 /*
566 * a fragment -> set the backpointer and add this to zero lsps frag list
567 */
568 lsp->lspu.zero_lsp = lsp0;
569 listnode_add (lsp0->lspu.frags, lsp);
570 }
571
jardineb5d44e2003-12-23 08:09:43 +0000572 return lsp;
573}
574
575struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000576lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
577 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000578{
579 struct isis_lsp *lsp;
580
hassoaac372f2005-09-01 17:52:33 +0000581 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000582 if (!lsp)
583 {
584 /* FIXME: set lspdbol bit */
585 zlog_warn ("lsp_new(): out of memory");
586 return NULL;
587 }
Josh Bailey3f045a02012-03-24 08:35:20 -0700588 /* FIXME: Should be minimal mtu? */
589 lsp->pdu = stream_new (1500);
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 */
1092 if (area->lsp_gen_interval[level - 1] > (rem_lifetime - 300))
1093 rem_lifetime = area->max_lsp_lifetime[level - 1];
1094
1095 return rem_lifetime;
1096}
1097
1098static u_int16_t
1099lsp_refresh_time (struct isis_lsp *lsp, u_int16_t rem_lifetime)
1100{
1101 struct isis_area *area = lsp->area;
1102 int level = lsp->level;
1103 u_int16_t refresh_time;
1104
1105 /* Add jitter to LSP refresh time */
1106 refresh_time = isis_jitter (area->lsp_refresh[level - 1],
1107 MAX_LSP_GEN_JITTER);
1108
1109 /* RFC 4444 : make sure the refresh time is at least less than 300
1110 * of the remaining lifetime and more than gen interval */
1111 if (refresh_time <= area->lsp_gen_interval[level - 1] ||
1112 refresh_time > (rem_lifetime - 300))
1113 refresh_time = rem_lifetime - 300;
1114
1115 assert (area->lsp_gen_interval[level - 1] < refresh_time);
1116
1117 return refresh_time;
1118}
1119
hasso92365882005-01-18 13:53:33 +00001120static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001121lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1122 int level)
jardineb5d44e2003-12-23 08:09:43 +00001123{
1124 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001125 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1126
jardineb5d44e2003-12-23 08:09:43 +00001127 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1128 LSP_FRAGMENT (frag_id) = frag_num;
Josh Bailey3f045a02012-03-24 08:35:20 -07001129 /* FIXME add authentication TLV for fragment LSPs */
jardineb5d44e2003-12-23 08:09:43 +00001130 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001131 if (lsp)
1132 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001133 /* Clear the TLVs */
hassof390d2c2004-09-10 20:48:21 +00001134 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +00001135 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001136 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001137 lsp = lsp_new (frag_id, ntohs(lsp0->lsp_header->rem_lifetime), 0,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001138 lsp_bits_generate (level, area->overload_bit), 0, level);
Josh Bailey3f045a02012-03-24 08:35:20 -07001139 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00001140 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001141 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001142 listnode_add (lsp0->lspu.frags, lsp);
1143 lsp->lspu.zero_lsp = lsp0;
jardineb5d44e2003-12-23 08:09:43 +00001144 return lsp;
1145}
1146
1147/*
1148 * Builds the LSP data part. This func creates a new frag whenever
1149 * area->lsp_frag_threshold is exceeded.
1150 */
hasso92365882005-01-18 13:53:33 +00001151static void
Josh Bailey3f045a02012-03-24 08:35:20 -07001152lsp_build (struct isis_lsp *lsp, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00001153{
1154 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001155 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001156 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001157 int level = lsp->level;
1158 struct isis_circuit *circuit;
1159 struct prefix_ipv4 *ipv4;
1160 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001161 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001162 struct isis_adjacency *nei;
1163#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001164 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001165 struct ipv6_reachability *ip6reach;
1166#endif /* HAVE_IPV6 */
1167 struct tlvs tlv_data;
1168 struct isis_lsp *lsp0 = lsp;
hasso18a6dce2004-10-03 18:18:34 +00001169 struct in_addr *routerid;
Josh Bailey3f045a02012-03-24 08:35:20 -07001170 uint32_t expected = 0, found = 0;
1171 uint32_t metric;
1172 u_char zero_id[ISIS_SYS_ID_LEN + 1];
1173 int retval = ISIS_OK;
1174
1175 /*
1176 * Building the zero lsp
1177 */
1178 memset (zero_id, 0, ISIS_SYS_ID_LEN + 1);
1179
1180 /* Reset stream endp. Stream is always there and on every LSP refresh only
1181 * TLV part of it is overwritten. So we must seek past header we will not
1182 * touch. */
1183 stream_reset (lsp->pdu);
1184 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1185
1186 /*
1187 * Add the authentication info if its present
1188 */
1189 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001190
1191 /*
1192 * First add the tlvs related to area
1193 */
hassof390d2c2004-09-10 20:48:21 +00001194
jardineb5d44e2003-12-23 08:09:43 +00001195 /* Area addresses */
1196 if (lsp->tlv_data.area_addrs == NULL)
1197 lsp->tlv_data.area_addrs = list_new ();
1198 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
Josh Bailey3f045a02012-03-24 08:35:20 -07001199 if (listcount (lsp->tlv_data.area_addrs) > 0)
1200 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1201
jardineb5d44e2003-12-23 08:09:43 +00001202 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001203 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001204#ifdef HAVE_IPV6
1205 || area->ipv6_circuits > 0
1206#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001207 )
jardineb5d44e2003-12-23 08:09:43 +00001208 {
hassoaac372f2005-09-01 17:52:33 +00001209 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001210 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001211 if (area->ip_circuits > 0)
1212 {
1213 lsp->tlv_data.nlpids->count++;
1214 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1215 }
jardineb5d44e2003-12-23 08:09:43 +00001216#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001217 if (area->ipv6_circuits > 0)
1218 {
1219 lsp->tlv_data.nlpids->count++;
1220 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1221 NLPID_IPV6;
1222 }
jardineb5d44e2003-12-23 08:09:43 +00001223#endif /* HAVE_IPV6 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001224 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00001225 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001226
jardineb5d44e2003-12-23 08:09:43 +00001227 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001228 if (area->dynhostname)
1229 {
1230 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1231 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001232
hassof390d2c2004-09-10 20:48:21 +00001233 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1234 strlen (unix_hostname ()));
1235 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
Josh Bailey3f045a02012-03-24 08:35:20 -07001236 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001237 }
jardineb5d44e2003-12-23 08:09:43 +00001238
hasso81ad8f62005-09-26 17:58:24 +00001239 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1240 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1241 * LSP and this address is same as router id. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001242 if (isis->router_id != 0)
hasso18a6dce2004-10-03 18:18:34 +00001243 {
hasso18a6dce2004-10-03 18:18:34 +00001244 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001245 {
1246 lsp->tlv_data.ipv4_addrs = list_new ();
1247 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1248 }
hasso18a6dce2004-10-03 18:18:34 +00001249
1250 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001251 routerid->s_addr = isis->router_id;
hasso18a6dce2004-10-03 18:18:34 +00001252 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001253 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001254
hasso81ad8f62005-09-26 17:58:24 +00001255 /* Exactly same data is put into TE router ID TLV, but only if new style
1256 * TLV's are in use. */
1257 if (area->newmetric)
1258 {
1259 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1260 sizeof (struct in_addr));
Josh Bailey3f045a02012-03-24 08:35:20 -07001261 lsp->tlv_data.router_id->id.s_addr = isis->router_id;
1262 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu,
1263 TE_ROUTER_ID);
hasso81ad8f62005-09-26 17:58:24 +00001264 }
hasso18a6dce2004-10-03 18:18:34 +00001265 }
hassof1082d12005-09-19 04:23:34 +00001266
hasso81ad8f62005-09-26 17:58:24 +00001267 memset (&tlv_data, 0, sizeof (struct tlvs));
1268
hassof1082d12005-09-19 04:23:34 +00001269#ifdef TOPOLOGY_GENERATE
1270 /* If topology exists (and we create topology for level 1 only), create
1271 * (hardcoded) link to topology. */
Josh Bailey3f045a02012-03-24 08:35:20 -07001272 if (area->topology && level == IS_LEVEL_1)
hassof1082d12005-09-19 04:23:34 +00001273 {
1274 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001275 {
1276 tlv_data.is_neighs = list_new ();
1277 tlv_data.is_neighs->del = free_tlv;
1278 }
hasso3fdb2dd2005-09-28 18:45:54 +00001279 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001280
1281 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1282 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1283 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1284 is_neigh->metrics.metric_default = 0x01;
1285 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1286 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1287 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1288 listnode_add (tlv_data.is_neighs, is_neigh);
1289 }
1290#endif /* TOPOLOGY_GENERATE */
1291
hasso18a6dce2004-10-03 18:18:34 +00001292 /*
jardineb5d44e2003-12-23 08:09:43 +00001293 * Then build lists of tlvs related to circuits
1294 */
hasso3fdb2dd2005-09-28 18:45:54 +00001295 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001296 {
hassof390d2c2004-09-10 20:48:21 +00001297 if (circuit->state != C_STATE_UP)
1298 continue;
jardineb5d44e2003-12-23 08:09:43 +00001299
hassof390d2c2004-09-10 20:48:21 +00001300 /*
1301 * Add IPv4 internal reachability of this circuit
1302 */
1303 if (circuit->ip_router && circuit->ip_addrs &&
1304 circuit->ip_addrs->count > 0)
1305 {
hassoaa4376e2005-09-26 17:39:48 +00001306 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001307 {
hassoaa4376e2005-09-26 17:39:48 +00001308 if (tlv_data.ipv4_int_reachs == NULL)
1309 {
1310 tlv_data.ipv4_int_reachs = list_new ();
1311 tlv_data.ipv4_int_reachs->del = free_tlv;
1312 }
hasso3fdb2dd2005-09-28 18:45:54 +00001313 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001314 {
1315 ipreach =
1316 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1317 ipreach->metrics = circuit->metrics[level - 1];
1318 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1319 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1320 (ipv4->prefix.s_addr));
1321 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1322 }
hassof390d2c2004-09-10 20:48:21 +00001323 }
hassoaa4376e2005-09-26 17:39:48 +00001324 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001325 {
hassoaa4376e2005-09-26 17:39:48 +00001326 if (tlv_data.te_ipv4_reachs == NULL)
1327 {
1328 tlv_data.te_ipv4_reachs = list_new ();
1329 tlv_data.te_ipv4_reachs->del = free_tlv;
1330 }
hasso3fdb2dd2005-09-28 18:45:54 +00001331 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001332 {
1333 /* FIXME All this assumes that we have no sub TLVs. */
1334 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1335 sizeof (struct te_ipv4_reachability) +
1336 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001337
1338 if (area->oldmetric)
1339 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1340 else
1341 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1342
hassoaa4376e2005-09-26 17:39:48 +00001343 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1344 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1345 (ipv4->prefixlen + 7)/8);
1346 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1347 }
hassof390d2c2004-09-10 20:48:21 +00001348 }
hassof390d2c2004-09-10 20:48:21 +00001349 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001350
jardineb5d44e2003-12-23 08:09:43 +00001351#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001352 /*
1353 * Add IPv6 reachability of this circuit
1354 */
1355 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1356 circuit->ipv6_non_link->count > 0)
1357 {
1358
1359 if (tlv_data.ipv6_reachs == NULL)
1360 {
1361 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001362 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001363 }
hasso3fdb2dd2005-09-28 18:45:54 +00001364 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001365 {
hassof390d2c2004-09-10 20:48:21 +00001366 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001367 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001368
1369 if (area->oldmetric)
1370 ip6reach->metric =
1371 htonl (circuit->metrics[level - 1].metric_default);
1372 else
1373 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1374
hassof390d2c2004-09-10 20:48:21 +00001375 ip6reach->control_info = 0;
1376 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001377 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1378 apply_mask_ipv6 (ip6prefix);
1379 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1380 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001381 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1382 }
1383 }
1384#endif /* HAVE_IPV6 */
1385
1386 switch (circuit->circ_type)
1387 {
1388 case CIRCUIT_T_BROADCAST:
Josh Bailey3f045a02012-03-24 08:35:20 -07001389 if (level & circuit->is_type)
hassof390d2c2004-09-10 20:48:21 +00001390 {
hassoaa4376e2005-09-26 17:39:48 +00001391 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001392 {
hassoaa4376e2005-09-26 17:39:48 +00001393 if (tlv_data.is_neighs == NULL)
1394 {
1395 tlv_data.is_neighs = list_new ();
1396 tlv_data.is_neighs->del = free_tlv;
1397 }
1398 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001399 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001400 memcpy (is_neigh->neigh_id,
1401 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1402 else
1403 memcpy (is_neigh->neigh_id,
1404 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1405 is_neigh->metrics = circuit->metrics[level - 1];
Josh Bailey3f045a02012-03-24 08:35:20 -07001406 if (!memcmp (is_neigh->neigh_id, zero_id,
1407 ISIS_SYS_ID_LEN + 1))
1408 XFREE (MTYPE_ISIS_TLV, is_neigh);
1409 else
1410 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001411 }
hassoaa4376e2005-09-26 17:39:48 +00001412 if (area->newmetric)
1413 {
hassoaa4376e2005-09-26 17:39:48 +00001414 if (tlv_data.te_is_neighs == NULL)
1415 {
1416 tlv_data.te_is_neighs = list_new ();
1417 tlv_data.te_is_neighs->del = free_tlv;
1418 }
1419 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1420 sizeof (struct te_is_neigh));
Josh Bailey3f045a02012-03-24 08:35:20 -07001421 if (level == IS_LEVEL_1)
hassoaa4376e2005-09-26 17:39:48 +00001422 memcpy (te_is_neigh->neigh_id,
1423 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1424 else
1425 memcpy (te_is_neigh->neigh_id,
1426 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001427 if (area->oldmetric)
Josh Bailey3f045a02012-03-24 08:35:20 -07001428 metric = circuit->metrics[level - 1].metric_default;
hasso309ddb12005-09-26 18:06:47 +00001429 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001430 metric = circuit->te_metric[level - 1];
1431 SET_TE_METRIC(te_is_neigh, metric);
1432 if (!memcmp (te_is_neigh->neigh_id, zero_id,
1433 ISIS_SYS_ID_LEN + 1))
1434 XFREE (MTYPE_ISIS_TLV, te_is_neigh);
1435 else
1436 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
hassoaa4376e2005-09-26 17:39:48 +00001437 }
hassof390d2c2004-09-10 20:48:21 +00001438 }
1439 break;
1440 case CIRCUIT_T_P2P:
1441 nei = circuit->u.p2p.neighbor;
1442 if (nei && (level & nei->circuit_t))
1443 {
hassoaa4376e2005-09-26 17:39:48 +00001444 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001445 {
hassoaa4376e2005-09-26 17:39:48 +00001446 if (tlv_data.is_neighs == NULL)
1447 {
1448 tlv_data.is_neighs = list_new ();
1449 tlv_data.is_neighs->del = free_tlv;
1450 }
1451 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1452 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1453 is_neigh->metrics = circuit->metrics[level - 1];
1454 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001455 }
hassoaa4376e2005-09-26 17:39:48 +00001456 if (area->newmetric)
1457 {
1458 uint32_t metric;
1459
1460 if (tlv_data.te_is_neighs == NULL)
1461 {
1462 tlv_data.te_is_neighs = list_new ();
1463 tlv_data.te_is_neighs->del = free_tlv;
1464 }
1465 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1466 sizeof (struct te_is_neigh));
1467 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07001468 metric = circuit->te_metric[level - 1];
1469 SET_TE_METRIC(te_is_neigh, metric);
hassoaa4376e2005-09-26 17:39:48 +00001470 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1471 }
hassof390d2c2004-09-10 20:48:21 +00001472 }
1473 break;
Josh Bailey3f045a02012-03-24 08:35:20 -07001474 case CIRCUIT_T_LOOPBACK:
1475 break;
hassof390d2c2004-09-10 20:48:21 +00001476 default:
1477 zlog_warn ("lsp_area_create: unknown circuit type");
1478 }
1479 }
1480
1481 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1482 {
1483 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1484 lsp->tlv_data.ipv4_int_reachs = list_new ();
1485 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1486 &lsp->tlv_data.ipv4_int_reachs,
1487 IPV4_REACH_LEN, area->lsp_frag_threshold,
1488 tlv_add_ipv4_reachs);
1489 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1490 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1491 lsp0, area, level);
1492 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001493
hassoaa4376e2005-09-26 17:39:48 +00001494 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1495 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1496 * TLVs (sub TLVs!). */
1497 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1498 {
1499 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1500 lsp->tlv_data.te_ipv4_reachs = list_new ();
1501 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1502 &lsp->tlv_data.te_ipv4_reachs,
Josh Bailey3f045a02012-03-24 08:35:20 -07001503 TE_IPV4_REACH_LEN, area->lsp_frag_threshold,
1504 tlv_add_te_ipv4_reachs);
hassoaa4376e2005-09-26 17:39:48 +00001505 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1506 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1507 lsp0, area, level);
1508 }
hassof390d2c2004-09-10 20:48:21 +00001509
1510#ifdef HAVE_IPV6
1511 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1512 {
1513 if (lsp->tlv_data.ipv6_reachs == NULL)
1514 lsp->tlv_data.ipv6_reachs = list_new ();
1515 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1516 &lsp->tlv_data.ipv6_reachs,
1517 IPV6_REACH_LEN, area->lsp_frag_threshold,
1518 tlv_add_ipv6_reachs);
1519 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1520 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1521 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001522 }
1523#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001524
1525 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1526 {
1527 if (lsp->tlv_data.is_neighs == NULL)
1528 lsp->tlv_data.is_neighs = list_new ();
1529 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1530 &lsp->tlv_data.is_neighs,
1531 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1532 tlv_add_is_neighs);
1533 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1534 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1535 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001536 }
jardineb5d44e2003-12-23 08:09:43 +00001537
hassoaa4376e2005-09-26 17:39:48 +00001538 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1539 {
1540 if (lsp->tlv_data.te_is_neighs == NULL)
1541 lsp->tlv_data.te_is_neighs = list_new ();
1542 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1543 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1544 tlv_add_te_is_neighs);
1545 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1546 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1547 lsp0, area, level);
1548 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001549 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassoaa4376e2005-09-26 17:39:48 +00001550
1551 free_tlvs (&tlv_data);
Josh Bailey3f045a02012-03-24 08:35:20 -07001552
1553 /* Validate the LSP */
1554 retval = parse_tlvs (area->area_tag, STREAM_DATA (lsp->pdu) +
1555 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
1556 stream_get_endp (lsp->pdu) -
1557 ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
1558 &expected, &found, &tlv_data, NULL);
1559 assert (retval == ISIS_OK);
1560
jardineb5d44e2003-12-23 08:09:43 +00001561 return;
1562}
jardineb5d44e2003-12-23 08:09:43 +00001563
1564/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001565 * 7.3.7 and 7.3.9 Generation on non-pseudonode LSPs
jardineb5d44e2003-12-23 08:09:43 +00001566 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001567int
1568lsp_generate (struct isis_area *area, int level)
hassof390d2c2004-09-10 20:48:21 +00001569{
jardineb5d44e2003-12-23 08:09:43 +00001570 struct isis_lsp *oldlsp, *newlsp;
1571 u_int32_t seq_num = 0;
1572 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001573 u_int16_t rem_lifetime, refresh_time;
1574
1575 if ((area == NULL) || (area->is_type & level) != level)
1576 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001577
1578 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1579 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1580
1581 /* only builds the lsp if the area shares the level */
Josh Bailey3f045a02012-03-24 08:35:20 -07001582 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1583 if (oldlsp)
hassof390d2c2004-09-10 20:48:21 +00001584 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001585 /* FIXME: we should actually initiate a purge */
1586 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1587 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1588 area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001589 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001590 rem_lifetime = lsp_rem_lifetime (area, level);
1591 newlsp = lsp_new (lspid, rem_lifetime, seq_num,
1592 area->is_type | area->overload_bit, 0, level);
1593 newlsp->area = area;
1594 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001595
Josh Bailey3f045a02012-03-24 08:35:20 -07001596 lsp_insert (newlsp, area->lspdb[level - 1]);
1597 /* build_lsp_data (newlsp, area); */
1598 lsp_build (newlsp, area);
1599 /* time to calculate our checksum */
1600 lsp_seqnum_update (newlsp);
1601 lsp_set_all_srmflags (newlsp);
1602
1603 refresh_time = lsp_refresh_time (newlsp, rem_lifetime);
1604 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
1605 if (level == IS_LEVEL_1)
1606 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1607 lsp_l1_refresh, area, refresh_time);
1608 else if (level == IS_LEVEL_2)
1609 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1610 lsp_l2_refresh, area, refresh_time);
1611
1612 if (isis->debugs & DEBUG_UPDATE_PACKETS)
hassof390d2c2004-09-10 20:48:21 +00001613 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001614 zlog_debug ("ISIS-Upd (%s): Building L%d LSP %s, len %d, "
1615 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1616 area->area_tag, level,
1617 rawlspid_print (newlsp->lsp_header->lsp_id),
1618 ntohl (newlsp->lsp_header->pdu_len),
1619 ntohl (newlsp->lsp_header->seq_num),
1620 ntohs (newlsp->lsp_header->checksum),
1621 ntohs (newlsp->lsp_header->rem_lifetime),
1622 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001623 }
jardineb5d44e2003-12-23 08:09:43 +00001624
1625 return ISIS_OK;
1626}
1627
1628/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001629 * Search own LSPs, update holding time and set SRM
jardineb5d44e2003-12-23 08:09:43 +00001630 */
hasso92365882005-01-18 13:53:33 +00001631static int
Josh Bailey3f045a02012-03-24 08:35:20 -07001632lsp_regenerate (struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +00001633{
David Lampartere8aca322012-11-27 01:10:30 +00001634 dict_t *lspdb;
jardineb5d44e2003-12-23 08:09:43 +00001635 struct isis_lsp *lsp, *frag;
1636 struct listnode *node;
1637 u_char lspid[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001638 u_int16_t rem_lifetime, refresh_time;
1639
1640 if ((area == NULL) || (area->is_type & level) != level)
1641 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001642
David Lampartere8aca322012-11-27 01:10:30 +00001643 lspdb = area->lspdb[level - 1];
1644
jardineb5d44e2003-12-23 08:09:43 +00001645 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1646 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001647
jardineb5d44e2003-12-23 08:09:43 +00001648 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001649
hassof390d2c2004-09-10 20:48:21 +00001650 if (!lsp)
1651 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001652 zlog_err ("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
1653 area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001654 return ISIS_ERROR;
1655 }
1656
1657 lsp_clear_data (lsp);
Josh Bailey3f045a02012-03-24 08:35:20 -07001658 lsp_build (lsp, area);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001659 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, area->overload_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001660 rem_lifetime = lsp_rem_lifetime (area, level);
1661 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00001662 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001663
Josh Bailey3f045a02012-03-24 08:35:20 -07001664 lsp->last_generated = time (NULL);
1665 lsp_set_all_srmflags (lsp);
1666 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
1667 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001668 frag->lsp_header->lsp_bits = lsp_bits_generate (level,
1669 area->overload_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07001670 /* Set the lifetime values of all the fragments to the same value,
1671 * so that no fragment expires before the lsp is refreshed.
1672 */
1673 frag->lsp_header->rem_lifetime = htons (rem_lifetime);
1674 lsp_set_all_srmflags (frag);
1675 }
1676
1677 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1678 if (level == IS_LEVEL_1)
1679 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1680 lsp_l1_refresh, area, refresh_time);
1681 else if (level == IS_LEVEL_2)
1682 THREAD_TIMER_ON (master, area->t_lsp_refresh[level - 1],
1683 lsp_l2_refresh, area, refresh_time);
1684
hassof390d2c2004-09-10 20:48:21 +00001685 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1686 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001687 zlog_debug ("ISIS-Upd (%s): Refreshing our L%d LSP %s, len %d, "
1688 "seq 0x%08x, cksum 0x%04x, lifetime %us refresh %us",
1689 area->area_tag, level,
1690 rawlspid_print (lsp->lsp_header->lsp_id),
1691 ntohl (lsp->lsp_header->pdu_len),
1692 ntohl (lsp->lsp_header->seq_num),
1693 ntohs (lsp->lsp_header->checksum),
1694 ntohs (lsp->lsp_header->rem_lifetime),
1695 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00001696 }
jardineb5d44e2003-12-23 08:09:43 +00001697
jardineb5d44e2003-12-23 08:09:43 +00001698 return ISIS_OK;
1699}
1700
jardineb5d44e2003-12-23 08:09:43 +00001701/*
Josh Bailey3f045a02012-03-24 08:35:20 -07001702 * Something has changed or periodic refresh -> regenerate LSP
jardineb5d44e2003-12-23 08:09:43 +00001703 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001704static int
1705lsp_l1_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001706{
1707 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001708
1709 area = THREAD_ARG (thread);
1710 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001711
jardineb5d44e2003-12-23 08:09:43 +00001712 area->t_lsp_refresh[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07001713 area->lsp_regenerate_pending[0] = 0;
hassof390d2c2004-09-10 20:48:21 +00001714
Josh Bailey3f045a02012-03-24 08:35:20 -07001715 if ((area->is_type & IS_LEVEL_1) == 0)
1716 return ISIS_ERROR;
jardineb5d44e2003-12-23 08:09:43 +00001717
Josh Bailey3f045a02012-03-24 08:35:20 -07001718 return lsp_regenerate (area, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00001719}
1720
Josh Bailey3f045a02012-03-24 08:35:20 -07001721static int
1722lsp_l2_refresh (struct thread *thread)
jardineb5d44e2003-12-23 08:09:43 +00001723{
1724 struct isis_area *area;
jardineb5d44e2003-12-23 08:09:43 +00001725
1726 area = THREAD_ARG (thread);
1727 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001728
jardineb5d44e2003-12-23 08:09:43 +00001729 area->t_lsp_refresh[1] = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001730 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001731
Josh Bailey3f045a02012-03-24 08:35:20 -07001732 if ((area->is_type & IS_LEVEL_2) == 0)
1733 return ISIS_ERROR;
1734
1735 return lsp_regenerate (area, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00001736}
1737
hassof390d2c2004-09-10 20:48:21 +00001738int
Josh Bailey3f045a02012-03-24 08:35:20 -07001739lsp_regenerate_schedule (struct isis_area *area, int level, int all_pseudo)
jardineb5d44e2003-12-23 08:09:43 +00001740{
1741 struct isis_lsp *lsp;
1742 u_char id[ISIS_SYS_ID_LEN + 2];
1743 time_t now, diff;
Josh Bailey3f045a02012-03-24 08:35:20 -07001744 struct listnode *cnode;
1745 struct isis_circuit *circuit;
1746 int lvl;
1747
1748 if (area == NULL)
1749 return ISIS_ERROR;
1750
hassof390d2c2004-09-10 20:48:21 +00001751 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1752 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001753 now = time (NULL);
Josh Bailey3f045a02012-03-24 08:35:20 -07001754
1755 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
hassof390d2c2004-09-10 20:48:21 +00001756 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001757 if (!((level & lvl) && (area->is_type & lvl)))
1758 continue;
1759
1760 if (area->lsp_regenerate_pending[lvl - 1])
1761 continue;
1762
1763 lsp = lsp_search (id, area->lspdb[lvl - 1]);
1764 if (!lsp)
1765 continue;
1766
hassof390d2c2004-09-10 20:48:21 +00001767 /*
1768 * Throttle avoidance
1769 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001770 THREAD_TIMER_OFF (area->t_lsp_refresh[lvl - 1]);
hassof390d2c2004-09-10 20:48:21 +00001771 diff = now - lsp->last_generated;
Josh Bailey3f045a02012-03-24 08:35:20 -07001772 if (diff < area->lsp_gen_interval[lvl - 1])
1773 {
1774 area->lsp_regenerate_pending[lvl - 1] = 1;
1775 if (lvl == IS_LEVEL_1)
1776 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1777 lsp_l1_refresh, area,
1778 area->lsp_gen_interval[lvl - 1] - diff);
1779 else if (lvl == IS_LEVEL_2)
1780 THREAD_TIMER_ON (master, area->t_lsp_refresh[lvl - 1],
1781 lsp_l2_refresh, area,
1782 area->lsp_gen_interval[lvl - 1] - diff);
1783 }
hassof390d2c2004-09-10 20:48:21 +00001784 else
Josh Bailey3f045a02012-03-24 08:35:20 -07001785 {
1786 lsp_regenerate (area, lvl);
1787 }
hassof390d2c2004-09-10 20:48:21 +00001788 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001789
1790 if (all_pseudo)
hassof390d2c2004-09-10 20:48:21 +00001791 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001792 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
1793 lsp_regenerate_schedule_pseudo (circuit, level);
hassof390d2c2004-09-10 20:48:21 +00001794 }
1795
1796 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001797}
1798
1799/*
1800 * Funcs for pseudonode LSPs
1801 */
1802
1803/*
1804 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1805 */
hasso92365882005-01-18 13:53:33 +00001806static void
hassof390d2c2004-09-10 20:48:21 +00001807lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1808 int level)
jardineb5d44e2003-12-23 08:09:43 +00001809{
1810 struct isis_adjacency *adj;
1811 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001812 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001813 struct es_neigh *es_neigh;
1814 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001815 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +00001816
jardineb5d44e2003-12-23 08:09:43 +00001817 lsp->level = level;
Josh Bailey3f045a02012-03-24 08:35:20 -07001818 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07001819 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0);
jardineb5d44e2003-12-23 08:09:43 +00001820
1821 /*
1822 * add self to IS neighbours
1823 */
hassoaa4376e2005-09-26 17:39:48 +00001824 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001825 {
hassoaa4376e2005-09-26 17:39:48 +00001826 if (lsp->tlv_data.is_neighs == NULL)
1827 {
1828 lsp->tlv_data.is_neighs = list_new ();
1829 lsp->tlv_data.is_neighs->del = free_tlv;
1830 }
1831 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001832
hassoaa4376e2005-09-26 17:39:48 +00001833 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1834 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1835 }
1836 if (circuit->area->newmetric)
1837 {
1838 if (lsp->tlv_data.te_is_neighs == NULL)
1839 {
1840 lsp->tlv_data.te_is_neighs = list_new ();
1841 lsp->tlv_data.te_is_neighs->del = free_tlv;
1842 }
1843 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1844
1845 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1846 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1847 }
hassof390d2c2004-09-10 20:48:21 +00001848
1849 adj_list = list_new ();
1850 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1851
hasso3fdb2dd2005-09-28 18:45:54 +00001852 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001853 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001854 if (adj->level & level)
hassof390d2c2004-09-10 20:48:21 +00001855 {
Josh Bailey3f045a02012-03-24 08:35:20 -07001856 if ((level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1857 (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00001858 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
Josh Bailey3f045a02012-03-24 08:35:20 -07001859 (level == IS_LEVEL_2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
hassof390d2c2004-09-10 20:48:21 +00001860 {
1861 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00001862 if (circuit->area->oldmetric)
1863 {
1864 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001865
hassoaa4376e2005-09-26 17:39:48 +00001866 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1867 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1868 }
1869 if (circuit->area->newmetric)
1870 {
1871 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1872 sizeof (struct te_is_neigh));
1873 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1874 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1875 }
hassof390d2c2004-09-10 20:48:21 +00001876 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001877 else if (level == IS_LEVEL_1 && adj->sys_type == ISIS_SYSTYPE_ES)
hassof390d2c2004-09-10 20:48:21 +00001878 {
1879 /* an ES neigbour add it, if we are building level 1 LSP */
1880 /* FIXME: the tlv-format is hard to use here */
1881 if (lsp->tlv_data.es_neighs == NULL)
1882 {
1883 lsp->tlv_data.es_neighs = list_new ();
1884 lsp->tlv_data.es_neighs->del = free_tlv;
1885 }
paul15935e92005-05-03 09:27:23 +00001886 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1887
hassof390d2c2004-09-10 20:48:21 +00001888 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001889 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001890 }
1891 }
jardineb5d44e2003-12-23 08:09:43 +00001892 }
Josh Bailey3f045a02012-03-24 08:35:20 -07001893 list_delete (adj_list);
hassof390d2c2004-09-10 20:48:21 +00001894
hassoc0fb2a52005-09-03 16:29:40 +00001895 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001896 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001897 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1898
jardineb5d44e2003-12-23 08:09:43 +00001899 /*
1900 * Add the authentication info if it's present
1901 */
Josh Bailey3f045a02012-03-24 08:35:20 -07001902 lsp_auth_add (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001903
1904 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1905 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1906
hassoaa4376e2005-09-26 17:39:48 +00001907 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
1908 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
1909
jardineb5d44e2003-12-23 08:09:43 +00001910 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1911 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1912
paul9985f832005-02-09 15:51:56 +00001913 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001914
Josh Bailey3f045a02012-03-24 08:35:20 -07001915 /* Recompute authentication and checksum information */
1916 lsp_auth_update (lsp);
1917 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
1918 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +00001919
1920 return;
1921}
1922
Josh Bailey3f045a02012-03-24 08:35:20 -07001923int
1924lsp_generate_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00001925{
1926 dict_t *lspdb = circuit->area->lspdb[level - 1];
1927 struct isis_lsp *lsp;
1928 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
Josh Bailey3f045a02012-03-24 08:35:20 -07001929 u_int16_t rem_lifetime, refresh_time;
1930
1931 if ((circuit->is_type & level) != level ||
1932 (circuit->state != C_STATE_UP) ||
1933 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
1934 (circuit->u.bc.is_dr[level - 1] == 0))
1935 return ISIS_ERROR;
1936
1937 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1938 LSP_FRAGMENT (lsp_id) = 0;
1939 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1940
1941 /*
1942 * If for some reason have a pseudo LSP in the db already -> regenerate
1943 */
1944 if (lsp_search (lsp_id, lspdb))
1945 return lsp_regenerate_schedule_pseudo (circuit, level);
1946
1947 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
1948 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
1949 lsp = lsp_new (lsp_id, rem_lifetime, 1, circuit->area->is_type, 0, level);
1950 lsp->area = circuit->area;
1951
1952 lsp_build_pseudo (lsp, circuit, level);
1953
1954 lsp->own_lsp = 1;
1955 lsp_insert (lsp, lspdb);
1956 lsp_set_all_srmflags (lsp);
1957
1958 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
1959 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
1960 circuit->lsp_regenerate_pending[level - 1] = 0;
1961 if (level == IS_LEVEL_1)
1962 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1963 lsp_l1_refresh_pseudo, circuit, refresh_time);
1964 else if (level == IS_LEVEL_2)
1965 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
1966 lsp_l2_refresh_pseudo, circuit, refresh_time);
1967
1968 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1969 {
1970 zlog_debug ("ISIS-Upd (%s): Building L%d Pseudo LSP %s, len %d, "
1971 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
1972 circuit->area->area_tag, level,
1973 rawlspid_print (lsp->lsp_header->lsp_id),
1974 ntohl (lsp->lsp_header->pdu_len),
1975 ntohl (lsp->lsp_header->seq_num),
1976 ntohs (lsp->lsp_header->checksum),
1977 ntohs (lsp->lsp_header->rem_lifetime),
1978 refresh_time);
1979 }
1980
1981 return ISIS_OK;
1982}
1983
1984static int
1985lsp_regenerate_pseudo (struct isis_circuit *circuit, int level)
1986{
1987 dict_t *lspdb = circuit->area->lspdb[level - 1];
1988 struct isis_lsp *lsp;
1989 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
1990 u_int16_t rem_lifetime, refresh_time;
1991
1992 if ((circuit->is_type & level) != level ||
1993 (circuit->state != C_STATE_UP) ||
1994 (circuit->circ_type != CIRCUIT_T_BROADCAST) ||
1995 (circuit->u.bc.is_dr[level - 1] == 0))
1996 return ISIS_ERROR;
hassof390d2c2004-09-10 20:48:21 +00001997
jardineb5d44e2003-12-23 08:09:43 +00001998 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001999 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2000 LSP_FRAGMENT (lsp_id) = 0;
2001
jardineb5d44e2003-12-23 08:09:43 +00002002 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002003
2004 if (!lsp)
2005 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002006 zlog_err ("lsp_regenerate_pseudo: no l%d LSP %s found!",
2007 level, rawlspid_print (lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002008 return ISIS_ERROR;
2009 }
2010 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002011
2012 lsp_build_pseudo (lsp, circuit, level);
2013
Josh Bailey3f045a02012-03-24 08:35:20 -07002014 /* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002015 lsp->lsp_header->lsp_bits = lsp_bits_generate (level, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002016 rem_lifetime = lsp_rem_lifetime (circuit->area, level);
2017 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002018 lsp_inc_seqnum (lsp, 0);
Josh Bailey3f045a02012-03-24 08:35:20 -07002019 lsp->last_generated = time (NULL);
2020 lsp_set_all_srmflags (lsp);
2021
2022 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
2023 if (level == IS_LEVEL_1)
2024 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2025 lsp_l1_refresh_pseudo, circuit, refresh_time);
2026 else if (level == IS_LEVEL_2)
2027 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[level - 1],
2028 lsp_l2_refresh_pseudo, circuit, refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002029
2030 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2031 {
Josh Bailey3f045a02012-03-24 08:35:20 -07002032 zlog_debug ("ISIS-Upd (%s): Refreshing L%d Pseudo LSP %s, len %d, "
2033 "seq 0x%08x, cksum 0x%04x, lifetime %us, refresh %us",
2034 circuit->area->area_tag, level,
2035 rawlspid_print (lsp->lsp_header->lsp_id),
2036 ntohl (lsp->lsp_header->pdu_len),
2037 ntohl (lsp->lsp_header->seq_num),
2038 ntohs (lsp->lsp_header->checksum),
2039 ntohs (lsp->lsp_header->rem_lifetime),
2040 refresh_time);
hassof390d2c2004-09-10 20:48:21 +00002041 }
jardineb5d44e2003-12-23 08:09:43 +00002042
jardineb5d44e2003-12-23 08:09:43 +00002043 return ISIS_OK;
2044}
2045
Josh Bailey3f045a02012-03-24 08:35:20 -07002046/*
2047 * Something has changed or periodic refresh -> regenerate pseudo LSP
2048 */
2049static int
jardineb5d44e2003-12-23 08:09:43 +00002050lsp_l1_refresh_pseudo (struct thread *thread)
2051{
2052 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002053 u_char id[ISIS_SYS_ID_LEN + 2];
jardineb5d44e2003-12-23 08:09:43 +00002054
hassof390d2c2004-09-10 20:48:21 +00002055 circuit = THREAD_ARG (thread);
2056
hasso13c48f72004-09-10 21:19:13 +00002057 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002058 circuit->lsp_regenerate_pending[0] = 0;
hasso13c48f72004-09-10 21:19:13 +00002059
Josh Bailey3f045a02012-03-24 08:35:20 -07002060 if ((circuit->u.bc.is_dr[0] == 0) ||
2061 (circuit->is_type & IS_LEVEL_1) == 0)
2062 {
2063 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2064 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2065 LSP_FRAGMENT (id) = 0;
2066 lsp_purge_pseudo (id, circuit, IS_LEVEL_1);
2067 return ISIS_ERROR;
2068 }
hassof390d2c2004-09-10 20:48:21 +00002069
Josh Bailey3f045a02012-03-24 08:35:20 -07002070 return lsp_regenerate_pseudo (circuit, IS_LEVEL_1);
jardineb5d44e2003-12-23 08:09:43 +00002071}
2072
Josh Bailey3f045a02012-03-24 08:35:20 -07002073static int
jardineb5d44e2003-12-23 08:09:43 +00002074lsp_l2_refresh_pseudo (struct thread *thread)
2075{
2076 struct isis_circuit *circuit;
Josh Bailey3f045a02012-03-24 08:35:20 -07002077 u_char id[ISIS_SYS_ID_LEN + 2];
2078
hassof390d2c2004-09-10 20:48:21 +00002079 circuit = THREAD_ARG (thread);
2080
hasso13c48f72004-09-10 21:19:13 +00002081 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
Josh Bailey3f045a02012-03-24 08:35:20 -07002082 circuit->lsp_regenerate_pending[1] = 0;
hasso13c48f72004-09-10 21:19:13 +00002083
Josh Bailey3f045a02012-03-24 08:35:20 -07002084 if ((circuit->u.bc.is_dr[1] == 0) ||
2085 (circuit->is_type & IS_LEVEL_2) == 0)
2086 {
2087 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2088 LSP_PSEUDO_ID (id) = circuit->circuit_id;
2089 LSP_FRAGMENT (id) = 0;
2090 lsp_purge_pseudo (id, circuit, IS_LEVEL_2);
2091 return ISIS_ERROR;
2092 }
jardineb5d44e2003-12-23 08:09:43 +00002093
Josh Bailey3f045a02012-03-24 08:35:20 -07002094 return lsp_regenerate_pseudo (circuit, IS_LEVEL_2);
jardineb5d44e2003-12-23 08:09:43 +00002095}
2096
hassof390d2c2004-09-10 20:48:21 +00002097int
Josh Bailey3f045a02012-03-24 08:35:20 -07002098lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002099{
2100 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002101 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
2102 time_t now, diff;
2103 int lvl;
jardineb5d44e2003-12-23 08:09:43 +00002104
Josh Bailey3f045a02012-03-24 08:35:20 -07002105 if (circuit == NULL ||
2106 circuit->circ_type != CIRCUIT_T_BROADCAST ||
2107 circuit->state != C_STATE_UP)
2108 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002109
Josh Bailey3f045a02012-03-24 08:35:20 -07002110 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
2111 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2112 LSP_FRAGMENT (lsp_id) = 0;
2113 now = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +00002114
Josh Bailey3f045a02012-03-24 08:35:20 -07002115 for (lvl = IS_LEVEL_1; lvl <= IS_LEVEL_2; lvl++)
2116 {
2117 if (!((level & lvl) && (circuit->is_type & lvl)))
2118 continue;
jardineb5d44e2003-12-23 08:09:43 +00002119
Josh Bailey3f045a02012-03-24 08:35:20 -07002120 if (circuit->u.bc.is_dr[lvl - 1] == 0 ||
2121 circuit->lsp_regenerate_pending[lvl - 1])
2122 continue;
hassof390d2c2004-09-10 20:48:21 +00002123
Josh Bailey3f045a02012-03-24 08:35:20 -07002124 lsp = lsp_search (lsp_id, circuit->area->lspdb[lvl - 1]);
2125 if (!lsp)
2126 continue;
jardineb5d44e2003-12-23 08:09:43 +00002127
Josh Bailey3f045a02012-03-24 08:35:20 -07002128 /*
2129 * Throttle avoidance
2130 */
2131 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
2132 diff = now - lsp->last_generated;
2133 if (diff < circuit->area->lsp_gen_interval[lvl - 1])
2134 {
2135 circuit->lsp_regenerate_pending[lvl - 1] = 1;
2136 if (lvl == IS_LEVEL_1)
2137 THREAD_TIMER_ON (master,
2138 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2139 lsp_l1_refresh_pseudo, circuit,
2140 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2141 else if (lvl == IS_LEVEL_2)
2142 THREAD_TIMER_ON (master,
2143 circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1],
2144 lsp_l2_refresh_pseudo, circuit,
2145 circuit->area->lsp_gen_interval[lvl - 1] - diff);
2146 }
2147 else
2148 {
2149 lsp_regenerate_pseudo (circuit, lvl);
2150 }
2151 }
jardineb5d44e2003-12-23 08:09:43 +00002152
Josh Bailey3f045a02012-03-24 08:35:20 -07002153 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00002154}
2155
jardineb5d44e2003-12-23 08:09:43 +00002156/*
2157 * Walk through LSPs for an area
2158 * - set remaining lifetime
2159 * - set LSPs with SRMflag set for sending
2160 */
hassof390d2c2004-09-10 20:48:21 +00002161int
jardineb5d44e2003-12-23 08:09:43 +00002162lsp_tick (struct thread *thread)
2163{
2164 struct isis_area *area;
2165 struct isis_circuit *circuit;
2166 struct isis_lsp *lsp;
2167 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002168 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002169 dnode_t *dnode, *dnode_next;
2170 int level;
Josh Bailey3f045a02012-03-24 08:35:20 -07002171 u_int16_t rem_lifetime;
jardineb5d44e2003-12-23 08:09:43 +00002172
2173 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002174
jardineb5d44e2003-12-23 08:09:43 +00002175 area = THREAD_ARG (thread);
2176 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002177 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002178 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002179
2180 /*
2181 * Build a list of LSPs with (any) SRMflag set
2182 * and removed the ones that have aged out
2183 */
hassof390d2c2004-09-10 20:48:21 +00002184 for (level = 0; level < ISIS_LEVELS; level++)
2185 {
2186 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
Josh Bailey3f045a02012-03-24 08:35:20 -07002187 {
2188 for (dnode = dict_first (area->lspdb[level]);
2189 dnode != NULL; dnode = dnode_next)
2190 {
2191 dnode_next = dict_next (area->lspdb[level], dnode);
2192 lsp = dnode_get (dnode);
jardineb5d44e2003-12-23 08:09:43 +00002193
Josh Bailey3f045a02012-03-24 08:35:20 -07002194 /*
2195 * The lsp rem_lifetime is kept at 0 for MaxAge or
2196 * ZeroAgeLifetime depending on explicit purge or
2197 * natural age out. So schedule spf only once when
2198 * the first time rem_lifetime becomes 0.
2199 */
2200 rem_lifetime = ntohs(lsp->lsp_header->rem_lifetime);
2201 lsp_set_time (lsp);
2202
2203 /*
2204 * Schedule may run spf which should be done only after
2205 * the lsp rem_lifetime becomes 0 for the first time.
2206 * ISO 10589 - 7.3.16.4 first paragraph.
2207 */
2208 if (rem_lifetime == 1 && lsp->lsp_header->seq_num != 0)
2209 {
2210 /* 7.3.16.4 a) set SRM flags on all */
2211 lsp_set_all_srmflags (lsp);
2212 /* 7.3.16.4 b) retain only the header FIXME */
2213 /* 7.3.16.4 c) record the time to purge FIXME */
2214 /* run/schedule spf */
2215 /* isis_spf_schedule is called inside lsp_destroy() below;
2216 * so it is not needed here. */
2217 /* isis_spf_schedule (lsp->area, lsp->level); */
2218 }
2219
2220 if (lsp->age_out == 0)
2221 {
2222 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2223 area->area_tag,
2224 lsp->level,
2225 rawlspid_print (lsp->lsp_header->lsp_id),
2226 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002227#ifdef TOPOLOGY_GENERATE
Josh Bailey3f045a02012-03-24 08:35:20 -07002228 if (lsp->from_topology)
2229 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
hassof1082d12005-09-19 04:23:34 +00002230#endif /* TOPOLOGY_GENERATE */
Josh Bailey3f045a02012-03-24 08:35:20 -07002231 lsp_destroy (lsp);
2232 lsp = NULL;
2233 dict_delete_free (area->lspdb[level], dnode);
2234 }
2235 else if (flags_any_set (lsp->SRMflags))
2236 listnode_add (lsp_list, lsp);
2237 }
jardineb5d44e2003-12-23 08:09:43 +00002238
Josh Bailey3f045a02012-03-24 08:35:20 -07002239 /*
2240 * Send LSPs on circuits indicated by the SRMflags
2241 */
2242 if (listcount (lsp_list) > 0)
2243 {
paul1eb8ef22005-04-07 07:30:20 +00002244 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
Josh Bailey3f045a02012-03-24 08:35:20 -07002245 {
2246 int diff = time (NULL) - circuit->lsp_queue_last_cleared;
2247 if (circuit->lsp_queue == NULL ||
2248 diff < MIN_LSP_TRANS_INTERVAL)
2249 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002250 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
Josh Bailey3f045a02012-03-24 08:35:20 -07002251 {
2252 if (circuit->upadjcount[lsp->level - 1] &&
2253 ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2254 {
2255 /* Add the lsp only if it is not already in lsp
2256 * queue */
2257 if (! listnode_lookup (circuit->lsp_queue, lsp))
2258 {
2259 listnode_add (circuit->lsp_queue, lsp);
2260 thread_add_event (master, send_lsp, circuit, 0);
2261 }
2262 }
2263 }
2264 }
2265 list_delete_all_node (lsp_list);
2266 }
2267 }
jardineb5d44e2003-12-23 08:09:43 +00002268 }
jardineb5d44e2003-12-23 08:09:43 +00002269
2270 list_delete (lsp_list);
2271
2272 return ISIS_OK;
2273}
2274
jardineb5d44e2003-12-23 08:09:43 +00002275void
Josh Bailey3f045a02012-03-24 08:35:20 -07002276lsp_purge_pseudo (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002277{
2278 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002279 u_int16_t seq_num;
2280 u_int8_t lsp_bits;
hassof390d2c2004-09-10 20:48:21 +00002281
jardineb5d44e2003-12-23 08:09:43 +00002282 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
Josh Bailey3f045a02012-03-24 08:35:20 -07002283 if (!lsp)
2284 return;
hassof390d2c2004-09-10 20:48:21 +00002285
Josh Bailey3f045a02012-03-24 08:35:20 -07002286 /* store old values */
2287 seq_num = lsp->lsp_header->seq_num;
2288 lsp_bits = lsp->lsp_header->lsp_bits;
2289
2290 /* reset stream */
2291 lsp_clear_data (lsp);
2292 stream_reset (lsp->pdu);
2293
2294 /* update header */
2295 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2296 memcpy (lsp->lsp_header->lsp_id, id, ISIS_SYS_ID_LEN + 2);
2297 lsp->lsp_header->checksum = 0;
2298 lsp->lsp_header->seq_num = seq_num;
2299 lsp->lsp_header->rem_lifetime = 0;
2300 lsp->lsp_header->lsp_bits = lsp_bits;
2301 lsp->level = level;
2302 lsp->age_out = lsp->area->max_lsp_lifetime[level-1];
2303 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2304
2305 /*
2306 * Add and update the authentication info if its present
2307 */
2308 lsp_auth_add (lsp);
2309 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2310 lsp_auth_update (lsp);
2311 fletcher_checksum(STREAM_DATA (lsp->pdu) + 12,
2312 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2313
2314 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002315
jardineb5d44e2003-12-23 08:09:43 +00002316 return;
2317}
2318
2319/*
2320 * Purge own LSP that is received and we don't have.
2321 * -> Do as in 7.3.16.4
2322 */
2323void
hassof390d2c2004-09-10 20:48:21 +00002324lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2325 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002326{
2327 struct isis_lsp *lsp;
2328
2329 /*
2330 * We need to create the LSP to be purged
2331 */
hassoaac372f2005-09-01 17:52:33 +00002332 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
Josh Bailey3f045a02012-03-24 08:35:20 -07002333 lsp->area = area;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002334 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ?
2335 IS_LEVEL_1 : IS_LEVEL_2;
Josh Bailey3f045a02012-03-24 08:35:20 -07002336 /* FIXME: Should be minimal mtu? */
2337 lsp->pdu = stream_new (1500);
hassof390d2c2004-09-10 20:48:21 +00002338 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
Josh Bailey3f045a02012-03-24 08:35:20 -07002339 fill_fixed_hdr (lsp->isis_header, (lsp->level == IS_LEVEL_1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002340 : L2_LINK_STATE);
2341 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2342 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002343 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
Josh Bailey3f045a02012-03-24 08:35:20 -07002344 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002345
jardineb5d44e2003-12-23 08:09:43 +00002346 /*
jardineb5d44e2003-12-23 08:09:43 +00002347 * Set the remaining lifetime to 0
2348 */
2349 lsp->lsp_header->rem_lifetime = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -07002350
2351 /*
2352 * Add and update the authentication info if its present
2353 */
2354 lsp_auth_add (lsp);
2355 lsp_auth_update (lsp);
2356
2357 /*
2358 * Update the PDU length to header plus any authentication TLV.
2359 */
2360 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
2361
jardineb5d44e2003-12-23 08:09:43 +00002362 /*
2363 * Put the lsp into LSPdb
2364 */
hassof390d2c2004-09-10 20:48:21 +00002365 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002366
2367 /*
2368 * Send in to whole area
2369 */
Josh Bailey3f045a02012-03-24 08:35:20 -07002370 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002371
jardineb5d44e2003-12-23 08:09:43 +00002372 return;
2373}
2374
Josh Bailey3f045a02012-03-24 08:35:20 -07002375void lsp_set_all_srmflags (struct isis_lsp *lsp)
2376{
2377 struct listnode *node;
2378 struct isis_circuit *circuit;
2379
2380 assert (lsp);
2381
2382 ISIS_FLAGS_CLEAR_ALL(lsp->SRMflags);
2383
2384 if (lsp->area)
2385 {
2386 struct list *circuit_list = lsp->area->circuit_list;
2387 for (ALL_LIST_ELEMENTS_RO (circuit_list, node, circuit))
2388 {
2389 ISIS_SET_FLAG(lsp->SRMflags, circuit);
2390 }
2391 }
2392}
2393
jardineb5d44e2003-12-23 08:09:43 +00002394#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002395static int
jardineb5d44e2003-12-23 08:09:43 +00002396top_lsp_refresh (struct thread *thread)
2397{
hassof390d2c2004-09-10 20:48:21 +00002398 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002399 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002400
2401 lsp = THREAD_ARG (thread);
2402 assert (lsp);
2403
2404 lsp->t_lsp_top_ref = NULL;
2405
hassof1082d12005-09-19 04:23:34 +00002406 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002407
Josh Bailey3f045a02012-03-24 08:35:20 -07002408 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002409 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2410 {
hasso529d65b2004-12-24 00:14:50 +00002411 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2412 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002413 }
hassod3d74742005-09-28 18:30:51 +00002414 /* Refresh dynamic hostname in the cache. */
2415 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2416 IS_LEVEL_1);
2417
David Lampartera47c5832012-06-21 09:55:38 +02002418 lsp->lsp_header->lsp_bits = lsp_bits_generate (lsp->level,
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -07002419 lsp->area->overload_bit);
Josh Bailey3f045a02012-03-24 08:35:20 -07002420 rem_lifetime = lsp_rem_lifetime (lsp->area, IS_LEVEL_1);
2421 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
jardineb5d44e2003-12-23 08:09:43 +00002422
Josh Bailey3f045a02012-03-24 08:35:20 -07002423 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof390d2c2004-09-10 20:48:21 +00002424 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002425 lsp->area->lsp_refresh[0]);
jardineb5d44e2003-12-23 08:09:43 +00002426
2427 return ISIS_OK;
2428}
2429
2430void
2431generate_topology_lsps (struct isis_area *area)
2432{
2433 struct listnode *node;
2434 int i, max = 0;
2435 struct arc *arc;
2436 u_char lspid[ISIS_SYS_ID_LEN + 2];
2437 struct isis_lsp *lsp;
Josh Bailey3f045a02012-03-24 08:35:20 -07002438 u_int16_t rem_lifetime, refresh_time;
jardineb5d44e2003-12-23 08:09:43 +00002439
2440 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002441 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
Josh Bailey3f045a02012-03-24 08:35:20 -07002442 {
2443 if (arc->from_node > max)
2444 max = arc->from_node;
2445 if (arc->to_node > max)
2446 max = arc->to_node;
2447 }
jardineb5d44e2003-12-23 08:09:43 +00002448
hassof390d2c2004-09-10 20:48:21 +00002449 for (i = 1; i < (max + 1); i++)
2450 {
2451 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2452 LSP_PSEUDO_ID (lspid) = 0x00;
2453 LSP_FRAGMENT (lspid) = 0x00;
2454 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2455 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002456
Josh Bailey3f045a02012-03-24 08:35:20 -07002457 rem_lifetime = lsp_rem_lifetime (area, IS_LEVEL_1);
2458 lsp = lsp_new (lspid, rem_lifetime, 1, IS_LEVEL_1 | area->overload_bit,
2459 0, 1);
hassof1082d12005-09-19 04:23:34 +00002460 if (!lsp)
2461 return;
hassof1082d12005-09-19 04:23:34 +00002462 lsp->area = area;
Josh Bailey3f045a02012-03-24 08:35:20 -07002463 lsp->from_topology = 1;
jardineb5d44e2003-12-23 08:09:43 +00002464
hassof1082d12005-09-19 04:23:34 +00002465 /* Creating LSP data based on topology info. */
2466 build_topology_lsp_data (lsp, area, i);
2467 /* Checksum is also calculated here. */
2468 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002469 /* Take care of inserting dynamic hostname into cache. */
2470 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002471
Josh Bailey3f045a02012-03-24 08:35:20 -07002472 refresh_time = lsp_refresh_time (lsp, rem_lifetime);
hassof1082d12005-09-19 04:23:34 +00002473 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
Josh Bailey3f045a02012-03-24 08:35:20 -07002474 refresh_time);
2475 lsp_set_all_srmflags (lsp);
hassof390d2c2004-09-10 20:48:21 +00002476 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002477 }
jardineb5d44e2003-12-23 08:09:43 +00002478}
2479
2480void
2481remove_topology_lsps (struct isis_area *area)
2482{
2483 struct isis_lsp *lsp;
2484 dnode_t *dnode, *dnode_next;
2485
2486 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002487 while (dnode != NULL)
2488 {
2489 dnode_next = dict_next (area->lspdb[0], dnode);
2490 lsp = dnode_get (dnode);
2491 if (lsp->from_topology)
2492 {
2493 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2494 lsp_destroy (lsp);
2495 dict_delete (area->lspdb[0], dnode);
2496 }
2497 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002498 }
jardineb5d44e2003-12-23 08:09:43 +00002499}
2500
2501void
hassof390d2c2004-09-10 20:48:21 +00002502build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002503 int lsp_top_num)
2504{
hasso3fdb2dd2005-09-28 18:45:54 +00002505 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002506 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002507 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002508 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002509 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002510 struct tlvs tlv_data;
2511 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002512
hassof1082d12005-09-19 04:23:34 +00002513 /* Add area addresses. FIXME: Is it needed at all? */
2514 if (lsp->tlv_data.area_addrs == NULL)
2515 lsp->tlv_data.area_addrs = list_new ();
2516 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002517
hassof1082d12005-09-19 04:23:34 +00002518 if (lsp->tlv_data.nlpids == NULL)
2519 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2520 lsp->tlv_data.nlpids->count = 1;
2521 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002522
hassof1082d12005-09-19 04:23:34 +00002523 if (area->dynhostname)
2524 {
2525 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2526 sizeof (struct hostname));
2527 memset (buff, 0x00, 200);
2528 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2529 "feedme", lsp_top_num);
2530 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2531 lsp->tlv_data.hostname->namelen = strlen (buff);
2532 }
2533
2534 if (lsp->tlv_data.nlpids)
2535 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2536 if (lsp->tlv_data.hostname)
2537 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2538 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2539 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2540
2541 memset (&tlv_data, 0, sizeof (struct tlvs));
2542 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002543 {
2544 tlv_data.is_neighs = list_new ();
2545 tlv_data.is_neighs->del = free_tlv;
2546 }
hassof1082d12005-09-19 04:23:34 +00002547
2548 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002549 if (lsp_top_num == 1)
2550 {
hasso3fdb2dd2005-09-28 18:45:54 +00002551 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002552
hassof390d2c2004-09-10 20:48:21 +00002553 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002554 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002555 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2556 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002557 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2558 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2559 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002560 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002561 }
hassof390d2c2004-09-10 20:48:21 +00002562
hassof1082d12005-09-19 04:23:34 +00002563 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002564 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002565 {
hassof1082d12005-09-19 04:23:34 +00002566 int to_lsp = 0;
2567
2568 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2569 continue;
2570
2571 if (lsp_top_num == arc->from_node)
2572 to_lsp = arc->to_node;
2573 else
2574 to_lsp = arc->from_node;
2575
hasso9551eea2005-09-28 18:26:25 +00002576 if (area->oldmetric)
2577 {
2578 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002579
hasso9551eea2005-09-28 18:26:25 +00002580 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2581 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2582 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2583 is_neigh->metrics.metric_default = arc->distance;
2584 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2585 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2586 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2587 listnode_add (tlv_data.is_neighs, is_neigh);
2588 }
2589
2590 if (area->newmetric)
2591 {
hasso9551eea2005-09-28 18:26:25 +00002592 if (tlv_data.te_is_neighs == NULL)
2593 {
2594 tlv_data.te_is_neighs = list_new ();
2595 tlv_data.te_is_neighs->del = free_tlv;
2596 }
2597 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2598 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2599 ISIS_SYS_ID_LEN);
2600 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2601 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
Josh Bailey3f045a02012-03-24 08:35:20 -07002602 SET_TE_METRIC(te_is_neigh, arc->distance);
hasso9551eea2005-09-28 18:26:25 +00002603 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2604 }
hassof390d2c2004-09-10 20:48:21 +00002605 }
hassof1082d12005-09-19 04:23:34 +00002606
2607 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2608 {
2609 if (lsp->tlv_data.is_neighs == NULL)
2610 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002611 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002612 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2613 tlv_add_is_neighs);
2614 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2615 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2616 lsp0, area, IS_LEVEL_1);
2617 }
2618
hasso9551eea2005-09-28 18:26:25 +00002619 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2620 {
2621 if (lsp->tlv_data.te_is_neighs == NULL)
2622 lsp->tlv_data.te_is_neighs = list_new ();
2623 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2624 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2625 tlv_add_te_is_neighs);
2626 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2627 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2628 lsp0, area, IS_LEVEL_1);
2629 }
2630
hassof1082d12005-09-19 04:23:34 +00002631 free_tlvs (&tlv_data);
2632 return;
jardineb5d44e2003-12-23 08:09:43 +00002633}
2634#endif /* TOPOLOGY_GENERATE */