blob: 88d4886bcb1d21e54a9d2651d6ae25dceb93813d [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 */
23#include <stdlib.h>
24#include <stdio.h>
25#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000026
27#include "linklist.h"
28#include "thread.h"
29#include "vty.h"
30#include "stream.h"
31#include "memory.h"
32#include "log.h"
33#include "prefix.h"
34#include "command.h"
35#include "hash.h"
36#include "if.h"
37
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"
49#include "isisd/iso_checksum.h"
50#include "isisd/isis_csm.h"
51#include "isisd/isis_adjacency.h"
52#include "isisd/isis_spf.h"
53
54#ifdef TOPOLOGY_GENERATE
55#include "spgrid.h"
56#endif
57
hassof390d2c2004-09-10 20:48:21 +000058#define LSP_MEMORY_PREASSIGN
jardineb5d44e2003-12-23 08:09:43 +000059
60extern struct isis *isis;
61extern struct thread_master *master;
hasso18a6dce2004-10-03 18:18:34 +000062extern struct in_addr router_id_zebra;
jardineb5d44e2003-12-23 08:09:43 +000063
hasso73d1aea2004-09-24 10:45:28 +000064/* staticly assigned vars for printing purposes */
65char lsp_bits_string[200]; /* FIXME: enough ? */
66
hassof390d2c2004-09-10 20:48:21 +000067int
68lsp_id_cmp (u_char * id1, u_char * id2)
69{
jardineb5d44e2003-12-23 08:09:43 +000070 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
71}
72
73dict_t *
hassof390d2c2004-09-10 20:48:21 +000074lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000075{
76 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000077
78 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
79
jardineb5d44e2003-12-23 08:09:43 +000080 return dict;
81}
82
83struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000084lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000085{
86 dnode_t *node;
87
hassof390d2c2004-09-10 20:48:21 +000088#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000089 dnode_t *dn;
90
hasso529d65b2004-12-24 00:14:50 +000091 zlog_debug ("searching db");
hassof390d2c2004-09-10 20:48:21 +000092 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
93 {
hasso529d65b2004-12-24 00:14:50 +000094 zlog_debug ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn)),
95 dnode_get (dn));
hassof390d2c2004-09-10 20:48:21 +000096 }
jardineb5d44e2003-12-23 08:09:43 +000097#endif /* EXTREME DEBUG */
98
99 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000100
jardineb5d44e2003-12-23 08:09:43 +0000101 if (node)
hassof390d2c2004-09-10 20:48:21 +0000102 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000103
104 return NULL;
105}
106
hasso92365882005-01-18 13:53:33 +0000107static void
jardineb5d44e2003-12-23 08:09:43 +0000108lsp_clear_data (struct isis_lsp *lsp)
109{
110 if (!lsp)
111 return;
hassof390d2c2004-09-10 20:48:21 +0000112
113 if (lsp->own_lsp)
114 {
115 if (lsp->tlv_data.nlpids)
116 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
117 if (lsp->tlv_data.hostname)
118 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
119 }
jardineb5d44e2003-12-23 08:09:43 +0000120 if (lsp->tlv_data.is_neighs)
121 list_delete (lsp->tlv_data.is_neighs);
122 if (lsp->tlv_data.area_addrs)
123 list_delete (lsp->tlv_data.area_addrs);
124 if (lsp->tlv_data.es_neighs)
125 list_delete (lsp->tlv_data.es_neighs);
126 if (lsp->tlv_data.ipv4_addrs)
127 list_delete (lsp->tlv_data.ipv4_addrs);
128 if (lsp->tlv_data.ipv4_int_reachs)
129 list_delete (lsp->tlv_data.ipv4_int_reachs);
130 if (lsp->tlv_data.ipv4_ext_reachs)
131 list_delete (lsp->tlv_data.ipv4_ext_reachs);
132#ifdef HAVE_IPV6
133 if (lsp->tlv_data.ipv6_addrs)
134 list_delete (lsp->tlv_data.ipv6_addrs);
135 if (lsp->tlv_data.ipv6_reachs)
136 list_delete (lsp->tlv_data.ipv6_reachs);
137#endif /* HAVE_IPV6 */
138
139 memset (&lsp->tlv_data, 0, sizeof (struct tlvs));
140
141 return;
142}
143
hasso92365882005-01-18 13:53:33 +0000144static void
jardineb5d44e2003-12-23 08:09:43 +0000145lsp_destroy (struct isis_lsp *lsp)
146{
147 if (!lsp)
148 return;
hassof390d2c2004-09-10 20:48:21 +0000149
jardineb5d44e2003-12-23 08:09:43 +0000150 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000151
152 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
153 {
jardineb5d44e2003-12-23 08:09:43 +0000154 list_delete (lsp->lspu.frags);
hassof390d2c2004-09-10 20:48:21 +0000155 }
156
jardineb5d44e2003-12-23 08:09:43 +0000157 if (lsp->pdu)
158 stream_free (lsp->pdu);
159 XFREE (MTYPE_ISIS_LSP, lsp);
160}
161
hassof390d2c2004-09-10 20:48:21 +0000162void
163lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000164{
165 dnode_t *dnode, *next;
166 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000167
jardineb5d44e2003-12-23 08:09:43 +0000168 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000169 while (dnode)
170 {
171 next = dict_next (lspdb, dnode);
172 lsp = dnode_get (dnode);
173 lsp_destroy (lsp);
174 dict_delete_free (lspdb, dnode);
175 dnode = next;
176 }
177
jardineb5d44e2003-12-23 08:09:43 +0000178 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000179
jardineb5d44e2003-12-23 08:09:43 +0000180 return;
181}
182
183/*
184 * Remove all the frags belonging to the given lsp
185 */
hasso92365882005-01-18 13:53:33 +0000186static void
hassof390d2c2004-09-10 20:48:21 +0000187lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000188{
189 dnode_t *dnode;
paul1eb8ef22005-04-07 07:30:20 +0000190 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000191 struct isis_lsp *lsp;
192
paul1eb8ef22005-04-07 07:30:20 +0000193 for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +0000194 {
hassof390d2c2004-09-10 20:48:21 +0000195 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
196 lsp_destroy (lsp);
197 dnode_destroy (dict_delete (lspdb, dnode));
198 }
199
jardineb5d44e2003-12-23 08:09:43 +0000200 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000201
jardineb5d44e2003-12-23 08:09:43 +0000202 return;
203}
204
205void
hassof390d2c2004-09-10 20:48:21 +0000206lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000207{
208 dnode_t *node;
209 struct isis_lsp *lsp;
210
211 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000212 if (node)
213 {
214 node = dict_delete (lspdb, node);
215 lsp = dnode_get (node);
216 /*
217 * If this is a zero lsp, remove all the frags now
218 */
219 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
220 {
221 if (lsp->lspu.frags)
222 lsp_remove_frags (lsp->lspu.frags, lspdb);
223 }
224 else
225 {
226 /*
227 * else just remove this frag, from the zero lsps' frag list
228 */
229 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
230 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
231 }
232 lsp_destroy (lsp);
233 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000234 }
jardineb5d44e2003-12-23 08:09:43 +0000235}
236
237/*
238 * Compares a LSP to given values
239 * Params are given in net order
240 */
hassof390d2c2004-09-10 20:48:21 +0000241int
242lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000243 u_int16_t checksum, u_int16_t rem_lifetime)
244{
hassof390d2c2004-09-10 20:48:21 +0000245 /* no point in double ntohl on seqnum */
246 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000247 lsp->lsp_header->checksum == checksum &&
248 /*comparing with 0, no need to do ntohl */
249 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000250 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
251 {
252 if (isis->debugs & DEBUG_SNP_PACKETS)
253 {
hasso529d65b2004-12-24 00:14:50 +0000254 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
255 " lifetime %us",
256 areatag,
257 rawlspid_print (lsp->lsp_header->lsp_id),
258 ntohl (lsp->lsp_header->seq_num),
259 ntohs (lsp->lsp_header->checksum),
260 ntohs (lsp->lsp_header->rem_lifetime));
261 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
262 " cksum 0x%04x, lifetime %us",
263 areatag,
264 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000265 }
266 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000267 }
jardineb5d44e2003-12-23 08:09:43 +0000268
hassof390d2c2004-09-10 20:48:21 +0000269 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
270 {
271 if (isis->debugs & DEBUG_SNP_PACKETS)
272 {
hasso529d65b2004-12-24 00:14:50 +0000273 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
274 " lifetime %us",
275 areatag,
276 rawlspid_print (lsp->lsp_header->lsp_id),
277 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
278 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
279 "cksum 0x%04x, lifetime %us",
280 areatag,
281 ntohl (lsp->lsp_header->seq_num),
282 ntohs (lsp->lsp_header->checksum),
283 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000284 }
285 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000286 }
hassof390d2c2004-09-10 20:48:21 +0000287 if (isis->debugs & DEBUG_SNP_PACKETS)
288 {
hasso529d65b2004-12-24 00:14:50 +0000289 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000290 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
291 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
292 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000293 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
294 " cksum 0x%04x, lifetime %us", areatag,
295 ntohl (lsp->lsp_header->seq_num),
296 ntohs (lsp->lsp_header->checksum),
297 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000298 }
jardineb5d44e2003-12-23 08:09:43 +0000299
300 return LSP_OLDER;
301}
302
hassof390d2c2004-09-10 20:48:21 +0000303void
jardineb5d44e2003-12-23 08:09:43 +0000304lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
305{
306 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000307
jardineb5d44e2003-12-23 08:09:43 +0000308 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
309 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
310 else
hassof390d2c2004-09-10 20:48:21 +0000311 newseq = seq_num++;
312
jardineb5d44e2003-12-23 08:09:43 +0000313 lsp->lsp_header->seq_num = htonl (newseq);
hassof390d2c2004-09-10 20:48:21 +0000314 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
315 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +0000316
317 return;
318}
319
320/*
321 * Genetates checksum for LSP and its frags
322 */
hasso92365882005-01-18 13:53:33 +0000323static void
jardineb5d44e2003-12-23 08:09:43 +0000324lsp_seqnum_update (struct isis_lsp *lsp0)
325{
326 struct isis_lsp *lsp;
paul1eb8ef22005-04-07 07:30:20 +0000327 struct listnode *node, *nnode;
hassof390d2c2004-09-10 20:48:21 +0000328
jardineb5d44e2003-12-23 08:09:43 +0000329 lsp_inc_seqnum (lsp0, 0);
330
331 if (!lsp0->lspu.frags)
332 return;
333
paul1eb8ef22005-04-07 07:30:20 +0000334 for (ALL_LIST_ELEMENTS (lsp0->lspu.frags, node, nnode, lsp))
335 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +0000336
jardineb5d44e2003-12-23 08:09:43 +0000337 return;
338}
339
hassof390d2c2004-09-10 20:48:21 +0000340int
jardineb5d44e2003-12-23 08:09:43 +0000341isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
hassof390d2c2004-09-10 20:48:21 +0000342 int pdulen, struct isis_passwd *passwd)
jardineb5d44e2003-12-23 08:09:43 +0000343{
344 uint32_t expected = 0, found;
345 struct tlvs tlvs;
346 int retval = 0;
347
348 expected |= TLVFLAG_AUTH_INFO;
349 retval = parse_tlvs (area->area_tag, stream->data +
hassof390d2c2004-09-10 20:48:21 +0000350 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
351 pdulen - ISIS_FIXED_HDR_LEN
352 - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000353 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000354 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000355
356 return authentication_check (passwd, &tlvs.auth_info);
357}
358
hasso92365882005-01-18 13:53:33 +0000359static void
hassof390d2c2004-09-10 20:48:21 +0000360lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
361 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000362{
hassof390d2c2004-09-10 20:48:21 +0000363 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000364 int retval;
hassof390d2c2004-09-10 20:48:21 +0000365
jardineb5d44e2003-12-23 08:09:43 +0000366 /* copying only the relevant part of our stream */
367 lsp->pdu = stream_new (stream->endp);
jardineb5d44e2003-12-23 08:09:43 +0000368 lsp->pdu->getp = stream->getp;
369 lsp->pdu->endp = stream->endp;
370 memcpy (lsp->pdu->data, stream->data, stream->endp);
371
372 /* 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,
hassof390d2c2004-09-10 20:48:21 +0000421 struct stream *stream, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000422{
hassof390d2c2004-09-10 20:48:21 +0000423 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000424 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
425 lsp_clear_data (lsp);
426
427 /* rebuild the lsp data */
428 lsp_update_data (lsp, stream, area);
429
hassof390d2c2004-09-10 20:48:21 +0000430 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000431 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000432}
433
jardineb5d44e2003-12-23 08:09:43 +0000434/* creation of LSP directly from what we received */
435struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000436lsp_new_from_stream_ptr (struct stream *stream,
437 u_int16_t pdu_len, struct isis_lsp *lsp0,
438 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000439{
440 struct isis_lsp *lsp;
441
442 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
443 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000444
jardineb5d44e2003-12-23 08:09:43 +0000445 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000446
447 if (lsp0 == NULL)
448 {
449 /*
450 * zero lsp -> create the list for fragments
451 */
452 lsp->lspu.frags = list_new ();
453 }
454 else
455 {
456 /*
457 * a fragment -> set the backpointer and add this to zero lsps frag list
458 */
459 lsp->lspu.zero_lsp = lsp0;
460 listnode_add (lsp0->lspu.frags, lsp);
461 }
462
jardineb5d44e2003-12-23 08:09:43 +0000463 return lsp;
464}
465
466struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000467lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
468 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000469{
470 struct isis_lsp *lsp;
471
472 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000473 if (!lsp)
474 {
475 /* FIXME: set lspdbol bit */
476 zlog_warn ("lsp_new(): out of memory");
477 return NULL;
478 }
jardineb5d44e2003-12-23 08:09:43 +0000479 memset (lsp, 0, sizeof (struct isis_lsp));
480#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000481 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000482#else
hassof390d2c2004-09-10 20:48:21 +0000483 /* We need to do realloc on TLVs additions */
484 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000485#endif /* LSP_MEMORY_PREASSIGN */
486 if (LSP_FRAGMENT (lsp_id) == 0)
487 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000488 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
489 lsp->lsp_header = (struct isis_link_state_hdr *)
490 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
491
jardineb5d44e2003-12-23 08:09:43 +0000492 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000493 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
494 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
495
jardineb5d44e2003-12-23 08:09:43 +0000496 /* now for the LSP HEADER */
497 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000498 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000499 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000500 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000501 lsp->lsp_header->seq_num = htonl (seq_num);
502 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
503 lsp->lsp_header->lsp_bits = lsp_bits;
504 lsp->level = level;
505 lsp->age_out = ZERO_AGE_LIFETIME;
506
paul9985f832005-02-09 15:51:56 +0000507 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000508
509 /* #ifdef EXTREME_DEBUG */
510 /* logging */
hasso529d65b2004-12-24 00:14:50 +0000511 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
512 LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
513 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
514 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000515 /* #endif EXTREME DEBUG */
516
517 return lsp;
518}
519
520void
hassof390d2c2004-09-10 20:48:21 +0000521lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000522{
523 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
524}
525
526/*
527 * Build a list of LSPs with non-zero ht bounded by start and stop ids
528 */
hassof390d2c2004-09-10 20:48:21 +0000529void
530lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
531 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000532{
533 dnode_t *first, *last, *curr;
534
535 first = dict_lower_bound (lspdb, start_id);
536 if (!first)
537 return;
hassof390d2c2004-09-10 20:48:21 +0000538
jardineb5d44e2003-12-23 08:09:43 +0000539 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000540
jardineb5d44e2003-12-23 08:09:43 +0000541 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000542
543 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000544 listnode_add (list, first->dict_data);
545
hassof390d2c2004-09-10 20:48:21 +0000546 while (curr)
547 {
548 curr = dict_next (lspdb, curr);
549 if (curr &&
550 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
551 listnode_add (list, curr->dict_data);
552 if (curr == last)
553 break;
554 }
555
jardineb5d44e2003-12-23 08:09:43 +0000556 return;
557}
558
559/*
560 * Build a list of all LSPs bounded by start and stop ids
561 */
hassof390d2c2004-09-10 20:48:21 +0000562void
563lsp_build_list (u_char * start_id, u_char * stop_id,
564 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000565{
566 dnode_t *first, *last, *curr;
567
568 first = dict_lower_bound (lspdb, start_id);
569 if (!first)
570 return;
hassof390d2c2004-09-10 20:48:21 +0000571
jardineb5d44e2003-12-23 08:09:43 +0000572 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000573
jardineb5d44e2003-12-23 08:09:43 +0000574 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000575
jardineb5d44e2003-12-23 08:09:43 +0000576 listnode_add (list, first->dict_data);
577
hassof390d2c2004-09-10 20:48:21 +0000578 while (curr)
579 {
580 curr = dict_next (lspdb, curr);
581 if (curr)
582 listnode_add (list, curr->dict_data);
583 if (curr == last)
584 break;
585 }
586
jardineb5d44e2003-12-23 08:09:43 +0000587 return;
588}
589
590/*
591 * Build a list of LSPs with SSN flag set for the given circuit
592 */
593void
hassof390d2c2004-09-10 20:48:21 +0000594lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
595 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000596{
597 dnode_t *dnode, *next;
598 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000599
jardineb5d44e2003-12-23 08:09:43 +0000600 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000601 while (dnode != NULL)
602 {
603 next = dict_next (lspdb, dnode);
604 lsp = dnode_get (dnode);
605 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
606 listnode_add (list, lsp);
607 dnode = next;
608 }
609
jardineb5d44e2003-12-23 08:09:43 +0000610 return;
611}
612
hasso92365882005-01-18 13:53:33 +0000613static void
jardineb5d44e2003-12-23 08:09:43 +0000614lsp_set_time (struct isis_lsp *lsp)
615{
616 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000617
618 if (lsp->lsp_header->rem_lifetime == 0)
619 {
620 if (lsp->age_out != 0)
621 lsp->age_out--;
622 return;
623 }
jardineb5d44e2003-12-23 08:09:43 +0000624
625 /* If we are turning 0 */
626 /* ISO 10589 - 7.3.16.4 first paragraph */
627
hassof390d2c2004-09-10 20:48:21 +0000628 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
629 {
630 /* 7.3.16.4 a) set SRM flags on all */
631 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
632 /* 7.3.16.4 b) retain only the header FIXME */
633 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
634 }
jardineb5d44e2003-12-23 08:09:43 +0000635
hassof390d2c2004-09-10 20:48:21 +0000636 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000637 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
638}
639
hasso92365882005-01-18 13:53:33 +0000640static void
hassof390d2c2004-09-10 20:48:21 +0000641lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000642{
643 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000644 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000645
646 if (dynhost)
647 dyn = dynhn_find_by_id (lsp_id);
648 else
649 dyn = NULL;
650
651 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000652 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000653 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000654 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000655 else
hassof390d2c2004-09-10 20:48:21 +0000656 {
657 memcpy (id, sysid_print (lsp_id), 15);
658 }
659 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000660 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000661 LSP_FRAGMENT (lsp_id));
662 else
hassof7c43dc2004-09-26 16:24:14 +0000663 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000664}
665
hassof390d2c2004-09-10 20:48:21 +0000666/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000667const char *
hassof390d2c2004-09-10 20:48:21 +0000668lsp_bits2string (u_char * lsp_bits)
669{
670 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000671
hassof390d2c2004-09-10 20:48:21 +0000672 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000673 return " none";
674
675 /* we only focus on the default metric */
676 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000677 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000678
679 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000680 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000681
hassof390d2c2004-09-10 20:48:21 +0000682 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
683
jardineb5d44e2003-12-23 08:09:43 +0000684 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000685
hassof390d2c2004-09-10 20:48:21 +0000686 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000687}
688
689/* this function prints the lsp on show isis database */
hasso92365882005-01-18 13:53:33 +0000690static void
hassof390d2c2004-09-10 20:48:21 +0000691lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000692{
hassof390d2c2004-09-10 20:48:21 +0000693 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000694 u_char LSPid[255];
695
696 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000697 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
698 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
699 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000700
hassof390d2c2004-09-10 20:48:21 +0000701 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
702 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000703 else
hassof390d2c2004-09-10 20:48:21 +0000704 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000705
706 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000707 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000708}
709
hasso92365882005-01-18 13:53:33 +0000710static void
hassof390d2c2004-09-10 20:48:21 +0000711lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000712{
713 struct isis_lsp *lsp = dnode_get (node);
714 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000715 int i;
paul1eb8ef22005-04-07 07:30:20 +0000716 struct listnode *lnode, *lnnode;
jardineb5d44e2003-12-23 08:09:43 +0000717 struct is_neigh *is_neigh;
718 struct te_is_neigh *te_is_neigh;
719 struct ipv4_reachability *ipv4_reach;
720 struct in_addr *ipv4_addr;
721 struct te_ipv4_reachability *te_ipv4_reach;
722#ifdef HAVE_IPV6
723 struct ipv6_reachability *ipv6_reach;
724 struct in6_addr in6;
725#endif
726 u_char LSPid[255];
727 u_char hostname[255];
728 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000729 u_char ipv4_reach_prefix[20];
730 u_char ipv4_reach_mask[20];
731 u_char ipv4_address[20];
732
733 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000734 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000735
736 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000737 if (lsp->tlv_data.area_addrs)
paul1eb8ef22005-04-07 07:30:20 +0000738 for (ALL_LIST_ELEMENTS (lsp->tlv_data.area_addrs, lnode,
739 lnnode, area_addr))
hassof390d2c2004-09-10 20:48:21 +0000740 {
hasso1cd80842004-10-07 20:07:40 +0000741 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000742 isonet_print (area_addr->area_addr, area_addr->addr_len),
743 VTY_NEWLINE);
744 }
paul1eb8ef22005-04-07 07:30:20 +0000745
jardineb5d44e2003-12-23 08:09:43 +0000746 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000747 if (lsp->tlv_data.nlpids)
748 {
749 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
750 {
751 switch (lsp->tlv_data.nlpids->nlpids[i])
752 {
753 case NLPID_IP:
754 case NLPID_IPV6:
hasso1cd80842004-10-07 20:07:40 +0000755 vty_out (vty, " NLPID: 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000756 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
757 break;
758 default:
hasso1cd80842004-10-07 20:07:40 +0000759 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000760 break;
761 }
762 }
763 }
jardineb5d44e2003-12-23 08:09:43 +0000764
765 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000766 if (lsp->tlv_data.hostname)
767 {
768 bzero (hostname, sizeof (hostname));
769 memcpy (hostname, lsp->tlv_data.hostname->name,
770 lsp->tlv_data.hostname->namelen);
771 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000772 }
hassof390d2c2004-09-10 20:48:21 +0000773
774 if (lsp->tlv_data.ipv4_addrs)
paul1eb8ef22005-04-07 07:30:20 +0000775 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_addrs, lnode,
776 lnnode, ipv4_addr))
hassof390d2c2004-09-10 20:48:21 +0000777 {
778 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
779 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
780 }
hassof390d2c2004-09-10 20:48:21 +0000781
hasso1cd80842004-10-07 20:07:40 +0000782 /* TE router id */
783 if (lsp->tlv_data.router_id)
784 {
785 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
786 sizeof (ipv4_address));
787 vty_out (vty, " Router ID: %s%s", ipv4_address, VTY_NEWLINE);
788 }
789
790 /* for the IS neighbor tlv */
791 if (lsp->tlv_data.is_neighs)
paul1eb8ef22005-04-07 07:30:20 +0000792 for (ALL_LIST_ELEMENTS (lsp->tlv_data.is_neighs, lnode, lnnode, is_neigh))
hasso1cd80842004-10-07 20:07:40 +0000793 {
794 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
795 vty_out (vty, " Metric: %d IS %s%s",
796 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
797 }
hasso1cd80842004-10-07 20:07:40 +0000798
jardineb5d44e2003-12-23 08:09:43 +0000799 /* for the internal reachable tlv */
800 if (lsp->tlv_data.ipv4_int_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000801 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_int_reachs, lnode,
802 lnnode, ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000803 {
804 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
805 sizeof (ipv4_reach_prefix));
806 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
807 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000808 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000809 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
810 ipv4_reach_mask, VTY_NEWLINE);
811 }
hasso2097cd82003-12-23 11:51:08 +0000812
813 /* for the external reachable tlv */
814 if (lsp->tlv_data.ipv4_ext_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000815 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_ext_reachs, lnode,
816 lnnode, ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000817 {
818 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
819 sizeof (ipv4_reach_prefix));
820 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
821 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000822 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000823 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
824 ipv4_reach_mask, VTY_NEWLINE);
825 }
paul1eb8ef22005-04-07 07:30:20 +0000826
hasso2097cd82003-12-23 11:51:08 +0000827 /* IPv6 tlv */
828#ifdef HAVE_IPV6
829 if (lsp->tlv_data.ipv6_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000830 for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv6_reachs, lnode,
831 lnnode, ipv6_reach))
hassof390d2c2004-09-10 20:48:21 +0000832 {
833 memset (&in6, 0, sizeof (in6));
834 memcpy (in6.s6_addr, ipv6_reach->prefix,
835 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000836 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000837 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000838 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
839 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
840 ntohl (ipv6_reach->metric),
841 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000842 else
hassof390d2c2004-09-10 20:48:21 +0000843 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
844 ntohl (ipv6_reach->metric),
845 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000846 }
847#endif
paul1eb8ef22005-04-07 07:30:20 +0000848
hasso1cd80842004-10-07 20:07:40 +0000849 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000850 if (lsp->tlv_data.te_is_neighs)
paul1eb8ef22005-04-07 07:30:20 +0000851 for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_is_neighs, lnode,
852 lnnode, te_is_neigh))
hassof390d2c2004-09-10 20:48:21 +0000853 {
hasso1cd80842004-10-07 20:07:40 +0000854 /* FIXME: metric display is wrong. */
hassof390d2c2004-09-10 20:48:21 +0000855 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
hasso1cd80842004-10-07 20:07:40 +0000856 vty_out (vty, " Metric: %d extd-IS %s%s",
857 te_is_neigh->te_metric[0], LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000858 }
jardineb5d44e2003-12-23 08:09:43 +0000859
hasso1cd80842004-10-07 20:07:40 +0000860 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000861 if (lsp->tlv_data.te_ipv4_reachs)
paul1eb8ef22005-04-07 07:30:20 +0000862 for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_ipv4_reachs, lnode,
863 lnnode, te_ipv4_reach))
hassof390d2c2004-09-10 20:48:21 +0000864 {
hasso1cd80842004-10-07 20:07:40 +0000865 /* FIXME: There should be better way to output this stuff. */
hasso2e864cf2004-10-08 06:40:24 +0000866 vty_out (vty, " Metric: %d extd-IP %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000867 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000868 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
869 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000870 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000871 }
jardineb5d44e2003-12-23 08:09:43 +0000872
hassof390d2c2004-09-10 20:48:21 +0000873 return;
jardineb5d44e2003-12-23 08:09:43 +0000874}
875
876/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000877int
878lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000879{
880
hassof390d2c2004-09-10 20:48:21 +0000881 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000882 int lsp_count = 0;
883
884 /* print the title, for both modes */
885 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000886 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
887
888 if (detail == ISIS_UI_LEVEL_BRIEF)
889 {
890 while (node != NULL)
891 {
892 /* I think it is unnecessary, so I comment it out */
893 /* dict_contains (lspdb, node); */
894 next = dict_next (lspdb, node);
895 lsp_print (node, vty, dynhost);
896 node = next;
897 lsp_count++;
898 }
jardineb5d44e2003-12-23 08:09:43 +0000899 }
hassof390d2c2004-09-10 20:48:21 +0000900 else if (detail == ISIS_UI_LEVEL_DETAIL)
901 {
902 while (node != NULL)
903 {
904 next = dict_next (lspdb, node);
905 lsp_print_detail (node, vty, dynhost);
906 node = next;
907 lsp_count++;
908 }
jardineb5d44e2003-12-23 08:09:43 +0000909 }
jardineb5d44e2003-12-23 08:09:43 +0000910
911 return lsp_count;
912}
913
914/* this function reallocate memory to an lsp pdu, with an additional
915 * size of memory, it scans the lsp and moves all pointers the
916 * way they should */
hasso92365882005-01-18 13:53:33 +0000917static u_char *
hassof390d2c2004-09-10 20:48:21 +0000918lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +0000919{
920 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +0000921
922 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000923#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000924 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +0000925 return retval;
hassof390d2c2004-09-10 20:48:21 +0000926#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +0000927 u_char *newpdu;
928 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassof390d2c2004-09-10 20:48:21 +0000929 memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu),
930 ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +0000931 XFREE (memorytype, lsp->pdu);
932 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +0000933 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
934 lsp->lsp_header = (struct isis_link_state_hdr *)
935 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000936 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +0000937 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +0000938#endif /* LSP_MEMORY_PREASSIGN */
939}
940
hassof390d2c2004-09-10 20:48:21 +0000941#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +0000942/*
943 * Builds the lsp->tlv_data
944 * and writes the tlvs into lsp->pdu
945 */
946void
947lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
948{
949 struct is_neigh *is_neigh;
paul1eb8ef22005-04-07 07:30:20 +0000950 struct listnode *node, *nnode, *ipnode, *ipnnode;
jardineb5d44e2003-12-23 08:09:43 +0000951 int level = lsp->level;
952 struct isis_circuit *circuit;
953 struct prefix_ipv4 *ipv4;
954 struct ipv4_reachability *ipreach;
955 struct isis_adjacency *nei;
956#ifdef HAVE_IPV6
957 struct prefix_ipv6 *ipv6;
958 struct ipv6_reachability *ip6reach;
959#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000960
jardineb5d44e2003-12-23 08:09:43 +0000961 /*
962 * First add the tlvs related to area
963 */
hassof390d2c2004-09-10 20:48:21 +0000964
jardineb5d44e2003-12-23 08:09:43 +0000965 /* Area addresses */
966 if (lsp->tlv_data.area_addrs == NULL)
967 lsp->tlv_data.area_addrs = list_new ();
968 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
969 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +0000970 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +0000971#ifdef HAVE_IPV6
972 || area->ipv6_circuits > 0
973#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000974 )
jardineb5d44e2003-12-23 08:09:43 +0000975 {
976 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
977 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +0000978 if (area->ip_circuits > 0)
979 {
980 lsp->tlv_data.nlpids->count++;
981 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
982 }
jardineb5d44e2003-12-23 08:09:43 +0000983#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000984 if (area->ipv6_circuits > 0)
985 {
986 lsp->tlv_data.nlpids->count++;
987 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
988 NLPID_IPV6;
989 }
jardineb5d44e2003-12-23 08:09:43 +0000990#endif /* HAVE_IPV6 */
991 }
992 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +0000993 if (area->dynhostname)
994 {
995 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
996 sizeof (struct hostname));
997 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
998 strlen (unix_hostname ()));
999 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1000 }
jardineb5d44e2003-12-23 08:09:43 +00001001#ifdef TOPOLOGY_GENERATE
1002 /*
1003 * If we have a topology in this area, we need to connect this lsp to
1004 * the first topology lsp
1005 */
hassof390d2c2004-09-10 20:48:21 +00001006 if ((area->topology) && (level == 1))
1007 {
1008 if (lsp->tlv_data.is_neighs == NULL)
1009 lsp->tlv_data.is_neighs = list_new ();
1010 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1011 memset (is_neigh, 0, sizeof (struct is_neigh));
1012 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1013 /* connected to the first */
1014 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1015 /* this is actually the same system, why mess the SPT */
1016 is_neigh->metrics.metric_default = 0;
1017 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1018 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1019 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1020 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001021
hassof390d2c2004-09-10 20:48:21 +00001022 }
jardineb5d44e2003-12-23 08:09:43 +00001023#endif
1024
1025 /*
1026 * Then add tlvs related to circuits
1027 */
paul1eb8ef22005-04-07 07:30:20 +00001028 for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00001029 {
hassof390d2c2004-09-10 20:48:21 +00001030 if (circuit->state != C_STATE_UP)
1031 continue;
1032
1033 /*
1034 * Add IPv4 internal reachability of this circuit
1035 */
1036 if (circuit->ip_router && circuit->ip_addrs &&
1037 circuit->ip_addrs->count > 0)
1038 {
1039 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1040 {
1041 lsp->tlv_data.ipv4_int_reachs = list_new ();
1042 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1043 }
paul1eb8ef22005-04-07 07:30:20 +00001044 for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4))
hassof390d2c2004-09-10 20:48:21 +00001045 {
hassof390d2c2004-09-10 20:48:21 +00001046 ipreach =
1047 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1048 ipreach->metrics = circuit->metrics[level - 1];
1049 ipreach->prefix = ipv4->prefix;
1050 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1051 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1052 }
1053 }
jardineb5d44e2003-12-23 08:09:43 +00001054#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001055 /*
1056 * Add IPv6 reachability of this circuit
1057 */
1058 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1059 circuit->ipv6_non_link->count > 0)
1060 {
1061 if (lsp->tlv_data.ipv6_reachs == NULL)
1062 {
1063 lsp->tlv_data.ipv6_reachs = list_new ();
1064 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1065 }
paul1eb8ef22005-04-07 07:30:20 +00001066 for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode,
1067 ipnnode, ipv6))
hassof390d2c2004-09-10 20:48:21 +00001068 {
hassof390d2c2004-09-10 20:48:21 +00001069 ip6reach =
1070 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1071 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1072 ip6reach->metric =
1073 htonl (circuit->metrics[level - 1].metric_default);
1074 ip6reach->control_info = 0;
1075 ip6reach->prefix_len = ipv6->prefixlen;
1076 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1077 (ipv6->prefixlen + 7) / 8);
1078 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1079 }
1080 }
jardineb5d44e2003-12-23 08:09:43 +00001081#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001082
1083 switch (circuit->circ_type)
1084 {
1085 case CIRCUIT_T_BROADCAST:
1086 if (level & circuit->circuit_is_type)
1087 {
1088 if (lsp->tlv_data.is_neighs == NULL)
1089 {
1090 lsp->tlv_data.is_neighs = list_new ();
1091 lsp->tlv_data.is_neighs->del = free_tlv;
1092 }
1093 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1094 memset (is_neigh, 0, sizeof (struct is_neigh));
1095 if (level == 1)
1096 memcpy (&is_neigh->neigh_id,
1097 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1098 else
1099 memcpy (&is_neigh->neigh_id,
1100 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1101 is_neigh->metrics = circuit->metrics[level - 1];
1102 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1103 }
1104 break;
1105 case CIRCUIT_T_P2P:
1106 nei = circuit->u.p2p.neighbor;
1107 if (nei && (level & nei->circuit_t))
1108 {
1109 if (lsp->tlv_data.is_neighs == NULL)
1110 {
1111 lsp->tlv_data.is_neighs = list_new ();
1112 lsp->tlv_data.is_neighs->del = free_tlv;
1113 }
1114 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1115 memset (is_neigh, 0, sizeof (struct is_neigh));
1116 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1117 is_neigh->metrics = circuit->metrics[level - 1];
1118 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1119 }
1120 break;
1121 case CIRCUIT_T_STATIC_IN:
1122 zlog_warn ("lsp_area_create: unsupported circuit type");
1123 break;
1124 case CIRCUIT_T_STATIC_OUT:
1125 zlog_warn ("lsp_area_create: unsupported circuit type");
1126 break;
1127 case CIRCUIT_T_DA:
1128 zlog_warn ("lsp_area_create: unsupported circuit type");
1129 break;
1130 default:
1131 zlog_warn ("lsp_area_create: unknown circuit type");
1132 }
jardineb5d44e2003-12-23 08:09:43 +00001133 }
hassof390d2c2004-09-10 20:48:21 +00001134
paul9985f832005-02-09 15:51:56 +00001135 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00001136
jardineb5d44e2003-12-23 08:09:43 +00001137 if (lsp->tlv_data.nlpids)
1138 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1139 if (lsp->tlv_data.hostname)
1140 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001141 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001142 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1143 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1144 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001145 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001146 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1147 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001148#ifdef HAVE_IPV6
1149 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001150 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1151#endif /* HAVE_IPV6 */
1152
paul9985f832005-02-09 15:51:56 +00001153 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001154
1155 return;
1156}
1157#endif
1158
1159#define FRAG_THOLD(S,T) \
1160((STREAM_SIZE(S)*T)/100)
1161
1162/* stream*, area->lsp_frag_threshold, increment */
1163#define FRAG_NEEDED(S,T,I) \
1164 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1165
hasso92365882005-01-18 13:53:33 +00001166static void
jardineb5d44e2003-12-23 08:09:43 +00001167lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001168 int tlvsize, int frag_thold,
1169 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001170{
1171 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001172
jardineb5d44e2003-12-23 08:09:43 +00001173 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001174 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1175 {
1176 tlv_build_func (*from, lsp->pdu);
1177 *to = *from;
1178 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001179 }
hassof390d2c2004-09-10 20:48:21 +00001180 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1181 {
1182 /* fit all we can */
1183 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1184 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1185 if (count)
1186 count = count / tlvsize;
1187 for (i = 0; i < count; i++)
1188 {
paul1eb8ef22005-04-07 07:30:20 +00001189 listnode_add (*to, listgetdata (listhead (*from)));
1190 listnode_delete (*from, listgetdata (listhead (*from)));
hassof390d2c2004-09-10 20:48:21 +00001191 }
1192 tlv_build_func (*to, lsp->pdu);
1193 }
paul9985f832005-02-09 15:51:56 +00001194 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001195 return;
1196}
1197
hasso92365882005-01-18 13:53:33 +00001198static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001199lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1200 int level)
jardineb5d44e2003-12-23 08:09:43 +00001201{
1202 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001203 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1204
jardineb5d44e2003-12-23 08:09:43 +00001205 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1206 LSP_FRAGMENT (frag_id) = frag_num;
1207 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001208 if (lsp)
1209 {
1210 /*
1211 * Clear the TLVs, but inherit the authinfo
1212 */
1213 lsp_clear_data (lsp);
1214 if (lsp0->tlv_data.auth_info.type)
1215 {
1216 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1217 sizeof (struct isis_passwd));
1218 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1219 lsp->tlv_data.auth_info.len,
1220 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1221 }
1222 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001223 }
jardineb5d44e2003-12-23 08:09:43 +00001224 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001225 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001226 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001227 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001228 listnode_add (lsp0->lspu.frags, lsp);
1229 lsp->lspu.zero_lsp = lsp0;
1230 /*
1231 * Copy the authinfo from zero LSP
1232 */
hassof390d2c2004-09-10 20:48:21 +00001233 if (lsp0->tlv_data.auth_info.type)
1234 {
1235 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1236 sizeof (struct isis_passwd));
1237 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1238 lsp->tlv_data.auth_info.len,
1239 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1240 }
jardineb5d44e2003-12-23 08:09:43 +00001241 return lsp;
1242}
1243
1244/*
1245 * Builds the LSP data part. This func creates a new frag whenever
1246 * area->lsp_frag_threshold is exceeded.
1247 */
1248#if 1
hasso92365882005-01-18 13:53:33 +00001249static void
jardineb5d44e2003-12-23 08:09:43 +00001250lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1251{
1252 struct is_neigh *is_neigh;
paul1eb8ef22005-04-07 07:30:20 +00001253 struct listnode *node, *nnode, *ipnode, *ipnnode;
jardineb5d44e2003-12-23 08:09:43 +00001254 int level = lsp->level;
1255 struct isis_circuit *circuit;
1256 struct prefix_ipv4 *ipv4;
1257 struct ipv4_reachability *ipreach;
1258 struct isis_adjacency *nei;
1259#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001260 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001261 struct ipv6_reachability *ip6reach;
1262#endif /* HAVE_IPV6 */
1263 struct tlvs tlv_data;
1264 struct isis_lsp *lsp0 = lsp;
1265 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001266 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001267
1268 /*
1269 * First add the tlvs related to area
1270 */
hassof390d2c2004-09-10 20:48:21 +00001271
jardineb5d44e2003-12-23 08:09:43 +00001272 /* Area addresses */
1273 if (lsp->tlv_data.area_addrs == NULL)
1274 lsp->tlv_data.area_addrs = list_new ();
1275 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1276 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001277 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001278#ifdef HAVE_IPV6
1279 || area->ipv6_circuits > 0
1280#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001281 )
jardineb5d44e2003-12-23 08:09:43 +00001282 {
1283 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1284 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001285 if (area->ip_circuits > 0)
1286 {
1287 lsp->tlv_data.nlpids->count++;
1288 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1289 }
jardineb5d44e2003-12-23 08:09:43 +00001290#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001291 if (area->ipv6_circuits > 0)
1292 {
1293 lsp->tlv_data.nlpids->count++;
1294 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1295 NLPID_IPV6;
1296 }
jardineb5d44e2003-12-23 08:09:43 +00001297#endif /* HAVE_IPV6 */
1298 }
1299 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001300 if (area->dynhostname)
1301 {
1302 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1303 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001304
hassof390d2c2004-09-10 20:48:21 +00001305 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1306 strlen (unix_hostname ()));
1307 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1308 }
jardineb5d44e2003-12-23 08:09:43 +00001309
1310 /*
1311 * Building the zero lsp
1312 */
paul9985f832005-02-09 15:51:56 +00001313 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001314 /*
1315 * Add the authentication info if its present
1316 */
hassof390d2c2004-09-10 20:48:21 +00001317 (level == 1) ? (passwd = &area->area_passwd) :
1318 (passwd = &area->domain_passwd);
1319 if (passwd->type)
1320 {
1321 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1322 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1323 }
jardineb5d44e2003-12-23 08:09:43 +00001324 if (lsp->tlv_data.nlpids)
1325 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1326 if (lsp->tlv_data.hostname)
1327 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001328 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001329 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001330
jardineb5d44e2003-12-23 08:09:43 +00001331 memset (&tlv_data, 0, sizeof (struct tlvs));
1332 /*
hasso18a6dce2004-10-03 18:18:34 +00001333 * IPv4 address TLV. We don't follow "C" vendor, but "J" vendor behavior -
1334 * one IPv4 address is put into LSP and this address is same as router id.
1335 */
1336 if (router_id_zebra.s_addr != 0)
1337 {
hasso18a6dce2004-10-03 18:18:34 +00001338 if (lsp->tlv_data.ipv4_addrs == NULL)
1339 lsp->tlv_data.ipv4_addrs = list_new ();
1340
1341 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1342 routerid->s_addr = router_id_zebra.s_addr;
1343
1344 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
1345
1346 /*
1347 * FIXME: Using add_tlv() directly is hack, but tlv_add_ip_addrs()
1348 * expects list of prefix_ipv4 structures, but we have list of
1349 * in_addr structures.
1350 */
1351 add_tlv (IPV4_ADDR, IPV4_MAX_BYTELEN, (u_char *) &routerid->s_addr,
1352 lsp->pdu);
1353 }
1354 /*
jardineb5d44e2003-12-23 08:09:43 +00001355 * Then build lists of tlvs related to circuits
1356 */
paul1eb8ef22005-04-07 07:30:20 +00001357 for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00001358 {
hassof390d2c2004-09-10 20:48:21 +00001359 if (circuit->state != C_STATE_UP)
1360 continue;
jardineb5d44e2003-12-23 08:09:43 +00001361
hassof390d2c2004-09-10 20:48:21 +00001362 /*
1363 * Add IPv4 internal reachability of this circuit
1364 */
1365 if (circuit->ip_router && circuit->ip_addrs &&
1366 circuit->ip_addrs->count > 0)
1367 {
1368 if (tlv_data.ipv4_int_reachs == NULL)
1369 {
1370 tlv_data.ipv4_int_reachs = list_new ();
1371 }
paul1eb8ef22005-04-07 07:30:20 +00001372 for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4))
hassof390d2c2004-09-10 20:48:21 +00001373 {
hassof390d2c2004-09-10 20:48:21 +00001374 ipreach =
1375 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1376 ipreach->metrics = circuit->metrics[level - 1];
hassof390d2c2004-09-10 20:48:21 +00001377 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001378 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1379 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001380 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1381 }
1382
1383 }
jardineb5d44e2003-12-23 08:09:43 +00001384#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001385 /*
1386 * Add IPv6 reachability of this circuit
1387 */
1388 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1389 circuit->ipv6_non_link->count > 0)
1390 {
1391
1392 if (tlv_data.ipv6_reachs == NULL)
1393 {
1394 tlv_data.ipv6_reachs = list_new ();
1395 }
paul1eb8ef22005-04-07 07:30:20 +00001396 for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode, ipnnode,
1397 ipv6))
hassof390d2c2004-09-10 20:48:21 +00001398 {
hassof390d2c2004-09-10 20:48:21 +00001399 ip6reach =
1400 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1401 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1402 ip6reach->metric =
1403 htonl (circuit->metrics[level - 1].metric_default);
1404 ip6reach->control_info = 0;
1405 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001406 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1407 apply_mask_ipv6 (ip6prefix);
1408 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1409 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001410 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1411 }
1412 }
1413#endif /* HAVE_IPV6 */
1414
1415 switch (circuit->circ_type)
1416 {
1417 case CIRCUIT_T_BROADCAST:
1418 if (level & circuit->circuit_is_type)
1419 {
1420 if (tlv_data.is_neighs == NULL)
1421 {
1422 tlv_data.is_neighs = list_new ();
1423 }
1424 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1425 memset (is_neigh, 0, sizeof (struct is_neigh));
1426 if (level == 1)
1427 memcpy (is_neigh->neigh_id,
1428 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1429 else
1430 memcpy (is_neigh->neigh_id,
1431 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1432 is_neigh->metrics = circuit->metrics[level - 1];
1433 listnode_add (tlv_data.is_neighs, is_neigh);
1434 }
1435 break;
1436 case CIRCUIT_T_P2P:
1437 nei = circuit->u.p2p.neighbor;
1438 if (nei && (level & nei->circuit_t))
1439 {
1440 if (tlv_data.is_neighs == NULL)
1441 {
1442 tlv_data.is_neighs = list_new ();
1443 tlv_data.is_neighs->del = free_tlv;
1444 }
1445 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1446 memset (is_neigh, 0, sizeof (struct is_neigh));
1447 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1448 is_neigh->metrics = circuit->metrics[level - 1];
1449 listnode_add (tlv_data.is_neighs, is_neigh);
1450 }
1451 break;
1452 case CIRCUIT_T_STATIC_IN:
1453 zlog_warn ("lsp_area_create: unsupported circuit type");
1454 break;
1455 case CIRCUIT_T_STATIC_OUT:
1456 zlog_warn ("lsp_area_create: unsupported circuit type");
1457 break;
1458 case CIRCUIT_T_DA:
1459 zlog_warn ("lsp_area_create: unsupported circuit type");
1460 break;
1461 default:
1462 zlog_warn ("lsp_area_create: unknown circuit type");
1463 }
1464 }
1465
1466 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1467 {
1468 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1469 lsp->tlv_data.ipv4_int_reachs = list_new ();
1470 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1471 &lsp->tlv_data.ipv4_int_reachs,
1472 IPV4_REACH_LEN, area->lsp_frag_threshold,
1473 tlv_add_ipv4_reachs);
1474 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1475 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1476 lsp0, area, level);
1477 }
1478
1479#ifdef HAVE_IPV6
1480 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1481 {
1482 if (lsp->tlv_data.ipv6_reachs == NULL)
1483 lsp->tlv_data.ipv6_reachs = list_new ();
1484 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1485 &lsp->tlv_data.ipv6_reachs,
1486 IPV6_REACH_LEN, area->lsp_frag_threshold,
1487 tlv_add_ipv6_reachs);
1488 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1489 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1490 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001491 }
1492#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001493
1494 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1495 {
1496 if (lsp->tlv_data.is_neighs == NULL)
1497 lsp->tlv_data.is_neighs = list_new ();
1498 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1499 &lsp->tlv_data.is_neighs,
1500 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1501 tlv_add_is_neighs);
1502 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1503 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1504 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001505 }
jardineb5d44e2003-12-23 08:09:43 +00001506
jardineb5d44e2003-12-23 08:09:43 +00001507 return;
1508}
1509#endif
1510
hasso92365882005-01-18 13:53:33 +00001511#if 0 /* Old code? */
1512static void
jardineb5d44e2003-12-23 08:09:43 +00001513build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1514{
1515 struct list *circuit_list = area->circuit_list;
1516 struct isis_circuit *circuit;
1517 u_char *tlv_ptr;
1518 struct is_neigh *is_neigh;
1519
hassof390d2c2004-09-10 20:48:21 +00001520
jardineb5d44e2003-12-23 08:09:43 +00001521 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001522 /* the 2 is for the TL plus 1 for the nlpid */
1523 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1524 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1525 *(tlv_ptr + 1) = 1; /* one protocol */
1526#ifdef HAVE_IPV6 /*dunno if its right */
1527 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001528#else
hassof390d2c2004-09-10 20:48:21 +00001529 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001530#endif /* HAVE_IPV6 */
1531
1532 /* we should add our areas here
1533 * FIXME: we need to figure out which should be added? Adj? All? First? */
1534
1535 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001536 /* the 2 is for the TL plus 1 for the virtual field */
1537 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1538 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1539 *(tlv_ptr + 2) = 0; /* virtual is zero */
1540 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001541 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001542 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1543 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001544 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001545 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001546 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001547 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001548 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001549 circuit = (struct isis_circuit *) listhead (circuit_list);
1550 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001551 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001552 *(tlv_ptr + 1) =
1553 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001554
1555 /* FIXME: scan for adjencecies and add them */
1556
1557 /* FIXME: add reachability info */
1558
hassof390d2c2004-09-10 20:48:21 +00001559 /* adding dynamic hostname if needed */
1560 if (area->dynhostname)
1561 {
1562 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1563 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1564 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1565 lsp->tlv_data.hostname = (struct hostname *)
1566 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1567 /* the -1 is to fit the length in the struct */
1568 strlen (unix_hostname ())) - 1);
1569 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1570 strlen (unix_hostname ()));
1571 }
jardineb5d44e2003-12-23 08:09:43 +00001572
1573}
hasso92365882005-01-18 13:53:33 +00001574#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +00001575
1576/*
1577 * 7.3.7 Generation on non-pseudonode LSPs
1578 */
hasso92365882005-01-18 13:53:33 +00001579static int
hassof390d2c2004-09-10 20:48:21 +00001580lsp_generate_non_pseudo (struct isis_area *area, int level)
1581{
jardineb5d44e2003-12-23 08:09:43 +00001582 struct isis_lsp *oldlsp, *newlsp;
1583 u_int32_t seq_num = 0;
1584 u_char lspid[ISIS_SYS_ID_LEN + 2];
1585
1586 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1587 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1588
1589 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001590 if ((area->is_type & level) == level)
1591 {
1592 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1593 if (oldlsp)
1594 {
1595 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1596 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1597 area->lspdb[level - 1]);
1598 /* FIXME: we should actually initiate a purge */
1599 }
1600 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1601 area->is_type, 0, level);
1602 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001603
hassof390d2c2004-09-10 20:48:21 +00001604 lsp_insert (newlsp, area->lspdb[level - 1]);
1605 /* build_lsp_data (newlsp, area); */
1606 lsp_build_nonpseudo (newlsp, area);
1607 /* time to calculate our checksum */
1608 lsp_seqnum_update (newlsp);
1609 }
jardineb5d44e2003-12-23 08:09:43 +00001610
1611 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001612 if (isis->debugs & DEBUG_ADJ_PACKETS)
1613 {
1614 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +00001615 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001616 }
jardineb5d44e2003-12-23 08:09:43 +00001617
1618 return ISIS_OK;
1619}
1620
1621/*
1622 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1623 */
1624int
1625lsp_l1_generate (struct isis_area *area)
1626{
hassof390d2c2004-09-10 20:48:21 +00001627 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1628 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001629
1630 return lsp_generate_non_pseudo (area, 1);
1631}
1632
jardineb5d44e2003-12-23 08:09:43 +00001633/*
1634 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1635 */
1636int
1637lsp_l2_generate (struct isis_area *area)
1638{
hassof390d2c2004-09-10 20:48:21 +00001639 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1640 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001641
1642 return lsp_generate_non_pseudo (area, 2);
1643}
1644
hasso92365882005-01-18 13:53:33 +00001645static int
jardineb5d44e2003-12-23 08:09:43 +00001646lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1647{
1648 dict_t *lspdb = area->lspdb[level - 1];
1649 struct isis_lsp *lsp, *frag;
1650 struct listnode *node;
1651 u_char lspid[ISIS_SYS_ID_LEN + 2];
1652
1653 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1654 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001655
jardineb5d44e2003-12-23 08:09:43 +00001656 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001657
hassof390d2c2004-09-10 20:48:21 +00001658 if (!lsp)
1659 {
1660 zlog_err
1661 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1662 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001663
hassof390d2c2004-09-10 20:48:21 +00001664 return ISIS_ERROR;
1665 }
1666
1667 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001668 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001669 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1670 (area->max_lsp_lifetime[level - 1],
1671 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001672 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001673
1674 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1675 {
hasso529d65b2004-12-24 00:14:50 +00001676 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1677 "seq 0x%08x, cksum 0x%04x lifetime %us",
1678 area->area_tag,
1679 level,
1680 rawlspid_print (lsp->lsp_header->lsp_id),
1681 ntohl (lsp->lsp_header->seq_num),
1682 ntohs (lsp->lsp_header->checksum),
1683 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001684 }
jardineb5d44e2003-12-23 08:09:43 +00001685
1686 lsp->last_generated = time (NULL);
1687 area->lsp_regenerate_pending[level - 1] = 0;
1688 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
paul1eb8ef22005-04-07 07:30:20 +00001689 for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag))
hassof390d2c2004-09-10 20:48:21 +00001690 {
hassof390d2c2004-09-10 20:48:21 +00001691 frag->lsp_header->rem_lifetime = htons (isis_jitter
1692 (area->
1693 max_lsp_lifetime[level - 1],
1694 MAX_AGE_JITTER));
1695 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1696 }
jardineb5d44e2003-12-23 08:09:43 +00001697
1698 if (area->ip_circuits)
1699 isis_spf_schedule (area, level);
1700#ifdef HAVE_IPV6
1701 if (area->ipv6_circuits)
1702 isis_spf_schedule6 (area, level);
1703#endif
1704 return ISIS_OK;
1705}
1706
jardineb5d44e2003-12-23 08:09:43 +00001707/*
1708 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1709 * time and set SRM
1710 */
hassof390d2c2004-09-10 20:48:21 +00001711int
jardineb5d44e2003-12-23 08:09:43 +00001712lsp_refresh_l1 (struct thread *thread)
1713{
1714 struct isis_area *area;
1715 unsigned long ref_time;
1716
1717 area = THREAD_ARG (thread);
1718 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001719
jardineb5d44e2003-12-23 08:09:43 +00001720 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001721 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001722 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001723
1724 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001725 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1726
hassof390d2c2004-09-10 20:48:21 +00001727 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1728 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001729
jardineb5d44e2003-12-23 08:09:43 +00001730 return ISIS_OK;
1731}
1732
hassof390d2c2004-09-10 20:48:21 +00001733int
jardineb5d44e2003-12-23 08:09:43 +00001734lsp_refresh_l2 (struct thread *thread)
1735{
1736 struct isis_area *area;
1737 unsigned long ref_time;
1738
1739 area = THREAD_ARG (thread);
1740 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001741
jardineb5d44e2003-12-23 08:09:43 +00001742 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001743 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001744 lsp_non_pseudo_regenerate (area, 2);
1745
hassof390d2c2004-09-10 20:48:21 +00001746 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001747 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1748
hassof390d2c2004-09-10 20:48:21 +00001749 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1750 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001751
jardineb5d44e2003-12-23 08:09:43 +00001752 return ISIS_OK;
1753}
1754
jardineb5d44e2003-12-23 08:09:43 +00001755/*
1756 * Something has changed -> regenerate LSP
1757 */
1758
hasso92365882005-01-18 13:53:33 +00001759static int
jardineb5d44e2003-12-23 08:09:43 +00001760lsp_l1_regenerate (struct thread *thread)
1761{
1762 struct isis_area *area;
1763
1764 area = THREAD_ARG (thread);
1765 area->lsp_regenerate_pending[0] = 0;
1766
1767 return lsp_non_pseudo_regenerate (area, 1);
1768}
1769
hasso92365882005-01-18 13:53:33 +00001770static int
jardineb5d44e2003-12-23 08:09:43 +00001771lsp_l2_regenerate (struct thread *thread)
1772{
1773 struct isis_area *area;
1774
1775 area = THREAD_ARG (thread);
1776 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001777
jardineb5d44e2003-12-23 08:09:43 +00001778 return lsp_non_pseudo_regenerate (area, 2);
1779}
1780
hassof390d2c2004-09-10 20:48:21 +00001781int
jardineb5d44e2003-12-23 08:09:43 +00001782lsp_regenerate_schedule (struct isis_area *area)
1783{
1784 struct isis_lsp *lsp;
1785 u_char id[ISIS_SYS_ID_LEN + 2];
1786 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001787 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1788 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001789 now = time (NULL);
1790 /*
1791 * First level 1
1792 */
hassof390d2c2004-09-10 20:48:21 +00001793 if (area->is_type & IS_LEVEL_1)
1794 {
1795 lsp = lsp_search (id, area->lspdb[0]);
1796 if (!lsp || area->lsp_regenerate_pending[0])
1797 goto L2;
1798 /*
1799 * Throttle avoidance
1800 */
1801 diff = now - lsp->last_generated;
1802 if (diff < MIN_LSP_GEN_INTERVAL)
1803 {
1804 area->lsp_regenerate_pending[0] = 1;
1805 thread_add_timer (master, lsp_l1_regenerate, area,
1806 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001807 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001808 }
1809 else
1810 lsp_non_pseudo_regenerate (area, 1);
1811 }
jardineb5d44e2003-12-23 08:09:43 +00001812 /*
1813 * then 2
1814 */
hassof390d2c2004-09-10 20:48:21 +00001815L2:
1816 if (area->is_type & IS_LEVEL_2)
1817 {
1818 lsp = lsp_search (id, area->lspdb[1]);
1819 if (!lsp || area->lsp_regenerate_pending[1])
1820 return ISIS_OK;
1821 /*
1822 * Throttle avoidance
1823 */
1824 diff = now - lsp->last_generated;
1825 if (diff < MIN_LSP_GEN_INTERVAL)
1826 {
1827 area->lsp_regenerate_pending[1] = 1;
1828 thread_add_timer (master, lsp_l2_regenerate, area,
1829 MIN_LSP_GEN_INTERVAL - diff);
1830 return ISIS_OK;
1831 }
1832 else
1833 lsp_non_pseudo_regenerate (area, 2);
1834 }
1835
1836 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001837}
1838
1839/*
1840 * Funcs for pseudonode LSPs
1841 */
1842
1843/*
1844 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1845 */
hasso92365882005-01-18 13:53:33 +00001846static void
hassof390d2c2004-09-10 20:48:21 +00001847lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1848 int level)
jardineb5d44e2003-12-23 08:09:43 +00001849{
1850 struct isis_adjacency *adj;
1851 struct is_neigh *is_neigh;
1852 struct es_neigh *es_neigh;
1853 struct list *adj_list;
paul1eb8ef22005-04-07 07:30:20 +00001854 struct listnode *node, *nnode;
jardineb5d44e2003-12-23 08:09:43 +00001855 struct isis_passwd *passwd;
1856
1857 assert (circuit);
1858 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001859
jardineb5d44e2003-12-23 08:09:43 +00001860 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001861 return; /* we are not DIS on this circuit */
1862
jardineb5d44e2003-12-23 08:09:43 +00001863 lsp->level = level;
1864 if (level == 1)
1865 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1866 else
1867 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1868
1869 /*
1870 * add self to IS neighbours
1871 */
hassof390d2c2004-09-10 20:48:21 +00001872 if (lsp->tlv_data.is_neighs == NULL)
1873 {
1874 lsp->tlv_data.is_neighs = list_new ();
1875 lsp->tlv_data.is_neighs->del = free_tlv;
1876 }
jardineb5d44e2003-12-23 08:09:43 +00001877 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1878 memset (is_neigh, 0, sizeof (struct is_neigh));
1879 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1880 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001881
1882 adj_list = list_new ();
1883 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1884
paul1eb8ef22005-04-07 07:30:20 +00001885 for (ALL_LIST_ELEMENTS (adj_list, node, nnode, adj))
hassof390d2c2004-09-10 20:48:21 +00001886 {
hassof390d2c2004-09-10 20:48:21 +00001887 if (adj->circuit_t & level)
1888 {
1889 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1890 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1891 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1892 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1893 {
1894 /* an IS neighbour -> add it */
1895 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1896 memset (is_neigh, 0, sizeof (struct is_neigh));
1897 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1898 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1899 }
1900 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1901 {
1902 /* an ES neigbour add it, if we are building level 1 LSP */
1903 /* FIXME: the tlv-format is hard to use here */
1904 if (lsp->tlv_data.es_neighs == NULL)
1905 {
1906 lsp->tlv_data.es_neighs = list_new ();
1907 lsp->tlv_data.es_neighs->del = free_tlv;
1908 }
1909 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1910 memset (es_neigh, 0, sizeof (struct es_neigh));
1911 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
1912 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
1913 }
1914 }
jardineb5d44e2003-12-23 08:09:43 +00001915 }
hassof390d2c2004-09-10 20:48:21 +00001916
paul9985f832005-02-09 15:51:56 +00001917 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001918 /*
1919 * Add the authentication info if it's present
1920 */
hassof390d2c2004-09-10 20:48:21 +00001921 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1922 (passwd = &circuit->area->domain_passwd);
1923 if (passwd->type)
1924 {
1925 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1926 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1927 }
jardineb5d44e2003-12-23 08:09:43 +00001928
1929 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1930 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1931
1932 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1933 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1934
paul9985f832005-02-09 15:51:56 +00001935 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001936 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1937 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1938
jardineb5d44e2003-12-23 08:09:43 +00001939 list_delete (adj_list);
1940
1941 return;
1942}
1943
hasso92365882005-01-18 13:53:33 +00001944static int
jardineb5d44e2003-12-23 08:09:43 +00001945lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1946{
1947 dict_t *lspdb = circuit->area->lspdb[level - 1];
1948 struct isis_lsp *lsp;
1949 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00001950
jardineb5d44e2003-12-23 08:09:43 +00001951 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001952 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1953 LSP_FRAGMENT (lsp_id) = 0;
1954
jardineb5d44e2003-12-23 08:09:43 +00001955 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00001956
1957 if (!lsp)
1958 {
1959 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1960 rawlspid_print (lsp_id));
1961 return ISIS_ERROR;
1962 }
1963 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001964
1965 lsp_build_pseudo (lsp, circuit, level);
1966
hassof390d2c2004-09-10 20:48:21 +00001967 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00001968 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00001969 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001970
1971 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00001972
1973 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1974 {
hasso529d65b2004-12-24 00:14:50 +00001975 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1976 circuit->area->area_tag, level,
1977 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00001978 }
jardineb5d44e2003-12-23 08:09:43 +00001979
1980 lsp->last_generated = time (NULL);
1981 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001982
jardineb5d44e2003-12-23 08:09:43 +00001983 return ISIS_OK;
1984}
1985
jardineb5d44e2003-12-23 08:09:43 +00001986int
1987lsp_l1_refresh_pseudo (struct thread *thread)
1988{
1989 struct isis_circuit *circuit;
1990 int retval;
1991 unsigned long ref_time;
1992
hassof390d2c2004-09-10 20:48:21 +00001993 circuit = THREAD_ARG (thread);
1994
jardineb5d44e2003-12-23 08:09:43 +00001995 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00001996 return ISIS_ERROR; /* FIXME: purge and such */
1997
hasso13c48f72004-09-10 21:19:13 +00001998 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
1999
jardineb5d44e2003-12-23 08:09:43 +00002000 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002001
2002 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002003 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2004
hassof390d2c2004-09-10 20:48:21 +00002005 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2006 lsp_l1_refresh_pseudo, circuit,
2007 isis_jitter (ref_time, MAX_AGE_JITTER));
2008
jardineb5d44e2003-12-23 08:09:43 +00002009 return retval;
2010}
2011
hassof390d2c2004-09-10 20:48:21 +00002012int
jardineb5d44e2003-12-23 08:09:43 +00002013lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2014{
2015 struct isis_lsp *lsp;
2016 u_char id[ISIS_SYS_ID_LEN + 2];
2017 unsigned long ref_time;
2018
hassof390d2c2004-09-10 20:48:21 +00002019 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2020 LSP_FRAGMENT (id) = 0;
2021 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002022
2023 /*
2024 * If for some reason have a pseudo LSP in the db already -> regenerate
2025 */
2026 if (lsp_search (id, circuit->area->lspdb[0]))
2027 return lsp_pseudo_regenerate (circuit, 1);
2028 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002029 1, circuit->area->is_type, 0, 1);
2030
jardineb5d44e2003-12-23 08:09:43 +00002031 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002032
jardineb5d44e2003-12-23 08:09:43 +00002033 lsp->own_lsp = 1;
2034 lsp_insert (lsp, circuit->area->lspdb[0]);
2035 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2036
hassof390d2c2004-09-10 20:48:21 +00002037 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002038 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2039
hassof390d2c2004-09-10 20:48:21 +00002040 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2041 lsp_l1_refresh_pseudo, circuit,
2042 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002043
2044 return lsp_regenerate_schedule (circuit->area);
2045}
2046
2047int
2048lsp_l2_refresh_pseudo (struct thread *thread)
2049{
2050 struct isis_circuit *circuit;
2051 int retval;
2052 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002053 circuit = THREAD_ARG (thread);
2054
jardineb5d44e2003-12-23 08:09:43 +00002055 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002056 return ISIS_ERROR; /* FIXME: purge and such */
2057
hasso13c48f72004-09-10 21:19:13 +00002058 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2059
jardineb5d44e2003-12-23 08:09:43 +00002060 retval = lsp_pseudo_regenerate (circuit, 2);
2061
hassof390d2c2004-09-10 20:48:21 +00002062 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002063 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2064
hassof390d2c2004-09-10 20:48:21 +00002065 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2066 lsp_l2_refresh_pseudo, circuit,
2067 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002068
jardineb5d44e2003-12-23 08:09:43 +00002069 return retval;
2070}
2071
hassof390d2c2004-09-10 20:48:21 +00002072int
jardineb5d44e2003-12-23 08:09:43 +00002073lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2074{
2075 struct isis_lsp *lsp;
2076 u_char id[ISIS_SYS_ID_LEN + 2];
2077 unsigned long ref_time;
2078
hassof390d2c2004-09-10 20:48:21 +00002079 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2080 LSP_FRAGMENT (id) = 0;
2081 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002082
2083 if (lsp_search (id, circuit->area->lspdb[1]))
2084 return lsp_pseudo_regenerate (circuit, 2);
2085
2086 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002087 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002088
2089 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002090
2091 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002092 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2093
2094
2095 lsp->own_lsp = 1;
2096 lsp_insert (lsp, circuit->area->lspdb[1]);
2097 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002098
2099 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2100 lsp_l2_refresh_pseudo, circuit,
2101 isis_jitter (ref_time, MAX_AGE_JITTER));
2102
jardineb5d44e2003-12-23 08:09:43 +00002103 return lsp_regenerate_schedule (circuit->area);
2104}
2105
jardineb5d44e2003-12-23 08:09:43 +00002106/*
2107 * Walk through LSPs for an area
2108 * - set remaining lifetime
2109 * - set LSPs with SRMflag set for sending
2110 */
hassof390d2c2004-09-10 20:48:21 +00002111int
jardineb5d44e2003-12-23 08:09:43 +00002112lsp_tick (struct thread *thread)
2113{
2114 struct isis_area *area;
2115 struct isis_circuit *circuit;
2116 struct isis_lsp *lsp;
2117 struct list *lsp_list;
paul1eb8ef22005-04-07 07:30:20 +00002118 struct listnode *lspnode, *lspnnode, *cnode;
jardineb5d44e2003-12-23 08:09:43 +00002119 dnode_t *dnode, *dnode_next;
2120 int level;
2121
2122 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002123
jardineb5d44e2003-12-23 08:09:43 +00002124 area = THREAD_ARG (thread);
2125 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002126 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002127 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002128
2129 /*
2130 * Build a list of LSPs with (any) SRMflag set
2131 * and removed the ones that have aged out
2132 */
hassof390d2c2004-09-10 20:48:21 +00002133 for (level = 0; level < ISIS_LEVELS; level++)
2134 {
2135 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2136 {
2137 dnode = dict_first (area->lspdb[level]);
2138 while (dnode != NULL)
2139 {
2140 dnode_next = dict_next (area->lspdb[level], dnode);
2141 lsp = dnode_get (dnode);
2142 lsp_set_time (lsp);
2143 if (lsp->age_out == 0)
2144 {
jardineb5d44e2003-12-23 08:09:43 +00002145
hasso529d65b2004-12-24 00:14:50 +00002146 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2147 area->area_tag,
2148 lsp->level,
2149 rawlspid_print (lsp->lsp_header->lsp_id),
2150 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002151
hassof390d2c2004-09-10 20:48:21 +00002152 lsp_destroy (lsp);
2153 dict_delete (area->lspdb[level], dnode);
2154 }
2155 else if (flags_any_set (lsp->SRMflags))
2156 listnode_add (lsp_list, lsp);
2157 dnode = dnode_next;
2158 }
jardineb5d44e2003-12-23 08:09:43 +00002159
hassof390d2c2004-09-10 20:48:21 +00002160 /*
2161 * Send LSPs on circuits indicated by the SRMflags
2162 */
2163 if (listcount (lsp_list) > 0)
2164 {
paul1eb8ef22005-04-07 07:30:20 +00002165 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
hassof390d2c2004-09-10 20:48:21 +00002166 {
paul1eb8ef22005-04-07 07:30:20 +00002167 for (ALL_LIST_ELEMENTS (lsp_list, lspnode, lspnnode, lsp))
hassof390d2c2004-09-10 20:48:21 +00002168 {
hassof390d2c2004-09-10 20:48:21 +00002169 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2170 {
2171 /* FIXME: if same or elder lsp is already in lsp
2172 * queue */
2173 listnode_add (circuit->lsp_queue, lsp);
2174 thread_add_event (master, send_lsp, circuit, 0);
2175 }
2176 }
2177 }
2178 }
2179 list_delete_all_node (lsp_list);
2180 }
jardineb5d44e2003-12-23 08:09:43 +00002181 }
jardineb5d44e2003-12-23 08:09:43 +00002182
2183 list_delete (lsp_list);
2184
2185 return ISIS_OK;
2186}
2187
jardineb5d44e2003-12-23 08:09:43 +00002188void
hassof390d2c2004-09-10 20:48:21 +00002189lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002190{
2191 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002192
jardineb5d44e2003-12-23 08:09:43 +00002193 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002194
2195 if (lsp && lsp->purged == 0)
2196 {
2197 lsp->lsp_header->rem_lifetime = htons (0);
2198 lsp->lsp_header->pdu_len =
2199 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2200 lsp->purged = 0;
2201 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2202 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2203 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2204 }
2205
jardineb5d44e2003-12-23 08:09:43 +00002206 return;
2207}
2208
2209/*
2210 * Purge own LSP that is received and we don't have.
2211 * -> Do as in 7.3.16.4
2212 */
2213void
hassof390d2c2004-09-10 20:48:21 +00002214lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2215 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002216{
2217 struct isis_lsp *lsp;
2218
2219 /*
2220 * We need to create the LSP to be purged
2221 */
hasso529d65b2004-12-24 00:14:50 +00002222 zlog_debug ("LSP PURGE NON EXIST");
jardineb5d44e2003-12-23 08:09:43 +00002223 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2224 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002225 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2226 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002227 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2228 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002229 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002230 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002231 : L2_LINK_STATE);
2232 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2233 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002234 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002235
jardineb5d44e2003-12-23 08:09:43 +00002236 /*
2237 * Retain only LSP header
2238 */
2239 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2240 /*
2241 * Set the remaining lifetime to 0
2242 */
2243 lsp->lsp_header->rem_lifetime = 0;
2244 /*
2245 * Put the lsp into LSPdb
2246 */
hassof390d2c2004-09-10 20:48:21 +00002247 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002248
2249 /*
2250 * Send in to whole area
2251 */
2252 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002253
jardineb5d44e2003-12-23 08:09:43 +00002254 return;
2255}
2256
2257#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002258static int
jardineb5d44e2003-12-23 08:09:43 +00002259top_lsp_refresh (struct thread *thread)
2260{
hassof390d2c2004-09-10 20:48:21 +00002261 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002262
2263 lsp = THREAD_ARG (thread);
2264 assert (lsp);
2265
2266 lsp->t_lsp_top_ref = NULL;
2267
hassof390d2c2004-09-10 20:48:21 +00002268 lsp->lsp_header->rem_lifetime =
2269 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2270 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002271
2272 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002273 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2274 {
hasso529d65b2004-12-24 00:14:50 +00002275 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2276 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002277 }
jardineb5d44e2003-12-23 08:09:43 +00002278
2279 /* time to calculate our checksum */
2280 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002281 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2282 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2283 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002284
2285 return ISIS_OK;
2286}
2287
2288void
2289generate_topology_lsps (struct isis_area *area)
2290{
2291 struct listnode *node;
2292 int i, max = 0;
2293 struct arc *arc;
2294 u_char lspid[ISIS_SYS_ID_LEN + 2];
2295 struct isis_lsp *lsp;
2296
2297 /* first we find the maximal node */
hassof390d2c2004-09-10 20:48:21 +00002298 LIST_LOOP (area->topology, arc, node)
2299 {
2300 if (arc->from_node > max)
2301 max = arc->from_node;
2302 if (arc->to_node > max)
2303 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002304 }
2305
hassof390d2c2004-09-10 20:48:21 +00002306 for (i = 1; i < (max + 1); i++)
2307 {
2308 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2309 LSP_PSEUDO_ID (lspid) = 0x00;
2310 LSP_FRAGMENT (lspid) = 0x00;
2311 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2312 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002313
hassof390d2c2004-09-10 20:48:21 +00002314 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2315 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2316 1);
2317 lsp->from_topology = 1;
2318 /* creating data based on topology */
2319 build_topology_lsp_data (lsp, area, i);
2320 /* time to calculate our checksum */
2321 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2322 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2323 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2324 isis_jitter (MAX_LSP_GEN_INTERVAL,
2325 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002326
hassof390d2c2004-09-10 20:48:21 +00002327 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2328 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002329
hassof390d2c2004-09-10 20:48:21 +00002330 }
jardineb5d44e2003-12-23 08:09:43 +00002331}
2332
2333void
2334remove_topology_lsps (struct isis_area *area)
2335{
2336 struct isis_lsp *lsp;
2337 dnode_t *dnode, *dnode_next;
2338
2339 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002340 while (dnode != NULL)
2341 {
2342 dnode_next = dict_next (area->lspdb[0], dnode);
2343 lsp = dnode_get (dnode);
2344 if (lsp->from_topology)
2345 {
2346 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2347 lsp_destroy (lsp);
2348 dict_delete (area->lspdb[0], dnode);
2349 }
2350 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002351 }
jardineb5d44e2003-12-23 08:09:43 +00002352}
2353
2354void
hassof390d2c2004-09-10 20:48:21 +00002355build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002356 int lsp_top_num)
2357{
2358 struct listnode *node;
2359 struct arc *arc;
2360 u_char *tlv_ptr;
2361 struct is_neigh *is_neigh;
2362 int to_lsp = 0;
2363 char buff[200];
2364
2365 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002366 /* the 2 is for the TL plus 1 for the nlpid */
2367 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2368 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2369 *(tlv_ptr + 1) = 1; /* one protocol */
2370 *(tlv_ptr + 2) = NLPID_IP;
2371 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002372
2373 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002374 /* the 2 is for the TL plus 1 for the virtual field */
2375 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2376 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2377 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2378 *(tlv_ptr + 2) = 0; /* virtual is zero */
2379 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002380
2381 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002382 if (lsp_top_num == 1)
2383 {
jardineb5d44e2003-12-23 08:09:43 +00002384 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002385 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2386 sizeof (struct
2387 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002388 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002389 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2390 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002391 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002392 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002393 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2394 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2395 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2396 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002397 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2398 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002399 }
hassof390d2c2004-09-10 20:48:21 +00002400
2401 /* addding is reachabilities */
2402 LIST_LOOP (area->topology, arc, node)
2403 {
2404 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2405 {
2406 if (arc->to_node == lsp_top_num)
2407 to_lsp = arc->from_node;
2408 if (arc->from_node == lsp_top_num)
2409 to_lsp = arc->to_node;
2410
2411 /* if the length here is about to cross the FF limit, we reTLV */
2412 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2413 {
2414 /* retlv */
2415 /* the 2 is for the TL plus 1 for the virtual field */
2416 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2417 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2418 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2419 *(tlv_ptr + 2) = 0; /* virtual is zero */
2420 }
2421 /* doing this here assures us that we won't add an "empty" tlv */
2422 /* assign space for the is_neigh at the pdu end */
2423 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2424 sizeof (struct
2425 is_neigh));
2426 /* add this node to our list */
2427 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2428 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2429 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2430 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2431 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2432 is_neigh->metrics.metric_default = arc->distance;
2433 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2434 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2435 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2436 /* don't forget the length */
2437 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2438 }
jardineb5d44e2003-12-23 08:09:43 +00002439 }
2440
hassof390d2c2004-09-10 20:48:21 +00002441 /* adding dynamic hostname if needed */
2442 if (area->dynhostname)
2443 {
2444 memset (buff, 0x00, 200);
2445 sprintf (buff, "feedme%d", lsp_top_num);
2446 /* the 2 is for the TL */
2447 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2448 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2449 *(tlv_ptr + 1) = strlen (buff); /* Length */
2450 /* the -1 is to fit the length in the struct */
2451 lsp->tlv_data.hostname = (struct hostname *)
2452 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2453 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2454 }
jardineb5d44e2003-12-23 08:09:43 +00002455
2456 /* thanks to hannes, another bug bites the dust */
hassof390d2c2004-09-10 20:48:21 +00002457 lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00002458}
2459#endif /* TOPOLOGY_GENERATE */