blob: 48e3147d75f540d0eee3db6ef813870fefc9dffe [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);
jardineb5d44e2003-12-23 08:09:43 +0000356 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000357 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000358
359 return authentication_check (passwd, &tlvs.auth_info);
360}
361
hasso92365882005-01-18 13:53:33 +0000362static void
hassof390d2c2004-09-10 20:48:21 +0000363lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
364 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000365{
hassof390d2c2004-09-10 20:48:21 +0000366 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000367 int retval;
hassof390d2c2004-09-10 20:48:21 +0000368
jardineb5d44e2003-12-23 08:09:43 +0000369 /* copying only the relevant part of our stream */
paul15935e92005-05-03 09:27:23 +0000370 lsp->pdu = stream_dup (stream);
371
jardineb5d44e2003-12-23 08:09:43 +0000372 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000373 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
374 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
375 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000376 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000377 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000378 /*
379 * Get LSP data i.e. TLVs
380 */
381 expected |= TLVFLAG_AUTH_INFO;
382 expected |= TLVFLAG_AREA_ADDRS;
383 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000384 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000385 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
386 expected |= TLVFLAG_NLPID;
387 if (area->dynhostname)
388 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000389 if (area->newmetric)
390 {
391 expected |= TLVFLAG_TE_IS_NEIGHS;
392 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
393 expected |= TLVFLAG_TE_ROUTER_ID;
394 }
jardineb5d44e2003-12-23 08:09:43 +0000395 expected |= TLVFLAG_IPV4_ADDR;
396 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
397 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
398#ifdef HAVE_IPV6
399 expected |= TLVFLAG_IPV6_ADDR;
400 expected |= TLVFLAG_IPV6_REACHABILITY;
401#endif /* HAVE_IPV6 */
402
403 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000404 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
405 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
406 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000407
hassof390d2c2004-09-10 20:48:21 +0000408 if (found & TLVFLAG_DYN_HOSTNAME)
409 {
410 if (area->dynhostname)
411 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
412 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
413 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
414 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
415 }
jardineb5d44e2003-12-23 08:09:43 +0000416
417}
418
419void
420lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassoa96d8d12005-09-16 14:44:23 +0000421 struct stream *stream, struct isis_area *area, int level)
jardineb5d44e2003-12-23 08:09:43 +0000422{
hasso4eda93a2005-09-18 17:51:02 +0000423 dnode_t *dnode = NULL;
hassoa96d8d12005-09-16 14:44:23 +0000424
425 /* Remove old LSP from LSP database. */
hasso4eda93a2005-09-18 17:51:02 +0000426 dnode = dict_lookup (area->lspdb[level - 1], lsp->lsp_header->lsp_id);
427 if (dnode)
428 dnode_destroy (dict_delete (area->lspdb[level - 1], dnode));
hassoa96d8d12005-09-16 14:44:23 +0000429
hassof390d2c2004-09-10 20:48:21 +0000430 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000431 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
432 lsp_clear_data (lsp);
433
434 /* rebuild the lsp data */
435 lsp_update_data (lsp, stream, area);
436
hassof390d2c2004-09-10 20:48:21 +0000437 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000438 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassoa96d8d12005-09-16 14:44:23 +0000439
hasso4eda93a2005-09-18 17:51:02 +0000440 if (dnode)
441 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000442}
443
jardineb5d44e2003-12-23 08:09:43 +0000444/* creation of LSP directly from what we received */
445struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000446lsp_new_from_stream_ptr (struct stream *stream,
447 u_int16_t pdu_len, struct isis_lsp *lsp0,
448 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000449{
450 struct isis_lsp *lsp;
451
hassoaac372f2005-09-01 17:52:33 +0000452 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
jardineb5d44e2003-12-23 08:09:43 +0000453 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000454
455 if (lsp0 == NULL)
456 {
457 /*
458 * zero lsp -> create the list for fragments
459 */
460 lsp->lspu.frags = list_new ();
461 }
462 else
463 {
464 /*
465 * a fragment -> set the backpointer and add this to zero lsps frag list
466 */
467 lsp->lspu.zero_lsp = lsp0;
468 listnode_add (lsp0->lspu.frags, lsp);
469 }
470
jardineb5d44e2003-12-23 08:09:43 +0000471 return lsp;
472}
473
474struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000475lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
476 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000477{
478 struct isis_lsp *lsp;
479
hassoaac372f2005-09-01 17:52:33 +0000480 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000481 if (!lsp)
482 {
483 /* FIXME: set lspdbol bit */
484 zlog_warn ("lsp_new(): out of memory");
485 return NULL;
486 }
jardineb5d44e2003-12-23 08:09:43 +0000487#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000488 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000489#else
hassof390d2c2004-09-10 20:48:21 +0000490 /* We need to do realloc on TLVs additions */
491 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000492#endif /* LSP_MEMORY_PREASSIGN */
493 if (LSP_FRAGMENT (lsp_id) == 0)
494 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000495 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
496 lsp->lsp_header = (struct isis_link_state_hdr *)
497 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
498
jardineb5d44e2003-12-23 08:09:43 +0000499 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000500 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
501 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
502
jardineb5d44e2003-12-23 08:09:43 +0000503 /* now for the LSP HEADER */
504 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000505 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000506 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000507 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000508 lsp->lsp_header->seq_num = htonl (seq_num);
509 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
510 lsp->lsp_header->lsp_bits = lsp_bits;
511 lsp->level = level;
512 lsp->age_out = ZERO_AGE_LIFETIME;
513
paul9985f832005-02-09 15:51:56 +0000514 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000515
hassoc89c05d2005-09-04 21:36:36 +0000516 if (isis->debugs & DEBUG_EVENTS)
517 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x",
518 sysid_print (lsp_id), LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
519 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
520 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000521
522 return lsp;
523}
524
525void
hassof390d2c2004-09-10 20:48:21 +0000526lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000527{
528 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
529}
530
531/*
532 * Build a list of LSPs with non-zero ht bounded by start and stop ids
533 */
hassof390d2c2004-09-10 20:48:21 +0000534void
535lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
536 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000537{
538 dnode_t *first, *last, *curr;
539
540 first = dict_lower_bound (lspdb, start_id);
541 if (!first)
542 return;
hassof390d2c2004-09-10 20:48:21 +0000543
jardineb5d44e2003-12-23 08:09:43 +0000544 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000545
jardineb5d44e2003-12-23 08:09:43 +0000546 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000547
548 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000549 listnode_add (list, first->dict_data);
550
hassof390d2c2004-09-10 20:48:21 +0000551 while (curr)
552 {
553 curr = dict_next (lspdb, curr);
554 if (curr &&
555 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
556 listnode_add (list, curr->dict_data);
557 if (curr == last)
558 break;
559 }
560
jardineb5d44e2003-12-23 08:09:43 +0000561 return;
562}
563
564/*
565 * Build a list of all LSPs bounded by start and stop ids
566 */
hassof390d2c2004-09-10 20:48:21 +0000567void
568lsp_build_list (u_char * start_id, u_char * stop_id,
569 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000570{
571 dnode_t *first, *last, *curr;
572
573 first = dict_lower_bound (lspdb, start_id);
574 if (!first)
575 return;
hassof390d2c2004-09-10 20:48:21 +0000576
jardineb5d44e2003-12-23 08:09:43 +0000577 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000578
jardineb5d44e2003-12-23 08:09:43 +0000579 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000580
jardineb5d44e2003-12-23 08:09:43 +0000581 listnode_add (list, first->dict_data);
582
hassof390d2c2004-09-10 20:48:21 +0000583 while (curr)
584 {
585 curr = dict_next (lspdb, curr);
586 if (curr)
587 listnode_add (list, curr->dict_data);
588 if (curr == last)
589 break;
590 }
591
jardineb5d44e2003-12-23 08:09:43 +0000592 return;
593}
594
595/*
596 * Build a list of LSPs with SSN flag set for the given circuit
597 */
598void
hassof390d2c2004-09-10 20:48:21 +0000599lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
600 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000601{
602 dnode_t *dnode, *next;
603 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000604
jardineb5d44e2003-12-23 08:09:43 +0000605 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000606 while (dnode != NULL)
607 {
608 next = dict_next (lspdb, dnode);
609 lsp = dnode_get (dnode);
610 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
611 listnode_add (list, lsp);
612 dnode = next;
613 }
614
jardineb5d44e2003-12-23 08:09:43 +0000615 return;
616}
617
hasso92365882005-01-18 13:53:33 +0000618static void
jardineb5d44e2003-12-23 08:09:43 +0000619lsp_set_time (struct isis_lsp *lsp)
620{
621 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000622
623 if (lsp->lsp_header->rem_lifetime == 0)
624 {
625 if (lsp->age_out != 0)
626 lsp->age_out--;
627 return;
628 }
jardineb5d44e2003-12-23 08:09:43 +0000629
630 /* If we are turning 0 */
631 /* ISO 10589 - 7.3.16.4 first paragraph */
632
hassof390d2c2004-09-10 20:48:21 +0000633 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
634 {
635 /* 7.3.16.4 a) set SRM flags on all */
636 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
637 /* 7.3.16.4 b) retain only the header FIXME */
638 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
639 }
jardineb5d44e2003-12-23 08:09:43 +0000640
hassof390d2c2004-09-10 20:48:21 +0000641 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000642 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
643}
644
hasso92365882005-01-18 13:53:33 +0000645static void
hassof390d2c2004-09-10 20:48:21 +0000646lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000647{
648 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000649 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000650
651 if (dynhost)
652 dyn = dynhn_find_by_id (lsp_id);
653 else
654 dyn = NULL;
655
656 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000657 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000658 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000659 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000660 else
hassof390d2c2004-09-10 20:48:21 +0000661 {
662 memcpy (id, sysid_print (lsp_id), 15);
663 }
664 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000665 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000666 LSP_FRAGMENT (lsp_id));
667 else
hassof7c43dc2004-09-26 16:24:14 +0000668 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000669}
670
hassof390d2c2004-09-10 20:48:21 +0000671/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000672const char *
hassof390d2c2004-09-10 20:48:21 +0000673lsp_bits2string (u_char * lsp_bits)
674{
675 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000676
hassof390d2c2004-09-10 20:48:21 +0000677 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000678 return " none";
679
680 /* we only focus on the default metric */
681 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000682 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000683
684 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000685 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000686
hassof390d2c2004-09-10 20:48:21 +0000687 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
688
jardineb5d44e2003-12-23 08:09:43 +0000689 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000690
hassof390d2c2004-09-10 20:48:21 +0000691 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000692}
693
694/* this function prints the lsp on show isis database */
hasso92365882005-01-18 13:53:33 +0000695static void
hassof390d2c2004-09-10 20:48:21 +0000696lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000697{
hassof390d2c2004-09-10 20:48:21 +0000698 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000699 u_char LSPid[255];
700
701 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000702 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
703 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
704 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000705
hassof390d2c2004-09-10 20:48:21 +0000706 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
707 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000708 else
hassof390d2c2004-09-10 20:48:21 +0000709 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000710
711 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000712 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000713}
714
hasso92365882005-01-18 13:53:33 +0000715static void
hassof390d2c2004-09-10 20:48:21 +0000716lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000717{
718 struct isis_lsp *lsp = dnode_get (node);
719 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000720 int i;
hasso3fdb2dd2005-09-28 18:45:54 +0000721 struct listnode *lnode;
jardineb5d44e2003-12-23 08:09:43 +0000722 struct is_neigh *is_neigh;
723 struct te_is_neigh *te_is_neigh;
724 struct ipv4_reachability *ipv4_reach;
725 struct in_addr *ipv4_addr;
726 struct te_ipv4_reachability *te_ipv4_reach;
727#ifdef HAVE_IPV6
728 struct ipv6_reachability *ipv6_reach;
729 struct in6_addr in6;
Paul Jakma41b36e92006-12-08 01:09:50 +0000730 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000731#endif
732 u_char LSPid[255];
733 u_char hostname[255];
jardineb5d44e2003-12-23 08:09:43 +0000734 u_char ipv4_reach_prefix[20];
735 u_char ipv4_reach_mask[20];
736 u_char ipv4_address[20];
737
738 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000739 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000740
741 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000742 if (lsp->tlv_data.area_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000743 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.area_addrs, lnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000744 {
hasso1cd80842004-10-07 20:07:40 +0000745 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000746 isonet_print (area_addr->area_addr, area_addr->addr_len),
747 VTY_NEWLINE);
748 }
paul1eb8ef22005-04-07 07:30:20 +0000749
jardineb5d44e2003-12-23 08:09:43 +0000750 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000751 if (lsp->tlv_data.nlpids)
752 {
753 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
754 {
755 switch (lsp->tlv_data.nlpids->nlpids[i])
756 {
757 case NLPID_IP:
758 case NLPID_IPV6:
hasso1cd80842004-10-07 20:07:40 +0000759 vty_out (vty, " NLPID: 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000760 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
761 break;
762 default:
hasso1cd80842004-10-07 20:07:40 +0000763 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000764 break;
765 }
766 }
767 }
jardineb5d44e2003-12-23 08:09:43 +0000768
769 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000770 if (lsp->tlv_data.hostname)
771 {
772 bzero (hostname, sizeof (hostname));
773 memcpy (hostname, lsp->tlv_data.hostname->name,
774 lsp->tlv_data.hostname->namelen);
775 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000776 }
hassof390d2c2004-09-10 20:48:21 +0000777
778 if (lsp->tlv_data.ipv4_addrs)
hasso3fdb2dd2005-09-28 18:45:54 +0000779 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_addrs, lnode, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000780 {
781 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
782 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
783 }
hassof390d2c2004-09-10 20:48:21 +0000784
hasso1cd80842004-10-07 20:07:40 +0000785 /* TE router id */
786 if (lsp->tlv_data.router_id)
787 {
788 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
789 sizeof (ipv4_address));
790 vty_out (vty, " Router ID: %s%s", ipv4_address, VTY_NEWLINE);
791 }
792
793 /* for the IS neighbor tlv */
794 if (lsp->tlv_data.is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000795 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, lnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000796 {
797 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
hasso96e30382005-09-19 06:35:47 +0000798 vty_out (vty, " Metric: %-10d IS %s%s",
hasso1cd80842004-10-07 20:07:40 +0000799 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
800 }
hasso1cd80842004-10-07 20:07:40 +0000801
jardineb5d44e2003-12-23 08:09:43 +0000802 /* for the internal reachable tlv */
803 if (lsp->tlv_data.ipv4_int_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000804 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, lnode,
805 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000806 {
807 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
808 sizeof (ipv4_reach_prefix));
809 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
810 sizeof (ipv4_reach_mask));
hasso96e30382005-09-19 06:35:47 +0000811 vty_out (vty, " Metric: %-10d IP-Internal %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000812 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
813 ipv4_reach_mask, VTY_NEWLINE);
814 }
hasso2097cd82003-12-23 11:51:08 +0000815
816 /* for the external reachable tlv */
817 if (lsp->tlv_data.ipv4_ext_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000818 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, lnode,
819 ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000820 {
821 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
822 sizeof (ipv4_reach_prefix));
823 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
824 sizeof (ipv4_reach_mask));
hasso96e30382005-09-19 06:35:47 +0000825 vty_out (vty, " Metric: %-10d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000826 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
827 ipv4_reach_mask, VTY_NEWLINE);
828 }
paul1eb8ef22005-04-07 07:30:20 +0000829
hasso2097cd82003-12-23 11:51:08 +0000830 /* IPv6 tlv */
831#ifdef HAVE_IPV6
832 if (lsp->tlv_data.ipv6_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000833 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, lnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000834 {
835 memset (&in6, 0, sizeof (in6));
836 memcpy (in6.s6_addr, ipv6_reach->prefix,
837 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000838 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000839 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000840 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
hasso96e30382005-09-19 06:35:47 +0000841 vty_out (vty, " Metric: %-10d IPv6-Internal %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000842 ntohl (ipv6_reach->metric),
843 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000844 else
hasso96e30382005-09-19 06:35:47 +0000845 vty_out (vty, " Metric: %-10d IPv6-External %s/%d%s",
hassof390d2c2004-09-10 20:48:21 +0000846 ntohl (ipv6_reach->metric),
847 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000848 }
849#endif
paul1eb8ef22005-04-07 07:30:20 +0000850
hasso1cd80842004-10-07 20:07:40 +0000851 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000852 if (lsp->tlv_data.te_is_neighs)
hasso3fdb2dd2005-09-28 18:45:54 +0000853 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, lnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000854 {
hasso96e30382005-09-19 06:35:47 +0000855 uint32_t metric;
856 memcpy (&metric, te_is_neigh->te_metric, 3);
hassof390d2c2004-09-10 20:48:21 +0000857 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
hasso96e30382005-09-19 06:35:47 +0000858 vty_out (vty, " Metric: %-10d IS-Extended %s%s",
859 ntohl (metric << 8), LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000860 }
jardineb5d44e2003-12-23 08:09:43 +0000861
hasso1cd80842004-10-07 20:07:40 +0000862 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000863 if (lsp->tlv_data.te_ipv4_reachs)
hasso3fdb2dd2005-09-28 18:45:54 +0000864 for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, lnode,
865 te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000866 {
hasso1cd80842004-10-07 20:07:40 +0000867 /* FIXME: There should be better way to output this stuff. */
hasso96e30382005-09-19 06:35:47 +0000868 vty_out (vty, " Metric: %-10d IP-Extended %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000869 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000870 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
871 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000872 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000873 }
jardineb5d44e2003-12-23 08:09:43 +0000874
hassof390d2c2004-09-10 20:48:21 +0000875 return;
jardineb5d44e2003-12-23 08:09:43 +0000876}
877
878/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000879int
880lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000881{
882
hassof390d2c2004-09-10 20:48:21 +0000883 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000884 int lsp_count = 0;
885
886 /* print the title, for both modes */
887 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000888 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
889
890 if (detail == ISIS_UI_LEVEL_BRIEF)
891 {
892 while (node != NULL)
893 {
894 /* I think it is unnecessary, so I comment it out */
895 /* dict_contains (lspdb, node); */
896 next = dict_next (lspdb, node);
897 lsp_print (node, vty, dynhost);
898 node = next;
899 lsp_count++;
900 }
jardineb5d44e2003-12-23 08:09:43 +0000901 }
hassof390d2c2004-09-10 20:48:21 +0000902 else if (detail == ISIS_UI_LEVEL_DETAIL)
903 {
904 while (node != NULL)
905 {
906 next = dict_next (lspdb, node);
907 lsp_print_detail (node, vty, dynhost);
908 node = next;
909 lsp_count++;
910 }
jardineb5d44e2003-12-23 08:09:43 +0000911 }
jardineb5d44e2003-12-23 08:09:43 +0000912
913 return lsp_count;
914}
915
jardineb5d44e2003-12-23 08:09:43 +0000916#define FRAG_THOLD(S,T) \
917((STREAM_SIZE(S)*T)/100)
918
919/* stream*, area->lsp_frag_threshold, increment */
920#define FRAG_NEEDED(S,T,I) \
921 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
922
hassoaa4376e2005-09-26 17:39:48 +0000923/* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
924 * variable length (TE TLVs, sub TLVs). */
hasso92365882005-01-18 13:53:33 +0000925static void
jardineb5d44e2003-12-23 08:09:43 +0000926lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +0000927 int tlvsize, int frag_thold,
928 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +0000929{
930 int count, i;
hassof390d2c2004-09-10 20:48:21 +0000931
jardineb5d44e2003-12-23 08:09:43 +0000932 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +0000933 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
934 {
935 tlv_build_func (*from, lsp->pdu);
936 *to = *from;
937 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +0000938 }
hassof390d2c2004-09-10 20:48:21 +0000939 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
940 {
941 /* fit all we can */
942 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
943 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
944 if (count)
945 count = count / tlvsize;
946 for (i = 0; i < count; i++)
947 {
paul1eb8ef22005-04-07 07:30:20 +0000948 listnode_add (*to, listgetdata (listhead (*from)));
949 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +0000950 }
951 tlv_build_func (*to, lsp->pdu);
952 }
paul9985f832005-02-09 15:51:56 +0000953 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +0000954 return;
955}
956
hasso92365882005-01-18 13:53:33 +0000957static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000958lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
959 int level)
jardineb5d44e2003-12-23 08:09:43 +0000960{
961 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000962 u_char frag_id[ISIS_SYS_ID_LEN + 2];
963
jardineb5d44e2003-12-23 08:09:43 +0000964 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
965 LSP_FRAGMENT (frag_id) = frag_num;
966 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +0000967 if (lsp)
968 {
969 /*
970 * Clear the TLVs, but inherit the authinfo
971 */
972 lsp_clear_data (lsp);
973 if (lsp0->tlv_data.auth_info.type)
974 {
975 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
976 sizeof (struct isis_passwd));
977 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
978 lsp->tlv_data.auth_info.len,
979 lsp->tlv_data.auth_info.passwd, lsp->pdu);
980 }
981 return lsp;
jardineb5d44e2003-12-23 08:09:43 +0000982 }
jardineb5d44e2003-12-23 08:09:43 +0000983 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +0000984 0, level);
jardineb5d44e2003-12-23 08:09:43 +0000985 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +0000986 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +0000987 listnode_add (lsp0->lspu.frags, lsp);
988 lsp->lspu.zero_lsp = lsp0;
989 /*
990 * Copy the authinfo from zero LSP
991 */
hassof390d2c2004-09-10 20:48:21 +0000992 if (lsp0->tlv_data.auth_info.type)
993 {
994 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
995 sizeof (struct isis_passwd));
996 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
997 lsp->tlv_data.auth_info.len,
998 lsp->tlv_data.auth_info.passwd, lsp->pdu);
999 }
jardineb5d44e2003-12-23 08:09:43 +00001000 return lsp;
1001}
1002
1003/*
1004 * Builds the LSP data part. This func creates a new frag whenever
1005 * area->lsp_frag_threshold is exceeded.
1006 */
hasso92365882005-01-18 13:53:33 +00001007static void
jardineb5d44e2003-12-23 08:09:43 +00001008lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1009{
1010 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001011 struct te_is_neigh *te_is_neigh;
hasso3fdb2dd2005-09-28 18:45:54 +00001012 struct listnode *node, *ipnode;
jardineb5d44e2003-12-23 08:09:43 +00001013 int level = lsp->level;
1014 struct isis_circuit *circuit;
1015 struct prefix_ipv4 *ipv4;
1016 struct ipv4_reachability *ipreach;
hassoaa4376e2005-09-26 17:39:48 +00001017 struct te_ipv4_reachability *te_ipreach;
jardineb5d44e2003-12-23 08:09:43 +00001018 struct isis_adjacency *nei;
1019#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001020 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001021 struct ipv6_reachability *ip6reach;
1022#endif /* HAVE_IPV6 */
1023 struct tlvs tlv_data;
1024 struct isis_lsp *lsp0 = lsp;
1025 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001026 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001027
1028 /*
1029 * First add the tlvs related to area
1030 */
hassof390d2c2004-09-10 20:48:21 +00001031
jardineb5d44e2003-12-23 08:09:43 +00001032 /* Area addresses */
1033 if (lsp->tlv_data.area_addrs == NULL)
1034 lsp->tlv_data.area_addrs = list_new ();
1035 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1036 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001037 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001038#ifdef HAVE_IPV6
1039 || area->ipv6_circuits > 0
1040#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001041 )
jardineb5d44e2003-12-23 08:09:43 +00001042 {
hassoaac372f2005-09-01 17:52:33 +00001043 lsp->tlv_data.nlpids = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
jardineb5d44e2003-12-23 08:09:43 +00001044 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001045 if (area->ip_circuits > 0)
1046 {
1047 lsp->tlv_data.nlpids->count++;
1048 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1049 }
jardineb5d44e2003-12-23 08:09:43 +00001050#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001051 if (area->ipv6_circuits > 0)
1052 {
1053 lsp->tlv_data.nlpids->count++;
1054 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1055 NLPID_IPV6;
1056 }
jardineb5d44e2003-12-23 08:09:43 +00001057#endif /* HAVE_IPV6 */
1058 }
1059 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001060 if (area->dynhostname)
1061 {
1062 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1063 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001064
hassof390d2c2004-09-10 20:48:21 +00001065 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1066 strlen (unix_hostname ()));
1067 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1068 }
jardineb5d44e2003-12-23 08:09:43 +00001069
1070 /*
1071 * Building the zero lsp
1072 */
hassoaac372f2005-09-01 17:52:33 +00001073
1074 /* Reset stream endp. Stream is always there and on every LSP refresh only
1075 * TLV part of it is overwritten. So we must seek past header we will not
1076 * touch. */
hassoc89c05d2005-09-04 21:36:36 +00001077 stream_reset (lsp->pdu);
hassoaac372f2005-09-01 17:52:33 +00001078 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1079
jardineb5d44e2003-12-23 08:09:43 +00001080 /*
1081 * Add the authentication info if its present
1082 */
hassof390d2c2004-09-10 20:48:21 +00001083 (level == 1) ? (passwd = &area->area_passwd) :
1084 (passwd = &area->domain_passwd);
1085 if (passwd->type)
1086 {
1087 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1088 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1089 }
jardineb5d44e2003-12-23 08:09:43 +00001090 if (lsp->tlv_data.nlpids)
1091 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1092 if (lsp->tlv_data.hostname)
1093 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001094 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001095 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001096
hasso81ad8f62005-09-26 17:58:24 +00001097 /* IPv4 address and TE router ID TLVs. In case of the first one we don't
1098 * follow "C" vendor, but "J" vendor behavior - one IPv4 address is put into
1099 * LSP and this address is same as router id. */
hasso18a6dce2004-10-03 18:18:34 +00001100 if (router_id_zebra.s_addr != 0)
1101 {
hasso18a6dce2004-10-03 18:18:34 +00001102 if (lsp->tlv_data.ipv4_addrs == NULL)
hassobe7d65d2005-09-02 01:38:16 +00001103 {
1104 lsp->tlv_data.ipv4_addrs = list_new ();
1105 lsp->tlv_data.ipv4_addrs->del = free_tlv;
1106 }
hasso18a6dce2004-10-03 18:18:34 +00001107
1108 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1109 routerid->s_addr = router_id_zebra.s_addr;
hasso18a6dce2004-10-03 18:18:34 +00001110 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
hasso81ad8f62005-09-26 17:58:24 +00001111 tlv_add_in_addr (routerid, lsp->pdu, IPV4_ADDR);
hasso18a6dce2004-10-03 18:18:34 +00001112
hasso81ad8f62005-09-26 17:58:24 +00001113 /* Exactly same data is put into TE router ID TLV, but only if new style
1114 * TLV's are in use. */
1115 if (area->newmetric)
1116 {
1117 lsp->tlv_data.router_id = XMALLOC (MTYPE_ISIS_TLV,
1118 sizeof (struct in_addr));
1119 lsp->tlv_data.router_id->id.s_addr = router_id_zebra.s_addr;
1120 tlv_add_in_addr (&lsp->tlv_data.router_id->id, lsp->pdu, TE_ROUTER_ID);
1121 }
hasso18a6dce2004-10-03 18:18:34 +00001122 }
hassof1082d12005-09-19 04:23:34 +00001123
hasso81ad8f62005-09-26 17:58:24 +00001124 memset (&tlv_data, 0, sizeof (struct tlvs));
1125
hassof1082d12005-09-19 04:23:34 +00001126#ifdef TOPOLOGY_GENERATE
1127 /* If topology exists (and we create topology for level 1 only), create
1128 * (hardcoded) link to topology. */
1129 if (area->topology && level == 1)
1130 {
1131 if (tlv_data.is_neighs == NULL)
hassoaa4376e2005-09-26 17:39:48 +00001132 {
1133 tlv_data.is_neighs = list_new ();
1134 tlv_data.is_neighs->del = free_tlv;
1135 }
hasso3fdb2dd2005-09-28 18:45:54 +00001136 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00001137
1138 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1139 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (1 & 0xFF);
1140 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((1 >> 8) & 0xFF);
1141 is_neigh->metrics.metric_default = 0x01;
1142 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1143 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1144 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1145 listnode_add (tlv_data.is_neighs, is_neigh);
1146 }
1147#endif /* TOPOLOGY_GENERATE */
1148
hasso18a6dce2004-10-03 18:18:34 +00001149 /*
jardineb5d44e2003-12-23 08:09:43 +00001150 * Then build lists of tlvs related to circuits
1151 */
hasso3fdb2dd2005-09-28 18:45:54 +00001152 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
hassof390d2c2004-09-10 20:48:21 +00001153 {
hassof390d2c2004-09-10 20:48:21 +00001154 if (circuit->state != C_STATE_UP)
1155 continue;
jardineb5d44e2003-12-23 08:09:43 +00001156
hassof390d2c2004-09-10 20:48:21 +00001157 /*
1158 * Add IPv4 internal reachability of this circuit
1159 */
1160 if (circuit->ip_router && circuit->ip_addrs &&
1161 circuit->ip_addrs->count > 0)
1162 {
hassoaa4376e2005-09-26 17:39:48 +00001163 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001164 {
hassoaa4376e2005-09-26 17:39:48 +00001165 if (tlv_data.ipv4_int_reachs == NULL)
1166 {
1167 tlv_data.ipv4_int_reachs = list_new ();
1168 tlv_data.ipv4_int_reachs->del = free_tlv;
1169 }
hasso3fdb2dd2005-09-28 18:45:54 +00001170 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001171 {
1172 ipreach =
1173 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1174 ipreach->metrics = circuit->metrics[level - 1];
1175 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1176 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1177 (ipv4->prefix.s_addr));
1178 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1179 }
hassobe7d65d2005-09-02 01:38:16 +00001180 tlv_data.ipv4_int_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001181 }
hassoaa4376e2005-09-26 17:39:48 +00001182 if (area->newmetric)
hassof390d2c2004-09-10 20:48:21 +00001183 {
hassoaa4376e2005-09-26 17:39:48 +00001184 if (tlv_data.te_ipv4_reachs == NULL)
1185 {
1186 tlv_data.te_ipv4_reachs = list_new ();
1187 tlv_data.te_ipv4_reachs->del = free_tlv;
1188 }
hasso3fdb2dd2005-09-28 18:45:54 +00001189 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4))
hassoaa4376e2005-09-26 17:39:48 +00001190 {
1191 /* FIXME All this assumes that we have no sub TLVs. */
1192 te_ipreach = XCALLOC (MTYPE_ISIS_TLV,
1193 sizeof (struct te_ipv4_reachability) +
1194 ((ipv4->prefixlen + 7)/8) - 1);
hasso309ddb12005-09-26 18:06:47 +00001195
1196 if (area->oldmetric)
1197 te_ipreach->te_metric = htonl (circuit->metrics[level - 1].metric_default);
1198 else
1199 te_ipreach->te_metric = htonl (circuit->te_metric[level - 1]);
1200
hassoaa4376e2005-09-26 17:39:48 +00001201 te_ipreach->control = (ipv4->prefixlen & 0x3F);
1202 memcpy (&te_ipreach->prefix_start, &ipv4->prefix.s_addr,
1203 (ipv4->prefixlen + 7)/8);
1204 listnode_add (tlv_data.te_ipv4_reachs, te_ipreach);
1205 }
hassof390d2c2004-09-10 20:48:21 +00001206 }
hassof390d2c2004-09-10 20:48:21 +00001207 }
jardineb5d44e2003-12-23 08:09:43 +00001208#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001209 /*
1210 * Add IPv6 reachability of this circuit
1211 */
1212 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1213 circuit->ipv6_non_link->count > 0)
1214 {
1215
1216 if (tlv_data.ipv6_reachs == NULL)
1217 {
1218 tlv_data.ipv6_reachs = list_new ();
hassobe7d65d2005-09-02 01:38:16 +00001219 tlv_data.ipv6_reachs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001220 }
hasso3fdb2dd2005-09-28 18:45:54 +00001221 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001222 {
hassof390d2c2004-09-10 20:48:21 +00001223 ip6reach =
hassoaac372f2005-09-01 17:52:33 +00001224 XCALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
hasso309ddb12005-09-26 18:06:47 +00001225
1226 if (area->oldmetric)
1227 ip6reach->metric =
1228 htonl (circuit->metrics[level - 1].metric_default);
1229 else
1230 ip6reach->metric = htonl (circuit->te_metric[level - 1]);
1231
hassof390d2c2004-09-10 20:48:21 +00001232 ip6reach->control_info = 0;
1233 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001234 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1235 apply_mask_ipv6 (ip6prefix);
1236 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1237 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001238 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1239 }
1240 }
1241#endif /* HAVE_IPV6 */
1242
1243 switch (circuit->circ_type)
1244 {
1245 case CIRCUIT_T_BROADCAST:
1246 if (level & circuit->circuit_is_type)
1247 {
hassoaa4376e2005-09-26 17:39:48 +00001248 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001249 {
hassoaa4376e2005-09-26 17:39:48 +00001250 if (tlv_data.is_neighs == NULL)
1251 {
1252 tlv_data.is_neighs = list_new ();
1253 tlv_data.is_neighs->del = free_tlv;
1254 }
1255 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1256 if (level == 1)
1257 memcpy (is_neigh->neigh_id,
1258 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1259 else
1260 memcpy (is_neigh->neigh_id,
1261 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1262 is_neigh->metrics = circuit->metrics[level - 1];
1263 listnode_add (tlv_data.is_neighs, is_neigh);
hassobe7d65d2005-09-02 01:38:16 +00001264 tlv_data.is_neighs->del = free_tlv;
hassof390d2c2004-09-10 20:48:21 +00001265 }
hassoaa4376e2005-09-26 17:39:48 +00001266 if (area->newmetric)
1267 {
1268 uint32_t metric;
1269
1270 if (tlv_data.te_is_neighs == NULL)
1271 {
1272 tlv_data.te_is_neighs = list_new ();
1273 tlv_data.te_is_neighs->del = free_tlv;
1274 }
1275 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1276 sizeof (struct te_is_neigh));
1277 if (level == 1)
1278 memcpy (te_is_neigh->neigh_id,
1279 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1280 else
1281 memcpy (te_is_neigh->neigh_id,
1282 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
hasso309ddb12005-09-26 18:06:47 +00001283 if (area->oldmetric)
1284 metric =
1285 ((htonl(circuit->metrics[level - 1].metric_default) >> 8)
1286 & 0xffffff);
1287 else
1288 metric = ((htonl(*circuit->te_metric) >> 8) & 0xffffff);
1289
hassoaa4376e2005-09-26 17:39:48 +00001290 memcpy (te_is_neigh->te_metric, &metric, 3);
1291 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1292 }
hassof390d2c2004-09-10 20:48:21 +00001293 }
1294 break;
1295 case CIRCUIT_T_P2P:
1296 nei = circuit->u.p2p.neighbor;
1297 if (nei && (level & nei->circuit_t))
1298 {
hassoaa4376e2005-09-26 17:39:48 +00001299 if (area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001300 {
hassoaa4376e2005-09-26 17:39:48 +00001301 if (tlv_data.is_neighs == NULL)
1302 {
1303 tlv_data.is_neighs = list_new ();
1304 tlv_data.is_neighs->del = free_tlv;
1305 }
1306 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1307 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1308 is_neigh->metrics = circuit->metrics[level - 1];
1309 listnode_add (tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001310 }
hassoaa4376e2005-09-26 17:39:48 +00001311 if (area->newmetric)
1312 {
1313 uint32_t metric;
1314
1315 if (tlv_data.te_is_neighs == NULL)
1316 {
1317 tlv_data.te_is_neighs = list_new ();
1318 tlv_data.te_is_neighs->del = free_tlv;
1319 }
1320 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1321 sizeof (struct te_is_neigh));
1322 memcpy (te_is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1323 metric = ((htonl(*circuit->te_metric) >> 8) & 0xffffff);
1324 memcpy (te_is_neigh->te_metric, &metric, 3);
1325 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
1326 }
hassof390d2c2004-09-10 20:48:21 +00001327 }
1328 break;
1329 case CIRCUIT_T_STATIC_IN:
1330 zlog_warn ("lsp_area_create: unsupported circuit type");
1331 break;
1332 case CIRCUIT_T_STATIC_OUT:
1333 zlog_warn ("lsp_area_create: unsupported circuit type");
1334 break;
1335 case CIRCUIT_T_DA:
1336 zlog_warn ("lsp_area_create: unsupported circuit type");
1337 break;
1338 default:
1339 zlog_warn ("lsp_area_create: unknown circuit type");
1340 }
1341 }
1342
1343 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1344 {
1345 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1346 lsp->tlv_data.ipv4_int_reachs = list_new ();
1347 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1348 &lsp->tlv_data.ipv4_int_reachs,
1349 IPV4_REACH_LEN, area->lsp_frag_threshold,
1350 tlv_add_ipv4_reachs);
1351 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1352 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1353 lsp0, area, level);
1354 }
hassoaa4376e2005-09-26 17:39:48 +00001355 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1356 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1357 * TLVs (sub TLVs!). */
1358 while (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1359 {
1360 if (lsp->tlv_data.te_ipv4_reachs == NULL)
1361 lsp->tlv_data.te_ipv4_reachs = list_new ();
1362 lsp_tlv_fit (lsp, &tlv_data.te_ipv4_reachs,
1363 &lsp->tlv_data.te_ipv4_reachs,
1364 9, area->lsp_frag_threshold, tlv_add_te_ipv4_reachs);
1365 if (tlv_data.te_ipv4_reachs && listcount (tlv_data.te_ipv4_reachs))
1366 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1367 lsp0, area, level);
1368 }
hassof390d2c2004-09-10 20:48:21 +00001369
1370#ifdef HAVE_IPV6
1371 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1372 {
1373 if (lsp->tlv_data.ipv6_reachs == NULL)
1374 lsp->tlv_data.ipv6_reachs = list_new ();
1375 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1376 &lsp->tlv_data.ipv6_reachs,
1377 IPV6_REACH_LEN, area->lsp_frag_threshold,
1378 tlv_add_ipv6_reachs);
1379 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1380 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1381 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001382 }
1383#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001384
1385 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1386 {
1387 if (lsp->tlv_data.is_neighs == NULL)
1388 lsp->tlv_data.is_neighs = list_new ();
1389 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1390 &lsp->tlv_data.is_neighs,
1391 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1392 tlv_add_is_neighs);
1393 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1394 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1395 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001396 }
jardineb5d44e2003-12-23 08:09:43 +00001397
hassoaa4376e2005-09-26 17:39:48 +00001398 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1399 {
1400 if (lsp->tlv_data.te_is_neighs == NULL)
1401 lsp->tlv_data.te_is_neighs = list_new ();
1402 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
1403 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1404 tlv_add_te_is_neighs);
1405 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
1406 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1407 lsp0, area, level);
1408 }
1409
1410 free_tlvs (&tlv_data);
jardineb5d44e2003-12-23 08:09:43 +00001411 return;
1412}
jardineb5d44e2003-12-23 08:09:43 +00001413
1414/*
1415 * 7.3.7 Generation on non-pseudonode LSPs
1416 */
hasso92365882005-01-18 13:53:33 +00001417static int
hassof390d2c2004-09-10 20:48:21 +00001418lsp_generate_non_pseudo (struct isis_area *area, int level)
1419{
jardineb5d44e2003-12-23 08:09:43 +00001420 struct isis_lsp *oldlsp, *newlsp;
1421 u_int32_t seq_num = 0;
1422 u_char lspid[ISIS_SYS_ID_LEN + 2];
1423
1424 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1425 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1426
1427 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001428 if ((area->is_type & level) == level)
1429 {
1430 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1431 if (oldlsp)
1432 {
1433 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1434 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1435 area->lspdb[level - 1]);
1436 /* FIXME: we should actually initiate a purge */
1437 }
1438 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1439 area->is_type, 0, level);
1440 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001441
hassof390d2c2004-09-10 20:48:21 +00001442 lsp_insert (newlsp, area->lspdb[level - 1]);
1443 /* build_lsp_data (newlsp, area); */
1444 lsp_build_nonpseudo (newlsp, area);
1445 /* time to calculate our checksum */
1446 lsp_seqnum_update (newlsp);
1447 }
jardineb5d44e2003-12-23 08:09:43 +00001448
1449 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001450 if (isis->debugs & DEBUG_ADJ_PACKETS)
1451 {
1452 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +00001453 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001454 }
jardineb5d44e2003-12-23 08:09:43 +00001455
1456 return ISIS_OK;
1457}
1458
1459/*
1460 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1461 */
1462int
1463lsp_l1_generate (struct isis_area *area)
1464{
hassof390d2c2004-09-10 20:48:21 +00001465 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1466 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001467
1468 return lsp_generate_non_pseudo (area, 1);
1469}
1470
jardineb5d44e2003-12-23 08:09:43 +00001471/*
1472 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1473 */
1474int
1475lsp_l2_generate (struct isis_area *area)
1476{
hassof390d2c2004-09-10 20:48:21 +00001477 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1478 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001479
1480 return lsp_generate_non_pseudo (area, 2);
1481}
1482
hasso92365882005-01-18 13:53:33 +00001483static int
jardineb5d44e2003-12-23 08:09:43 +00001484lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1485{
1486 dict_t *lspdb = area->lspdb[level - 1];
1487 struct isis_lsp *lsp, *frag;
1488 struct listnode *node;
1489 u_char lspid[ISIS_SYS_ID_LEN + 2];
1490
1491 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1492 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001493
jardineb5d44e2003-12-23 08:09:43 +00001494 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001495
hassof390d2c2004-09-10 20:48:21 +00001496 if (!lsp)
1497 {
1498 zlog_err
1499 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1500 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001501
hassof390d2c2004-09-10 20:48:21 +00001502 return ISIS_ERROR;
1503 }
1504
1505 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001506 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001507 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1508 (area->max_lsp_lifetime[level - 1],
1509 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001510 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001511
1512 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1513 {
hasso529d65b2004-12-24 00:14:50 +00001514 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1515 "seq 0x%08x, cksum 0x%04x lifetime %us",
1516 area->area_tag,
1517 level,
1518 rawlspid_print (lsp->lsp_header->lsp_id),
1519 ntohl (lsp->lsp_header->seq_num),
1520 ntohs (lsp->lsp_header->checksum),
1521 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001522 }
jardineb5d44e2003-12-23 08:09:43 +00001523
1524 lsp->last_generated = time (NULL);
1525 area->lsp_regenerate_pending[level - 1] = 0;
1526 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
paul1eb8ef22005-04-07 07:30:20 +00001527 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
hassof390d2c2004-09-10 20:48:21 +00001528 {
hassof390d2c2004-09-10 20:48:21 +00001529 frag->lsp_header->rem_lifetime = htons (isis_jitter
1530 (area->
1531 max_lsp_lifetime[level - 1],
1532 MAX_AGE_JITTER));
1533 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1534 }
jardineb5d44e2003-12-23 08:09:43 +00001535
1536 if (area->ip_circuits)
1537 isis_spf_schedule (area, level);
1538#ifdef HAVE_IPV6
1539 if (area->ipv6_circuits)
1540 isis_spf_schedule6 (area, level);
1541#endif
1542 return ISIS_OK;
1543}
1544
jardineb5d44e2003-12-23 08:09:43 +00001545/*
1546 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1547 * time and set SRM
1548 */
hassof390d2c2004-09-10 20:48:21 +00001549int
jardineb5d44e2003-12-23 08:09:43 +00001550lsp_refresh_l1 (struct thread *thread)
1551{
1552 struct isis_area *area;
1553 unsigned long ref_time;
1554
1555 area = THREAD_ARG (thread);
1556 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001557
jardineb5d44e2003-12-23 08:09:43 +00001558 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001559 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001560 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001561
1562 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001563 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1564
hassof390d2c2004-09-10 20:48:21 +00001565 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1566 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001567
jardineb5d44e2003-12-23 08:09:43 +00001568 return ISIS_OK;
1569}
1570
hassof390d2c2004-09-10 20:48:21 +00001571int
jardineb5d44e2003-12-23 08:09:43 +00001572lsp_refresh_l2 (struct thread *thread)
1573{
1574 struct isis_area *area;
1575 unsigned long ref_time;
1576
1577 area = THREAD_ARG (thread);
1578 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001579
jardineb5d44e2003-12-23 08:09:43 +00001580 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001581 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001582 lsp_non_pseudo_regenerate (area, 2);
1583
hassof390d2c2004-09-10 20:48:21 +00001584 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001585 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1586
hassof390d2c2004-09-10 20:48:21 +00001587 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1588 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001589
jardineb5d44e2003-12-23 08:09:43 +00001590 return ISIS_OK;
1591}
1592
jardineb5d44e2003-12-23 08:09:43 +00001593/*
1594 * Something has changed -> regenerate LSP
1595 */
1596
hasso92365882005-01-18 13:53:33 +00001597static int
jardineb5d44e2003-12-23 08:09:43 +00001598lsp_l1_regenerate (struct thread *thread)
1599{
1600 struct isis_area *area;
1601
1602 area = THREAD_ARG (thread);
1603 area->lsp_regenerate_pending[0] = 0;
1604
1605 return lsp_non_pseudo_regenerate (area, 1);
1606}
1607
hasso92365882005-01-18 13:53:33 +00001608static int
jardineb5d44e2003-12-23 08:09:43 +00001609lsp_l2_regenerate (struct thread *thread)
1610{
1611 struct isis_area *area;
1612
1613 area = THREAD_ARG (thread);
1614 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001615
jardineb5d44e2003-12-23 08:09:43 +00001616 return lsp_non_pseudo_regenerate (area, 2);
1617}
1618
hassof390d2c2004-09-10 20:48:21 +00001619int
jardineb5d44e2003-12-23 08:09:43 +00001620lsp_regenerate_schedule (struct isis_area *area)
1621{
1622 struct isis_lsp *lsp;
1623 u_char id[ISIS_SYS_ID_LEN + 2];
1624 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001625 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1626 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001627 now = time (NULL);
1628 /*
1629 * First level 1
1630 */
hassof390d2c2004-09-10 20:48:21 +00001631 if (area->is_type & IS_LEVEL_1)
1632 {
1633 lsp = lsp_search (id, area->lspdb[0]);
1634 if (!lsp || area->lsp_regenerate_pending[0])
1635 goto L2;
1636 /*
1637 * Throttle avoidance
1638 */
1639 diff = now - lsp->last_generated;
1640 if (diff < MIN_LSP_GEN_INTERVAL)
1641 {
1642 area->lsp_regenerate_pending[0] = 1;
1643 thread_add_timer (master, lsp_l1_regenerate, area,
1644 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001645 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001646 }
1647 else
1648 lsp_non_pseudo_regenerate (area, 1);
1649 }
jardineb5d44e2003-12-23 08:09:43 +00001650 /*
1651 * then 2
1652 */
hassof390d2c2004-09-10 20:48:21 +00001653L2:
1654 if (area->is_type & IS_LEVEL_2)
1655 {
1656 lsp = lsp_search (id, area->lspdb[1]);
1657 if (!lsp || area->lsp_regenerate_pending[1])
1658 return ISIS_OK;
1659 /*
1660 * Throttle avoidance
1661 */
1662 diff = now - lsp->last_generated;
1663 if (diff < MIN_LSP_GEN_INTERVAL)
1664 {
1665 area->lsp_regenerate_pending[1] = 1;
1666 thread_add_timer (master, lsp_l2_regenerate, area,
1667 MIN_LSP_GEN_INTERVAL - diff);
1668 return ISIS_OK;
1669 }
1670 else
1671 lsp_non_pseudo_regenerate (area, 2);
1672 }
1673
1674 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001675}
1676
1677/*
1678 * Funcs for pseudonode LSPs
1679 */
1680
1681/*
1682 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1683 */
hasso92365882005-01-18 13:53:33 +00001684static void
hassof390d2c2004-09-10 20:48:21 +00001685lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1686 int level)
jardineb5d44e2003-12-23 08:09:43 +00001687{
1688 struct isis_adjacency *adj;
1689 struct is_neigh *is_neigh;
hassoaa4376e2005-09-26 17:39:48 +00001690 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00001691 struct es_neigh *es_neigh;
1692 struct list *adj_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001693 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00001694 struct isis_passwd *passwd;
1695
1696 assert (circuit);
1697 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001698
jardineb5d44e2003-12-23 08:09:43 +00001699 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001700 return; /* we are not DIS on this circuit */
1701
jardineb5d44e2003-12-23 08:09:43 +00001702 lsp->level = level;
1703 if (level == 1)
1704 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1705 else
1706 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1707
1708 /*
1709 * add self to IS neighbours
1710 */
hassoaa4376e2005-09-26 17:39:48 +00001711 if (circuit->area->oldmetric)
hassof390d2c2004-09-10 20:48:21 +00001712 {
hassoaa4376e2005-09-26 17:39:48 +00001713 if (lsp->tlv_data.is_neighs == NULL)
1714 {
1715 lsp->tlv_data.is_neighs = list_new ();
1716 lsp->tlv_data.is_neighs->del = free_tlv;
1717 }
1718 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001719
hassoaa4376e2005-09-26 17:39:48 +00001720 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1721 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1722 }
1723 if (circuit->area->newmetric)
1724 {
1725 if (lsp->tlv_data.te_is_neighs == NULL)
1726 {
1727 lsp->tlv_data.te_is_neighs = list_new ();
1728 lsp->tlv_data.te_is_neighs->del = free_tlv;
1729 }
1730 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
1731
1732 memcpy (&te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1733 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1734 }
hassof390d2c2004-09-10 20:48:21 +00001735
1736 adj_list = list_new ();
1737 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1738
hasso3fdb2dd2005-09-28 18:45:54 +00001739 for (ALL_LIST_ELEMENTS_RO (adj_list, node, adj))
hassof390d2c2004-09-10 20:48:21 +00001740 {
hassof390d2c2004-09-10 20:48:21 +00001741 if (adj->circuit_t & level)
1742 {
1743 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1744 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
hassoaa4376e2005-09-26 17:39:48 +00001745 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
hassof390d2c2004-09-10 20:48:21 +00001746 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1747 {
1748 /* an IS neighbour -> add it */
hassoaa4376e2005-09-26 17:39:48 +00001749 if (circuit->area->oldmetric)
1750 {
1751 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
paul15935e92005-05-03 09:27:23 +00001752
hassoaa4376e2005-09-26 17:39:48 +00001753 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1754 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1755 }
1756 if (circuit->area->newmetric)
1757 {
1758 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV,
1759 sizeof (struct te_is_neigh));
1760 memcpy (&te_is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1761 listnode_add (lsp->tlv_data.te_is_neighs, te_is_neigh);
1762 }
hassof390d2c2004-09-10 20:48:21 +00001763 }
1764 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1765 {
1766 /* an ES neigbour add it, if we are building level 1 LSP */
1767 /* FIXME: the tlv-format is hard to use here */
1768 if (lsp->tlv_data.es_neighs == NULL)
1769 {
1770 lsp->tlv_data.es_neighs = list_new ();
1771 lsp->tlv_data.es_neighs->del = free_tlv;
1772 }
paul15935e92005-05-03 09:27:23 +00001773 es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1774
hassof390d2c2004-09-10 20:48:21 +00001775 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
hassoaac372f2005-09-01 17:52:33 +00001776 listnode_add (lsp->tlv_data.es_neighs, es_neigh);
hassof390d2c2004-09-10 20:48:21 +00001777 }
1778 }
jardineb5d44e2003-12-23 08:09:43 +00001779 }
hassof390d2c2004-09-10 20:48:21 +00001780
hassoc0fb2a52005-09-03 16:29:40 +00001781 /* Reset endp of stream to overwrite only TLV part of it. */
hassoc89c05d2005-09-04 21:36:36 +00001782 stream_reset (lsp->pdu);
hassoc0fb2a52005-09-03 16:29:40 +00001783 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1784
jardineb5d44e2003-12-23 08:09:43 +00001785 /*
1786 * Add the authentication info if it's present
1787 */
hassof390d2c2004-09-10 20:48:21 +00001788 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1789 (passwd = &circuit->area->domain_passwd);
1790 if (passwd->type)
1791 {
1792 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1793 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1794 }
jardineb5d44e2003-12-23 08:09:43 +00001795
1796 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1797 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1798
hassoaa4376e2005-09-26 17:39:48 +00001799 if (lsp->tlv_data.te_is_neighs && listcount (lsp->tlv_data.te_is_neighs) > 0)
1800 tlv_add_te_is_neighs (lsp->tlv_data.te_is_neighs, lsp->pdu);
1801
jardineb5d44e2003-12-23 08:09:43 +00001802 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1803 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1804
paul9985f832005-02-09 15:51:56 +00001805 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
Jingjing Duan6a270cd2008-08-13 19:09:10 +01001806 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00001807 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1808
jardineb5d44e2003-12-23 08:09:43 +00001809 list_delete (adj_list);
1810
1811 return;
1812}
1813
hasso92365882005-01-18 13:53:33 +00001814static int
jardineb5d44e2003-12-23 08:09:43 +00001815lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1816{
1817 dict_t *lspdb = circuit->area->lspdb[level - 1];
1818 struct isis_lsp *lsp;
1819 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00001820
jardineb5d44e2003-12-23 08:09:43 +00001821 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001822 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1823 LSP_FRAGMENT (lsp_id) = 0;
1824
jardineb5d44e2003-12-23 08:09:43 +00001825 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00001826
1827 if (!lsp)
1828 {
1829 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1830 rawlspid_print (lsp_id));
1831 return ISIS_ERROR;
1832 }
1833 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001834
1835 lsp_build_pseudo (lsp, circuit, level);
1836
hassof390d2c2004-09-10 20:48:21 +00001837 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00001838 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00001839 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001840
1841 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00001842
1843 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1844 {
hasso529d65b2004-12-24 00:14:50 +00001845 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1846 circuit->area->area_tag, level,
1847 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00001848 }
jardineb5d44e2003-12-23 08:09:43 +00001849
1850 lsp->last_generated = time (NULL);
1851 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001852
jardineb5d44e2003-12-23 08:09:43 +00001853 return ISIS_OK;
1854}
1855
jardineb5d44e2003-12-23 08:09:43 +00001856int
1857lsp_l1_refresh_pseudo (struct thread *thread)
1858{
1859 struct isis_circuit *circuit;
1860 int retval;
1861 unsigned long ref_time;
1862
hassof390d2c2004-09-10 20:48:21 +00001863 circuit = THREAD_ARG (thread);
1864
jardineb5d44e2003-12-23 08:09:43 +00001865 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00001866 return ISIS_ERROR; /* FIXME: purge and such */
1867
hasso13c48f72004-09-10 21:19:13 +00001868 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
1869
jardineb5d44e2003-12-23 08:09:43 +00001870 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00001871
1872 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001873 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
1874
hassof390d2c2004-09-10 20:48:21 +00001875 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
1876 lsp_l1_refresh_pseudo, circuit,
1877 isis_jitter (ref_time, MAX_AGE_JITTER));
1878
jardineb5d44e2003-12-23 08:09:43 +00001879 return retval;
1880}
1881
hassof390d2c2004-09-10 20:48:21 +00001882int
jardineb5d44e2003-12-23 08:09:43 +00001883lsp_l1_pseudo_generate (struct isis_circuit *circuit)
1884{
1885 struct isis_lsp *lsp;
1886 u_char id[ISIS_SYS_ID_LEN + 2];
1887 unsigned long ref_time;
1888
hassof390d2c2004-09-10 20:48:21 +00001889 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1890 LSP_FRAGMENT (id) = 0;
1891 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00001892
1893 /*
1894 * If for some reason have a pseudo LSP in the db already -> regenerate
1895 */
1896 if (lsp_search (id, circuit->area->lspdb[0]))
1897 return lsp_pseudo_regenerate (circuit, 1);
1898 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00001899 1, circuit->area->is_type, 0, 1);
1900
jardineb5d44e2003-12-23 08:09:43 +00001901 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00001902
jardineb5d44e2003-12-23 08:09:43 +00001903 lsp->own_lsp = 1;
1904 lsp_insert (lsp, circuit->area->lspdb[0]);
1905 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1906
hassof390d2c2004-09-10 20:48:21 +00001907 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001908 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
1909
hassof390d2c2004-09-10 20:48:21 +00001910 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
1911 lsp_l1_refresh_pseudo, circuit,
1912 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001913
1914 return lsp_regenerate_schedule (circuit->area);
1915}
1916
1917int
1918lsp_l2_refresh_pseudo (struct thread *thread)
1919{
1920 struct isis_circuit *circuit;
1921 int retval;
1922 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00001923 circuit = THREAD_ARG (thread);
1924
jardineb5d44e2003-12-23 08:09:43 +00001925 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00001926 return ISIS_ERROR; /* FIXME: purge and such */
1927
hasso13c48f72004-09-10 21:19:13 +00001928 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
1929
jardineb5d44e2003-12-23 08:09:43 +00001930 retval = lsp_pseudo_regenerate (circuit, 2);
1931
hassof390d2c2004-09-10 20:48:21 +00001932 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001933 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
1934
hassof390d2c2004-09-10 20:48:21 +00001935 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
1936 lsp_l2_refresh_pseudo, circuit,
1937 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001938
jardineb5d44e2003-12-23 08:09:43 +00001939 return retval;
1940}
1941
hassof390d2c2004-09-10 20:48:21 +00001942int
jardineb5d44e2003-12-23 08:09:43 +00001943lsp_l2_pseudo_generate (struct isis_circuit *circuit)
1944{
1945 struct isis_lsp *lsp;
1946 u_char id[ISIS_SYS_ID_LEN + 2];
1947 unsigned long ref_time;
1948
hassof390d2c2004-09-10 20:48:21 +00001949 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1950 LSP_FRAGMENT (id) = 0;
1951 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00001952
1953 if (lsp_search (id, circuit->area->lspdb[1]))
1954 return lsp_pseudo_regenerate (circuit, 2);
1955
1956 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00001957 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00001958
1959 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00001960
1961 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001962 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
1963
1964
1965 lsp->own_lsp = 1;
1966 lsp_insert (lsp, circuit->area->lspdb[1]);
1967 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001968
1969 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
1970 lsp_l2_refresh_pseudo, circuit,
1971 isis_jitter (ref_time, MAX_AGE_JITTER));
1972
jardineb5d44e2003-12-23 08:09:43 +00001973 return lsp_regenerate_schedule (circuit->area);
1974}
1975
jardineb5d44e2003-12-23 08:09:43 +00001976/*
1977 * Walk through LSPs for an area
1978 * - set remaining lifetime
1979 * - set LSPs with SRMflag set for sending
1980 */
hassof390d2c2004-09-10 20:48:21 +00001981int
jardineb5d44e2003-12-23 08:09:43 +00001982lsp_tick (struct thread *thread)
1983{
1984 struct isis_area *area;
1985 struct isis_circuit *circuit;
1986 struct isis_lsp *lsp;
1987 struct list *lsp_list;
hasso3fdb2dd2005-09-28 18:45:54 +00001988 struct listnode *lspnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00001989 dnode_t *dnode, *dnode_next;
1990 int level;
1991
1992 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00001993
jardineb5d44e2003-12-23 08:09:43 +00001994 area = THREAD_ARG (thread);
1995 assert (area);
hasso13c48f72004-09-10 21:19:13 +00001996 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00001997 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00001998
1999 /*
2000 * Build a list of LSPs with (any) SRMflag set
2001 * and removed the ones that have aged out
2002 */
hassof390d2c2004-09-10 20:48:21 +00002003 for (level = 0; level < ISIS_LEVELS; level++)
2004 {
2005 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2006 {
2007 dnode = dict_first (area->lspdb[level]);
2008 while (dnode != NULL)
2009 {
2010 dnode_next = dict_next (area->lspdb[level], dnode);
2011 lsp = dnode_get (dnode);
2012 lsp_set_time (lsp);
2013 if (lsp->age_out == 0)
2014 {
jardineb5d44e2003-12-23 08:09:43 +00002015
hasso529d65b2004-12-24 00:14:50 +00002016 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2017 area->area_tag,
2018 lsp->level,
2019 rawlspid_print (lsp->lsp_header->lsp_id),
2020 ntohl (lsp->lsp_header->seq_num));
hassof1082d12005-09-19 04:23:34 +00002021#ifdef TOPOLOGY_GENERATE
2022 if (lsp->from_topology)
2023 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2024#endif /* TOPOLOGY_GENERATE */
hassof390d2c2004-09-10 20:48:21 +00002025 lsp_destroy (lsp);
2026 dict_delete (area->lspdb[level], dnode);
2027 }
2028 else if (flags_any_set (lsp->SRMflags))
2029 listnode_add (lsp_list, lsp);
2030 dnode = dnode_next;
2031 }
jardineb5d44e2003-12-23 08:09:43 +00002032
hassof390d2c2004-09-10 20:48:21 +00002033 /*
2034 * Send LSPs on circuits indicated by the SRMflags
2035 */
2036 if (listcount (lsp_list) > 0)
2037 {
paul1eb8ef22005-04-07 07:30:20 +00002038 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00002039 {
hasso3fdb2dd2005-09-28 18:45:54 +00002040 for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
hassof390d2c2004-09-10 20:48:21 +00002041 {
hassof390d2c2004-09-10 20:48:21 +00002042 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2043 {
2044 /* FIXME: if same or elder lsp is already in lsp
2045 * queue */
2046 listnode_add (circuit->lsp_queue, lsp);
2047 thread_add_event (master, send_lsp, circuit, 0);
2048 }
2049 }
2050 }
2051 }
2052 list_delete_all_node (lsp_list);
2053 }
jardineb5d44e2003-12-23 08:09:43 +00002054 }
jardineb5d44e2003-12-23 08:09:43 +00002055
2056 list_delete (lsp_list);
2057
2058 return ISIS_OK;
2059}
2060
jardineb5d44e2003-12-23 08:09:43 +00002061void
hassof390d2c2004-09-10 20:48:21 +00002062lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002063{
2064 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002065
jardineb5d44e2003-12-23 08:09:43 +00002066 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002067
2068 if (lsp && lsp->purged == 0)
2069 {
2070 lsp->lsp_header->rem_lifetime = htons (0);
2071 lsp->lsp_header->pdu_len =
2072 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2073 lsp->purged = 0;
Jingjing Duan6a270cd2008-08-13 19:09:10 +01002074 fletcher_checksum (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002075 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2076 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2077 }
2078
jardineb5d44e2003-12-23 08:09:43 +00002079 return;
2080}
2081
2082/*
2083 * Purge own LSP that is received and we don't have.
2084 * -> Do as in 7.3.16.4
2085 */
2086void
hassof390d2c2004-09-10 20:48:21 +00002087lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2088 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002089{
2090 struct isis_lsp *lsp;
2091
2092 /*
2093 * We need to create the LSP to be purged
2094 */
hasso529d65b2004-12-24 00:14:50 +00002095 zlog_debug ("LSP PURGE NON EXIST");
hassoaac372f2005-09-01 17:52:33 +00002096 lsp = XCALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002097 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2098 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002099 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2100 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002101 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002102 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002103 : L2_LINK_STATE);
2104 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2105 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002106 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002107
jardineb5d44e2003-12-23 08:09:43 +00002108 /*
2109 * Retain only LSP header
2110 */
2111 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2112 /*
2113 * Set the remaining lifetime to 0
2114 */
2115 lsp->lsp_header->rem_lifetime = 0;
2116 /*
2117 * Put the lsp into LSPdb
2118 */
hassof390d2c2004-09-10 20:48:21 +00002119 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002120
2121 /*
2122 * Send in to whole area
2123 */
2124 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002125
jardineb5d44e2003-12-23 08:09:43 +00002126 return;
2127}
2128
2129#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002130static int
jardineb5d44e2003-12-23 08:09:43 +00002131top_lsp_refresh (struct thread *thread)
2132{
hassof390d2c2004-09-10 20:48:21 +00002133 struct isis_lsp *lsp;
hassof1082d12005-09-19 04:23:34 +00002134 unsigned long ref_time;
jardineb5d44e2003-12-23 08:09:43 +00002135
2136 lsp = THREAD_ARG (thread);
2137 assert (lsp);
2138
2139 lsp->t_lsp_top_ref = NULL;
2140
hassof1082d12005-09-19 04:23:34 +00002141 lsp_seqnum_update (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002142
2143 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002144 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2145 {
hasso529d65b2004-12-24 00:14:50 +00002146 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2147 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002148 }
hassod3d74742005-09-28 18:30:51 +00002149 /* Refresh dynamic hostname in the cache. */
2150 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
2151 IS_LEVEL_1);
2152
hassof1082d12005-09-19 04:23:34 +00002153 lsp->lsp_header->rem_lifetime =
2154 htons (isis_jitter (lsp->area->max_lsp_lifetime[0], MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002155
hassof1082d12005-09-19 04:23:34 +00002156 ref_time = lsp->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2157 MAX_LSP_GEN_INTERVAL : lsp->area->lsp_refresh[0];
2158
hassof390d2c2004-09-10 20:48:21 +00002159 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
hassof1082d12005-09-19 04:23:34 +00002160 isis_jitter (ref_time, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002161
2162 return ISIS_OK;
2163}
2164
2165void
2166generate_topology_lsps (struct isis_area *area)
2167{
2168 struct listnode *node;
2169 int i, max = 0;
2170 struct arc *arc;
2171 u_char lspid[ISIS_SYS_ID_LEN + 2];
2172 struct isis_lsp *lsp;
hassof1082d12005-09-19 04:23:34 +00002173 unsigned long ref_time;
jardineb5d44e2003-12-23 08:09:43 +00002174
2175 /* first we find the maximal node */
paula8f03df2005-04-10 15:58:10 +00002176 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002177 {
2178 if (arc->from_node > max)
2179 max = arc->from_node;
2180 if (arc->to_node > max)
2181 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002182 }
2183
hassof390d2c2004-09-10 20:48:21 +00002184 for (i = 1; i < (max + 1); i++)
2185 {
2186 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2187 LSP_PSEUDO_ID (lspid) = 0x00;
2188 LSP_FRAGMENT (lspid) = 0x00;
2189 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2190 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002191
hassof390d2c2004-09-10 20:48:21 +00002192 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
hassof1082d12005-09-19 04:23:34 +00002193 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0, 1);
2194 if (!lsp)
2195 return;
hassof390d2c2004-09-10 20:48:21 +00002196 lsp->from_topology = 1;
hassof1082d12005-09-19 04:23:34 +00002197 lsp->area = area;
jardineb5d44e2003-12-23 08:09:43 +00002198
hassof1082d12005-09-19 04:23:34 +00002199 /* Creating LSP data based on topology info. */
2200 build_topology_lsp_data (lsp, area, i);
2201 /* Checksum is also calculated here. */
2202 lsp_seqnum_update (lsp);
hasso9551eea2005-09-28 18:26:25 +00002203 /* Take care of inserting dynamic hostname into cache. */
2204 isis_dynhn_insert (lspid, lsp->tlv_data.hostname, IS_LEVEL_1);
hassof1082d12005-09-19 04:23:34 +00002205
2206 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2207 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
2208
2209 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2210 isis_jitter (ref_time, MAX_LSP_GEN_JITTER));
hassof390d2c2004-09-10 20:48:21 +00002211 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2212 lsp_insert (lsp, area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002213 }
jardineb5d44e2003-12-23 08:09:43 +00002214}
2215
2216void
2217remove_topology_lsps (struct isis_area *area)
2218{
2219 struct isis_lsp *lsp;
2220 dnode_t *dnode, *dnode_next;
2221
2222 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002223 while (dnode != NULL)
2224 {
2225 dnode_next = dict_next (area->lspdb[0], dnode);
2226 lsp = dnode_get (dnode);
2227 if (lsp->from_topology)
2228 {
2229 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2230 lsp_destroy (lsp);
2231 dict_delete (area->lspdb[0], dnode);
2232 }
2233 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002234 }
jardineb5d44e2003-12-23 08:09:43 +00002235}
2236
2237void
hassof390d2c2004-09-10 20:48:21 +00002238build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002239 int lsp_top_num)
2240{
hasso3fdb2dd2005-09-28 18:45:54 +00002241 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +00002242 struct arc *arc;
jardineb5d44e2003-12-23 08:09:43 +00002243 struct is_neigh *is_neigh;
hasso9551eea2005-09-28 18:26:25 +00002244 struct te_is_neigh *te_is_neigh;
jardineb5d44e2003-12-23 08:09:43 +00002245 char buff[200];
hassof1082d12005-09-19 04:23:34 +00002246 struct tlvs tlv_data;
2247 struct isis_lsp *lsp0 = lsp;
jardineb5d44e2003-12-23 08:09:43 +00002248
hassof1082d12005-09-19 04:23:34 +00002249 /* Add area addresses. FIXME: Is it needed at all? */
2250 if (lsp->tlv_data.area_addrs == NULL)
2251 lsp->tlv_data.area_addrs = list_new ();
2252 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
jardineb5d44e2003-12-23 08:09:43 +00002253
hassof1082d12005-09-19 04:23:34 +00002254 if (lsp->tlv_data.nlpids == NULL)
2255 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
2256 lsp->tlv_data.nlpids->count = 1;
2257 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00002258
hassof1082d12005-09-19 04:23:34 +00002259 if (area->dynhostname)
2260 {
2261 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
2262 sizeof (struct hostname));
2263 memset (buff, 0x00, 200);
2264 sprintf (buff, "%s%d", area->topology_basedynh ? area->topology_basedynh :
2265 "feedme", lsp_top_num);
2266 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2267 lsp->tlv_data.hostname->namelen = strlen (buff);
2268 }
2269
2270 if (lsp->tlv_data.nlpids)
2271 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
2272 if (lsp->tlv_data.hostname)
2273 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
2274 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
2275 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
2276
2277 memset (&tlv_data, 0, sizeof (struct tlvs));
2278 if (tlv_data.is_neighs == NULL)
hasso9551eea2005-09-28 18:26:25 +00002279 {
2280 tlv_data.is_neighs = list_new ();
2281 tlv_data.is_neighs->del = free_tlv;
2282 }
hassof1082d12005-09-19 04:23:34 +00002283
2284 /* Add reachability for this IS for simulated 1. */
hassof390d2c2004-09-10 20:48:21 +00002285 if (lsp_top_num == 1)
2286 {
hasso3fdb2dd2005-09-28 18:45:54 +00002287 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002288
hassof390d2c2004-09-10 20:48:21 +00002289 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002290 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof1082d12005-09-19 04:23:34 +00002291 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2292 is_neigh->metrics.metric_default = 0x01;
jardineb5d44e2003-12-23 08:09:43 +00002293 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2294 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2295 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
hassof1082d12005-09-19 04:23:34 +00002296 listnode_add (tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00002297 }
hassof390d2c2004-09-10 20:48:21 +00002298
hassof1082d12005-09-19 04:23:34 +00002299 /* Add IS reachabilities. */
hasso3fdb2dd2005-09-28 18:45:54 +00002300 for (ALL_LIST_ELEMENTS_RO (area->topology, node, arc))
hassof390d2c2004-09-10 20:48:21 +00002301 {
hassof1082d12005-09-19 04:23:34 +00002302 int to_lsp = 0;
2303
2304 if ((lsp_top_num != arc->from_node) && (lsp_top_num != arc->to_node))
2305 continue;
2306
2307 if (lsp_top_num == arc->from_node)
2308 to_lsp = arc->to_node;
2309 else
2310 to_lsp = arc->from_node;
2311
hasso9551eea2005-09-28 18:26:25 +00002312 if (area->oldmetric)
2313 {
2314 is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
hassof1082d12005-09-19 04:23:34 +00002315
hasso9551eea2005-09-28 18:26:25 +00002316 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2317 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2318 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2319 is_neigh->metrics.metric_default = arc->distance;
2320 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2321 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2322 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2323 listnode_add (tlv_data.is_neighs, is_neigh);
2324 }
2325
2326 if (area->newmetric)
2327 {
2328 uint32_t metric;
2329
2330 if (tlv_data.te_is_neighs == NULL)
2331 {
2332 tlv_data.te_is_neighs = list_new ();
2333 tlv_data.te_is_neighs->del = free_tlv;
2334 }
2335 te_is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct te_is_neigh));
2336 memcpy (&te_is_neigh->neigh_id, area->topology_baseis,
2337 ISIS_SYS_ID_LEN);
2338 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2339 te_is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2340 metric = ((htonl(arc->distance) >> 8) & 0xffffff);
2341 memcpy (te_is_neigh->te_metric, &metric, 3);
2342 listnode_add (tlv_data.te_is_neighs, te_is_neigh);
2343 }
hassof390d2c2004-09-10 20:48:21 +00002344 }
hassof1082d12005-09-19 04:23:34 +00002345
2346 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2347 {
2348 if (lsp->tlv_data.is_neighs == NULL)
2349 lsp->tlv_data.is_neighs = list_new ();
hasso9551eea2005-09-28 18:26:25 +00002350 lsp_tlv_fit (lsp, &tlv_data.is_neighs, &lsp->tlv_data.is_neighs,
hassof1082d12005-09-19 04:23:34 +00002351 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2352 tlv_add_is_neighs);
2353 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
2354 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2355 lsp0, area, IS_LEVEL_1);
2356 }
2357
hasso9551eea2005-09-28 18:26:25 +00002358 while (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2359 {
2360 if (lsp->tlv_data.te_is_neighs == NULL)
2361 lsp->tlv_data.te_is_neighs = list_new ();
2362 lsp_tlv_fit (lsp, &tlv_data.te_is_neighs, &lsp->tlv_data.te_is_neighs,
2363 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
2364 tlv_add_te_is_neighs);
2365 if (tlv_data.te_is_neighs && listcount (tlv_data.te_is_neighs))
2366 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
2367 lsp0, area, IS_LEVEL_1);
2368 }
2369
hassof1082d12005-09-19 04:23:34 +00002370 free_tlvs (&tlv_data);
2371 return;
jardineb5d44e2003-12-23 08:09:43 +00002372}
2373#endif /* TOPOLOGY_GENERATE */