blob: 52d8884ddddac33af4a051d4515d18a41a507d34 [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);
jardineb5d44e2003-12-23 08:09:43 +0000372 lsp->pdu->getp = stream->getp;
373 lsp->pdu->endp = stream->endp;
374 memcpy (lsp->pdu->data, stream->data, stream->endp);
375
376 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000377 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
378 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
379 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000380 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000381 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000382 /*
383 * Get LSP data i.e. TLVs
384 */
385 expected |= TLVFLAG_AUTH_INFO;
386 expected |= TLVFLAG_AREA_ADDRS;
387 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000388 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000389 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
390 expected |= TLVFLAG_NLPID;
391 if (area->dynhostname)
392 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000393 if (area->newmetric)
394 {
395 expected |= TLVFLAG_TE_IS_NEIGHS;
396 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
397 expected |= TLVFLAG_TE_ROUTER_ID;
398 }
jardineb5d44e2003-12-23 08:09:43 +0000399 expected |= TLVFLAG_IPV4_ADDR;
400 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
401 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
402#ifdef HAVE_IPV6
403 expected |= TLVFLAG_IPV6_ADDR;
404 expected |= TLVFLAG_IPV6_REACHABILITY;
405#endif /* HAVE_IPV6 */
406
407 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000408 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
409 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
410 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000411
hassof390d2c2004-09-10 20:48:21 +0000412 if (found & TLVFLAG_DYN_HOSTNAME)
413 {
414 if (area->dynhostname)
415 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
416 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
417 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
418 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
419 }
jardineb5d44e2003-12-23 08:09:43 +0000420
421}
422
423void
424lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +0000425 struct stream *stream, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000426{
hassof390d2c2004-09-10 20:48:21 +0000427 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000428 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
429 lsp_clear_data (lsp);
430
431 /* rebuild the lsp data */
432 lsp_update_data (lsp, stream, area);
433
hassof390d2c2004-09-10 20:48:21 +0000434 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000435 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000436}
437
jardineb5d44e2003-12-23 08:09:43 +0000438/* creation of LSP directly from what we received */
439struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000440lsp_new_from_stream_ptr (struct stream *stream,
441 u_int16_t pdu_len, struct isis_lsp *lsp0,
442 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000443{
444 struct isis_lsp *lsp;
445
446 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
447 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000448
jardineb5d44e2003-12-23 08:09:43 +0000449 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000450
451 if (lsp0 == NULL)
452 {
453 /*
454 * zero lsp -> create the list for fragments
455 */
456 lsp->lspu.frags = list_new ();
457 }
458 else
459 {
460 /*
461 * a fragment -> set the backpointer and add this to zero lsps frag list
462 */
463 lsp->lspu.zero_lsp = lsp0;
464 listnode_add (lsp0->lspu.frags, lsp);
465 }
466
jardineb5d44e2003-12-23 08:09:43 +0000467 return lsp;
468}
469
470struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000471lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
472 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000473{
474 struct isis_lsp *lsp;
475
476 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000477 if (!lsp)
478 {
479 /* FIXME: set lspdbol bit */
480 zlog_warn ("lsp_new(): out of memory");
481 return NULL;
482 }
jardineb5d44e2003-12-23 08:09:43 +0000483 memset (lsp, 0, sizeof (struct isis_lsp));
484#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000485 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000486#else
hassof390d2c2004-09-10 20:48:21 +0000487 /* We need to do realloc on TLVs additions */
488 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000489#endif /* LSP_MEMORY_PREASSIGN */
490 if (LSP_FRAGMENT (lsp_id) == 0)
491 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000492 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
493 lsp->lsp_header = (struct isis_link_state_hdr *)
494 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
495
jardineb5d44e2003-12-23 08:09:43 +0000496 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000497 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
498 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
499
jardineb5d44e2003-12-23 08:09:43 +0000500 /* now for the LSP HEADER */
501 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000502 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000503 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000504 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000505 lsp->lsp_header->seq_num = htonl (seq_num);
506 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
507 lsp->lsp_header->lsp_bits = lsp_bits;
508 lsp->level = level;
509 lsp->age_out = ZERO_AGE_LIFETIME;
510
paul9985f832005-02-09 15:51:56 +0000511 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000512
513 /* #ifdef EXTREME_DEBUG */
514 /* logging */
hasso529d65b2004-12-24 00:14:50 +0000515 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
516 LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
517 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
518 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000519 /* #endif EXTREME DEBUG */
520
521 return lsp;
522}
523
524void
hassof390d2c2004-09-10 20:48:21 +0000525lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000526{
527 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
528}
529
530/*
531 * Build a list of LSPs with non-zero ht bounded by start and stop ids
532 */
hassof390d2c2004-09-10 20:48:21 +0000533void
534lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
535 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000536{
537 dnode_t *first, *last, *curr;
538
539 first = dict_lower_bound (lspdb, start_id);
540 if (!first)
541 return;
hassof390d2c2004-09-10 20:48:21 +0000542
jardineb5d44e2003-12-23 08:09:43 +0000543 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000544
jardineb5d44e2003-12-23 08:09:43 +0000545 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000546
547 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000548 listnode_add (list, first->dict_data);
549
hassof390d2c2004-09-10 20:48:21 +0000550 while (curr)
551 {
552 curr = dict_next (lspdb, curr);
553 if (curr &&
554 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
555 listnode_add (list, curr->dict_data);
556 if (curr == last)
557 break;
558 }
559
jardineb5d44e2003-12-23 08:09:43 +0000560 return;
561}
562
563/*
564 * Build a list of all LSPs bounded by start and stop ids
565 */
hassof390d2c2004-09-10 20:48:21 +0000566void
567lsp_build_list (u_char * start_id, u_char * stop_id,
568 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000569{
570 dnode_t *first, *last, *curr;
571
572 first = dict_lower_bound (lspdb, start_id);
573 if (!first)
574 return;
hassof390d2c2004-09-10 20:48:21 +0000575
jardineb5d44e2003-12-23 08:09:43 +0000576 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000577
jardineb5d44e2003-12-23 08:09:43 +0000578 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000579
jardineb5d44e2003-12-23 08:09:43 +0000580 listnode_add (list, first->dict_data);
581
hassof390d2c2004-09-10 20:48:21 +0000582 while (curr)
583 {
584 curr = dict_next (lspdb, curr);
585 if (curr)
586 listnode_add (list, curr->dict_data);
587 if (curr == last)
588 break;
589 }
590
jardineb5d44e2003-12-23 08:09:43 +0000591 return;
592}
593
594/*
595 * Build a list of LSPs with SSN flag set for the given circuit
596 */
597void
hassof390d2c2004-09-10 20:48:21 +0000598lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
599 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000600{
601 dnode_t *dnode, *next;
602 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000603
jardineb5d44e2003-12-23 08:09:43 +0000604 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000605 while (dnode != NULL)
606 {
607 next = dict_next (lspdb, dnode);
608 lsp = dnode_get (dnode);
609 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
610 listnode_add (list, lsp);
611 dnode = next;
612 }
613
jardineb5d44e2003-12-23 08:09:43 +0000614 return;
615}
616
hasso92365882005-01-18 13:53:33 +0000617static void
jardineb5d44e2003-12-23 08:09:43 +0000618lsp_set_time (struct isis_lsp *lsp)
619{
620 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000621
622 if (lsp->lsp_header->rem_lifetime == 0)
623 {
624 if (lsp->age_out != 0)
625 lsp->age_out--;
626 return;
627 }
jardineb5d44e2003-12-23 08:09:43 +0000628
629 /* If we are turning 0 */
630 /* ISO 10589 - 7.3.16.4 first paragraph */
631
hassof390d2c2004-09-10 20:48:21 +0000632 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
633 {
634 /* 7.3.16.4 a) set SRM flags on all */
635 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
636 /* 7.3.16.4 b) retain only the header FIXME */
637 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
638 }
jardineb5d44e2003-12-23 08:09:43 +0000639
hassof390d2c2004-09-10 20:48:21 +0000640 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000641 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
642}
643
hasso92365882005-01-18 13:53:33 +0000644static void
hassof390d2c2004-09-10 20:48:21 +0000645lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000646{
647 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000648 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000649
650 if (dynhost)
651 dyn = dynhn_find_by_id (lsp_id);
652 else
653 dyn = NULL;
654
655 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000656 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000657 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000658 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000659 else
hassof390d2c2004-09-10 20:48:21 +0000660 {
661 memcpy (id, sysid_print (lsp_id), 15);
662 }
663 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000664 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000665 LSP_FRAGMENT (lsp_id));
666 else
hassof7c43dc2004-09-26 16:24:14 +0000667 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000668}
669
hassof390d2c2004-09-10 20:48:21 +0000670/* Convert the lsp attribute bits to attribute string */
hasso1cd80842004-10-07 20:07:40 +0000671const char *
hassof390d2c2004-09-10 20:48:21 +0000672lsp_bits2string (u_char * lsp_bits)
673{
674 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000675
hassof390d2c2004-09-10 20:48:21 +0000676 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000677 return " none";
678
679 /* we only focus on the default metric */
680 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000681 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000682
683 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000684 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000685
hassof390d2c2004-09-10 20:48:21 +0000686 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
687
jardineb5d44e2003-12-23 08:09:43 +0000688 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000689
hassof390d2c2004-09-10 20:48:21 +0000690 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000691}
692
693/* this function prints the lsp on show isis database */
hasso92365882005-01-18 13:53:33 +0000694static void
hassof390d2c2004-09-10 20:48:21 +0000695lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000696{
hassof390d2c2004-09-10 20:48:21 +0000697 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000698 u_char LSPid[255];
699
700 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000701 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
702 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
703 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000704
hassof390d2c2004-09-10 20:48:21 +0000705 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
706 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000707 else
hassof390d2c2004-09-10 20:48:21 +0000708 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000709
710 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000711 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000712}
713
hasso92365882005-01-18 13:53:33 +0000714static void
hassof390d2c2004-09-10 20:48:21 +0000715lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000716{
717 struct isis_lsp *lsp = dnode_get (node);
718 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000719 int i;
jardineb5d44e2003-12-23 08:09:43 +0000720 struct listnode *lnode;
721 struct is_neigh *is_neigh;
722 struct te_is_neigh *te_is_neigh;
723 struct ipv4_reachability *ipv4_reach;
724 struct in_addr *ipv4_addr;
725 struct te_ipv4_reachability *te_ipv4_reach;
726#ifdef HAVE_IPV6
727 struct ipv6_reachability *ipv6_reach;
728 struct in6_addr in6;
729#endif
730 u_char LSPid[255];
731 u_char hostname[255];
732 u_char buff[BUFSIZ];
jardineb5d44e2003-12-23 08:09:43 +0000733 u_char ipv4_reach_prefix[20];
734 u_char ipv4_reach_mask[20];
735 u_char ipv4_address[20];
736
737 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000738 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000739
740 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000741 if (lsp->tlv_data.area_addrs)
742 {
743 LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode)
744 {
hasso1cd80842004-10-07 20:07:40 +0000745 vty_out (vty, " Area Address: %s%s",
hassof390d2c2004-09-10 20:48:21 +0000746 isonet_print (area_addr->area_addr, area_addr->addr_len),
747 VTY_NEWLINE);
748 }
jardineb5d44e2003-12-23 08:09:43 +0000749 }
jardineb5d44e2003-12-23 08:09:43 +0000750
751 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000752 if (lsp->tlv_data.nlpids)
753 {
754 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
755 {
756 switch (lsp->tlv_data.nlpids->nlpids[i])
757 {
758 case NLPID_IP:
759 case NLPID_IPV6:
hasso1cd80842004-10-07 20:07:40 +0000760 vty_out (vty, " NLPID: 0x%X%s",
hassof390d2c2004-09-10 20:48:21 +0000761 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
762 break;
763 default:
hasso1cd80842004-10-07 20:07:40 +0000764 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000765 break;
766 }
767 }
768 }
jardineb5d44e2003-12-23 08:09:43 +0000769
770 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000771 if (lsp->tlv_data.hostname)
772 {
773 bzero (hostname, sizeof (hostname));
774 memcpy (hostname, lsp->tlv_data.hostname->name,
775 lsp->tlv_data.hostname->namelen);
776 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000777 }
hassof390d2c2004-09-10 20:48:21 +0000778
779 if (lsp->tlv_data.ipv4_addrs)
780 {
781 LIST_LOOP (lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode)
782 {
783 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
784 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
785 }
786 }
787
hasso1cd80842004-10-07 20:07:40 +0000788 /* TE router id */
789 if (lsp->tlv_data.router_id)
790 {
791 memcpy (ipv4_address, inet_ntoa (lsp->tlv_data.router_id->id),
792 sizeof (ipv4_address));
793 vty_out (vty, " Router ID: %s%s", ipv4_address, VTY_NEWLINE);
794 }
795
796 /* for the IS neighbor tlv */
797 if (lsp->tlv_data.is_neighs)
798 {
799 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
800 {
801 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
802 vty_out (vty, " Metric: %d IS %s%s",
803 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
804 }
805 }
806
jardineb5d44e2003-12-23 08:09:43 +0000807 /* for the internal reachable tlv */
808 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000809 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
810 {
811 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
812 sizeof (ipv4_reach_prefix));
813 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
814 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000815 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000816 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
817 ipv4_reach_mask, VTY_NEWLINE);
818 }
hasso2097cd82003-12-23 11:51:08 +0000819
820 /* for the external reachable tlv */
821 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000822 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
823 {
824 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
825 sizeof (ipv4_reach_prefix));
826 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
827 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000828 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000829 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
830 ipv4_reach_mask, VTY_NEWLINE);
831 }
jardineb5d44e2003-12-23 08:09:43 +0000832
hasso2097cd82003-12-23 11:51:08 +0000833 /* IPv6 tlv */
834#ifdef HAVE_IPV6
835 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000836 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
837 {
838 memset (&in6, 0, sizeof (in6));
839 memcpy (in6.s6_addr, ipv6_reach->prefix,
840 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000841 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000842 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000843 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
844 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
845 ntohl (ipv6_reach->metric),
846 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000847 else
hassof390d2c2004-09-10 20:48:21 +0000848 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
849 ntohl (ipv6_reach->metric),
850 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000851 }
852#endif
hasso1cd80842004-10-07 20:07:40 +0000853 /* TE IS neighbor tlv */
jardineb5d44e2003-12-23 08:09:43 +0000854 if (lsp->tlv_data.te_is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000855 LIST_LOOP (lsp->tlv_data.te_is_neighs, te_is_neigh, lnode)
856 {
hasso1cd80842004-10-07 20:07:40 +0000857 /* FIXME: metric display is wrong. */
hassof390d2c2004-09-10 20:48:21 +0000858 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
hasso1cd80842004-10-07 20:07:40 +0000859 vty_out (vty, " Metric: %d extd-IS %s%s",
860 te_is_neigh->te_metric[0], LSPid, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000861 }
jardineb5d44e2003-12-23 08:09:43 +0000862
hasso1cd80842004-10-07 20:07:40 +0000863 /* TE IPv4 tlv */
jardineb5d44e2003-12-23 08:09:43 +0000864 if (lsp->tlv_data.te_ipv4_reachs)
hassof390d2c2004-09-10 20:48:21 +0000865 LIST_LOOP (lsp->tlv_data.te_ipv4_reachs, te_ipv4_reach, lnode)
866 {
hasso1cd80842004-10-07 20:07:40 +0000867 /* FIXME: There should be better way to output this stuff. */
hasso2e864cf2004-10-08 06:40:24 +0000868 vty_out (vty, " Metric: %d extd-IP %s/%d%s",
hasso1cd80842004-10-07 20:07:40 +0000869 ntohl (te_ipv4_reach->te_metric),
hassof390d2c2004-09-10 20:48:21 +0000870 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
871 te_ipv4_reach->control)),
hasso1cd80842004-10-07 20:07:40 +0000872 te_ipv4_reach->control & 0x3F, VTY_NEWLINE);
hassof390d2c2004-09-10 20:48:21 +0000873 }
jardineb5d44e2003-12-23 08:09:43 +0000874
hassof390d2c2004-09-10 20:48:21 +0000875 return;
jardineb5d44e2003-12-23 08:09:43 +0000876}
877
878/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000879int
880lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000881{
882
hassof390d2c2004-09-10 20:48:21 +0000883 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000884 int lsp_count = 0;
885
886 /* print the title, for both modes */
887 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000888 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
889
890 if (detail == ISIS_UI_LEVEL_BRIEF)
891 {
892 while (node != NULL)
893 {
894 /* I think it is unnecessary, so I comment it out */
895 /* dict_contains (lspdb, node); */
896 next = dict_next (lspdb, node);
897 lsp_print (node, vty, dynhost);
898 node = next;
899 lsp_count++;
900 }
jardineb5d44e2003-12-23 08:09:43 +0000901 }
hassof390d2c2004-09-10 20:48:21 +0000902 else if (detail == ISIS_UI_LEVEL_DETAIL)
903 {
904 while (node != NULL)
905 {
906 next = dict_next (lspdb, node);
907 lsp_print_detail (node, vty, dynhost);
908 node = next;
909 lsp_count++;
910 }
jardineb5d44e2003-12-23 08:09:43 +0000911 }
jardineb5d44e2003-12-23 08:09:43 +0000912
913 return lsp_count;
914}
915
hasso92365882005-01-18 13:53:33 +0000916#if 0 /* Seems to be old code */
jardineb5d44e2003-12-23 08:09:43 +0000917/* this function reallocate memory to an lsp pdu, with an additional
918 * size of memory, it scans the lsp and moves all pointers the
919 * way they should */
hasso92365882005-01-18 13:53:33 +0000920static u_char *
hassof390d2c2004-09-10 20:48:21 +0000921lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +0000922{
923 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +0000924
925 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +0000926#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000927 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +0000928 return retval;
hassof390d2c2004-09-10 20:48:21 +0000929#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +0000930 u_char *newpdu;
931 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassof390d2c2004-09-10 20:48:21 +0000932 memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu),
933 ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +0000934 XFREE (memorytype, lsp->pdu);
935 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +0000936 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
937 lsp->lsp_header = (struct isis_link_state_hdr *)
938 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000939 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +0000940 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +0000941#endif /* LSP_MEMORY_PREASSIGN */
942}
hasso92365882005-01-18 13:53:33 +0000943#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +0000944
hassof390d2c2004-09-10 20:48:21 +0000945#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +0000946/*
947 * Builds the lsp->tlv_data
948 * and writes the tlvs into lsp->pdu
949 */
950void
951lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
952{
953 struct is_neigh *is_neigh;
954 struct listnode *node, *ipnode;
955 int level = lsp->level;
956 struct isis_circuit *circuit;
957 struct prefix_ipv4 *ipv4;
958 struct ipv4_reachability *ipreach;
959 struct isis_adjacency *nei;
960#ifdef HAVE_IPV6
961 struct prefix_ipv6 *ipv6;
962 struct ipv6_reachability *ip6reach;
963#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000964
jardineb5d44e2003-12-23 08:09:43 +0000965 /*
966 * First add the tlvs related to area
967 */
hassof390d2c2004-09-10 20:48:21 +0000968
jardineb5d44e2003-12-23 08:09:43 +0000969 /* Area addresses */
970 if (lsp->tlv_data.area_addrs == NULL)
971 lsp->tlv_data.area_addrs = list_new ();
972 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
973 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +0000974 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +0000975#ifdef HAVE_IPV6
976 || area->ipv6_circuits > 0
977#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000978 )
jardineb5d44e2003-12-23 08:09:43 +0000979 {
980 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
981 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +0000982 if (area->ip_circuits > 0)
983 {
984 lsp->tlv_data.nlpids->count++;
985 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
986 }
jardineb5d44e2003-12-23 08:09:43 +0000987#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +0000988 if (area->ipv6_circuits > 0)
989 {
990 lsp->tlv_data.nlpids->count++;
991 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
992 NLPID_IPV6;
993 }
jardineb5d44e2003-12-23 08:09:43 +0000994#endif /* HAVE_IPV6 */
995 }
996 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +0000997 if (area->dynhostname)
998 {
999 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1000 sizeof (struct hostname));
1001 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
1002 strlen (unix_hostname ()));
1003 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1004 }
jardineb5d44e2003-12-23 08:09:43 +00001005#ifdef TOPOLOGY_GENERATE
1006 /*
1007 * If we have a topology in this area, we need to connect this lsp to
1008 * the first topology lsp
1009 */
hassof390d2c2004-09-10 20:48:21 +00001010 if ((area->topology) && (level == 1))
1011 {
1012 if (lsp->tlv_data.is_neighs == NULL)
1013 lsp->tlv_data.is_neighs = list_new ();
1014 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1015 memset (is_neigh, 0, sizeof (struct is_neigh));
1016 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1017 /* connected to the first */
1018 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1019 /* this is actually the same system, why mess the SPT */
1020 is_neigh->metrics.metric_default = 0;
1021 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1022 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1023 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1024 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001025
hassof390d2c2004-09-10 20:48:21 +00001026 }
jardineb5d44e2003-12-23 08:09:43 +00001027#endif
1028
1029 /*
1030 * Then add tlvs related to circuits
1031 */
hassof390d2c2004-09-10 20:48:21 +00001032 for (node = listhead (area->circuit_list); node; nextnode (node))
1033 {
1034 circuit = getdata (node);
1035 if (circuit->state != C_STATE_UP)
1036 continue;
1037
1038 /*
1039 * Add IPv4 internal reachability of this circuit
1040 */
1041 if (circuit->ip_router && circuit->ip_addrs &&
1042 circuit->ip_addrs->count > 0)
1043 {
1044 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1045 {
1046 lsp->tlv_data.ipv4_int_reachs = list_new ();
1047 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1048 }
1049 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1050 nextnode (ipnode))
1051 {
1052 ipv4 = getdata (ipnode);
1053 ipreach =
1054 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1055 ipreach->metrics = circuit->metrics[level - 1];
1056 ipreach->prefix = ipv4->prefix;
1057 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1058 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1059 }
1060 }
jardineb5d44e2003-12-23 08:09:43 +00001061#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001062 /*
1063 * Add IPv6 reachability of this circuit
1064 */
1065 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1066 circuit->ipv6_non_link->count > 0)
1067 {
1068 if (lsp->tlv_data.ipv6_reachs == NULL)
1069 {
1070 lsp->tlv_data.ipv6_reachs = list_new ();
1071 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1072 }
1073 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1074 nextnode (ipnode))
1075 {
1076 ipv6 = getdata (ipnode);
1077 ip6reach =
1078 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1079 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1080 ip6reach->metric =
1081 htonl (circuit->metrics[level - 1].metric_default);
1082 ip6reach->control_info = 0;
1083 ip6reach->prefix_len = ipv6->prefixlen;
1084 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1085 (ipv6->prefixlen + 7) / 8);
1086 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1087 }
1088 }
jardineb5d44e2003-12-23 08:09:43 +00001089#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001090
1091 switch (circuit->circ_type)
1092 {
1093 case CIRCUIT_T_BROADCAST:
1094 if (level & circuit->circuit_is_type)
1095 {
1096 if (lsp->tlv_data.is_neighs == NULL)
1097 {
1098 lsp->tlv_data.is_neighs = list_new ();
1099 lsp->tlv_data.is_neighs->del = free_tlv;
1100 }
1101 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1102 memset (is_neigh, 0, sizeof (struct is_neigh));
1103 if (level == 1)
1104 memcpy (&is_neigh->neigh_id,
1105 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1106 else
1107 memcpy (&is_neigh->neigh_id,
1108 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1109 is_neigh->metrics = circuit->metrics[level - 1];
1110 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1111 }
1112 break;
1113 case CIRCUIT_T_P2P:
1114 nei = circuit->u.p2p.neighbor;
1115 if (nei && (level & nei->circuit_t))
1116 {
1117 if (lsp->tlv_data.is_neighs == NULL)
1118 {
1119 lsp->tlv_data.is_neighs = list_new ();
1120 lsp->tlv_data.is_neighs->del = free_tlv;
1121 }
1122 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1123 memset (is_neigh, 0, sizeof (struct is_neigh));
1124 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1125 is_neigh->metrics = circuit->metrics[level - 1];
1126 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1127 }
1128 break;
1129 case CIRCUIT_T_STATIC_IN:
1130 zlog_warn ("lsp_area_create: unsupported circuit type");
1131 break;
1132 case CIRCUIT_T_STATIC_OUT:
1133 zlog_warn ("lsp_area_create: unsupported circuit type");
1134 break;
1135 case CIRCUIT_T_DA:
1136 zlog_warn ("lsp_area_create: unsupported circuit type");
1137 break;
1138 default:
1139 zlog_warn ("lsp_area_create: unknown circuit type");
1140 }
jardineb5d44e2003-12-23 08:09:43 +00001141 }
hassof390d2c2004-09-10 20:48:21 +00001142
paul9985f832005-02-09 15:51:56 +00001143 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00001144
jardineb5d44e2003-12-23 08:09:43 +00001145 if (lsp->tlv_data.nlpids)
1146 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1147 if (lsp->tlv_data.hostname)
1148 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001149 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001150 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1151 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1152 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001153 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001154 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1155 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001156#ifdef HAVE_IPV6
1157 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001158 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1159#endif /* HAVE_IPV6 */
1160
paul9985f832005-02-09 15:51:56 +00001161 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001162
1163 return;
1164}
1165#endif
1166
1167#define FRAG_THOLD(S,T) \
1168((STREAM_SIZE(S)*T)/100)
1169
1170/* stream*, area->lsp_frag_threshold, increment */
1171#define FRAG_NEEDED(S,T,I) \
1172 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1173
hasso92365882005-01-18 13:53:33 +00001174static void
jardineb5d44e2003-12-23 08:09:43 +00001175lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001176 int tlvsize, int frag_thold,
1177 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001178{
1179 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001180
jardineb5d44e2003-12-23 08:09:43 +00001181 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001182 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1183 {
1184 tlv_build_func (*from, lsp->pdu);
1185 *to = *from;
1186 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001187 }
hassof390d2c2004-09-10 20:48:21 +00001188 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1189 {
1190 /* fit all we can */
1191 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1192 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1193 if (count)
1194 count = count / tlvsize;
1195 for (i = 0; i < count; i++)
1196 {
1197 listnode_add (*to, getdata (listhead (*from)));
1198 listnode_delete (*from, getdata (listhead (*from)));
1199 }
1200 tlv_build_func (*to, lsp->pdu);
1201 }
paul9985f832005-02-09 15:51:56 +00001202 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001203 return;
1204}
1205
hasso92365882005-01-18 13:53:33 +00001206static struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +00001207lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1208 int level)
jardineb5d44e2003-12-23 08:09:43 +00001209{
1210 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001211 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1212
jardineb5d44e2003-12-23 08:09:43 +00001213 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1214 LSP_FRAGMENT (frag_id) = frag_num;
1215 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001216 if (lsp)
1217 {
1218 /*
1219 * Clear the TLVs, but inherit the authinfo
1220 */
1221 lsp_clear_data (lsp);
1222 if (lsp0->tlv_data.auth_info.type)
1223 {
1224 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1225 sizeof (struct isis_passwd));
1226 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1227 lsp->tlv_data.auth_info.len,
1228 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1229 }
1230 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001231 }
jardineb5d44e2003-12-23 08:09:43 +00001232 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001233 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001234 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001235 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001236 listnode_add (lsp0->lspu.frags, lsp);
1237 lsp->lspu.zero_lsp = lsp0;
1238 /*
1239 * Copy the authinfo from zero LSP
1240 */
hassof390d2c2004-09-10 20:48:21 +00001241 if (lsp0->tlv_data.auth_info.type)
1242 {
1243 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1244 sizeof (struct isis_passwd));
1245 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1246 lsp->tlv_data.auth_info.len,
1247 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1248 }
jardineb5d44e2003-12-23 08:09:43 +00001249 return lsp;
1250}
1251
1252/*
1253 * Builds the LSP data part. This func creates a new frag whenever
1254 * area->lsp_frag_threshold is exceeded.
1255 */
1256#if 1
hasso92365882005-01-18 13:53:33 +00001257static void
jardineb5d44e2003-12-23 08:09:43 +00001258lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1259{
1260 struct is_neigh *is_neigh;
1261 struct listnode *node, *ipnode;
1262 int level = lsp->level;
1263 struct isis_circuit *circuit;
1264 struct prefix_ipv4 *ipv4;
1265 struct ipv4_reachability *ipreach;
1266 struct isis_adjacency *nei;
1267#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001268 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001269 struct ipv6_reachability *ip6reach;
1270#endif /* HAVE_IPV6 */
1271 struct tlvs tlv_data;
1272 struct isis_lsp *lsp0 = lsp;
1273 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001274 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001275
1276 /*
1277 * First add the tlvs related to area
1278 */
hassof390d2c2004-09-10 20:48:21 +00001279
jardineb5d44e2003-12-23 08:09:43 +00001280 /* Area addresses */
1281 if (lsp->tlv_data.area_addrs == NULL)
1282 lsp->tlv_data.area_addrs = list_new ();
1283 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1284 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001285 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001286#ifdef HAVE_IPV6
1287 || area->ipv6_circuits > 0
1288#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001289 )
jardineb5d44e2003-12-23 08:09:43 +00001290 {
1291 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1292 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001293 if (area->ip_circuits > 0)
1294 {
1295 lsp->tlv_data.nlpids->count++;
1296 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1297 }
jardineb5d44e2003-12-23 08:09:43 +00001298#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001299 if (area->ipv6_circuits > 0)
1300 {
1301 lsp->tlv_data.nlpids->count++;
1302 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1303 NLPID_IPV6;
1304 }
jardineb5d44e2003-12-23 08:09:43 +00001305#endif /* HAVE_IPV6 */
1306 }
1307 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001308 if (area->dynhostname)
1309 {
1310 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1311 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001312
hassof390d2c2004-09-10 20:48:21 +00001313 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1314 strlen (unix_hostname ()));
1315 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1316 }
jardineb5d44e2003-12-23 08:09:43 +00001317
1318 /*
1319 * Building the zero lsp
1320 */
paul9985f832005-02-09 15:51:56 +00001321 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001322 /*
1323 * Add the authentication info if its present
1324 */
hassof390d2c2004-09-10 20:48:21 +00001325 (level == 1) ? (passwd = &area->area_passwd) :
1326 (passwd = &area->domain_passwd);
1327 if (passwd->type)
1328 {
1329 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1330 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1331 }
jardineb5d44e2003-12-23 08:09:43 +00001332 if (lsp->tlv_data.nlpids)
1333 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1334 if (lsp->tlv_data.hostname)
1335 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001336 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001337 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001338
jardineb5d44e2003-12-23 08:09:43 +00001339 memset (&tlv_data, 0, sizeof (struct tlvs));
1340 /*
hasso18a6dce2004-10-03 18:18:34 +00001341 * IPv4 address TLV. We don't follow "C" vendor, but "J" vendor behavior -
1342 * one IPv4 address is put into LSP and this address is same as router id.
1343 */
1344 if (router_id_zebra.s_addr != 0)
1345 {
hasso18a6dce2004-10-03 18:18:34 +00001346 if (lsp->tlv_data.ipv4_addrs == NULL)
1347 lsp->tlv_data.ipv4_addrs = list_new ();
1348
1349 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1350 routerid->s_addr = router_id_zebra.s_addr;
1351
1352 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
1353
1354 /*
1355 * FIXME: Using add_tlv() directly is hack, but tlv_add_ip_addrs()
1356 * expects list of prefix_ipv4 structures, but we have list of
1357 * in_addr structures.
1358 */
1359 add_tlv (IPV4_ADDR, IPV4_MAX_BYTELEN, (u_char *) &routerid->s_addr,
1360 lsp->pdu);
1361 }
1362 /*
jardineb5d44e2003-12-23 08:09:43 +00001363 * Then build lists of tlvs related to circuits
1364 */
hassof390d2c2004-09-10 20:48:21 +00001365 for (node = listhead (area->circuit_list); node; nextnode (node))
1366 {
1367 circuit = getdata (node);
1368 if (circuit->state != C_STATE_UP)
1369 continue;
jardineb5d44e2003-12-23 08:09:43 +00001370
hassof390d2c2004-09-10 20:48:21 +00001371 /*
1372 * Add IPv4 internal reachability of this circuit
1373 */
1374 if (circuit->ip_router && circuit->ip_addrs &&
1375 circuit->ip_addrs->count > 0)
1376 {
1377 if (tlv_data.ipv4_int_reachs == NULL)
1378 {
1379 tlv_data.ipv4_int_reachs = list_new ();
1380 }
1381 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1382 nextnode (ipnode))
1383 {
1384 ipv4 = getdata (ipnode);
1385 ipreach =
1386 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1387 ipreach->metrics = circuit->metrics[level - 1];
hassof390d2c2004-09-10 20:48:21 +00001388 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001389 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1390 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001391 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1392 }
1393
1394 }
jardineb5d44e2003-12-23 08:09:43 +00001395#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001396 /*
1397 * Add IPv6 reachability of this circuit
1398 */
1399 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1400 circuit->ipv6_non_link->count > 0)
1401 {
1402
1403 if (tlv_data.ipv6_reachs == NULL)
1404 {
1405 tlv_data.ipv6_reachs = list_new ();
1406 }
1407 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1408 nextnode (ipnode))
1409 {
1410 ipv6 = getdata (ipnode);
1411 ip6reach =
1412 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1413 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1414 ip6reach->metric =
1415 htonl (circuit->metrics[level - 1].metric_default);
1416 ip6reach->control_info = 0;
1417 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001418 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1419 apply_mask_ipv6 (ip6prefix);
1420 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1421 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001422 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1423 }
1424 }
1425#endif /* HAVE_IPV6 */
1426
1427 switch (circuit->circ_type)
1428 {
1429 case CIRCUIT_T_BROADCAST:
1430 if (level & circuit->circuit_is_type)
1431 {
1432 if (tlv_data.is_neighs == NULL)
1433 {
1434 tlv_data.is_neighs = list_new ();
1435 }
1436 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1437 memset (is_neigh, 0, sizeof (struct is_neigh));
1438 if (level == 1)
1439 memcpy (is_neigh->neigh_id,
1440 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1441 else
1442 memcpy (is_neigh->neigh_id,
1443 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1444 is_neigh->metrics = circuit->metrics[level - 1];
1445 listnode_add (tlv_data.is_neighs, is_neigh);
1446 }
1447 break;
1448 case CIRCUIT_T_P2P:
1449 nei = circuit->u.p2p.neighbor;
1450 if (nei && (level & nei->circuit_t))
1451 {
1452 if (tlv_data.is_neighs == NULL)
1453 {
1454 tlv_data.is_neighs = list_new ();
1455 tlv_data.is_neighs->del = free_tlv;
1456 }
1457 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1458 memset (is_neigh, 0, sizeof (struct is_neigh));
1459 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1460 is_neigh->metrics = circuit->metrics[level - 1];
1461 listnode_add (tlv_data.is_neighs, is_neigh);
1462 }
1463 break;
1464 case CIRCUIT_T_STATIC_IN:
1465 zlog_warn ("lsp_area_create: unsupported circuit type");
1466 break;
1467 case CIRCUIT_T_STATIC_OUT:
1468 zlog_warn ("lsp_area_create: unsupported circuit type");
1469 break;
1470 case CIRCUIT_T_DA:
1471 zlog_warn ("lsp_area_create: unsupported circuit type");
1472 break;
1473 default:
1474 zlog_warn ("lsp_area_create: unknown circuit type");
1475 }
1476 }
1477
1478 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1479 {
1480 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1481 lsp->tlv_data.ipv4_int_reachs = list_new ();
1482 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1483 &lsp->tlv_data.ipv4_int_reachs,
1484 IPV4_REACH_LEN, area->lsp_frag_threshold,
1485 tlv_add_ipv4_reachs);
1486 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1487 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1488 lsp0, area, level);
1489 }
1490
1491#ifdef HAVE_IPV6
1492 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1493 {
1494 if (lsp->tlv_data.ipv6_reachs == NULL)
1495 lsp->tlv_data.ipv6_reachs = list_new ();
1496 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1497 &lsp->tlv_data.ipv6_reachs,
1498 IPV6_REACH_LEN, area->lsp_frag_threshold,
1499 tlv_add_ipv6_reachs);
1500 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1501 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1502 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001503 }
1504#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001505
1506 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1507 {
1508 if (lsp->tlv_data.is_neighs == NULL)
1509 lsp->tlv_data.is_neighs = list_new ();
1510 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1511 &lsp->tlv_data.is_neighs,
1512 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1513 tlv_add_is_neighs);
1514 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1515 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1516 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001517 }
jardineb5d44e2003-12-23 08:09:43 +00001518
jardineb5d44e2003-12-23 08:09:43 +00001519 return;
1520}
1521#endif
1522
hasso92365882005-01-18 13:53:33 +00001523#if 0 /* Old code? */
1524static void
jardineb5d44e2003-12-23 08:09:43 +00001525build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1526{
1527 struct list *circuit_list = area->circuit_list;
1528 struct isis_circuit *circuit;
1529 u_char *tlv_ptr;
1530 struct is_neigh *is_neigh;
1531
hassof390d2c2004-09-10 20:48:21 +00001532
jardineb5d44e2003-12-23 08:09:43 +00001533 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001534 /* the 2 is for the TL plus 1 for the nlpid */
1535 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1536 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1537 *(tlv_ptr + 1) = 1; /* one protocol */
1538#ifdef HAVE_IPV6 /*dunno if its right */
1539 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001540#else
hassof390d2c2004-09-10 20:48:21 +00001541 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001542#endif /* HAVE_IPV6 */
1543
1544 /* we should add our areas here
1545 * FIXME: we need to figure out which should be added? Adj? All? First? */
1546
1547 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001548 /* the 2 is for the TL plus 1 for the virtual field */
1549 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1550 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1551 *(tlv_ptr + 2) = 0; /* virtual is zero */
1552 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001553 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001554 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1555 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001556 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001557 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001558 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001559 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001560 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001561 circuit = (struct isis_circuit *) listhead (circuit_list);
1562 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001563 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001564 *(tlv_ptr + 1) =
1565 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001566
1567 /* FIXME: scan for adjencecies and add them */
1568
1569 /* FIXME: add reachability info */
1570
hassof390d2c2004-09-10 20:48:21 +00001571 /* adding dynamic hostname if needed */
1572 if (area->dynhostname)
1573 {
1574 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1575 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1576 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1577 lsp->tlv_data.hostname = (struct hostname *)
1578 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1579 /* the -1 is to fit the length in the struct */
1580 strlen (unix_hostname ())) - 1);
1581 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1582 strlen (unix_hostname ()));
1583 }
jardineb5d44e2003-12-23 08:09:43 +00001584
1585}
hasso92365882005-01-18 13:53:33 +00001586#endif /* 0 */
jardineb5d44e2003-12-23 08:09:43 +00001587
1588/*
1589 * 7.3.7 Generation on non-pseudonode LSPs
1590 */
hasso92365882005-01-18 13:53:33 +00001591static int
hassof390d2c2004-09-10 20:48:21 +00001592lsp_generate_non_pseudo (struct isis_area *area, int level)
1593{
jardineb5d44e2003-12-23 08:09:43 +00001594 struct isis_lsp *oldlsp, *newlsp;
1595 u_int32_t seq_num = 0;
1596 u_char lspid[ISIS_SYS_ID_LEN + 2];
1597
1598 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1599 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1600
1601 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001602 if ((area->is_type & level) == level)
1603 {
1604 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1605 if (oldlsp)
1606 {
1607 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1608 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1609 area->lspdb[level - 1]);
1610 /* FIXME: we should actually initiate a purge */
1611 }
1612 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1613 area->is_type, 0, level);
1614 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001615
hassof390d2c2004-09-10 20:48:21 +00001616 lsp_insert (newlsp, area->lspdb[level - 1]);
1617 /* build_lsp_data (newlsp, area); */
1618 lsp_build_nonpseudo (newlsp, area);
1619 /* time to calculate our checksum */
1620 lsp_seqnum_update (newlsp);
1621 }
jardineb5d44e2003-12-23 08:09:43 +00001622
1623 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001624 if (isis->debugs & DEBUG_ADJ_PACKETS)
1625 {
1626 /* FIXME: is this place right? fix missing info */
hasso529d65b2004-12-24 00:14:50 +00001627 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
hassof390d2c2004-09-10 20:48:21 +00001628 }
jardineb5d44e2003-12-23 08:09:43 +00001629
1630 return ISIS_OK;
1631}
1632
1633/*
1634 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1635 */
1636int
1637lsp_l1_generate (struct isis_area *area)
1638{
hassof390d2c2004-09-10 20:48:21 +00001639 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1640 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001641
1642 return lsp_generate_non_pseudo (area, 1);
1643}
1644
jardineb5d44e2003-12-23 08:09:43 +00001645/*
1646 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1647 */
1648int
1649lsp_l2_generate (struct isis_area *area)
1650{
hassof390d2c2004-09-10 20:48:21 +00001651 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1652 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001653
1654 return lsp_generate_non_pseudo (area, 2);
1655}
1656
hasso92365882005-01-18 13:53:33 +00001657static int
jardineb5d44e2003-12-23 08:09:43 +00001658lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1659{
1660 dict_t *lspdb = area->lspdb[level - 1];
1661 struct isis_lsp *lsp, *frag;
1662 struct listnode *node;
1663 u_char lspid[ISIS_SYS_ID_LEN + 2];
1664
1665 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1666 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001667
jardineb5d44e2003-12-23 08:09:43 +00001668 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001669
hassof390d2c2004-09-10 20:48:21 +00001670 if (!lsp)
1671 {
1672 zlog_err
1673 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1674 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001675
hassof390d2c2004-09-10 20:48:21 +00001676 return ISIS_ERROR;
1677 }
1678
1679 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001680 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001681 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1682 (area->max_lsp_lifetime[level - 1],
1683 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001684 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001685
1686 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1687 {
hasso529d65b2004-12-24 00:14:50 +00001688 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1689 "seq 0x%08x, cksum 0x%04x lifetime %us",
1690 area->area_tag,
1691 level,
1692 rawlspid_print (lsp->lsp_header->lsp_id),
1693 ntohl (lsp->lsp_header->seq_num),
1694 ntohs (lsp->lsp_header->checksum),
1695 ntohs (lsp->lsp_header->rem_lifetime));
hassof390d2c2004-09-10 20:48:21 +00001696 }
jardineb5d44e2003-12-23 08:09:43 +00001697
1698 lsp->last_generated = time (NULL);
1699 area->lsp_regenerate_pending[level - 1] = 0;
1700 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001701 for (node = listhead (lsp->lspu.frags); node; nextnode (node))
1702 {
1703 frag = getdata (node);
1704 frag->lsp_header->rem_lifetime = htons (isis_jitter
1705 (area->
1706 max_lsp_lifetime[level - 1],
1707 MAX_AGE_JITTER));
1708 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1709 }
jardineb5d44e2003-12-23 08:09:43 +00001710
1711 if (area->ip_circuits)
1712 isis_spf_schedule (area, level);
1713#ifdef HAVE_IPV6
1714 if (area->ipv6_circuits)
1715 isis_spf_schedule6 (area, level);
1716#endif
1717 return ISIS_OK;
1718}
1719
jardineb5d44e2003-12-23 08:09:43 +00001720/*
1721 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1722 * time and set SRM
1723 */
hassof390d2c2004-09-10 20:48:21 +00001724int
jardineb5d44e2003-12-23 08:09:43 +00001725lsp_refresh_l1 (struct thread *thread)
1726{
1727 struct isis_area *area;
1728 unsigned long ref_time;
1729
1730 area = THREAD_ARG (thread);
1731 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001732
jardineb5d44e2003-12-23 08:09:43 +00001733 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001734 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001735 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001736
1737 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001738 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1739
hassof390d2c2004-09-10 20:48:21 +00001740 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1741 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001742
jardineb5d44e2003-12-23 08:09:43 +00001743 return ISIS_OK;
1744}
1745
hassof390d2c2004-09-10 20:48:21 +00001746int
jardineb5d44e2003-12-23 08:09:43 +00001747lsp_refresh_l2 (struct thread *thread)
1748{
1749 struct isis_area *area;
1750 unsigned long ref_time;
1751
1752 area = THREAD_ARG (thread);
1753 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001754
jardineb5d44e2003-12-23 08:09:43 +00001755 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001756 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001757 lsp_non_pseudo_regenerate (area, 2);
1758
hassof390d2c2004-09-10 20:48:21 +00001759 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001760 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1761
hassof390d2c2004-09-10 20:48:21 +00001762 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1763 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001764
jardineb5d44e2003-12-23 08:09:43 +00001765 return ISIS_OK;
1766}
1767
jardineb5d44e2003-12-23 08:09:43 +00001768/*
1769 * Something has changed -> regenerate LSP
1770 */
1771
hasso92365882005-01-18 13:53:33 +00001772static int
jardineb5d44e2003-12-23 08:09:43 +00001773lsp_l1_regenerate (struct thread *thread)
1774{
1775 struct isis_area *area;
1776
1777 area = THREAD_ARG (thread);
1778 area->lsp_regenerate_pending[0] = 0;
1779
1780 return lsp_non_pseudo_regenerate (area, 1);
1781}
1782
hasso92365882005-01-18 13:53:33 +00001783static int
jardineb5d44e2003-12-23 08:09:43 +00001784lsp_l2_regenerate (struct thread *thread)
1785{
1786 struct isis_area *area;
1787
1788 area = THREAD_ARG (thread);
1789 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001790
jardineb5d44e2003-12-23 08:09:43 +00001791 return lsp_non_pseudo_regenerate (area, 2);
1792}
1793
hassof390d2c2004-09-10 20:48:21 +00001794int
jardineb5d44e2003-12-23 08:09:43 +00001795lsp_regenerate_schedule (struct isis_area *area)
1796{
1797 struct isis_lsp *lsp;
1798 u_char id[ISIS_SYS_ID_LEN + 2];
1799 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001800 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1801 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001802 now = time (NULL);
1803 /*
1804 * First level 1
1805 */
hassof390d2c2004-09-10 20:48:21 +00001806 if (area->is_type & IS_LEVEL_1)
1807 {
1808 lsp = lsp_search (id, area->lspdb[0]);
1809 if (!lsp || area->lsp_regenerate_pending[0])
1810 goto L2;
1811 /*
1812 * Throttle avoidance
1813 */
1814 diff = now - lsp->last_generated;
1815 if (diff < MIN_LSP_GEN_INTERVAL)
1816 {
1817 area->lsp_regenerate_pending[0] = 1;
1818 thread_add_timer (master, lsp_l1_regenerate, area,
1819 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001820 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001821 }
1822 else
1823 lsp_non_pseudo_regenerate (area, 1);
1824 }
jardineb5d44e2003-12-23 08:09:43 +00001825 /*
1826 * then 2
1827 */
hassof390d2c2004-09-10 20:48:21 +00001828L2:
1829 if (area->is_type & IS_LEVEL_2)
1830 {
1831 lsp = lsp_search (id, area->lspdb[1]);
1832 if (!lsp || area->lsp_regenerate_pending[1])
1833 return ISIS_OK;
1834 /*
1835 * Throttle avoidance
1836 */
1837 diff = now - lsp->last_generated;
1838 if (diff < MIN_LSP_GEN_INTERVAL)
1839 {
1840 area->lsp_regenerate_pending[1] = 1;
1841 thread_add_timer (master, lsp_l2_regenerate, area,
1842 MIN_LSP_GEN_INTERVAL - diff);
1843 return ISIS_OK;
1844 }
1845 else
1846 lsp_non_pseudo_regenerate (area, 2);
1847 }
1848
1849 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001850}
1851
1852/*
1853 * Funcs for pseudonode LSPs
1854 */
1855
1856/*
1857 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1858 */
hasso92365882005-01-18 13:53:33 +00001859static void
hassof390d2c2004-09-10 20:48:21 +00001860lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1861 int level)
jardineb5d44e2003-12-23 08:09:43 +00001862{
1863 struct isis_adjacency *adj;
1864 struct is_neigh *is_neigh;
1865 struct es_neigh *es_neigh;
1866 struct list *adj_list;
1867 struct listnode *node;
1868 struct isis_passwd *passwd;
1869
1870 assert (circuit);
1871 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001872
jardineb5d44e2003-12-23 08:09:43 +00001873 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001874 return; /* we are not DIS on this circuit */
1875
jardineb5d44e2003-12-23 08:09:43 +00001876 lsp->level = level;
1877 if (level == 1)
1878 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1879 else
1880 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1881
1882 /*
1883 * add self to IS neighbours
1884 */
hassof390d2c2004-09-10 20:48:21 +00001885 if (lsp->tlv_data.is_neighs == NULL)
1886 {
1887 lsp->tlv_data.is_neighs = list_new ();
1888 lsp->tlv_data.is_neighs->del = free_tlv;
1889 }
jardineb5d44e2003-12-23 08:09:43 +00001890 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1891 memset (is_neigh, 0, sizeof (struct is_neigh));
1892 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1893 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001894
1895 adj_list = list_new ();
1896 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1897
1898 for (node = listhead (adj_list); node; nextnode (node))
1899 {
1900 adj = getdata (node);
1901 if (adj->circuit_t & level)
1902 {
1903 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1904 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1905 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1906 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1907 {
1908 /* an IS neighbour -> add it */
1909 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1910 memset (is_neigh, 0, sizeof (struct is_neigh));
1911 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1912 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1913 }
1914 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1915 {
1916 /* an ES neigbour add it, if we are building level 1 LSP */
1917 /* FIXME: the tlv-format is hard to use here */
1918 if (lsp->tlv_data.es_neighs == NULL)
1919 {
1920 lsp->tlv_data.es_neighs = list_new ();
1921 lsp->tlv_data.es_neighs->del = free_tlv;
1922 }
1923 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1924 memset (es_neigh, 0, sizeof (struct es_neigh));
1925 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
1926 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
1927 }
1928 }
jardineb5d44e2003-12-23 08:09:43 +00001929 }
hassof390d2c2004-09-10 20:48:21 +00001930
paul9985f832005-02-09 15:51:56 +00001931 stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001932 /*
1933 * Add the authentication info if it's present
1934 */
hassof390d2c2004-09-10 20:48:21 +00001935 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1936 (passwd = &circuit->area->domain_passwd);
1937 if (passwd->type)
1938 {
1939 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1940 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1941 }
jardineb5d44e2003-12-23 08:09:43 +00001942
1943 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1944 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1945
1946 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1947 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1948
paul9985f832005-02-09 15:51:56 +00001949 lsp->lsp_header->pdu_len = htons (stream_get_endp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00001950 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1951 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
1952
jardineb5d44e2003-12-23 08:09:43 +00001953 list_delete (adj_list);
1954
1955 return;
1956}
1957
hasso92365882005-01-18 13:53:33 +00001958static int
jardineb5d44e2003-12-23 08:09:43 +00001959lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1960{
1961 dict_t *lspdb = circuit->area->lspdb[level - 1];
1962 struct isis_lsp *lsp;
1963 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00001964
jardineb5d44e2003-12-23 08:09:43 +00001965 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001966 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
1967 LSP_FRAGMENT (lsp_id) = 0;
1968
jardineb5d44e2003-12-23 08:09:43 +00001969 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00001970
1971 if (!lsp)
1972 {
1973 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1974 rawlspid_print (lsp_id));
1975 return ISIS_ERROR;
1976 }
1977 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001978
1979 lsp_build_pseudo (lsp, circuit, level);
1980
hassof390d2c2004-09-10 20:48:21 +00001981 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00001982 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00001983 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001984
1985 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00001986
1987 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1988 {
hasso529d65b2004-12-24 00:14:50 +00001989 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1990 circuit->area->area_tag, level,
1991 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00001992 }
jardineb5d44e2003-12-23 08:09:43 +00001993
1994 lsp->last_generated = time (NULL);
1995 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001996
jardineb5d44e2003-12-23 08:09:43 +00001997 return ISIS_OK;
1998}
1999
jardineb5d44e2003-12-23 08:09:43 +00002000int
2001lsp_l1_refresh_pseudo (struct thread *thread)
2002{
2003 struct isis_circuit *circuit;
2004 int retval;
2005 unsigned long ref_time;
2006
hassof390d2c2004-09-10 20:48:21 +00002007 circuit = THREAD_ARG (thread);
2008
jardineb5d44e2003-12-23 08:09:43 +00002009 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002010 return ISIS_ERROR; /* FIXME: purge and such */
2011
hasso13c48f72004-09-10 21:19:13 +00002012 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2013
jardineb5d44e2003-12-23 08:09:43 +00002014 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002015
2016 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002017 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2018
hassof390d2c2004-09-10 20:48:21 +00002019 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2020 lsp_l1_refresh_pseudo, circuit,
2021 isis_jitter (ref_time, MAX_AGE_JITTER));
2022
jardineb5d44e2003-12-23 08:09:43 +00002023 return retval;
2024}
2025
hassof390d2c2004-09-10 20:48:21 +00002026int
jardineb5d44e2003-12-23 08:09:43 +00002027lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2028{
2029 struct isis_lsp *lsp;
2030 u_char id[ISIS_SYS_ID_LEN + 2];
2031 unsigned long ref_time;
2032
hassof390d2c2004-09-10 20:48:21 +00002033 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2034 LSP_FRAGMENT (id) = 0;
2035 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002036
2037 /*
2038 * If for some reason have a pseudo LSP in the db already -> regenerate
2039 */
2040 if (lsp_search (id, circuit->area->lspdb[0]))
2041 return lsp_pseudo_regenerate (circuit, 1);
2042 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002043 1, circuit->area->is_type, 0, 1);
2044
jardineb5d44e2003-12-23 08:09:43 +00002045 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002046
jardineb5d44e2003-12-23 08:09:43 +00002047 lsp->own_lsp = 1;
2048 lsp_insert (lsp, circuit->area->lspdb[0]);
2049 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2050
hassof390d2c2004-09-10 20:48:21 +00002051 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002052 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2053
hassof390d2c2004-09-10 20:48:21 +00002054 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2055 lsp_l1_refresh_pseudo, circuit,
2056 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002057
2058 return lsp_regenerate_schedule (circuit->area);
2059}
2060
2061int
2062lsp_l2_refresh_pseudo (struct thread *thread)
2063{
2064 struct isis_circuit *circuit;
2065 int retval;
2066 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002067 circuit = THREAD_ARG (thread);
2068
jardineb5d44e2003-12-23 08:09:43 +00002069 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002070 return ISIS_ERROR; /* FIXME: purge and such */
2071
hasso13c48f72004-09-10 21:19:13 +00002072 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2073
jardineb5d44e2003-12-23 08:09:43 +00002074 retval = lsp_pseudo_regenerate (circuit, 2);
2075
hassof390d2c2004-09-10 20:48:21 +00002076 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002077 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2078
hassof390d2c2004-09-10 20:48:21 +00002079 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2080 lsp_l2_refresh_pseudo, circuit,
2081 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002082
jardineb5d44e2003-12-23 08:09:43 +00002083 return retval;
2084}
2085
hassof390d2c2004-09-10 20:48:21 +00002086int
jardineb5d44e2003-12-23 08:09:43 +00002087lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2088{
2089 struct isis_lsp *lsp;
2090 u_char id[ISIS_SYS_ID_LEN + 2];
2091 unsigned long ref_time;
2092
hassof390d2c2004-09-10 20:48:21 +00002093 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2094 LSP_FRAGMENT (id) = 0;
2095 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002096
2097 if (lsp_search (id, circuit->area->lspdb[1]))
2098 return lsp_pseudo_regenerate (circuit, 2);
2099
2100 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002101 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002102
2103 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002104
2105 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002106 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2107
2108
2109 lsp->own_lsp = 1;
2110 lsp_insert (lsp, circuit->area->lspdb[1]);
2111 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002112
2113 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2114 lsp_l2_refresh_pseudo, circuit,
2115 isis_jitter (ref_time, MAX_AGE_JITTER));
2116
jardineb5d44e2003-12-23 08:09:43 +00002117 return lsp_regenerate_schedule (circuit->area);
2118}
2119
jardineb5d44e2003-12-23 08:09:43 +00002120/*
2121 * Walk through LSPs for an area
2122 * - set remaining lifetime
2123 * - set LSPs with SRMflag set for sending
2124 */
hassof390d2c2004-09-10 20:48:21 +00002125int
jardineb5d44e2003-12-23 08:09:43 +00002126lsp_tick (struct thread *thread)
2127{
2128 struct isis_area *area;
2129 struct isis_circuit *circuit;
2130 struct isis_lsp *lsp;
2131 struct list *lsp_list;
2132 struct listnode *lspnode, *cnode;
2133 dnode_t *dnode, *dnode_next;
2134 int level;
2135
2136 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002137
jardineb5d44e2003-12-23 08:09:43 +00002138 area = THREAD_ARG (thread);
2139 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002140 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002141 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002142
2143 /*
2144 * Build a list of LSPs with (any) SRMflag set
2145 * and removed the ones that have aged out
2146 */
hassof390d2c2004-09-10 20:48:21 +00002147 for (level = 0; level < ISIS_LEVELS; level++)
2148 {
2149 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2150 {
2151 dnode = dict_first (area->lspdb[level]);
2152 while (dnode != NULL)
2153 {
2154 dnode_next = dict_next (area->lspdb[level], dnode);
2155 lsp = dnode_get (dnode);
2156 lsp_set_time (lsp);
2157 if (lsp->age_out == 0)
2158 {
jardineb5d44e2003-12-23 08:09:43 +00002159
hasso529d65b2004-12-24 00:14:50 +00002160 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2161 area->area_tag,
2162 lsp->level,
2163 rawlspid_print (lsp->lsp_header->lsp_id),
2164 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002165
hassof390d2c2004-09-10 20:48:21 +00002166 lsp_destroy (lsp);
2167 dict_delete (area->lspdb[level], dnode);
2168 }
2169 else if (flags_any_set (lsp->SRMflags))
2170 listnode_add (lsp_list, lsp);
2171 dnode = dnode_next;
2172 }
jardineb5d44e2003-12-23 08:09:43 +00002173
hassof390d2c2004-09-10 20:48:21 +00002174 /*
2175 * Send LSPs on circuits indicated by the SRMflags
2176 */
2177 if (listcount (lsp_list) > 0)
2178 {
2179 for (cnode = listhead (area->circuit_list); cnode;
2180 nextnode (cnode))
2181 {
2182 circuit = getdata (cnode);
2183 for (lspnode = listhead (lsp_list); lspnode;
2184 nextnode (lspnode))
2185 {
2186 lsp = getdata (lspnode);
2187 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2188 {
2189 /* FIXME: if same or elder lsp is already in lsp
2190 * queue */
2191 listnode_add (circuit->lsp_queue, lsp);
2192 thread_add_event (master, send_lsp, circuit, 0);
2193 }
2194 }
2195 }
2196 }
2197 list_delete_all_node (lsp_list);
2198 }
jardineb5d44e2003-12-23 08:09:43 +00002199 }
jardineb5d44e2003-12-23 08:09:43 +00002200
2201 list_delete (lsp_list);
2202
2203 return ISIS_OK;
2204}
2205
jardineb5d44e2003-12-23 08:09:43 +00002206void
hassof390d2c2004-09-10 20:48:21 +00002207lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002208{
2209 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002210
jardineb5d44e2003-12-23 08:09:43 +00002211 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002212
2213 if (lsp && lsp->purged == 0)
2214 {
2215 lsp->lsp_header->rem_lifetime = htons (0);
2216 lsp->lsp_header->pdu_len =
2217 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2218 lsp->purged = 0;
2219 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2220 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2221 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2222 }
2223
jardineb5d44e2003-12-23 08:09:43 +00002224 return;
2225}
2226
2227/*
2228 * Purge own LSP that is received and we don't have.
2229 * -> Do as in 7.3.16.4
2230 */
2231void
hassof390d2c2004-09-10 20:48:21 +00002232lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2233 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002234{
2235 struct isis_lsp *lsp;
2236
2237 /*
2238 * We need to create the LSP to be purged
2239 */
hasso529d65b2004-12-24 00:14:50 +00002240 zlog_debug ("LSP PURGE NON EXIST");
jardineb5d44e2003-12-23 08:09:43 +00002241 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2242 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002243 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2244 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002245 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2246 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002247 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002248 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002249 : L2_LINK_STATE);
2250 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2251 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002252 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002253
jardineb5d44e2003-12-23 08:09:43 +00002254 /*
2255 * Retain only LSP header
2256 */
2257 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2258 /*
2259 * Set the remaining lifetime to 0
2260 */
2261 lsp->lsp_header->rem_lifetime = 0;
2262 /*
2263 * Put the lsp into LSPdb
2264 */
hassof390d2c2004-09-10 20:48:21 +00002265 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002266
2267 /*
2268 * Send in to whole area
2269 */
2270 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002271
jardineb5d44e2003-12-23 08:09:43 +00002272 return;
2273}
2274
2275#ifdef TOPOLOGY_GENERATE
hasso92365882005-01-18 13:53:33 +00002276static int
jardineb5d44e2003-12-23 08:09:43 +00002277top_lsp_refresh (struct thread *thread)
2278{
hassof390d2c2004-09-10 20:48:21 +00002279 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002280
2281 lsp = THREAD_ARG (thread);
2282 assert (lsp);
2283
2284 lsp->t_lsp_top_ref = NULL;
2285
hassof390d2c2004-09-10 20:48:21 +00002286 lsp->lsp_header->rem_lifetime =
2287 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2288 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002289
2290 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002291 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2292 {
hasso529d65b2004-12-24 00:14:50 +00002293 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2294 rawlspid_print (lsp->lsp_header->lsp_id));
hassof390d2c2004-09-10 20:48:21 +00002295 }
jardineb5d44e2003-12-23 08:09:43 +00002296
2297 /* time to calculate our checksum */
2298 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002299 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2300 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2301 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002302
2303 return ISIS_OK;
2304}
2305
2306void
2307generate_topology_lsps (struct isis_area *area)
2308{
2309 struct listnode *node;
2310 int i, max = 0;
2311 struct arc *arc;
2312 u_char lspid[ISIS_SYS_ID_LEN + 2];
2313 struct isis_lsp *lsp;
2314
2315 /* first we find the maximal node */
hassof390d2c2004-09-10 20:48:21 +00002316 LIST_LOOP (area->topology, arc, node)
2317 {
2318 if (arc->from_node > max)
2319 max = arc->from_node;
2320 if (arc->to_node > max)
2321 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002322 }
2323
hassof390d2c2004-09-10 20:48:21 +00002324 for (i = 1; i < (max + 1); i++)
2325 {
2326 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2327 LSP_PSEUDO_ID (lspid) = 0x00;
2328 LSP_FRAGMENT (lspid) = 0x00;
2329 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2330 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002331
hassof390d2c2004-09-10 20:48:21 +00002332 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2333 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2334 1);
2335 lsp->from_topology = 1;
2336 /* creating data based on topology */
2337 build_topology_lsp_data (lsp, area, i);
2338 /* time to calculate our checksum */
2339 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2340 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2341 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2342 isis_jitter (MAX_LSP_GEN_INTERVAL,
2343 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002344
hassof390d2c2004-09-10 20:48:21 +00002345 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2346 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002347
hassof390d2c2004-09-10 20:48:21 +00002348 }
jardineb5d44e2003-12-23 08:09:43 +00002349}
2350
2351void
2352remove_topology_lsps (struct isis_area *area)
2353{
2354 struct isis_lsp *lsp;
2355 dnode_t *dnode, *dnode_next;
2356
2357 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002358 while (dnode != NULL)
2359 {
2360 dnode_next = dict_next (area->lspdb[0], dnode);
2361 lsp = dnode_get (dnode);
2362 if (lsp->from_topology)
2363 {
2364 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2365 lsp_destroy (lsp);
2366 dict_delete (area->lspdb[0], dnode);
2367 }
2368 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002369 }
jardineb5d44e2003-12-23 08:09:43 +00002370}
2371
2372void
hassof390d2c2004-09-10 20:48:21 +00002373build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002374 int lsp_top_num)
2375{
2376 struct listnode *node;
2377 struct arc *arc;
2378 u_char *tlv_ptr;
2379 struct is_neigh *is_neigh;
2380 int to_lsp = 0;
2381 char buff[200];
2382
2383 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002384 /* the 2 is for the TL plus 1 for the nlpid */
2385 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2386 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2387 *(tlv_ptr + 1) = 1; /* one protocol */
2388 *(tlv_ptr + 2) = NLPID_IP;
2389 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002390
2391 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002392 /* the 2 is for the TL plus 1 for the virtual field */
2393 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2394 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2395 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2396 *(tlv_ptr + 2) = 0; /* virtual is zero */
2397 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002398
2399 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002400 if (lsp_top_num == 1)
2401 {
jardineb5d44e2003-12-23 08:09:43 +00002402 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002403 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2404 sizeof (struct
2405 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002406 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002407 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2408 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002409 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002410 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002411 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2412 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2413 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2414 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002415 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2416 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002417 }
hassof390d2c2004-09-10 20:48:21 +00002418
2419 /* addding is reachabilities */
2420 LIST_LOOP (area->topology, arc, node)
2421 {
2422 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2423 {
2424 if (arc->to_node == lsp_top_num)
2425 to_lsp = arc->from_node;
2426 if (arc->from_node == lsp_top_num)
2427 to_lsp = arc->to_node;
2428
2429 /* if the length here is about to cross the FF limit, we reTLV */
2430 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2431 {
2432 /* retlv */
2433 /* the 2 is for the TL plus 1 for the virtual field */
2434 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2435 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2436 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2437 *(tlv_ptr + 2) = 0; /* virtual is zero */
2438 }
2439 /* doing this here assures us that we won't add an "empty" tlv */
2440 /* assign space for the is_neigh at the pdu end */
2441 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2442 sizeof (struct
2443 is_neigh));
2444 /* add this node to our list */
2445 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2446 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2447 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2448 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2449 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2450 is_neigh->metrics.metric_default = arc->distance;
2451 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2452 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2453 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2454 /* don't forget the length */
2455 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2456 }
jardineb5d44e2003-12-23 08:09:43 +00002457 }
2458
hassof390d2c2004-09-10 20:48:21 +00002459 /* adding dynamic hostname if needed */
2460 if (area->dynhostname)
2461 {
2462 memset (buff, 0x00, 200);
2463 sprintf (buff, "feedme%d", lsp_top_num);
2464 /* the 2 is for the TL */
2465 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2466 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2467 *(tlv_ptr + 1) = strlen (buff); /* Length */
2468 /* the -1 is to fit the length in the struct */
2469 lsp->tlv_data.hostname = (struct hostname *)
2470 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2471 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2472 }
jardineb5d44e2003-12-23 08:09:43 +00002473
2474 /* thanks to hannes, another bug bites the dust */
hassof390d2c2004-09-10 20:48:21 +00002475 lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00002476}
2477#endif /* TOPOLOGY_GENERATE */