blob: 567afa3b514a490a836983bd8fbfee3f201262d3 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_lsp.c
3 * LSP processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23#include <stdlib.h>
24#include <stdio.h>
25#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000026
27#include "linklist.h"
28#include "thread.h"
29#include "vty.h"
30#include "stream.h"
31#include "memory.h"
32#include "log.h"
33#include "prefix.h"
34#include "command.h"
35#include "hash.h"
36#include "if.h"
37
38#include "isisd/dict.h"
39#include "isisd/isis_constants.h"
40#include "isisd/isis_common.h"
41#include "isisd/isis_circuit.h"
42#include "isisd/isisd.h"
43#include "isisd/isis_tlv.h"
44#include "isisd/isis_lsp.h"
45#include "isisd/isis_pdu.h"
46#include "isisd/isis_dynhn.h"
47#include "isisd/isis_misc.h"
48#include "isisd/isis_flags.h"
49#include "isisd/iso_checksum.h"
50#include "isisd/isis_csm.h"
51#include "isisd/isis_adjacency.h"
52#include "isisd/isis_spf.h"
53
54#ifdef TOPOLOGY_GENERATE
55#include "spgrid.h"
56#endif
57
hassof390d2c2004-09-10 20:48:21 +000058#define LSP_MEMORY_PREASSIGN
jardineb5d44e2003-12-23 08:09:43 +000059
60extern struct isis *isis;
61extern struct thread_master *master;
hasso18a6dce2004-10-03 18:18:34 +000062extern struct in_addr router_id_zebra;
jardineb5d44e2003-12-23 08:09:43 +000063
hasso73d1aea2004-09-24 10:45:28 +000064/* staticly assigned vars for printing purposes */
65char lsp_bits_string[200]; /* FIXME: enough ? */
66
hassof390d2c2004-09-10 20:48:21 +000067int
68lsp_id_cmp (u_char * id1, u_char * id2)
69{
jardineb5d44e2003-12-23 08:09:43 +000070 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
71}
72
73dict_t *
hassof390d2c2004-09-10 20:48:21 +000074lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000075{
76 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000077
78 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
79
jardineb5d44e2003-12-23 08:09:43 +000080 return dict;
81}
82
83struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000084lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000085{
86 dnode_t *node;
87
hassof390d2c2004-09-10 20:48:21 +000088#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000089 dnode_t *dn;
90
hassof390d2c2004-09-10 20:48:21 +000091 zlog_warn ("searching db");
92 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
93 {
94 zlog_warn ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn)),
95 dnode_get (dn));
96 }
jardineb5d44e2003-12-23 08:09:43 +000097#endif /* EXTREME DEBUG */
98
99 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000100
jardineb5d44e2003-12-23 08:09:43 +0000101 if (node)
hassof390d2c2004-09-10 20:48:21 +0000102 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000103
104 return NULL;
105}
106
107void
108lsp_clear_data (struct isis_lsp *lsp)
109{
110 if (!lsp)
111 return;
hassof390d2c2004-09-10 20:48:21 +0000112
113 if (lsp->own_lsp)
114 {
115 if (lsp->tlv_data.nlpids)
116 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
117 if (lsp->tlv_data.hostname)
118 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
119 }
jardineb5d44e2003-12-23 08:09:43 +0000120 if (lsp->tlv_data.is_neighs)
121 list_delete (lsp->tlv_data.is_neighs);
122 if (lsp->tlv_data.area_addrs)
123 list_delete (lsp->tlv_data.area_addrs);
124 if (lsp->tlv_data.es_neighs)
125 list_delete (lsp->tlv_data.es_neighs);
126 if (lsp->tlv_data.ipv4_addrs)
127 list_delete (lsp->tlv_data.ipv4_addrs);
128 if (lsp->tlv_data.ipv4_int_reachs)
129 list_delete (lsp->tlv_data.ipv4_int_reachs);
130 if (lsp->tlv_data.ipv4_ext_reachs)
131 list_delete (lsp->tlv_data.ipv4_ext_reachs);
132#ifdef HAVE_IPV6
133 if (lsp->tlv_data.ipv6_addrs)
134 list_delete (lsp->tlv_data.ipv6_addrs);
135 if (lsp->tlv_data.ipv6_reachs)
136 list_delete (lsp->tlv_data.ipv6_reachs);
137#endif /* HAVE_IPV6 */
138
139 memset (&lsp->tlv_data, 0, sizeof (struct tlvs));
140
141 return;
142}
143
144void
145lsp_destroy (struct isis_lsp *lsp)
146{
147 if (!lsp)
148 return;
hassof390d2c2004-09-10 20:48:21 +0000149
jardineb5d44e2003-12-23 08:09:43 +0000150 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000151
152 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
153 {
jardineb5d44e2003-12-23 08:09:43 +0000154 list_delete (lsp->lspu.frags);
hassof390d2c2004-09-10 20:48:21 +0000155 }
156
jardineb5d44e2003-12-23 08:09:43 +0000157 if (lsp->pdu)
158 stream_free (lsp->pdu);
159 XFREE (MTYPE_ISIS_LSP, lsp);
160}
161
hassof390d2c2004-09-10 20:48:21 +0000162void
163lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000164{
165 dnode_t *dnode, *next;
166 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000167
jardineb5d44e2003-12-23 08:09:43 +0000168 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000169 while (dnode)
170 {
171 next = dict_next (lspdb, dnode);
172 lsp = dnode_get (dnode);
173 lsp_destroy (lsp);
174 dict_delete_free (lspdb, dnode);
175 dnode = next;
176 }
177
jardineb5d44e2003-12-23 08:09:43 +0000178 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000179
jardineb5d44e2003-12-23 08:09:43 +0000180 return;
181}
182
183/*
184 * Remove all the frags belonging to the given lsp
185 */
186void
hassof390d2c2004-09-10 20:48:21 +0000187lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000188{
189 dnode_t *dnode;
190 struct listnode *lnode;
191 struct isis_lsp *lsp;
192
hassof390d2c2004-09-10 20:48:21 +0000193 for (lnode = listhead (frags); lnode; nextnode (lnode))
194 {
195 lsp = getdata (lnode);
196 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
197 lsp_destroy (lsp);
198 dnode_destroy (dict_delete (lspdb, dnode));
199 }
200
jardineb5d44e2003-12-23 08:09:43 +0000201 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000202
jardineb5d44e2003-12-23 08:09:43 +0000203 return;
204}
205
206void
hassof390d2c2004-09-10 20:48:21 +0000207lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000208{
209 dnode_t *node;
210 struct isis_lsp *lsp;
211
212 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000213 if (node)
214 {
215 node = dict_delete (lspdb, node);
216 lsp = dnode_get (node);
217 /*
218 * If this is a zero lsp, remove all the frags now
219 */
220 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
221 {
222 if (lsp->lspu.frags)
223 lsp_remove_frags (lsp->lspu.frags, lspdb);
224 }
225 else
226 {
227 /*
228 * else just remove this frag, from the zero lsps' frag list
229 */
230 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
231 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
232 }
233 lsp_destroy (lsp);
234 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000235 }
jardineb5d44e2003-12-23 08:09:43 +0000236}
237
238/*
239 * Compares a LSP to given values
240 * Params are given in net order
241 */
hassof390d2c2004-09-10 20:48:21 +0000242int
243lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000244 u_int16_t checksum, u_int16_t rem_lifetime)
245{
hassof390d2c2004-09-10 20:48:21 +0000246 /* no point in double ntohl on seqnum */
247 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000248 lsp->lsp_header->checksum == checksum &&
249 /*comparing with 0, no need to do ntohl */
250 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000251 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
252 {
253 if (isis->debugs & DEBUG_SNP_PACKETS)
254 {
255 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
256 " lifetime %us",
257 areatag,
258 rawlspid_print (lsp->lsp_header->lsp_id),
259 ntohl (lsp->lsp_header->seq_num),
260 ntohs (lsp->lsp_header->checksum),
261 ntohs (lsp->lsp_header->rem_lifetime));
262 zlog_info ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
263 " cksum 0x%04x, lifetime %us",
264 areatag,
265 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
266 }
267 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000268 }
jardineb5d44e2003-12-23 08:09:43 +0000269
hassof390d2c2004-09-10 20:48:21 +0000270 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
271 {
272 if (isis->debugs & DEBUG_SNP_PACKETS)
273 {
274 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
275 " lifetime %us",
276 areatag,
277 rawlspid_print (lsp->lsp_header->lsp_id),
278 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
279 zlog_info ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
280 "cksum 0x%04x, lifetime %us",
281 areatag,
282 ntohl (lsp->lsp_header->seq_num),
283 ntohs (lsp->lsp_header->checksum),
284 ntohs (lsp->lsp_header->rem_lifetime));
285 }
286 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000287 }
hassof390d2c2004-09-10 20:48:21 +0000288 if (isis->debugs & DEBUG_SNP_PACKETS)
289 {
290 zlog_info
291 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
292 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
293 ntohs (checksum), ntohs (rem_lifetime));
294 zlog_info ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
295 " cksum 0x%04x, lifetime %us", areatag,
296 ntohl (lsp->lsp_header->seq_num),
297 ntohs (lsp->lsp_header->checksum),
298 ntohs (lsp->lsp_header->rem_lifetime));
299 }
jardineb5d44e2003-12-23 08:09:43 +0000300
301 return LSP_OLDER;
302}
303
hassof390d2c2004-09-10 20:48:21 +0000304void
jardineb5d44e2003-12-23 08:09:43 +0000305lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
306{
307 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000308
jardineb5d44e2003-12-23 08:09:43 +0000309 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
310 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
311 else
hassof390d2c2004-09-10 20:48:21 +0000312 newseq = seq_num++;
313
jardineb5d44e2003-12-23 08:09:43 +0000314 lsp->lsp_header->seq_num = htonl (newseq);
hassof390d2c2004-09-10 20:48:21 +0000315 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
316 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +0000317
318 return;
319}
320
321/*
322 * Genetates checksum for LSP and its frags
323 */
324void
325lsp_seqnum_update (struct isis_lsp *lsp0)
326{
327 struct isis_lsp *lsp;
328 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000329
jardineb5d44e2003-12-23 08:09:43 +0000330 lsp_inc_seqnum (lsp0, 0);
331
332 if (!lsp0->lspu.frags)
333 return;
334
hassof390d2c2004-09-10 20:48:21 +0000335 for (node = listhead (lsp0->lspu.frags); node; nextnode (node))
336 {
337 lsp = getdata (node);
338 lsp_inc_seqnum (lsp, 0);
339 }
340
jardineb5d44e2003-12-23 08:09:43 +0000341 return;
342}
343
hassof390d2c2004-09-10 20:48:21 +0000344int
jardineb5d44e2003-12-23 08:09:43 +0000345isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
hassof390d2c2004-09-10 20:48:21 +0000346 int pdulen, struct isis_passwd *passwd)
jardineb5d44e2003-12-23 08:09:43 +0000347{
348 uint32_t expected = 0, found;
349 struct tlvs tlvs;
350 int retval = 0;
351
352 expected |= TLVFLAG_AUTH_INFO;
353 retval = parse_tlvs (area->area_tag, stream->data +
hassof390d2c2004-09-10 20:48:21 +0000354 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
355 pdulen - ISIS_FIXED_HDR_LEN
356 - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000357 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000358 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000359
360 return authentication_check (passwd, &tlvs.auth_info);
361}
362
363void
hassof390d2c2004-09-10 20:48:21 +0000364lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
365 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000366{
hassof390d2c2004-09-10 20:48:21 +0000367 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000368 int retval;
hassof390d2c2004-09-10 20:48:21 +0000369
jardineb5d44e2003-12-23 08:09:43 +0000370 /* copying only the relevant part of our stream */
371 lsp->pdu = stream_new (stream->endp);
372 lsp->pdu->putp = stream->putp;
373 lsp->pdu->getp = stream->getp;
374 lsp->pdu->endp = stream->endp;
375 memcpy (lsp->pdu->data, stream->data, stream->endp);
376
377 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000378 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
379 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
380 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000381 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000382 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000383 /*
384 * Get LSP data i.e. TLVs
385 */
386 expected |= TLVFLAG_AUTH_INFO;
387 expected |= TLVFLAG_AREA_ADDRS;
388 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000389 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000390 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
391 expected |= TLVFLAG_NLPID;
392 if (area->dynhostname)
393 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000394 if (area->newmetric)
395 {
396 expected |= TLVFLAG_TE_IS_NEIGHS;
397 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
398 expected |= TLVFLAG_TE_ROUTER_ID;
399 }
jardineb5d44e2003-12-23 08:09:43 +0000400 expected |= TLVFLAG_IPV4_ADDR;
401 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
402 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
403#ifdef HAVE_IPV6
404 expected |= TLVFLAG_IPV6_ADDR;
405 expected |= TLVFLAG_IPV6_REACHABILITY;
406#endif /* HAVE_IPV6 */
407
408 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000409 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
410 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
411 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000412
hassof390d2c2004-09-10 20:48:21 +0000413 if (found & TLVFLAG_DYN_HOSTNAME)
414 {
415 if (area->dynhostname)
416 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
417 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
418 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
419 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
420 }
jardineb5d44e2003-12-23 08:09:43 +0000421
422}
423
424void
425lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +0000426 struct stream *stream, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000427{
hassof390d2c2004-09-10 20:48:21 +0000428 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000429 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
430 lsp_clear_data (lsp);
431
432 /* rebuild the lsp data */
433 lsp_update_data (lsp, stream, area);
434
hassof390d2c2004-09-10 20:48:21 +0000435 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000436 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000437}
438
jardineb5d44e2003-12-23 08:09:43 +0000439/* creation of LSP directly from what we received */
440struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000441lsp_new_from_stream_ptr (struct stream *stream,
442 u_int16_t pdu_len, struct isis_lsp *lsp0,
443 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000444{
445 struct isis_lsp *lsp;
446
447 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
448 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000449
jardineb5d44e2003-12-23 08:09:43 +0000450 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000451
452 if (lsp0 == NULL)
453 {
454 /*
455 * zero lsp -> create the list for fragments
456 */
457 lsp->lspu.frags = list_new ();
458 }
459 else
460 {
461 /*
462 * a fragment -> set the backpointer and add this to zero lsps frag list
463 */
464 lsp->lspu.zero_lsp = lsp0;
465 listnode_add (lsp0->lspu.frags, lsp);
466 }
467
jardineb5d44e2003-12-23 08:09:43 +0000468 return lsp;
469}
470
471struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000472lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
473 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000474{
475 struct isis_lsp *lsp;
476
477 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000478 if (!lsp)
479 {
480 /* FIXME: set lspdbol bit */
481 zlog_warn ("lsp_new(): out of memory");
482 return NULL;
483 }
jardineb5d44e2003-12-23 08:09:43 +0000484 memset (lsp, 0, sizeof (struct isis_lsp));
485#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000486 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000487#else
hassof390d2c2004-09-10 20:48:21 +0000488 /* We need to do realloc on TLVs additions */
489 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000490#endif /* LSP_MEMORY_PREASSIGN */
491 if (LSP_FRAGMENT (lsp_id) == 0)
492 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000493 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
494 lsp->lsp_header = (struct isis_link_state_hdr *)
495 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
496
jardineb5d44e2003-12-23 08:09:43 +0000497 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000498 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
499 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
500
jardineb5d44e2003-12-23 08:09:43 +0000501 /* now for the LSP HEADER */
502 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000503 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000504 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000505 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000506 lsp->lsp_header->seq_num = htonl (seq_num);
507 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
508 lsp->lsp_header->lsp_bits = lsp_bits;
509 lsp->level = level;
510 lsp->age_out = ZERO_AGE_LIFETIME;
511
512 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
513
514 /* #ifdef EXTREME_DEBUG */
515 /* logging */
516 zlog_info ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000517 LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
518 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
519 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000520 /* #endif EXTREME DEBUG */
521
522 return lsp;
523}
524
525void
hassof390d2c2004-09-10 20:48:21 +0000526lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000527{
528 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
529}
530
531/*
532 * Build a list of LSPs with non-zero ht bounded by start and stop ids
533 */
hassof390d2c2004-09-10 20:48:21 +0000534void
535lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
536 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000537{
538 dnode_t *first, *last, *curr;
539
540 first = dict_lower_bound (lspdb, start_id);
541 if (!first)
542 return;
hassof390d2c2004-09-10 20:48:21 +0000543
jardineb5d44e2003-12-23 08:09:43 +0000544 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000545
jardineb5d44e2003-12-23 08:09:43 +0000546 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000547
548 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000549 listnode_add (list, first->dict_data);
550
hassof390d2c2004-09-10 20:48:21 +0000551 while (curr)
552 {
553 curr = dict_next (lspdb, curr);
554 if (curr &&
555 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
556 listnode_add (list, curr->dict_data);
557 if (curr == last)
558 break;
559 }
560
jardineb5d44e2003-12-23 08:09:43 +0000561 return;
562}
563
564/*
565 * Build a list of all LSPs bounded by start and stop ids
566 */
hassof390d2c2004-09-10 20:48:21 +0000567void
568lsp_build_list (u_char * start_id, u_char * stop_id,
569 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000570{
571 dnode_t *first, *last, *curr;
572
573 first = dict_lower_bound (lspdb, start_id);
574 if (!first)
575 return;
hassof390d2c2004-09-10 20:48:21 +0000576
jardineb5d44e2003-12-23 08:09:43 +0000577 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000578
jardineb5d44e2003-12-23 08:09:43 +0000579 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000580
jardineb5d44e2003-12-23 08:09:43 +0000581 listnode_add (list, first->dict_data);
582
hassof390d2c2004-09-10 20:48:21 +0000583 while (curr)
584 {
585 curr = dict_next (lspdb, curr);
586 if (curr)
587 listnode_add (list, curr->dict_data);
588 if (curr == last)
589 break;
590 }
591
jardineb5d44e2003-12-23 08:09:43 +0000592 return;
593}
594
595/*
596 * Build a list of LSPs with SSN flag set for the given circuit
597 */
598void
hassof390d2c2004-09-10 20:48:21 +0000599lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
600 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000601{
602 dnode_t *dnode, *next;
603 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000604
jardineb5d44e2003-12-23 08:09:43 +0000605 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000606 while (dnode != NULL)
607 {
608 next = dict_next (lspdb, dnode);
609 lsp = dnode_get (dnode);
610 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
611 listnode_add (list, lsp);
612 dnode = next;
613 }
614
jardineb5d44e2003-12-23 08:09:43 +0000615 return;
616}
617
618void
619lsp_set_time (struct isis_lsp *lsp)
620{
621 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000622
623 if (lsp->lsp_header->rem_lifetime == 0)
624 {
625 if (lsp->age_out != 0)
626 lsp->age_out--;
627 return;
628 }
jardineb5d44e2003-12-23 08:09:43 +0000629
630 /* If we are turning 0 */
631 /* ISO 10589 - 7.3.16.4 first paragraph */
632
hassof390d2c2004-09-10 20:48:21 +0000633 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
634 {
635 /* 7.3.16.4 a) set SRM flags on all */
636 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
637 /* 7.3.16.4 b) retain only the header FIXME */
638 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
639 }
jardineb5d44e2003-12-23 08:09:43 +0000640
hassof390d2c2004-09-10 20:48:21 +0000641 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000642 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
643}
644
645void
hassof390d2c2004-09-10 20:48:21 +0000646lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000647{
648 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000649 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000650
651 if (dynhost)
652 dyn = dynhn_find_by_id (lsp_id);
653 else
654 dyn = NULL;
655
656 if (dyn)
hassof7c43dc2004-09-26 16:24:14 +0000657 sprintf ((char *)id, "%.14s", dyn->name.name);
jardineb5d44e2003-12-23 08:09:43 +0000658 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof7c43dc2004-09-26 16:24:14 +0000659 sprintf ((char *)id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000660 else
hassof390d2c2004-09-10 20:48:21 +0000661 {
662 memcpy (id, sysid_print (lsp_id), 15);
663 }
664 if (frag)
hassof7c43dc2004-09-26 16:24:14 +0000665 sprintf ((char *)trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000666 LSP_FRAGMENT (lsp_id));
667 else
hassof7c43dc2004-09-26 16:24:14 +0000668 sprintf ((char *)trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000669}
670
hassof390d2c2004-09-10 20:48:21 +0000671/* Convert the lsp attribute bits to attribute string */
672char *
673lsp_bits2string (u_char * lsp_bits)
674{
675 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000676
hassof390d2c2004-09-10 20:48:21 +0000677 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000678 return " none";
679
680 /* we only focus on the default metric */
681 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000682 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000683
684 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000685 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000686
hassof390d2c2004-09-10 20:48:21 +0000687 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
688
jardineb5d44e2003-12-23 08:09:43 +0000689 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000690
hassof390d2c2004-09-10 20:48:21 +0000691 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000692}
693
694/* this function prints the lsp on show isis database */
695void
hassof390d2c2004-09-10 20:48:21 +0000696lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000697{
hassof390d2c2004-09-10 20:48:21 +0000698 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000699 u_char LSPid[255];
700
701 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000702 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
703 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
704 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000705
hassof390d2c2004-09-10 20:48:21 +0000706 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
707 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000708 else
hassof390d2c2004-09-10 20:48:21 +0000709 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000710
711 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000712 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000713}
714
715void
hassof390d2c2004-09-10 20:48:21 +0000716lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000717{
718 struct isis_lsp *lsp = dnode_get (node);
719 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000720 char nlpidstr[2];
721 int i;
jardineb5d44e2003-12-23 08:09:43 +0000722 struct listnode *lnode;
723 struct is_neigh *is_neigh;
724 struct te_is_neigh *te_is_neigh;
725 struct ipv4_reachability *ipv4_reach;
726 struct in_addr *ipv4_addr;
727 struct te_ipv4_reachability *te_ipv4_reach;
728#ifdef HAVE_IPV6
729 struct ipv6_reachability *ipv6_reach;
730 struct in6_addr in6;
731#endif
732 u_char LSPid[255];
733 u_char hostname[255];
734 u_char buff[BUFSIZ];
hassof390d2c2004-09-10 20:48:21 +0000735 u_int32_t now, helper;
jardineb5d44e2003-12-23 08:09:43 +0000736 u_char ipv4_reach_prefix[20];
737 u_char ipv4_reach_mask[20];
738 u_char ipv4_address[20];
739
740 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000741 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000742
743 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000744 if (lsp->tlv_data.area_addrs)
745 {
746 LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode)
747 {
748 vty_out (vty, " Area Address: %s%s",
749 isonet_print (area_addr->area_addr, area_addr->addr_len),
750 VTY_NEWLINE);
751 }
jardineb5d44e2003-12-23 08:09:43 +0000752 }
jardineb5d44e2003-12-23 08:09:43 +0000753
754 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000755 if (lsp->tlv_data.nlpids)
756 {
757 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
758 {
759 switch (lsp->tlv_data.nlpids->nlpids[i])
760 {
761 case NLPID_IP:
762 case NLPID_IPV6:
763 vty_out (vty, " NLPID: 0x%X%s",
764 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
765 break;
766 default:
767 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
768 break;
769 }
770 }
771 }
jardineb5d44e2003-12-23 08:09:43 +0000772
773 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000774 if (lsp->tlv_data.hostname)
775 {
776 bzero (hostname, sizeof (hostname));
777 memcpy (hostname, lsp->tlv_data.hostname->name,
778 lsp->tlv_data.hostname->namelen);
779 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000780 }
hassof390d2c2004-09-10 20:48:21 +0000781
782 if (lsp->tlv_data.ipv4_addrs)
783 {
784 LIST_LOOP (lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode)
785 {
786 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
787 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
788 }
789 }
790
jardineb5d44e2003-12-23 08:09:43 +0000791 /* for the internal reachable tlv */
792 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000793 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
794 {
795 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
796 sizeof (ipv4_reach_prefix));
797 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
798 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000799 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000800 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
801 ipv4_reach_mask, VTY_NEWLINE);
802 }
hasso2097cd82003-12-23 11:51:08 +0000803
804 /* for the external reachable tlv */
805 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000806 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
807 {
808 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
809 sizeof (ipv4_reach_prefix));
810 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
811 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000812 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000813 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
814 ipv4_reach_mask, VTY_NEWLINE);
815 }
jardineb5d44e2003-12-23 08:09:43 +0000816
817 /* for the IS neighbor tlv */
hassof390d2c2004-09-10 20:48:21 +0000818 if (lsp->tlv_data.is_neighs)
819 {
820 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
821 {
822 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
823 vty_out (vty, " Metric: %d IS %s%s",
824 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
825 }
jardineb5d44e2003-12-23 08:09:43 +0000826 }
jardineb5d44e2003-12-23 08:09:43 +0000827
hasso2097cd82003-12-23 11:51:08 +0000828 /* IPv6 tlv */
829#ifdef HAVE_IPV6
830 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000831 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
832 {
833 memset (&in6, 0, sizeof (in6));
834 memcpy (in6.s6_addr, ipv6_reach->prefix,
835 PSIZE (ipv6_reach->prefix_len));
hassof7c43dc2004-09-26 16:24:14 +0000836 inet_ntop (AF_INET6, &in6, (char *)buff, BUFSIZ);
hasso2097cd82003-12-23 11:51:08 +0000837 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000838 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
839 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
840 ntohl (ipv6_reach->metric),
841 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000842 else
hassof390d2c2004-09-10 20:48:21 +0000843 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
844 ntohl (ipv6_reach->metric),
845 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000846 }
847#endif
848
jardineb5d44e2003-12-23 08:09:43 +0000849/* FIXME: Other tlvs such as te or external tlv will be added later */
hassof390d2c2004-09-10 20:48:21 +0000850#if 0
jardineb5d44e2003-12-23 08:09:43 +0000851 vty_out (vty, "%s %s %c%s",
hassof390d2c2004-09-10 20:48:21 +0000852 VTY_NEWLINE, LSPid, lsp->own_lsp ? '*' : ' ', VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000853
854 vty_out (vty, " Sequence: 0x%08x Checksum: 0x%04x Lifetime: ",
855 ntohl (lsp->lsp_header->seq_num),
856 ntohs (lsp->lsp_header->checksum));
857
858 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
859 vty_out (vty, " (%2u) ", lsp->age_out);
860 else
861 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->rem_lifetime));
862
863 vty_out (vty, "%s Attributes:%s",
hassof390d2c2004-09-10 20:48:21 +0000864 VTY_NEWLINE, lsp_bits2string (&lsp->lsp_header->lsp_bits));
jardineb5d44e2003-12-23 08:09:43 +0000865
866 /* if this is a self originated LSP then print
867 * the generation time plus when we sent it last
868 * if it is a non self-originated LSP then print the
869 * time when the LSP has been installed
870 */
871
hassof390d2c2004-09-10 20:48:21 +0000872 if (lsp->own_lsp)
873 {
jardineb5d44e2003-12-23 08:09:43 +0000874
hassof390d2c2004-09-10 20:48:21 +0000875 now = time (NULL);
876 helper = now - lsp->last_generated;
877 if (!lsp->last_generated)
878 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000879
hassof390d2c2004-09-10 20:48:21 +0000880 vty_out (vty, ", Generated: %s ago", time2string (helper));
jardineb5d44e2003-12-23 08:09:43 +0000881
hassof390d2c2004-09-10 20:48:21 +0000882 now = time (NULL);
883 helper = now - lsp->last_sent;
884 if (!lsp->last_sent)
885 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000886
hassof390d2c2004-09-10 20:48:21 +0000887 vty_out (vty, ", Last sent: %s ago", time2string (helper));
888 }
889 else
890 {
891 now = time (NULL);
892 helper = now - lsp->installed;
893 if (!lsp->installed)
894 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000895
hassof390d2c2004-09-10 20:48:21 +0000896 vty_out (vty, ", Installed: %s ago", time2string (helper));
jardineb5d44e2003-12-23 08:09:43 +0000897
hassof390d2c2004-09-10 20:48:21 +0000898 }
jardineb5d44e2003-12-23 08:09:43 +0000899
900 vty_out (vty, "%s", VTY_NEWLINE);
901
hassof390d2c2004-09-10 20:48:21 +0000902 if (lsp->tlv_data.nlpids)
903 {
904 vty_out (vty, " Speaks: %s%s", nlpid2string (lsp->tlv_data.nlpids),
905 VTY_NEWLINE);
906 }
jardineb5d44e2003-12-23 08:09:43 +0000907
hassof390d2c2004-09-10 20:48:21 +0000908 if (lsp->tlv_data.router_id)
909 {
910 vty_out (vty, " Router ID: %s%s",
911 inet_ntoa (lsp->tlv_data.router_id->id), VTY_NEWLINE);
912 }
jardineb5d44e2003-12-23 08:09:43 +0000913
914 if (lsp->tlv_data.is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000915 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
916 {
917 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
918 vty_out (vty, " IS %s, Metric: %d%s",
919 LSPid, is_neigh->metrics.metric_default, VTY_NEWLINE);
920 }
jardineb5d44e2003-12-23 08:09:43 +0000921
922 if (lsp->tlv_data.te_is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000923 LIST_LOOP (lsp->tlv_data.te_is_neighs, te_is_neigh, lnode)
924 {
925 /* FIXME: metric display is wrong */
926 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
927 vty_out (vty, " extd-IS %s, Metric: %d%s",
928 LSPid, te_is_neigh->te_metric[0], VTY_NEWLINE);
929 }
jardineb5d44e2003-12-23 08:09:43 +0000930
931 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000932 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
933 {
934 vty_out (vty, " int-IP %s/%d, Metric: %d%s",
935 inet_ntoa (ipv4_reach->prefix),
936 ip_masklen (ipv4_reach->mask),
937 ipv4_reach->metrics.metric_default, VTY_NEWLINE);
938 }
jardineb5d44e2003-12-23 08:09:43 +0000939
940 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000941 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
942 {
943 vty_out (vty, " ext-IP %s/%d, Metric: %d%s",
944 inet_ntoa (ipv4_reach->prefix),
945 ip_masklen (ipv4_reach->mask),
946 ipv4_reach->metrics.metric_default, VTY_NEWLINE);
947 }
jardineb5d44e2003-12-23 08:09:43 +0000948
949 if (lsp->tlv_data.te_ipv4_reachs)
hassof390d2c2004-09-10 20:48:21 +0000950 LIST_LOOP (lsp->tlv_data.te_ipv4_reachs, te_ipv4_reach, lnode)
951 {
952 vty_out (vty, " extd-IP %s/%d, Metric: %d%s",
953 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
954 te_ipv4_reach->control)),
955 te_ipv4_reach->control & 0x3F,
956 ntohl (te_ipv4_reach->te_metric), VTY_NEWLINE);
957 }
jardineb5d44e2003-12-23 08:09:43 +0000958
959#ifdef HAVE_IPV6
960 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000961 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
962 {
963 memcpy (in6.s6_addr, ipv6_reach->prefix, 16);
964 inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
965 if ((ipv6_reach->control_info &&
966 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
967 vty_out (vty, " int-IPv6 %s/%d, Metric: %d%s",
968 buff,
969 ipv6_reach->prefix_len,
970 ntohl (ipv6_reach->metric), VTY_NEWLINE);
971 else
972 vty_out (vty, " ext-IPv6 %s/%d, Metric: %d%s",
973 buff,
974 ipv6_reach->prefix_len,
975 ntohl (ipv6_reach->metric), VTY_NEWLINE);
976
977 }
jardineb5d44e2003-12-23 08:09:43 +0000978#endif
hassof390d2c2004-09-10 20:48:21 +0000979 if (lsp->tlv_data.hostname)
980 {
981 memset (hostname, 0, sizeof (hostname));
982 memcpy (hostname, lsp->tlv_data.hostname->name,
983 lsp->tlv_data.hostname->namelen);
984 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
985 }
jardineb5d44e2003-12-23 08:09:43 +0000986#endif
hassof390d2c2004-09-10 20:48:21 +0000987 return;
jardineb5d44e2003-12-23 08:09:43 +0000988}
989
990/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000991int
992lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000993{
994
hassof390d2c2004-09-10 20:48:21 +0000995 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000996 int lsp_count = 0;
997
998 /* print the title, for both modes */
999 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +00001000 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
1001
1002 if (detail == ISIS_UI_LEVEL_BRIEF)
1003 {
1004 while (node != NULL)
1005 {
1006 /* I think it is unnecessary, so I comment it out */
1007 /* dict_contains (lspdb, node); */
1008 next = dict_next (lspdb, node);
1009 lsp_print (node, vty, dynhost);
1010 node = next;
1011 lsp_count++;
1012 }
jardineb5d44e2003-12-23 08:09:43 +00001013 }
hassof390d2c2004-09-10 20:48:21 +00001014 else if (detail == ISIS_UI_LEVEL_DETAIL)
1015 {
1016 while (node != NULL)
1017 {
1018 next = dict_next (lspdb, node);
1019 lsp_print_detail (node, vty, dynhost);
1020 node = next;
1021 lsp_count++;
1022 }
jardineb5d44e2003-12-23 08:09:43 +00001023 }
jardineb5d44e2003-12-23 08:09:43 +00001024
1025 return lsp_count;
1026}
1027
1028/* this function reallocate memory to an lsp pdu, with an additional
1029 * size of memory, it scans the lsp and moves all pointers the
1030 * way they should */
1031u_char *
hassof390d2c2004-09-10 20:48:21 +00001032lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +00001033{
1034 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +00001035
1036 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001037#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +00001038 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +00001039 return retval;
hassof390d2c2004-09-10 20:48:21 +00001040#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +00001041 u_char *newpdu;
1042 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassof390d2c2004-09-10 20:48:21 +00001043 memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu),
1044 ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +00001045 XFREE (memorytype, lsp->pdu);
1046 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +00001047 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
1048 lsp->lsp_header = (struct isis_link_state_hdr *)
1049 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001050 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +00001051 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +00001052#endif /* LSP_MEMORY_PREASSIGN */
1053}
1054
hassof390d2c2004-09-10 20:48:21 +00001055#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +00001056/*
1057 * Builds the lsp->tlv_data
1058 * and writes the tlvs into lsp->pdu
1059 */
1060void
1061lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1062{
1063 struct is_neigh *is_neigh;
1064 struct listnode *node, *ipnode;
1065 int level = lsp->level;
1066 struct isis_circuit *circuit;
1067 struct prefix_ipv4 *ipv4;
1068 struct ipv4_reachability *ipreach;
1069 struct isis_adjacency *nei;
1070#ifdef HAVE_IPV6
1071 struct prefix_ipv6 *ipv6;
1072 struct ipv6_reachability *ip6reach;
1073#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001074
jardineb5d44e2003-12-23 08:09:43 +00001075 /*
1076 * First add the tlvs related to area
1077 */
hassof390d2c2004-09-10 20:48:21 +00001078
jardineb5d44e2003-12-23 08:09:43 +00001079 /* Area addresses */
1080 if (lsp->tlv_data.area_addrs == NULL)
1081 lsp->tlv_data.area_addrs = list_new ();
1082 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1083 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001084 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001085#ifdef HAVE_IPV6
1086 || area->ipv6_circuits > 0
1087#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001088 )
jardineb5d44e2003-12-23 08:09:43 +00001089 {
1090 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1091 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001092 if (area->ip_circuits > 0)
1093 {
1094 lsp->tlv_data.nlpids->count++;
1095 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1096 }
jardineb5d44e2003-12-23 08:09:43 +00001097#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001098 if (area->ipv6_circuits > 0)
1099 {
1100 lsp->tlv_data.nlpids->count++;
1101 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1102 NLPID_IPV6;
1103 }
jardineb5d44e2003-12-23 08:09:43 +00001104#endif /* HAVE_IPV6 */
1105 }
1106 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001107 if (area->dynhostname)
1108 {
1109 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1110 sizeof (struct hostname));
1111 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
1112 strlen (unix_hostname ()));
1113 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1114 }
jardineb5d44e2003-12-23 08:09:43 +00001115#ifdef TOPOLOGY_GENERATE
1116 /*
1117 * If we have a topology in this area, we need to connect this lsp to
1118 * the first topology lsp
1119 */
hassof390d2c2004-09-10 20:48:21 +00001120 if ((area->topology) && (level == 1))
1121 {
1122 if (lsp->tlv_data.is_neighs == NULL)
1123 lsp->tlv_data.is_neighs = list_new ();
1124 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1125 memset (is_neigh, 0, sizeof (struct is_neigh));
1126 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1127 /* connected to the first */
1128 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1129 /* this is actually the same system, why mess the SPT */
1130 is_neigh->metrics.metric_default = 0;
1131 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1132 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1133 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1134 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001135
hassof390d2c2004-09-10 20:48:21 +00001136 }
jardineb5d44e2003-12-23 08:09:43 +00001137#endif
1138
1139 /*
1140 * Then add tlvs related to circuits
1141 */
hassof390d2c2004-09-10 20:48:21 +00001142 for (node = listhead (area->circuit_list); node; nextnode (node))
1143 {
1144 circuit = getdata (node);
1145 if (circuit->state != C_STATE_UP)
1146 continue;
1147
1148 /*
1149 * Add IPv4 internal reachability of this circuit
1150 */
1151 if (circuit->ip_router && circuit->ip_addrs &&
1152 circuit->ip_addrs->count > 0)
1153 {
1154 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1155 {
1156 lsp->tlv_data.ipv4_int_reachs = list_new ();
1157 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1158 }
1159 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1160 nextnode (ipnode))
1161 {
1162 ipv4 = getdata (ipnode);
1163 ipreach =
1164 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1165 ipreach->metrics = circuit->metrics[level - 1];
1166 ipreach->prefix = ipv4->prefix;
1167 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1168 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1169 }
1170 }
jardineb5d44e2003-12-23 08:09:43 +00001171#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001172 /*
1173 * Add IPv6 reachability of this circuit
1174 */
1175 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1176 circuit->ipv6_non_link->count > 0)
1177 {
1178 if (lsp->tlv_data.ipv6_reachs == NULL)
1179 {
1180 lsp->tlv_data.ipv6_reachs = list_new ();
1181 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1182 }
1183 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1184 nextnode (ipnode))
1185 {
1186 ipv6 = getdata (ipnode);
1187 ip6reach =
1188 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1189 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1190 ip6reach->metric =
1191 htonl (circuit->metrics[level - 1].metric_default);
1192 ip6reach->control_info = 0;
1193 ip6reach->prefix_len = ipv6->prefixlen;
1194 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1195 (ipv6->prefixlen + 7) / 8);
1196 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1197 }
1198 }
jardineb5d44e2003-12-23 08:09:43 +00001199#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001200
1201 switch (circuit->circ_type)
1202 {
1203 case CIRCUIT_T_BROADCAST:
1204 if (level & circuit->circuit_is_type)
1205 {
1206 if (lsp->tlv_data.is_neighs == NULL)
1207 {
1208 lsp->tlv_data.is_neighs = list_new ();
1209 lsp->tlv_data.is_neighs->del = free_tlv;
1210 }
1211 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1212 memset (is_neigh, 0, sizeof (struct is_neigh));
1213 if (level == 1)
1214 memcpy (&is_neigh->neigh_id,
1215 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1216 else
1217 memcpy (&is_neigh->neigh_id,
1218 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1219 is_neigh->metrics = circuit->metrics[level - 1];
1220 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1221 }
1222 break;
1223 case CIRCUIT_T_P2P:
1224 nei = circuit->u.p2p.neighbor;
1225 if (nei && (level & nei->circuit_t))
1226 {
1227 if (lsp->tlv_data.is_neighs == NULL)
1228 {
1229 lsp->tlv_data.is_neighs = list_new ();
1230 lsp->tlv_data.is_neighs->del = free_tlv;
1231 }
1232 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1233 memset (is_neigh, 0, sizeof (struct is_neigh));
1234 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1235 is_neigh->metrics = circuit->metrics[level - 1];
1236 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1237 }
1238 break;
1239 case CIRCUIT_T_STATIC_IN:
1240 zlog_warn ("lsp_area_create: unsupported circuit type");
1241 break;
1242 case CIRCUIT_T_STATIC_OUT:
1243 zlog_warn ("lsp_area_create: unsupported circuit type");
1244 break;
1245 case CIRCUIT_T_DA:
1246 zlog_warn ("lsp_area_create: unsupported circuit type");
1247 break;
1248 default:
1249 zlog_warn ("lsp_area_create: unknown circuit type");
1250 }
jardineb5d44e2003-12-23 08:09:43 +00001251 }
hassof390d2c2004-09-10 20:48:21 +00001252
jardineb5d44e2003-12-23 08:09:43 +00001253 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00001254
jardineb5d44e2003-12-23 08:09:43 +00001255 if (lsp->tlv_data.nlpids)
1256 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1257 if (lsp->tlv_data.hostname)
1258 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001259 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001260 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1261 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1262 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001263 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001264 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1265 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001266#ifdef HAVE_IPV6
1267 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001268 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1269#endif /* HAVE_IPV6 */
1270
1271 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1272
1273 return;
1274}
1275#endif
1276
1277#define FRAG_THOLD(S,T) \
1278((STREAM_SIZE(S)*T)/100)
1279
1280/* stream*, area->lsp_frag_threshold, increment */
1281#define FRAG_NEEDED(S,T,I) \
1282 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1283
1284void
1285lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001286 int tlvsize, int frag_thold,
1287 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001288{
1289 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001290
jardineb5d44e2003-12-23 08:09:43 +00001291 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001292 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1293 {
1294 tlv_build_func (*from, lsp->pdu);
1295 *to = *from;
1296 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001297 }
hassof390d2c2004-09-10 20:48:21 +00001298 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1299 {
1300 /* fit all we can */
1301 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1302 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1303 if (count)
1304 count = count / tlvsize;
1305 for (i = 0; i < count; i++)
1306 {
1307 listnode_add (*to, getdata (listhead (*from)));
1308 listnode_delete (*from, getdata (listhead (*from)));
1309 }
1310 tlv_build_func (*to, lsp->pdu);
1311 }
1312 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001313 return;
1314}
1315
hassof390d2c2004-09-10 20:48:21 +00001316struct isis_lsp *
1317lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1318 int level)
jardineb5d44e2003-12-23 08:09:43 +00001319{
1320 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001321 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1322
jardineb5d44e2003-12-23 08:09:43 +00001323 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1324 LSP_FRAGMENT (frag_id) = frag_num;
1325 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001326 if (lsp)
1327 {
1328 /*
1329 * Clear the TLVs, but inherit the authinfo
1330 */
1331 lsp_clear_data (lsp);
1332 if (lsp0->tlv_data.auth_info.type)
1333 {
1334 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1335 sizeof (struct isis_passwd));
1336 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1337 lsp->tlv_data.auth_info.len,
1338 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1339 }
1340 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001341 }
jardineb5d44e2003-12-23 08:09:43 +00001342 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001343 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001344 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001345 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001346 listnode_add (lsp0->lspu.frags, lsp);
1347 lsp->lspu.zero_lsp = lsp0;
1348 /*
1349 * Copy the authinfo from zero LSP
1350 */
hassof390d2c2004-09-10 20:48:21 +00001351 if (lsp0->tlv_data.auth_info.type)
1352 {
1353 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1354 sizeof (struct isis_passwd));
1355 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1356 lsp->tlv_data.auth_info.len,
1357 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1358 }
jardineb5d44e2003-12-23 08:09:43 +00001359 return lsp;
1360}
1361
1362/*
1363 * Builds the LSP data part. This func creates a new frag whenever
1364 * area->lsp_frag_threshold is exceeded.
1365 */
1366#if 1
1367void
1368lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1369{
1370 struct is_neigh *is_neigh;
1371 struct listnode *node, *ipnode;
1372 int level = lsp->level;
1373 struct isis_circuit *circuit;
1374 struct prefix_ipv4 *ipv4;
1375 struct ipv4_reachability *ipreach;
1376 struct isis_adjacency *nei;
1377#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001378 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001379 struct ipv6_reachability *ip6reach;
1380#endif /* HAVE_IPV6 */
1381 struct tlvs tlv_data;
1382 struct isis_lsp *lsp0 = lsp;
1383 struct isis_passwd *passwd;
hasso18a6dce2004-10-03 18:18:34 +00001384 struct in_addr *routerid;
jardineb5d44e2003-12-23 08:09:43 +00001385
1386 /*
1387 * First add the tlvs related to area
1388 */
hassof390d2c2004-09-10 20:48:21 +00001389
jardineb5d44e2003-12-23 08:09:43 +00001390 /* Area addresses */
1391 if (lsp->tlv_data.area_addrs == NULL)
1392 lsp->tlv_data.area_addrs = list_new ();
1393 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1394 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001395 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001396#ifdef HAVE_IPV6
1397 || area->ipv6_circuits > 0
1398#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001399 )
jardineb5d44e2003-12-23 08:09:43 +00001400 {
1401 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1402 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001403 if (area->ip_circuits > 0)
1404 {
1405 lsp->tlv_data.nlpids->count++;
1406 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1407 }
jardineb5d44e2003-12-23 08:09:43 +00001408#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001409 if (area->ipv6_circuits > 0)
1410 {
1411 lsp->tlv_data.nlpids->count++;
1412 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1413 NLPID_IPV6;
1414 }
jardineb5d44e2003-12-23 08:09:43 +00001415#endif /* HAVE_IPV6 */
1416 }
1417 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001418 if (area->dynhostname)
1419 {
1420 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1421 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001422
hassof390d2c2004-09-10 20:48:21 +00001423 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1424 strlen (unix_hostname ()));
1425 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1426 }
jardineb5d44e2003-12-23 08:09:43 +00001427
1428 /*
1429 * Building the zero lsp
1430 */
hassof390d2c2004-09-10 20:48:21 +00001431 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001432 /*
1433 * Add the authentication info if its present
1434 */
hassof390d2c2004-09-10 20:48:21 +00001435 (level == 1) ? (passwd = &area->area_passwd) :
1436 (passwd = &area->domain_passwd);
1437 if (passwd->type)
1438 {
1439 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1440 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1441 }
jardineb5d44e2003-12-23 08:09:43 +00001442 if (lsp->tlv_data.nlpids)
1443 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1444 if (lsp->tlv_data.hostname)
1445 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001446 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001447 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001448
jardineb5d44e2003-12-23 08:09:43 +00001449 memset (&tlv_data, 0, sizeof (struct tlvs));
1450 /*
hasso18a6dce2004-10-03 18:18:34 +00001451 * IPv4 address TLV. We don't follow "C" vendor, but "J" vendor behavior -
1452 * one IPv4 address is put into LSP and this address is same as router id.
1453 */
1454 if (router_id_zebra.s_addr != 0)
1455 {
1456 u_char value[4];
1457
1458 if (lsp->tlv_data.ipv4_addrs == NULL)
1459 lsp->tlv_data.ipv4_addrs = list_new ();
1460
1461 routerid = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct in_addr));
1462 routerid->s_addr = router_id_zebra.s_addr;
1463
1464 listnode_add (lsp->tlv_data.ipv4_addrs, routerid);
1465
1466 /*
1467 * FIXME: Using add_tlv() directly is hack, but tlv_add_ip_addrs()
1468 * expects list of prefix_ipv4 structures, but we have list of
1469 * in_addr structures.
1470 */
1471 add_tlv (IPV4_ADDR, IPV4_MAX_BYTELEN, (u_char *) &routerid->s_addr,
1472 lsp->pdu);
1473 }
1474 /*
jardineb5d44e2003-12-23 08:09:43 +00001475 * Then build lists of tlvs related to circuits
1476 */
hassof390d2c2004-09-10 20:48:21 +00001477 for (node = listhead (area->circuit_list); node; nextnode (node))
1478 {
1479 circuit = getdata (node);
1480 if (circuit->state != C_STATE_UP)
1481 continue;
jardineb5d44e2003-12-23 08:09:43 +00001482
hassof390d2c2004-09-10 20:48:21 +00001483 /*
1484 * Add IPv4 internal reachability of this circuit
1485 */
1486 if (circuit->ip_router && circuit->ip_addrs &&
1487 circuit->ip_addrs->count > 0)
1488 {
1489 if (tlv_data.ipv4_int_reachs == NULL)
1490 {
1491 tlv_data.ipv4_int_reachs = list_new ();
1492 }
1493 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1494 nextnode (ipnode))
1495 {
1496 ipv4 = getdata (ipnode);
1497 ipreach =
1498 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1499 ipreach->metrics = circuit->metrics[level - 1];
hassof390d2c2004-09-10 20:48:21 +00001500 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001501 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1502 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001503 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1504 }
1505
1506 }
jardineb5d44e2003-12-23 08:09:43 +00001507#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001508 /*
1509 * Add IPv6 reachability of this circuit
1510 */
1511 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1512 circuit->ipv6_non_link->count > 0)
1513 {
1514
1515 if (tlv_data.ipv6_reachs == NULL)
1516 {
1517 tlv_data.ipv6_reachs = list_new ();
1518 }
1519 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1520 nextnode (ipnode))
1521 {
1522 ipv6 = getdata (ipnode);
1523 ip6reach =
1524 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1525 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1526 ip6reach->metric =
1527 htonl (circuit->metrics[level - 1].metric_default);
1528 ip6reach->control_info = 0;
1529 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001530 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1531 apply_mask_ipv6 (ip6prefix);
1532 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1533 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001534 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1535 }
1536 }
1537#endif /* HAVE_IPV6 */
1538
1539 switch (circuit->circ_type)
1540 {
1541 case CIRCUIT_T_BROADCAST:
1542 if (level & circuit->circuit_is_type)
1543 {
1544 if (tlv_data.is_neighs == NULL)
1545 {
1546 tlv_data.is_neighs = list_new ();
1547 }
1548 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1549 memset (is_neigh, 0, sizeof (struct is_neigh));
1550 if (level == 1)
1551 memcpy (is_neigh->neigh_id,
1552 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1553 else
1554 memcpy (is_neigh->neigh_id,
1555 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1556 is_neigh->metrics = circuit->metrics[level - 1];
1557 listnode_add (tlv_data.is_neighs, is_neigh);
1558 }
1559 break;
1560 case CIRCUIT_T_P2P:
1561 nei = circuit->u.p2p.neighbor;
1562 if (nei && (level & nei->circuit_t))
1563 {
1564 if (tlv_data.is_neighs == NULL)
1565 {
1566 tlv_data.is_neighs = list_new ();
1567 tlv_data.is_neighs->del = free_tlv;
1568 }
1569 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1570 memset (is_neigh, 0, sizeof (struct is_neigh));
1571 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1572 is_neigh->metrics = circuit->metrics[level - 1];
1573 listnode_add (tlv_data.is_neighs, is_neigh);
1574 }
1575 break;
1576 case CIRCUIT_T_STATIC_IN:
1577 zlog_warn ("lsp_area_create: unsupported circuit type");
1578 break;
1579 case CIRCUIT_T_STATIC_OUT:
1580 zlog_warn ("lsp_area_create: unsupported circuit type");
1581 break;
1582 case CIRCUIT_T_DA:
1583 zlog_warn ("lsp_area_create: unsupported circuit type");
1584 break;
1585 default:
1586 zlog_warn ("lsp_area_create: unknown circuit type");
1587 }
1588 }
1589
1590 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1591 {
1592 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1593 lsp->tlv_data.ipv4_int_reachs = list_new ();
1594 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1595 &lsp->tlv_data.ipv4_int_reachs,
1596 IPV4_REACH_LEN, area->lsp_frag_threshold,
1597 tlv_add_ipv4_reachs);
1598 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1599 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1600 lsp0, area, level);
1601 }
1602
1603#ifdef HAVE_IPV6
1604 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1605 {
1606 if (lsp->tlv_data.ipv6_reachs == NULL)
1607 lsp->tlv_data.ipv6_reachs = list_new ();
1608 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1609 &lsp->tlv_data.ipv6_reachs,
1610 IPV6_REACH_LEN, area->lsp_frag_threshold,
1611 tlv_add_ipv6_reachs);
1612 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1613 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1614 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001615 }
1616#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001617
1618 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1619 {
1620 if (lsp->tlv_data.is_neighs == NULL)
1621 lsp->tlv_data.is_neighs = list_new ();
1622 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1623 &lsp->tlv_data.is_neighs,
1624 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1625 tlv_add_is_neighs);
1626 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1627 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1628 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001629 }
jardineb5d44e2003-12-23 08:09:43 +00001630
jardineb5d44e2003-12-23 08:09:43 +00001631 return;
1632}
1633#endif
1634
1635void
1636build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1637{
1638 struct list *circuit_list = area->circuit_list;
1639 struct isis_circuit *circuit;
1640 u_char *tlv_ptr;
1641 struct is_neigh *is_neigh;
1642
hassof390d2c2004-09-10 20:48:21 +00001643
jardineb5d44e2003-12-23 08:09:43 +00001644 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001645 /* the 2 is for the TL plus 1 for the nlpid */
1646 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1647 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1648 *(tlv_ptr + 1) = 1; /* one protocol */
1649#ifdef HAVE_IPV6 /*dunno if its right */
1650 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001651#else
hassof390d2c2004-09-10 20:48:21 +00001652 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001653#endif /* HAVE_IPV6 */
1654
1655 /* we should add our areas here
1656 * FIXME: we need to figure out which should be added? Adj? All? First? */
1657
1658 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001659 /* the 2 is for the TL plus 1 for the virtual field */
1660 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1661 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1662 *(tlv_ptr + 2) = 0; /* virtual is zero */
1663 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001664 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001665 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1666 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001667 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001668 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001669 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001670 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001671 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001672 circuit = (struct isis_circuit *) listhead (circuit_list);
1673 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001674 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001675 *(tlv_ptr + 1) =
1676 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001677
1678 /* FIXME: scan for adjencecies and add them */
1679
1680 /* FIXME: add reachability info */
1681
hassof390d2c2004-09-10 20:48:21 +00001682 /* adding dynamic hostname if needed */
1683 if (area->dynhostname)
1684 {
1685 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1686 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1687 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1688 lsp->tlv_data.hostname = (struct hostname *)
1689 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1690 /* the -1 is to fit the length in the struct */
1691 strlen (unix_hostname ())) - 1);
1692 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1693 strlen (unix_hostname ()));
1694 }
jardineb5d44e2003-12-23 08:09:43 +00001695
1696}
1697
1698/*
1699 * 7.3.7 Generation on non-pseudonode LSPs
1700 */
1701int
hassof390d2c2004-09-10 20:48:21 +00001702lsp_generate_non_pseudo (struct isis_area *area, int level)
1703{
jardineb5d44e2003-12-23 08:09:43 +00001704 struct isis_lsp *oldlsp, *newlsp;
1705 u_int32_t seq_num = 0;
1706 u_char lspid[ISIS_SYS_ID_LEN + 2];
1707
1708 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1709 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1710
1711 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001712 if ((area->is_type & level) == level)
1713 {
1714 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1715 if (oldlsp)
1716 {
1717 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1718 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1719 area->lspdb[level - 1]);
1720 /* FIXME: we should actually initiate a purge */
1721 }
1722 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1723 area->is_type, 0, level);
1724 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001725
hassof390d2c2004-09-10 20:48:21 +00001726 lsp_insert (newlsp, area->lspdb[level - 1]);
1727 /* build_lsp_data (newlsp, area); */
1728 lsp_build_nonpseudo (newlsp, area);
1729 /* time to calculate our checksum */
1730 lsp_seqnum_update (newlsp);
1731 }
jardineb5d44e2003-12-23 08:09:43 +00001732
1733 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001734 if (isis->debugs & DEBUG_ADJ_PACKETS)
1735 {
1736 /* FIXME: is this place right? fix missing info */
1737 zlog_info ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
1738 }
jardineb5d44e2003-12-23 08:09:43 +00001739
1740 return ISIS_OK;
1741}
1742
1743/*
1744 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1745 */
1746int
1747lsp_l1_generate (struct isis_area *area)
1748{
hassof390d2c2004-09-10 20:48:21 +00001749 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1750 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001751
1752 return lsp_generate_non_pseudo (area, 1);
1753}
1754
jardineb5d44e2003-12-23 08:09:43 +00001755/*
1756 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1757 */
1758int
1759lsp_l2_generate (struct isis_area *area)
1760{
hassof390d2c2004-09-10 20:48:21 +00001761 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1762 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001763
1764 return lsp_generate_non_pseudo (area, 2);
1765}
1766
1767int
1768lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1769{
1770 dict_t *lspdb = area->lspdb[level - 1];
1771 struct isis_lsp *lsp, *frag;
1772 struct listnode *node;
1773 u_char lspid[ISIS_SYS_ID_LEN + 2];
1774
1775 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1776 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001777
jardineb5d44e2003-12-23 08:09:43 +00001778 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001779
hassof390d2c2004-09-10 20:48:21 +00001780 if (!lsp)
1781 {
1782 zlog_err
1783 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1784 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001785
hassof390d2c2004-09-10 20:48:21 +00001786 return ISIS_ERROR;
1787 }
1788
1789 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001790 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001791 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1792 (area->max_lsp_lifetime[level - 1],
1793 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001794 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001795
1796 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1797 {
1798 zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1799 "seq 0x%08x, cksum 0x%04x lifetime %us",
1800 area->area_tag,
1801 level,
1802 rawlspid_print (lsp->lsp_header->lsp_id),
1803 ntohl (lsp->lsp_header->seq_num),
1804 ntohs (lsp->lsp_header->checksum),
1805 ntohs (lsp->lsp_header->rem_lifetime));
1806 }
jardineb5d44e2003-12-23 08:09:43 +00001807
1808 lsp->last_generated = time (NULL);
1809 area->lsp_regenerate_pending[level - 1] = 0;
1810 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001811 for (node = listhead (lsp->lspu.frags); node; nextnode (node))
1812 {
1813 frag = getdata (node);
1814 frag->lsp_header->rem_lifetime = htons (isis_jitter
1815 (area->
1816 max_lsp_lifetime[level - 1],
1817 MAX_AGE_JITTER));
1818 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1819 }
jardineb5d44e2003-12-23 08:09:43 +00001820
1821 if (area->ip_circuits)
1822 isis_spf_schedule (area, level);
1823#ifdef HAVE_IPV6
1824 if (area->ipv6_circuits)
1825 isis_spf_schedule6 (area, level);
1826#endif
1827 return ISIS_OK;
1828}
1829
jardineb5d44e2003-12-23 08:09:43 +00001830/*
1831 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1832 * time and set SRM
1833 */
hassof390d2c2004-09-10 20:48:21 +00001834int
jardineb5d44e2003-12-23 08:09:43 +00001835lsp_refresh_l1 (struct thread *thread)
1836{
1837 struct isis_area *area;
1838 unsigned long ref_time;
1839
1840 area = THREAD_ARG (thread);
1841 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001842
jardineb5d44e2003-12-23 08:09:43 +00001843 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001844 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001845 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001846
1847 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001848 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1849
hassof390d2c2004-09-10 20:48:21 +00001850 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1851 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001852
jardineb5d44e2003-12-23 08:09:43 +00001853 return ISIS_OK;
1854}
1855
hassof390d2c2004-09-10 20:48:21 +00001856int
jardineb5d44e2003-12-23 08:09:43 +00001857lsp_refresh_l2 (struct thread *thread)
1858{
1859 struct isis_area *area;
1860 unsigned long ref_time;
1861
1862 area = THREAD_ARG (thread);
1863 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001864
jardineb5d44e2003-12-23 08:09:43 +00001865 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001866 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001867 lsp_non_pseudo_regenerate (area, 2);
1868
hassof390d2c2004-09-10 20:48:21 +00001869 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001870 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1871
hassof390d2c2004-09-10 20:48:21 +00001872 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1873 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001874
jardineb5d44e2003-12-23 08:09:43 +00001875 return ISIS_OK;
1876}
1877
jardineb5d44e2003-12-23 08:09:43 +00001878/*
1879 * Something has changed -> regenerate LSP
1880 */
1881
1882int
1883lsp_l1_regenerate (struct thread *thread)
1884{
1885 struct isis_area *area;
1886
1887 area = THREAD_ARG (thread);
1888 area->lsp_regenerate_pending[0] = 0;
1889
1890 return lsp_non_pseudo_regenerate (area, 1);
1891}
1892
1893int
1894lsp_l2_regenerate (struct thread *thread)
1895{
1896 struct isis_area *area;
1897
1898 area = THREAD_ARG (thread);
1899 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001900
jardineb5d44e2003-12-23 08:09:43 +00001901 return lsp_non_pseudo_regenerate (area, 2);
1902}
1903
hassof390d2c2004-09-10 20:48:21 +00001904int
jardineb5d44e2003-12-23 08:09:43 +00001905lsp_regenerate_schedule (struct isis_area *area)
1906{
1907 struct isis_lsp *lsp;
1908 u_char id[ISIS_SYS_ID_LEN + 2];
1909 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001910 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1911 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001912 now = time (NULL);
1913 /*
1914 * First level 1
1915 */
hassof390d2c2004-09-10 20:48:21 +00001916 if (area->is_type & IS_LEVEL_1)
1917 {
1918 lsp = lsp_search (id, area->lspdb[0]);
1919 if (!lsp || area->lsp_regenerate_pending[0])
1920 goto L2;
1921 /*
1922 * Throttle avoidance
1923 */
1924 diff = now - lsp->last_generated;
1925 if (diff < MIN_LSP_GEN_INTERVAL)
1926 {
1927 area->lsp_regenerate_pending[0] = 1;
1928 thread_add_timer (master, lsp_l1_regenerate, area,
1929 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001930 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001931 }
1932 else
1933 lsp_non_pseudo_regenerate (area, 1);
1934 }
jardineb5d44e2003-12-23 08:09:43 +00001935 /*
1936 * then 2
1937 */
hassof390d2c2004-09-10 20:48:21 +00001938L2:
1939 if (area->is_type & IS_LEVEL_2)
1940 {
1941 lsp = lsp_search (id, area->lspdb[1]);
1942 if (!lsp || area->lsp_regenerate_pending[1])
1943 return ISIS_OK;
1944 /*
1945 * Throttle avoidance
1946 */
1947 diff = now - lsp->last_generated;
1948 if (diff < MIN_LSP_GEN_INTERVAL)
1949 {
1950 area->lsp_regenerate_pending[1] = 1;
1951 thread_add_timer (master, lsp_l2_regenerate, area,
1952 MIN_LSP_GEN_INTERVAL - diff);
1953 return ISIS_OK;
1954 }
1955 else
1956 lsp_non_pseudo_regenerate (area, 2);
1957 }
1958
1959 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001960}
1961
1962/*
1963 * Funcs for pseudonode LSPs
1964 */
1965
1966/*
1967 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1968 */
1969void
hassof390d2c2004-09-10 20:48:21 +00001970lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1971 int level)
jardineb5d44e2003-12-23 08:09:43 +00001972{
1973 struct isis_adjacency *adj;
1974 struct is_neigh *is_neigh;
1975 struct es_neigh *es_neigh;
1976 struct list *adj_list;
1977 struct listnode *node;
1978 struct isis_passwd *passwd;
1979
1980 assert (circuit);
1981 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001982
jardineb5d44e2003-12-23 08:09:43 +00001983 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001984 return; /* we are not DIS on this circuit */
1985
jardineb5d44e2003-12-23 08:09:43 +00001986 lsp->level = level;
1987 if (level == 1)
1988 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1989 else
1990 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1991
1992 /*
1993 * add self to IS neighbours
1994 */
hassof390d2c2004-09-10 20:48:21 +00001995 if (lsp->tlv_data.is_neighs == NULL)
1996 {
1997 lsp->tlv_data.is_neighs = list_new ();
1998 lsp->tlv_data.is_neighs->del = free_tlv;
1999 }
jardineb5d44e2003-12-23 08:09:43 +00002000 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
2001 memset (is_neigh, 0, sizeof (struct is_neigh));
2002 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2003 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00002004
2005 adj_list = list_new ();
2006 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
2007
2008 for (node = listhead (adj_list); node; nextnode (node))
2009 {
2010 adj = getdata (node);
2011 if (adj->circuit_t & level)
2012 {
2013 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
2014 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
2015 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
2016 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
2017 {
2018 /* an IS neighbour -> add it */
2019 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
2020 memset (is_neigh, 0, sizeof (struct is_neigh));
2021 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
2022 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2023 }
2024 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
2025 {
2026 /* an ES neigbour add it, if we are building level 1 LSP */
2027 /* FIXME: the tlv-format is hard to use here */
2028 if (lsp->tlv_data.es_neighs == NULL)
2029 {
2030 lsp->tlv_data.es_neighs = list_new ();
2031 lsp->tlv_data.es_neighs->del = free_tlv;
2032 }
2033 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2034 memset (es_neigh, 0, sizeof (struct es_neigh));
2035 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
2036 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
2037 }
2038 }
jardineb5d44e2003-12-23 08:09:43 +00002039 }
hassof390d2c2004-09-10 20:48:21 +00002040
jardineb5d44e2003-12-23 08:09:43 +00002041 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2042 /*
2043 * Add the authentication info if it's present
2044 */
hassof390d2c2004-09-10 20:48:21 +00002045 (level == 1) ? (passwd = &circuit->area->area_passwd) :
2046 (passwd = &circuit->area->domain_passwd);
2047 if (passwd->type)
2048 {
2049 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
2050 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
2051 }
jardineb5d44e2003-12-23 08:09:43 +00002052
2053 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2054 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2055
2056 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2057 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2058
2059 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002060 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2061 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2062
jardineb5d44e2003-12-23 08:09:43 +00002063 list_delete (adj_list);
2064
2065 return;
2066}
2067
2068int
2069lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
2070{
2071 dict_t *lspdb = circuit->area->lspdb[level - 1];
2072 struct isis_lsp *lsp;
2073 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00002074
jardineb5d44e2003-12-23 08:09:43 +00002075 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002076 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2077 LSP_FRAGMENT (lsp_id) = 0;
2078
jardineb5d44e2003-12-23 08:09:43 +00002079 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002080
2081 if (!lsp)
2082 {
2083 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
2084 rawlspid_print (lsp_id));
2085 return ISIS_ERROR;
2086 }
2087 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002088
2089 lsp_build_pseudo (lsp, circuit, level);
2090
hassof390d2c2004-09-10 20:48:21 +00002091 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00002092 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00002093 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002094
2095 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00002096
2097 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2098 {
2099 zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
2100 circuit->area->area_tag, level,
2101 rawlspid_print (lsp->lsp_header->lsp_id));
2102 }
jardineb5d44e2003-12-23 08:09:43 +00002103
2104 lsp->last_generated = time (NULL);
2105 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002106
jardineb5d44e2003-12-23 08:09:43 +00002107 return ISIS_OK;
2108}
2109
jardineb5d44e2003-12-23 08:09:43 +00002110int
2111lsp_l1_refresh_pseudo (struct thread *thread)
2112{
2113 struct isis_circuit *circuit;
2114 int retval;
2115 unsigned long ref_time;
2116
hassof390d2c2004-09-10 20:48:21 +00002117 circuit = THREAD_ARG (thread);
2118
jardineb5d44e2003-12-23 08:09:43 +00002119 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002120 return ISIS_ERROR; /* FIXME: purge and such */
2121
hasso13c48f72004-09-10 21:19:13 +00002122 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2123
jardineb5d44e2003-12-23 08:09:43 +00002124 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002125
2126 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002127 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2128
hassof390d2c2004-09-10 20:48:21 +00002129 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2130 lsp_l1_refresh_pseudo, circuit,
2131 isis_jitter (ref_time, MAX_AGE_JITTER));
2132
jardineb5d44e2003-12-23 08:09:43 +00002133 return retval;
2134}
2135
hassof390d2c2004-09-10 20:48:21 +00002136int
jardineb5d44e2003-12-23 08:09:43 +00002137lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2138{
2139 struct isis_lsp *lsp;
2140 u_char id[ISIS_SYS_ID_LEN + 2];
2141 unsigned long ref_time;
2142
hassof390d2c2004-09-10 20:48:21 +00002143 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2144 LSP_FRAGMENT (id) = 0;
2145 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002146
2147 /*
2148 * If for some reason have a pseudo LSP in the db already -> regenerate
2149 */
2150 if (lsp_search (id, circuit->area->lspdb[0]))
2151 return lsp_pseudo_regenerate (circuit, 1);
2152 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002153 1, circuit->area->is_type, 0, 1);
2154
jardineb5d44e2003-12-23 08:09:43 +00002155 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002156
jardineb5d44e2003-12-23 08:09:43 +00002157 lsp->own_lsp = 1;
2158 lsp_insert (lsp, circuit->area->lspdb[0]);
2159 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2160
hassof390d2c2004-09-10 20:48:21 +00002161 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002162 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2163
hassof390d2c2004-09-10 20:48:21 +00002164 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2165 lsp_l1_refresh_pseudo, circuit,
2166 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002167
2168 return lsp_regenerate_schedule (circuit->area);
2169}
2170
2171int
2172lsp_l2_refresh_pseudo (struct thread *thread)
2173{
2174 struct isis_circuit *circuit;
2175 int retval;
2176 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002177 circuit = THREAD_ARG (thread);
2178
jardineb5d44e2003-12-23 08:09:43 +00002179 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002180 return ISIS_ERROR; /* FIXME: purge and such */
2181
hasso13c48f72004-09-10 21:19:13 +00002182 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2183
jardineb5d44e2003-12-23 08:09:43 +00002184 retval = lsp_pseudo_regenerate (circuit, 2);
2185
hassof390d2c2004-09-10 20:48:21 +00002186 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
hassof390d2c2004-09-10 20:48:21 +00002189 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2190 lsp_l2_refresh_pseudo, circuit,
2191 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002192
jardineb5d44e2003-12-23 08:09:43 +00002193 return retval;
2194}
2195
hassof390d2c2004-09-10 20:48:21 +00002196int
jardineb5d44e2003-12-23 08:09:43 +00002197lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2198{
2199 struct isis_lsp *lsp;
2200 u_char id[ISIS_SYS_ID_LEN + 2];
2201 unsigned long ref_time;
2202
hassof390d2c2004-09-10 20:48:21 +00002203 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2204 LSP_FRAGMENT (id) = 0;
2205 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002206
2207 if (lsp_search (id, circuit->area->lspdb[1]))
2208 return lsp_pseudo_regenerate (circuit, 2);
2209
2210 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002211 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002212
2213 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002214
2215 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002216 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2217
2218
2219 lsp->own_lsp = 1;
2220 lsp_insert (lsp, circuit->area->lspdb[1]);
2221 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002222
2223 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2224 lsp_l2_refresh_pseudo, circuit,
2225 isis_jitter (ref_time, MAX_AGE_JITTER));
2226
jardineb5d44e2003-12-23 08:09:43 +00002227 return lsp_regenerate_schedule (circuit->area);
2228}
2229
jardineb5d44e2003-12-23 08:09:43 +00002230/*
2231 * Walk through LSPs for an area
2232 * - set remaining lifetime
2233 * - set LSPs with SRMflag set for sending
2234 */
hassof390d2c2004-09-10 20:48:21 +00002235int
jardineb5d44e2003-12-23 08:09:43 +00002236lsp_tick (struct thread *thread)
2237{
2238 struct isis_area *area;
2239 struct isis_circuit *circuit;
2240 struct isis_lsp *lsp;
2241 struct list *lsp_list;
2242 struct listnode *lspnode, *cnode;
2243 dnode_t *dnode, *dnode_next;
2244 int level;
2245
2246 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002247
jardineb5d44e2003-12-23 08:09:43 +00002248 area = THREAD_ARG (thread);
2249 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002250 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002251 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002252
2253 /*
2254 * Build a list of LSPs with (any) SRMflag set
2255 * and removed the ones that have aged out
2256 */
hassof390d2c2004-09-10 20:48:21 +00002257 for (level = 0; level < ISIS_LEVELS; level++)
2258 {
2259 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2260 {
2261 dnode = dict_first (area->lspdb[level]);
2262 while (dnode != NULL)
2263 {
2264 dnode_next = dict_next (area->lspdb[level], dnode);
2265 lsp = dnode_get (dnode);
2266 lsp_set_time (lsp);
2267 if (lsp->age_out == 0)
2268 {
jardineb5d44e2003-12-23 08:09:43 +00002269
hassof390d2c2004-09-10 20:48:21 +00002270 zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2271 area->area_tag,
2272 lsp->level,
2273 rawlspid_print (lsp->lsp_header->lsp_id),
2274 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002275
hassof390d2c2004-09-10 20:48:21 +00002276 lsp_destroy (lsp);
2277 dict_delete (area->lspdb[level], dnode);
2278 }
2279 else if (flags_any_set (lsp->SRMflags))
2280 listnode_add (lsp_list, lsp);
2281 dnode = dnode_next;
2282 }
jardineb5d44e2003-12-23 08:09:43 +00002283
hassof390d2c2004-09-10 20:48:21 +00002284 /*
2285 * Send LSPs on circuits indicated by the SRMflags
2286 */
2287 if (listcount (lsp_list) > 0)
2288 {
2289 for (cnode = listhead (area->circuit_list); cnode;
2290 nextnode (cnode))
2291 {
2292 circuit = getdata (cnode);
2293 for (lspnode = listhead (lsp_list); lspnode;
2294 nextnode (lspnode))
2295 {
2296 lsp = getdata (lspnode);
2297 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2298 {
2299 /* FIXME: if same or elder lsp is already in lsp
2300 * queue */
2301 listnode_add (circuit->lsp_queue, lsp);
2302 thread_add_event (master, send_lsp, circuit, 0);
2303 }
2304 }
2305 }
2306 }
2307 list_delete_all_node (lsp_list);
2308 }
jardineb5d44e2003-12-23 08:09:43 +00002309 }
jardineb5d44e2003-12-23 08:09:43 +00002310
2311 list_delete (lsp_list);
2312
2313 return ISIS_OK;
2314}
2315
jardineb5d44e2003-12-23 08:09:43 +00002316void
hassof390d2c2004-09-10 20:48:21 +00002317lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002318{
2319 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002320
jardineb5d44e2003-12-23 08:09:43 +00002321 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002322
2323 if (lsp && lsp->purged == 0)
2324 {
2325 lsp->lsp_header->rem_lifetime = htons (0);
2326 lsp->lsp_header->pdu_len =
2327 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2328 lsp->purged = 0;
2329 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2330 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2331 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2332 }
2333
jardineb5d44e2003-12-23 08:09:43 +00002334 return;
2335}
2336
2337/*
2338 * Purge own LSP that is received and we don't have.
2339 * -> Do as in 7.3.16.4
2340 */
2341void
hassof390d2c2004-09-10 20:48:21 +00002342lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2343 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002344{
2345 struct isis_lsp *lsp;
2346
2347 /*
2348 * We need to create the LSP to be purged
2349 */
2350 zlog_info ("LSP PURGE NON EXIST");
2351 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2352 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002353 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2354 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002355 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2356 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002357 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002358 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002359 : L2_LINK_STATE);
2360 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2361 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002362 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002363
jardineb5d44e2003-12-23 08:09:43 +00002364 /*
2365 * Retain only LSP header
2366 */
2367 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2368 /*
2369 * Set the remaining lifetime to 0
2370 */
2371 lsp->lsp_header->rem_lifetime = 0;
2372 /*
2373 * Put the lsp into LSPdb
2374 */
hassof390d2c2004-09-10 20:48:21 +00002375 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002376
2377 /*
2378 * Send in to whole area
2379 */
2380 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002381
jardineb5d44e2003-12-23 08:09:43 +00002382 return;
2383}
2384
2385#ifdef TOPOLOGY_GENERATE
2386int
2387top_lsp_refresh (struct thread *thread)
2388{
hassof390d2c2004-09-10 20:48:21 +00002389 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002390
2391 lsp = THREAD_ARG (thread);
2392 assert (lsp);
2393
2394 lsp->t_lsp_top_ref = NULL;
2395
hassof390d2c2004-09-10 20:48:21 +00002396 lsp->lsp_header->rem_lifetime =
2397 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2398 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002399
2400 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002401 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2402 {
2403 zlog_info ("ISIS-Upd (): refreshing Topology L1 %s",
2404 rawlspid_print (lsp->lsp_header->lsp_id));
2405 }
jardineb5d44e2003-12-23 08:09:43 +00002406
2407 /* time to calculate our checksum */
2408 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002409 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2410 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2411 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002412
2413 return ISIS_OK;
2414}
2415
2416void
2417generate_topology_lsps (struct isis_area *area)
2418{
2419 struct listnode *node;
2420 int i, max = 0;
2421 struct arc *arc;
2422 u_char lspid[ISIS_SYS_ID_LEN + 2];
2423 struct isis_lsp *lsp;
2424
2425 /* first we find the maximal node */
hassof390d2c2004-09-10 20:48:21 +00002426 LIST_LOOP (area->topology, arc, node)
2427 {
2428 if (arc->from_node > max)
2429 max = arc->from_node;
2430 if (arc->to_node > max)
2431 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002432 }
2433
hassof390d2c2004-09-10 20:48:21 +00002434 for (i = 1; i < (max + 1); i++)
2435 {
2436 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2437 LSP_PSEUDO_ID (lspid) = 0x00;
2438 LSP_FRAGMENT (lspid) = 0x00;
2439 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2440 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002441
hassof390d2c2004-09-10 20:48:21 +00002442 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2443 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2444 1);
2445 lsp->from_topology = 1;
2446 /* creating data based on topology */
2447 build_topology_lsp_data (lsp, area, i);
2448 /* time to calculate our checksum */
2449 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2450 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2451 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2452 isis_jitter (MAX_LSP_GEN_INTERVAL,
2453 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002454
hassof390d2c2004-09-10 20:48:21 +00002455 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2456 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002457
hassof390d2c2004-09-10 20:48:21 +00002458 }
jardineb5d44e2003-12-23 08:09:43 +00002459}
2460
2461void
2462remove_topology_lsps (struct isis_area *area)
2463{
2464 struct isis_lsp *lsp;
2465 dnode_t *dnode, *dnode_next;
2466
2467 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002468 while (dnode != NULL)
2469 {
2470 dnode_next = dict_next (area->lspdb[0], dnode);
2471 lsp = dnode_get (dnode);
2472 if (lsp->from_topology)
2473 {
2474 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2475 lsp_destroy (lsp);
2476 dict_delete (area->lspdb[0], dnode);
2477 }
2478 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002479 }
jardineb5d44e2003-12-23 08:09:43 +00002480}
2481
2482void
hassof390d2c2004-09-10 20:48:21 +00002483build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002484 int lsp_top_num)
2485{
2486 struct listnode *node;
2487 struct arc *arc;
2488 u_char *tlv_ptr;
2489 struct is_neigh *is_neigh;
2490 int to_lsp = 0;
2491 char buff[200];
2492
2493 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002494 /* the 2 is for the TL plus 1 for the nlpid */
2495 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2496 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2497 *(tlv_ptr + 1) = 1; /* one protocol */
2498 *(tlv_ptr + 2) = NLPID_IP;
2499 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002500
2501 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002502 /* the 2 is for the TL plus 1 for the virtual field */
2503 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2504 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2505 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2506 *(tlv_ptr + 2) = 0; /* virtual is zero */
2507 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002508
2509 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002510 if (lsp_top_num == 1)
2511 {
jardineb5d44e2003-12-23 08:09:43 +00002512 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002513 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2514 sizeof (struct
2515 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002516 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002517 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2518 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002519 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002520 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002521 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2522 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2523 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2524 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002525 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2526 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002527 }
hassof390d2c2004-09-10 20:48:21 +00002528
2529 /* addding is reachabilities */
2530 LIST_LOOP (area->topology, arc, node)
2531 {
2532 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2533 {
2534 if (arc->to_node == lsp_top_num)
2535 to_lsp = arc->from_node;
2536 if (arc->from_node == lsp_top_num)
2537 to_lsp = arc->to_node;
2538
2539 /* if the length here is about to cross the FF limit, we reTLV */
2540 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2541 {
2542 /* retlv */
2543 /* the 2 is for the TL plus 1 for the virtual field */
2544 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2545 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2546 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2547 *(tlv_ptr + 2) = 0; /* virtual is zero */
2548 }
2549 /* doing this here assures us that we won't add an "empty" tlv */
2550 /* assign space for the is_neigh at the pdu end */
2551 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2552 sizeof (struct
2553 is_neigh));
2554 /* add this node to our list */
2555 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2556 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2557 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2558 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2559 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2560 is_neigh->metrics.metric_default = arc->distance;
2561 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2562 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2563 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2564 /* don't forget the length */
2565 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2566 }
jardineb5d44e2003-12-23 08:09:43 +00002567 }
2568
hassof390d2c2004-09-10 20:48:21 +00002569 /* adding dynamic hostname if needed */
2570 if (area->dynhostname)
2571 {
2572 memset (buff, 0x00, 200);
2573 sprintf (buff, "feedme%d", lsp_top_num);
2574 /* the 2 is for the TL */
2575 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2576 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2577 *(tlv_ptr + 1) = strlen (buff); /* Length */
2578 /* the -1 is to fit the length in the struct */
2579 lsp->tlv_data.hostname = (struct hostname *)
2580 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2581 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2582 }
jardineb5d44e2003-12-23 08:09:43 +00002583
2584 /* thanks to hannes, another bug bites the dust */
hassof390d2c2004-09-10 20:48:21 +00002585 lsp->pdu->putp = ntohs (lsp->lsp_header->pdu_len);
2586 lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00002587}
2588#endif /* TOPOLOGY_GENERATE */