blob: d52efb6afe1d4791954944d022bd946f29bfe643 [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;
jardineb5d44e2003-12-23 08:09:43 +000062
hassof390d2c2004-09-10 20:48:21 +000063int
64lsp_id_cmp (u_char * id1, u_char * id2)
65{
jardineb5d44e2003-12-23 08:09:43 +000066 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
67}
68
69dict_t *
hassof390d2c2004-09-10 20:48:21 +000070lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000071{
72 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000073
74 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
75
jardineb5d44e2003-12-23 08:09:43 +000076 return dict;
77}
78
79struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000080lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000081{
82 dnode_t *node;
83
hassof390d2c2004-09-10 20:48:21 +000084#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000085 dnode_t *dn;
86
hassof390d2c2004-09-10 20:48:21 +000087 zlog_warn ("searching db");
88 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
89 {
90 zlog_warn ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn)),
91 dnode_get (dn));
92 }
jardineb5d44e2003-12-23 08:09:43 +000093#endif /* EXTREME DEBUG */
94
95 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +000096
jardineb5d44e2003-12-23 08:09:43 +000097 if (node)
hassof390d2c2004-09-10 20:48:21 +000098 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +000099
100 return NULL;
101}
102
103void
104lsp_clear_data (struct isis_lsp *lsp)
105{
106 if (!lsp)
107 return;
hassof390d2c2004-09-10 20:48:21 +0000108
109 if (lsp->own_lsp)
110 {
111 if (lsp->tlv_data.nlpids)
112 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
113 if (lsp->tlv_data.hostname)
114 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
115 }
jardineb5d44e2003-12-23 08:09:43 +0000116 if (lsp->tlv_data.is_neighs)
117 list_delete (lsp->tlv_data.is_neighs);
118 if (lsp->tlv_data.area_addrs)
119 list_delete (lsp->tlv_data.area_addrs);
120 if (lsp->tlv_data.es_neighs)
121 list_delete (lsp->tlv_data.es_neighs);
122 if (lsp->tlv_data.ipv4_addrs)
123 list_delete (lsp->tlv_data.ipv4_addrs);
124 if (lsp->tlv_data.ipv4_int_reachs)
125 list_delete (lsp->tlv_data.ipv4_int_reachs);
126 if (lsp->tlv_data.ipv4_ext_reachs)
127 list_delete (lsp->tlv_data.ipv4_ext_reachs);
128#ifdef HAVE_IPV6
129 if (lsp->tlv_data.ipv6_addrs)
130 list_delete (lsp->tlv_data.ipv6_addrs);
131 if (lsp->tlv_data.ipv6_reachs)
132 list_delete (lsp->tlv_data.ipv6_reachs);
133#endif /* HAVE_IPV6 */
134
135 memset (&lsp->tlv_data, 0, sizeof (struct tlvs));
136
137 return;
138}
139
140void
141lsp_destroy (struct isis_lsp *lsp)
142{
143 if (!lsp)
144 return;
hassof390d2c2004-09-10 20:48:21 +0000145
jardineb5d44e2003-12-23 08:09:43 +0000146 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000147
148 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
149 {
jardineb5d44e2003-12-23 08:09:43 +0000150 list_delete (lsp->lspu.frags);
hassof390d2c2004-09-10 20:48:21 +0000151 }
152
jardineb5d44e2003-12-23 08:09:43 +0000153 if (lsp->pdu)
154 stream_free (lsp->pdu);
155 XFREE (MTYPE_ISIS_LSP, lsp);
156}
157
hassof390d2c2004-09-10 20:48:21 +0000158void
159lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000160{
161 dnode_t *dnode, *next;
162 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000163
jardineb5d44e2003-12-23 08:09:43 +0000164 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000165 while (dnode)
166 {
167 next = dict_next (lspdb, dnode);
168 lsp = dnode_get (dnode);
169 lsp_destroy (lsp);
170 dict_delete_free (lspdb, dnode);
171 dnode = next;
172 }
173
jardineb5d44e2003-12-23 08:09:43 +0000174 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000175
jardineb5d44e2003-12-23 08:09:43 +0000176 return;
177}
178
179/*
180 * Remove all the frags belonging to the given lsp
181 */
182void
hassof390d2c2004-09-10 20:48:21 +0000183lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000184{
185 dnode_t *dnode;
186 struct listnode *lnode;
187 struct isis_lsp *lsp;
188
hassof390d2c2004-09-10 20:48:21 +0000189 for (lnode = listhead (frags); lnode; nextnode (lnode))
190 {
191 lsp = getdata (lnode);
192 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
193 lsp_destroy (lsp);
194 dnode_destroy (dict_delete (lspdb, dnode));
195 }
196
jardineb5d44e2003-12-23 08:09:43 +0000197 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000198
jardineb5d44e2003-12-23 08:09:43 +0000199 return;
200}
201
202void
hassof390d2c2004-09-10 20:48:21 +0000203lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000204{
205 dnode_t *node;
206 struct isis_lsp *lsp;
207
208 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000209 if (node)
210 {
211 node = dict_delete (lspdb, node);
212 lsp = dnode_get (node);
213 /*
214 * If this is a zero lsp, remove all the frags now
215 */
216 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
217 {
218 if (lsp->lspu.frags)
219 lsp_remove_frags (lsp->lspu.frags, lspdb);
220 }
221 else
222 {
223 /*
224 * else just remove this frag, from the zero lsps' frag list
225 */
226 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
227 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
228 }
229 lsp_destroy (lsp);
230 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000231 }
jardineb5d44e2003-12-23 08:09:43 +0000232}
233
234/*
235 * Compares a LSP to given values
236 * Params are given in net order
237 */
hassof390d2c2004-09-10 20:48:21 +0000238int
239lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000240 u_int16_t checksum, u_int16_t rem_lifetime)
241{
hassof390d2c2004-09-10 20:48:21 +0000242 /* no point in double ntohl on seqnum */
243 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000244 lsp->lsp_header->checksum == checksum &&
245 /*comparing with 0, no need to do ntohl */
246 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000247 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
248 {
249 if (isis->debugs & DEBUG_SNP_PACKETS)
250 {
251 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
252 " lifetime %us",
253 areatag,
254 rawlspid_print (lsp->lsp_header->lsp_id),
255 ntohl (lsp->lsp_header->seq_num),
256 ntohs (lsp->lsp_header->checksum),
257 ntohs (lsp->lsp_header->rem_lifetime));
258 zlog_info ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
259 " cksum 0x%04x, lifetime %us",
260 areatag,
261 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
262 }
263 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000264 }
jardineb5d44e2003-12-23 08:09:43 +0000265
hassof390d2c2004-09-10 20:48:21 +0000266 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
267 {
268 if (isis->debugs & DEBUG_SNP_PACKETS)
269 {
270 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
271 " lifetime %us",
272 areatag,
273 rawlspid_print (lsp->lsp_header->lsp_id),
274 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
275 zlog_info ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
276 "cksum 0x%04x, lifetime %us",
277 areatag,
278 ntohl (lsp->lsp_header->seq_num),
279 ntohs (lsp->lsp_header->checksum),
280 ntohs (lsp->lsp_header->rem_lifetime));
281 }
282 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000283 }
hassof390d2c2004-09-10 20:48:21 +0000284 if (isis->debugs & DEBUG_SNP_PACKETS)
285 {
286 zlog_info
287 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
288 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
289 ntohs (checksum), ntohs (rem_lifetime));
290 zlog_info ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
291 " cksum 0x%04x, lifetime %us", areatag,
292 ntohl (lsp->lsp_header->seq_num),
293 ntohs (lsp->lsp_header->checksum),
294 ntohs (lsp->lsp_header->rem_lifetime));
295 }
jardineb5d44e2003-12-23 08:09:43 +0000296
297 return LSP_OLDER;
298}
299
hassof390d2c2004-09-10 20:48:21 +0000300void
jardineb5d44e2003-12-23 08:09:43 +0000301lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
302{
303 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000304
jardineb5d44e2003-12-23 08:09:43 +0000305 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
306 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
307 else
hassof390d2c2004-09-10 20:48:21 +0000308 newseq = seq_num++;
309
jardineb5d44e2003-12-23 08:09:43 +0000310 lsp->lsp_header->seq_num = htonl (newseq);
hassof390d2c2004-09-10 20:48:21 +0000311 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
312 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +0000313
314 return;
315}
316
317/*
318 * Genetates checksum for LSP and its frags
319 */
320void
321lsp_seqnum_update (struct isis_lsp *lsp0)
322{
323 struct isis_lsp *lsp;
324 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000325
jardineb5d44e2003-12-23 08:09:43 +0000326 lsp_inc_seqnum (lsp0, 0);
327
328 if (!lsp0->lspu.frags)
329 return;
330
hassof390d2c2004-09-10 20:48:21 +0000331 for (node = listhead (lsp0->lspu.frags); node; nextnode (node))
332 {
333 lsp = getdata (node);
334 lsp_inc_seqnum (lsp, 0);
335 }
336
jardineb5d44e2003-12-23 08:09:43 +0000337 return;
338}
339
hassof390d2c2004-09-10 20:48:21 +0000340int
jardineb5d44e2003-12-23 08:09:43 +0000341isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
hassof390d2c2004-09-10 20:48:21 +0000342 int pdulen, struct isis_passwd *passwd)
jardineb5d44e2003-12-23 08:09:43 +0000343{
344 uint32_t expected = 0, found;
345 struct tlvs tlvs;
346 int retval = 0;
347
348 expected |= TLVFLAG_AUTH_INFO;
349 retval = parse_tlvs (area->area_tag, stream->data +
hassof390d2c2004-09-10 20:48:21 +0000350 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
351 pdulen - ISIS_FIXED_HDR_LEN
352 - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000353 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000354 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000355
356 return authentication_check (passwd, &tlvs.auth_info);
357}
358
359void
hassof390d2c2004-09-10 20:48:21 +0000360lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
361 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000362{
hassof390d2c2004-09-10 20:48:21 +0000363 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000364 int retval;
hassof390d2c2004-09-10 20:48:21 +0000365
jardineb5d44e2003-12-23 08:09:43 +0000366 /* copying only the relevant part of our stream */
367 lsp->pdu = stream_new (stream->endp);
368 lsp->pdu->putp = stream->putp;
369 lsp->pdu->getp = stream->getp;
370 lsp->pdu->endp = stream->endp;
371 memcpy (lsp->pdu->data, stream->data, stream->endp);
372
373 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000374 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
375 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
376 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000377 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000378 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000379 /*
380 * Get LSP data i.e. TLVs
381 */
382 expected |= TLVFLAG_AUTH_INFO;
383 expected |= TLVFLAG_AREA_ADDRS;
384 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000385 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000386 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
387 expected |= TLVFLAG_NLPID;
388 if (area->dynhostname)
389 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000390 if (area->newmetric)
391 {
392 expected |= TLVFLAG_TE_IS_NEIGHS;
393 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
394 expected |= TLVFLAG_TE_ROUTER_ID;
395 }
jardineb5d44e2003-12-23 08:09:43 +0000396 expected |= TLVFLAG_IPV4_ADDR;
397 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
398 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
399#ifdef HAVE_IPV6
400 expected |= TLVFLAG_IPV6_ADDR;
401 expected |= TLVFLAG_IPV6_REACHABILITY;
402#endif /* HAVE_IPV6 */
403
404 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000405 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
406 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
407 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000408
hassof390d2c2004-09-10 20:48:21 +0000409 if (found & TLVFLAG_DYN_HOSTNAME)
410 {
411 if (area->dynhostname)
412 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
413 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
414 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
415 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
416 }
jardineb5d44e2003-12-23 08:09:43 +0000417
418}
419
420void
421lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +0000422 struct stream *stream, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000423{
hassof390d2c2004-09-10 20:48:21 +0000424 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000425 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
426 lsp_clear_data (lsp);
427
428 /* rebuild the lsp data */
429 lsp_update_data (lsp, stream, area);
430
hassof390d2c2004-09-10 20:48:21 +0000431 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000432 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000433}
434
jardineb5d44e2003-12-23 08:09:43 +0000435/* creation of LSP directly from what we received */
436struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000437lsp_new_from_stream_ptr (struct stream *stream,
438 u_int16_t pdu_len, struct isis_lsp *lsp0,
439 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000440{
441 struct isis_lsp *lsp;
442
443 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
444 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000445
jardineb5d44e2003-12-23 08:09:43 +0000446 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000447
448 if (lsp0 == NULL)
449 {
450 /*
451 * zero lsp -> create the list for fragments
452 */
453 lsp->lspu.frags = list_new ();
454 }
455 else
456 {
457 /*
458 * a fragment -> set the backpointer and add this to zero lsps frag list
459 */
460 lsp->lspu.zero_lsp = lsp0;
461 listnode_add (lsp0->lspu.frags, lsp);
462 }
463
jardineb5d44e2003-12-23 08:09:43 +0000464 return lsp;
465}
466
467struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000468lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
469 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000470{
471 struct isis_lsp *lsp;
472
473 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000474 if (!lsp)
475 {
476 /* FIXME: set lspdbol bit */
477 zlog_warn ("lsp_new(): out of memory");
478 return NULL;
479 }
jardineb5d44e2003-12-23 08:09:43 +0000480 memset (lsp, 0, sizeof (struct isis_lsp));
481#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000482 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000483#else
hassof390d2c2004-09-10 20:48:21 +0000484 /* We need to do realloc on TLVs additions */
485 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000486#endif /* LSP_MEMORY_PREASSIGN */
487 if (LSP_FRAGMENT (lsp_id) == 0)
488 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000489 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
490 lsp->lsp_header = (struct isis_link_state_hdr *)
491 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
492
jardineb5d44e2003-12-23 08:09:43 +0000493 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000494 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
495 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
496
jardineb5d44e2003-12-23 08:09:43 +0000497 /* now for the LSP HEADER */
498 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000499 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000500 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000501 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000502 lsp->lsp_header->seq_num = htonl (seq_num);
503 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
504 lsp->lsp_header->lsp_bits = lsp_bits;
505 lsp->level = level;
506 lsp->age_out = ZERO_AGE_LIFETIME;
507
508 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
509
510 /* #ifdef EXTREME_DEBUG */
511 /* logging */
512 zlog_info ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000513 LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
514 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
515 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000516 /* #endif EXTREME DEBUG */
517
518 return lsp;
519}
520
521void
hassof390d2c2004-09-10 20:48:21 +0000522lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000523{
524 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
525}
526
527/*
528 * Build a list of LSPs with non-zero ht bounded by start and stop ids
529 */
hassof390d2c2004-09-10 20:48:21 +0000530void
531lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
532 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000533{
534 dnode_t *first, *last, *curr;
535
536 first = dict_lower_bound (lspdb, start_id);
537 if (!first)
538 return;
hassof390d2c2004-09-10 20:48:21 +0000539
jardineb5d44e2003-12-23 08:09:43 +0000540 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000541
jardineb5d44e2003-12-23 08:09:43 +0000542 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000543
544 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000545 listnode_add (list, first->dict_data);
546
hassof390d2c2004-09-10 20:48:21 +0000547 while (curr)
548 {
549 curr = dict_next (lspdb, curr);
550 if (curr &&
551 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
552 listnode_add (list, curr->dict_data);
553 if (curr == last)
554 break;
555 }
556
jardineb5d44e2003-12-23 08:09:43 +0000557 return;
558}
559
560/*
561 * Build a list of all LSPs bounded by start and stop ids
562 */
hassof390d2c2004-09-10 20:48:21 +0000563void
564lsp_build_list (u_char * start_id, u_char * stop_id,
565 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000566{
567 dnode_t *first, *last, *curr;
568
569 first = dict_lower_bound (lspdb, start_id);
570 if (!first)
571 return;
hassof390d2c2004-09-10 20:48:21 +0000572
jardineb5d44e2003-12-23 08:09:43 +0000573 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000574
jardineb5d44e2003-12-23 08:09:43 +0000575 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000576
jardineb5d44e2003-12-23 08:09:43 +0000577 listnode_add (list, first->dict_data);
578
hassof390d2c2004-09-10 20:48:21 +0000579 while (curr)
580 {
581 curr = dict_next (lspdb, curr);
582 if (curr)
583 listnode_add (list, curr->dict_data);
584 if (curr == last)
585 break;
586 }
587
jardineb5d44e2003-12-23 08:09:43 +0000588 return;
589}
590
591/*
592 * Build a list of LSPs with SSN flag set for the given circuit
593 */
594void
hassof390d2c2004-09-10 20:48:21 +0000595lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
596 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000597{
598 dnode_t *dnode, *next;
599 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000600
jardineb5d44e2003-12-23 08:09:43 +0000601 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000602 while (dnode != NULL)
603 {
604 next = dict_next (lspdb, dnode);
605 lsp = dnode_get (dnode);
606 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
607 listnode_add (list, lsp);
608 dnode = next;
609 }
610
jardineb5d44e2003-12-23 08:09:43 +0000611 return;
612}
613
614void
615lsp_set_time (struct isis_lsp *lsp)
616{
617 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000618
619 if (lsp->lsp_header->rem_lifetime == 0)
620 {
621 if (lsp->age_out != 0)
622 lsp->age_out--;
623 return;
624 }
jardineb5d44e2003-12-23 08:09:43 +0000625
626 /* If we are turning 0 */
627 /* ISO 10589 - 7.3.16.4 first paragraph */
628
hassof390d2c2004-09-10 20:48:21 +0000629 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
630 {
631 /* 7.3.16.4 a) set SRM flags on all */
632 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
633 /* 7.3.16.4 b) retain only the header FIXME */
634 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
635 }
jardineb5d44e2003-12-23 08:09:43 +0000636
hassof390d2c2004-09-10 20:48:21 +0000637 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000638 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
639}
640
641void
hassof390d2c2004-09-10 20:48:21 +0000642lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000643{
644 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000645 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000646
647 if (dynhost)
648 dyn = dynhn_find_by_id (lsp_id);
649 else
650 dyn = NULL;
651
652 if (dyn)
653 sprintf (id, "%.14s", dyn->name.name);
654 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof390d2c2004-09-10 20:48:21 +0000655 sprintf (id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000656 else
hassof390d2c2004-09-10 20:48:21 +0000657 {
658 memcpy (id, sysid_print (lsp_id), 15);
659 }
660 if (frag)
661 sprintf (trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
662 LSP_FRAGMENT (lsp_id));
663 else
664 sprintf (trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000665}
666
hassof390d2c2004-09-10 20:48:21 +0000667/* Convert the lsp attribute bits to attribute string */
668char *
669lsp_bits2string (u_char * lsp_bits)
670{
671 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000672
hassof390d2c2004-09-10 20:48:21 +0000673 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000674 return " none";
675
676 /* we only focus on the default metric */
677 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000678 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000679
680 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000681 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000682
hassof390d2c2004-09-10 20:48:21 +0000683 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
684
jardineb5d44e2003-12-23 08:09:43 +0000685 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000686
hassof390d2c2004-09-10 20:48:21 +0000687 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000688}
689
690/* this function prints the lsp on show isis database */
691void
hassof390d2c2004-09-10 20:48:21 +0000692lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000693{
hassof390d2c2004-09-10 20:48:21 +0000694 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000695 u_char LSPid[255];
696
697 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000698 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
699 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
700 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000701
hassof390d2c2004-09-10 20:48:21 +0000702 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
703 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000704 else
hassof390d2c2004-09-10 20:48:21 +0000705 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000706
707 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000708 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000709}
710
711void
hassof390d2c2004-09-10 20:48:21 +0000712lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000713{
714 struct isis_lsp *lsp = dnode_get (node);
715 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000716 char nlpidstr[2];
717 int i;
jardineb5d44e2003-12-23 08:09:43 +0000718 struct listnode *lnode;
719 struct is_neigh *is_neigh;
720 struct te_is_neigh *te_is_neigh;
721 struct ipv4_reachability *ipv4_reach;
722 struct in_addr *ipv4_addr;
723 struct te_ipv4_reachability *te_ipv4_reach;
724#ifdef HAVE_IPV6
725 struct ipv6_reachability *ipv6_reach;
726 struct in6_addr in6;
727#endif
728 u_char LSPid[255];
729 u_char hostname[255];
730 u_char buff[BUFSIZ];
hassof390d2c2004-09-10 20:48:21 +0000731 u_int32_t now, helper;
jardineb5d44e2003-12-23 08:09:43 +0000732 u_char ipv4_reach_prefix[20];
733 u_char ipv4_reach_mask[20];
734 u_char ipv4_address[20];
735
736 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000737 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000738
739 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000740 if (lsp->tlv_data.area_addrs)
741 {
742 LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode)
743 {
744 vty_out (vty, " Area Address: %s%s",
745 isonet_print (area_addr->area_addr, area_addr->addr_len),
746 VTY_NEWLINE);
747 }
jardineb5d44e2003-12-23 08:09:43 +0000748 }
jardineb5d44e2003-12-23 08:09:43 +0000749
750 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000751 if (lsp->tlv_data.nlpids)
752 {
753 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
754 {
755 switch (lsp->tlv_data.nlpids->nlpids[i])
756 {
757 case NLPID_IP:
758 case NLPID_IPV6:
759 vty_out (vty, " NLPID: 0x%X%s",
760 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
761 break;
762 default:
763 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
764 break;
765 }
766 }
767 }
jardineb5d44e2003-12-23 08:09:43 +0000768
769 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000770 if (lsp->tlv_data.hostname)
771 {
772 bzero (hostname, sizeof (hostname));
773 memcpy (hostname, lsp->tlv_data.hostname->name,
774 lsp->tlv_data.hostname->namelen);
775 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000776 }
hassof390d2c2004-09-10 20:48:21 +0000777
778 if (lsp->tlv_data.ipv4_addrs)
779 {
780 LIST_LOOP (lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode)
781 {
782 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
783 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
784 }
785 }
786
jardineb5d44e2003-12-23 08:09:43 +0000787 /* for the internal reachable tlv */
788 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000789 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
790 {
791 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
792 sizeof (ipv4_reach_prefix));
793 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
794 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000795 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000796 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
797 ipv4_reach_mask, VTY_NEWLINE);
798 }
hasso2097cd82003-12-23 11:51:08 +0000799
800 /* for the external reachable tlv */
801 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000802 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
803 {
804 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
805 sizeof (ipv4_reach_prefix));
806 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
807 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000808 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000809 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
810 ipv4_reach_mask, VTY_NEWLINE);
811 }
jardineb5d44e2003-12-23 08:09:43 +0000812
813 /* for the IS neighbor tlv */
hassof390d2c2004-09-10 20:48:21 +0000814 if (lsp->tlv_data.is_neighs)
815 {
816 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
817 {
818 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
819 vty_out (vty, " Metric: %d IS %s%s",
820 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
821 }
jardineb5d44e2003-12-23 08:09:43 +0000822 }
jardineb5d44e2003-12-23 08:09:43 +0000823
hasso2097cd82003-12-23 11:51:08 +0000824 /* IPv6 tlv */
825#ifdef HAVE_IPV6
826 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000827 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
828 {
829 memset (&in6, 0, sizeof (in6));
830 memcpy (in6.s6_addr, ipv6_reach->prefix,
831 PSIZE (ipv6_reach->prefix_len));
hasso2097cd82003-12-23 11:51:08 +0000832 inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
833 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000834 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
835 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
836 ntohl (ipv6_reach->metric),
837 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000838 else
hassof390d2c2004-09-10 20:48:21 +0000839 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
840 ntohl (ipv6_reach->metric),
841 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000842 }
843#endif
844
jardineb5d44e2003-12-23 08:09:43 +0000845/* FIXME: Other tlvs such as te or external tlv will be added later */
hassof390d2c2004-09-10 20:48:21 +0000846#if 0
jardineb5d44e2003-12-23 08:09:43 +0000847 vty_out (vty, "%s %s %c%s",
hassof390d2c2004-09-10 20:48:21 +0000848 VTY_NEWLINE, LSPid, lsp->own_lsp ? '*' : ' ', VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000849
850 vty_out (vty, " Sequence: 0x%08x Checksum: 0x%04x Lifetime: ",
851 ntohl (lsp->lsp_header->seq_num),
852 ntohs (lsp->lsp_header->checksum));
853
854 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
855 vty_out (vty, " (%2u) ", lsp->age_out);
856 else
857 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->rem_lifetime));
858
859 vty_out (vty, "%s Attributes:%s",
hassof390d2c2004-09-10 20:48:21 +0000860 VTY_NEWLINE, lsp_bits2string (&lsp->lsp_header->lsp_bits));
jardineb5d44e2003-12-23 08:09:43 +0000861
862 /* if this is a self originated LSP then print
863 * the generation time plus when we sent it last
864 * if it is a non self-originated LSP then print the
865 * time when the LSP has been installed
866 */
867
hassof390d2c2004-09-10 20:48:21 +0000868 if (lsp->own_lsp)
869 {
jardineb5d44e2003-12-23 08:09:43 +0000870
hassof390d2c2004-09-10 20:48:21 +0000871 now = time (NULL);
872 helper = now - lsp->last_generated;
873 if (!lsp->last_generated)
874 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000875
hassof390d2c2004-09-10 20:48:21 +0000876 vty_out (vty, ", Generated: %s ago", time2string (helper));
jardineb5d44e2003-12-23 08:09:43 +0000877
hassof390d2c2004-09-10 20:48:21 +0000878 now = time (NULL);
879 helper = now - lsp->last_sent;
880 if (!lsp->last_sent)
881 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000882
hassof390d2c2004-09-10 20:48:21 +0000883 vty_out (vty, ", Last sent: %s ago", time2string (helper));
884 }
885 else
886 {
887 now = time (NULL);
888 helper = now - lsp->installed;
889 if (!lsp->installed)
890 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000891
hassof390d2c2004-09-10 20:48:21 +0000892 vty_out (vty, ", Installed: %s ago", time2string (helper));
jardineb5d44e2003-12-23 08:09:43 +0000893
hassof390d2c2004-09-10 20:48:21 +0000894 }
jardineb5d44e2003-12-23 08:09:43 +0000895
896 vty_out (vty, "%s", VTY_NEWLINE);
897
hassof390d2c2004-09-10 20:48:21 +0000898 if (lsp->tlv_data.nlpids)
899 {
900 vty_out (vty, " Speaks: %s%s", nlpid2string (lsp->tlv_data.nlpids),
901 VTY_NEWLINE);
902 }
jardineb5d44e2003-12-23 08:09:43 +0000903
hassof390d2c2004-09-10 20:48:21 +0000904 if (lsp->tlv_data.router_id)
905 {
906 vty_out (vty, " Router ID: %s%s",
907 inet_ntoa (lsp->tlv_data.router_id->id), VTY_NEWLINE);
908 }
jardineb5d44e2003-12-23 08:09:43 +0000909
910 if (lsp->tlv_data.is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000911 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
912 {
913 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
914 vty_out (vty, " IS %s, Metric: %d%s",
915 LSPid, is_neigh->metrics.metric_default, VTY_NEWLINE);
916 }
jardineb5d44e2003-12-23 08:09:43 +0000917
918 if (lsp->tlv_data.te_is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000919 LIST_LOOP (lsp->tlv_data.te_is_neighs, te_is_neigh, lnode)
920 {
921 /* FIXME: metric display is wrong */
922 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
923 vty_out (vty, " extd-IS %s, Metric: %d%s",
924 LSPid, te_is_neigh->te_metric[0], VTY_NEWLINE);
925 }
jardineb5d44e2003-12-23 08:09:43 +0000926
927 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000928 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
929 {
930 vty_out (vty, " int-IP %s/%d, Metric: %d%s",
931 inet_ntoa (ipv4_reach->prefix),
932 ip_masklen (ipv4_reach->mask),
933 ipv4_reach->metrics.metric_default, VTY_NEWLINE);
934 }
jardineb5d44e2003-12-23 08:09:43 +0000935
936 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000937 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
938 {
939 vty_out (vty, " ext-IP %s/%d, Metric: %d%s",
940 inet_ntoa (ipv4_reach->prefix),
941 ip_masklen (ipv4_reach->mask),
942 ipv4_reach->metrics.metric_default, VTY_NEWLINE);
943 }
jardineb5d44e2003-12-23 08:09:43 +0000944
945 if (lsp->tlv_data.te_ipv4_reachs)
hassof390d2c2004-09-10 20:48:21 +0000946 LIST_LOOP (lsp->tlv_data.te_ipv4_reachs, te_ipv4_reach, lnode)
947 {
948 vty_out (vty, " extd-IP %s/%d, Metric: %d%s",
949 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
950 te_ipv4_reach->control)),
951 te_ipv4_reach->control & 0x3F,
952 ntohl (te_ipv4_reach->te_metric), VTY_NEWLINE);
953 }
jardineb5d44e2003-12-23 08:09:43 +0000954
955#ifdef HAVE_IPV6
956 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000957 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
958 {
959 memcpy (in6.s6_addr, ipv6_reach->prefix, 16);
960 inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
961 if ((ipv6_reach->control_info &&
962 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
963 vty_out (vty, " int-IPv6 %s/%d, Metric: %d%s",
964 buff,
965 ipv6_reach->prefix_len,
966 ntohl (ipv6_reach->metric), VTY_NEWLINE);
967 else
968 vty_out (vty, " ext-IPv6 %s/%d, Metric: %d%s",
969 buff,
970 ipv6_reach->prefix_len,
971 ntohl (ipv6_reach->metric), VTY_NEWLINE);
972
973 }
jardineb5d44e2003-12-23 08:09:43 +0000974#endif
hassof390d2c2004-09-10 20:48:21 +0000975 if (lsp->tlv_data.hostname)
976 {
977 memset (hostname, 0, sizeof (hostname));
978 memcpy (hostname, lsp->tlv_data.hostname->name,
979 lsp->tlv_data.hostname->namelen);
980 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
981 }
jardineb5d44e2003-12-23 08:09:43 +0000982#endif
hassof390d2c2004-09-10 20:48:21 +0000983 return;
jardineb5d44e2003-12-23 08:09:43 +0000984}
985
986/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000987int
988lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000989{
990
hassof390d2c2004-09-10 20:48:21 +0000991 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000992 int lsp_count = 0;
993
994 /* print the title, for both modes */
995 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000996 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
997
998 if (detail == ISIS_UI_LEVEL_BRIEF)
999 {
1000 while (node != NULL)
1001 {
1002 /* I think it is unnecessary, so I comment it out */
1003 /* dict_contains (lspdb, node); */
1004 next = dict_next (lspdb, node);
1005 lsp_print (node, vty, dynhost);
1006 node = next;
1007 lsp_count++;
1008 }
jardineb5d44e2003-12-23 08:09:43 +00001009 }
hassof390d2c2004-09-10 20:48:21 +00001010 else if (detail == ISIS_UI_LEVEL_DETAIL)
1011 {
1012 while (node != NULL)
1013 {
1014 next = dict_next (lspdb, node);
1015 lsp_print_detail (node, vty, dynhost);
1016 node = next;
1017 lsp_count++;
1018 }
jardineb5d44e2003-12-23 08:09:43 +00001019 }
jardineb5d44e2003-12-23 08:09:43 +00001020
1021 return lsp_count;
1022}
1023
1024/* this function reallocate memory to an lsp pdu, with an additional
1025 * size of memory, it scans the lsp and moves all pointers the
1026 * way they should */
1027u_char *
hassof390d2c2004-09-10 20:48:21 +00001028lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +00001029{
1030 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +00001031
1032 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001033#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +00001034 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +00001035 return retval;
hassof390d2c2004-09-10 20:48:21 +00001036#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +00001037 u_char *newpdu;
1038 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassof390d2c2004-09-10 20:48:21 +00001039 memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu),
1040 ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +00001041 XFREE (memorytype, lsp->pdu);
1042 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +00001043 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
1044 lsp->lsp_header = (struct isis_link_state_hdr *)
1045 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001046 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +00001047 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +00001048#endif /* LSP_MEMORY_PREASSIGN */
1049}
1050
hassof390d2c2004-09-10 20:48:21 +00001051#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +00001052/*
1053 * Builds the lsp->tlv_data
1054 * and writes the tlvs into lsp->pdu
1055 */
1056void
1057lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1058{
1059 struct is_neigh *is_neigh;
1060 struct listnode *node, *ipnode;
1061 int level = lsp->level;
1062 struct isis_circuit *circuit;
1063 struct prefix_ipv4 *ipv4;
1064 struct ipv4_reachability *ipreach;
1065 struct isis_adjacency *nei;
1066#ifdef HAVE_IPV6
1067 struct prefix_ipv6 *ipv6;
1068 struct ipv6_reachability *ip6reach;
1069#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001070
jardineb5d44e2003-12-23 08:09:43 +00001071 /*
1072 * First add the tlvs related to area
1073 */
hassof390d2c2004-09-10 20:48:21 +00001074
jardineb5d44e2003-12-23 08:09:43 +00001075 /* Area addresses */
1076 if (lsp->tlv_data.area_addrs == NULL)
1077 lsp->tlv_data.area_addrs = list_new ();
1078 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1079 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001080 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001081#ifdef HAVE_IPV6
1082 || area->ipv6_circuits > 0
1083#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001084 )
jardineb5d44e2003-12-23 08:09:43 +00001085 {
1086 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1087 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001088 if (area->ip_circuits > 0)
1089 {
1090 lsp->tlv_data.nlpids->count++;
1091 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1092 }
jardineb5d44e2003-12-23 08:09:43 +00001093#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001094 if (area->ipv6_circuits > 0)
1095 {
1096 lsp->tlv_data.nlpids->count++;
1097 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1098 NLPID_IPV6;
1099 }
jardineb5d44e2003-12-23 08:09:43 +00001100#endif /* HAVE_IPV6 */
1101 }
1102 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001103 if (area->dynhostname)
1104 {
1105 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1106 sizeof (struct hostname));
1107 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
1108 strlen (unix_hostname ()));
1109 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1110 }
jardineb5d44e2003-12-23 08:09:43 +00001111#ifdef TOPOLOGY_GENERATE
1112 /*
1113 * If we have a topology in this area, we need to connect this lsp to
1114 * the first topology lsp
1115 */
hassof390d2c2004-09-10 20:48:21 +00001116 if ((area->topology) && (level == 1))
1117 {
1118 if (lsp->tlv_data.is_neighs == NULL)
1119 lsp->tlv_data.is_neighs = list_new ();
1120 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1121 memset (is_neigh, 0, sizeof (struct is_neigh));
1122 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1123 /* connected to the first */
1124 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1125 /* this is actually the same system, why mess the SPT */
1126 is_neigh->metrics.metric_default = 0;
1127 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1128 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1129 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1130 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001131
hassof390d2c2004-09-10 20:48:21 +00001132 }
jardineb5d44e2003-12-23 08:09:43 +00001133#endif
1134
1135 /*
1136 * Then add tlvs related to circuits
1137 */
hassof390d2c2004-09-10 20:48:21 +00001138 for (node = listhead (area->circuit_list); node; nextnode (node))
1139 {
1140 circuit = getdata (node);
1141 if (circuit->state != C_STATE_UP)
1142 continue;
1143
1144 /*
1145 * Add IPv4 internal reachability of this circuit
1146 */
1147 if (circuit->ip_router && circuit->ip_addrs &&
1148 circuit->ip_addrs->count > 0)
1149 {
1150 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1151 {
1152 lsp->tlv_data.ipv4_int_reachs = list_new ();
1153 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1154 }
1155 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1156 nextnode (ipnode))
1157 {
1158 ipv4 = getdata (ipnode);
1159 ipreach =
1160 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1161 ipreach->metrics = circuit->metrics[level - 1];
1162 ipreach->prefix = ipv4->prefix;
1163 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1164 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1165 }
1166 }
jardineb5d44e2003-12-23 08:09:43 +00001167#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001168 /*
1169 * Add IPv6 reachability of this circuit
1170 */
1171 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1172 circuit->ipv6_non_link->count > 0)
1173 {
1174 if (lsp->tlv_data.ipv6_reachs == NULL)
1175 {
1176 lsp->tlv_data.ipv6_reachs = list_new ();
1177 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1178 }
1179 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1180 nextnode (ipnode))
1181 {
1182 ipv6 = getdata (ipnode);
1183 ip6reach =
1184 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1185 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1186 ip6reach->metric =
1187 htonl (circuit->metrics[level - 1].metric_default);
1188 ip6reach->control_info = 0;
1189 ip6reach->prefix_len = ipv6->prefixlen;
1190 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1191 (ipv6->prefixlen + 7) / 8);
1192 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1193 }
1194 }
jardineb5d44e2003-12-23 08:09:43 +00001195#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001196
1197 switch (circuit->circ_type)
1198 {
1199 case CIRCUIT_T_BROADCAST:
1200 if (level & circuit->circuit_is_type)
1201 {
1202 if (lsp->tlv_data.is_neighs == NULL)
1203 {
1204 lsp->tlv_data.is_neighs = list_new ();
1205 lsp->tlv_data.is_neighs->del = free_tlv;
1206 }
1207 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1208 memset (is_neigh, 0, sizeof (struct is_neigh));
1209 if (level == 1)
1210 memcpy (&is_neigh->neigh_id,
1211 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1212 else
1213 memcpy (&is_neigh->neigh_id,
1214 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1215 is_neigh->metrics = circuit->metrics[level - 1];
1216 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1217 }
1218 break;
1219 case CIRCUIT_T_P2P:
1220 nei = circuit->u.p2p.neighbor;
1221 if (nei && (level & nei->circuit_t))
1222 {
1223 if (lsp->tlv_data.is_neighs == NULL)
1224 {
1225 lsp->tlv_data.is_neighs = list_new ();
1226 lsp->tlv_data.is_neighs->del = free_tlv;
1227 }
1228 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1229 memset (is_neigh, 0, sizeof (struct is_neigh));
1230 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1231 is_neigh->metrics = circuit->metrics[level - 1];
1232 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1233 }
1234 break;
1235 case CIRCUIT_T_STATIC_IN:
1236 zlog_warn ("lsp_area_create: unsupported circuit type");
1237 break;
1238 case CIRCUIT_T_STATIC_OUT:
1239 zlog_warn ("lsp_area_create: unsupported circuit type");
1240 break;
1241 case CIRCUIT_T_DA:
1242 zlog_warn ("lsp_area_create: unsupported circuit type");
1243 break;
1244 default:
1245 zlog_warn ("lsp_area_create: unknown circuit type");
1246 }
jardineb5d44e2003-12-23 08:09:43 +00001247 }
hassof390d2c2004-09-10 20:48:21 +00001248
jardineb5d44e2003-12-23 08:09:43 +00001249 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00001250
jardineb5d44e2003-12-23 08:09:43 +00001251 if (lsp->tlv_data.nlpids)
1252 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1253 if (lsp->tlv_data.hostname)
1254 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001255 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001256 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1257 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1258 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001259 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001260 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1261 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001262#ifdef HAVE_IPV6
1263 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001264 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1265#endif /* HAVE_IPV6 */
1266
1267 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1268
1269 return;
1270}
1271#endif
1272
1273#define FRAG_THOLD(S,T) \
1274((STREAM_SIZE(S)*T)/100)
1275
1276/* stream*, area->lsp_frag_threshold, increment */
1277#define FRAG_NEEDED(S,T,I) \
1278 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1279
1280void
1281lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001282 int tlvsize, int frag_thold,
1283 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001284{
1285 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001286
jardineb5d44e2003-12-23 08:09:43 +00001287 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001288 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1289 {
1290 tlv_build_func (*from, lsp->pdu);
1291 *to = *from;
1292 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001293 }
hassof390d2c2004-09-10 20:48:21 +00001294 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1295 {
1296 /* fit all we can */
1297 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1298 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1299 if (count)
1300 count = count / tlvsize;
1301 for (i = 0; i < count; i++)
1302 {
1303 listnode_add (*to, getdata (listhead (*from)));
1304 listnode_delete (*from, getdata (listhead (*from)));
1305 }
1306 tlv_build_func (*to, lsp->pdu);
1307 }
1308 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001309 return;
1310}
1311
hassof390d2c2004-09-10 20:48:21 +00001312struct isis_lsp *
1313lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1314 int level)
jardineb5d44e2003-12-23 08:09:43 +00001315{
1316 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001317 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1318
jardineb5d44e2003-12-23 08:09:43 +00001319 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1320 LSP_FRAGMENT (frag_id) = frag_num;
1321 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001322 if (lsp)
1323 {
1324 /*
1325 * Clear the TLVs, but inherit the authinfo
1326 */
1327 lsp_clear_data (lsp);
1328 if (lsp0->tlv_data.auth_info.type)
1329 {
1330 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1331 sizeof (struct isis_passwd));
1332 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1333 lsp->tlv_data.auth_info.len,
1334 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1335 }
1336 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001337 }
jardineb5d44e2003-12-23 08:09:43 +00001338 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001339 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001340 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001341 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001342 listnode_add (lsp0->lspu.frags, lsp);
1343 lsp->lspu.zero_lsp = lsp0;
1344 /*
1345 * Copy the authinfo from zero LSP
1346 */
hassof390d2c2004-09-10 20:48:21 +00001347 if (lsp0->tlv_data.auth_info.type)
1348 {
1349 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1350 sizeof (struct isis_passwd));
1351 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1352 lsp->tlv_data.auth_info.len,
1353 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1354 }
jardineb5d44e2003-12-23 08:09:43 +00001355 return lsp;
1356}
1357
1358/*
1359 * Builds the LSP data part. This func creates a new frag whenever
1360 * area->lsp_frag_threshold is exceeded.
1361 */
1362#if 1
1363void
1364lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1365{
1366 struct is_neigh *is_neigh;
1367 struct listnode *node, *ipnode;
1368 int level = lsp->level;
1369 struct isis_circuit *circuit;
1370 struct prefix_ipv4 *ipv4;
1371 struct ipv4_reachability *ipreach;
1372 struct isis_adjacency *nei;
1373#ifdef HAVE_IPV6
1374 struct prefix_ipv6 *ipv6;
1375 struct ipv6_reachability *ip6reach;
1376#endif /* HAVE_IPV6 */
1377 struct tlvs tlv_data;
1378 struct isis_lsp *lsp0 = lsp;
1379 struct isis_passwd *passwd;
1380
1381 /*
1382 * First add the tlvs related to area
1383 */
hassof390d2c2004-09-10 20:48:21 +00001384
jardineb5d44e2003-12-23 08:09:43 +00001385 /* Area addresses */
1386 if (lsp->tlv_data.area_addrs == NULL)
1387 lsp->tlv_data.area_addrs = list_new ();
1388 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1389 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001390 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001391#ifdef HAVE_IPV6
1392 || area->ipv6_circuits > 0
1393#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001394 )
jardineb5d44e2003-12-23 08:09:43 +00001395 {
1396 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1397 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001398 if (area->ip_circuits > 0)
1399 {
1400 lsp->tlv_data.nlpids->count++;
1401 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1402 }
jardineb5d44e2003-12-23 08:09:43 +00001403#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001404 if (area->ipv6_circuits > 0)
1405 {
1406 lsp->tlv_data.nlpids->count++;
1407 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1408 NLPID_IPV6;
1409 }
jardineb5d44e2003-12-23 08:09:43 +00001410#endif /* HAVE_IPV6 */
1411 }
1412 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001413 if (area->dynhostname)
1414 {
1415 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1416 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001417
hassof390d2c2004-09-10 20:48:21 +00001418 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1419 strlen (unix_hostname ()));
1420 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1421 }
jardineb5d44e2003-12-23 08:09:43 +00001422
1423 /*
1424 * Building the zero lsp
1425 */
hassof390d2c2004-09-10 20:48:21 +00001426 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001427 /*
1428 * Add the authentication info if its present
1429 */
hassof390d2c2004-09-10 20:48:21 +00001430 (level == 1) ? (passwd = &area->area_passwd) :
1431 (passwd = &area->domain_passwd);
1432 if (passwd->type)
1433 {
1434 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1435 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1436 }
jardineb5d44e2003-12-23 08:09:43 +00001437 if (lsp->tlv_data.nlpids)
1438 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1439 if (lsp->tlv_data.hostname)
1440 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001441 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001442 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001443
jardineb5d44e2003-12-23 08:09:43 +00001444 memset (&tlv_data, 0, sizeof (struct tlvs));
1445 /*
1446 * Then build lists of tlvs related to circuits
1447 */
hassof390d2c2004-09-10 20:48:21 +00001448 for (node = listhead (area->circuit_list); node; nextnode (node))
1449 {
1450 circuit = getdata (node);
1451 if (circuit->state != C_STATE_UP)
1452 continue;
jardineb5d44e2003-12-23 08:09:43 +00001453
hassof390d2c2004-09-10 20:48:21 +00001454 /*
1455 * Add IPv4 internal reachability of this circuit
1456 */
1457 if (circuit->ip_router && circuit->ip_addrs &&
1458 circuit->ip_addrs->count > 0)
1459 {
1460 if (tlv_data.ipv4_int_reachs == NULL)
1461 {
1462 tlv_data.ipv4_int_reachs = list_new ();
1463 }
1464 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1465 nextnode (ipnode))
1466 {
1467 ipv4 = getdata (ipnode);
1468 ipreach =
1469 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1470 ipreach->metrics = circuit->metrics[level - 1];
1471 ipreach->prefix = ipv4->prefix;
1472 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1473 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1474 }
1475
1476 }
jardineb5d44e2003-12-23 08:09:43 +00001477#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001478 /*
1479 * Add IPv6 reachability of this circuit
1480 */
1481 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1482 circuit->ipv6_non_link->count > 0)
1483 {
1484
1485 if (tlv_data.ipv6_reachs == NULL)
1486 {
1487 tlv_data.ipv6_reachs = list_new ();
1488 }
1489 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1490 nextnode (ipnode))
1491 {
1492 ipv6 = getdata (ipnode);
1493 ip6reach =
1494 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1495 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1496 ip6reach->metric =
1497 htonl (circuit->metrics[level - 1].metric_default);
1498 ip6reach->control_info = 0;
1499 ip6reach->prefix_len = ipv6->prefixlen;
1500 memcpy (ip6reach->prefix, ipv6->prefix.s6_addr,
1501 (ipv6->prefixlen + 7) / 8);
1502 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1503 }
1504 }
1505#endif /* HAVE_IPV6 */
1506
1507 switch (circuit->circ_type)
1508 {
1509 case CIRCUIT_T_BROADCAST:
1510 if (level & circuit->circuit_is_type)
1511 {
1512 if (tlv_data.is_neighs == NULL)
1513 {
1514 tlv_data.is_neighs = list_new ();
1515 }
1516 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1517 memset (is_neigh, 0, sizeof (struct is_neigh));
1518 if (level == 1)
1519 memcpy (is_neigh->neigh_id,
1520 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1521 else
1522 memcpy (is_neigh->neigh_id,
1523 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1524 is_neigh->metrics = circuit->metrics[level - 1];
1525 listnode_add (tlv_data.is_neighs, is_neigh);
1526 }
1527 break;
1528 case CIRCUIT_T_P2P:
1529 nei = circuit->u.p2p.neighbor;
1530 if (nei && (level & nei->circuit_t))
1531 {
1532 if (tlv_data.is_neighs == NULL)
1533 {
1534 tlv_data.is_neighs = list_new ();
1535 tlv_data.is_neighs->del = free_tlv;
1536 }
1537 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1538 memset (is_neigh, 0, sizeof (struct is_neigh));
1539 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1540 is_neigh->metrics = circuit->metrics[level - 1];
1541 listnode_add (tlv_data.is_neighs, is_neigh);
1542 }
1543 break;
1544 case CIRCUIT_T_STATIC_IN:
1545 zlog_warn ("lsp_area_create: unsupported circuit type");
1546 break;
1547 case CIRCUIT_T_STATIC_OUT:
1548 zlog_warn ("lsp_area_create: unsupported circuit type");
1549 break;
1550 case CIRCUIT_T_DA:
1551 zlog_warn ("lsp_area_create: unsupported circuit type");
1552 break;
1553 default:
1554 zlog_warn ("lsp_area_create: unknown circuit type");
1555 }
1556 }
1557
1558 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1559 {
1560 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1561 lsp->tlv_data.ipv4_int_reachs = list_new ();
1562 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1563 &lsp->tlv_data.ipv4_int_reachs,
1564 IPV4_REACH_LEN, area->lsp_frag_threshold,
1565 tlv_add_ipv4_reachs);
1566 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1567 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1568 lsp0, area, level);
1569 }
1570
1571#ifdef HAVE_IPV6
1572 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1573 {
1574 if (lsp->tlv_data.ipv6_reachs == NULL)
1575 lsp->tlv_data.ipv6_reachs = list_new ();
1576 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1577 &lsp->tlv_data.ipv6_reachs,
1578 IPV6_REACH_LEN, area->lsp_frag_threshold,
1579 tlv_add_ipv6_reachs);
1580 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1581 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1582 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001583 }
1584#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001585
1586 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1587 {
1588 if (lsp->tlv_data.is_neighs == NULL)
1589 lsp->tlv_data.is_neighs = list_new ();
1590 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1591 &lsp->tlv_data.is_neighs,
1592 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1593 tlv_add_is_neighs);
1594 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1595 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1596 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001597 }
jardineb5d44e2003-12-23 08:09:43 +00001598
jardineb5d44e2003-12-23 08:09:43 +00001599 return;
1600}
1601#endif
1602
1603void
1604build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1605{
1606 struct list *circuit_list = area->circuit_list;
1607 struct isis_circuit *circuit;
1608 u_char *tlv_ptr;
1609 struct is_neigh *is_neigh;
1610
hassof390d2c2004-09-10 20:48:21 +00001611
jardineb5d44e2003-12-23 08:09:43 +00001612 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001613 /* the 2 is for the TL plus 1 for the nlpid */
1614 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1615 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1616 *(tlv_ptr + 1) = 1; /* one protocol */
1617#ifdef HAVE_IPV6 /*dunno if its right */
1618 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001619#else
hassof390d2c2004-09-10 20:48:21 +00001620 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001621#endif /* HAVE_IPV6 */
1622
1623 /* we should add our areas here
1624 * FIXME: we need to figure out which should be added? Adj? All? First? */
1625
1626 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001627 /* the 2 is for the TL plus 1 for the virtual field */
1628 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1629 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1630 *(tlv_ptr + 2) = 0; /* virtual is zero */
1631 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001632 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001633 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1634 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001635 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001636 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001637 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001638 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001639 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001640 circuit = (struct isis_circuit *) listhead (circuit_list);
1641 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001642 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001643 *(tlv_ptr + 1) =
1644 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001645
1646 /* FIXME: scan for adjencecies and add them */
1647
1648 /* FIXME: add reachability info */
1649
hassof390d2c2004-09-10 20:48:21 +00001650 /* adding dynamic hostname if needed */
1651 if (area->dynhostname)
1652 {
1653 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1654 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1655 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1656 lsp->tlv_data.hostname = (struct hostname *)
1657 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1658 /* the -1 is to fit the length in the struct */
1659 strlen (unix_hostname ())) - 1);
1660 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1661 strlen (unix_hostname ()));
1662 }
jardineb5d44e2003-12-23 08:09:43 +00001663
1664}
1665
1666/*
1667 * 7.3.7 Generation on non-pseudonode LSPs
1668 */
1669int
hassof390d2c2004-09-10 20:48:21 +00001670lsp_generate_non_pseudo (struct isis_area *area, int level)
1671{
jardineb5d44e2003-12-23 08:09:43 +00001672 struct isis_lsp *oldlsp, *newlsp;
1673 u_int32_t seq_num = 0;
1674 u_char lspid[ISIS_SYS_ID_LEN + 2];
1675
1676 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1677 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1678
1679 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001680 if ((area->is_type & level) == level)
1681 {
1682 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1683 if (oldlsp)
1684 {
1685 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1686 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1687 area->lspdb[level - 1]);
1688 /* FIXME: we should actually initiate a purge */
1689 }
1690 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1691 area->is_type, 0, level);
1692 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001693
hassof390d2c2004-09-10 20:48:21 +00001694 lsp_insert (newlsp, area->lspdb[level - 1]);
1695 /* build_lsp_data (newlsp, area); */
1696 lsp_build_nonpseudo (newlsp, area);
1697 /* time to calculate our checksum */
1698 lsp_seqnum_update (newlsp);
1699 }
jardineb5d44e2003-12-23 08:09:43 +00001700
1701 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001702 if (isis->debugs & DEBUG_ADJ_PACKETS)
1703 {
1704 /* FIXME: is this place right? fix missing info */
1705 zlog_info ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
1706 }
jardineb5d44e2003-12-23 08:09:43 +00001707
1708 return ISIS_OK;
1709}
1710
1711/*
1712 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1713 */
1714int
1715lsp_l1_generate (struct isis_area *area)
1716{
hassof390d2c2004-09-10 20:48:21 +00001717 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1718 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001719
1720 return lsp_generate_non_pseudo (area, 1);
1721}
1722
jardineb5d44e2003-12-23 08:09:43 +00001723/*
1724 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1725 */
1726int
1727lsp_l2_generate (struct isis_area *area)
1728{
hassof390d2c2004-09-10 20:48:21 +00001729 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1730 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001731
1732 return lsp_generate_non_pseudo (area, 2);
1733}
1734
1735int
1736lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1737{
1738 dict_t *lspdb = area->lspdb[level - 1];
1739 struct isis_lsp *lsp, *frag;
1740 struct listnode *node;
1741 u_char lspid[ISIS_SYS_ID_LEN + 2];
1742
1743 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1744 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001745
jardineb5d44e2003-12-23 08:09:43 +00001746 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001747
hassof390d2c2004-09-10 20:48:21 +00001748 if (!lsp)
1749 {
1750 zlog_err
1751 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1752 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001753
hassof390d2c2004-09-10 20:48:21 +00001754 return ISIS_ERROR;
1755 }
1756
1757 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001758 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001759 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1760 (area->max_lsp_lifetime[level - 1],
1761 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001762 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001763
1764 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1765 {
1766 zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1767 "seq 0x%08x, cksum 0x%04x lifetime %us",
1768 area->area_tag,
1769 level,
1770 rawlspid_print (lsp->lsp_header->lsp_id),
1771 ntohl (lsp->lsp_header->seq_num),
1772 ntohs (lsp->lsp_header->checksum),
1773 ntohs (lsp->lsp_header->rem_lifetime));
1774 }
jardineb5d44e2003-12-23 08:09:43 +00001775
1776 lsp->last_generated = time (NULL);
1777 area->lsp_regenerate_pending[level - 1] = 0;
1778 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001779 for (node = listhead (lsp->lspu.frags); node; nextnode (node))
1780 {
1781 frag = getdata (node);
1782 frag->lsp_header->rem_lifetime = htons (isis_jitter
1783 (area->
1784 max_lsp_lifetime[level - 1],
1785 MAX_AGE_JITTER));
1786 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1787 }
jardineb5d44e2003-12-23 08:09:43 +00001788
1789 if (area->ip_circuits)
1790 isis_spf_schedule (area, level);
1791#ifdef HAVE_IPV6
1792 if (area->ipv6_circuits)
1793 isis_spf_schedule6 (area, level);
1794#endif
1795 return ISIS_OK;
1796}
1797
jardineb5d44e2003-12-23 08:09:43 +00001798/*
1799 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1800 * time and set SRM
1801 */
hassof390d2c2004-09-10 20:48:21 +00001802int
jardineb5d44e2003-12-23 08:09:43 +00001803lsp_refresh_l1 (struct thread *thread)
1804{
1805 struct isis_area *area;
1806 unsigned long ref_time;
1807
1808 area = THREAD_ARG (thread);
1809 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001810
jardineb5d44e2003-12-23 08:09:43 +00001811 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001812 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001813 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001814
1815 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001816 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1817
hassof390d2c2004-09-10 20:48:21 +00001818 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1819 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001820
jardineb5d44e2003-12-23 08:09:43 +00001821 return ISIS_OK;
1822}
1823
hassof390d2c2004-09-10 20:48:21 +00001824int
jardineb5d44e2003-12-23 08:09:43 +00001825lsp_refresh_l2 (struct thread *thread)
1826{
1827 struct isis_area *area;
1828 unsigned long ref_time;
1829
1830 area = THREAD_ARG (thread);
1831 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001832
jardineb5d44e2003-12-23 08:09:43 +00001833 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001834 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001835 lsp_non_pseudo_regenerate (area, 2);
1836
hassof390d2c2004-09-10 20:48:21 +00001837 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001838 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1839
hassof390d2c2004-09-10 20:48:21 +00001840 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1841 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001842
jardineb5d44e2003-12-23 08:09:43 +00001843 return ISIS_OK;
1844}
1845
jardineb5d44e2003-12-23 08:09:43 +00001846/*
1847 * Something has changed -> regenerate LSP
1848 */
1849
1850int
1851lsp_l1_regenerate (struct thread *thread)
1852{
1853 struct isis_area *area;
1854
1855 area = THREAD_ARG (thread);
1856 area->lsp_regenerate_pending[0] = 0;
1857
1858 return lsp_non_pseudo_regenerate (area, 1);
1859}
1860
1861int
1862lsp_l2_regenerate (struct thread *thread)
1863{
1864 struct isis_area *area;
1865
1866 area = THREAD_ARG (thread);
1867 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001868
jardineb5d44e2003-12-23 08:09:43 +00001869 return lsp_non_pseudo_regenerate (area, 2);
1870}
1871
hassof390d2c2004-09-10 20:48:21 +00001872int
jardineb5d44e2003-12-23 08:09:43 +00001873lsp_regenerate_schedule (struct isis_area *area)
1874{
1875 struct isis_lsp *lsp;
1876 u_char id[ISIS_SYS_ID_LEN + 2];
1877 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001878 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1879 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001880 now = time (NULL);
1881 /*
1882 * First level 1
1883 */
hassof390d2c2004-09-10 20:48:21 +00001884 if (area->is_type & IS_LEVEL_1)
1885 {
1886 lsp = lsp_search (id, area->lspdb[0]);
1887 if (!lsp || area->lsp_regenerate_pending[0])
1888 goto L2;
1889 /*
1890 * Throttle avoidance
1891 */
1892 diff = now - lsp->last_generated;
1893 if (diff < MIN_LSP_GEN_INTERVAL)
1894 {
1895 area->lsp_regenerate_pending[0] = 1;
1896 thread_add_timer (master, lsp_l1_regenerate, area,
1897 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001898 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001899 }
1900 else
1901 lsp_non_pseudo_regenerate (area, 1);
1902 }
jardineb5d44e2003-12-23 08:09:43 +00001903 /*
1904 * then 2
1905 */
hassof390d2c2004-09-10 20:48:21 +00001906L2:
1907 if (area->is_type & IS_LEVEL_2)
1908 {
1909 lsp = lsp_search (id, area->lspdb[1]);
1910 if (!lsp || area->lsp_regenerate_pending[1])
1911 return ISIS_OK;
1912 /*
1913 * Throttle avoidance
1914 */
1915 diff = now - lsp->last_generated;
1916 if (diff < MIN_LSP_GEN_INTERVAL)
1917 {
1918 area->lsp_regenerate_pending[1] = 1;
1919 thread_add_timer (master, lsp_l2_regenerate, area,
1920 MIN_LSP_GEN_INTERVAL - diff);
1921 return ISIS_OK;
1922 }
1923 else
1924 lsp_non_pseudo_regenerate (area, 2);
1925 }
1926
1927 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001928}
1929
1930/*
1931 * Funcs for pseudonode LSPs
1932 */
1933
1934/*
1935 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1936 */
1937void
hassof390d2c2004-09-10 20:48:21 +00001938lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1939 int level)
jardineb5d44e2003-12-23 08:09:43 +00001940{
1941 struct isis_adjacency *adj;
1942 struct is_neigh *is_neigh;
1943 struct es_neigh *es_neigh;
1944 struct list *adj_list;
1945 struct listnode *node;
1946 struct isis_passwd *passwd;
1947
1948 assert (circuit);
1949 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001950
jardineb5d44e2003-12-23 08:09:43 +00001951 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001952 return; /* we are not DIS on this circuit */
1953
jardineb5d44e2003-12-23 08:09:43 +00001954 lsp->level = level;
1955 if (level == 1)
1956 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1957 else
1958 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1959
1960 /*
1961 * add self to IS neighbours
1962 */
hassof390d2c2004-09-10 20:48:21 +00001963 if (lsp->tlv_data.is_neighs == NULL)
1964 {
1965 lsp->tlv_data.is_neighs = list_new ();
1966 lsp->tlv_data.is_neighs->del = free_tlv;
1967 }
jardineb5d44e2003-12-23 08:09:43 +00001968 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1969 memset (is_neigh, 0, sizeof (struct is_neigh));
1970 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1971 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001972
1973 adj_list = list_new ();
1974 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1975
1976 for (node = listhead (adj_list); node; nextnode (node))
1977 {
1978 adj = getdata (node);
1979 if (adj->circuit_t & level)
1980 {
1981 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1982 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1983 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1984 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1985 {
1986 /* an IS neighbour -> add it */
1987 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1988 memset (is_neigh, 0, sizeof (struct is_neigh));
1989 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1990 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1991 }
1992 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1993 {
1994 /* an ES neigbour add it, if we are building level 1 LSP */
1995 /* FIXME: the tlv-format is hard to use here */
1996 if (lsp->tlv_data.es_neighs == NULL)
1997 {
1998 lsp->tlv_data.es_neighs = list_new ();
1999 lsp->tlv_data.es_neighs->del = free_tlv;
2000 }
2001 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2002 memset (es_neigh, 0, sizeof (struct es_neigh));
2003 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
2004 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
2005 }
2006 }
jardineb5d44e2003-12-23 08:09:43 +00002007 }
hassof390d2c2004-09-10 20:48:21 +00002008
jardineb5d44e2003-12-23 08:09:43 +00002009 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2010 /*
2011 * Add the authentication info if it's present
2012 */
hassof390d2c2004-09-10 20:48:21 +00002013 (level == 1) ? (passwd = &circuit->area->area_passwd) :
2014 (passwd = &circuit->area->domain_passwd);
2015 if (passwd->type)
2016 {
2017 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
2018 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
2019 }
jardineb5d44e2003-12-23 08:09:43 +00002020
2021 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2022 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2023
2024 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2025 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2026
2027 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002028 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2029 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2030
jardineb5d44e2003-12-23 08:09:43 +00002031 list_delete (adj_list);
2032
2033 return;
2034}
2035
2036int
2037lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
2038{
2039 dict_t *lspdb = circuit->area->lspdb[level - 1];
2040 struct isis_lsp *lsp;
2041 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00002042
jardineb5d44e2003-12-23 08:09:43 +00002043 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002044 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2045 LSP_FRAGMENT (lsp_id) = 0;
2046
jardineb5d44e2003-12-23 08:09:43 +00002047 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002048
2049 if (!lsp)
2050 {
2051 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
2052 rawlspid_print (lsp_id));
2053 return ISIS_ERROR;
2054 }
2055 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002056
2057 lsp_build_pseudo (lsp, circuit, level);
2058
hassof390d2c2004-09-10 20:48:21 +00002059 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00002060 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00002061 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002062
2063 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00002064
2065 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2066 {
2067 zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
2068 circuit->area->area_tag, level,
2069 rawlspid_print (lsp->lsp_header->lsp_id));
2070 }
jardineb5d44e2003-12-23 08:09:43 +00002071
2072 lsp->last_generated = time (NULL);
2073 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002074
jardineb5d44e2003-12-23 08:09:43 +00002075 return ISIS_OK;
2076}
2077
jardineb5d44e2003-12-23 08:09:43 +00002078int
2079lsp_l1_refresh_pseudo (struct thread *thread)
2080{
2081 struct isis_circuit *circuit;
2082 int retval;
2083 unsigned long ref_time;
2084
hassof390d2c2004-09-10 20:48:21 +00002085 circuit = THREAD_ARG (thread);
2086
jardineb5d44e2003-12-23 08:09:43 +00002087 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002088 return ISIS_ERROR; /* FIXME: purge and such */
2089
hasso13c48f72004-09-10 21:19:13 +00002090 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2091
jardineb5d44e2003-12-23 08:09:43 +00002092 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002093
2094 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002095 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2096
hassof390d2c2004-09-10 20:48:21 +00002097 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2098 lsp_l1_refresh_pseudo, circuit,
2099 isis_jitter (ref_time, MAX_AGE_JITTER));
2100
jardineb5d44e2003-12-23 08:09:43 +00002101 return retval;
2102}
2103
hassof390d2c2004-09-10 20:48:21 +00002104int
jardineb5d44e2003-12-23 08:09:43 +00002105lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2106{
2107 struct isis_lsp *lsp;
2108 u_char id[ISIS_SYS_ID_LEN + 2];
2109 unsigned long ref_time;
2110
hassof390d2c2004-09-10 20:48:21 +00002111 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2112 LSP_FRAGMENT (id) = 0;
2113 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002114
2115 /*
2116 * If for some reason have a pseudo LSP in the db already -> regenerate
2117 */
2118 if (lsp_search (id, circuit->area->lspdb[0]))
2119 return lsp_pseudo_regenerate (circuit, 1);
2120 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002121 1, circuit->area->is_type, 0, 1);
2122
jardineb5d44e2003-12-23 08:09:43 +00002123 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002124
jardineb5d44e2003-12-23 08:09:43 +00002125 lsp->own_lsp = 1;
2126 lsp_insert (lsp, circuit->area->lspdb[0]);
2127 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2128
hassof390d2c2004-09-10 20:48:21 +00002129 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002130 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2131
hassof390d2c2004-09-10 20:48:21 +00002132 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2133 lsp_l1_refresh_pseudo, circuit,
2134 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002135
2136 return lsp_regenerate_schedule (circuit->area);
2137}
2138
2139int
2140lsp_l2_refresh_pseudo (struct thread *thread)
2141{
2142 struct isis_circuit *circuit;
2143 int retval;
2144 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002145 circuit = THREAD_ARG (thread);
2146
jardineb5d44e2003-12-23 08:09:43 +00002147 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002148 return ISIS_ERROR; /* FIXME: purge and such */
2149
hasso13c48f72004-09-10 21:19:13 +00002150 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2151
jardineb5d44e2003-12-23 08:09:43 +00002152 retval = lsp_pseudo_regenerate (circuit, 2);
2153
hassof390d2c2004-09-10 20:48:21 +00002154 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002155 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2156
hassof390d2c2004-09-10 20:48:21 +00002157 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2158 lsp_l2_refresh_pseudo, circuit,
2159 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002160
jardineb5d44e2003-12-23 08:09:43 +00002161 return retval;
2162}
2163
hassof390d2c2004-09-10 20:48:21 +00002164int
jardineb5d44e2003-12-23 08:09:43 +00002165lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2166{
2167 struct isis_lsp *lsp;
2168 u_char id[ISIS_SYS_ID_LEN + 2];
2169 unsigned long ref_time;
2170
hassof390d2c2004-09-10 20:48:21 +00002171 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2172 LSP_FRAGMENT (id) = 0;
2173 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002174
2175 if (lsp_search (id, circuit->area->lspdb[1]))
2176 return lsp_pseudo_regenerate (circuit, 2);
2177
2178 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002179 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002180
2181 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002182
2183 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002184 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2185
2186
2187 lsp->own_lsp = 1;
2188 lsp_insert (lsp, circuit->area->lspdb[1]);
2189 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002190
2191 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2192 lsp_l2_refresh_pseudo, circuit,
2193 isis_jitter (ref_time, MAX_AGE_JITTER));
2194
jardineb5d44e2003-12-23 08:09:43 +00002195 return lsp_regenerate_schedule (circuit->area);
2196}
2197
jardineb5d44e2003-12-23 08:09:43 +00002198/*
2199 * Walk through LSPs for an area
2200 * - set remaining lifetime
2201 * - set LSPs with SRMflag set for sending
2202 */
hassof390d2c2004-09-10 20:48:21 +00002203int
jardineb5d44e2003-12-23 08:09:43 +00002204lsp_tick (struct thread *thread)
2205{
2206 struct isis_area *area;
2207 struct isis_circuit *circuit;
2208 struct isis_lsp *lsp;
2209 struct list *lsp_list;
2210 struct listnode *lspnode, *cnode;
2211 dnode_t *dnode, *dnode_next;
2212 int level;
2213
2214 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002215
jardineb5d44e2003-12-23 08:09:43 +00002216 area = THREAD_ARG (thread);
2217 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002218 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002219 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002220
2221 /*
2222 * Build a list of LSPs with (any) SRMflag set
2223 * and removed the ones that have aged out
2224 */
hassof390d2c2004-09-10 20:48:21 +00002225 for (level = 0; level < ISIS_LEVELS; level++)
2226 {
2227 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2228 {
2229 dnode = dict_first (area->lspdb[level]);
2230 while (dnode != NULL)
2231 {
2232 dnode_next = dict_next (area->lspdb[level], dnode);
2233 lsp = dnode_get (dnode);
2234 lsp_set_time (lsp);
2235 if (lsp->age_out == 0)
2236 {
jardineb5d44e2003-12-23 08:09:43 +00002237
hassof390d2c2004-09-10 20:48:21 +00002238 zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2239 area->area_tag,
2240 lsp->level,
2241 rawlspid_print (lsp->lsp_header->lsp_id),
2242 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002243
hassof390d2c2004-09-10 20:48:21 +00002244 lsp_destroy (lsp);
2245 dict_delete (area->lspdb[level], dnode);
2246 }
2247 else if (flags_any_set (lsp->SRMflags))
2248 listnode_add (lsp_list, lsp);
2249 dnode = dnode_next;
2250 }
jardineb5d44e2003-12-23 08:09:43 +00002251
hassof390d2c2004-09-10 20:48:21 +00002252 /*
2253 * Send LSPs on circuits indicated by the SRMflags
2254 */
2255 if (listcount (lsp_list) > 0)
2256 {
2257 for (cnode = listhead (area->circuit_list); cnode;
2258 nextnode (cnode))
2259 {
2260 circuit = getdata (cnode);
2261 for (lspnode = listhead (lsp_list); lspnode;
2262 nextnode (lspnode))
2263 {
2264 lsp = getdata (lspnode);
2265 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2266 {
2267 /* FIXME: if same or elder lsp is already in lsp
2268 * queue */
2269 listnode_add (circuit->lsp_queue, lsp);
2270 thread_add_event (master, send_lsp, circuit, 0);
2271 }
2272 }
2273 }
2274 }
2275 list_delete_all_node (lsp_list);
2276 }
jardineb5d44e2003-12-23 08:09:43 +00002277 }
jardineb5d44e2003-12-23 08:09:43 +00002278
2279 list_delete (lsp_list);
2280
2281 return ISIS_OK;
2282}
2283
jardineb5d44e2003-12-23 08:09:43 +00002284void
hassof390d2c2004-09-10 20:48:21 +00002285lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002286{
2287 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002288
jardineb5d44e2003-12-23 08:09:43 +00002289 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002290
2291 if (lsp && lsp->purged == 0)
2292 {
2293 lsp->lsp_header->rem_lifetime = htons (0);
2294 lsp->lsp_header->pdu_len =
2295 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2296 lsp->purged = 0;
2297 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2298 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2299 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2300 }
2301
jardineb5d44e2003-12-23 08:09:43 +00002302 return;
2303}
2304
2305/*
2306 * Purge own LSP that is received and we don't have.
2307 * -> Do as in 7.3.16.4
2308 */
2309void
hassof390d2c2004-09-10 20:48:21 +00002310lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2311 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002312{
2313 struct isis_lsp *lsp;
2314
2315 /*
2316 * We need to create the LSP to be purged
2317 */
2318 zlog_info ("LSP PURGE NON EXIST");
2319 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2320 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002321 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2322 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002323 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2324 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002325 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002326 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002327 : L2_LINK_STATE);
2328 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2329 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002330 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002331
jardineb5d44e2003-12-23 08:09:43 +00002332 /*
2333 * Retain only LSP header
2334 */
2335 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2336 /*
2337 * Set the remaining lifetime to 0
2338 */
2339 lsp->lsp_header->rem_lifetime = 0;
2340 /*
2341 * Put the lsp into LSPdb
2342 */
hassof390d2c2004-09-10 20:48:21 +00002343 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002344
2345 /*
2346 * Send in to whole area
2347 */
2348 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002349
jardineb5d44e2003-12-23 08:09:43 +00002350 return;
2351}
2352
2353#ifdef TOPOLOGY_GENERATE
2354int
2355top_lsp_refresh (struct thread *thread)
2356{
hassof390d2c2004-09-10 20:48:21 +00002357 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002358
2359 lsp = THREAD_ARG (thread);
2360 assert (lsp);
2361
2362 lsp->t_lsp_top_ref = NULL;
2363
hassof390d2c2004-09-10 20:48:21 +00002364 lsp->lsp_header->rem_lifetime =
2365 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2366 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002367
2368 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002369 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2370 {
2371 zlog_info ("ISIS-Upd (): refreshing Topology L1 %s",
2372 rawlspid_print (lsp->lsp_header->lsp_id));
2373 }
jardineb5d44e2003-12-23 08:09:43 +00002374
2375 /* time to calculate our checksum */
2376 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002377 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2378 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2379 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002380
2381 return ISIS_OK;
2382}
2383
2384void
2385generate_topology_lsps (struct isis_area *area)
2386{
2387 struct listnode *node;
2388 int i, max = 0;
2389 struct arc *arc;
2390 u_char lspid[ISIS_SYS_ID_LEN + 2];
2391 struct isis_lsp *lsp;
2392
2393 /* first we find the maximal node */
hassof390d2c2004-09-10 20:48:21 +00002394 LIST_LOOP (area->topology, arc, node)
2395 {
2396 if (arc->from_node > max)
2397 max = arc->from_node;
2398 if (arc->to_node > max)
2399 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002400 }
2401
hassof390d2c2004-09-10 20:48:21 +00002402 for (i = 1; i < (max + 1); i++)
2403 {
2404 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2405 LSP_PSEUDO_ID (lspid) = 0x00;
2406 LSP_FRAGMENT (lspid) = 0x00;
2407 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2408 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002409
hassof390d2c2004-09-10 20:48:21 +00002410 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2411 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2412 1);
2413 lsp->from_topology = 1;
2414 /* creating data based on topology */
2415 build_topology_lsp_data (lsp, area, i);
2416 /* time to calculate our checksum */
2417 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2418 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2419 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2420 isis_jitter (MAX_LSP_GEN_INTERVAL,
2421 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002422
hassof390d2c2004-09-10 20:48:21 +00002423 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2424 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002425
hassof390d2c2004-09-10 20:48:21 +00002426 }
jardineb5d44e2003-12-23 08:09:43 +00002427}
2428
2429void
2430remove_topology_lsps (struct isis_area *area)
2431{
2432 struct isis_lsp *lsp;
2433 dnode_t *dnode, *dnode_next;
2434
2435 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002436 while (dnode != NULL)
2437 {
2438 dnode_next = dict_next (area->lspdb[0], dnode);
2439 lsp = dnode_get (dnode);
2440 if (lsp->from_topology)
2441 {
2442 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2443 lsp_destroy (lsp);
2444 dict_delete (area->lspdb[0], dnode);
2445 }
2446 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002447 }
jardineb5d44e2003-12-23 08:09:43 +00002448}
2449
2450void
hassof390d2c2004-09-10 20:48:21 +00002451build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002452 int lsp_top_num)
2453{
2454 struct listnode *node;
2455 struct arc *arc;
2456 u_char *tlv_ptr;
2457 struct is_neigh *is_neigh;
2458 int to_lsp = 0;
2459 char buff[200];
2460
2461 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002462 /* the 2 is for the TL plus 1 for the nlpid */
2463 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2464 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2465 *(tlv_ptr + 1) = 1; /* one protocol */
2466 *(tlv_ptr + 2) = NLPID_IP;
2467 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002468
2469 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002470 /* the 2 is for the TL plus 1 for the virtual field */
2471 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2472 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2473 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2474 *(tlv_ptr + 2) = 0; /* virtual is zero */
2475 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002476
2477 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002478 if (lsp_top_num == 1)
2479 {
jardineb5d44e2003-12-23 08:09:43 +00002480 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002481 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2482 sizeof (struct
2483 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002484 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002485 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2486 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002487 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002488 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002489 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2490 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2491 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2492 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002493 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2494 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002495 }
hassof390d2c2004-09-10 20:48:21 +00002496
2497 /* addding is reachabilities */
2498 LIST_LOOP (area->topology, arc, node)
2499 {
2500 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2501 {
2502 if (arc->to_node == lsp_top_num)
2503 to_lsp = arc->from_node;
2504 if (arc->from_node == lsp_top_num)
2505 to_lsp = arc->to_node;
2506
2507 /* if the length here is about to cross the FF limit, we reTLV */
2508 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2509 {
2510 /* retlv */
2511 /* the 2 is for the TL plus 1 for the virtual field */
2512 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2513 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2514 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2515 *(tlv_ptr + 2) = 0; /* virtual is zero */
2516 }
2517 /* doing this here assures us that we won't add an "empty" tlv */
2518 /* assign space for the is_neigh at the pdu end */
2519 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2520 sizeof (struct
2521 is_neigh));
2522 /* add this node to our list */
2523 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2524 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2525 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2526 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2527 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2528 is_neigh->metrics.metric_default = arc->distance;
2529 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2530 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2531 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2532 /* don't forget the length */
2533 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2534 }
jardineb5d44e2003-12-23 08:09:43 +00002535 }
2536
hassof390d2c2004-09-10 20:48:21 +00002537 /* adding dynamic hostname if needed */
2538 if (area->dynhostname)
2539 {
2540 memset (buff, 0x00, 200);
2541 sprintf (buff, "feedme%d", lsp_top_num);
2542 /* the 2 is for the TL */
2543 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2544 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2545 *(tlv_ptr + 1) = strlen (buff); /* Length */
2546 /* the -1 is to fit the length in the struct */
2547 lsp->tlv_data.hostname = (struct hostname *)
2548 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2549 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2550 }
jardineb5d44e2003-12-23 08:09:43 +00002551
2552 /* thanks to hannes, another bug bites the dust */
hassof390d2c2004-09-10 20:48:21 +00002553 lsp->pdu->putp = ntohs (lsp->lsp_header->pdu_len);
2554 lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00002555}
2556#endif /* TOPOLOGY_GENERATE */