blob: 8dae147f4f9d714aa16e1ecfcd490381887a3553 [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;
190 struct listnode *lnode;
191 struct isis_lsp *lsp;
192
hassof390d2c2004-09-10 20:48:21 +0000193 for (lnode = listhead (frags); lnode; nextnode (lnode))
194 {
195 lsp = getdata (lnode);
196 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
197 lsp_destroy (lsp);
198 dnode_destroy (dict_delete (lspdb, dnode));
199 }
200
jardineb5d44e2003-12-23 08:09:43 +0000201 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000202
jardineb5d44e2003-12-23 08:09:43 +0000203 return;
204}
205
206void
hassof390d2c2004-09-10 20:48:21 +0000207lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000208{
209 dnode_t *node;
210 struct isis_lsp *lsp;
211
212 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000213 if (node)
214 {
215 node = dict_delete (lspdb, node);
216 lsp = dnode_get (node);
217 /*
218 * If this is a zero lsp, remove all the frags now
219 */
220 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
221 {
222 if (lsp->lspu.frags)
223 lsp_remove_frags (lsp->lspu.frags, lspdb);
224 }
225 else
226 {
227 /*
228 * else just remove this frag, from the zero lsps' frag list
229 */
230 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
231 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
232 }
233 lsp_destroy (lsp);
234 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000235 }
jardineb5d44e2003-12-23 08:09:43 +0000236}
237
238/*
239 * Compares a LSP to given values
240 * Params are given in net order
241 */
hassof390d2c2004-09-10 20:48:21 +0000242int
243lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000244 u_int16_t checksum, u_int16_t rem_lifetime)
245{
hassof390d2c2004-09-10 20:48:21 +0000246 /* no point in double ntohl on seqnum */
247 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000248 lsp->lsp_header->checksum == checksum &&
249 /*comparing with 0, no need to do ntohl */
250 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000251 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
252 {
253 if (isis->debugs & DEBUG_SNP_PACKETS)
254 {
hasso529d65b2004-12-24 00:14:50 +0000255 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
256 " lifetime %us",
257 areatag,
258 rawlspid_print (lsp->lsp_header->lsp_id),
259 ntohl (lsp->lsp_header->seq_num),
260 ntohs (lsp->lsp_header->checksum),
261 ntohs (lsp->lsp_header->rem_lifetime));
262 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
263 " cksum 0x%04x, lifetime %us",
264 areatag,
265 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000266 }
267 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000268 }
jardineb5d44e2003-12-23 08:09:43 +0000269
hassof390d2c2004-09-10 20:48:21 +0000270 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
271 {
272 if (isis->debugs & DEBUG_SNP_PACKETS)
273 {
hasso529d65b2004-12-24 00:14:50 +0000274 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
275 " lifetime %us",
276 areatag,
277 rawlspid_print (lsp->lsp_header->lsp_id),
278 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
279 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
280 "cksum 0x%04x, lifetime %us",
281 areatag,
282 ntohl (lsp->lsp_header->seq_num),
283 ntohs (lsp->lsp_header->checksum),
284 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000285 }
286 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000287 }
hassof390d2c2004-09-10 20:48:21 +0000288 if (isis->debugs & DEBUG_SNP_PACKETS)
289 {
hasso529d65b2004-12-24 00:14:50 +0000290 zlog_debug
hassof390d2c2004-09-10 20:48:21 +0000291 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
292 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
293 ntohs (checksum), ntohs (rem_lifetime));
hasso529d65b2004-12-24 00:14:50 +0000294 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
295 " cksum 0x%04x, lifetime %us", areatag,
296 ntohl (lsp->lsp_header->seq_num),
297 ntohs (lsp->lsp_header->checksum),
298 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +0000299 }
jardineb5d44e2003-12-23 08:09:43 +0000300
301 return LSP_OLDER;
302}
303
hassof390d2c2004-09-10 20:48:21 +0000304void
jardineb5d44e2003-12-23 08:09:43 +0000305lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
306{
307 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000308
jardineb5d44e2003-12-23 08:09:43 +0000309 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
310 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
311 else
hassof390d2c2004-09-10 20:48:21 +0000312 newseq = seq_num++;
313
jardineb5d44e2003-12-23 08:09:43 +0000314 lsp->lsp_header->seq_num = htonl (newseq);
hassof390d2c2004-09-10 20:48:21 +0000315 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
316 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +0000317
318 return;
319}
320
321/*
322 * Genetates checksum for LSP and its frags
323 */
hasso92365882005-01-18 13:53:33 +0000324static void
jardineb5d44e2003-12-23 08:09:43 +0000325lsp_seqnum_update (struct isis_lsp *lsp0)
326{
327 struct isis_lsp *lsp;
328 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000329
jardineb5d44e2003-12-23 08:09:43 +0000330 lsp_inc_seqnum (lsp0, 0);
331
332 if (!lsp0->lspu.frags)
333 return;
334
hassof390d2c2004-09-10 20:48:21 +0000335 for (node = listhead (lsp0->lspu.frags); node; nextnode (node))
336 {
337 lsp = getdata (node);
338 lsp_inc_seqnum (lsp, 0);
339 }
340
jardineb5d44e2003-12-23 08:09:43 +0000341 return;
342}
343
hassof390d2c2004-09-10 20:48:21 +0000344int
jardineb5d44e2003-12-23 08:09:43 +0000345isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
hassof390d2c2004-09-10 20:48:21 +0000346 int pdulen, struct isis_passwd *passwd)
jardineb5d44e2003-12-23 08:09:43 +0000347{
348 uint32_t expected = 0, found;
349 struct tlvs tlvs;
350 int retval = 0;
351
352 expected |= TLVFLAG_AUTH_INFO;
353 retval = parse_tlvs (area->area_tag, stream->data +
hassof390d2c2004-09-10 20:48:21 +0000354 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
355 pdulen - ISIS_FIXED_HDR_LEN
356 - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000357 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000358 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000359
360 return authentication_check (passwd, &tlvs.auth_info);
361}
362
hasso92365882005-01-18 13:53:33 +0000363static void
hassof390d2c2004-09-10 20:48:21 +0000364lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
365 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000366{
hassof390d2c2004-09-10 20:48:21 +0000367 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000368 int retval;
hassof390d2c2004-09-10 20:48:21 +0000369
jardineb5d44e2003-12-23 08:09:43 +0000370 /* copying only the relevant part of our stream */
371 lsp->pdu = stream_new (stream->endp);
372 lsp->pdu->putp = stream->putp;
373 lsp->pdu->getp = stream->getp;
374 lsp->pdu->endp = stream->endp;
375 memcpy (lsp->pdu->data, stream->data, stream->endp);
376
377 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000378 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
379 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
380 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000381 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000382 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000383 /*
384 * Get LSP data i.e. TLVs
385 */
386 expected |= TLVFLAG_AUTH_INFO;
387 expected |= TLVFLAG_AREA_ADDRS;
388 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000389 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000390 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
391 expected |= TLVFLAG_NLPID;
392 if (area->dynhostname)
393 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000394 if (area->newmetric)
395 {
396 expected |= TLVFLAG_TE_IS_NEIGHS;
397 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
398 expected |= TLVFLAG_TE_ROUTER_ID;
399 }
jardineb5d44e2003-12-23 08:09:43 +0000400 expected |= TLVFLAG_IPV4_ADDR;
401 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
402 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
403#ifdef HAVE_IPV6
404 expected |= TLVFLAG_IPV6_ADDR;
405 expected |= TLVFLAG_IPV6_REACHABILITY;
406#endif /* HAVE_IPV6 */
407
408 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000409 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
410 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
411 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000412
hassof390d2c2004-09-10 20:48:21 +0000413 if (found & TLVFLAG_DYN_HOSTNAME)
414 {
415 if (area->dynhostname)
416 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
417 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
418 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
419 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
420 }
jardineb5d44e2003-12-23 08:09:43 +0000421
422}
423
424void
425lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +0000426 struct stream *stream, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000427{
hassof390d2c2004-09-10 20:48:21 +0000428 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000429 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
430 lsp_clear_data (lsp);
431
432 /* rebuild the lsp data */
433 lsp_update_data (lsp, stream, area);
434
hassof390d2c2004-09-10 20:48:21 +0000435 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000436 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000437}
438
jardineb5d44e2003-12-23 08:09:43 +0000439/* creation of LSP directly from what we received */
440struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000441lsp_new_from_stream_ptr (struct stream *stream,
442 u_int16_t pdu_len, struct isis_lsp *lsp0,
443 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000444{
445 struct isis_lsp *lsp;
446
447 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
448 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000449
jardineb5d44e2003-12-23 08:09:43 +0000450 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000451
452 if (lsp0 == NULL)
453 {
454 /*
455 * zero lsp -> create the list for fragments
456 */
457 lsp->lspu.frags = list_new ();
458 }
459 else
460 {
461 /*
462 * a fragment -> set the backpointer and add this to zero lsps frag list
463 */
464 lsp->lspu.zero_lsp = lsp0;
465 listnode_add (lsp0->lspu.frags, lsp);
466 }
467
jardineb5d44e2003-12-23 08:09:43 +0000468 return lsp;
469}
470
471struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000472lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
473 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000474{
475 struct isis_lsp *lsp;
476
477 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000478 if (!lsp)
479 {
480 /* FIXME: set lspdbol bit */
481 zlog_warn ("lsp_new(): out of memory");
482 return NULL;
483 }
jardineb5d44e2003-12-23 08:09:43 +0000484 memset (lsp, 0, sizeof (struct isis_lsp));
485#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000486 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000487#else
hassof390d2c2004-09-10 20:48:21 +0000488 /* We need to do realloc on TLVs additions */
489 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000490#endif /* LSP_MEMORY_PREASSIGN */
491 if (LSP_FRAGMENT (lsp_id) == 0)
492 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000493 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
494 lsp->lsp_header = (struct isis_link_state_hdr *)
495 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
496
jardineb5d44e2003-12-23 08:09:43 +0000497 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000498 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
499 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
500
jardineb5d44e2003-12-23 08:09:43 +0000501 /* now for the LSP HEADER */
502 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000503 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000504 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000505 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000506 lsp->lsp_header->seq_num = htonl (seq_num);
507 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
508 lsp->lsp_header->lsp_bits = lsp_bits;
509 lsp->level = level;
510 lsp->age_out = ZERO_AGE_LIFETIME;
511
512 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
513
514 /* #ifdef EXTREME_DEBUG */
515 /* logging */
hasso529d65b2004-12-24 00:14:50 +0000516 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
517 LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
518 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
519 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000520 /* #endif EXTREME DEBUG */
521
522 return lsp;
523}
524
525void
hassof390d2c2004-09-10 20:48:21 +0000526lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000527{
528 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
529}
530
531/*
532 * Build a list of LSPs with non-zero ht bounded by start and stop ids
533 */
hassof390d2c2004-09-10 20:48:21 +0000534void
535lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
536 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000537{
538 dnode_t *first, *last, *curr;
539
540 first = dict_lower_bound (lspdb, start_id);
541 if (!first)
542 return;
hassof390d2c2004-09-10 20:48:21 +0000543
jardineb5d44e2003-12-23 08:09:43 +0000544 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000545
jardineb5d44e2003-12-23 08:09:43 +0000546 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000547
548 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000549 listnode_add (list, first->dict_data);
550
hassof390d2c2004-09-10 20:48:21 +0000551 while (curr)
552 {
553 curr = dict_next (lspdb, curr);
554 if (curr &&
555 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
556 listnode_add (list, curr->dict_data);
557 if (curr == last)
558 break;
559 }
560
jardineb5d44e2003-12-23 08:09:43 +0000561 return;
562}
563
564/*
565 * Build a list of all LSPs bounded by start and stop ids
566 */
hassof390d2c2004-09-10 20:48:21 +0000567void
568lsp_build_list (u_char * start_id, u_char * stop_id,
569 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000570{
571 dnode_t *first, *last, *curr;
572
573 first = dict_lower_bound (lspdb, start_id);
574 if (!first)
575 return;
hassof390d2c2004-09-10 20:48:21 +0000576
jardineb5d44e2003-12-23 08:09:43 +0000577 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000578
jardineb5d44e2003-12-23 08:09:43 +0000579 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000580
jardineb5d44e2003-12-23 08:09:43 +0000581 listnode_add (list, first->dict_data);
582
hassof390d2c2004-09-10 20:48:21 +0000583 while (curr)
584 {
585 curr = dict_next (lspdb, curr);
586 if (curr)
587 listnode_add (list, curr->dict_data);
588 if (curr == last)
589 break;
590 }
591
jardineb5d44e2003-12-23 08:09:43 +0000592 return;
593}
594
595/*
596 * Build a list of LSPs with SSN flag set for the given circuit
597 */
598void
hassof390d2c2004-09-10 20:48:21 +0000599lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
600 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000601{
602 dnode_t *dnode, *next;
603 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000604
jardineb5d44e2003-12-23 08:09:43 +0000605 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000606 while (dnode != NULL)
607 {
608 next = dict_next (lspdb, dnode);
609 lsp = dnode_get (dnode);
610 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
611 listnode_add (list, lsp);
612 dnode = next;
613 }
614
jardineb5d44e2003-12-23 08:09:43 +0000615 return;
616}
617
hasso92365882005-01-18 13:53:33 +0000618static void
jardineb5d44e2003-12-23 08:09:43 +0000619lsp_set_time (struct isis_lsp *lsp)
620{
621 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000622
623 if (lsp->lsp_header->rem_lifetime == 0)
624 {
625 if (lsp->age_out != 0)
626 lsp->age_out--;
627 return;
628 }
jardineb5d44e2003-12-23 08:09:43 +0000629
630 /* If we are turning 0 */
631 /* ISO 10589 - 7.3.16.4 first paragraph */
632
hassof390d2c2004-09-10 20:48:21 +0000633 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
634 {
635 /* 7.3.16.4 a) set SRM flags on all */
636 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
637 /* 7.3.16.4 b) retain only the header FIXME */
638 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
639 }
jardineb5d44e2003-12-23 08:09:43 +0000640
hassof390d2c2004-09-10 20:48:21 +0000641 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000642 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
643}
644
hasso92365882005-01-18 13:53:33 +0000645static void
hassof390d2c2004-09-10 20:48:21 +0000646lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000647{
648 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000649 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000650
651 if (dynhost)
652 dyn = dynhn_find_by_id (lsp_id);
653 else
654 dyn = NULL;
655
656 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000657 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000658 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000659 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000660 else
hassof390d2c2004-09-10 20:48:21 +0000661 {
662 memcpy (id, sysid_print (lsp_id), 15);
663 }
664 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000665 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000666 LSP_FRAGMENT (lsp_id));
667 else
hassof7c43dc2004-09-26 16:24:14 +0000668 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000669}
670
hassof390d2c2004-09-10 20:48:21 +0000671/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000672const char *
hassof390d2c2004-09-10 20:48:21 +0000673lsp_bits2string (u_char * lsp_bits)
674{
675 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000676
hassof390d2c2004-09-10 20:48:21 +0000677 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000678 return " none";
679
680 /* we only focus on the default metric */
681 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000682 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000683
684 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000685 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000686
hassof390d2c2004-09-10 20:48:21 +0000687 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
688
jardineb5d44e2003-12-23 08:09:43 +0000689 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000690
hassof390d2c2004-09-10 20:48:21 +0000691 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000692}
693
694/* this function prints the lsp on show isis database */
hasso92365882005-01-18 13:53:33 +0000695static void
hassof390d2c2004-09-10 20:48:21 +0000696lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000697{
hassof390d2c2004-09-10 20:48:21 +0000698 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000699 u_char LSPid[255];
700
701 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000702 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
703 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
704 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000705
hassof390d2c2004-09-10 20:48:21 +0000706 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
707 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000708 else
hassof390d2c2004-09-10 20:48:21 +0000709 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000710
711 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000712 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000713}
714
hasso92365882005-01-18 13:53:33 +0000715static void
hassof390d2c2004-09-10 20:48:21 +0000716lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000717{
718 struct isis_lsp *lsp = dnode_get (node);
719 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000720 int i;
jardineb5d44e2003-12-23 08:09:43 +0000721 struct listnode *lnode;
722 struct is_neigh *is_neigh;
723 struct te_is_neigh *te_is_neigh;
724 struct ipv4_reachability *ipv4_reach;
725 struct in_addr *ipv4_addr;
726 struct te_ipv4_reachability *te_ipv4_reach;
727#ifdef HAVE_IPV6
728 struct ipv6_reachability *ipv6_reach;
729 struct in6_addr in6;
730#endif
731 u_char LSPid[255];
732 u_char hostname[255];
733 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000734 u_char ipv4_reach_prefix[20];
735 u_char ipv4_reach_mask[20];
736 u_char ipv4_address[20];
737
738 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000739 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000740
741 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000742 if (lsp->tlv_data.area_addrs)
743 {
744 LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode)
745 {
hasso1cd80842004-10-07 20:07:40 +0000746 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000747 isonet_print (area_addr->area_addr, area_addr->addr_len),
748 VTY_NEWLINE);
749 }
jardineb5d44e2003-12-23 08:09:43 +0000750 }
jardineb5d44e2003-12-23 08:09:43 +0000751
752 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000753 if (lsp->tlv_data.nlpids)
754 {
755 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
756 {
757 switch (lsp->tlv_data.nlpids->nlpids[i])
758 {
759 case NLPID_IP:
760 case NLPID_IPV6:
hasso1cd80842004-10-07 20:07:40 +0000761 vty_out (vty, " NLPID: 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000762 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
763 break;
764 default:
hasso1cd80842004-10-07 20:07:40 +0000765 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000766 break;
767 }
768 }
769 }
jardineb5d44e2003-12-23 08:09:43 +0000770
771 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000772 if (lsp->tlv_data.hostname)
773 {
774 bzero (hostname, sizeof (hostname));
775 memcpy (hostname, lsp->tlv_data.hostname->name,
776 lsp->tlv_data.hostname->namelen);
777 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000778 }
hassof390d2c2004-09-10 20:48:21 +0000779
780 if (lsp->tlv_data.ipv4_addrs)
781 {
782 LIST_LOOP (lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode)
783 {
784 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
785 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
786 }
787 }
788
hasso1cd80842004-10-07 20:07:40 +0000789 /* TE router id */
790 if (lsp->tlv_data.router_id)
791 {
792 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
793 sizeof (ipv4_address));
794 vty_out (vty, " Router ID: %s%s", ipv4_address, VTY_NEWLINE);
795 }
796
797 /* for the IS neighbor tlv */
798 if (lsp->tlv_data.is_neighs)
799 {
800 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
801 {
802 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
803 vty_out (vty, " Metric: %d IS %s%s",
804 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
805 }
806 }
807
jardineb5d44e2003-12-23 08:09:43 +0000808 /* for the internal reachable tlv */
809 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000810 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
811 {
812 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
813 sizeof (ipv4_reach_prefix));
814 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
815 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000816 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000817 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
818 ipv4_reach_mask, VTY_NEWLINE);
819 }
hasso2097cd82003-12-23 11:51:08 +0000820
821 /* for the external reachable tlv */
822 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000823 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
824 {
825 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
826 sizeof (ipv4_reach_prefix));
827 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
828 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000829 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000830 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
831 ipv4_reach_mask, VTY_NEWLINE);
832 }
jardineb5d44e2003-12-23 08:09:43 +0000833
hasso2097cd82003-12-23 11:51:08 +0000834 /* IPv6 tlv */
835#ifdef HAVE_IPV6
836 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000837 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
838 {
839 memset (&in6, 0, sizeof (in6));
840 memcpy (in6.s6_addr, ipv6_reach->prefix,
841 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000842 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000843 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000844 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
845 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
846 ntohl (ipv6_reach->metric),
847 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000848 else
hassof390d2c2004-09-10 20:48:21 +0000849 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
850 ntohl (ipv6_reach->metric),
851 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000852 }
853#endif
hasso1cd80842004-10-07 20:07:40 +0000854 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000855 if (lsp->tlv_data.te_is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000856 LIST_LOOP (lsp->tlv_data.te_is_neighs, te_is_neigh, lnode)
857 {
hasso1cd80842004-10-07 20:07:40 +0000858 /* FIXME: metric display is wrong. */
hassof390d2c2004-09-10 20:48:21 +0000859 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
hasso1cd80842004-10-07 20:07:40 +0000860 vty_out (vty, " Metric: %d extd-IS %s%s",
861 te_is_neigh->te_metric[0], LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000862 }
jardineb5d44e2003-12-23 08:09:43 +0000863
hasso1cd80842004-10-07 20:07:40 +0000864 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000865 if (lsp->tlv_data.te_ipv4_reachs)
hassof390d2c2004-09-10 20:48:21 +0000866 LIST_LOOP (lsp->tlv_data.te_ipv4_reachs, te_ipv4_reach, lnode)
867 {
hasso1cd80842004-10-07 20:07:40 +0000868 /* FIXME: There should be better way to output this stuff. */
hasso2e864cf2004-10-08 06:40:24 +0000869 vty_out (vty, " Metric: %d extd-IP %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000870 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000871 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
872 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000873 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000874 }
jardineb5d44e2003-12-23 08:09:43 +0000875
hassof390d2c2004-09-10 20:48:21 +0000876 return;
jardineb5d44e2003-12-23 08:09:43 +0000877}
878
879/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000880int
881lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000882{
883
hassof390d2c2004-09-10 20:48:21 +0000884 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000885 int lsp_count = 0;
886
887 /* print the title, for both modes */
888 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000889 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
890
891 if (detail == ISIS_UI_LEVEL_BRIEF)
892 {
893 while (node != NULL)
894 {
895 /* I think it is unnecessary, so I comment it out */
896 /* dict_contains (lspdb, node); */
897 next = dict_next (lspdb, node);
898 lsp_print (node, vty, dynhost);
899 node = next;
900 lsp_count++;
901 }
jardineb5d44e2003-12-23 08:09:43 +0000902 }
hassof390d2c2004-09-10 20:48:21 +0000903 else if (detail == ISIS_UI_LEVEL_DETAIL)
904 {
905 while (node != NULL)
906 {
907 next = dict_next (lspdb, node);
908 lsp_print_detail (node, vty, dynhost);
909 node = next;
910 lsp_count++;
911 }
jardineb5d44e2003-12-23 08:09:43 +0000912 }
jardineb5d44e2003-12-23 08:09:43 +0000913
914 return lsp_count;
915}
916
hasso92365882005-01-18 13:53:33 +0000917#if 0 /* Seems to be old code */
jardineb5d44e2003-12-23 08:09:43 +0000918/* this function reallocate memory to an lsp pdu, with an additional
919 * size of memory, it scans the lsp and moves all pointers the
920 * way they should */
hasso92365882005-01-18 13:53:33 +0000921static u_char *
hassof390d2c2004-09-10 20:48:21 +0000922lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +0000923{
924 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +0000925
926 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000927#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000928 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +0000929 return retval;
hassof390d2c2004-09-10 20:48:21 +0000930#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +0000931 u_char *newpdu;
932 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassof390d2c2004-09-10 20:48:21 +0000933 memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu),
934 ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +0000935 XFREE (memorytype, lsp->pdu);
936 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +0000937 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
938 lsp->lsp_header = (struct isis_link_state_hdr *)
939 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000940 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +0000941 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +0000942#endif /* LSP_MEMORY_PREASSIGN */
943}
hasso92365882005-01-18 13:53:33 +0000944#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +0000945
hassof390d2c2004-09-10 20:48:21 +0000946#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +0000947/*
948 * Builds the lsp->tlv_data
949 * and writes the tlvs into lsp->pdu
950 */
951void
952lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
953{
954 struct is_neigh *is_neigh;
955 struct listnode *node, *ipnode;
956 int level = lsp->level;
957 struct isis_circuit *circuit;
958 struct prefix_ipv4 *ipv4;
959 struct ipv4_reachability *ipreach;
960 struct isis_adjacency *nei;
961#ifdef HAVE_IPV6
962 struct prefix_ipv6 *ipv6;
963 struct ipv6_reachability *ip6reach;
964#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000965
jardineb5d44e2003-12-23 08:09:43 +0000966 /*
967 * First add the tlvs related to area
968 */
hassof390d2c2004-09-10 20:48:21 +0000969
jardineb5d44e2003-12-23 08:09:43 +0000970 /* Area addresses */
971 if (lsp->tlv_data.area_addrs == NULL)
972 lsp->tlv_data.area_addrs = list_new ();
973 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
974 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +0000975 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +0000976#ifdef HAVE_IPV6
977 || area->ipv6_circuits > 0
978#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000979 )
jardineb5d44e2003-12-23 08:09:43 +0000980 {
981 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
982 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +0000983 if (area->ip_circuits > 0)
984 {
985 lsp->tlv_data.nlpids->count++;
986 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
987 }
jardineb5d44e2003-12-23 08:09:43 +0000988#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000989 if (area->ipv6_circuits > 0)
990 {
991 lsp->tlv_data.nlpids->count++;
992 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
993 NLPID_IPV6;
994 }
jardineb5d44e2003-12-23 08:09:43 +0000995#endif /* HAVE_IPV6 */
996 }
997 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +0000998 if (area->dynhostname)
999 {
1000 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1001 sizeof (struct hostname));
1002 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
1003 strlen (unix_hostname ()));
1004 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1005 }
jardineb5d44e2003-12-23 08:09:43 +00001006#ifdef TOPOLOGY_GENERATE
1007 /*
1008 * If we have a topology in this area, we need to connect this lsp to
1009 * the first topology lsp
1010 */
hassof390d2c2004-09-10 20:48:21 +00001011 if ((area->topology) && (level == 1))
1012 {
1013 if (lsp->tlv_data.is_neighs == NULL)
1014 lsp->tlv_data.is_neighs = list_new ();
1015 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1016 memset (is_neigh, 0, sizeof (struct is_neigh));
1017 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1018 /* connected to the first */
1019 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1020 /* this is actually the same system, why mess the SPT */
1021 is_neigh->metrics.metric_default = 0;
1022 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1023 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1024 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1025 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001026
hassof390d2c2004-09-10 20:48:21 +00001027 }
jardineb5d44e2003-12-23 08:09:43 +00001028#endif
1029
1030 /*
1031 * Then add tlvs related to circuits
1032 */
hassof390d2c2004-09-10 20:48:21 +00001033 for (node = listhead (area->circuit_list); node; nextnode (node))
1034 {
1035 circuit = getdata (node);
1036 if (circuit->state != C_STATE_UP)
1037 continue;
1038
1039 /*
1040 * Add IPv4 internal reachability of this circuit
1041 */
1042 if (circuit->ip_router && circuit->ip_addrs &&
1043 circuit->ip_addrs->count > 0)
1044 {
1045 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1046 {
1047 lsp->tlv_data.ipv4_int_reachs = list_new ();
1048 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1049 }
1050 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1051 nextnode (ipnode))
1052 {
1053 ipv4 = getdata (ipnode);
1054 ipreach =
1055 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1056 ipreach->metrics = circuit->metrics[level - 1];
1057 ipreach->prefix = ipv4->prefix;
1058 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1059 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1060 }
1061 }
jardineb5d44e2003-12-23 08:09:43 +00001062#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001063 /*
1064 * Add IPv6 reachability of this circuit
1065 */
1066 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1067 circuit->ipv6_non_link->count > 0)
1068 {
1069 if (lsp->tlv_data.ipv6_reachs == NULL)
1070 {
1071 lsp->tlv_data.ipv6_reachs = list_new ();
1072 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1073 }
1074 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1075 nextnode (ipnode))
1076 {
1077 ipv6 = getdata (ipnode);
1078 ip6reach =
1079 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1080 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1081 ip6reach->metric =
1082 htonl (circuit->metrics[level - 1].metric_default);
1083 ip6reach->control_info = 0;
1084 ip6reach->prefix_len = ipv6->prefixlen;
1085 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1086 (ipv6->prefixlen + 7) / 8);
1087 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1088 }
1089 }
jardineb5d44e2003-12-23 08:09:43 +00001090#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001091
1092 switch (circuit->circ_type)
1093 {
1094 case CIRCUIT_T_BROADCAST:
1095 if (level & circuit->circuit_is_type)
1096 {
1097 if (lsp->tlv_data.is_neighs == NULL)
1098 {
1099 lsp->tlv_data.is_neighs = list_new ();
1100 lsp->tlv_data.is_neighs->del = free_tlv;
1101 }
1102 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1103 memset (is_neigh, 0, sizeof (struct is_neigh));
1104 if (level == 1)
1105 memcpy (&is_neigh->neigh_id,
1106 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1107 else
1108 memcpy (&is_neigh->neigh_id,
1109 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1110 is_neigh->metrics = circuit->metrics[level - 1];
1111 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1112 }
1113 break;
1114 case CIRCUIT_T_P2P:
1115 nei = circuit->u.p2p.neighbor;
1116 if (nei && (level & nei->circuit_t))
1117 {
1118 if (lsp->tlv_data.is_neighs == NULL)
1119 {
1120 lsp->tlv_data.is_neighs = list_new ();
1121 lsp->tlv_data.is_neighs->del = free_tlv;
1122 }
1123 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1124 memset (is_neigh, 0, sizeof (struct is_neigh));
1125 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1126 is_neigh->metrics = circuit->metrics[level - 1];
1127 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1128 }
1129 break;
1130 case CIRCUIT_T_STATIC_IN:
1131 zlog_warn ("lsp_area_create: unsupported circuit type");
1132 break;
1133 case CIRCUIT_T_STATIC_OUT:
1134 zlog_warn ("lsp_area_create: unsupported circuit type");
1135 break;
1136 case CIRCUIT_T_DA:
1137 zlog_warn ("lsp_area_create: unsupported circuit type");
1138 break;
1139 default:
1140 zlog_warn ("lsp_area_create: unknown circuit type");
1141 }
jardineb5d44e2003-12-23 08:09:43 +00001142 }
hassof390d2c2004-09-10 20:48:21 +00001143
jardineb5d44e2003-12-23 08:09:43 +00001144 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00001145
jardineb5d44e2003-12-23 08:09:43 +00001146 if (lsp->tlv_data.nlpids)
1147 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1148 if (lsp->tlv_data.hostname)
1149 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001150 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001151 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1152 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1153 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001154 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001155 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1156 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001157#ifdef HAVE_IPV6
1158 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001159 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1160#endif /* HAVE_IPV6 */
1161
1162 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1163
1164 return;
1165}
1166#endif
1167
1168#define FRAG_THOLD(S,T) \
1169((STREAM_SIZE(S)*T)/100)
1170
1171/* stream*, area->lsp_frag_threshold, increment */
1172#define FRAG_NEEDED(S,T,I) \
1173 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1174
hasso92365882005-01-18 13:53:33 +00001175static void
jardineb5d44e2003-12-23 08:09:43 +00001176lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001177 int tlvsize, int frag_thold,
1178 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001179{
1180 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001181
jardineb5d44e2003-12-23 08:09:43 +00001182 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001183 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1184 {
1185 tlv_build_func (*from, lsp->pdu);
1186 *to = *from;
1187 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001188 }
hassof390d2c2004-09-10 20:48:21 +00001189 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1190 {
1191 /* fit all we can */
1192 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1193 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1194 if (count)
1195 count = count / tlvsize;
1196 for (i = 0; i < count; i++)
1197 {
1198 listnode_add (*to, getdata (listhead (*from)));
1199 listnode_delete (*from, getdata (listhead (*from)));
1200 }
1201 tlv_build_func (*to, lsp->pdu);
1202 }
1203 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001204 return;
1205}
1206
hasso92365882005-01-18 13:53:33 +00001207static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001208lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1209 int level)
jardineb5d44e2003-12-23 08:09:43 +00001210{
1211 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001212 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1213
jardineb5d44e2003-12-23 08:09:43 +00001214 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1215 LSP_FRAGMENT (frag_id) = frag_num;
1216 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001217 if (lsp)
1218 {
1219 /*
1220 * Clear the TLVs, but inherit the authinfo
1221 */
1222 lsp_clear_data (lsp);
1223 if (lsp0->tlv_data.auth_info.type)
1224 {
1225 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1226 sizeof (struct isis_passwd));
1227 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1228 lsp->tlv_data.auth_info.len,
1229 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1230 }
1231 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001232 }
jardineb5d44e2003-12-23 08:09:43 +00001233 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001234 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001235 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001236 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001237 listnode_add (lsp0->lspu.frags, lsp);
1238 lsp->lspu.zero_lsp = lsp0;
1239 /*
1240 * Copy the authinfo from zero LSP
1241 */
hassof390d2c2004-09-10 20:48:21 +00001242 if (lsp0->tlv_data.auth_info.type)
1243 {
1244 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1245 sizeof (struct isis_passwd));
1246 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1247 lsp->tlv_data.auth_info.len,
1248 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1249 }
jardineb5d44e2003-12-23 08:09:43 +00001250 return lsp;
1251}
1252
1253/*
1254 * Builds the LSP data part. This func creates a new frag whenever
1255 * area->lsp_frag_threshold is exceeded.
1256 */
1257#if 1
hasso92365882005-01-18 13:53:33 +00001258static void
jardineb5d44e2003-12-23 08:09:43 +00001259lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1260{
1261 struct is_neigh *is_neigh;
1262 struct listnode *node, *ipnode;
1263 int level = lsp->level;
1264 struct isis_circuit *circuit;
1265 struct prefix_ipv4 *ipv4;
1266 struct ipv4_reachability *ipreach;
1267 struct isis_adjacency *nei;
1268#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001269 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001270 struct ipv6_reachability *ip6reach;
1271#endif /* HAVE_IPV6 */
1272 struct tlvs tlv_data;
1273 struct isis_lsp *lsp0 = lsp;
1274 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001275 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001276
1277 /*
1278 * First add the tlvs related to area
1279 */
hassof390d2c2004-09-10 20:48:21 +00001280
jardineb5d44e2003-12-23 08:09:43 +00001281 /* Area addresses */
1282 if (lsp->tlv_data.area_addrs == NULL)
1283 lsp->tlv_data.area_addrs = list_new ();
1284 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1285 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001286 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001287#ifdef HAVE_IPV6
1288 || area->ipv6_circuits > 0
1289#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001290 )
jardineb5d44e2003-12-23 08:09:43 +00001291 {
1292 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1293 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001294 if (area->ip_circuits > 0)
1295 {
1296 lsp->tlv_data.nlpids->count++;
1297 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1298 }
jardineb5d44e2003-12-23 08:09:43 +00001299#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001300 if (area->ipv6_circuits > 0)
1301 {
1302 lsp->tlv_data.nlpids->count++;
1303 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1304 NLPID_IPV6;
1305 }
jardineb5d44e2003-12-23 08:09:43 +00001306#endif /* HAVE_IPV6 */
1307 }
1308 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001309 if (area->dynhostname)
1310 {
1311 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1312 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001313
hassof390d2c2004-09-10 20:48:21 +00001314 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1315 strlen (unix_hostname ()));
1316 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1317 }
jardineb5d44e2003-12-23 08:09:43 +00001318
1319 /*
1320 * Building the zero lsp
1321 */
hassof390d2c2004-09-10 20:48:21 +00001322 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001323 /*
1324 * Add the authentication info if its present
1325 */
hassof390d2c2004-09-10 20:48:21 +00001326 (level == 1) ? (passwd = &area->area_passwd) :
1327 (passwd = &area->domain_passwd);
1328 if (passwd->type)
1329 {
1330 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1331 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1332 }
jardineb5d44e2003-12-23 08:09:43 +00001333 if (lsp->tlv_data.nlpids)
1334 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1335 if (lsp->tlv_data.hostname)
1336 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001337 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001338 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001339
jardineb5d44e2003-12-23 08:09:43 +00001340 memset (&tlv_data, 0, sizeof (struct tlvs));
1341 /*
hasso18a6dce2004-10-03 18:18:34 +00001342 * IPv4 address TLV. We don't follow "C" vendor, but "J" vendor behavior -
1343 * one IPv4 address is put into LSP and this address is same as router id.
1344 */
1345 if (router_id_zebra.s_addr != 0)
1346 {
hasso18a6dce2004-10-03 18:18:34 +00001347 if (lsp->tlv_data.ipv4_addrs == NULL)
1348 lsp->tlv_data.ipv4_addrs = list_new ();
1349
1350 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1351 routerid->s_addr = router_id_zebra.s_addr;
1352
1353 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
1354
1355 /*
1356 * FIXME: Using add_tlv() directly is hack, but tlv_add_ip_addrs()
1357 * expects list of prefix_ipv4 structures, but we have list of
1358 * in_addr structures.
1359 */
1360 add_tlv (IPV4_ADDR, IPV4_MAX_BYTELEN, (u_char *) &routerid->s_addr,
1361 lsp->pdu);
1362 }
1363 /*
jardineb5d44e2003-12-23 08:09:43 +00001364 * Then build lists of tlvs related to circuits
1365 */
hassof390d2c2004-09-10 20:48:21 +00001366 for (node = listhead (area->circuit_list); node; nextnode (node))
1367 {
1368 circuit = getdata (node);
1369 if (circuit->state != C_STATE_UP)
1370 continue;
jardineb5d44e2003-12-23 08:09:43 +00001371
hassof390d2c2004-09-10 20:48:21 +00001372 /*
1373 * Add IPv4 internal reachability of this circuit
1374 */
1375 if (circuit->ip_router && circuit->ip_addrs &&
1376 circuit->ip_addrs->count > 0)
1377 {
1378 if (tlv_data.ipv4_int_reachs == NULL)
1379 {
1380 tlv_data.ipv4_int_reachs = list_new ();
1381 }
1382 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1383 nextnode (ipnode))
1384 {
1385 ipv4 = getdata (ipnode);
1386 ipreach =
1387 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1388 ipreach->metrics = circuit->metrics[level - 1];
hassof390d2c2004-09-10 20:48:21 +00001389 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001390 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1391 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001392 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1393 }
1394
1395 }
jardineb5d44e2003-12-23 08:09:43 +00001396#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001397 /*
1398 * Add IPv6 reachability of this circuit
1399 */
1400 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1401 circuit->ipv6_non_link->count > 0)
1402 {
1403
1404 if (tlv_data.ipv6_reachs == NULL)
1405 {
1406 tlv_data.ipv6_reachs = list_new ();
1407 }
1408 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1409 nextnode (ipnode))
1410 {
1411 ipv6 = getdata (ipnode);
1412 ip6reach =
1413 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1414 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1415 ip6reach->metric =
1416 htonl (circuit->metrics[level - 1].metric_default);
1417 ip6reach->control_info = 0;
1418 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001419 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1420 apply_mask_ipv6 (ip6prefix);
1421 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1422 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001423 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1424 }
1425 }
1426#endif /* HAVE_IPV6 */
1427
1428 switch (circuit->circ_type)
1429 {
1430 case CIRCUIT_T_BROADCAST:
1431 if (level & circuit->circuit_is_type)
1432 {
1433 if (tlv_data.is_neighs == NULL)
1434 {
1435 tlv_data.is_neighs = list_new ();
1436 }
1437 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1438 memset (is_neigh, 0, sizeof (struct is_neigh));
1439 if (level == 1)
1440 memcpy (is_neigh->neigh_id,
1441 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1442 else
1443 memcpy (is_neigh->neigh_id,
1444 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1445 is_neigh->metrics = circuit->metrics[level - 1];
1446 listnode_add (tlv_data.is_neighs, is_neigh);
1447 }
1448 break;
1449 case CIRCUIT_T_P2P:
1450 nei = circuit->u.p2p.neighbor;
1451 if (nei && (level & nei->circuit_t))
1452 {
1453 if (tlv_data.is_neighs == NULL)
1454 {
1455 tlv_data.is_neighs = list_new ();
1456 tlv_data.is_neighs->del = free_tlv;
1457 }
1458 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1459 memset (is_neigh, 0, sizeof (struct is_neigh));
1460 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1461 is_neigh->metrics = circuit->metrics[level - 1];
1462 listnode_add (tlv_data.is_neighs, is_neigh);
1463 }
1464 break;
1465 case CIRCUIT_T_STATIC_IN:
1466 zlog_warn ("lsp_area_create: unsupported circuit type");
1467 break;
1468 case CIRCUIT_T_STATIC_OUT:
1469 zlog_warn ("lsp_area_create: unsupported circuit type");
1470 break;
1471 case CIRCUIT_T_DA:
1472 zlog_warn ("lsp_area_create: unsupported circuit type");
1473 break;
1474 default:
1475 zlog_warn ("lsp_area_create: unknown circuit type");
1476 }
1477 }
1478
1479 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1480 {
1481 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1482 lsp->tlv_data.ipv4_int_reachs = list_new ();
1483 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1484 &lsp->tlv_data.ipv4_int_reachs,
1485 IPV4_REACH_LEN, area->lsp_frag_threshold,
1486 tlv_add_ipv4_reachs);
1487 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1488 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1489 lsp0, area, level);
1490 }
1491
1492#ifdef HAVE_IPV6
1493 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1494 {
1495 if (lsp->tlv_data.ipv6_reachs == NULL)
1496 lsp->tlv_data.ipv6_reachs = list_new ();
1497 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1498 &lsp->tlv_data.ipv6_reachs,
1499 IPV6_REACH_LEN, area->lsp_frag_threshold,
1500 tlv_add_ipv6_reachs);
1501 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1502 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1503 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001504 }
1505#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001506
1507 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1508 {
1509 if (lsp->tlv_data.is_neighs == NULL)
1510 lsp->tlv_data.is_neighs = list_new ();
1511 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1512 &lsp->tlv_data.is_neighs,
1513 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1514 tlv_add_is_neighs);
1515 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1516 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1517 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001518 }
jardineb5d44e2003-12-23 08:09:43 +00001519
jardineb5d44e2003-12-23 08:09:43 +00001520 return;
1521}
1522#endif
1523
hasso92365882005-01-18 13:53:33 +00001524#if 0 /* Old code? */
1525static void
jardineb5d44e2003-12-23 08:09:43 +00001526build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1527{
1528 struct list *circuit_list = area->circuit_list;
1529 struct isis_circuit *circuit;
1530 u_char *tlv_ptr;
1531 struct is_neigh *is_neigh;
1532
hassof390d2c2004-09-10 20:48:21 +00001533
jardineb5d44e2003-12-23 08:09:43 +00001534 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001535 /* the 2 is for the TL plus 1 for the nlpid */
1536 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1537 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1538 *(tlv_ptr + 1) = 1; /* one protocol */
1539#ifdef HAVE_IPV6 /*dunno if its right */
1540 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001541#else
hassof390d2c2004-09-10 20:48:21 +00001542 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001543#endif /* HAVE_IPV6 */
1544
1545 /* we should add our areas here
1546 * FIXME: we need to figure out which should be added? Adj? All? First? */
1547
1548 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001549 /* the 2 is for the TL plus 1 for the virtual field */
1550 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1551 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1552 *(tlv_ptr + 2) = 0; /* virtual is zero */
1553 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001554 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001555 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1556 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001557 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001558 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001559 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001560 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001561 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001562 circuit = (struct isis_circuit *) listhead (circuit_list);
1563 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001564 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001565 *(tlv_ptr + 1) =
1566 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001567
1568 /* FIXME: scan for adjencecies and add them */
1569
1570 /* FIXME: add reachability info */
1571
hassof390d2c2004-09-10 20:48:21 +00001572 /* adding dynamic hostname if needed */
1573 if (area->dynhostname)
1574 {
1575 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1576 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1577 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1578 lsp->tlv_data.hostname = (struct hostname *)
1579 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1580 /* the -1 is to fit the length in the struct */
1581 strlen (unix_hostname ())) - 1);
1582 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1583 strlen (unix_hostname ()));
1584 }
jardineb5d44e2003-12-23 08:09:43 +00001585
1586}
hasso92365882005-01-18 13:53:33 +00001587#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +00001588
1589/*
1590 * 7.3.7 Generation on non-pseudonode LSPs
1591 */
hasso92365882005-01-18 13:53:33 +00001592static int
hassof390d2c2004-09-10 20:48:21 +00001593lsp_generate_non_pseudo (struct isis_area *area, int level)
1594{
jardineb5d44e2003-12-23 08:09:43 +00001595 struct isis_lsp *oldlsp, *newlsp;
1596 u_int32_t seq_num = 0;
1597 u_char lspid[ISIS_SYS_ID_LEN + 2];
1598
1599 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1600 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1601
1602 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001603 if ((area->is_type & level) == level)
1604 {
1605 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1606 if (oldlsp)
1607 {
1608 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1609 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1610 area->lspdb[level - 1]);
1611 /* FIXME: we should actually initiate a purge */
1612 }
1613 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1614 area->is_type, 0, level);
1615 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001616
hassof390d2c2004-09-10 20:48:21 +00001617 lsp_insert (newlsp, area->lspdb[level - 1]);
1618 /* build_lsp_data (newlsp, area); */
1619 lsp_build_nonpseudo (newlsp, area);
1620 /* time to calculate our checksum */
1621 lsp_seqnum_update (newlsp);
1622 }
jardineb5d44e2003-12-23 08:09:43 +00001623
1624 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001625 if (isis->debugs & DEBUG_ADJ_PACKETS)
1626 {
1627 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +00001628 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001629 }
jardineb5d44e2003-12-23 08:09:43 +00001630
1631 return ISIS_OK;
1632}
1633
1634/*
1635 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1636 */
1637int
1638lsp_l1_generate (struct isis_area *area)
1639{
hassof390d2c2004-09-10 20:48:21 +00001640 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1641 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001642
1643 return lsp_generate_non_pseudo (area, 1);
1644}
1645
jardineb5d44e2003-12-23 08:09:43 +00001646/*
1647 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1648 */
1649int
1650lsp_l2_generate (struct isis_area *area)
1651{
hassof390d2c2004-09-10 20:48:21 +00001652 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1653 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001654
1655 return lsp_generate_non_pseudo (area, 2);
1656}
1657
hasso92365882005-01-18 13:53:33 +00001658static int
jardineb5d44e2003-12-23 08:09:43 +00001659lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1660{
1661 dict_t *lspdb = area->lspdb[level - 1];
1662 struct isis_lsp *lsp, *frag;
1663 struct listnode *node;
1664 u_char lspid[ISIS_SYS_ID_LEN + 2];
1665
1666 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1667 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001668
jardineb5d44e2003-12-23 08:09:43 +00001669 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001670
hassof390d2c2004-09-10 20:48:21 +00001671 if (!lsp)
1672 {
1673 zlog_err
1674 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1675 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001676
hassof390d2c2004-09-10 20:48:21 +00001677 return ISIS_ERROR;
1678 }
1679
1680 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001681 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001682 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1683 (area->max_lsp_lifetime[level - 1],
1684 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001685 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001686
1687 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1688 {
hasso529d65b2004-12-24 00:14:50 +00001689 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1690 "seq 0x%08x, cksum 0x%04x lifetime %us",
1691 area->area_tag,
1692 level,
1693 rawlspid_print (lsp->lsp_header->lsp_id),
1694 ntohl (lsp->lsp_header->seq_num),
1695 ntohs (lsp->lsp_header->checksum),
1696 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001697 }
jardineb5d44e2003-12-23 08:09:43 +00001698
1699 lsp->last_generated = time (NULL);
1700 area->lsp_regenerate_pending[level - 1] = 0;
1701 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001702 for (node = listhead (lsp->lspu.frags); node; nextnode (node))
1703 {
1704 frag = getdata (node);
1705 frag->lsp_header->rem_lifetime = htons (isis_jitter
1706 (area->
1707 max_lsp_lifetime[level - 1],
1708 MAX_AGE_JITTER));
1709 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1710 }
jardineb5d44e2003-12-23 08:09:43 +00001711
1712 if (area->ip_circuits)
1713 isis_spf_schedule (area, level);
1714#ifdef HAVE_IPV6
1715 if (area->ipv6_circuits)
1716 isis_spf_schedule6 (area, level);
1717#endif
1718 return ISIS_OK;
1719}
1720
jardineb5d44e2003-12-23 08:09:43 +00001721/*
1722 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1723 * time and set SRM
1724 */
hassof390d2c2004-09-10 20:48:21 +00001725int
jardineb5d44e2003-12-23 08:09:43 +00001726lsp_refresh_l1 (struct thread *thread)
1727{
1728 struct isis_area *area;
1729 unsigned long ref_time;
1730
1731 area = THREAD_ARG (thread);
1732 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001733
jardineb5d44e2003-12-23 08:09:43 +00001734 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001735 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001736 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001737
1738 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001739 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1740
hassof390d2c2004-09-10 20:48:21 +00001741 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1742 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001743
jardineb5d44e2003-12-23 08:09:43 +00001744 return ISIS_OK;
1745}
1746
hassof390d2c2004-09-10 20:48:21 +00001747int
jardineb5d44e2003-12-23 08:09:43 +00001748lsp_refresh_l2 (struct thread *thread)
1749{
1750 struct isis_area *area;
1751 unsigned long ref_time;
1752
1753 area = THREAD_ARG (thread);
1754 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001755
jardineb5d44e2003-12-23 08:09:43 +00001756 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001757 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001758 lsp_non_pseudo_regenerate (area, 2);
1759
hassof390d2c2004-09-10 20:48:21 +00001760 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001761 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1762
hassof390d2c2004-09-10 20:48:21 +00001763 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1764 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001765
jardineb5d44e2003-12-23 08:09:43 +00001766 return ISIS_OK;
1767}
1768
jardineb5d44e2003-12-23 08:09:43 +00001769/*
1770 * Something has changed -> regenerate LSP
1771 */
1772
hasso92365882005-01-18 13:53:33 +00001773static int
jardineb5d44e2003-12-23 08:09:43 +00001774lsp_l1_regenerate (struct thread *thread)
1775{
1776 struct isis_area *area;
1777
1778 area = THREAD_ARG (thread);
1779 area->lsp_regenerate_pending[0] = 0;
1780
1781 return lsp_non_pseudo_regenerate (area, 1);
1782}
1783
hasso92365882005-01-18 13:53:33 +00001784static int
jardineb5d44e2003-12-23 08:09:43 +00001785lsp_l2_regenerate (struct thread *thread)
1786{
1787 struct isis_area *area;
1788
1789 area = THREAD_ARG (thread);
1790 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001791
jardineb5d44e2003-12-23 08:09:43 +00001792 return lsp_non_pseudo_regenerate (area, 2);
1793}
1794
hassof390d2c2004-09-10 20:48:21 +00001795int
jardineb5d44e2003-12-23 08:09:43 +00001796lsp_regenerate_schedule (struct isis_area *area)
1797{
1798 struct isis_lsp *lsp;
1799 u_char id[ISIS_SYS_ID_LEN + 2];
1800 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001801 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1802 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001803 now = time (NULL);
1804 /*
1805 * First level 1
1806 */
hassof390d2c2004-09-10 20:48:21 +00001807 if (area->is_type & IS_LEVEL_1)
1808 {
1809 lsp = lsp_search (id, area->lspdb[0]);
1810 if (!lsp || area->lsp_regenerate_pending[0])
1811 goto L2;
1812 /*
1813 * Throttle avoidance
1814 */
1815 diff = now - lsp->last_generated;
1816 if (diff < MIN_LSP_GEN_INTERVAL)
1817 {
1818 area->lsp_regenerate_pending[0] = 1;
1819 thread_add_timer (master, lsp_l1_regenerate, area,
1820 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001821 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001822 }
1823 else
1824 lsp_non_pseudo_regenerate (area, 1);
1825 }
jardineb5d44e2003-12-23 08:09:43 +00001826 /*
1827 * then 2
1828 */
hassof390d2c2004-09-10 20:48:21 +00001829L2:
1830 if (area->is_type & IS_LEVEL_2)
1831 {
1832 lsp = lsp_search (id, area->lspdb[1]);
1833 if (!lsp || area->lsp_regenerate_pending[1])
1834 return ISIS_OK;
1835 /*
1836 * Throttle avoidance
1837 */
1838 diff = now - lsp->last_generated;
1839 if (diff < MIN_LSP_GEN_INTERVAL)
1840 {
1841 area->lsp_regenerate_pending[1] = 1;
1842 thread_add_timer (master, lsp_l2_regenerate, area,
1843 MIN_LSP_GEN_INTERVAL - diff);
1844 return ISIS_OK;
1845 }
1846 else
1847 lsp_non_pseudo_regenerate (area, 2);
1848 }
1849
1850 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001851}
1852
1853/*
1854 * Funcs for pseudonode LSPs
1855 */
1856
1857/*
1858 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1859 */
hasso92365882005-01-18 13:53:33 +00001860static void
hassof390d2c2004-09-10 20:48:21 +00001861lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1862 int level)
jardineb5d44e2003-12-23 08:09:43 +00001863{
1864 struct isis_adjacency *adj;
1865 struct is_neigh *is_neigh;
1866 struct es_neigh *es_neigh;
1867 struct list *adj_list;
1868 struct listnode *node;
1869 struct isis_passwd *passwd;
1870
1871 assert (circuit);
1872 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001873
jardineb5d44e2003-12-23 08:09:43 +00001874 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001875 return; /* we are not DIS on this circuit */
1876
jardineb5d44e2003-12-23 08:09:43 +00001877 lsp->level = level;
1878 if (level == 1)
1879 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1880 else
1881 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1882
1883 /*
1884 * add self to IS neighbours
1885 */
hassof390d2c2004-09-10 20:48:21 +00001886 if (lsp->tlv_data.is_neighs == NULL)
1887 {
1888 lsp->tlv_data.is_neighs = list_new ();
1889 lsp->tlv_data.is_neighs->del = free_tlv;
1890 }
jardineb5d44e2003-12-23 08:09:43 +00001891 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1892 memset (is_neigh, 0, sizeof (struct is_neigh));
1893 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1894 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001895
1896 adj_list = list_new ();
1897 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1898
1899 for (node = listhead (adj_list); node; nextnode (node))
1900 {
1901 adj = getdata (node);
1902 if (adj->circuit_t & level)
1903 {
1904 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1905 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1906 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1907 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1908 {
1909 /* an IS neighbour -> add it */
1910 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1911 memset (is_neigh, 0, sizeof (struct is_neigh));
1912 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1913 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1914 }
1915 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1916 {
1917 /* an ES neigbour add it, if we are building level 1 LSP */
1918 /* FIXME: the tlv-format is hard to use here */
1919 if (lsp->tlv_data.es_neighs == NULL)
1920 {
1921 lsp->tlv_data.es_neighs = list_new ();
1922 lsp->tlv_data.es_neighs->del = free_tlv;
1923 }
1924 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1925 memset (es_neigh, 0, sizeof (struct es_neigh));
1926 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
1927 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
1928 }
1929 }
jardineb5d44e2003-12-23 08:09:43 +00001930 }
hassof390d2c2004-09-10 20:48:21 +00001931
jardineb5d44e2003-12-23 08:09:43 +00001932 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1933 /*
1934 * Add the authentication info if it's present
1935 */
hassof390d2c2004-09-10 20:48:21 +00001936 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1937 (passwd = &circuit->area->domain_passwd);
1938 if (passwd->type)
1939 {
1940 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1941 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1942 }
jardineb5d44e2003-12-23 08:09:43 +00001943
1944 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1945 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1946
1947 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1948 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1949
1950 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001951 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1952 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1953
jardineb5d44e2003-12-23 08:09:43 +00001954 list_delete (adj_list);
1955
1956 return;
1957}
1958
hasso92365882005-01-18 13:53:33 +00001959static int
jardineb5d44e2003-12-23 08:09:43 +00001960lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1961{
1962 dict_t *lspdb = circuit->area->lspdb[level - 1];
1963 struct isis_lsp *lsp;
1964 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00001965
jardineb5d44e2003-12-23 08:09:43 +00001966 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001967 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1968 LSP_FRAGMENT (lsp_id) = 0;
1969
jardineb5d44e2003-12-23 08:09:43 +00001970 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00001971
1972 if (!lsp)
1973 {
1974 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1975 rawlspid_print (lsp_id));
1976 return ISIS_ERROR;
1977 }
1978 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001979
1980 lsp_build_pseudo (lsp, circuit, level);
1981
hassof390d2c2004-09-10 20:48:21 +00001982 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00001983 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00001984 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001985
1986 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00001987
1988 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1989 {
hasso529d65b2004-12-24 00:14:50 +00001990 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1991 circuit->area->area_tag, level,
1992 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00001993 }
jardineb5d44e2003-12-23 08:09:43 +00001994
1995 lsp->last_generated = time (NULL);
1996 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001997
jardineb5d44e2003-12-23 08:09:43 +00001998 return ISIS_OK;
1999}
2000
jardineb5d44e2003-12-23 08:09:43 +00002001int
2002lsp_l1_refresh_pseudo (struct thread *thread)
2003{
2004 struct isis_circuit *circuit;
2005 int retval;
2006 unsigned long ref_time;
2007
hassof390d2c2004-09-10 20:48:21 +00002008 circuit = THREAD_ARG (thread);
2009
jardineb5d44e2003-12-23 08:09:43 +00002010 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002011 return ISIS_ERROR; /* FIXME: purge and such */
2012
hasso13c48f72004-09-10 21:19:13 +00002013 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2014
jardineb5d44e2003-12-23 08:09:43 +00002015 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002016
2017 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002018 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2019
hassof390d2c2004-09-10 20:48:21 +00002020 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2021 lsp_l1_refresh_pseudo, circuit,
2022 isis_jitter (ref_time, MAX_AGE_JITTER));
2023
jardineb5d44e2003-12-23 08:09:43 +00002024 return retval;
2025}
2026
hassof390d2c2004-09-10 20:48:21 +00002027int
jardineb5d44e2003-12-23 08:09:43 +00002028lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2029{
2030 struct isis_lsp *lsp;
2031 u_char id[ISIS_SYS_ID_LEN + 2];
2032 unsigned long ref_time;
2033
hassof390d2c2004-09-10 20:48:21 +00002034 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2035 LSP_FRAGMENT (id) = 0;
2036 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002037
2038 /*
2039 * If for some reason have a pseudo LSP in the db already -> regenerate
2040 */
2041 if (lsp_search (id, circuit->area->lspdb[0]))
2042 return lsp_pseudo_regenerate (circuit, 1);
2043 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002044 1, circuit->area->is_type, 0, 1);
2045
jardineb5d44e2003-12-23 08:09:43 +00002046 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002047
jardineb5d44e2003-12-23 08:09:43 +00002048 lsp->own_lsp = 1;
2049 lsp_insert (lsp, circuit->area->lspdb[0]);
2050 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2051
hassof390d2c2004-09-10 20:48:21 +00002052 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002053 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2054
hassof390d2c2004-09-10 20:48:21 +00002055 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2056 lsp_l1_refresh_pseudo, circuit,
2057 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002058
2059 return lsp_regenerate_schedule (circuit->area);
2060}
2061
2062int
2063lsp_l2_refresh_pseudo (struct thread *thread)
2064{
2065 struct isis_circuit *circuit;
2066 int retval;
2067 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002068 circuit = THREAD_ARG (thread);
2069
jardineb5d44e2003-12-23 08:09:43 +00002070 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002071 return ISIS_ERROR; /* FIXME: purge and such */
2072
hasso13c48f72004-09-10 21:19:13 +00002073 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2074
jardineb5d44e2003-12-23 08:09:43 +00002075 retval = lsp_pseudo_regenerate (circuit, 2);
2076
hassof390d2c2004-09-10 20:48:21 +00002077 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002078 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2079
hassof390d2c2004-09-10 20:48:21 +00002080 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2081 lsp_l2_refresh_pseudo, circuit,
2082 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002083
jardineb5d44e2003-12-23 08:09:43 +00002084 return retval;
2085}
2086
hassof390d2c2004-09-10 20:48:21 +00002087int
jardineb5d44e2003-12-23 08:09:43 +00002088lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2089{
2090 struct isis_lsp *lsp;
2091 u_char id[ISIS_SYS_ID_LEN + 2];
2092 unsigned long ref_time;
2093
hassof390d2c2004-09-10 20:48:21 +00002094 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2095 LSP_FRAGMENT (id) = 0;
2096 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002097
2098 if (lsp_search (id, circuit->area->lspdb[1]))
2099 return lsp_pseudo_regenerate (circuit, 2);
2100
2101 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002102 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002103
2104 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002105
2106 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002107 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2108
2109
2110 lsp->own_lsp = 1;
2111 lsp_insert (lsp, circuit->area->lspdb[1]);
2112 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002113
2114 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2115 lsp_l2_refresh_pseudo, circuit,
2116 isis_jitter (ref_time, MAX_AGE_JITTER));
2117
jardineb5d44e2003-12-23 08:09:43 +00002118 return lsp_regenerate_schedule (circuit->area);
2119}
2120
jardineb5d44e2003-12-23 08:09:43 +00002121/*
2122 * Walk through LSPs for an area
2123 * - set remaining lifetime
2124 * - set LSPs with SRMflag set for sending
2125 */
hassof390d2c2004-09-10 20:48:21 +00002126int
jardineb5d44e2003-12-23 08:09:43 +00002127lsp_tick (struct thread *thread)
2128{
2129 struct isis_area *area;
2130 struct isis_circuit *circuit;
2131 struct isis_lsp *lsp;
2132 struct list *lsp_list;
2133 struct listnode *lspnode, *cnode;
2134 dnode_t *dnode, *dnode_next;
2135 int level;
2136
2137 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002138
jardineb5d44e2003-12-23 08:09:43 +00002139 area = THREAD_ARG (thread);
2140 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002141 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002142 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002143
2144 /*
2145 * Build a list of LSPs with (any) SRMflag set
2146 * and removed the ones that have aged out
2147 */
hassof390d2c2004-09-10 20:48:21 +00002148 for (level = 0; level < ISIS_LEVELS; level++)
2149 {
2150 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2151 {
2152 dnode = dict_first (area->lspdb[level]);
2153 while (dnode != NULL)
2154 {
2155 dnode_next = dict_next (area->lspdb[level], dnode);
2156 lsp = dnode_get (dnode);
2157 lsp_set_time (lsp);
2158 if (lsp->age_out == 0)
2159 {
jardineb5d44e2003-12-23 08:09:43 +00002160
hasso529d65b2004-12-24 00:14:50 +00002161 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2162 area->area_tag,
2163 lsp->level,
2164 rawlspid_print (lsp->lsp_header->lsp_id),
2165 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002166
hassof390d2c2004-09-10 20:48:21 +00002167 lsp_destroy (lsp);
2168 dict_delete (area->lspdb[level], dnode);
2169 }
2170 else if (flags_any_set (lsp->SRMflags))
2171 listnode_add (lsp_list, lsp);
2172 dnode = dnode_next;
2173 }
jardineb5d44e2003-12-23 08:09:43 +00002174
hassof390d2c2004-09-10 20:48:21 +00002175 /*
2176 * Send LSPs on circuits indicated by the SRMflags
2177 */
2178 if (listcount (lsp_list) > 0)
2179 {
2180 for (cnode = listhead (area->circuit_list); cnode;
2181 nextnode (cnode))
2182 {
2183 circuit = getdata (cnode);
2184 for (lspnode = listhead (lsp_list); lspnode;
2185 nextnode (lspnode))
2186 {
2187 lsp = getdata (lspnode);
2188 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2189 {
2190 /* FIXME: if same or elder lsp is already in lsp
2191 * queue */
2192 listnode_add (circuit->lsp_queue, lsp);
2193 thread_add_event (master, send_lsp, circuit, 0);
2194 }
2195 }
2196 }
2197 }
2198 list_delete_all_node (lsp_list);
2199 }
jardineb5d44e2003-12-23 08:09:43 +00002200 }
jardineb5d44e2003-12-23 08:09:43 +00002201
2202 list_delete (lsp_list);
2203
2204 return ISIS_OK;
2205}
2206
jardineb5d44e2003-12-23 08:09:43 +00002207void
hassof390d2c2004-09-10 20:48:21 +00002208lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002209{
2210 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002211
jardineb5d44e2003-12-23 08:09:43 +00002212 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002213
2214 if (lsp && lsp->purged == 0)
2215 {
2216 lsp->lsp_header->rem_lifetime = htons (0);
2217 lsp->lsp_header->pdu_len =
2218 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2219 lsp->purged = 0;
2220 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2221 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2222 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2223 }
2224
jardineb5d44e2003-12-23 08:09:43 +00002225 return;
2226}
2227
2228/*
2229 * Purge own LSP that is received and we don't have.
2230 * -> Do as in 7.3.16.4
2231 */
2232void
hassof390d2c2004-09-10 20:48:21 +00002233lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2234 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002235{
2236 struct isis_lsp *lsp;
2237
2238 /*
2239 * We need to create the LSP to be purged
2240 */
hasso529d65b2004-12-24 00:14:50 +00002241 zlog_debug ("LSP PURGE NON EXIST");
jardineb5d44e2003-12-23 08:09:43 +00002242 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2243 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002244 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2245 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002246 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2247 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002248 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002249 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002250 : L2_LINK_STATE);
2251 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2252 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002253 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002254
jardineb5d44e2003-12-23 08:09:43 +00002255 /*
2256 * Retain only LSP header
2257 */
2258 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2259 /*
2260 * Set the remaining lifetime to 0
2261 */
2262 lsp->lsp_header->rem_lifetime = 0;
2263 /*
2264 * Put the lsp into LSPdb
2265 */
hassof390d2c2004-09-10 20:48:21 +00002266 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002267
2268 /*
2269 * Send in to whole area
2270 */
2271 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002272
jardineb5d44e2003-12-23 08:09:43 +00002273 return;
2274}
2275
2276#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002277static int
jardineb5d44e2003-12-23 08:09:43 +00002278top_lsp_refresh (struct thread *thread)
2279{
hassof390d2c2004-09-10 20:48:21 +00002280 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002281
2282 lsp = THREAD_ARG (thread);
2283 assert (lsp);
2284
2285 lsp->t_lsp_top_ref = NULL;
2286
hassof390d2c2004-09-10 20:48:21 +00002287 lsp->lsp_header->rem_lifetime =
2288 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2289 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002290
2291 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002292 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2293 {
hasso529d65b2004-12-24 00:14:50 +00002294 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2295 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002296 }
jardineb5d44e2003-12-23 08:09:43 +00002297
2298 /* time to calculate our checksum */
2299 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002300 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2301 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2302 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002303
2304 return ISIS_OK;
2305}
2306
2307void
2308generate_topology_lsps (struct isis_area *area)
2309{
2310 struct listnode *node;
2311 int i, max = 0;
2312 struct arc *arc;
2313 u_char lspid[ISIS_SYS_ID_LEN + 2];
2314 struct isis_lsp *lsp;
2315
2316 /* first we find the maximal node */
hassof390d2c2004-09-10 20:48:21 +00002317 LIST_LOOP (area->topology, arc, node)
2318 {
2319 if (arc->from_node > max)
2320 max = arc->from_node;
2321 if (arc->to_node > max)
2322 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002323 }
2324
hassof390d2c2004-09-10 20:48:21 +00002325 for (i = 1; i < (max + 1); i++)
2326 {
2327 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2328 LSP_PSEUDO_ID (lspid) = 0x00;
2329 LSP_FRAGMENT (lspid) = 0x00;
2330 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2331 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002332
hassof390d2c2004-09-10 20:48:21 +00002333 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2334 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2335 1);
2336 lsp->from_topology = 1;
2337 /* creating data based on topology */
2338 build_topology_lsp_data (lsp, area, i);
2339 /* time to calculate our checksum */
2340 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2341 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2342 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2343 isis_jitter (MAX_LSP_GEN_INTERVAL,
2344 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002345
hassof390d2c2004-09-10 20:48:21 +00002346 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2347 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002348
hassof390d2c2004-09-10 20:48:21 +00002349 }
jardineb5d44e2003-12-23 08:09:43 +00002350}
2351
2352void
2353remove_topology_lsps (struct isis_area *area)
2354{
2355 struct isis_lsp *lsp;
2356 dnode_t *dnode, *dnode_next;
2357
2358 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002359 while (dnode != NULL)
2360 {
2361 dnode_next = dict_next (area->lspdb[0], dnode);
2362 lsp = dnode_get (dnode);
2363 if (lsp->from_topology)
2364 {
2365 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2366 lsp_destroy (lsp);
2367 dict_delete (area->lspdb[0], dnode);
2368 }
2369 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002370 }
jardineb5d44e2003-12-23 08:09:43 +00002371}
2372
2373void
hassof390d2c2004-09-10 20:48:21 +00002374build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002375 int lsp_top_num)
2376{
2377 struct listnode *node;
2378 struct arc *arc;
2379 u_char *tlv_ptr;
2380 struct is_neigh *is_neigh;
2381 int to_lsp = 0;
2382 char buff[200];
2383
2384 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002385 /* the 2 is for the TL plus 1 for the nlpid */
2386 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2387 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2388 *(tlv_ptr + 1) = 1; /* one protocol */
2389 *(tlv_ptr + 2) = NLPID_IP;
2390 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002391
2392 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002393 /* the 2 is for the TL plus 1 for the virtual field */
2394 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2395 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2396 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2397 *(tlv_ptr + 2) = 0; /* virtual is zero */
2398 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002399
2400 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002401 if (lsp_top_num == 1)
2402 {
jardineb5d44e2003-12-23 08:09:43 +00002403 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002404 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2405 sizeof (struct
2406 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002407 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002408 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2409 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002410 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002411 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002412 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2413 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2414 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2415 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002416 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2417 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002418 }
hassof390d2c2004-09-10 20:48:21 +00002419
2420 /* addding is reachabilities */
2421 LIST_LOOP (area->topology, arc, node)
2422 {
2423 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2424 {
2425 if (arc->to_node == lsp_top_num)
2426 to_lsp = arc->from_node;
2427 if (arc->from_node == lsp_top_num)
2428 to_lsp = arc->to_node;
2429
2430 /* if the length here is about to cross the FF limit, we reTLV */
2431 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2432 {
2433 /* retlv */
2434 /* the 2 is for the TL plus 1 for the virtual field */
2435 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2436 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2437 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2438 *(tlv_ptr + 2) = 0; /* virtual is zero */
2439 }
2440 /* doing this here assures us that we won't add an "empty" tlv */
2441 /* assign space for the is_neigh at the pdu end */
2442 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2443 sizeof (struct
2444 is_neigh));
2445 /* add this node to our list */
2446 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2447 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2448 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2449 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2450 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2451 is_neigh->metrics.metric_default = arc->distance;
2452 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2453 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2454 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2455 /* don't forget the length */
2456 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2457 }
jardineb5d44e2003-12-23 08:09:43 +00002458 }
2459
hassof390d2c2004-09-10 20:48:21 +00002460 /* adding dynamic hostname if needed */
2461 if (area->dynhostname)
2462 {
2463 memset (buff, 0x00, 200);
2464 sprintf (buff, "feedme%d", lsp_top_num);
2465 /* the 2 is for the TL */
2466 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2467 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2468 *(tlv_ptr + 1) = strlen (buff); /* Length */
2469 /* the -1 is to fit the length in the struct */
2470 lsp->tlv_data.hostname = (struct hostname *)
2471 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2472 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2473 }
jardineb5d44e2003-12-23 08:09:43 +00002474
2475 /* thanks to hannes, another bug bites the dust */
hassof390d2c2004-09-10 20:48:21 +00002476 lsp->pdu->putp = ntohs (lsp->lsp_header->pdu_len);
2477 lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00002478}
2479#endif /* TOPOLOGY_GENERATE */