blob: d0764e04182a94935372d3d7145afbb39512bb20 [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
hasso67851572004-09-21 14:17:04 +00001374 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001375 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];
hassof390d2c2004-09-10 20:48:21 +00001471 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001472 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1473 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001474 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1475 }
1476
1477 }
jardineb5d44e2003-12-23 08:09:43 +00001478#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001479 /*
1480 * Add IPv6 reachability of this circuit
1481 */
1482 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1483 circuit->ipv6_non_link->count > 0)
1484 {
1485
1486 if (tlv_data.ipv6_reachs == NULL)
1487 {
1488 tlv_data.ipv6_reachs = list_new ();
1489 }
1490 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1491 nextnode (ipnode))
1492 {
1493 ipv6 = getdata (ipnode);
1494 ip6reach =
1495 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1496 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1497 ip6reach->metric =
1498 htonl (circuit->metrics[level - 1].metric_default);
1499 ip6reach->control_info = 0;
1500 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001501 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1502 apply_mask_ipv6 (ip6prefix);
1503 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1504 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001505 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1506 }
1507 }
1508#endif /* HAVE_IPV6 */
1509
1510 switch (circuit->circ_type)
1511 {
1512 case CIRCUIT_T_BROADCAST:
1513 if (level & circuit->circuit_is_type)
1514 {
1515 if (tlv_data.is_neighs == NULL)
1516 {
1517 tlv_data.is_neighs = list_new ();
1518 }
1519 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1520 memset (is_neigh, 0, sizeof (struct is_neigh));
1521 if (level == 1)
1522 memcpy (is_neigh->neigh_id,
1523 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1524 else
1525 memcpy (is_neigh->neigh_id,
1526 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1527 is_neigh->metrics = circuit->metrics[level - 1];
1528 listnode_add (tlv_data.is_neighs, is_neigh);
1529 }
1530 break;
1531 case CIRCUIT_T_P2P:
1532 nei = circuit->u.p2p.neighbor;
1533 if (nei && (level & nei->circuit_t))
1534 {
1535 if (tlv_data.is_neighs == NULL)
1536 {
1537 tlv_data.is_neighs = list_new ();
1538 tlv_data.is_neighs->del = free_tlv;
1539 }
1540 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1541 memset (is_neigh, 0, sizeof (struct is_neigh));
1542 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1543 is_neigh->metrics = circuit->metrics[level - 1];
1544 listnode_add (tlv_data.is_neighs, is_neigh);
1545 }
1546 break;
1547 case CIRCUIT_T_STATIC_IN:
1548 zlog_warn ("lsp_area_create: unsupported circuit type");
1549 break;
1550 case CIRCUIT_T_STATIC_OUT:
1551 zlog_warn ("lsp_area_create: unsupported circuit type");
1552 break;
1553 case CIRCUIT_T_DA:
1554 zlog_warn ("lsp_area_create: unsupported circuit type");
1555 break;
1556 default:
1557 zlog_warn ("lsp_area_create: unknown circuit type");
1558 }
1559 }
1560
1561 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1562 {
1563 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1564 lsp->tlv_data.ipv4_int_reachs = list_new ();
1565 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1566 &lsp->tlv_data.ipv4_int_reachs,
1567 IPV4_REACH_LEN, area->lsp_frag_threshold,
1568 tlv_add_ipv4_reachs);
1569 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1570 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1571 lsp0, area, level);
1572 }
1573
1574#ifdef HAVE_IPV6
1575 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1576 {
1577 if (lsp->tlv_data.ipv6_reachs == NULL)
1578 lsp->tlv_data.ipv6_reachs = list_new ();
1579 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1580 &lsp->tlv_data.ipv6_reachs,
1581 IPV6_REACH_LEN, area->lsp_frag_threshold,
1582 tlv_add_ipv6_reachs);
1583 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1584 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1585 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001586 }
1587#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001588
1589 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1590 {
1591 if (lsp->tlv_data.is_neighs == NULL)
1592 lsp->tlv_data.is_neighs = list_new ();
1593 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1594 &lsp->tlv_data.is_neighs,
1595 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1596 tlv_add_is_neighs);
1597 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1598 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1599 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001600 }
jardineb5d44e2003-12-23 08:09:43 +00001601
jardineb5d44e2003-12-23 08:09:43 +00001602 return;
1603}
1604#endif
1605
1606void
1607build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1608{
1609 struct list *circuit_list = area->circuit_list;
1610 struct isis_circuit *circuit;
1611 u_char *tlv_ptr;
1612 struct is_neigh *is_neigh;
1613
hassof390d2c2004-09-10 20:48:21 +00001614
jardineb5d44e2003-12-23 08:09:43 +00001615 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001616 /* the 2 is for the TL plus 1 for the nlpid */
1617 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1618 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1619 *(tlv_ptr + 1) = 1; /* one protocol */
1620#ifdef HAVE_IPV6 /*dunno if its right */
1621 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001622#else
hassof390d2c2004-09-10 20:48:21 +00001623 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001624#endif /* HAVE_IPV6 */
1625
1626 /* we should add our areas here
1627 * FIXME: we need to figure out which should be added? Adj? All? First? */
1628
1629 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001630 /* the 2 is for the TL plus 1 for the virtual field */
1631 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1632 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1633 *(tlv_ptr + 2) = 0; /* virtual is zero */
1634 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001635 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001636 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1637 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001638 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001639 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001640 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001641 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001642 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001643 circuit = (struct isis_circuit *) listhead (circuit_list);
1644 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001645 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001646 *(tlv_ptr + 1) =
1647 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001648
1649 /* FIXME: scan for adjencecies and add them */
1650
1651 /* FIXME: add reachability info */
1652
hassof390d2c2004-09-10 20:48:21 +00001653 /* adding dynamic hostname if needed */
1654 if (area->dynhostname)
1655 {
1656 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1657 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1658 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1659 lsp->tlv_data.hostname = (struct hostname *)
1660 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1661 /* the -1 is to fit the length in the struct */
1662 strlen (unix_hostname ())) - 1);
1663 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1664 strlen (unix_hostname ()));
1665 }
jardineb5d44e2003-12-23 08:09:43 +00001666
1667}
1668
1669/*
1670 * 7.3.7 Generation on non-pseudonode LSPs
1671 */
1672int
hassof390d2c2004-09-10 20:48:21 +00001673lsp_generate_non_pseudo (struct isis_area *area, int level)
1674{
jardineb5d44e2003-12-23 08:09:43 +00001675 struct isis_lsp *oldlsp, *newlsp;
1676 u_int32_t seq_num = 0;
1677 u_char lspid[ISIS_SYS_ID_LEN + 2];
1678
1679 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1680 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1681
1682 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001683 if ((area->is_type & level) == level)
1684 {
1685 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1686 if (oldlsp)
1687 {
1688 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1689 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1690 area->lspdb[level - 1]);
1691 /* FIXME: we should actually initiate a purge */
1692 }
1693 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1694 area->is_type, 0, level);
1695 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001696
hassof390d2c2004-09-10 20:48:21 +00001697 lsp_insert (newlsp, area->lspdb[level - 1]);
1698 /* build_lsp_data (newlsp, area); */
1699 lsp_build_nonpseudo (newlsp, area);
1700 /* time to calculate our checksum */
1701 lsp_seqnum_update (newlsp);
1702 }
jardineb5d44e2003-12-23 08:09:43 +00001703
1704 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001705 if (isis->debugs & DEBUG_ADJ_PACKETS)
1706 {
1707 /* FIXME: is this place right? fix missing info */
1708 zlog_info ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
1709 }
jardineb5d44e2003-12-23 08:09:43 +00001710
1711 return ISIS_OK;
1712}
1713
1714/*
1715 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1716 */
1717int
1718lsp_l1_generate (struct isis_area *area)
1719{
hassof390d2c2004-09-10 20:48:21 +00001720 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1721 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001722
1723 return lsp_generate_non_pseudo (area, 1);
1724}
1725
jardineb5d44e2003-12-23 08:09:43 +00001726/*
1727 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1728 */
1729int
1730lsp_l2_generate (struct isis_area *area)
1731{
hassof390d2c2004-09-10 20:48:21 +00001732 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1733 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001734
1735 return lsp_generate_non_pseudo (area, 2);
1736}
1737
1738int
1739lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1740{
1741 dict_t *lspdb = area->lspdb[level - 1];
1742 struct isis_lsp *lsp, *frag;
1743 struct listnode *node;
1744 u_char lspid[ISIS_SYS_ID_LEN + 2];
1745
1746 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1747 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001748
jardineb5d44e2003-12-23 08:09:43 +00001749 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001750
hassof390d2c2004-09-10 20:48:21 +00001751 if (!lsp)
1752 {
1753 zlog_err
1754 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1755 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001756
hassof390d2c2004-09-10 20:48:21 +00001757 return ISIS_ERROR;
1758 }
1759
1760 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001761 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001762 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1763 (area->max_lsp_lifetime[level - 1],
1764 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001765 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001766
1767 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1768 {
1769 zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1770 "seq 0x%08x, cksum 0x%04x lifetime %us",
1771 area->area_tag,
1772 level,
1773 rawlspid_print (lsp->lsp_header->lsp_id),
1774 ntohl (lsp->lsp_header->seq_num),
1775 ntohs (lsp->lsp_header->checksum),
1776 ntohs (lsp->lsp_header->rem_lifetime));
1777 }
jardineb5d44e2003-12-23 08:09:43 +00001778
1779 lsp->last_generated = time (NULL);
1780 area->lsp_regenerate_pending[level - 1] = 0;
1781 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001782 for (node = listhead (lsp->lspu.frags); node; nextnode (node))
1783 {
1784 frag = getdata (node);
1785 frag->lsp_header->rem_lifetime = htons (isis_jitter
1786 (area->
1787 max_lsp_lifetime[level - 1],
1788 MAX_AGE_JITTER));
1789 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1790 }
jardineb5d44e2003-12-23 08:09:43 +00001791
1792 if (area->ip_circuits)
1793 isis_spf_schedule (area, level);
1794#ifdef HAVE_IPV6
1795 if (area->ipv6_circuits)
1796 isis_spf_schedule6 (area, level);
1797#endif
1798 return ISIS_OK;
1799}
1800
jardineb5d44e2003-12-23 08:09:43 +00001801/*
1802 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1803 * time and set SRM
1804 */
hassof390d2c2004-09-10 20:48:21 +00001805int
jardineb5d44e2003-12-23 08:09:43 +00001806lsp_refresh_l1 (struct thread *thread)
1807{
1808 struct isis_area *area;
1809 unsigned long ref_time;
1810
1811 area = THREAD_ARG (thread);
1812 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001813
jardineb5d44e2003-12-23 08:09:43 +00001814 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001815 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001816 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001817
1818 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001819 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1820
hassof390d2c2004-09-10 20:48:21 +00001821 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1822 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001823
jardineb5d44e2003-12-23 08:09:43 +00001824 return ISIS_OK;
1825}
1826
hassof390d2c2004-09-10 20:48:21 +00001827int
jardineb5d44e2003-12-23 08:09:43 +00001828lsp_refresh_l2 (struct thread *thread)
1829{
1830 struct isis_area *area;
1831 unsigned long ref_time;
1832
1833 area = THREAD_ARG (thread);
1834 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001835
jardineb5d44e2003-12-23 08:09:43 +00001836 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001837 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001838 lsp_non_pseudo_regenerate (area, 2);
1839
hassof390d2c2004-09-10 20:48:21 +00001840 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001841 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1842
hassof390d2c2004-09-10 20:48:21 +00001843 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1844 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001845
jardineb5d44e2003-12-23 08:09:43 +00001846 return ISIS_OK;
1847}
1848
jardineb5d44e2003-12-23 08:09:43 +00001849/*
1850 * Something has changed -> regenerate LSP
1851 */
1852
1853int
1854lsp_l1_regenerate (struct thread *thread)
1855{
1856 struct isis_area *area;
1857
1858 area = THREAD_ARG (thread);
1859 area->lsp_regenerate_pending[0] = 0;
1860
1861 return lsp_non_pseudo_regenerate (area, 1);
1862}
1863
1864int
1865lsp_l2_regenerate (struct thread *thread)
1866{
1867 struct isis_area *area;
1868
1869 area = THREAD_ARG (thread);
1870 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001871
jardineb5d44e2003-12-23 08:09:43 +00001872 return lsp_non_pseudo_regenerate (area, 2);
1873}
1874
hassof390d2c2004-09-10 20:48:21 +00001875int
jardineb5d44e2003-12-23 08:09:43 +00001876lsp_regenerate_schedule (struct isis_area *area)
1877{
1878 struct isis_lsp *lsp;
1879 u_char id[ISIS_SYS_ID_LEN + 2];
1880 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001881 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1882 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001883 now = time (NULL);
1884 /*
1885 * First level 1
1886 */
hassof390d2c2004-09-10 20:48:21 +00001887 if (area->is_type & IS_LEVEL_1)
1888 {
1889 lsp = lsp_search (id, area->lspdb[0]);
1890 if (!lsp || area->lsp_regenerate_pending[0])
1891 goto L2;
1892 /*
1893 * Throttle avoidance
1894 */
1895 diff = now - lsp->last_generated;
1896 if (diff < MIN_LSP_GEN_INTERVAL)
1897 {
1898 area->lsp_regenerate_pending[0] = 1;
1899 thread_add_timer (master, lsp_l1_regenerate, area,
1900 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001901 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001902 }
1903 else
1904 lsp_non_pseudo_regenerate (area, 1);
1905 }
jardineb5d44e2003-12-23 08:09:43 +00001906 /*
1907 * then 2
1908 */
hassof390d2c2004-09-10 20:48:21 +00001909L2:
1910 if (area->is_type & IS_LEVEL_2)
1911 {
1912 lsp = lsp_search (id, area->lspdb[1]);
1913 if (!lsp || area->lsp_regenerate_pending[1])
1914 return ISIS_OK;
1915 /*
1916 * Throttle avoidance
1917 */
1918 diff = now - lsp->last_generated;
1919 if (diff < MIN_LSP_GEN_INTERVAL)
1920 {
1921 area->lsp_regenerate_pending[1] = 1;
1922 thread_add_timer (master, lsp_l2_regenerate, area,
1923 MIN_LSP_GEN_INTERVAL - diff);
1924 return ISIS_OK;
1925 }
1926 else
1927 lsp_non_pseudo_regenerate (area, 2);
1928 }
1929
1930 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001931}
1932
1933/*
1934 * Funcs for pseudonode LSPs
1935 */
1936
1937/*
1938 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1939 */
1940void
hassof390d2c2004-09-10 20:48:21 +00001941lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1942 int level)
jardineb5d44e2003-12-23 08:09:43 +00001943{
1944 struct isis_adjacency *adj;
1945 struct is_neigh *is_neigh;
1946 struct es_neigh *es_neigh;
1947 struct list *adj_list;
1948 struct listnode *node;
1949 struct isis_passwd *passwd;
1950
1951 assert (circuit);
1952 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001953
jardineb5d44e2003-12-23 08:09:43 +00001954 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001955 return; /* we are not DIS on this circuit */
1956
jardineb5d44e2003-12-23 08:09:43 +00001957 lsp->level = level;
1958 if (level == 1)
1959 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1960 else
1961 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1962
1963 /*
1964 * add self to IS neighbours
1965 */
hassof390d2c2004-09-10 20:48:21 +00001966 if (lsp->tlv_data.is_neighs == NULL)
1967 {
1968 lsp->tlv_data.is_neighs = list_new ();
1969 lsp->tlv_data.is_neighs->del = free_tlv;
1970 }
jardineb5d44e2003-12-23 08:09:43 +00001971 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1972 memset (is_neigh, 0, sizeof (struct is_neigh));
1973 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1974 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001975
1976 adj_list = list_new ();
1977 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1978
1979 for (node = listhead (adj_list); node; nextnode (node))
1980 {
1981 adj = getdata (node);
1982 if (adj->circuit_t & level)
1983 {
1984 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1985 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1986 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1987 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1988 {
1989 /* an IS neighbour -> add it */
1990 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1991 memset (is_neigh, 0, sizeof (struct is_neigh));
1992 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1993 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1994 }
1995 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1996 {
1997 /* an ES neigbour add it, if we are building level 1 LSP */
1998 /* FIXME: the tlv-format is hard to use here */
1999 if (lsp->tlv_data.es_neighs == NULL)
2000 {
2001 lsp->tlv_data.es_neighs = list_new ();
2002 lsp->tlv_data.es_neighs->del = free_tlv;
2003 }
2004 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2005 memset (es_neigh, 0, sizeof (struct es_neigh));
2006 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
2007 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
2008 }
2009 }
jardineb5d44e2003-12-23 08:09:43 +00002010 }
hassof390d2c2004-09-10 20:48:21 +00002011
jardineb5d44e2003-12-23 08:09:43 +00002012 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2013 /*
2014 * Add the authentication info if it's present
2015 */
hassof390d2c2004-09-10 20:48:21 +00002016 (level == 1) ? (passwd = &circuit->area->area_passwd) :
2017 (passwd = &circuit->area->domain_passwd);
2018 if (passwd->type)
2019 {
2020 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
2021 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
2022 }
jardineb5d44e2003-12-23 08:09:43 +00002023
2024 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2025 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2026
2027 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2028 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2029
2030 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002031 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2032 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2033
jardineb5d44e2003-12-23 08:09:43 +00002034 list_delete (adj_list);
2035
2036 return;
2037}
2038
2039int
2040lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
2041{
2042 dict_t *lspdb = circuit->area->lspdb[level - 1];
2043 struct isis_lsp *lsp;
2044 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00002045
jardineb5d44e2003-12-23 08:09:43 +00002046 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002047 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2048 LSP_FRAGMENT (lsp_id) = 0;
2049
jardineb5d44e2003-12-23 08:09:43 +00002050 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002051
2052 if (!lsp)
2053 {
2054 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
2055 rawlspid_print (lsp_id));
2056 return ISIS_ERROR;
2057 }
2058 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002059
2060 lsp_build_pseudo (lsp, circuit, level);
2061
hassof390d2c2004-09-10 20:48:21 +00002062 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00002063 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00002064 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002065
2066 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00002067
2068 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2069 {
2070 zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
2071 circuit->area->area_tag, level,
2072 rawlspid_print (lsp->lsp_header->lsp_id));
2073 }
jardineb5d44e2003-12-23 08:09:43 +00002074
2075 lsp->last_generated = time (NULL);
2076 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002077
jardineb5d44e2003-12-23 08:09:43 +00002078 return ISIS_OK;
2079}
2080
jardineb5d44e2003-12-23 08:09:43 +00002081int
2082lsp_l1_refresh_pseudo (struct thread *thread)
2083{
2084 struct isis_circuit *circuit;
2085 int retval;
2086 unsigned long ref_time;
2087
hassof390d2c2004-09-10 20:48:21 +00002088 circuit = THREAD_ARG (thread);
2089
jardineb5d44e2003-12-23 08:09:43 +00002090 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002091 return ISIS_ERROR; /* FIXME: purge and such */
2092
hasso13c48f72004-09-10 21:19:13 +00002093 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2094
jardineb5d44e2003-12-23 08:09:43 +00002095 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002096
2097 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002098 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2099
hassof390d2c2004-09-10 20:48:21 +00002100 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2101 lsp_l1_refresh_pseudo, circuit,
2102 isis_jitter (ref_time, MAX_AGE_JITTER));
2103
jardineb5d44e2003-12-23 08:09:43 +00002104 return retval;
2105}
2106
hassof390d2c2004-09-10 20:48:21 +00002107int
jardineb5d44e2003-12-23 08:09:43 +00002108lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2109{
2110 struct isis_lsp *lsp;
2111 u_char id[ISIS_SYS_ID_LEN + 2];
2112 unsigned long ref_time;
2113
hassof390d2c2004-09-10 20:48:21 +00002114 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2115 LSP_FRAGMENT (id) = 0;
2116 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002117
2118 /*
2119 * If for some reason have a pseudo LSP in the db already -> regenerate
2120 */
2121 if (lsp_search (id, circuit->area->lspdb[0]))
2122 return lsp_pseudo_regenerate (circuit, 1);
2123 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002124 1, circuit->area->is_type, 0, 1);
2125
jardineb5d44e2003-12-23 08:09:43 +00002126 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002127
jardineb5d44e2003-12-23 08:09:43 +00002128 lsp->own_lsp = 1;
2129 lsp_insert (lsp, circuit->area->lspdb[0]);
2130 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2131
hassof390d2c2004-09-10 20:48:21 +00002132 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002133 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2134
hassof390d2c2004-09-10 20:48:21 +00002135 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2136 lsp_l1_refresh_pseudo, circuit,
2137 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002138
2139 return lsp_regenerate_schedule (circuit->area);
2140}
2141
2142int
2143lsp_l2_refresh_pseudo (struct thread *thread)
2144{
2145 struct isis_circuit *circuit;
2146 int retval;
2147 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002148 circuit = THREAD_ARG (thread);
2149
jardineb5d44e2003-12-23 08:09:43 +00002150 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002151 return ISIS_ERROR; /* FIXME: purge and such */
2152
hasso13c48f72004-09-10 21:19:13 +00002153 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2154
jardineb5d44e2003-12-23 08:09:43 +00002155 retval = lsp_pseudo_regenerate (circuit, 2);
2156
hassof390d2c2004-09-10 20:48:21 +00002157 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002158 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2159
hassof390d2c2004-09-10 20:48:21 +00002160 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2161 lsp_l2_refresh_pseudo, circuit,
2162 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002163
jardineb5d44e2003-12-23 08:09:43 +00002164 return retval;
2165}
2166
hassof390d2c2004-09-10 20:48:21 +00002167int
jardineb5d44e2003-12-23 08:09:43 +00002168lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2169{
2170 struct isis_lsp *lsp;
2171 u_char id[ISIS_SYS_ID_LEN + 2];
2172 unsigned long ref_time;
2173
hassof390d2c2004-09-10 20:48:21 +00002174 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2175 LSP_FRAGMENT (id) = 0;
2176 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002177
2178 if (lsp_search (id, circuit->area->lspdb[1]))
2179 return lsp_pseudo_regenerate (circuit, 2);
2180
2181 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002182 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002183
2184 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002185
2186 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002187 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2188
2189
2190 lsp->own_lsp = 1;
2191 lsp_insert (lsp, circuit->area->lspdb[1]);
2192 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002193
2194 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2195 lsp_l2_refresh_pseudo, circuit,
2196 isis_jitter (ref_time, MAX_AGE_JITTER));
2197
jardineb5d44e2003-12-23 08:09:43 +00002198 return lsp_regenerate_schedule (circuit->area);
2199}
2200
jardineb5d44e2003-12-23 08:09:43 +00002201/*
2202 * Walk through LSPs for an area
2203 * - set remaining lifetime
2204 * - set LSPs with SRMflag set for sending
2205 */
hassof390d2c2004-09-10 20:48:21 +00002206int
jardineb5d44e2003-12-23 08:09:43 +00002207lsp_tick (struct thread *thread)
2208{
2209 struct isis_area *area;
2210 struct isis_circuit *circuit;
2211 struct isis_lsp *lsp;
2212 struct list *lsp_list;
2213 struct listnode *lspnode, *cnode;
2214 dnode_t *dnode, *dnode_next;
2215 int level;
2216
2217 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002218
jardineb5d44e2003-12-23 08:09:43 +00002219 area = THREAD_ARG (thread);
2220 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002221 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002222 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002223
2224 /*
2225 * Build a list of LSPs with (any) SRMflag set
2226 * and removed the ones that have aged out
2227 */
hassof390d2c2004-09-10 20:48:21 +00002228 for (level = 0; level < ISIS_LEVELS; level++)
2229 {
2230 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2231 {
2232 dnode = dict_first (area->lspdb[level]);
2233 while (dnode != NULL)
2234 {
2235 dnode_next = dict_next (area->lspdb[level], dnode);
2236 lsp = dnode_get (dnode);
2237 lsp_set_time (lsp);
2238 if (lsp->age_out == 0)
2239 {
jardineb5d44e2003-12-23 08:09:43 +00002240
hassof390d2c2004-09-10 20:48:21 +00002241 zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2242 area->area_tag,
2243 lsp->level,
2244 rawlspid_print (lsp->lsp_header->lsp_id),
2245 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002246
hassof390d2c2004-09-10 20:48:21 +00002247 lsp_destroy (lsp);
2248 dict_delete (area->lspdb[level], dnode);
2249 }
2250 else if (flags_any_set (lsp->SRMflags))
2251 listnode_add (lsp_list, lsp);
2252 dnode = dnode_next;
2253 }
jardineb5d44e2003-12-23 08:09:43 +00002254
hassof390d2c2004-09-10 20:48:21 +00002255 /*
2256 * Send LSPs on circuits indicated by the SRMflags
2257 */
2258 if (listcount (lsp_list) > 0)
2259 {
2260 for (cnode = listhead (area->circuit_list); cnode;
2261 nextnode (cnode))
2262 {
2263 circuit = getdata (cnode);
2264 for (lspnode = listhead (lsp_list); lspnode;
2265 nextnode (lspnode))
2266 {
2267 lsp = getdata (lspnode);
2268 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2269 {
2270 /* FIXME: if same or elder lsp is already in lsp
2271 * queue */
2272 listnode_add (circuit->lsp_queue, lsp);
2273 thread_add_event (master, send_lsp, circuit, 0);
2274 }
2275 }
2276 }
2277 }
2278 list_delete_all_node (lsp_list);
2279 }
jardineb5d44e2003-12-23 08:09:43 +00002280 }
jardineb5d44e2003-12-23 08:09:43 +00002281
2282 list_delete (lsp_list);
2283
2284 return ISIS_OK;
2285}
2286
jardineb5d44e2003-12-23 08:09:43 +00002287void
hassof390d2c2004-09-10 20:48:21 +00002288lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002289{
2290 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002291
jardineb5d44e2003-12-23 08:09:43 +00002292 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002293
2294 if (lsp && lsp->purged == 0)
2295 {
2296 lsp->lsp_header->rem_lifetime = htons (0);
2297 lsp->lsp_header->pdu_len =
2298 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2299 lsp->purged = 0;
2300 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2301 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2302 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2303 }
2304
jardineb5d44e2003-12-23 08:09:43 +00002305 return;
2306}
2307
2308/*
2309 * Purge own LSP that is received and we don't have.
2310 * -> Do as in 7.3.16.4
2311 */
2312void
hassof390d2c2004-09-10 20:48:21 +00002313lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2314 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002315{
2316 struct isis_lsp *lsp;
2317
2318 /*
2319 * We need to create the LSP to be purged
2320 */
2321 zlog_info ("LSP PURGE NON EXIST");
2322 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2323 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002324 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2325 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002326 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2327 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002328 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002329 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002330 : L2_LINK_STATE);
2331 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2332 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002333 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002334
jardineb5d44e2003-12-23 08:09:43 +00002335 /*
2336 * Retain only LSP header
2337 */
2338 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2339 /*
2340 * Set the remaining lifetime to 0
2341 */
2342 lsp->lsp_header->rem_lifetime = 0;
2343 /*
2344 * Put the lsp into LSPdb
2345 */
hassof390d2c2004-09-10 20:48:21 +00002346 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002347
2348 /*
2349 * Send in to whole area
2350 */
2351 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002352
jardineb5d44e2003-12-23 08:09:43 +00002353 return;
2354}
2355
2356#ifdef TOPOLOGY_GENERATE
2357int
2358top_lsp_refresh (struct thread *thread)
2359{
hassof390d2c2004-09-10 20:48:21 +00002360 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002361
2362 lsp = THREAD_ARG (thread);
2363 assert (lsp);
2364
2365 lsp->t_lsp_top_ref = NULL;
2366
hassof390d2c2004-09-10 20:48:21 +00002367 lsp->lsp_header->rem_lifetime =
2368 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2369 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002370
2371 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002372 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2373 {
2374 zlog_info ("ISIS-Upd (): refreshing Topology L1 %s",
2375 rawlspid_print (lsp->lsp_header->lsp_id));
2376 }
jardineb5d44e2003-12-23 08:09:43 +00002377
2378 /* time to calculate our checksum */
2379 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002380 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2381 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2382 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002383
2384 return ISIS_OK;
2385}
2386
2387void
2388generate_topology_lsps (struct isis_area *area)
2389{
2390 struct listnode *node;
2391 int i, max = 0;
2392 struct arc *arc;
2393 u_char lspid[ISIS_SYS_ID_LEN + 2];
2394 struct isis_lsp *lsp;
2395
2396 /* first we find the maximal node */
hassof390d2c2004-09-10 20:48:21 +00002397 LIST_LOOP (area->topology, arc, node)
2398 {
2399 if (arc->from_node > max)
2400 max = arc->from_node;
2401 if (arc->to_node > max)
2402 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002403 }
2404
hassof390d2c2004-09-10 20:48:21 +00002405 for (i = 1; i < (max + 1); i++)
2406 {
2407 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2408 LSP_PSEUDO_ID (lspid) = 0x00;
2409 LSP_FRAGMENT (lspid) = 0x00;
2410 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2411 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002412
hassof390d2c2004-09-10 20:48:21 +00002413 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2414 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2415 1);
2416 lsp->from_topology = 1;
2417 /* creating data based on topology */
2418 build_topology_lsp_data (lsp, area, i);
2419 /* time to calculate our checksum */
2420 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2421 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2422 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2423 isis_jitter (MAX_LSP_GEN_INTERVAL,
2424 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002425
hassof390d2c2004-09-10 20:48:21 +00002426 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2427 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002428
hassof390d2c2004-09-10 20:48:21 +00002429 }
jardineb5d44e2003-12-23 08:09:43 +00002430}
2431
2432void
2433remove_topology_lsps (struct isis_area *area)
2434{
2435 struct isis_lsp *lsp;
2436 dnode_t *dnode, *dnode_next;
2437
2438 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002439 while (dnode != NULL)
2440 {
2441 dnode_next = dict_next (area->lspdb[0], dnode);
2442 lsp = dnode_get (dnode);
2443 if (lsp->from_topology)
2444 {
2445 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2446 lsp_destroy (lsp);
2447 dict_delete (area->lspdb[0], dnode);
2448 }
2449 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002450 }
jardineb5d44e2003-12-23 08:09:43 +00002451}
2452
2453void
hassof390d2c2004-09-10 20:48:21 +00002454build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002455 int lsp_top_num)
2456{
2457 struct listnode *node;
2458 struct arc *arc;
2459 u_char *tlv_ptr;
2460 struct is_neigh *is_neigh;
2461 int to_lsp = 0;
2462 char buff[200];
2463
2464 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002465 /* the 2 is for the TL plus 1 for the nlpid */
2466 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2467 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2468 *(tlv_ptr + 1) = 1; /* one protocol */
2469 *(tlv_ptr + 2) = NLPID_IP;
2470 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002471
2472 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002473 /* the 2 is for the TL plus 1 for the virtual field */
2474 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2475 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2476 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2477 *(tlv_ptr + 2) = 0; /* virtual is zero */
2478 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002479
2480 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002481 if (lsp_top_num == 1)
2482 {
jardineb5d44e2003-12-23 08:09:43 +00002483 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002484 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2485 sizeof (struct
2486 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002487 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002488 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2489 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002490 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002491 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002492 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2493 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2494 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2495 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002496 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2497 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002498 }
hassof390d2c2004-09-10 20:48:21 +00002499
2500 /* addding is reachabilities */
2501 LIST_LOOP (area->topology, arc, node)
2502 {
2503 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2504 {
2505 if (arc->to_node == lsp_top_num)
2506 to_lsp = arc->from_node;
2507 if (arc->from_node == lsp_top_num)
2508 to_lsp = arc->to_node;
2509
2510 /* if the length here is about to cross the FF limit, we reTLV */
2511 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2512 {
2513 /* retlv */
2514 /* the 2 is for the TL plus 1 for the virtual field */
2515 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2516 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2517 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2518 *(tlv_ptr + 2) = 0; /* virtual is zero */
2519 }
2520 /* doing this here assures us that we won't add an "empty" tlv */
2521 /* assign space for the is_neigh at the pdu end */
2522 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2523 sizeof (struct
2524 is_neigh));
2525 /* add this node to our list */
2526 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2527 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2528 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2529 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2530 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2531 is_neigh->metrics.metric_default = arc->distance;
2532 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2533 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2534 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2535 /* don't forget the length */
2536 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2537 }
jardineb5d44e2003-12-23 08:09:43 +00002538 }
2539
hassof390d2c2004-09-10 20:48:21 +00002540 /* adding dynamic hostname if needed */
2541 if (area->dynhostname)
2542 {
2543 memset (buff, 0x00, 200);
2544 sprintf (buff, "feedme%d", lsp_top_num);
2545 /* the 2 is for the TL */
2546 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2547 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2548 *(tlv_ptr + 1) = strlen (buff); /* Length */
2549 /* the -1 is to fit the length in the struct */
2550 lsp->tlv_data.hostname = (struct hostname *)
2551 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2552 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2553 }
jardineb5d44e2003-12-23 08:09:43 +00002554
2555 /* thanks to hannes, another bug bites the dust */
hassof390d2c2004-09-10 20:48:21 +00002556 lsp->pdu->putp = ntohs (lsp->lsp_header->pdu_len);
2557 lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00002558}
2559#endif /* TOPOLOGY_GENERATE */