blob: 5467b48345133f88152133199b4ffb5e20f88c1a [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_lsp.c
3 * LSP processing
4 *
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23#include <stdlib.h>
24#include <stdio.h>
25#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000026
27#include "linklist.h"
28#include "thread.h"
29#include "vty.h"
30#include "stream.h"
31#include "memory.h"
32#include "log.h"
33#include "prefix.h"
34#include "command.h"
35#include "hash.h"
36#include "if.h"
37
38#include "isisd/dict.h"
39#include "isisd/isis_constants.h"
40#include "isisd/isis_common.h"
41#include "isisd/isis_circuit.h"
42#include "isisd/isisd.h"
43#include "isisd/isis_tlv.h"
44#include "isisd/isis_lsp.h"
45#include "isisd/isis_pdu.h"
46#include "isisd/isis_dynhn.h"
47#include "isisd/isis_misc.h"
48#include "isisd/isis_flags.h"
49#include "isisd/iso_checksum.h"
50#include "isisd/isis_csm.h"
51#include "isisd/isis_adjacency.h"
52#include "isisd/isis_spf.h"
53
54#ifdef TOPOLOGY_GENERATE
55#include "spgrid.h"
56#endif
57
hassof390d2c2004-09-10 20:48:21 +000058#define LSP_MEMORY_PREASSIGN
jardineb5d44e2003-12-23 08:09:43 +000059
60extern struct isis *isis;
61extern struct thread_master *master;
jardineb5d44e2003-12-23 08:09:43 +000062
hasso73d1aea2004-09-24 10:45:28 +000063/* staticly assigned vars for printing purposes */
64char lsp_bits_string[200]; /* FIXME: enough ? */
65
hassof390d2c2004-09-10 20:48:21 +000066int
67lsp_id_cmp (u_char * id1, u_char * id2)
68{
jardineb5d44e2003-12-23 08:09:43 +000069 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
70}
71
72dict_t *
hassof390d2c2004-09-10 20:48:21 +000073lsp_db_init (void)
jardineb5d44e2003-12-23 08:09:43 +000074{
75 dict_t *dict;
hassof390d2c2004-09-10 20:48:21 +000076
77 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t) lsp_id_cmp);
78
jardineb5d44e2003-12-23 08:09:43 +000079 return dict;
80}
81
82struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +000083lsp_search (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +000084{
85 dnode_t *node;
86
hassof390d2c2004-09-10 20:48:21 +000087#ifdef EXTREME_DEBUG
jardineb5d44e2003-12-23 08:09:43 +000088 dnode_t *dn;
89
hassof390d2c2004-09-10 20:48:21 +000090 zlog_warn ("searching db");
91 for (dn = dict_first (lspdb); dn; dn = dict_next (lspdb, dn))
92 {
93 zlog_warn ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn)),
94 dnode_get (dn));
95 }
jardineb5d44e2003-12-23 08:09:43 +000096#endif /* EXTREME DEBUG */
97
98 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +000099
jardineb5d44e2003-12-23 08:09:43 +0000100 if (node)
hassof390d2c2004-09-10 20:48:21 +0000101 return (struct isis_lsp *) dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000102
103 return NULL;
104}
105
106void
107lsp_clear_data (struct isis_lsp *lsp)
108{
109 if (!lsp)
110 return;
hassof390d2c2004-09-10 20:48:21 +0000111
112 if (lsp->own_lsp)
113 {
114 if (lsp->tlv_data.nlpids)
115 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
116 if (lsp->tlv_data.hostname)
117 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
118 }
jardineb5d44e2003-12-23 08:09:43 +0000119 if (lsp->tlv_data.is_neighs)
120 list_delete (lsp->tlv_data.is_neighs);
121 if (lsp->tlv_data.area_addrs)
122 list_delete (lsp->tlv_data.area_addrs);
123 if (lsp->tlv_data.es_neighs)
124 list_delete (lsp->tlv_data.es_neighs);
125 if (lsp->tlv_data.ipv4_addrs)
126 list_delete (lsp->tlv_data.ipv4_addrs);
127 if (lsp->tlv_data.ipv4_int_reachs)
128 list_delete (lsp->tlv_data.ipv4_int_reachs);
129 if (lsp->tlv_data.ipv4_ext_reachs)
130 list_delete (lsp->tlv_data.ipv4_ext_reachs);
131#ifdef HAVE_IPV6
132 if (lsp->tlv_data.ipv6_addrs)
133 list_delete (lsp->tlv_data.ipv6_addrs);
134 if (lsp->tlv_data.ipv6_reachs)
135 list_delete (lsp->tlv_data.ipv6_reachs);
136#endif /* HAVE_IPV6 */
137
138 memset (&lsp->tlv_data, 0, sizeof (struct tlvs));
139
140 return;
141}
142
143void
144lsp_destroy (struct isis_lsp *lsp)
145{
146 if (!lsp)
147 return;
hassof390d2c2004-09-10 20:48:21 +0000148
jardineb5d44e2003-12-23 08:09:43 +0000149 lsp_clear_data (lsp);
hassof390d2c2004-09-10 20:48:21 +0000150
151 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags)
152 {
jardineb5d44e2003-12-23 08:09:43 +0000153 list_delete (lsp->lspu.frags);
hassof390d2c2004-09-10 20:48:21 +0000154 }
155
jardineb5d44e2003-12-23 08:09:43 +0000156 if (lsp->pdu)
157 stream_free (lsp->pdu);
158 XFREE (MTYPE_ISIS_LSP, lsp);
159}
160
hassof390d2c2004-09-10 20:48:21 +0000161void
162lsp_db_destroy (dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000163{
164 dnode_t *dnode, *next;
165 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000166
jardineb5d44e2003-12-23 08:09:43 +0000167 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000168 while (dnode)
169 {
170 next = dict_next (lspdb, dnode);
171 lsp = dnode_get (dnode);
172 lsp_destroy (lsp);
173 dict_delete_free (lspdb, dnode);
174 dnode = next;
175 }
176
jardineb5d44e2003-12-23 08:09:43 +0000177 dict_free (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000178
jardineb5d44e2003-12-23 08:09:43 +0000179 return;
180}
181
182/*
183 * Remove all the frags belonging to the given lsp
184 */
185void
hassof390d2c2004-09-10 20:48:21 +0000186lsp_remove_frags (struct list *frags, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000187{
188 dnode_t *dnode;
189 struct listnode *lnode;
190 struct isis_lsp *lsp;
191
hassof390d2c2004-09-10 20:48:21 +0000192 for (lnode = listhead (frags); lnode; nextnode (lnode))
193 {
194 lsp = getdata (lnode);
195 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
196 lsp_destroy (lsp);
197 dnode_destroy (dict_delete (lspdb, dnode));
198 }
199
jardineb5d44e2003-12-23 08:09:43 +0000200 list_delete_all_node (frags);
hassof390d2c2004-09-10 20:48:21 +0000201
jardineb5d44e2003-12-23 08:09:43 +0000202 return;
203}
204
205void
hassof390d2c2004-09-10 20:48:21 +0000206lsp_search_and_destroy (u_char * id, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000207{
208 dnode_t *node;
209 struct isis_lsp *lsp;
210
211 node = dict_lookup (lspdb, id);
hassof390d2c2004-09-10 20:48:21 +0000212 if (node)
213 {
214 node = dict_delete (lspdb, node);
215 lsp = dnode_get (node);
216 /*
217 * If this is a zero lsp, remove all the frags now
218 */
219 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0)
220 {
221 if (lsp->lspu.frags)
222 lsp_remove_frags (lsp->lspu.frags, lspdb);
223 }
224 else
225 {
226 /*
227 * else just remove this frag, from the zero lsps' frag list
228 */
229 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
230 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
231 }
232 lsp_destroy (lsp);
233 dnode_destroy (node);
jardineb5d44e2003-12-23 08:09:43 +0000234 }
jardineb5d44e2003-12-23 08:09:43 +0000235}
236
237/*
238 * Compares a LSP to given values
239 * Params are given in net order
240 */
hassof390d2c2004-09-10 20:48:21 +0000241int
242lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
jardineb5d44e2003-12-23 08:09:43 +0000243 u_int16_t checksum, u_int16_t rem_lifetime)
244{
hassof390d2c2004-09-10 20:48:21 +0000245 /* no point in double ntohl on seqnum */
246 if (lsp->lsp_header->seq_num == seq_num &&
jardineb5d44e2003-12-23 08:09:43 +0000247 lsp->lsp_header->checksum == checksum &&
248 /*comparing with 0, no need to do ntohl */
249 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
hassof390d2c2004-09-10 20:48:21 +0000250 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0)))
251 {
252 if (isis->debugs & DEBUG_SNP_PACKETS)
253 {
254 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
255 " lifetime %us",
256 areatag,
257 rawlspid_print (lsp->lsp_header->lsp_id),
258 ntohl (lsp->lsp_header->seq_num),
259 ntohs (lsp->lsp_header->checksum),
260 ntohs (lsp->lsp_header->rem_lifetime));
261 zlog_info ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
262 " cksum 0x%04x, lifetime %us",
263 areatag,
264 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
265 }
266 return LSP_EQUAL;
jardineb5d44e2003-12-23 08:09:43 +0000267 }
jardineb5d44e2003-12-23 08:09:43 +0000268
hassof390d2c2004-09-10 20:48:21 +0000269 if (ntohl (seq_num) >= ntohl (lsp->lsp_header->seq_num))
270 {
271 if (isis->debugs & DEBUG_SNP_PACKETS)
272 {
273 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
274 " lifetime %us",
275 areatag,
276 rawlspid_print (lsp->lsp_header->lsp_id),
277 ntohl (seq_num), ntohs (checksum), ntohs (rem_lifetime));
278 zlog_info ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
279 "cksum 0x%04x, lifetime %us",
280 areatag,
281 ntohl (lsp->lsp_header->seq_num),
282 ntohs (lsp->lsp_header->checksum),
283 ntohs (lsp->lsp_header->rem_lifetime));
284 }
285 return LSP_NEWER;
jardineb5d44e2003-12-23 08:09:43 +0000286 }
hassof390d2c2004-09-10 20:48:21 +0000287 if (isis->debugs & DEBUG_SNP_PACKETS)
288 {
289 zlog_info
290 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
291 areatag, rawlspid_print (lsp->lsp_header->lsp_id), ntohl (seq_num),
292 ntohs (checksum), ntohs (rem_lifetime));
293 zlog_info ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
294 " cksum 0x%04x, lifetime %us", areatag,
295 ntohl (lsp->lsp_header->seq_num),
296 ntohs (lsp->lsp_header->checksum),
297 ntohs (lsp->lsp_header->rem_lifetime));
298 }
jardineb5d44e2003-12-23 08:09:43 +0000299
300 return LSP_OLDER;
301}
302
hassof390d2c2004-09-10 20:48:21 +0000303void
jardineb5d44e2003-12-23 08:09:43 +0000304lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
305{
306 u_int32_t newseq;
hassof390d2c2004-09-10 20:48:21 +0000307
jardineb5d44e2003-12-23 08:09:43 +0000308 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
309 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
310 else
hassof390d2c2004-09-10 20:48:21 +0000311 newseq = seq_num++;
312
jardineb5d44e2003-12-23 08:09:43 +0000313 lsp->lsp_header->seq_num = htonl (newseq);
hassof390d2c2004-09-10 20:48:21 +0000314 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
315 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
jardineb5d44e2003-12-23 08:09:43 +0000316
317 return;
318}
319
320/*
321 * Genetates checksum for LSP and its frags
322 */
323void
324lsp_seqnum_update (struct isis_lsp *lsp0)
325{
326 struct isis_lsp *lsp;
327 struct listnode *node;
hassof390d2c2004-09-10 20:48:21 +0000328
jardineb5d44e2003-12-23 08:09:43 +0000329 lsp_inc_seqnum (lsp0, 0);
330
331 if (!lsp0->lspu.frags)
332 return;
333
hassof390d2c2004-09-10 20:48:21 +0000334 for (node = listhead (lsp0->lspu.frags); node; nextnode (node))
335 {
336 lsp = getdata (node);
337 lsp_inc_seqnum (lsp, 0);
338 }
339
jardineb5d44e2003-12-23 08:09:43 +0000340 return;
341}
342
hassof390d2c2004-09-10 20:48:21 +0000343int
jardineb5d44e2003-12-23 08:09:43 +0000344isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
hassof390d2c2004-09-10 20:48:21 +0000345 int pdulen, struct isis_passwd *passwd)
jardineb5d44e2003-12-23 08:09:43 +0000346{
347 uint32_t expected = 0, found;
348 struct tlvs tlvs;
349 int retval = 0;
350
351 expected |= TLVFLAG_AUTH_INFO;
352 retval = parse_tlvs (area->area_tag, stream->data +
hassof390d2c2004-09-10 20:48:21 +0000353 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
354 pdulen - ISIS_FIXED_HDR_LEN
355 - ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
jardineb5d44e2003-12-23 08:09:43 +0000356 if (retval || !(found & TLVFLAG_AUTH_INFO))
hassof390d2c2004-09-10 20:48:21 +0000357 return 1; /* Auth fail (parsing failed or no auth-tlv) */
jardineb5d44e2003-12-23 08:09:43 +0000358
359 return authentication_check (passwd, &tlvs.auth_info);
360}
361
362void
hassof390d2c2004-09-10 20:48:21 +0000363lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
364 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000365{
hassof390d2c2004-09-10 20:48:21 +0000366 uint32_t expected = 0, found;
jardineb5d44e2003-12-23 08:09:43 +0000367 int retval;
hassof390d2c2004-09-10 20:48:21 +0000368
jardineb5d44e2003-12-23 08:09:43 +0000369 /* copying only the relevant part of our stream */
370 lsp->pdu = stream_new (stream->endp);
371 lsp->pdu->putp = stream->putp;
372 lsp->pdu->getp = stream->getp;
373 lsp->pdu->endp = stream->endp;
374 memcpy (lsp->pdu->data, stream->data, stream->endp);
375
376 /* setting pointers to the correct place */
hassof390d2c2004-09-10 20:48:21 +0000377 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
378 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
379 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000380 lsp->age_out = ZERO_AGE_LIFETIME;
hassof390d2c2004-09-10 20:48:21 +0000381 lsp->installed = time (NULL);
jardineb5d44e2003-12-23 08:09:43 +0000382 /*
383 * Get LSP data i.e. TLVs
384 */
385 expected |= TLVFLAG_AUTH_INFO;
386 expected |= TLVFLAG_AREA_ADDRS;
387 expected |= TLVFLAG_IS_NEIGHS;
hassof390d2c2004-09-10 20:48:21 +0000388 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
jardineb5d44e2003-12-23 08:09:43 +0000389 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
390 expected |= TLVFLAG_NLPID;
391 if (area->dynhostname)
392 expected |= TLVFLAG_DYN_HOSTNAME;
hassof390d2c2004-09-10 20:48:21 +0000393 if (area->newmetric)
394 {
395 expected |= TLVFLAG_TE_IS_NEIGHS;
396 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
397 expected |= TLVFLAG_TE_ROUTER_ID;
398 }
jardineb5d44e2003-12-23 08:09:43 +0000399 expected |= TLVFLAG_IPV4_ADDR;
400 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
401 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
402#ifdef HAVE_IPV6
403 expected |= TLVFLAG_IPV6_ADDR;
404 expected |= TLVFLAG_IPV6_REACHABILITY;
405#endif /* HAVE_IPV6 */
406
407 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
hassof390d2c2004-09-10 20:48:21 +0000408 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
409 ntohs (lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
410 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
jardineb5d44e2003-12-23 08:09:43 +0000411
hassof390d2c2004-09-10 20:48:21 +0000412 if (found & TLVFLAG_DYN_HOSTNAME)
413 {
414 if (area->dynhostname)
415 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
416 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
417 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
418 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
419 }
jardineb5d44e2003-12-23 08:09:43 +0000420
421}
422
423void
424lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
hassof390d2c2004-09-10 20:48:21 +0000425 struct stream *stream, struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000426{
hassof390d2c2004-09-10 20:48:21 +0000427 /* free the old lsp data */
jardineb5d44e2003-12-23 08:09:43 +0000428 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
429 lsp_clear_data (lsp);
430
431 /* rebuild the lsp data */
432 lsp_update_data (lsp, stream, area);
433
hassof390d2c2004-09-10 20:48:21 +0000434 /* set the new values for lsp header */
jardineb5d44e2003-12-23 08:09:43 +0000435 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000436}
437
jardineb5d44e2003-12-23 08:09:43 +0000438/* creation of LSP directly from what we received */
439struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000440lsp_new_from_stream_ptr (struct stream *stream,
441 u_int16_t pdu_len, struct isis_lsp *lsp0,
442 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +0000443{
444 struct isis_lsp *lsp;
445
446 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
447 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000448
jardineb5d44e2003-12-23 08:09:43 +0000449 lsp_update_data (lsp, stream, area);
hassof390d2c2004-09-10 20:48:21 +0000450
451 if (lsp0 == NULL)
452 {
453 /*
454 * zero lsp -> create the list for fragments
455 */
456 lsp->lspu.frags = list_new ();
457 }
458 else
459 {
460 /*
461 * a fragment -> set the backpointer and add this to zero lsps frag list
462 */
463 lsp->lspu.zero_lsp = lsp0;
464 listnode_add (lsp0->lspu.frags, lsp);
465 }
466
jardineb5d44e2003-12-23 08:09:43 +0000467 return lsp;
468}
469
470struct isis_lsp *
hassof390d2c2004-09-10 20:48:21 +0000471lsp_new (u_char * lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
472 u_int8_t lsp_bits, u_int16_t checksum, int level)
jardineb5d44e2003-12-23 08:09:43 +0000473{
474 struct isis_lsp *lsp;
475
476 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +0000477 if (!lsp)
478 {
479 /* FIXME: set lspdbol bit */
480 zlog_warn ("lsp_new(): out of memory");
481 return NULL;
482 }
jardineb5d44e2003-12-23 08:09:43 +0000483 memset (lsp, 0, sizeof (struct isis_lsp));
484#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +0000485 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup... */
jardineb5d44e2003-12-23 08:09:43 +0000486#else
hassof390d2c2004-09-10 20:48:21 +0000487 /* We need to do realloc on TLVs additions */
488 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000489#endif /* LSP_MEMORY_PREASSIGN */
490 if (LSP_FRAGMENT (lsp_id) == 0)
491 lsp->lspu.frags = list_new ();
hassof390d2c2004-09-10 20:48:21 +0000492 lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu));
493 lsp->lsp_header = (struct isis_link_state_hdr *)
494 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
495
jardineb5d44e2003-12-23 08:09:43 +0000496 /* at first we fill the FIXED HEADER */
hassof390d2c2004-09-10 20:48:21 +0000497 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE) :
498 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
499
jardineb5d44e2003-12-23 08:09:43 +0000500 /* now for the LSP HEADER */
501 /* Minimal LSP PDU size */
hassof390d2c2004-09-10 20:48:21 +0000502 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +0000503 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
hassof390d2c2004-09-10 20:48:21 +0000504 lsp->lsp_header->checksum = checksum; /* Provided in network order */
jardineb5d44e2003-12-23 08:09:43 +0000505 lsp->lsp_header->seq_num = htonl (seq_num);
506 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
507 lsp->lsp_header->lsp_bits = lsp_bits;
508 lsp->level = level;
509 lsp->age_out = ZERO_AGE_LIFETIME;
510
511 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
512
513 /* #ifdef EXTREME_DEBUG */
514 /* logging */
515 zlog_info ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
hassof390d2c2004-09-10 20:48:21 +0000516 LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
517 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
518 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +0000519 /* #endif EXTREME DEBUG */
520
521 return lsp;
522}
523
524void
hassof390d2c2004-09-10 20:48:21 +0000525lsp_insert (struct isis_lsp *lsp, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000526{
527 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
528}
529
530/*
531 * Build a list of LSPs with non-zero ht bounded by start and stop ids
532 */
hassof390d2c2004-09-10 20:48:21 +0000533void
534lsp_build_list_nonzero_ht (u_char * start_id, u_char * stop_id,
535 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000536{
537 dnode_t *first, *last, *curr;
538
539 first = dict_lower_bound (lspdb, start_id);
540 if (!first)
541 return;
hassof390d2c2004-09-10 20:48:21 +0000542
jardineb5d44e2003-12-23 08:09:43 +0000543 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000544
jardineb5d44e2003-12-23 08:09:43 +0000545 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000546
547 if (((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
jardineb5d44e2003-12-23 08:09:43 +0000548 listnode_add (list, first->dict_data);
549
hassof390d2c2004-09-10 20:48:21 +0000550 while (curr)
551 {
552 curr = dict_next (lspdb, curr);
553 if (curr &&
554 ((struct isis_lsp *) (curr->dict_data))->lsp_header->rem_lifetime)
555 listnode_add (list, curr->dict_data);
556 if (curr == last)
557 break;
558 }
559
jardineb5d44e2003-12-23 08:09:43 +0000560 return;
561}
562
563/*
564 * Build a list of all LSPs bounded by start and stop ids
565 */
hassof390d2c2004-09-10 20:48:21 +0000566void
567lsp_build_list (u_char * start_id, u_char * stop_id,
568 struct list *list, dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000569{
570 dnode_t *first, *last, *curr;
571
572 first = dict_lower_bound (lspdb, start_id);
573 if (!first)
574 return;
hassof390d2c2004-09-10 20:48:21 +0000575
jardineb5d44e2003-12-23 08:09:43 +0000576 last = dict_upper_bound (lspdb, stop_id);
hassof390d2c2004-09-10 20:48:21 +0000577
jardineb5d44e2003-12-23 08:09:43 +0000578 curr = first;
hassof390d2c2004-09-10 20:48:21 +0000579
jardineb5d44e2003-12-23 08:09:43 +0000580 listnode_add (list, first->dict_data);
581
hassof390d2c2004-09-10 20:48:21 +0000582 while (curr)
583 {
584 curr = dict_next (lspdb, curr);
585 if (curr)
586 listnode_add (list, curr->dict_data);
587 if (curr == last)
588 break;
589 }
590
jardineb5d44e2003-12-23 08:09:43 +0000591 return;
592}
593
594/*
595 * Build a list of LSPs with SSN flag set for the given circuit
596 */
597void
hassof390d2c2004-09-10 20:48:21 +0000598lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
599 dict_t * lspdb)
jardineb5d44e2003-12-23 08:09:43 +0000600{
601 dnode_t *dnode, *next;
602 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +0000603
jardineb5d44e2003-12-23 08:09:43 +0000604 dnode = dict_first (lspdb);
hassof390d2c2004-09-10 20:48:21 +0000605 while (dnode != NULL)
606 {
607 next = dict_next (lspdb, dnode);
608 lsp = dnode_get (dnode);
609 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
610 listnode_add (list, lsp);
611 dnode = next;
612 }
613
jardineb5d44e2003-12-23 08:09:43 +0000614 return;
615}
616
617void
618lsp_set_time (struct isis_lsp *lsp)
619{
620 assert (lsp);
hassof390d2c2004-09-10 20:48:21 +0000621
622 if (lsp->lsp_header->rem_lifetime == 0)
623 {
624 if (lsp->age_out != 0)
625 lsp->age_out--;
626 return;
627 }
jardineb5d44e2003-12-23 08:09:43 +0000628
629 /* If we are turning 0 */
630 /* ISO 10589 - 7.3.16.4 first paragraph */
631
hassof390d2c2004-09-10 20:48:21 +0000632 if (ntohs (lsp->lsp_header->rem_lifetime) == 1)
633 {
634 /* 7.3.16.4 a) set SRM flags on all */
635 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
636 /* 7.3.16.4 b) retain only the header FIXME */
637 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
638 }
jardineb5d44e2003-12-23 08:09:43 +0000639
hassof390d2c2004-09-10 20:48:21 +0000640 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +0000641 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
642}
643
644void
hassof390d2c2004-09-10 20:48:21 +0000645lspid_print (u_char * lsp_id, u_char * trg, char dynhost, char frag)
jardineb5d44e2003-12-23 08:09:43 +0000646{
647 struct isis_dynhn *dyn = NULL;
hassof390d2c2004-09-10 20:48:21 +0000648 u_char id[SYSID_STRLEN];
jardineb5d44e2003-12-23 08:09:43 +0000649
650 if (dynhost)
651 dyn = dynhn_find_by_id (lsp_id);
652 else
653 dyn = NULL;
654
655 if (dyn)
656 sprintf (id, "%.14s", dyn->name.name);
657 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
hassof390d2c2004-09-10 20:48:21 +0000658 sprintf (id, "%.14s", unix_hostname ());
jardineb5d44e2003-12-23 08:09:43 +0000659 else
hassof390d2c2004-09-10 20:48:21 +0000660 {
661 memcpy (id, sysid_print (lsp_id), 15);
662 }
663 if (frag)
664 sprintf (trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID (lsp_id),
665 LSP_FRAGMENT (lsp_id));
666 else
667 sprintf (trg, "%s.%02x", id, LSP_PSEUDO_ID (lsp_id));
jardineb5d44e2003-12-23 08:09:43 +0000668}
669
hassof390d2c2004-09-10 20:48:21 +0000670/* Convert the lsp attribute bits to attribute string */
671char *
672lsp_bits2string (u_char * lsp_bits)
673{
674 char *pos = lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000675
hassof390d2c2004-09-10 20:48:21 +0000676 if (!*lsp_bits)
jardineb5d44e2003-12-23 08:09:43 +0000677 return " none";
678
679 /* we only focus on the default metric */
680 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000681 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000682
683 pos += sprintf (pos, "%d/",
hassof390d2c2004-09-10 20:48:21 +0000684 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits) ? 1 : 0);
jardineb5d44e2003-12-23 08:09:43 +0000685
hassof390d2c2004-09-10 20:48:21 +0000686 pos += sprintf (pos, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits) ? 1 : 0);
687
jardineb5d44e2003-12-23 08:09:43 +0000688 *(pos) = '\0';
jardineb5d44e2003-12-23 08:09:43 +0000689
hassof390d2c2004-09-10 20:48:21 +0000690 return lsp_bits_string;
jardineb5d44e2003-12-23 08:09:43 +0000691}
692
693/* this function prints the lsp on show isis database */
694void
hassof390d2c2004-09-10 20:48:21 +0000695lsp_print (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000696{
hassof390d2c2004-09-10 20:48:21 +0000697 struct isis_lsp *lsp = dnode_get (node);
jardineb5d44e2003-12-23 08:09:43 +0000698 u_char LSPid[255];
699
700 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000701 vty_out (vty, "%-21s%c ", LSPid, lsp->own_lsp ? '*' : ' ');
702 vty_out (vty, "0x%08x ", ntohl (lsp->lsp_header->seq_num));
703 vty_out (vty, "0x%04x ", ntohs (lsp->lsp_header->checksum));
jardineb5d44e2003-12-23 08:09:43 +0000704
hassof390d2c2004-09-10 20:48:21 +0000705 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
706 vty_out (vty, " (%2u)", lsp->age_out);
jardineb5d44e2003-12-23 08:09:43 +0000707 else
hassof390d2c2004-09-10 20:48:21 +0000708 vty_out (vty, "%5u", ntohs (lsp->lsp_header->rem_lifetime));
jardineb5d44e2003-12-23 08:09:43 +0000709
710 vty_out (vty, " %s%s",
hassof390d2c2004-09-10 20:48:21 +0000711 lsp_bits2string (&lsp->lsp_header->lsp_bits), VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000712}
713
714void
hassof390d2c2004-09-10 20:48:21 +0000715lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000716{
717 struct isis_lsp *lsp = dnode_get (node);
718 struct area_addr *area_addr;
hassof390d2c2004-09-10 20:48:21 +0000719 char nlpidstr[2];
720 int i;
jardineb5d44e2003-12-23 08:09:43 +0000721 struct listnode *lnode;
722 struct is_neigh *is_neigh;
723 struct te_is_neigh *te_is_neigh;
724 struct ipv4_reachability *ipv4_reach;
725 struct in_addr *ipv4_addr;
726 struct te_ipv4_reachability *te_ipv4_reach;
727#ifdef HAVE_IPV6
728 struct ipv6_reachability *ipv6_reach;
729 struct in6_addr in6;
730#endif
731 u_char LSPid[255];
732 u_char hostname[255];
733 u_char buff[BUFSIZ];
hassof390d2c2004-09-10 20:48:21 +0000734 u_int32_t now, helper;
jardineb5d44e2003-12-23 08:09:43 +0000735 u_char ipv4_reach_prefix[20];
736 u_char ipv4_reach_mask[20];
737 u_char ipv4_address[20];
738
739 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
hassof390d2c2004-09-10 20:48:21 +0000740 lsp_print (node, vty, dynhost);
jardineb5d44e2003-12-23 08:09:43 +0000741
742 /* for all area address */
hassof390d2c2004-09-10 20:48:21 +0000743 if (lsp->tlv_data.area_addrs)
744 {
745 LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode)
746 {
747 vty_out (vty, " Area Address: %s%s",
748 isonet_print (area_addr->area_addr, area_addr->addr_len),
749 VTY_NEWLINE);
750 }
jardineb5d44e2003-12-23 08:09:43 +0000751 }
jardineb5d44e2003-12-23 08:09:43 +0000752
753 /* for the nlpid tlv */
hassof390d2c2004-09-10 20:48:21 +0000754 if (lsp->tlv_data.nlpids)
755 {
756 for (i = 0; i < lsp->tlv_data.nlpids->count; i++)
757 {
758 switch (lsp->tlv_data.nlpids->nlpids[i])
759 {
760 case NLPID_IP:
761 case NLPID_IPV6:
762 vty_out (vty, " NLPID: 0x%X%s",
763 lsp->tlv_data.nlpids->nlpids[i], VTY_NEWLINE);
764 break;
765 default:
766 vty_out (vty, " NLPID: %s%s", "unknown", VTY_NEWLINE);
767 break;
768 }
769 }
770 }
jardineb5d44e2003-12-23 08:09:43 +0000771
772 /* for the hostname tlv */
hassof390d2c2004-09-10 20:48:21 +0000773 if (lsp->tlv_data.hostname)
774 {
775 bzero (hostname, sizeof (hostname));
776 memcpy (hostname, lsp->tlv_data.hostname->name,
777 lsp->tlv_data.hostname->namelen);
778 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000779 }
hassof390d2c2004-09-10 20:48:21 +0000780
781 if (lsp->tlv_data.ipv4_addrs)
782 {
783 LIST_LOOP (lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode)
784 {
785 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
786 vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE);
787 }
788 }
789
jardineb5d44e2003-12-23 08:09:43 +0000790 /* for the internal reachable tlv */
791 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000792 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
793 {
794 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
795 sizeof (ipv4_reach_prefix));
796 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
797 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000798 vty_out (vty, " Metric: %d IP %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000799 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
800 ipv4_reach_mask, VTY_NEWLINE);
801 }
hasso2097cd82003-12-23 11:51:08 +0000802
803 /* for the external reachable tlv */
804 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000805 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
806 {
807 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix),
808 sizeof (ipv4_reach_prefix));
809 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask),
810 sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000811 vty_out (vty, " Metric: %d IP-External %s %s%s",
hassof390d2c2004-09-10 20:48:21 +0000812 ipv4_reach->metrics.metric_default, ipv4_reach_prefix,
813 ipv4_reach_mask, VTY_NEWLINE);
814 }
jardineb5d44e2003-12-23 08:09:43 +0000815
816 /* for the IS neighbor tlv */
hassof390d2c2004-09-10 20:48:21 +0000817 if (lsp->tlv_data.is_neighs)
818 {
819 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
820 {
821 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
822 vty_out (vty, " Metric: %d IS %s%s",
823 is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE);
824 }
jardineb5d44e2003-12-23 08:09:43 +0000825 }
jardineb5d44e2003-12-23 08:09:43 +0000826
hasso2097cd82003-12-23 11:51:08 +0000827 /* IPv6 tlv */
828#ifdef HAVE_IPV6
829 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000830 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
831 {
832 memset (&in6, 0, sizeof (in6));
833 memcpy (in6.s6_addr, ipv6_reach->prefix,
834 PSIZE (ipv6_reach->prefix_len));
hasso2097cd82003-12-23 11:51:08 +0000835 inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
836 if ((ipv6_reach->control_info &&
hassof390d2c2004-09-10 20:48:21 +0000837 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
838 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
839 ntohl (ipv6_reach->metric),
840 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000841 else
hassof390d2c2004-09-10 20:48:21 +0000842 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
843 ntohl (ipv6_reach->metric),
844 buff, ipv6_reach->prefix_len, VTY_NEWLINE);
hasso2097cd82003-12-23 11:51:08 +0000845 }
846#endif
847
jardineb5d44e2003-12-23 08:09:43 +0000848/* FIXME: Other tlvs such as te or external tlv will be added later */
hassof390d2c2004-09-10 20:48:21 +0000849#if 0
jardineb5d44e2003-12-23 08:09:43 +0000850 vty_out (vty, "%s %s %c%s",
hassof390d2c2004-09-10 20:48:21 +0000851 VTY_NEWLINE, LSPid, lsp->own_lsp ? '*' : ' ', VTY_NEWLINE);
jardineb5d44e2003-12-23 08:09:43 +0000852
853 vty_out (vty, " Sequence: 0x%08x Checksum: 0x%04x Lifetime: ",
854 ntohl (lsp->lsp_header->seq_num),
855 ntohs (lsp->lsp_header->checksum));
856
857 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
858 vty_out (vty, " (%2u) ", lsp->age_out);
859 else
860 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->rem_lifetime));
861
862 vty_out (vty, "%s Attributes:%s",
hassof390d2c2004-09-10 20:48:21 +0000863 VTY_NEWLINE, lsp_bits2string (&lsp->lsp_header->lsp_bits));
jardineb5d44e2003-12-23 08:09:43 +0000864
865 /* if this is a self originated LSP then print
866 * the generation time plus when we sent it last
867 * if it is a non self-originated LSP then print the
868 * time when the LSP has been installed
869 */
870
hassof390d2c2004-09-10 20:48:21 +0000871 if (lsp->own_lsp)
872 {
jardineb5d44e2003-12-23 08:09:43 +0000873
hassof390d2c2004-09-10 20:48:21 +0000874 now = time (NULL);
875 helper = now - lsp->last_generated;
876 if (!lsp->last_generated)
877 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000878
hassof390d2c2004-09-10 20:48:21 +0000879 vty_out (vty, ", Generated: %s ago", time2string (helper));
jardineb5d44e2003-12-23 08:09:43 +0000880
hassof390d2c2004-09-10 20:48:21 +0000881 now = time (NULL);
882 helper = now - lsp->last_sent;
883 if (!lsp->last_sent)
884 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000885
hassof390d2c2004-09-10 20:48:21 +0000886 vty_out (vty, ", Last sent: %s ago", time2string (helper));
887 }
888 else
889 {
890 now = time (NULL);
891 helper = now - lsp->installed;
892 if (!lsp->installed)
893 helper = 0;
jardineb5d44e2003-12-23 08:09:43 +0000894
hassof390d2c2004-09-10 20:48:21 +0000895 vty_out (vty, ", Installed: %s ago", time2string (helper));
jardineb5d44e2003-12-23 08:09:43 +0000896
hassof390d2c2004-09-10 20:48:21 +0000897 }
jardineb5d44e2003-12-23 08:09:43 +0000898
899 vty_out (vty, "%s", VTY_NEWLINE);
900
hassof390d2c2004-09-10 20:48:21 +0000901 if (lsp->tlv_data.nlpids)
902 {
903 vty_out (vty, " Speaks: %s%s", nlpid2string (lsp->tlv_data.nlpids),
904 VTY_NEWLINE);
905 }
jardineb5d44e2003-12-23 08:09:43 +0000906
hassof390d2c2004-09-10 20:48:21 +0000907 if (lsp->tlv_data.router_id)
908 {
909 vty_out (vty, " Router ID: %s%s",
910 inet_ntoa (lsp->tlv_data.router_id->id), VTY_NEWLINE);
911 }
jardineb5d44e2003-12-23 08:09:43 +0000912
913 if (lsp->tlv_data.is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000914 LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode)
915 {
916 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
917 vty_out (vty, " IS %s, Metric: %d%s",
918 LSPid, is_neigh->metrics.metric_default, VTY_NEWLINE);
919 }
jardineb5d44e2003-12-23 08:09:43 +0000920
921 if (lsp->tlv_data.te_is_neighs)
hassof390d2c2004-09-10 20:48:21 +0000922 LIST_LOOP (lsp->tlv_data.te_is_neighs, te_is_neigh, lnode)
923 {
924 /* FIXME: metric display is wrong */
925 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
926 vty_out (vty, " extd-IS %s, Metric: %d%s",
927 LSPid, te_is_neigh->te_metric[0], VTY_NEWLINE);
928 }
jardineb5d44e2003-12-23 08:09:43 +0000929
930 if (lsp->tlv_data.ipv4_int_reachs)
hassof390d2c2004-09-10 20:48:21 +0000931 LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode)
932 {
933 vty_out (vty, " int-IP %s/%d, Metric: %d%s",
934 inet_ntoa (ipv4_reach->prefix),
935 ip_masklen (ipv4_reach->mask),
936 ipv4_reach->metrics.metric_default, VTY_NEWLINE);
937 }
jardineb5d44e2003-12-23 08:09:43 +0000938
939 if (lsp->tlv_data.ipv4_ext_reachs)
hassof390d2c2004-09-10 20:48:21 +0000940 LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode)
941 {
942 vty_out (vty, " ext-IP %s/%d, Metric: %d%s",
943 inet_ntoa (ipv4_reach->prefix),
944 ip_masklen (ipv4_reach->mask),
945 ipv4_reach->metrics.metric_default, VTY_NEWLINE);
946 }
jardineb5d44e2003-12-23 08:09:43 +0000947
948 if (lsp->tlv_data.te_ipv4_reachs)
hassof390d2c2004-09-10 20:48:21 +0000949 LIST_LOOP (lsp->tlv_data.te_ipv4_reachs, te_ipv4_reach, lnode)
950 {
951 vty_out (vty, " extd-IP %s/%d, Metric: %d%s",
952 inet_ntoa (newprefix2inaddr (&te_ipv4_reach->prefix_start,
953 te_ipv4_reach->control)),
954 te_ipv4_reach->control & 0x3F,
955 ntohl (te_ipv4_reach->te_metric), VTY_NEWLINE);
956 }
jardineb5d44e2003-12-23 08:09:43 +0000957
958#ifdef HAVE_IPV6
959 if (lsp->tlv_data.ipv6_reachs)
hassof390d2c2004-09-10 20:48:21 +0000960 LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode)
961 {
962 memcpy (in6.s6_addr, ipv6_reach->prefix, 16);
963 inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
964 if ((ipv6_reach->control_info &&
965 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
966 vty_out (vty, " int-IPv6 %s/%d, Metric: %d%s",
967 buff,
968 ipv6_reach->prefix_len,
969 ntohl (ipv6_reach->metric), VTY_NEWLINE);
970 else
971 vty_out (vty, " ext-IPv6 %s/%d, Metric: %d%s",
972 buff,
973 ipv6_reach->prefix_len,
974 ntohl (ipv6_reach->metric), VTY_NEWLINE);
975
976 }
jardineb5d44e2003-12-23 08:09:43 +0000977#endif
hassof390d2c2004-09-10 20:48:21 +0000978 if (lsp->tlv_data.hostname)
979 {
980 memset (hostname, 0, sizeof (hostname));
981 memcpy (hostname, lsp->tlv_data.hostname->name,
982 lsp->tlv_data.hostname->namelen);
983 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
984 }
jardineb5d44e2003-12-23 08:09:43 +0000985#endif
hassof390d2c2004-09-10 20:48:21 +0000986 return;
jardineb5d44e2003-12-23 08:09:43 +0000987}
988
989/* print all the lsps info in the local lspdb */
hassof390d2c2004-09-10 20:48:21 +0000990int
991lsp_print_all (struct vty *vty, dict_t * lspdb, char detail, char dynhost)
jardineb5d44e2003-12-23 08:09:43 +0000992{
993
hassof390d2c2004-09-10 20:48:21 +0000994 dnode_t *node = dict_first (lspdb), *next;
jardineb5d44e2003-12-23 08:09:43 +0000995 int lsp_count = 0;
996
997 /* print the title, for both modes */
998 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
hassof390d2c2004-09-10 20:48:21 +0000999 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
1000
1001 if (detail == ISIS_UI_LEVEL_BRIEF)
1002 {
1003 while (node != NULL)
1004 {
1005 /* I think it is unnecessary, so I comment it out */
1006 /* dict_contains (lspdb, node); */
1007 next = dict_next (lspdb, node);
1008 lsp_print (node, vty, dynhost);
1009 node = next;
1010 lsp_count++;
1011 }
jardineb5d44e2003-12-23 08:09:43 +00001012 }
hassof390d2c2004-09-10 20:48:21 +00001013 else if (detail == ISIS_UI_LEVEL_DETAIL)
1014 {
1015 while (node != NULL)
1016 {
1017 next = dict_next (lspdb, node);
1018 lsp_print_detail (node, vty, dynhost);
1019 node = next;
1020 lsp_count++;
1021 }
jardineb5d44e2003-12-23 08:09:43 +00001022 }
jardineb5d44e2003-12-23 08:09:43 +00001023
1024 return lsp_count;
1025}
1026
1027/* this function reallocate memory to an lsp pdu, with an additional
1028 * size of memory, it scans the lsp and moves all pointers the
1029 * way they should */
1030u_char *
hassof390d2c2004-09-10 20:48:21 +00001031lsppdu_realloc (struct isis_lsp * lsp, int memorytype, int size)
jardineb5d44e2003-12-23 08:09:43 +00001032{
1033 u_char *retval;
hassof390d2c2004-09-10 20:48:21 +00001034
1035 retval = STREAM_DATA (lsp->pdu) + ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00001036#ifdef LSP_MEMORY_PREASSIGN
hassof390d2c2004-09-10 20:48:21 +00001037 lsp->lsp_header->pdu_len = htons (ntohs (lsp->lsp_header->pdu_len) + size);
jardineb5d44e2003-12-23 08:09:43 +00001038 return retval;
hassof390d2c2004-09-10 20:48:21 +00001039#else /* otherwise we have to move all pointers */
jardineb5d44e2003-12-23 08:09:43 +00001040 u_char *newpdu;
1041 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
hassof390d2c2004-09-10 20:48:21 +00001042 memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu),
1043 ntohs (lsp->lsp_header->pdu_len));
jardineb5d44e2003-12-23 08:09:43 +00001044 XFREE (memorytype, lsp->pdu);
1045 lsp->pdu = newpdu;
hassof390d2c2004-09-10 20:48:21 +00001046 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
1047 lsp->lsp_header = (struct isis_link_state_hdr *)
1048 (STREAM_DATA (lsp->pdu) + ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001049 htons (ntohs (lsp->lsp_header->pdu_len) += size);
hassof390d2c2004-09-10 20:48:21 +00001050 return STREAM_DATA (lsp->pdu) + (lsp->lsp_header->pdu_len - size);
jardineb5d44e2003-12-23 08:09:43 +00001051#endif /* LSP_MEMORY_PREASSIGN */
1052}
1053
hassof390d2c2004-09-10 20:48:21 +00001054#if 0 /* Saving the old one just in case :) */
jardineb5d44e2003-12-23 08:09:43 +00001055/*
1056 * Builds the lsp->tlv_data
1057 * and writes the tlvs into lsp->pdu
1058 */
1059void
1060lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1061{
1062 struct is_neigh *is_neigh;
1063 struct listnode *node, *ipnode;
1064 int level = lsp->level;
1065 struct isis_circuit *circuit;
1066 struct prefix_ipv4 *ipv4;
1067 struct ipv4_reachability *ipreach;
1068 struct isis_adjacency *nei;
1069#ifdef HAVE_IPV6
1070 struct prefix_ipv6 *ipv6;
1071 struct ipv6_reachability *ip6reach;
1072#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001073
jardineb5d44e2003-12-23 08:09:43 +00001074 /*
1075 * First add the tlvs related to area
1076 */
hassof390d2c2004-09-10 20:48:21 +00001077
jardineb5d44e2003-12-23 08:09:43 +00001078 /* Area addresses */
1079 if (lsp->tlv_data.area_addrs == NULL)
1080 lsp->tlv_data.area_addrs = list_new ();
1081 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1082 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001083 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001084#ifdef HAVE_IPV6
1085 || area->ipv6_circuits > 0
1086#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001087 )
jardineb5d44e2003-12-23 08:09:43 +00001088 {
1089 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1090 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001091 if (area->ip_circuits > 0)
1092 {
1093 lsp->tlv_data.nlpids->count++;
1094 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1095 }
jardineb5d44e2003-12-23 08:09:43 +00001096#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001097 if (area->ipv6_circuits > 0)
1098 {
1099 lsp->tlv_data.nlpids->count++;
1100 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1101 NLPID_IPV6;
1102 }
jardineb5d44e2003-12-23 08:09:43 +00001103#endif /* HAVE_IPV6 */
1104 }
1105 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001106 if (area->dynhostname)
1107 {
1108 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1109 sizeof (struct hostname));
1110 memcpy (&lsp->tlv_data.hostname->name, unix_hostname (),
1111 strlen (unix_hostname ()));
1112 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1113 }
jardineb5d44e2003-12-23 08:09:43 +00001114#ifdef TOPOLOGY_GENERATE
1115 /*
1116 * If we have a topology in this area, we need to connect this lsp to
1117 * the first topology lsp
1118 */
hassof390d2c2004-09-10 20:48:21 +00001119 if ((area->topology) && (level == 1))
1120 {
1121 if (lsp->tlv_data.is_neighs == NULL)
1122 lsp->tlv_data.is_neighs = list_new ();
1123 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1124 memset (is_neigh, 0, sizeof (struct is_neigh));
1125 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1126 /* connected to the first */
1127 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (0x01);
1128 /* this is actually the same system, why mess the SPT */
1129 is_neigh->metrics.metric_default = 0;
1130 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1131 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1132 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1133 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001134
hassof390d2c2004-09-10 20:48:21 +00001135 }
jardineb5d44e2003-12-23 08:09:43 +00001136#endif
1137
1138 /*
1139 * Then add tlvs related to circuits
1140 */
hassof390d2c2004-09-10 20:48:21 +00001141 for (node = listhead (area->circuit_list); node; nextnode (node))
1142 {
1143 circuit = getdata (node);
1144 if (circuit->state != C_STATE_UP)
1145 continue;
1146
1147 /*
1148 * Add IPv4 internal reachability of this circuit
1149 */
1150 if (circuit->ip_router && circuit->ip_addrs &&
1151 circuit->ip_addrs->count > 0)
1152 {
1153 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1154 {
1155 lsp->tlv_data.ipv4_int_reachs = list_new ();
1156 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1157 }
1158 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1159 nextnode (ipnode))
1160 {
1161 ipv4 = getdata (ipnode);
1162 ipreach =
1163 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1164 ipreach->metrics = circuit->metrics[level - 1];
1165 ipreach->prefix = ipv4->prefix;
1166 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1167 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1168 }
1169 }
jardineb5d44e2003-12-23 08:09:43 +00001170#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001171 /*
1172 * Add IPv6 reachability of this circuit
1173 */
1174 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1175 circuit->ipv6_non_link->count > 0)
1176 {
1177 if (lsp->tlv_data.ipv6_reachs == NULL)
1178 {
1179 lsp->tlv_data.ipv6_reachs = list_new ();
1180 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1181 }
1182 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1183 nextnode (ipnode))
1184 {
1185 ipv6 = getdata (ipnode);
1186 ip6reach =
1187 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1188 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1189 ip6reach->metric =
1190 htonl (circuit->metrics[level - 1].metric_default);
1191 ip6reach->control_info = 0;
1192 ip6reach->prefix_len = ipv6->prefixlen;
1193 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1194 (ipv6->prefixlen + 7) / 8);
1195 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1196 }
1197 }
jardineb5d44e2003-12-23 08:09:43 +00001198#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001199
1200 switch (circuit->circ_type)
1201 {
1202 case CIRCUIT_T_BROADCAST:
1203 if (level & circuit->circuit_is_type)
1204 {
1205 if (lsp->tlv_data.is_neighs == NULL)
1206 {
1207 lsp->tlv_data.is_neighs = list_new ();
1208 lsp->tlv_data.is_neighs->del = free_tlv;
1209 }
1210 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1211 memset (is_neigh, 0, sizeof (struct is_neigh));
1212 if (level == 1)
1213 memcpy (&is_neigh->neigh_id,
1214 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1215 else
1216 memcpy (&is_neigh->neigh_id,
1217 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1218 is_neigh->metrics = circuit->metrics[level - 1];
1219 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1220 }
1221 break;
1222 case CIRCUIT_T_P2P:
1223 nei = circuit->u.p2p.neighbor;
1224 if (nei && (level & nei->circuit_t))
1225 {
1226 if (lsp->tlv_data.is_neighs == NULL)
1227 {
1228 lsp->tlv_data.is_neighs = list_new ();
1229 lsp->tlv_data.is_neighs->del = free_tlv;
1230 }
1231 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1232 memset (is_neigh, 0, sizeof (struct is_neigh));
1233 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1234 is_neigh->metrics = circuit->metrics[level - 1];
1235 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1236 }
1237 break;
1238 case CIRCUIT_T_STATIC_IN:
1239 zlog_warn ("lsp_area_create: unsupported circuit type");
1240 break;
1241 case CIRCUIT_T_STATIC_OUT:
1242 zlog_warn ("lsp_area_create: unsupported circuit type");
1243 break;
1244 case CIRCUIT_T_DA:
1245 zlog_warn ("lsp_area_create: unsupported circuit type");
1246 break;
1247 default:
1248 zlog_warn ("lsp_area_create: unknown circuit type");
1249 }
jardineb5d44e2003-12-23 08:09:43 +00001250 }
hassof390d2c2004-09-10 20:48:21 +00001251
jardineb5d44e2003-12-23 08:09:43 +00001252 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00001253
jardineb5d44e2003-12-23 08:09:43 +00001254 if (lsp->tlv_data.nlpids)
1255 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1256 if (lsp->tlv_data.hostname)
1257 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001258 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001259 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1260 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1261 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001262 if (lsp->tlv_data.ipv4_int_reachs &&
jardineb5d44e2003-12-23 08:09:43 +00001263 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1264 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001265#ifdef HAVE_IPV6
1266 if (lsp->tlv_data.ipv6_reachs && listcount (lsp->tlv_data.ipv6_reachs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001267 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1268#endif /* HAVE_IPV6 */
1269
1270 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1271
1272 return;
1273}
1274#endif
1275
1276#define FRAG_THOLD(S,T) \
1277((STREAM_SIZE(S)*T)/100)
1278
1279/* stream*, area->lsp_frag_threshold, increment */
1280#define FRAG_NEEDED(S,T,I) \
1281 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1282
1283void
1284lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
hassof390d2c2004-09-10 20:48:21 +00001285 int tlvsize, int frag_thold,
1286 int tlv_build_func (struct list *, struct stream *))
jardineb5d44e2003-12-23 08:09:43 +00001287{
1288 int count, i;
hassof390d2c2004-09-10 20:48:21 +00001289
jardineb5d44e2003-12-23 08:09:43 +00001290 /* can we fit all ? */
hassof390d2c2004-09-10 20:48:21 +00001291 if (!FRAG_NEEDED (lsp->pdu, frag_thold, listcount (*from) * tlvsize + 2))
1292 {
1293 tlv_build_func (*from, lsp->pdu);
1294 *to = *from;
1295 *from = NULL;
jardineb5d44e2003-12-23 08:09:43 +00001296 }
hassof390d2c2004-09-10 20:48:21 +00001297 else if (!FRAG_NEEDED (lsp->pdu, frag_thold, tlvsize + 2))
1298 {
1299 /* fit all we can */
1300 count = FRAG_THOLD (lsp->pdu, frag_thold) - 2 -
1301 (STREAM_SIZE (lsp->pdu) - STREAM_REMAIN (lsp->pdu));
1302 if (count)
1303 count = count / tlvsize;
1304 for (i = 0; i < count; i++)
1305 {
1306 listnode_add (*to, getdata (listhead (*from)));
1307 listnode_delete (*from, getdata (listhead (*from)));
1308 }
1309 tlv_build_func (*to, lsp->pdu);
1310 }
1311 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
jardineb5d44e2003-12-23 08:09:43 +00001312 return;
1313}
1314
hassof390d2c2004-09-10 20:48:21 +00001315struct isis_lsp *
1316lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1317 int level)
jardineb5d44e2003-12-23 08:09:43 +00001318{
1319 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00001320 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1321
jardineb5d44e2003-12-23 08:09:43 +00001322 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1323 LSP_FRAGMENT (frag_id) = frag_num;
1324 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00001325 if (lsp)
1326 {
1327 /*
1328 * Clear the TLVs, but inherit the authinfo
1329 */
1330 lsp_clear_data (lsp);
1331 if (lsp0->tlv_data.auth_info.type)
1332 {
1333 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1334 sizeof (struct isis_passwd));
1335 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1336 lsp->tlv_data.auth_info.len,
1337 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1338 }
1339 return lsp;
jardineb5d44e2003-12-23 08:09:43 +00001340 }
jardineb5d44e2003-12-23 08:09:43 +00001341 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
hassof390d2c2004-09-10 20:48:21 +00001342 0, level);
jardineb5d44e2003-12-23 08:09:43 +00001343 lsp->own_lsp = 1;
hassof390d2c2004-09-10 20:48:21 +00001344 lsp_insert (lsp, area->lspdb[level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00001345 listnode_add (lsp0->lspu.frags, lsp);
1346 lsp->lspu.zero_lsp = lsp0;
1347 /*
1348 * Copy the authinfo from zero LSP
1349 */
hassof390d2c2004-09-10 20:48:21 +00001350 if (lsp0->tlv_data.auth_info.type)
1351 {
1352 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1353 sizeof (struct isis_passwd));
1354 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1355 lsp->tlv_data.auth_info.len,
1356 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1357 }
jardineb5d44e2003-12-23 08:09:43 +00001358 return lsp;
1359}
1360
1361/*
1362 * Builds the LSP data part. This func creates a new frag whenever
1363 * area->lsp_frag_threshold is exceeded.
1364 */
1365#if 1
1366void
1367lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1368{
1369 struct is_neigh *is_neigh;
1370 struct listnode *node, *ipnode;
1371 int level = lsp->level;
1372 struct isis_circuit *circuit;
1373 struct prefix_ipv4 *ipv4;
1374 struct ipv4_reachability *ipreach;
1375 struct isis_adjacency *nei;
1376#ifdef HAVE_IPV6
hasso67851572004-09-21 14:17:04 +00001377 struct prefix_ipv6 *ipv6, *ip6prefix;
jardineb5d44e2003-12-23 08:09:43 +00001378 struct ipv6_reachability *ip6reach;
1379#endif /* HAVE_IPV6 */
1380 struct tlvs tlv_data;
1381 struct isis_lsp *lsp0 = lsp;
1382 struct isis_passwd *passwd;
1383
1384 /*
1385 * First add the tlvs related to area
1386 */
hassof390d2c2004-09-10 20:48:21 +00001387
jardineb5d44e2003-12-23 08:09:43 +00001388 /* Area addresses */
1389 if (lsp->tlv_data.area_addrs == NULL)
1390 lsp->tlv_data.area_addrs = list_new ();
1391 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1392 /* Protocols Supported */
hassof390d2c2004-09-10 20:48:21 +00001393 if (area->ip_circuits > 0
jardineb5d44e2003-12-23 08:09:43 +00001394#ifdef HAVE_IPV6
1395 || area->ipv6_circuits > 0
1396#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001397 )
jardineb5d44e2003-12-23 08:09:43 +00001398 {
1399 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1400 lsp->tlv_data.nlpids->count = 0;
hassof390d2c2004-09-10 20:48:21 +00001401 if (area->ip_circuits > 0)
1402 {
1403 lsp->tlv_data.nlpids->count++;
1404 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1405 }
jardineb5d44e2003-12-23 08:09:43 +00001406#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001407 if (area->ipv6_circuits > 0)
1408 {
1409 lsp->tlv_data.nlpids->count++;
1410 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1411 NLPID_IPV6;
1412 }
jardineb5d44e2003-12-23 08:09:43 +00001413#endif /* HAVE_IPV6 */
1414 }
1415 /* Dynamic Hostname */
hassof390d2c2004-09-10 20:48:21 +00001416 if (area->dynhostname)
1417 {
1418 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1419 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001420
hassof390d2c2004-09-10 20:48:21 +00001421 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1422 strlen (unix_hostname ()));
1423 lsp->tlv_data.hostname->namelen = strlen (unix_hostname ());
1424 }
jardineb5d44e2003-12-23 08:09:43 +00001425
1426 /*
1427 * Building the zero lsp
1428 */
hassof390d2c2004-09-10 20:48:21 +00001429 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00001430 /*
1431 * Add the authentication info if its present
1432 */
hassof390d2c2004-09-10 20:48:21 +00001433 (level == 1) ? (passwd = &area->area_passwd) :
1434 (passwd = &area->domain_passwd);
1435 if (passwd->type)
1436 {
1437 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1438 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
1439 }
jardineb5d44e2003-12-23 08:09:43 +00001440 if (lsp->tlv_data.nlpids)
1441 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1442 if (lsp->tlv_data.hostname)
1443 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001444 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0)
jardineb5d44e2003-12-23 08:09:43 +00001445 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
hassof390d2c2004-09-10 20:48:21 +00001446
jardineb5d44e2003-12-23 08:09:43 +00001447 memset (&tlv_data, 0, sizeof (struct tlvs));
1448 /*
1449 * Then build lists of tlvs related to circuits
1450 */
hassof390d2c2004-09-10 20:48:21 +00001451 for (node = listhead (area->circuit_list); node; nextnode (node))
1452 {
1453 circuit = getdata (node);
1454 if (circuit->state != C_STATE_UP)
1455 continue;
jardineb5d44e2003-12-23 08:09:43 +00001456
hassof390d2c2004-09-10 20:48:21 +00001457 /*
1458 * Add IPv4 internal reachability of this circuit
1459 */
1460 if (circuit->ip_router && circuit->ip_addrs &&
1461 circuit->ip_addrs->count > 0)
1462 {
1463 if (tlv_data.ipv4_int_reachs == NULL)
1464 {
1465 tlv_data.ipv4_int_reachs = list_new ();
1466 }
1467 for (ipnode = listhead (circuit->ip_addrs); ipnode;
1468 nextnode (ipnode))
1469 {
1470 ipv4 = getdata (ipnode);
1471 ipreach =
1472 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1473 ipreach->metrics = circuit->metrics[level - 1];
hassof390d2c2004-09-10 20:48:21 +00001474 masklen2ip (ipv4->prefixlen, &ipreach->mask);
hasso67851572004-09-21 14:17:04 +00001475 ipreach->prefix.s_addr = ((ipreach->mask.s_addr) &
1476 (ipv4->prefix.s_addr));
hassof390d2c2004-09-10 20:48:21 +00001477 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1478 }
1479
1480 }
jardineb5d44e2003-12-23 08:09:43 +00001481#ifdef HAVE_IPV6
hassof390d2c2004-09-10 20:48:21 +00001482 /*
1483 * Add IPv6 reachability of this circuit
1484 */
1485 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1486 circuit->ipv6_non_link->count > 0)
1487 {
1488
1489 if (tlv_data.ipv6_reachs == NULL)
1490 {
1491 tlv_data.ipv6_reachs = list_new ();
1492 }
1493 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1494 nextnode (ipnode))
1495 {
1496 ipv6 = getdata (ipnode);
1497 ip6reach =
1498 XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1499 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1500 ip6reach->metric =
1501 htonl (circuit->metrics[level - 1].metric_default);
1502 ip6reach->control_info = 0;
1503 ip6reach->prefix_len = ipv6->prefixlen;
hasso67851572004-09-21 14:17:04 +00001504 memcpy (&ip6prefix, &ipv6, sizeof(ip6prefix));
1505 apply_mask_ipv6 (ip6prefix);
1506 memcpy (ip6reach->prefix, ip6prefix->prefix.s6_addr,
1507 sizeof (ip6reach->prefix));
hassof390d2c2004-09-10 20:48:21 +00001508 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1509 }
1510 }
1511#endif /* HAVE_IPV6 */
1512
1513 switch (circuit->circ_type)
1514 {
1515 case CIRCUIT_T_BROADCAST:
1516 if (level & circuit->circuit_is_type)
1517 {
1518 if (tlv_data.is_neighs == NULL)
1519 {
1520 tlv_data.is_neighs = list_new ();
1521 }
1522 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1523 memset (is_neigh, 0, sizeof (struct is_neigh));
1524 if (level == 1)
1525 memcpy (is_neigh->neigh_id,
1526 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1527 else
1528 memcpy (is_neigh->neigh_id,
1529 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1530 is_neigh->metrics = circuit->metrics[level - 1];
1531 listnode_add (tlv_data.is_neighs, is_neigh);
1532 }
1533 break;
1534 case CIRCUIT_T_P2P:
1535 nei = circuit->u.p2p.neighbor;
1536 if (nei && (level & nei->circuit_t))
1537 {
1538 if (tlv_data.is_neighs == NULL)
1539 {
1540 tlv_data.is_neighs = list_new ();
1541 tlv_data.is_neighs->del = free_tlv;
1542 }
1543 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1544 memset (is_neigh, 0, sizeof (struct is_neigh));
1545 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1546 is_neigh->metrics = circuit->metrics[level - 1];
1547 listnode_add (tlv_data.is_neighs, is_neigh);
1548 }
1549 break;
1550 case CIRCUIT_T_STATIC_IN:
1551 zlog_warn ("lsp_area_create: unsupported circuit type");
1552 break;
1553 case CIRCUIT_T_STATIC_OUT:
1554 zlog_warn ("lsp_area_create: unsupported circuit type");
1555 break;
1556 case CIRCUIT_T_DA:
1557 zlog_warn ("lsp_area_create: unsupported circuit type");
1558 break;
1559 default:
1560 zlog_warn ("lsp_area_create: unknown circuit type");
1561 }
1562 }
1563
1564 while (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1565 {
1566 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1567 lsp->tlv_data.ipv4_int_reachs = list_new ();
1568 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1569 &lsp->tlv_data.ipv4_int_reachs,
1570 IPV4_REACH_LEN, area->lsp_frag_threshold,
1571 tlv_add_ipv4_reachs);
1572 if (tlv_data.ipv4_int_reachs && listcount (tlv_data.ipv4_int_reachs))
1573 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1574 lsp0, area, level);
1575 }
1576
1577#ifdef HAVE_IPV6
1578 while (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1579 {
1580 if (lsp->tlv_data.ipv6_reachs == NULL)
1581 lsp->tlv_data.ipv6_reachs = list_new ();
1582 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1583 &lsp->tlv_data.ipv6_reachs,
1584 IPV6_REACH_LEN, area->lsp_frag_threshold,
1585 tlv_add_ipv6_reachs);
1586 if (tlv_data.ipv6_reachs && listcount (tlv_data.ipv6_reachs))
1587 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1588 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001589 }
1590#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +00001591
1592 while (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1593 {
1594 if (lsp->tlv_data.is_neighs == NULL)
1595 lsp->tlv_data.is_neighs = list_new ();
1596 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1597 &lsp->tlv_data.is_neighs,
1598 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1599 tlv_add_is_neighs);
1600 if (tlv_data.is_neighs && listcount (tlv_data.is_neighs))
1601 lsp = lsp_next_frag (LSP_FRAGMENT (lsp->lsp_header->lsp_id) + 1,
1602 lsp0, area, level);
jardineb5d44e2003-12-23 08:09:43 +00001603 }
jardineb5d44e2003-12-23 08:09:43 +00001604
jardineb5d44e2003-12-23 08:09:43 +00001605 return;
1606}
1607#endif
1608
1609void
1610build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1611{
1612 struct list *circuit_list = area->circuit_list;
1613 struct isis_circuit *circuit;
1614 u_char *tlv_ptr;
1615 struct is_neigh *is_neigh;
1616
hassof390d2c2004-09-10 20:48:21 +00001617
jardineb5d44e2003-12-23 08:09:43 +00001618 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00001619 /* the 2 is for the TL plus 1 for the nlpid */
1620 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1621 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1622 *(tlv_ptr + 1) = 1; /* one protocol */
1623#ifdef HAVE_IPV6 /*dunno if its right */
1624 *(tlv_ptr + 2) = NLPID_IPV6;
jardineb5d44e2003-12-23 08:09:43 +00001625#else
hassof390d2c2004-09-10 20:48:21 +00001626 *(tlv_ptr + 2) = NLPID_IP;
jardineb5d44e2003-12-23 08:09:43 +00001627#endif /* HAVE_IPV6 */
1628
1629 /* we should add our areas here
1630 * FIXME: we need to figure out which should be added? Adj? All? First? */
1631
1632 /* first, lets add ourselves to the IS neighbours info */
hassof390d2c2004-09-10 20:48:21 +00001633 /* the 2 is for the TL plus 1 for the virtual field */
1634 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
1635 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1636 *(tlv_ptr + 2) = 0; /* virtual is zero */
1637 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00001638 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00001639 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1640 sizeof (struct is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00001641 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00001642 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
jardineb5d44e2003-12-23 08:09:43 +00001643 /* FIXME: Do we need our designated address here? */
hassof390d2c2004-09-10 20:48:21 +00001644 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
jardineb5d44e2003-12-23 08:09:43 +00001645 /* FIXME: Where should we really get our own LSPs metrics from? */
hassof390d2c2004-09-10 20:48:21 +00001646 circuit = (struct isis_circuit *) listhead (circuit_list);
1647 /* is_neigh->metrics = circuit->metrics[lsp->level -1]; */
jardineb5d44e2003-12-23 08:09:43 +00001648 /* Length */
hassof390d2c2004-09-10 20:48:21 +00001649 *(tlv_ptr + 1) =
1650 (lsp->tlv_data.is_neighs->count * sizeof (struct is_neigh) + 1);
jardineb5d44e2003-12-23 08:09:43 +00001651
1652 /* FIXME: scan for adjencecies and add them */
1653
1654 /* FIXME: add reachability info */
1655
hassof390d2c2004-09-10 20:48:21 +00001656 /* adding dynamic hostname if needed */
1657 if (area->dynhostname)
1658 {
1659 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1660 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
1661 *(tlv_ptr + 1) = strlen (unix_hostname ()); /* Length */
1662 lsp->tlv_data.hostname = (struct hostname *)
1663 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
1664 /* the -1 is to fit the length in the struct */
1665 strlen (unix_hostname ())) - 1);
1666 memcpy (lsp->tlv_data.hostname->name, unix_hostname (),
1667 strlen (unix_hostname ()));
1668 }
jardineb5d44e2003-12-23 08:09:43 +00001669
1670}
1671
1672/*
1673 * 7.3.7 Generation on non-pseudonode LSPs
1674 */
1675int
hassof390d2c2004-09-10 20:48:21 +00001676lsp_generate_non_pseudo (struct isis_area *area, int level)
1677{
jardineb5d44e2003-12-23 08:09:43 +00001678 struct isis_lsp *oldlsp, *newlsp;
1679 u_int32_t seq_num = 0;
1680 u_char lspid[ISIS_SYS_ID_LEN + 2];
1681
1682 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1683 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1684
1685 /* only builds the lsp if the area shares the level */
hassof390d2c2004-09-10 20:48:21 +00001686 if ((area->is_type & level) == level)
1687 {
1688 oldlsp = lsp_search (lspid, area->lspdb[level - 1]);
1689 if (oldlsp)
1690 {
1691 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1692 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1693 area->lspdb[level - 1]);
1694 /* FIXME: we should actually initiate a purge */
1695 }
1696 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level - 1], seq_num,
1697 area->is_type, 0, level);
1698 newlsp->own_lsp = 1;
jardineb5d44e2003-12-23 08:09:43 +00001699
hassof390d2c2004-09-10 20:48:21 +00001700 lsp_insert (newlsp, area->lspdb[level - 1]);
1701 /* build_lsp_data (newlsp, area); */
1702 lsp_build_nonpseudo (newlsp, area);
1703 /* time to calculate our checksum */
1704 lsp_seqnum_update (newlsp);
1705 }
jardineb5d44e2003-12-23 08:09:43 +00001706
1707 /* DEBUG_ADJ_PACKETS */
hassof390d2c2004-09-10 20:48:21 +00001708 if (isis->debugs & DEBUG_ADJ_PACKETS)
1709 {
1710 /* FIXME: is this place right? fix missing info */
1711 zlog_info ("ISIS-Upd (%s): Building L%d LSP", area->area_tag, level);
1712 }
jardineb5d44e2003-12-23 08:09:43 +00001713
1714 return ISIS_OK;
1715}
1716
1717/*
1718 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1719 */
1720int
1721lsp_l1_generate (struct isis_area *area)
1722{
hassof390d2c2004-09-10 20:48:21 +00001723 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1724 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001725
1726 return lsp_generate_non_pseudo (area, 1);
1727}
1728
jardineb5d44e2003-12-23 08:09:43 +00001729/*
1730 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1731 */
1732int
1733lsp_l2_generate (struct isis_area *area)
1734{
hassof390d2c2004-09-10 20:48:21 +00001735 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1736 MAX_LSP_GEN_INTERVAL);
jardineb5d44e2003-12-23 08:09:43 +00001737
1738 return lsp_generate_non_pseudo (area, 2);
1739}
1740
1741int
1742lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1743{
1744 dict_t *lspdb = area->lspdb[level - 1];
1745 struct isis_lsp *lsp, *frag;
1746 struct listnode *node;
1747 u_char lspid[ISIS_SYS_ID_LEN + 2];
1748
1749 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1750 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00001751
jardineb5d44e2003-12-23 08:09:43 +00001752 lsp = lsp_search (lspid, lspdb);
jardineb5d44e2003-12-23 08:09:43 +00001753
hassof390d2c2004-09-10 20:48:21 +00001754 if (!lsp)
1755 {
1756 zlog_err
1757 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1758 area->area_tag, level);
jardineb5d44e2003-12-23 08:09:43 +00001759
hassof390d2c2004-09-10 20:48:21 +00001760 return ISIS_ERROR;
1761 }
1762
1763 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00001764 lsp_build_nonpseudo (lsp, area);
hassof390d2c2004-09-10 20:48:21 +00001765 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1766 (area->max_lsp_lifetime[level - 1],
1767 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001768 lsp_seqnum_update (lsp);
hassof390d2c2004-09-10 20:48:21 +00001769
1770 if (isis->debugs & DEBUG_UPDATE_PACKETS)
1771 {
1772 zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1773 "seq 0x%08x, cksum 0x%04x lifetime %us",
1774 area->area_tag,
1775 level,
1776 rawlspid_print (lsp->lsp_header->lsp_id),
1777 ntohl (lsp->lsp_header->seq_num),
1778 ntohs (lsp->lsp_header->checksum),
1779 ntohs (lsp->lsp_header->rem_lifetime));
1780 }
jardineb5d44e2003-12-23 08:09:43 +00001781
1782 lsp->last_generated = time (NULL);
1783 area->lsp_regenerate_pending[level - 1] = 0;
1784 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00001785 for (node = listhead (lsp->lspu.frags); node; nextnode (node))
1786 {
1787 frag = getdata (node);
1788 frag->lsp_header->rem_lifetime = htons (isis_jitter
1789 (area->
1790 max_lsp_lifetime[level - 1],
1791 MAX_AGE_JITTER));
1792 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1793 }
jardineb5d44e2003-12-23 08:09:43 +00001794
1795 if (area->ip_circuits)
1796 isis_spf_schedule (area, level);
1797#ifdef HAVE_IPV6
1798 if (area->ipv6_circuits)
1799 isis_spf_schedule6 (area, level);
1800#endif
1801 return ISIS_OK;
1802}
1803
jardineb5d44e2003-12-23 08:09:43 +00001804/*
1805 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1806 * time and set SRM
1807 */
hassof390d2c2004-09-10 20:48:21 +00001808int
jardineb5d44e2003-12-23 08:09:43 +00001809lsp_refresh_l1 (struct thread *thread)
1810{
1811 struct isis_area *area;
1812 unsigned long ref_time;
1813
1814 area = THREAD_ARG (thread);
1815 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001816
jardineb5d44e2003-12-23 08:09:43 +00001817 area->t_lsp_refresh[0] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001818 if (area->is_type & IS_LEVEL_1)
jardineb5d44e2003-12-23 08:09:43 +00001819 lsp_non_pseudo_regenerate (area, 1);
hassof390d2c2004-09-10 20:48:21 +00001820
1821 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001822 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1823
hassof390d2c2004-09-10 20:48:21 +00001824 THREAD_TIMER_ON (master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1825 isis_jitter (ref_time, MAX_AGE_JITTER));
hassod70f99e2004-02-11 20:26:31 +00001826
jardineb5d44e2003-12-23 08:09:43 +00001827 return ISIS_OK;
1828}
1829
hassof390d2c2004-09-10 20:48:21 +00001830int
jardineb5d44e2003-12-23 08:09:43 +00001831lsp_refresh_l2 (struct thread *thread)
1832{
1833 struct isis_area *area;
1834 unsigned long ref_time;
1835
1836 area = THREAD_ARG (thread);
1837 assert (area);
hassof390d2c2004-09-10 20:48:21 +00001838
jardineb5d44e2003-12-23 08:09:43 +00001839 area->t_lsp_refresh[1] = NULL;
hassof390d2c2004-09-10 20:48:21 +00001840 if (area->is_type & IS_LEVEL_2)
jardineb5d44e2003-12-23 08:09:43 +00001841 lsp_non_pseudo_regenerate (area, 2);
1842
hassof390d2c2004-09-10 20:48:21 +00001843 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00001844 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1845
hassof390d2c2004-09-10 20:48:21 +00001846 THREAD_TIMER_ON (master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1847 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001848
jardineb5d44e2003-12-23 08:09:43 +00001849 return ISIS_OK;
1850}
1851
jardineb5d44e2003-12-23 08:09:43 +00001852/*
1853 * Something has changed -> regenerate LSP
1854 */
1855
1856int
1857lsp_l1_regenerate (struct thread *thread)
1858{
1859 struct isis_area *area;
1860
1861 area = THREAD_ARG (thread);
1862 area->lsp_regenerate_pending[0] = 0;
1863
1864 return lsp_non_pseudo_regenerate (area, 1);
1865}
1866
1867int
1868lsp_l2_regenerate (struct thread *thread)
1869{
1870 struct isis_area *area;
1871
1872 area = THREAD_ARG (thread);
1873 area->lsp_regenerate_pending[1] = 0;
hassof390d2c2004-09-10 20:48:21 +00001874
jardineb5d44e2003-12-23 08:09:43 +00001875 return lsp_non_pseudo_regenerate (area, 2);
1876}
1877
hassof390d2c2004-09-10 20:48:21 +00001878int
jardineb5d44e2003-12-23 08:09:43 +00001879lsp_regenerate_schedule (struct isis_area *area)
1880{
1881 struct isis_lsp *lsp;
1882 u_char id[ISIS_SYS_ID_LEN + 2];
1883 time_t now, diff;
hassof390d2c2004-09-10 20:48:21 +00001884 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
1885 LSP_PSEUDO_ID (id) = LSP_FRAGMENT (id) = 0;
jardineb5d44e2003-12-23 08:09:43 +00001886 now = time (NULL);
1887 /*
1888 * First level 1
1889 */
hassof390d2c2004-09-10 20:48:21 +00001890 if (area->is_type & IS_LEVEL_1)
1891 {
1892 lsp = lsp_search (id, area->lspdb[0]);
1893 if (!lsp || area->lsp_regenerate_pending[0])
1894 goto L2;
1895 /*
1896 * Throttle avoidance
1897 */
1898 diff = now - lsp->last_generated;
1899 if (diff < MIN_LSP_GEN_INTERVAL)
1900 {
1901 area->lsp_regenerate_pending[0] = 1;
1902 thread_add_timer (master, lsp_l1_regenerate, area,
1903 MIN_LSP_GEN_INTERVAL - diff);
hasso12a5cae2004-09-19 19:39:26 +00001904 goto L2;
hassof390d2c2004-09-10 20:48:21 +00001905 }
1906 else
1907 lsp_non_pseudo_regenerate (area, 1);
1908 }
jardineb5d44e2003-12-23 08:09:43 +00001909 /*
1910 * then 2
1911 */
hassof390d2c2004-09-10 20:48:21 +00001912L2:
1913 if (area->is_type & IS_LEVEL_2)
1914 {
1915 lsp = lsp_search (id, area->lspdb[1]);
1916 if (!lsp || area->lsp_regenerate_pending[1])
1917 return ISIS_OK;
1918 /*
1919 * Throttle avoidance
1920 */
1921 diff = now - lsp->last_generated;
1922 if (diff < MIN_LSP_GEN_INTERVAL)
1923 {
1924 area->lsp_regenerate_pending[1] = 1;
1925 thread_add_timer (master, lsp_l2_regenerate, area,
1926 MIN_LSP_GEN_INTERVAL - diff);
1927 return ISIS_OK;
1928 }
1929 else
1930 lsp_non_pseudo_regenerate (area, 2);
1931 }
1932
1933 return ISIS_OK;
jardineb5d44e2003-12-23 08:09:43 +00001934}
1935
1936/*
1937 * Funcs for pseudonode LSPs
1938 */
1939
1940/*
1941 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1942 */
1943void
hassof390d2c2004-09-10 20:48:21 +00001944lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1945 int level)
jardineb5d44e2003-12-23 08:09:43 +00001946{
1947 struct isis_adjacency *adj;
1948 struct is_neigh *is_neigh;
1949 struct es_neigh *es_neigh;
1950 struct list *adj_list;
1951 struct listnode *node;
1952 struct isis_passwd *passwd;
1953
1954 assert (circuit);
1955 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
hassof390d2c2004-09-10 20:48:21 +00001956
jardineb5d44e2003-12-23 08:09:43 +00001957 if (!circuit->u.bc.is_dr[level - 1])
hassof390d2c2004-09-10 20:48:21 +00001958 return; /* we are not DIS on this circuit */
1959
jardineb5d44e2003-12-23 08:09:43 +00001960 lsp->level = level;
1961 if (level == 1)
1962 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1963 else
1964 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1965
1966 /*
1967 * add self to IS neighbours
1968 */
hassof390d2c2004-09-10 20:48:21 +00001969 if (lsp->tlv_data.is_neighs == NULL)
1970 {
1971 lsp->tlv_data.is_neighs = list_new ();
1972 lsp->tlv_data.is_neighs->del = free_tlv;
1973 }
jardineb5d44e2003-12-23 08:09:43 +00001974 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1975 memset (is_neigh, 0, sizeof (struct is_neigh));
1976 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1977 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
hassof390d2c2004-09-10 20:48:21 +00001978
1979 adj_list = list_new ();
1980 isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list);
1981
1982 for (node = listhead (adj_list); node; nextnode (node))
1983 {
1984 adj = getdata (node);
1985 if (adj->circuit_t & level)
1986 {
1987 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1988 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1989 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1990 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS))
1991 {
1992 /* an IS neighbour -> add it */
1993 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1994 memset (is_neigh, 0, sizeof (struct is_neigh));
1995 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1996 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1997 }
1998 else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES)
1999 {
2000 /* an ES neigbour add it, if we are building level 1 LSP */
2001 /* FIXME: the tlv-format is hard to use here */
2002 if (lsp->tlv_data.es_neighs == NULL)
2003 {
2004 lsp->tlv_data.es_neighs = list_new ();
2005 lsp->tlv_data.es_neighs->del = free_tlv;
2006 }
2007 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
2008 memset (es_neigh, 0, sizeof (struct es_neigh));
2009 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
2010 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
2011 }
2012 }
jardineb5d44e2003-12-23 08:09:43 +00002013 }
hassof390d2c2004-09-10 20:48:21 +00002014
jardineb5d44e2003-12-23 08:09:43 +00002015 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2016 /*
2017 * Add the authentication info if it's present
2018 */
hassof390d2c2004-09-10 20:48:21 +00002019 (level == 1) ? (passwd = &circuit->area->area_passwd) :
2020 (passwd = &circuit->area->domain_passwd);
2021 if (passwd->type)
2022 {
2023 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
2024 tlv_add_authinfo (passwd->type, passwd->len, passwd->passwd, lsp->pdu);
2025 }
jardineb5d44e2003-12-23 08:09:43 +00002026
2027 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
2028 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
2029
2030 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
2031 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
2032
2033 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
hassof390d2c2004-09-10 20:48:21 +00002034 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2035 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2036
jardineb5d44e2003-12-23 08:09:43 +00002037 list_delete (adj_list);
2038
2039 return;
2040}
2041
2042int
2043lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
2044{
2045 dict_t *lspdb = circuit->area->lspdb[level - 1];
2046 struct isis_lsp *lsp;
2047 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
hassof390d2c2004-09-10 20:48:21 +00002048
jardineb5d44e2003-12-23 08:09:43 +00002049 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
hassof390d2c2004-09-10 20:48:21 +00002050 LSP_PSEUDO_ID (lsp_id) = circuit->circuit_id;
2051 LSP_FRAGMENT (lsp_id) = 0;
2052
jardineb5d44e2003-12-23 08:09:43 +00002053 lsp = lsp_search (lsp_id, lspdb);
hassof390d2c2004-09-10 20:48:21 +00002054
2055 if (!lsp)
2056 {
2057 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
2058 rawlspid_print (lsp_id));
2059 return ISIS_ERROR;
2060 }
2061 lsp_clear_data (lsp);
jardineb5d44e2003-12-23 08:09:43 +00002062
2063 lsp_build_pseudo (lsp, circuit, level);
2064
hassof390d2c2004-09-10 20:48:21 +00002065 lsp->lsp_header->rem_lifetime =
jardineb5d44e2003-12-23 08:09:43 +00002066 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
hassof390d2c2004-09-10 20:48:21 +00002067 MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002068
2069 lsp_inc_seqnum (lsp, 0);
hassof390d2c2004-09-10 20:48:21 +00002070
2071 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2072 {
2073 zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
2074 circuit->area->area_tag, level,
2075 rawlspid_print (lsp->lsp_header->lsp_id));
2076 }
jardineb5d44e2003-12-23 08:09:43 +00002077
2078 lsp->last_generated = time (NULL);
2079 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002080
jardineb5d44e2003-12-23 08:09:43 +00002081 return ISIS_OK;
2082}
2083
jardineb5d44e2003-12-23 08:09:43 +00002084int
2085lsp_l1_refresh_pseudo (struct thread *thread)
2086{
2087 struct isis_circuit *circuit;
2088 int retval;
2089 unsigned long ref_time;
2090
hassof390d2c2004-09-10 20:48:21 +00002091 circuit = THREAD_ARG (thread);
2092
jardineb5d44e2003-12-23 08:09:43 +00002093 if (!circuit->u.bc.is_dr[0])
hassof390d2c2004-09-10 20:48:21 +00002094 return ISIS_ERROR; /* FIXME: purge and such */
2095
hasso13c48f72004-09-10 21:19:13 +00002096 circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
2097
jardineb5d44e2003-12-23 08:09:43 +00002098 retval = lsp_pseudo_regenerate (circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002099
2100 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002101 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2102
hassof390d2c2004-09-10 20:48:21 +00002103 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2104 lsp_l1_refresh_pseudo, circuit,
2105 isis_jitter (ref_time, MAX_AGE_JITTER));
2106
jardineb5d44e2003-12-23 08:09:43 +00002107 return retval;
2108}
2109
hassof390d2c2004-09-10 20:48:21 +00002110int
jardineb5d44e2003-12-23 08:09:43 +00002111lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2112{
2113 struct isis_lsp *lsp;
2114 u_char id[ISIS_SYS_ID_LEN + 2];
2115 unsigned long ref_time;
2116
hassof390d2c2004-09-10 20:48:21 +00002117 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2118 LSP_FRAGMENT (id) = 0;
2119 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002120
2121 /*
2122 * If for some reason have a pseudo LSP in the db already -> regenerate
2123 */
2124 if (lsp_search (id, circuit->area->lspdb[0]))
2125 return lsp_pseudo_regenerate (circuit, 1);
2126 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
hassof390d2c2004-09-10 20:48:21 +00002127 1, circuit->area->is_type, 0, 1);
2128
jardineb5d44e2003-12-23 08:09:43 +00002129 lsp_build_pseudo (lsp, circuit, 1);
hassof390d2c2004-09-10 20:48:21 +00002130
jardineb5d44e2003-12-23 08:09:43 +00002131 lsp->own_lsp = 1;
2132 lsp_insert (lsp, circuit->area->lspdb[0]);
2133 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2134
hassof390d2c2004-09-10 20:48:21 +00002135 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002136 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2137
hassof390d2c2004-09-10 20:48:21 +00002138 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2139 lsp_l1_refresh_pseudo, circuit,
2140 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002141
2142 return lsp_regenerate_schedule (circuit->area);
2143}
2144
2145int
2146lsp_l2_refresh_pseudo (struct thread *thread)
2147{
2148 struct isis_circuit *circuit;
2149 int retval;
2150 unsigned long ref_time;
hassof390d2c2004-09-10 20:48:21 +00002151 circuit = THREAD_ARG (thread);
2152
jardineb5d44e2003-12-23 08:09:43 +00002153 if (!circuit->u.bc.is_dr[1])
hassof390d2c2004-09-10 20:48:21 +00002154 return ISIS_ERROR; /* FIXME: purge and such */
2155
hasso13c48f72004-09-10 21:19:13 +00002156 circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
2157
jardineb5d44e2003-12-23 08:09:43 +00002158 retval = lsp_pseudo_regenerate (circuit, 2);
2159
hassof390d2c2004-09-10 20:48:21 +00002160 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002161 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2162
hassof390d2c2004-09-10 20:48:21 +00002163 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2164 lsp_l2_refresh_pseudo, circuit,
2165 isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002166
jardineb5d44e2003-12-23 08:09:43 +00002167 return retval;
2168}
2169
hassof390d2c2004-09-10 20:48:21 +00002170int
jardineb5d44e2003-12-23 08:09:43 +00002171lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2172{
2173 struct isis_lsp *lsp;
2174 u_char id[ISIS_SYS_ID_LEN + 2];
2175 unsigned long ref_time;
2176
hassof390d2c2004-09-10 20:48:21 +00002177 memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
2178 LSP_FRAGMENT (id) = 0;
2179 LSP_PSEUDO_ID (id) = circuit->circuit_id;
jardineb5d44e2003-12-23 08:09:43 +00002180
2181 if (lsp_search (id, circuit->area->lspdb[1]))
2182 return lsp_pseudo_regenerate (circuit, 2);
2183
2184 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
hassof390d2c2004-09-10 20:48:21 +00002185 1, circuit->area->is_type, 0, 2);
jardineb5d44e2003-12-23 08:09:43 +00002186
2187 lsp_build_pseudo (lsp, circuit, 2);
hassof390d2c2004-09-10 20:48:21 +00002188
2189 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
jardineb5d44e2003-12-23 08:09:43 +00002190 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2191
2192
2193 lsp->own_lsp = 1;
2194 lsp_insert (lsp, circuit->area->lspdb[1]);
2195 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002196
2197 THREAD_TIMER_ON (master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2198 lsp_l2_refresh_pseudo, circuit,
2199 isis_jitter (ref_time, MAX_AGE_JITTER));
2200
jardineb5d44e2003-12-23 08:09:43 +00002201 return lsp_regenerate_schedule (circuit->area);
2202}
2203
jardineb5d44e2003-12-23 08:09:43 +00002204/*
2205 * Walk through LSPs for an area
2206 * - set remaining lifetime
2207 * - set LSPs with SRMflag set for sending
2208 */
hassof390d2c2004-09-10 20:48:21 +00002209int
jardineb5d44e2003-12-23 08:09:43 +00002210lsp_tick (struct thread *thread)
2211{
2212 struct isis_area *area;
2213 struct isis_circuit *circuit;
2214 struct isis_lsp *lsp;
2215 struct list *lsp_list;
2216 struct listnode *lspnode, *cnode;
2217 dnode_t *dnode, *dnode_next;
2218 int level;
2219
2220 lsp_list = list_new ();
hassof390d2c2004-09-10 20:48:21 +00002221
jardineb5d44e2003-12-23 08:09:43 +00002222 area = THREAD_ARG (thread);
2223 assert (area);
hasso13c48f72004-09-10 21:19:13 +00002224 area->t_tick = NULL;
hassof390d2c2004-09-10 20:48:21 +00002225 THREAD_TIMER_ON (master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002226
2227 /*
2228 * Build a list of LSPs with (any) SRMflag set
2229 * and removed the ones that have aged out
2230 */
hassof390d2c2004-09-10 20:48:21 +00002231 for (level = 0; level < ISIS_LEVELS; level++)
2232 {
2233 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0)
2234 {
2235 dnode = dict_first (area->lspdb[level]);
2236 while (dnode != NULL)
2237 {
2238 dnode_next = dict_next (area->lspdb[level], dnode);
2239 lsp = dnode_get (dnode);
2240 lsp_set_time (lsp);
2241 if (lsp->age_out == 0)
2242 {
jardineb5d44e2003-12-23 08:09:43 +00002243
hassof390d2c2004-09-10 20:48:21 +00002244 zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2245 area->area_tag,
2246 lsp->level,
2247 rawlspid_print (lsp->lsp_header->lsp_id),
2248 ntohl (lsp->lsp_header->seq_num));
jardineb5d44e2003-12-23 08:09:43 +00002249
hassof390d2c2004-09-10 20:48:21 +00002250 lsp_destroy (lsp);
2251 dict_delete (area->lspdb[level], dnode);
2252 }
2253 else if (flags_any_set (lsp->SRMflags))
2254 listnode_add (lsp_list, lsp);
2255 dnode = dnode_next;
2256 }
jardineb5d44e2003-12-23 08:09:43 +00002257
hassof390d2c2004-09-10 20:48:21 +00002258 /*
2259 * Send LSPs on circuits indicated by the SRMflags
2260 */
2261 if (listcount (lsp_list) > 0)
2262 {
2263 for (cnode = listhead (area->circuit_list); cnode;
2264 nextnode (cnode))
2265 {
2266 circuit = getdata (cnode);
2267 for (lspnode = listhead (lsp_list); lspnode;
2268 nextnode (lspnode))
2269 {
2270 lsp = getdata (lspnode);
2271 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
2272 {
2273 /* FIXME: if same or elder lsp is already in lsp
2274 * queue */
2275 listnode_add (circuit->lsp_queue, lsp);
2276 thread_add_event (master, send_lsp, circuit, 0);
2277 }
2278 }
2279 }
2280 }
2281 list_delete_all_node (lsp_list);
2282 }
jardineb5d44e2003-12-23 08:09:43 +00002283 }
jardineb5d44e2003-12-23 08:09:43 +00002284
2285 list_delete (lsp_list);
2286
2287 return ISIS_OK;
2288}
2289
jardineb5d44e2003-12-23 08:09:43 +00002290void
hassof390d2c2004-09-10 20:48:21 +00002291lsp_purge_dr (u_char * id, struct isis_circuit *circuit, int level)
jardineb5d44e2003-12-23 08:09:43 +00002292{
2293 struct isis_lsp *lsp;
hassof390d2c2004-09-10 20:48:21 +00002294
jardineb5d44e2003-12-23 08:09:43 +00002295 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
hassof390d2c2004-09-10 20:48:21 +00002296
2297 if (lsp && lsp->purged == 0)
2298 {
2299 lsp->lsp_header->rem_lifetime = htons (0);
2300 lsp->lsp_header->pdu_len =
2301 htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2302 lsp->purged = 0;
2303 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2304 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2305 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2306 }
2307
jardineb5d44e2003-12-23 08:09:43 +00002308 return;
2309}
2310
2311/*
2312 * Purge own LSP that is received and we don't have.
2313 * -> Do as in 7.3.16.4
2314 */
2315void
hassof390d2c2004-09-10 20:48:21 +00002316lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2317 struct isis_area *area)
jardineb5d44e2003-12-23 08:09:43 +00002318{
2319 struct isis_lsp *lsp;
2320
2321 /*
2322 * We need to create the LSP to be purged
2323 */
2324 zlog_info ("LSP PURGE NON EXIST");
2325 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2326 memset (lsp, 0, sizeof (struct isis_lsp));
hassof390d2c2004-09-10 20:48:21 +00002327 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2328 /*did smt here, maybe good probably not */
jardineb5d44e2003-12-23 08:09:43 +00002329 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2330 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002331 lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu);
jardineb5d44e2003-12-23 08:09:43 +00002332 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
hassof390d2c2004-09-10 20:48:21 +00002333 : L2_LINK_STATE);
2334 lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) +
2335 ISIS_FIXED_HDR_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002336 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
hassof390d2c2004-09-10 20:48:21 +00002337
jardineb5d44e2003-12-23 08:09:43 +00002338 /*
2339 * Retain only LSP header
2340 */
2341 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2342 /*
2343 * Set the remaining lifetime to 0
2344 */
2345 lsp->lsp_header->rem_lifetime = 0;
2346 /*
2347 * Put the lsp into LSPdb
2348 */
hassof390d2c2004-09-10 20:48:21 +00002349 lsp_insert (lsp, area->lspdb[lsp->level - 1]);
jardineb5d44e2003-12-23 08:09:43 +00002350
2351 /*
2352 * Send in to whole area
2353 */
2354 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002355
jardineb5d44e2003-12-23 08:09:43 +00002356 return;
2357}
2358
2359#ifdef TOPOLOGY_GENERATE
2360int
2361top_lsp_refresh (struct thread *thread)
2362{
hassof390d2c2004-09-10 20:48:21 +00002363 struct isis_lsp *lsp;
jardineb5d44e2003-12-23 08:09:43 +00002364
2365 lsp = THREAD_ARG (thread);
2366 assert (lsp);
2367
2368 lsp->t_lsp_top_ref = NULL;
2369
hassof390d2c2004-09-10 20:48:21 +00002370 lsp->lsp_header->rem_lifetime =
2371 htons (isis_jitter (MAX_AGE, MAX_AGE_JITTER));
2372 lsp->lsp_header->seq_num = htonl (ntohl (lsp->lsp_header->seq_num) + 1);
jardineb5d44e2003-12-23 08:09:43 +00002373
2374 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
hassof390d2c2004-09-10 20:48:21 +00002375 if (isis->debugs & DEBUG_UPDATE_PACKETS)
2376 {
2377 zlog_info ("ISIS-Upd (): refreshing Topology L1 %s",
2378 rawlspid_print (lsp->lsp_header->lsp_id));
2379 }
jardineb5d44e2003-12-23 08:09:43 +00002380
2381 /* time to calculate our checksum */
2382 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
hassof390d2c2004-09-10 20:48:21 +00002383 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2384 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2385 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002386
2387 return ISIS_OK;
2388}
2389
2390void
2391generate_topology_lsps (struct isis_area *area)
2392{
2393 struct listnode *node;
2394 int i, max = 0;
2395 struct arc *arc;
2396 u_char lspid[ISIS_SYS_ID_LEN + 2];
2397 struct isis_lsp *lsp;
2398
2399 /* first we find the maximal node */
hassof390d2c2004-09-10 20:48:21 +00002400 LIST_LOOP (area->topology, arc, node)
2401 {
2402 if (arc->from_node > max)
2403 max = arc->from_node;
2404 if (arc->to_node > max)
2405 max = arc->to_node;
jardineb5d44e2003-12-23 08:09:43 +00002406 }
2407
hassof390d2c2004-09-10 20:48:21 +00002408 for (i = 1; i < (max + 1); i++)
2409 {
2410 memcpy (lspid, area->topology_baseis, ISIS_SYS_ID_LEN);
2411 LSP_PSEUDO_ID (lspid) = 0x00;
2412 LSP_FRAGMENT (lspid) = 0x00;
2413 lspid[ISIS_SYS_ID_LEN - 1] = (i & 0xFF);
2414 lspid[ISIS_SYS_ID_LEN - 2] = ((i >> 8) & 0xFF);
jardineb5d44e2003-12-23 08:09:43 +00002415
hassof390d2c2004-09-10 20:48:21 +00002416 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2417 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0,
2418 1);
2419 lsp->from_topology = 1;
2420 /* creating data based on topology */
2421 build_topology_lsp_data (lsp, area, i);
2422 /* time to calculate our checksum */
2423 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2424 ntohs (lsp->lsp_header->pdu_len) - 12, 12);
2425 THREAD_TIMER_ON (master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2426 isis_jitter (MAX_LSP_GEN_INTERVAL,
2427 MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002428
hassof390d2c2004-09-10 20:48:21 +00002429 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2430 lsp_insert (lsp, area->lspdb[0]);
jardineb5d44e2003-12-23 08:09:43 +00002431
hassof390d2c2004-09-10 20:48:21 +00002432 }
jardineb5d44e2003-12-23 08:09:43 +00002433}
2434
2435void
2436remove_topology_lsps (struct isis_area *area)
2437{
2438 struct isis_lsp *lsp;
2439 dnode_t *dnode, *dnode_next;
2440
2441 dnode = dict_first (area->lspdb[0]);
hassof390d2c2004-09-10 20:48:21 +00002442 while (dnode != NULL)
2443 {
2444 dnode_next = dict_next (area->lspdb[0], dnode);
2445 lsp = dnode_get (dnode);
2446 if (lsp->from_topology)
2447 {
2448 THREAD_TIMER_OFF (lsp->t_lsp_top_ref);
2449 lsp_destroy (lsp);
2450 dict_delete (area->lspdb[0], dnode);
2451 }
2452 dnode = dnode_next;
jardineb5d44e2003-12-23 08:09:43 +00002453 }
jardineb5d44e2003-12-23 08:09:43 +00002454}
2455
2456void
hassof390d2c2004-09-10 20:48:21 +00002457build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
jardineb5d44e2003-12-23 08:09:43 +00002458 int lsp_top_num)
2459{
2460 struct listnode *node;
2461 struct arc *arc;
2462 u_char *tlv_ptr;
2463 struct is_neigh *is_neigh;
2464 int to_lsp = 0;
2465 char buff[200];
2466
2467 /* add our nlpids */
hassof390d2c2004-09-10 20:48:21 +00002468 /* the 2 is for the TL plus 1 for the nlpid */
2469 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2470 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2471 *(tlv_ptr + 1) = 1; /* one protocol */
2472 *(tlv_ptr + 2) = NLPID_IP;
2473 lsp->tlv_data.nlpids = (struct nlpids *) (tlv_ptr + 1);
jardineb5d44e2003-12-23 08:09:43 +00002474
2475 /* first, lets add the tops */
hassof390d2c2004-09-10 20:48:21 +00002476 /* the 2 is for the TL plus 1 for the virtual field */
2477 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2478 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2479 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2480 *(tlv_ptr + 2) = 0; /* virtual is zero */
2481 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
jardineb5d44e2003-12-23 08:09:43 +00002482
2483 /* add reachability for this IS for simulated 1 */
hassof390d2c2004-09-10 20:48:21 +00002484 if (lsp_top_num == 1)
2485 {
jardineb5d44e2003-12-23 08:09:43 +00002486 /* assign space for the is_neigh at the pdu end */
hassof390d2c2004-09-10 20:48:21 +00002487 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2488 sizeof (struct
2489 is_neigh));
jardineb5d44e2003-12-23 08:09:43 +00002490 /* add this node to our list */
hassof390d2c2004-09-10 20:48:21 +00002491 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2492 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
jardineb5d44e2003-12-23 08:09:43 +00002493 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
hassof390d2c2004-09-10 20:48:21 +00002494 is_neigh->metrics.metric_default = 0x00; /* no special reason */
jardineb5d44e2003-12-23 08:09:43 +00002495 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2496 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2497 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2498 /* don't forget the length */
hassof390d2c2004-09-10 20:48:21 +00002499 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2500 /* no need to check for fragging here, it is a lonely is_reach */
jardineb5d44e2003-12-23 08:09:43 +00002501 }
hassof390d2c2004-09-10 20:48:21 +00002502
2503 /* addding is reachabilities */
2504 LIST_LOOP (area->topology, arc, node)
2505 {
2506 if ((arc->from_node == lsp_top_num) || (arc->to_node == lsp_top_num))
2507 {
2508 if (arc->to_node == lsp_top_num)
2509 to_lsp = arc->from_node;
2510 if (arc->from_node == lsp_top_num)
2511 to_lsp = arc->to_node;
2512
2513 /* if the length here is about to cross the FF limit, we reTLV */
2514 if (*(tlv_ptr + 1) >= (0xFF - IS_NEIGHBOURS_LEN))
2515 {
2516 /* retlv */
2517 /* the 2 is for the TL plus 1 for the virtual field */
2518 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 3);
2519 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2520 *(tlv_ptr + 1) = 1; /* this is the virtual char len */
2521 *(tlv_ptr + 2) = 0; /* virtual is zero */
2522 }
2523 /* doing this here assures us that we won't add an "empty" tlv */
2524 /* assign space for the is_neigh at the pdu end */
2525 is_neigh = (struct is_neigh *) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2526 sizeof (struct
2527 is_neigh));
2528 /* add this node to our list */
2529 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2530 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2531 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2532 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 1] = (to_lsp & 0xFF);
2533 is_neigh->neigh_id[ISIS_SYS_ID_LEN - 2] = ((to_lsp >> 8) & 0xFF);
2534 is_neigh->metrics.metric_default = arc->distance;
2535 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2536 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2537 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2538 /* don't forget the length */
2539 *(tlv_ptr + 1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2540 }
jardineb5d44e2003-12-23 08:09:43 +00002541 }
2542
hassof390d2c2004-09-10 20:48:21 +00002543 /* adding dynamic hostname if needed */
2544 if (area->dynhostname)
2545 {
2546 memset (buff, 0x00, 200);
2547 sprintf (buff, "feedme%d", lsp_top_num);
2548 /* the 2 is for the TL */
2549 tlv_ptr = lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 2);
2550 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2551 *(tlv_ptr + 1) = strlen (buff); /* Length */
2552 /* the -1 is to fit the length in the struct */
2553 lsp->tlv_data.hostname = (struct hostname *)
2554 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1);
2555 memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff));
2556 }
jardineb5d44e2003-12-23 08:09:43 +00002557
2558 /* thanks to hannes, another bug bites the dust */
hassof390d2c2004-09-10 20:48:21 +00002559 lsp->pdu->putp = ntohs (lsp->lsp_header->pdu_len);
2560 lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len);
jardineb5d44e2003-12-23 08:09:43 +00002561}
2562#endif /* TOPOLOGY_GENERATE */