blob: fd40bb37277c00931e779e3a718f4523359bfa10 [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"
jardineb5d44e2003-12-23 08:09:43 +000037
38#include "isisd/dict.h"
39#include "isisd/isis_constants.h"
40#include "isisd/isis_common.h"
41#include "isisd/isis_circuit.h"
42#include "isisd/isisd.h"
43#include "isisd/isis_tlv.h"
44#include "isisd/isis_lsp.h"
45#include "isisd/isis_pdu.h"
46#include "isisd/isis_dynhn.h"
47#include "isisd/isis_misc.h"
48#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000049#include "isisd/isis_csm.h"
50#include "isisd/isis_adjacency.h"
51#include "isisd/isis_spf.h"
52
53#ifdef TOPOLOGY_GENERATE
54#include "spgrid.h"
55#endif
56
hassof390d2c2004-09-10 20:48:21 +000057#define LSP_MEMORY_PREASSIGN
jardineb5d44e2003-12-23 08:09:43 +000058
59extern struct isis *isis;
60extern struct thread_master *master;
hasso18a6dce2004-10-03 18:18:34 +000061extern struct in_addr router_id_zebra;
jardineb5d44e2003-12-23 08:09:43 +000062
hasso73d1aea2004-09-24 10:45:28 +000063/* staticly assigned vars for printing purposes */
64char lsp_bits_string[200]; /* FIXME: enough ? */
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 {
hasso529d65b2004-12-24 00:14:50 +000093 zlog_debug ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn)),
94 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
112 if (lsp->own_lsp)
113 {
114 if (lsp->tlv_data.nlpids)
115 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
116 if (lsp->tlv_data.hostname)
117 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
118 }
jardineb5d44e2003-12-23 08:09:43 +0000119 if (lsp->tlv_data.is_neighs)
120 list_delete (lsp->tlv_data.is_neighs);
hassoaa4376e2005-09-26 17:39:48 +0000121 if (lsp->tlv_data.te_is_neighs)
122 list_delete (lsp->tlv_data.te_is_neighs);
jardineb5d44e2003-12-23 08:09:43 +0000123 if (lsp->tlv_data.area_addrs)
124 list_delete (lsp->tlv_data.area_addrs);
125 if (lsp->tlv_data.es_neighs)
126 list_delete (lsp->tlv_data.es_neighs);
127 if (lsp->tlv_data.ipv4_addrs)
128 list_delete (lsp->tlv_data.ipv4_addrs);
129 if (lsp->tlv_data.ipv4_int_reachs)
130 list_delete (lsp->tlv_data.ipv4_int_reachs);
131 if (lsp->tlv_data.ipv4_ext_reachs)
132 list_delete (lsp->tlv_data.ipv4_ext_reachs);
hassoaa4376e2005-09-26 17:39:48 +0000133 if (lsp->tlv_data.te_ipv4_reachs)
134 list_delete (lsp->tlv_data.te_ipv4_reachs);
jardineb5d44e2003-12-23 08:09:43 +0000135#ifdef HAVE_IPV6
136 if (lsp->tlv_data.ipv6_addrs)
137 list_delete (lsp->tlv_data.ipv6_addrs);
138 if (lsp->tlv_data.ipv6_reachs)
139 list_delete (lsp->tlv_data.ipv6_reachs);
140#endif /* HAVE_IPV6 */
141
142 memset (&lsp->tlv_data, 0, sizeof (struct tlvs));
143
144 return;
145}
146
hasso92365882005-01-18 13:53:33 +0000147static void
jardineb5d44e2003-12-23 08:09:43 +0000148lsp_destroy (struct isis_lsp *lsp)
149{
150 if (!lsp)
151 return;
hassof390d2c2004-09-10 20:48:21 +0000152
jardineb5d44e2003-12-23 08:09:43 +0000153 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000154
155 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
156 {
jardineb5d44e2003-12-23 08:09:43 +0000157 list_delete (lsp->lspu.frags);
hassof390d2c2004-09-10 20:48:21 +0000158 }
159
jardineb5d44e2003-12-23 08:09:43 +0000160 if (lsp->pdu)
161 stream_free (lsp->pdu);
162 XFREE (MTYPE_ISIS_LSP, lsp);
163}
164
hassof390d2c2004-09-10 20:48:21 +0000165void
166lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000167{
168 dnode_t *dnode, *next;
169 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000170
jardineb5d44e2003-12-23 08:09:43 +0000171 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000172 while (dnode)
173 {
174 next = dict_next (lspdb, dnode);
175 lsp = dnode_get (dnode);
176 lsp_destroy (lsp);
177 dict_delete_free (lspdb, dnode);
178 dnode = next;
179 }
180
jardineb5d44e2003-12-23 08:09:43 +0000181 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000182
jardineb5d44e2003-12-23 08:09:43 +0000183 return;
184}
185
186/*
187 * Remove all the frags belonging to the given lsp
188 */
hasso92365882005-01-18 13:53:33 +0000189static void
hassof390d2c2004-09-10 20:48:21 +0000190lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000191{
192 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000193 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000194 struct isis_lsp *lsp;
195
paul1eb8ef22005-04-07 07:30:20 +0000196 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000197 {
hassof390d2c2004-09-10 20:48:21 +0000198 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
199 lsp_destroy (lsp);
200 dnode_destroy (dict_delete (lspdb, dnode));
201 }
202
jardineb5d44e2003-12-23 08:09:43 +0000203 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000204
jardineb5d44e2003-12-23 08:09:43 +0000205 return;
206}
207
208void
hassof390d2c2004-09-10 20:48:21 +0000209lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000210{
211 dnode_t *node;
212 struct isis_lsp *lsp;
213
214 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000215 if (node)
216 {
217 node = dict_delete (lspdb, node);
218 lsp = dnode_get (node);
219 /*
220 * If this is a zero lsp, remove all the frags now
221 */
222 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
223 {
224 if (lsp->lspu.frags)
225 lsp_remove_frags (lsp->lspu.frags, lspdb);
226 }
227 else
228 {
229 /*
230 * else just remove this frag, from the zero lsps' frag list
231 */
232 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
233 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
234 }
235 lsp_destroy (lsp);
236 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000237 }
jardineb5d44e2003-12-23 08:09:43 +0000238}
239
240/*
241 * Compares a LSP to given values
242 * Params are given in net order
243 */
hassof390d2c2004-09-10 20:48:21 +0000244int
245lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000246 u_int16_t checksum, u_int16_t rem_lifetime)
247{
hassof390d2c2004-09-10 20:48:21 +0000248 /* no point in double ntohl on seqnum */
249 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000250 lsp->lsp_header->checksum == checksum &&
251 /*comparing with 0, no need to do ntohl */
252 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000253 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
254 {
255 if (isis->debugs & DEBUG_SNP_PACKETS)
256 {
hasso529d65b2004-12-24 00:14:50 +0000257 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
258 " lifetime %us",
259 areatag,
260 rawlspid_print (lsp->lsp_header->lsp_id),
261 ntohl (lsp->lsp_header->seq_num),
262 ntohs (lsp->lsp_header->checksum),
263 ntohs (lsp->lsp_header->rem_lifetime));
264 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
265 " cksum 0x%04x, lifetime %us",
266 areatag,
267 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000268 }
269 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000270 }
jardineb5d44e2003-12-23 08:09:43 +0000271
hassof390d2c2004-09-10 20:48:21 +0000272 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
273 {
274 if (isis->debugs & DEBUG_SNP_PACKETS)
275 {
hasso529d65b2004-12-24 00:14:50 +0000276 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
277 " lifetime %us",
278 areatag,
279 rawlspid_print (lsp->lsp_header->lsp_id),
280 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
281 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
282 "cksum 0x%04x, lifetime %us",
283 areatag,
284 ntohl (lsp->lsp_header->seq_num),
285 ntohs (lsp->lsp_header->checksum),
286 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000287 }
288 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000289 }
hassof390d2c2004-09-10 20:48:21 +0000290 if (isis->debugs & DEBUG_SNP_PACKETS)
291 {
hasso529d65b2004-12-24 00:14:50 +0000292 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000293 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
294 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
295 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000296 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
297 " cksum 0x%04x, lifetime %us", areatag,
298 ntohl (lsp->lsp_header->seq_num),
299 ntohs (lsp->lsp_header->checksum),
300 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000301 }
jardineb5d44e2003-12-23 08:09:43 +0000302
303 return LSP_OLDER;
304}
305
hassof390d2c2004-09-10 20:48:21 +0000306void
jardineb5d44e2003-12-23 08:09:43 +0000307lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
308{
309 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000310
jardineb5d44e2003-12-23 08:09:43 +0000311 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
312 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
313 else
hassof390d2c2004-09-10 20:48:21 +0000314 newseq = seq_num++;
315
jardineb5d44e2003-12-23 08:09:43 +0000316 lsp->lsp_header->seq_num = htonl (newseq);
Jingjing Duan6a270cd2008-08-13 19:09:10 +0100317 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +0000318 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +0000319
320 return;
321}
322
323/*
324 * Genetates checksum for LSP and its frags
325 */
hasso92365882005-01-18 13:53:33 +0000326static void
jardineb5d44e2003-12-23 08:09:43 +0000327lsp_seqnum_update (struct isis_lsp *lsp0)
328{
329 struct isis_lsp *lsp;
hasso3fdb2dd2005-09-28 18:45:54 +0000330 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000331
jardineb5d44e2003-12-23 08:09:43 +0000332 lsp_inc_seqnum (lsp0, 0);
333
334 if (!lsp0->lspu.frags)
335 return;
336
hasso3fdb2dd2005-09-28 18:45:54 +0000337 for (ALL_LIST_ELEMENTS_RO (lsp0->lspu.frags, node, lsp))
paul1eb8ef22005-04-07 07:30:20 +0000338 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000339
jardineb5d44e2003-12-23 08:09:43 +0000340 return;
341}
342
hassof390d2c2004-09-10 20:48:21 +0000343int
jardineb5d44e2003-12-23 08:09:43 +0000344isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
hassof390d2c2004-09-10 20:48:21 +0000345 int pdulen, struct isis_passwd *passwd)
jardineb5d44e2003-12-23 08:09:43 +0000346{
347 uint32_t expected = 0, found;
348 struct tlvs tlvs;
349 int retval = 0;
350
351 expected |= TLVFLAG_AUTH_INFO;
352 retval = parse_tlvs (area->area_tag, stream->data +
hassof390d2c2004-09-10 20:48:21 +0000353 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
354 pdulen - ISIS_FIXED_HDR_LEN
355 - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400356
jardineb5d44e2003-12-23 08:09:43 +0000357 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000358 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000359
Fritz Reichmanne6b03b72011-10-01 17:49:48 +0400360 switch (tlvs.auth_info.type)
361 {
362 case ISIS_PASSWD_TYPE_HMAC_MD5:
363 zlog_debug("Got LSP with ISIS_PASSWD_TYPE_HMAC_MD5");
364 break;
365 case ISIS_PASSWD_TYPE_CLEARTXT:
366 zlog_debug("Got LSP with ISIS_PASSWD_TYPE_CLEARTXT");
367 break;
368 default:
369 zlog_debug("Unknown authentication type in LSP");
370 break;
371 }
372
373 return 0;
374 /* return authentication_check (passwd, &tlvs.auth_info);*/
jardineb5d44e2003-12-23 08:09:43 +0000375}
376
hasso92365882005-01-18 13:53:33 +0000377static void
hassof390d2c2004-09-10 20:48:21 +0000378lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
379 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000380{
hassof390d2c2004-09-10 20:48:21 +0000381 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000382 int retval;
hassof390d2c2004-09-10 20:48:21 +0000383
jardineb5d44e2003-12-23 08:09:43 +0000384 /* copying only the relevant part of our stream */
paul15935e92005-05-03 09:27:23 +0000385 lsp->pdu = stream_dup (stream);
386
jardineb5d44e2003-12-23 08:09:43 +0000387 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000388 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
389 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
390 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000391 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000392 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000393 /*
394 * Get LSP data i.e. TLVs
395 */
396 expected |= TLVFLAG_AUTH_INFO;
397 expected |= TLVFLAG_AREA_ADDRS;
398 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000399 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000400 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
401 expected |= TLVFLAG_NLPID;
402 if (area->dynhostname)
403 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000404 if (area->newmetric)
405 {
406 expected |= TLVFLAG_TE_IS_NEIGHS;
407 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
408 expected |= TLVFLAG_TE_ROUTER_ID;
409 }
jardineb5d44e2003-12-23 08:09:43 +0000410 expected |= TLVFLAG_IPV4_ADDR;
411 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
412 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
413#ifdef HAVE_IPV6
414 expected |= TLVFLAG_IPV6_ADDR;
415 expected |= TLVFLAG_IPV6_REACHABILITY;
416#endif /* HAVE_IPV6 */
417
418 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000419 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
420 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
421 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000422
hassof390d2c2004-09-10 20:48:21 +0000423 if (found & TLVFLAG_DYN_HOSTNAME)
424 {
425 if (area->dynhostname)
426 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
427 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
428 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
429 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
430 }
jardineb5d44e2003-12-23 08:09:43 +0000431
432}
433
434void
435lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassoa96d8d12005-09-16 14:44:23 +0000436 struct stream *stream, struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000437{
hasso4eda93a2005-09-18 17:51:02 +0000438 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000439
440 /* Remove old LSP from LSP database. */
hasso4eda93a2005-09-18 17:51:02 +0000441 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
442 if (dnode)
443 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000444
hassof390d2c2004-09-10 20:48:21 +0000445 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000446 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
447 lsp_clear_data (lsp);
448
449 /* rebuild the lsp data */
450 lsp_update_data (lsp, stream, area);
451
hassof390d2c2004-09-10 20:48:21 +0000452 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000453 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassoa96d8d12005-09-16 14:44:23 +0000454
hasso4eda93a2005-09-18 17:51:02 +0000455 if (dnode)
456 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000457}
458
jardineb5d44e2003-12-23 08:09:43 +0000459/* creation of LSP directly from what we received */
460struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000461lsp_new_from_stream_ptr (struct stream *stream,
462 u_int16_t pdu_len, struct isis_lsp *lsp0,
463 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000464{
465 struct isis_lsp *lsp;
466
hassoaac372f2005-09-01 17:52:33 +0000467 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
jardineb5d44e2003-12-23 08:09:43 +0000468 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000469
470 if (lsp0 == NULL)
471 {
472 /*
473 * zero lsp -> create the list for fragments
474 */
475 lsp->lspu.frags = list_new ();
476 }
477 else
478 {
479 /*
480 * a fragment -> set the backpointer and add this to zero lsps frag list
481 */
482 lsp->lspu.zero_lsp = lsp0;
483 listnode_add (lsp0->lspu.frags, lsp);
484 }
485
jardineb5d44e2003-12-23 08:09:43 +0000486 return lsp;
487}
488
489struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000490lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
491 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000492{
493 struct isis_lsp *lsp;
494
hassoaac372f2005-09-01 17:52:33 +0000495 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000496 if (!lsp)
497 {
498 /* FIXME: set lspdbol bit */
499 zlog_warn ("lsp_new(): out of memory");
500 return NULL;
501 }
jardineb5d44e2003-12-23 08:09:43 +0000502#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000503 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000504#else
hassof390d2c2004-09-10 20:48:21 +0000505 /* We need to do realloc on TLVs additions */
506 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000507#endif /* LSP_MEMORY_PREASSIGN */
508 if (LSP_FRAGMENT (lsp_id) == 0)
509 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000510 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
511 lsp->lsp_header = (struct isis_link_state_hdr *)
512 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
513
jardineb5d44e2003-12-23 08:09:43 +0000514 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000515 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
516 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
517
jardineb5d44e2003-12-23 08:09:43 +0000518 /* now for the LSP HEADER */
519 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000520 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000521 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000522 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000523 lsp->lsp_header->seq_num = htonl (seq_num);
524 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
525 lsp->lsp_header->lsp_bits = lsp_bits;
526 lsp->level = level;
527 lsp->age_out = ZERO_AGE_LIFETIME;
528
paul9985f832005-02-09 15:51:56 +0000529 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000530
hassoc89c05d2005-09-04 21:36:36 +0000531 if (isis->debugs & DEBUG_EVENTS)
532 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x",
533 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
534 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
535 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000536
537 return lsp;
538}
539
540void
hassof390d2c2004-09-10 20:48:21 +0000541lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000542{
543 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
544}
545
546/*
547 * Build a list of LSPs with non-zero ht bounded by start and stop ids
548 */
hassof390d2c2004-09-10 20:48:21 +0000549void
550lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
551 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000552{
553 dnode_t *first, *last, *curr;
554
555 first = dict_lower_bound (lspdb, start_id);
556 if (!first)
557 return;
hassof390d2c2004-09-10 20:48:21 +0000558
jardineb5d44e2003-12-23 08:09:43 +0000559 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000560
jardineb5d44e2003-12-23 08:09:43 +0000561 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000562
563 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000564 listnode_add (list, first->dict_data);
565
hassof390d2c2004-09-10 20:48:21 +0000566 while (curr)
567 {
568 curr = dict_next (lspdb, curr);
569 if (curr &&
570 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
571 listnode_add (list, curr->dict_data);
572 if (curr == last)
573 break;
574 }
575
jardineb5d44e2003-12-23 08:09:43 +0000576 return;
577}
578
579/*
580 * Build a list of all LSPs bounded by start and stop ids
581 */
hassof390d2c2004-09-10 20:48:21 +0000582void
583lsp_build_list (u_char * start_id, u_char * stop_id,
584 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000585{
586 dnode_t *first, *last, *curr;
587
588 first = dict_lower_bound (lspdb, start_id);
589 if (!first)
590 return;
hassof390d2c2004-09-10 20:48:21 +0000591
jardineb5d44e2003-12-23 08:09:43 +0000592 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000593
jardineb5d44e2003-12-23 08:09:43 +0000594 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000595
jardineb5d44e2003-12-23 08:09:43 +0000596 listnode_add (list, first->dict_data);
597
hassof390d2c2004-09-10 20:48:21 +0000598 while (curr)
599 {
600 curr = dict_next (lspdb, curr);
601 if (curr)
602 listnode_add (list, curr->dict_data);
603 if (curr == last)
604 break;
605 }
606
jardineb5d44e2003-12-23 08:09:43 +0000607 return;
608}
609
610/*
611 * Build a list of LSPs with SSN flag set for the given circuit
612 */
613void
hassof390d2c2004-09-10 20:48:21 +0000614lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
615 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000616{
617 dnode_t *dnode, *next;
618 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000619
jardineb5d44e2003-12-23 08:09:43 +0000620 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000621 while (dnode != NULL)
622 {
623 next = dict_next (lspdb, dnode);
624 lsp = dnode_get (dnode);
625 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
626 listnode_add (list, lsp);
627 dnode = next;
628 }
629
jardineb5d44e2003-12-23 08:09:43 +0000630 return;
631}
632
hasso92365882005-01-18 13:53:33 +0000633static void
jardineb5d44e2003-12-23 08:09:43 +0000634lsp_set_time (struct isis_lsp *lsp)
635{
636 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000637
638 if (lsp->lsp_header->rem_lifetime == 0)
639 {
640 if (lsp->age_out != 0)
641 lsp->age_out--;
642 return;
643 }
jardineb5d44e2003-12-23 08:09:43 +0000644
645 /* If we are turning 0 */
646 /* ISO 10589 - 7.3.16.4 first paragraph */
647
hassof390d2c2004-09-10 20:48:21 +0000648 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
649 {
650 /* 7.3.16.4 a) set SRM flags on all */
651 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
652 /* 7.3.16.4 b) retain only the header FIXME */
653 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
654 }
jardineb5d44e2003-12-23 08:09:43 +0000655
hassof390d2c2004-09-10 20:48:21 +0000656 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000657 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
658}
659
hasso92365882005-01-18 13:53:33 +0000660static void
hassof390d2c2004-09-10 20:48:21 +0000661lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000662{
663 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000664 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000665
666 if (dynhost)
667 dyn = dynhn_find_by_id (lsp_id);
668 else
669 dyn = NULL;
670
671 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000672 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000673 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000674 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000675 else
hassof390d2c2004-09-10 20:48:21 +0000676 {
677 memcpy (id, sysid_print (lsp_id), 15);
678 }
679 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000680 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000681 LSP_FRAGMENT (lsp_id));
682 else
hassof7c43dc2004-09-26 16:24:14 +0000683 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000684}
685
hassof390d2c2004-09-10 20:48:21 +0000686/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000687const char *
hassof390d2c2004-09-10 20:48:21 +0000688lsp_bits2string (u_char * lsp_bits)
689{
690 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000691
hassof390d2c2004-09-10 20:48:21 +0000692 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000693 return " none";
694
695 /* we only focus on the default metric */
696 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000697 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000698
699 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000700 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000701
hassof390d2c2004-09-10 20:48:21 +0000702 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
703
jardineb5d44e2003-12-23 08:09:43 +0000704 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000705
hassof390d2c2004-09-10 20:48:21 +0000706 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000707}
708
709/* this function prints the lsp on show isis database */
hasso92365882005-01-18 13:53:33 +0000710static void
hassof390d2c2004-09-10 20:48:21 +0000711lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000712{
hassof390d2c2004-09-10 20:48:21 +0000713 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000714 u_char LSPid[255];
715
716 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000717 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
718 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
719 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000720
hassof390d2c2004-09-10 20:48:21 +0000721 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
722 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000723 else
hassof390d2c2004-09-10 20:48:21 +0000724 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000725
726 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000727 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000728}
729
hasso92365882005-01-18 13:53:33 +0000730static void
hassof390d2c2004-09-10 20:48:21 +0000731lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000732{
733 struct isis_lsp *lsp = dnode_get (node);
734 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000735 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000736 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000737 struct is_neigh *is_neigh;
738 struct te_is_neigh *te_is_neigh;
739 struct ipv4_reachability *ipv4_reach;
740 struct in_addr *ipv4_addr;
741 struct te_ipv4_reachability *te_ipv4_reach;
742#ifdef HAVE_IPV6
743 struct ipv6_reachability *ipv6_reach;
744 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000745 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000746#endif
747 u_char LSPid[255];
748 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000749 u_char ipv4_reach_prefix[20];
750 u_char ipv4_reach_mask[20];
751 u_char ipv4_address[20];
752
753 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000754 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000755
756 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000757 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000758 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000759 {
hasso1cd80842004-10-07 20:07:40 +0000760 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000761 isonet_print (area_addr->area_addr, area_addr->addr_len),
762 VTY_NEWLINE);
763 }
paul1eb8ef22005-04-07 07:30:20 +0000764
jardineb5d44e2003-12-23 08:09:43 +0000765 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000766 if (lsp->tlv_data.nlpids)
767 {
768 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
769 {
770 switch (lsp->tlv_data.nlpids->nlpids[i])
771 {
772 case NLPID_IP:
773 case NLPID_IPV6:
hasso1cd80842004-10-07 20:07:40 +0000774 vty_out (vty, " NLPID: 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000775 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
776 break;
777 default:
hasso1cd80842004-10-07 20:07:40 +0000778 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000779 break;
780 }
781 }
782 }
jardineb5d44e2003-12-23 08:09:43 +0000783
784 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000785 if (lsp->tlv_data.hostname)
786 {
Jeremy Jacksonec5e42b2009-01-21 20:51:57 -0500787 memset (hostname, 0, sizeof (hostname));
hassof390d2c2004-09-10 20:48:21 +0000788 memcpy (hostname, lsp->tlv_data.hostname->name,
789 lsp->tlv_data.hostname->namelen);
790 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000791 }
hassof390d2c2004-09-10 20:48:21 +0000792
793 if (lsp->tlv_data.ipv4_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000794 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000795 {
796 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
797 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
798 }
hassof390d2c2004-09-10 20:48:21 +0000799
hasso1cd80842004-10-07 20:07:40 +0000800 /* TE router id */
801 if (lsp->tlv_data.router_id)
802 {
803 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
804 sizeof (ipv4_address));
805 vty_out (vty, " Router ID: %s%s", ipv4_address, VTY_NEWLINE);
806 }
807
808 /* for the IS neighbor tlv */
809 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000810 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000811 {
812 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
hasso96e30382005-09-19 06:35:47 +0000813 vty_out (vty, " Metric: %-10d IS %s%s",
hasso1cd80842004-10-07 20:07:40 +0000814 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
815 }
hasso1cd80842004-10-07 20:07:40 +0000816
jardineb5d44e2003-12-23 08:09:43 +0000817 /* for the internal reachable tlv */
818 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000819 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
820 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000821 {
822 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
823 sizeof (ipv4_reach_prefix));
824 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
825 sizeof (ipv4_reach_mask));
hasso96e30382005-09-19 06:35:47 +0000826 vty_out (vty, " Metric: %-10d IP-Internal %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000827 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
828 ipv4_reach_mask, VTY_NEWLINE);
829 }
hasso2097cd82003-12-23 11:51:08 +0000830
831 /* for the external reachable tlv */
832 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000833 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
834 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000835 {
836 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
837 sizeof (ipv4_reach_prefix));
838 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
839 sizeof (ipv4_reach_mask));
hasso96e30382005-09-19 06:35:47 +0000840 vty_out (vty, " Metric: %-10d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000841 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
842 ipv4_reach_mask, VTY_NEWLINE);
843 }
paul1eb8ef22005-04-07 07:30:20 +0000844
hasso2097cd82003-12-23 11:51:08 +0000845 /* IPv6 tlv */
846#ifdef HAVE_IPV6
847 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000848 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000849 {
850 memset (&in6, 0, sizeof (in6));
851 memcpy (in6.s6_addr, ipv6_reach->prefix,
852 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000853 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000854 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000855 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
hasso96e30382005-09-19 06:35:47 +0000856 vty_out (vty, " Metric: %-10d IPv6-Internal %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000857 ntohl (ipv6_reach->metric),
858 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000859 else
hasso96e30382005-09-19 06:35:47 +0000860 vty_out (vty, " Metric: %-10d IPv6-External %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000861 ntohl (ipv6_reach->metric),
862 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000863 }
864#endif
paul1eb8ef22005-04-07 07:30:20 +0000865
hasso1cd80842004-10-07 20:07:40 +0000866 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000867 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000868 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000869 {
hasso96e30382005-09-19 06:35:47 +0000870 uint32_t metric;
871 memcpy (&metric, te_is_neigh->te_metric, 3);
hassof390d2c2004-09-10 20:48:21 +0000872 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
hasso96e30382005-09-19 06:35:47 +0000873 vty_out (vty, " Metric: %-10d IS-Extended %s%s",
874 ntohl (metric << 8), LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000875 }
jardineb5d44e2003-12-23 08:09:43 +0000876
hasso1cd80842004-10-07 20:07:40 +0000877 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000878 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000879 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
880 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000881 {
hasso1cd80842004-10-07 20:07:40 +0000882 /* FIXME: There should be better way to output this stuff. */
hasso96e30382005-09-19 06:35:47 +0000883 vty_out (vty, " Metric: %-10d IP-Extended %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000884 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000885 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
886 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000887 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000888 }
jardineb5d44e2003-12-23 08:09:43 +0000889
hassof390d2c2004-09-10 20:48:21 +0000890 return;
jardineb5d44e2003-12-23 08:09:43 +0000891}
892
893/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000894int
895lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000896{
897
hassof390d2c2004-09-10 20:48:21 +0000898 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000899 int lsp_count = 0;
900
901 /* print the title, for both modes */
902 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000903 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
904
905 if (detail == ISIS_UI_LEVEL_BRIEF)
906 {
907 while (node != NULL)
908 {
909 /* I think it is unnecessary, so I comment it out */
910 /* dict_contains (lspdb, node); */
911 next = dict_next (lspdb, node);
912 lsp_print (node, vty, dynhost);
913 node = next;
914 lsp_count++;
915 }
jardineb5d44e2003-12-23 08:09:43 +0000916 }
hassof390d2c2004-09-10 20:48:21 +0000917 else if (detail == ISIS_UI_LEVEL_DETAIL)
918 {
919 while (node != NULL)
920 {
921 next = dict_next (lspdb, node);
922 lsp_print_detail (node, vty, dynhost);
923 node = next;
924 lsp_count++;
925 }
jardineb5d44e2003-12-23 08:09:43 +0000926 }
jardineb5d44e2003-12-23 08:09:43 +0000927
928 return lsp_count;
929}
930
jardineb5d44e2003-12-23 08:09:43 +0000931#define FRAG_THOLD(S,T) \
932((STREAM_SIZE(S)*T)/100)
933
934/* stream*, area->lsp_frag_threshold, increment */
935#define FRAG_NEEDED(S,T,I) \
936 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
937
hassoaa4376e2005-09-26 17:39:48 +0000938/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
939 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +0000940static void
jardineb5d44e2003-12-23 08:09:43 +0000941lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +0000942 int tlvsize, int frag_thold,
943 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +0000944{
945 int count, i;
hassof390d2c2004-09-10 20:48:21 +0000946
jardineb5d44e2003-12-23 08:09:43 +0000947 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +0000948 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
949 {
950 tlv_build_func (*from, lsp->pdu);
951 *to = *from;
952 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +0000953 }
hassof390d2c2004-09-10 20:48:21 +0000954 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
955 {
956 /* fit all we can */
957 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
958 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
959 if (count)
960 count = count / tlvsize;
961 for (i = 0; i < count; i++)
962 {
paul1eb8ef22005-04-07 07:30:20 +0000963 listnode_add (*to, listgetdata (listhead (*from)));
964 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +0000965 }
966 tlv_build_func (*to, lsp->pdu);
967 }
paul9985f832005-02-09 15:51:56 +0000968 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +0000969 return;
970}
971
hasso92365882005-01-18 13:53:33 +0000972static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000973lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
974 int level)
jardineb5d44e2003-12-23 08:09:43 +0000975{
976 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000977 u_char frag_id[ISIS_SYS_ID_LEN + 2];
978
jardineb5d44e2003-12-23 08:09:43 +0000979 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
980 LSP_FRAGMENT (frag_id) = frag_num;
981 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000982 if (lsp)
983 {
984 /*
985 * Clear the TLVs, but inherit the authinfo
986 */
987 lsp_clear_data (lsp);
988 if (lsp0->tlv_data.auth_info.type)
989 {
990 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
991 sizeof (struct isis_passwd));
992 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
993 lsp->tlv_data.auth_info.len,
994 lsp->tlv_data.auth_info.passwd, lsp->pdu);
995 }
996 return lsp;
jardineb5d44e2003-12-23 08:09:43 +0000997 }
jardineb5d44e2003-12-23 08:09:43 +0000998 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +0000999 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001000 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001001 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001002 listnode_add (lsp0->lspu.frags, lsp);
1003 lsp->lspu.zero_lsp = lsp0;
1004 /*
1005 * Copy the authinfo from zero LSP
1006 */
hassof390d2c2004-09-10 20:48:21 +00001007 if (lsp0->tlv_data.auth_info.type)
1008 {
1009 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1010 sizeof (struct isis_passwd));
1011 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1012 lsp->tlv_data.auth_info.len,
1013 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1014 }
jardineb5d44e2003-12-23 08:09:43 +00001015 return lsp;
1016}
1017
1018/*
1019 * Builds the LSP data part. This func creates a new frag whenever
1020 * area->lsp_frag_threshold is exceeded.
1021 */
hasso92365882005-01-18 13:53:33 +00001022static void
jardineb5d44e2003-12-23 08:09:43 +00001023lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1024{
1025 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001026 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001027 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001028 int level = lsp->level;
1029 struct isis_circuit *circuit;
1030 struct prefix_ipv4 *ipv4;
1031 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001032 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001033 struct isis_adjacency *nei;
1034#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001035 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001036 struct ipv6_reachability *ip6reach;
1037#endif /* HAVE_IPV6 */
1038 struct tlvs tlv_data;
1039 struct isis_lsp *lsp0 = lsp;
1040 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001041 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001042
1043 /*
1044 * First add the tlvs related to area
1045 */
hassof390d2c2004-09-10 20:48:21 +00001046
jardineb5d44e2003-12-23 08:09:43 +00001047 /* Area addresses */
1048 if (lsp->tlv_data.area_addrs == NULL)
1049 lsp->tlv_data.area_addrs = list_new ();
1050 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1051 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001052 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001053#ifdef HAVE_IPV6
1054 || area->ipv6_circuits > 0
1055#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001056 )
jardineb5d44e2003-12-23 08:09:43 +00001057 {
hassoaac372f2005-09-01 17:52:33 +00001058 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001059 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001060 if (area->ip_circuits > 0)
1061 {
1062 lsp->tlv_data.nlpids->count++;
1063 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1064 }
jardineb5d44e2003-12-23 08:09:43 +00001065#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001066 if (area->ipv6_circuits > 0)
1067 {
1068 lsp->tlv_data.nlpids->count++;
1069 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1070 NLPID_IPV6;
1071 }
jardineb5d44e2003-12-23 08:09:43 +00001072#endif /* HAVE_IPV6 */
1073 }
1074 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001075 if (area->dynhostname)
1076 {
1077 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1078 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001079
hassof390d2c2004-09-10 20:48:21 +00001080 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1081 strlen (unix_hostname ()));
1082 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1083 }
jardineb5d44e2003-12-23 08:09:43 +00001084
1085 /*
1086 * Building the zero lsp
1087 */
hassoaac372f2005-09-01 17:52:33 +00001088
1089 /* Reset stream endp. Stream is always there and on every LSP refresh only
1090 * TLV part of it is overwritten. So we must seek past header we will not
1091 * touch. */
hassoc89c05d2005-09-04 21:36:36 +00001092 stream_reset (lsp->pdu);
hassoaac372f2005-09-01 17:52:33 +00001093 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1094
jardineb5d44e2003-12-23 08:09:43 +00001095 /*
1096 * Add the authentication info if its present
1097 */
hassof390d2c2004-09-10 20:48:21 +00001098 (level == 1) ? (passwd = &area->area_passwd) :
1099 (passwd = &area->domain_passwd);
1100 if (passwd->type)
1101 {
1102 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1103 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1104 }
jardineb5d44e2003-12-23 08:09:43 +00001105 if (lsp->tlv_data.nlpids)
1106 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1107 if (lsp->tlv_data.hostname)
1108 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001109 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001110 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001111
hasso81ad8f62005-09-26 17:58:24 +00001112 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1113 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1114 * LSP and this address is same as router id. */
hasso18a6dce2004-10-03 18:18:34 +00001115 if (router_id_zebra.s_addr != 0)
1116 {
hasso18a6dce2004-10-03 18:18:34 +00001117 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001118 {
1119 lsp->tlv_data.ipv4_addrs = list_new ();
1120 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1121 }
hasso18a6dce2004-10-03 18:18:34 +00001122
1123 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1124 routerid->s_addr = router_id_zebra.s_addr;
hasso18a6dce2004-10-03 18:18:34 +00001125 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001126 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001127
hasso81ad8f62005-09-26 17:58:24 +00001128 /* Exactly same data is put into TE router ID TLV, but only if new style
1129 * TLV's are in use. */
1130 if (area->newmetric)
1131 {
1132 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1133 sizeof (struct in_addr));
1134 lsp->tlv_data.router_id->id.s_addr = router_id_zebra.s_addr;
1135 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu, TE_ROUTER_ID);
1136 }
hasso18a6dce2004-10-03 18:18:34 +00001137 }
hassof1082d12005-09-19 04:23:34 +00001138
hasso81ad8f62005-09-26 17:58:24 +00001139 memset (&tlv_data, 0, sizeof (struct tlvs));
1140
hassof1082d12005-09-19 04:23:34 +00001141#ifdef TOPOLOGY_GENERATE
1142 /* If topology exists (and we create topology for level 1 only), create
1143 * (hardcoded) link to topology. */
1144 if (area->topology && level == 1)
1145 {
1146 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001147 {
1148 tlv_data.is_neighs = list_new ();
1149 tlv_data.is_neighs->del = free_tlv;
1150 }
hasso3fdb2dd2005-09-28 18:45:54 +00001151 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001152
1153 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1154 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1155 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1156 is_neigh->metrics.metric_default = 0x01;
1157 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1158 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1159 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1160 listnode_add (tlv_data.is_neighs, is_neigh);
1161 }
1162#endif /* TOPOLOGY_GENERATE */
1163
hasso18a6dce2004-10-03 18:18:34 +00001164 /*
jardineb5d44e2003-12-23 08:09:43 +00001165 * Then build lists of tlvs related to circuits
1166 */
hasso3fdb2dd2005-09-28 18:45:54 +00001167 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001168 {
hassof390d2c2004-09-10 20:48:21 +00001169 if (circuit->state != C_STATE_UP)
1170 continue;
jardineb5d44e2003-12-23 08:09:43 +00001171
hassof390d2c2004-09-10 20:48:21 +00001172 /*
1173 * Add IPv4 internal reachability of this circuit
1174 */
1175 if (circuit->ip_router && circuit->ip_addrs &&
1176 circuit->ip_addrs->count > 0)
1177 {
hassoaa4376e2005-09-26 17:39:48 +00001178 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001179 {
hassoaa4376e2005-09-26 17:39:48 +00001180 if (tlv_data.ipv4_int_reachs == NULL)
1181 {
1182 tlv_data.ipv4_int_reachs = list_new ();
1183 tlv_data.ipv4_int_reachs->del = free_tlv;
1184 }
hasso3fdb2dd2005-09-28 18:45:54 +00001185 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001186 {
1187 ipreach =
1188 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1189 ipreach->metrics = circuit->metrics[level - 1];
1190 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1191 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1192 (ipv4->prefix.s_addr));
1193 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1194 }
hassobe7d65d2005-09-02 01:38:16 +00001195 tlv_data.ipv4_int_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001196 }
hassoaa4376e2005-09-26 17:39:48 +00001197 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001198 {
hassoaa4376e2005-09-26 17:39:48 +00001199 if (tlv_data.te_ipv4_reachs == NULL)
1200 {
1201 tlv_data.te_ipv4_reachs = list_new ();
1202 tlv_data.te_ipv4_reachs->del = free_tlv;
1203 }
hasso3fdb2dd2005-09-28 18:45:54 +00001204 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001205 {
1206 /* FIXME All this assumes that we have no sub TLVs. */
1207 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1208 sizeof (struct te_ipv4_reachability) +
1209 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001210
1211 if (area->oldmetric)
1212 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1213 else
1214 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1215
hassoaa4376e2005-09-26 17:39:48 +00001216 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1217 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1218 (ipv4->prefixlen + 7)/8);
1219 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1220 }
hassof390d2c2004-09-10 20:48:21 +00001221 }
hassof390d2c2004-09-10 20:48:21 +00001222 }
jardineb5d44e2003-12-23 08:09:43 +00001223#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001224 /*
1225 * Add IPv6 reachability of this circuit
1226 */
1227 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1228 circuit->ipv6_non_link->count > 0)
1229 {
1230
1231 if (tlv_data.ipv6_reachs == NULL)
1232 {
1233 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001234 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001235 }
hasso3fdb2dd2005-09-28 18:45:54 +00001236 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001237 {
hassof390d2c2004-09-10 20:48:21 +00001238 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001239 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001240
1241 if (area->oldmetric)
1242 ip6reach->metric =
1243 htonl (circuit->metrics[level - 1].metric_default);
1244 else
1245 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1246
hassof390d2c2004-09-10 20:48:21 +00001247 ip6reach->control_info = 0;
1248 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001249 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1250 apply_mask_ipv6 (ip6prefix);
1251 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1252 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001253 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1254 }
1255 }
1256#endif /* HAVE_IPV6 */
1257
1258 switch (circuit->circ_type)
1259 {
1260 case CIRCUIT_T_BROADCAST:
1261 if (level & circuit->circuit_is_type)
1262 {
hassoaa4376e2005-09-26 17:39:48 +00001263 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001264 {
hassoaa4376e2005-09-26 17:39:48 +00001265 if (tlv_data.is_neighs == NULL)
1266 {
1267 tlv_data.is_neighs = list_new ();
1268 tlv_data.is_neighs->del = free_tlv;
1269 }
1270 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1271 if (level == 1)
1272 memcpy (is_neigh->neigh_id,
1273 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1274 else
1275 memcpy (is_neigh->neigh_id,
1276 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1277 is_neigh->metrics = circuit->metrics[level - 1];
1278 listnode_add (tlv_data.is_neighs, is_neigh);
hassobe7d65d2005-09-02 01:38:16 +00001279 tlv_data.is_neighs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001280 }
hassoaa4376e2005-09-26 17:39:48 +00001281 if (area->newmetric)
1282 {
1283 uint32_t metric;
1284
1285 if (tlv_data.te_is_neighs == NULL)
1286 {
1287 tlv_data.te_is_neighs = list_new ();
1288 tlv_data.te_is_neighs->del = free_tlv;
1289 }
1290 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1291 sizeof (struct te_is_neigh));
1292 if (level == 1)
1293 memcpy (te_is_neigh->neigh_id,
1294 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1295 else
1296 memcpy (te_is_neigh->neigh_id,
1297 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001298 if (area->oldmetric)
1299 metric =
1300 ((htonl(circuit->metrics[level - 1].metric_default) >> 8)
1301 & 0xffffff);
1302 else
1303 metric = ((htonl(*circuit->te_metric) >> 8) & 0xffffff);
1304
hassoaa4376e2005-09-26 17:39:48 +00001305 memcpy (te_is_neigh->te_metric, &metric, 3);
1306 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1307 }
hassof390d2c2004-09-10 20:48:21 +00001308 }
1309 break;
1310 case CIRCUIT_T_P2P:
1311 nei = circuit->u.p2p.neighbor;
1312 if (nei && (level & nei->circuit_t))
1313 {
hassoaa4376e2005-09-26 17:39:48 +00001314 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001315 {
hassoaa4376e2005-09-26 17:39:48 +00001316 if (tlv_data.is_neighs == NULL)
1317 {
1318 tlv_data.is_neighs = list_new ();
1319 tlv_data.is_neighs->del = free_tlv;
1320 }
1321 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1322 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1323 is_neigh->metrics = circuit->metrics[level - 1];
1324 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001325 }
hassoaa4376e2005-09-26 17:39:48 +00001326 if (area->newmetric)
1327 {
1328 uint32_t metric;
1329
1330 if (tlv_data.te_is_neighs == NULL)
1331 {
1332 tlv_data.te_is_neighs = list_new ();
1333 tlv_data.te_is_neighs->del = free_tlv;
1334 }
1335 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1336 sizeof (struct te_is_neigh));
1337 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1338 metric = ((htonl(*circuit->te_metric) >> 8) & 0xffffff);
1339 memcpy (te_is_neigh->te_metric, &metric, 3);
1340 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1341 }
hassof390d2c2004-09-10 20:48:21 +00001342 }
1343 break;
1344 case CIRCUIT_T_STATIC_IN:
1345 zlog_warn ("lsp_area_create: unsupported circuit type");
1346 break;
1347 case CIRCUIT_T_STATIC_OUT:
1348 zlog_warn ("lsp_area_create: unsupported circuit type");
1349 break;
1350 case CIRCUIT_T_DA:
1351 zlog_warn ("lsp_area_create: unsupported circuit type");
1352 break;
1353 default:
1354 zlog_warn ("lsp_area_create: unknown circuit type");
1355 }
1356 }
1357
1358 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1359 {
1360 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1361 lsp->tlv_data.ipv4_int_reachs = list_new ();
1362 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1363 &lsp->tlv_data.ipv4_int_reachs,
1364 IPV4_REACH_LEN, area->lsp_frag_threshold,
1365 tlv_add_ipv4_reachs);
1366 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1367 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1368 lsp0, area, level);
1369 }
hassoaa4376e2005-09-26 17:39:48 +00001370 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1371 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1372 * TLVs (sub TLVs!). */
1373 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1374 {
1375 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1376 lsp->tlv_data.te_ipv4_reachs = list_new ();
1377 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1378 &lsp->tlv_data.te_ipv4_reachs,
1379 9, area->lsp_frag_threshold, tlv_add_te_ipv4_reachs);
1380 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1381 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1382 lsp0, area, level);
1383 }
hassof390d2c2004-09-10 20:48:21 +00001384
1385#ifdef HAVE_IPV6
1386 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1387 {
1388 if (lsp->tlv_data.ipv6_reachs == NULL)
1389 lsp->tlv_data.ipv6_reachs = list_new ();
1390 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1391 &lsp->tlv_data.ipv6_reachs,
1392 IPV6_REACH_LEN, area->lsp_frag_threshold,
1393 tlv_add_ipv6_reachs);
1394 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1395 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1396 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001397 }
1398#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001399
1400 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1401 {
1402 if (lsp->tlv_data.is_neighs == NULL)
1403 lsp->tlv_data.is_neighs = list_new ();
1404 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1405 &lsp->tlv_data.is_neighs,
1406 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1407 tlv_add_is_neighs);
1408 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1409 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1410 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001411 }
jardineb5d44e2003-12-23 08:09:43 +00001412
hassoaa4376e2005-09-26 17:39:48 +00001413 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1414 {
1415 if (lsp->tlv_data.te_is_neighs == NULL)
1416 lsp->tlv_data.te_is_neighs = list_new ();
1417 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1418 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1419 tlv_add_te_is_neighs);
1420 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1421 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1422 lsp0, area, level);
1423 }
1424
1425 free_tlvs (&tlv_data);
jardineb5d44e2003-12-23 08:09:43 +00001426 return;
1427}
jardineb5d44e2003-12-23 08:09:43 +00001428
1429/*
1430 * 7.3.7 Generation on non-pseudonode LSPs
1431 */
hasso92365882005-01-18 13:53:33 +00001432static int
hassof390d2c2004-09-10 20:48:21 +00001433lsp_generate_non_pseudo (struct isis_area *area, int level)
1434{
jardineb5d44e2003-12-23 08:09:43 +00001435 struct isis_lsp *oldlsp, *newlsp;
1436 u_int32_t seq_num = 0;
1437 u_char lspid[ISIS_SYS_ID_LEN + 2];
1438
1439 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1440 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1441
1442 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001443 if ((area->is_type & level) == level)
1444 {
1445 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1446 if (oldlsp)
1447 {
1448 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1449 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1450 area->lspdb[level - 1]);
1451 /* FIXME: we should actually initiate a purge */
1452 }
1453 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1454 area->is_type, 0, level);
1455 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001456
hassof390d2c2004-09-10 20:48:21 +00001457 lsp_insert (newlsp, area->lspdb[level - 1]);
1458 /* build_lsp_data (newlsp, area); */
1459 lsp_build_nonpseudo (newlsp, area);
1460 /* time to calculate our checksum */
1461 lsp_seqnum_update (newlsp);
1462 }
jardineb5d44e2003-12-23 08:09:43 +00001463
1464 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001465 if (isis->debugs & DEBUG_ADJ_PACKETS)
1466 {
1467 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +00001468 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001469 }
jardineb5d44e2003-12-23 08:09:43 +00001470
1471 return ISIS_OK;
1472}
1473
1474/*
1475 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1476 */
1477int
1478lsp_l1_generate (struct isis_area *area)
1479{
hassof390d2c2004-09-10 20:48:21 +00001480 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1481 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001482
1483 return lsp_generate_non_pseudo (area, 1);
1484}
1485
jardineb5d44e2003-12-23 08:09:43 +00001486/*
1487 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1488 */
1489int
1490lsp_l2_generate (struct isis_area *area)
1491{
hassof390d2c2004-09-10 20:48:21 +00001492 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1493 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001494
1495 return lsp_generate_non_pseudo (area, 2);
1496}
1497
hasso92365882005-01-18 13:53:33 +00001498static int
jardineb5d44e2003-12-23 08:09:43 +00001499lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1500{
1501 dict_t *lspdb = area->lspdb[level - 1];
1502 struct isis_lsp *lsp, *frag;
1503 struct listnode *node;
1504 u_char lspid[ISIS_SYS_ID_LEN + 2];
1505
1506 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1507 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001508
jardineb5d44e2003-12-23 08:09:43 +00001509 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001510
hassof390d2c2004-09-10 20:48:21 +00001511 if (!lsp)
1512 {
1513 zlog_err
1514 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1515 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001516
hassof390d2c2004-09-10 20:48:21 +00001517 return ISIS_ERROR;
1518 }
1519
1520 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001521 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001522 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1523 (area->max_lsp_lifetime[level - 1],
1524 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001525 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001526
1527 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1528 {
hasso529d65b2004-12-24 00:14:50 +00001529 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1530 "seq 0x%08x, cksum 0x%04x lifetime %us",
1531 area->area_tag,
1532 level,
1533 rawlspid_print (lsp->lsp_header->lsp_id),
1534 ntohl (lsp->lsp_header->seq_num),
1535 ntohs (lsp->lsp_header->checksum),
1536 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001537 }
jardineb5d44e2003-12-23 08:09:43 +00001538
1539 lsp->last_generated = time (NULL);
1540 area->lsp_regenerate_pending[level - 1] = 0;
1541 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
paul1eb8ef22005-04-07 07:30:20 +00001542 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
hassof390d2c2004-09-10 20:48:21 +00001543 {
hassof390d2c2004-09-10 20:48:21 +00001544 frag->lsp_header->rem_lifetime = htons (isis_jitter
1545 (area->
1546 max_lsp_lifetime[level - 1],
1547 MAX_AGE_JITTER));
1548 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1549 }
jardineb5d44e2003-12-23 08:09:43 +00001550
1551 if (area->ip_circuits)
1552 isis_spf_schedule (area, level);
1553#ifdef HAVE_IPV6
1554 if (area->ipv6_circuits)
1555 isis_spf_schedule6 (area, level);
1556#endif
1557 return ISIS_OK;
1558}
1559
jardineb5d44e2003-12-23 08:09:43 +00001560/*
1561 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1562 * time and set SRM
1563 */
hassof390d2c2004-09-10 20:48:21 +00001564int
jardineb5d44e2003-12-23 08:09:43 +00001565lsp_refresh_l1 (struct thread *thread)
1566{
1567 struct isis_area *area;
1568 unsigned long ref_time;
1569
1570 area = THREAD_ARG (thread);
1571 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001572
jardineb5d44e2003-12-23 08:09:43 +00001573 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001574 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001575 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001576
1577 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001578 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1579
hassof390d2c2004-09-10 20:48:21 +00001580 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1581 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001582
jardineb5d44e2003-12-23 08:09:43 +00001583 return ISIS_OK;
1584}
1585
hassof390d2c2004-09-10 20:48:21 +00001586int
jardineb5d44e2003-12-23 08:09:43 +00001587lsp_refresh_l2 (struct thread *thread)
1588{
1589 struct isis_area *area;
1590 unsigned long ref_time;
1591
1592 area = THREAD_ARG (thread);
1593 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001594
jardineb5d44e2003-12-23 08:09:43 +00001595 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001596 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001597 lsp_non_pseudo_regenerate (area, 2);
1598
hassof390d2c2004-09-10 20:48:21 +00001599 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001600 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1601
hassof390d2c2004-09-10 20:48:21 +00001602 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1603 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001604
jardineb5d44e2003-12-23 08:09:43 +00001605 return ISIS_OK;
1606}
1607
jardineb5d44e2003-12-23 08:09:43 +00001608/*
1609 * Something has changed -> regenerate LSP
1610 */
1611
hasso92365882005-01-18 13:53:33 +00001612static int
jardineb5d44e2003-12-23 08:09:43 +00001613lsp_l1_regenerate (struct thread *thread)
1614{
1615 struct isis_area *area;
1616
1617 area = THREAD_ARG (thread);
1618 area->lsp_regenerate_pending[0] = 0;
1619
1620 return lsp_non_pseudo_regenerate (area, 1);
1621}
1622
hasso92365882005-01-18 13:53:33 +00001623static int
jardineb5d44e2003-12-23 08:09:43 +00001624lsp_l2_regenerate (struct thread *thread)
1625{
1626 struct isis_area *area;
1627
1628 area = THREAD_ARG (thread);
1629 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001630
jardineb5d44e2003-12-23 08:09:43 +00001631 return lsp_non_pseudo_regenerate (area, 2);
1632}
1633
hassof390d2c2004-09-10 20:48:21 +00001634int
jardineb5d44e2003-12-23 08:09:43 +00001635lsp_regenerate_schedule (struct isis_area *area)
1636{
1637 struct isis_lsp *lsp;
1638 u_char id[ISIS_SYS_ID_LEN + 2];
1639 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001640 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1641 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001642 now = time (NULL);
1643 /*
1644 * First level 1
1645 */
hassof390d2c2004-09-10 20:48:21 +00001646 if (area->is_type & IS_LEVEL_1)
1647 {
1648 lsp = lsp_search (id, area->lspdb[0]);
1649 if (!lsp || area->lsp_regenerate_pending[0])
1650 goto L2;
1651 /*
1652 * Throttle avoidance
1653 */
1654 diff = now - lsp->last_generated;
1655 if (diff < MIN_LSP_GEN_INTERVAL)
1656 {
1657 area->lsp_regenerate_pending[0] = 1;
Fritz Reichmann55749992011-09-14 19:31:51 +04001658 area->t_lsp_l1_regenerate=thread_add_timer (master, lsp_l1_regenerate, area,
hassof390d2c2004-09-10 20:48:21 +00001659 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001660 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001661 }
1662 else
1663 lsp_non_pseudo_regenerate (area, 1);
1664 }
jardineb5d44e2003-12-23 08:09:43 +00001665 /*
1666 * then 2
1667 */
hassof390d2c2004-09-10 20:48:21 +00001668L2:
1669 if (area->is_type & IS_LEVEL_2)
1670 {
1671 lsp = lsp_search (id, area->lspdb[1]);
1672 if (!lsp || area->lsp_regenerate_pending[1])
1673 return ISIS_OK;
1674 /*
1675 * Throttle avoidance
1676 */
1677 diff = now - lsp->last_generated;
1678 if (diff < MIN_LSP_GEN_INTERVAL)
1679 {
1680 area->lsp_regenerate_pending[1] = 1;
Fritz Reichmann55749992011-09-14 19:31:51 +04001681 area->t_lsp_l2_regenerate=thread_add_timer (master, lsp_l2_regenerate, area,
hassof390d2c2004-09-10 20:48:21 +00001682 MIN_LSP_GEN_INTERVAL - diff);
1683 return ISIS_OK;
1684 }
1685 else
1686 lsp_non_pseudo_regenerate (area, 2);
1687 }
1688
1689 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001690}
1691
1692/*
1693 * Funcs for pseudonode LSPs
1694 */
1695
1696/*
1697 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1698 */
hasso92365882005-01-18 13:53:33 +00001699static void
hassof390d2c2004-09-10 20:48:21 +00001700lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1701 int level)
jardineb5d44e2003-12-23 08:09:43 +00001702{
1703 struct isis_adjacency *adj;
1704 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001705 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001706 struct es_neigh *es_neigh;
1707 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001708 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00001709 struct isis_passwd *passwd;
1710
1711 assert (circuit);
1712 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001713
jardineb5d44e2003-12-23 08:09:43 +00001714 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001715 return; /* we are not DIS on this circuit */
1716
jardineb5d44e2003-12-23 08:09:43 +00001717 lsp->level = level;
1718 if (level == 1)
1719 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1720 else
1721 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1722
1723 /*
1724 * add self to IS neighbours
1725 */
hassoaa4376e2005-09-26 17:39:48 +00001726 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001727 {
hassoaa4376e2005-09-26 17:39:48 +00001728 if (lsp->tlv_data.is_neighs == NULL)
1729 {
1730 lsp->tlv_data.is_neighs = list_new ();
1731 lsp->tlv_data.is_neighs->del = free_tlv;
1732 }
1733 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001734
hassoaa4376e2005-09-26 17:39:48 +00001735 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1736 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1737 }
1738 if (circuit->area->newmetric)
1739 {
1740 if (lsp->tlv_data.te_is_neighs == NULL)
1741 {
1742 lsp->tlv_data.te_is_neighs = list_new ();
1743 lsp->tlv_data.te_is_neighs->del = free_tlv;
1744 }
1745 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1746
1747 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1748 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1749 }
hassof390d2c2004-09-10 20:48:21 +00001750
1751 adj_list = list_new ();
1752 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1753
hasso3fdb2dd2005-09-28 18:45:54 +00001754 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001755 {
hassof390d2c2004-09-10 20:48:21 +00001756 if (adj->circuit_t & level)
1757 {
1758 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1759 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00001760 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
hassof390d2c2004-09-10 20:48:21 +00001761 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1762 {
1763 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00001764 if (circuit->area->oldmetric)
1765 {
1766 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001767
hassoaa4376e2005-09-26 17:39:48 +00001768 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1769 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1770 }
1771 if (circuit->area->newmetric)
1772 {
1773 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1774 sizeof (struct te_is_neigh));
1775 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1776 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1777 }
hassof390d2c2004-09-10 20:48:21 +00001778 }
1779 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1780 {
1781 /* an ES neigbour add it, if we are building level 1 LSP */
1782 /* FIXME: the tlv-format is hard to use here */
1783 if (lsp->tlv_data.es_neighs == NULL)
1784 {
1785 lsp->tlv_data.es_neighs = list_new ();
1786 lsp->tlv_data.es_neighs->del = free_tlv;
1787 }
paul15935e92005-05-03 09:27:23 +00001788 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1789
hassof390d2c2004-09-10 20:48:21 +00001790 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001791 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001792 }
1793 }
jardineb5d44e2003-12-23 08:09:43 +00001794 }
hassof390d2c2004-09-10 20:48:21 +00001795
hassoc0fb2a52005-09-03 16:29:40 +00001796 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001797 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001798 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1799
jardineb5d44e2003-12-23 08:09:43 +00001800 /*
1801 * Add the authentication info if it's present
1802 */
hassof390d2c2004-09-10 20:48:21 +00001803 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1804 (passwd = &circuit->area->domain_passwd);
1805 if (passwd->type)
1806 {
1807 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1808 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1809 }
jardineb5d44e2003-12-23 08:09:43 +00001810
1811 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1812 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1813
hassoaa4376e2005-09-26 17:39:48 +00001814 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
1815 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
1816
jardineb5d44e2003-12-23 08:09:43 +00001817 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1818 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1819
paul9985f832005-02-09 15:51:56 +00001820 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
Jingjing Duan6a270cd2008-08-13 19:09:10 +01001821 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00001822 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1823
jardineb5d44e2003-12-23 08:09:43 +00001824 list_delete (adj_list);
1825
1826 return;
1827}
1828
hasso92365882005-01-18 13:53:33 +00001829static int
jardineb5d44e2003-12-23 08:09:43 +00001830lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1831{
1832 dict_t *lspdb = circuit->area->lspdb[level - 1];
1833 struct isis_lsp *lsp;
1834 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00001835
jardineb5d44e2003-12-23 08:09:43 +00001836 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001837 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1838 LSP_FRAGMENT (lsp_id) = 0;
1839
jardineb5d44e2003-12-23 08:09:43 +00001840 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00001841
1842 if (!lsp)
1843 {
1844 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1845 rawlspid_print (lsp_id));
1846 return ISIS_ERROR;
1847 }
1848 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001849
1850 lsp_build_pseudo (lsp, circuit, level);
1851
hassof390d2c2004-09-10 20:48:21 +00001852 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00001853 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00001854 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001855
1856 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00001857
1858 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1859 {
hasso529d65b2004-12-24 00:14:50 +00001860 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1861 circuit->area->area_tag, level,
1862 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00001863 }
jardineb5d44e2003-12-23 08:09:43 +00001864
1865 lsp->last_generated = time (NULL);
1866 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001867
jardineb5d44e2003-12-23 08:09:43 +00001868 return ISIS_OK;
1869}
1870
jardineb5d44e2003-12-23 08:09:43 +00001871int
1872lsp_l1_refresh_pseudo (struct thread *thread)
1873{
1874 struct isis_circuit *circuit;
1875 int retval;
1876 unsigned long ref_time;
1877
hassof390d2c2004-09-10 20:48:21 +00001878 circuit = THREAD_ARG (thread);
1879
jardineb5d44e2003-12-23 08:09:43 +00001880 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00001881 return ISIS_ERROR; /* FIXME: purge and such */
1882
hasso13c48f72004-09-10 21:19:13 +00001883 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
1884
jardineb5d44e2003-12-23 08:09:43 +00001885 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00001886
1887 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001888 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
1889
hassof390d2c2004-09-10 20:48:21 +00001890 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
1891 lsp_l1_refresh_pseudo, circuit,
1892 isis_jitter (ref_time, MAX_AGE_JITTER));
1893
jardineb5d44e2003-12-23 08:09:43 +00001894 return retval;
1895}
1896
hassof390d2c2004-09-10 20:48:21 +00001897int
jardineb5d44e2003-12-23 08:09:43 +00001898lsp_l1_pseudo_generate (struct isis_circuit *circuit)
1899{
1900 struct isis_lsp *lsp;
1901 u_char id[ISIS_SYS_ID_LEN + 2];
1902 unsigned long ref_time;
1903
hassof390d2c2004-09-10 20:48:21 +00001904 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1905 LSP_FRAGMENT (id) = 0;
1906 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00001907
1908 /*
1909 * If for some reason have a pseudo LSP in the db already -> regenerate
1910 */
1911 if (lsp_search (id, circuit->area->lspdb[0]))
1912 return lsp_pseudo_regenerate (circuit, 1);
1913 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00001914 1, circuit->area->is_type, 0, 1);
1915
jardineb5d44e2003-12-23 08:09:43 +00001916 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00001917
jardineb5d44e2003-12-23 08:09:43 +00001918 lsp->own_lsp = 1;
1919 lsp_insert (lsp, circuit->area->lspdb[0]);
1920 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1921
hassof390d2c2004-09-10 20:48:21 +00001922 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001923 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
1924
hassof390d2c2004-09-10 20:48:21 +00001925 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
1926 lsp_l1_refresh_pseudo, circuit,
1927 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001928
1929 return lsp_regenerate_schedule (circuit->area);
1930}
1931
1932int
1933lsp_l2_refresh_pseudo (struct thread *thread)
1934{
1935 struct isis_circuit *circuit;
1936 int retval;
1937 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00001938 circuit = THREAD_ARG (thread);
1939
jardineb5d44e2003-12-23 08:09:43 +00001940 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00001941 return ISIS_ERROR; /* FIXME: purge and such */
1942
hasso13c48f72004-09-10 21:19:13 +00001943 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
1944
jardineb5d44e2003-12-23 08:09:43 +00001945 retval = lsp_pseudo_regenerate (circuit, 2);
1946
hassof390d2c2004-09-10 20:48:21 +00001947 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001948 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
1949
hassof390d2c2004-09-10 20:48:21 +00001950 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
1951 lsp_l2_refresh_pseudo, circuit,
1952 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001953
jardineb5d44e2003-12-23 08:09:43 +00001954 return retval;
1955}
1956
hassof390d2c2004-09-10 20:48:21 +00001957int
jardineb5d44e2003-12-23 08:09:43 +00001958lsp_l2_pseudo_generate (struct isis_circuit *circuit)
1959{
1960 struct isis_lsp *lsp;
1961 u_char id[ISIS_SYS_ID_LEN + 2];
1962 unsigned long ref_time;
1963
hassof390d2c2004-09-10 20:48:21 +00001964 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1965 LSP_FRAGMENT (id) = 0;
1966 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00001967
1968 if (lsp_search (id, circuit->area->lspdb[1]))
1969 return lsp_pseudo_regenerate (circuit, 2);
1970
1971 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00001972 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00001973
1974 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00001975
1976 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001977 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
1978
1979
1980 lsp->own_lsp = 1;
1981 lsp_insert (lsp, circuit->area->lspdb[1]);
1982 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001983
1984 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
1985 lsp_l2_refresh_pseudo, circuit,
1986 isis_jitter (ref_time, MAX_AGE_JITTER));
1987
jardineb5d44e2003-12-23 08:09:43 +00001988 return lsp_regenerate_schedule (circuit->area);
1989}
1990
jardineb5d44e2003-12-23 08:09:43 +00001991/*
1992 * Walk through LSPs for an area
1993 * - set remaining lifetime
1994 * - set LSPs with SRMflag set for sending
1995 */
hassof390d2c2004-09-10 20:48:21 +00001996int
jardineb5d44e2003-12-23 08:09:43 +00001997lsp_tick (struct thread *thread)
1998{
1999 struct isis_area *area;
2000 struct isis_circuit *circuit;
2001 struct isis_lsp *lsp;
2002 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00002003 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002004 dnode_t *dnode, *dnode_next;
2005 int level;
2006
2007 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002008
jardineb5d44e2003-12-23 08:09:43 +00002009 area = THREAD_ARG (thread);
2010 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002011 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002012 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002013
2014 /*
2015 * Build a list of LSPs with (any) SRMflag set
2016 * and removed the ones that have aged out
2017 */
hassof390d2c2004-09-10 20:48:21 +00002018 for (level = 0; level < ISIS_LEVELS; level++)
2019 {
2020 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2021 {
2022 dnode = dict_first (area->lspdb[level]);
2023 while (dnode != NULL)
2024 {
2025 dnode_next = dict_next (area->lspdb[level], dnode);
2026 lsp = dnode_get (dnode);
2027 lsp_set_time (lsp);
2028 if (lsp->age_out == 0)
2029 {
jardineb5d44e2003-12-23 08:09:43 +00002030
hasso529d65b2004-12-24 00:14:50 +00002031 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2032 area->area_tag,
2033 lsp->level,
2034 rawlspid_print (lsp->lsp_header->lsp_id),
2035 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002036#ifdef TOPOLOGY_GENERATE
2037 if (lsp->from_topology)
2038 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2039#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00002040 lsp_destroy (lsp);
2041 dict_delete (area->lspdb[level], dnode);
2042 }
2043 else if (flags_any_set (lsp->SRMflags))
2044 listnode_add (lsp_list, lsp);
2045 dnode = dnode_next;
2046 }
jardineb5d44e2003-12-23 08:09:43 +00002047
hassof390d2c2004-09-10 20:48:21 +00002048 /*
2049 * Send LSPs on circuits indicated by the SRMflags
2050 */
2051 if (listcount (lsp_list) > 0)
2052 {
paul1eb8ef22005-04-07 07:30:20 +00002053 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00002054 {
Peter Szilagyi7fd6cd82011-10-01 17:11:45 +04002055 if (circuit->state != C_STATE_UP)
2056 continue;
hasso3fdb2dd2005-09-28 18:45:54 +00002057 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
hassof390d2c2004-09-10 20:48:21 +00002058 {
hassof390d2c2004-09-10 20:48:21 +00002059 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2060 {
2061 /* FIXME: if same or elder lsp is already in lsp
2062 * queue */
2063 listnode_add (circuit->lsp_queue, lsp);
2064 thread_add_event (master, send_lsp, circuit, 0);
2065 }
2066 }
2067 }
2068 }
2069 list_delete_all_node (lsp_list);
2070 }
jardineb5d44e2003-12-23 08:09:43 +00002071 }
jardineb5d44e2003-12-23 08:09:43 +00002072
2073 list_delete (lsp_list);
2074
2075 return ISIS_OK;
2076}
2077
jardineb5d44e2003-12-23 08:09:43 +00002078void
hassof390d2c2004-09-10 20:48:21 +00002079lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002080{
2081 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002082
jardineb5d44e2003-12-23 08:09:43 +00002083 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002084
2085 if (lsp && lsp->purged == 0)
2086 {
2087 lsp->lsp_header->rem_lifetime = htons (0);
2088 lsp->lsp_header->pdu_len =
2089 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2090 lsp->purged = 0;
Jingjing Duan6a270cd2008-08-13 19:09:10 +01002091 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002092 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2093 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2094 }
2095
jardineb5d44e2003-12-23 08:09:43 +00002096 return;
2097}
2098
2099/*
2100 * Purge own LSP that is received and we don't have.
2101 * -> Do as in 7.3.16.4
2102 */
2103void
hassof390d2c2004-09-10 20:48:21 +00002104lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2105 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002106{
2107 struct isis_lsp *lsp;
2108
2109 /*
2110 * We need to create the LSP to be purged
2111 */
hasso529d65b2004-12-24 00:14:50 +00002112 zlog_debug ("LSP PURGE NON EXIST");
hassoaac372f2005-09-01 17:52:33 +00002113 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002114 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2115 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002116 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2117 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002118 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002119 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002120 : L2_LINK_STATE);
2121 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2122 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002123 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002124
jardineb5d44e2003-12-23 08:09:43 +00002125 /*
2126 * Retain only LSP header
2127 */
2128 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2129 /*
2130 * Set the remaining lifetime to 0
2131 */
2132 lsp->lsp_header->rem_lifetime = 0;
2133 /*
2134 * Put the lsp into LSPdb
2135 */
hassof390d2c2004-09-10 20:48:21 +00002136 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002137
2138 /*
2139 * Send in to whole area
2140 */
2141 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002142
jardineb5d44e2003-12-23 08:09:43 +00002143 return;
2144}
2145
2146#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002147static int
jardineb5d44e2003-12-23 08:09:43 +00002148top_lsp_refresh (struct thread *thread)
2149{
hassof390d2c2004-09-10 20:48:21 +00002150 struct isis_lsp *lsp;
hassof1082d12005-09-19 04:23:34 +00002151 unsigned long ref_time;
jardineb5d44e2003-12-23 08:09:43 +00002152
2153 lsp = THREAD_ARG (thread);
2154 assert (lsp);
2155
2156 lsp->t_lsp_top_ref = NULL;
2157
hassof1082d12005-09-19 04:23:34 +00002158 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002159
2160 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002161 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2162 {
hasso529d65b2004-12-24 00:14:50 +00002163 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2164 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002165 }
hassod3d74742005-09-28 18:30:51 +00002166 /* Refresh dynamic hostname in the cache. */
2167 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2168 IS_LEVEL_1);
2169
hassof1082d12005-09-19 04:23:34 +00002170 lsp->lsp_header->rem_lifetime =
2171 htons (isis_jitter (lsp->area->max_lsp_lifetime[0], MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002172
hassof1082d12005-09-19 04:23:34 +00002173 ref_time = lsp->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2174 MAX_LSP_GEN_INTERVAL : lsp->area->lsp_refresh[0];
2175
hassof390d2c2004-09-10 20:48:21 +00002176 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
hassof1082d12005-09-19 04:23:34 +00002177 isis_jitter (ref_time, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002178
2179 return ISIS_OK;
2180}
2181
2182void
2183generate_topology_lsps (struct isis_area *area)
2184{
2185 struct listnode *node;
2186 int i, max = 0;
2187 struct arc *arc;
2188 u_char lspid[ISIS_SYS_ID_LEN + 2];
2189 struct isis_lsp *lsp;
hassof1082d12005-09-19 04:23:34 +00002190 unsigned long ref_time;
jardineb5d44e2003-12-23 08:09:43 +00002191
2192 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002193 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002194 {
2195 if (arc->from_node > max)
2196 max = arc->from_node;
2197 if (arc->to_node > max)
2198 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002199 }
2200
hassof390d2c2004-09-10 20:48:21 +00002201 for (i = 1; i < (max + 1); i++)
2202 {
2203 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2204 LSP_PSEUDO_ID (lspid) = 0x00;
2205 LSP_FRAGMENT (lspid) = 0x00;
2206 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2207 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002208
hassof390d2c2004-09-10 20:48:21 +00002209 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
hassof1082d12005-09-19 04:23:34 +00002210 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0, 1);
2211 if (!lsp)
2212 return;
hassof390d2c2004-09-10 20:48:21 +00002213 lsp->from_topology = 1;
hassof1082d12005-09-19 04:23:34 +00002214 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00002215
hassof1082d12005-09-19 04:23:34 +00002216 /* Creating LSP data based on topology info. */
2217 build_topology_lsp_data (lsp, area, i);
2218 /* Checksum is also calculated here. */
2219 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002220 /* Take care of inserting dynamic hostname into cache. */
2221 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002222
2223 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2224 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
2225
2226 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2227 isis_jitter (ref_time, MAX_LSP_GEN_JITTER));
hassof390d2c2004-09-10 20:48:21 +00002228 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2229 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002230 }
jardineb5d44e2003-12-23 08:09:43 +00002231}
2232
2233void
2234remove_topology_lsps (struct isis_area *area)
2235{
2236 struct isis_lsp *lsp;
2237 dnode_t *dnode, *dnode_next;
2238
2239 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002240 while (dnode != NULL)
2241 {
2242 dnode_next = dict_next (area->lspdb[0], dnode);
2243 lsp = dnode_get (dnode);
2244 if (lsp->from_topology)
2245 {
2246 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2247 lsp_destroy (lsp);
2248 dict_delete (area->lspdb[0], dnode);
2249 }
2250 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002251 }
jardineb5d44e2003-12-23 08:09:43 +00002252}
2253
2254void
hassof390d2c2004-09-10 20:48:21 +00002255build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002256 int lsp_top_num)
2257{
hasso3fdb2dd2005-09-28 18:45:54 +00002258 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002259 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002260 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002261 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002262 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002263 struct tlvs tlv_data;
2264 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002265
hassof1082d12005-09-19 04:23:34 +00002266 /* Add area addresses. FIXME: Is it needed at all? */
2267 if (lsp->tlv_data.area_addrs == NULL)
2268 lsp->tlv_data.area_addrs = list_new ();
2269 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002270
hassof1082d12005-09-19 04:23:34 +00002271 if (lsp->tlv_data.nlpids == NULL)
2272 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2273 lsp->tlv_data.nlpids->count = 1;
2274 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002275
hassof1082d12005-09-19 04:23:34 +00002276 if (area->dynhostname)
2277 {
2278 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2279 sizeof (struct hostname));
2280 memset (buff, 0x00, 200);
2281 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2282 "feedme", lsp_top_num);
2283 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2284 lsp->tlv_data.hostname->namelen = strlen (buff);
2285 }
2286
2287 if (lsp->tlv_data.nlpids)
2288 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2289 if (lsp->tlv_data.hostname)
2290 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2291 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2292 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2293
2294 memset (&tlv_data, 0, sizeof (struct tlvs));
2295 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002296 {
2297 tlv_data.is_neighs = list_new ();
2298 tlv_data.is_neighs->del = free_tlv;
2299 }
hassof1082d12005-09-19 04:23:34 +00002300
2301 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002302 if (lsp_top_num == 1)
2303 {
hasso3fdb2dd2005-09-28 18:45:54 +00002304 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002305
hassof390d2c2004-09-10 20:48:21 +00002306 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002307 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002308 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2309 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002310 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2311 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2312 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002313 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002314 }
hassof390d2c2004-09-10 20:48:21 +00002315
hassof1082d12005-09-19 04:23:34 +00002316 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002317 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002318 {
hassof1082d12005-09-19 04:23:34 +00002319 int to_lsp = 0;
2320
2321 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2322 continue;
2323
2324 if (lsp_top_num == arc->from_node)
2325 to_lsp = arc->to_node;
2326 else
2327 to_lsp = arc->from_node;
2328
hasso9551eea2005-09-28 18:26:25 +00002329 if (area->oldmetric)
2330 {
2331 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002332
hasso9551eea2005-09-28 18:26:25 +00002333 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2334 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2335 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2336 is_neigh->metrics.metric_default = arc->distance;
2337 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2338 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2339 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2340 listnode_add (tlv_data.is_neighs, is_neigh);
2341 }
2342
2343 if (area->newmetric)
2344 {
2345 uint32_t metric;
2346
2347 if (tlv_data.te_is_neighs == NULL)
2348 {
2349 tlv_data.te_is_neighs = list_new ();
2350 tlv_data.te_is_neighs->del = free_tlv;
2351 }
2352 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2353 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2354 ISIS_SYS_ID_LEN);
2355 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2356 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2357 metric = ((htonl(arc->distance) >> 8) & 0xffffff);
2358 memcpy (te_is_neigh->te_metric, &metric, 3);
2359 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2360 }
hassof390d2c2004-09-10 20:48:21 +00002361 }
hassof1082d12005-09-19 04:23:34 +00002362
2363 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2364 {
2365 if (lsp->tlv_data.is_neighs == NULL)
2366 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002367 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002368 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2369 tlv_add_is_neighs);
2370 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2371 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2372 lsp0, area, IS_LEVEL_1);
2373 }
2374
hasso9551eea2005-09-28 18:26:25 +00002375 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2376 {
2377 if (lsp->tlv_data.te_is_neighs == NULL)
2378 lsp->tlv_data.te_is_neighs = list_new ();
2379 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2380 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2381 tlv_add_te_is_neighs);
2382 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2383 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2384 lsp0, area, IS_LEVEL_1);
2385 }
2386
hassof1082d12005-09-19 04:23:34 +00002387 free_tlvs (&tlv_data);
2388 return;
jardineb5d44e2003-12-23 08:09:43 +00002389}
2390#endif /* TOPOLOGY_GENERATE */