blob: 0faadbd8cc980889236abb87156e80163b8f4083 [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>
26#include <net/ethernet.h>
27
28#include "linklist.h"
29#include "thread.h"
30#include "vty.h"
31#include "stream.h"
32#include "memory.h"
33#include "log.h"
34#include "prefix.h"
35#include "command.h"
36#include "hash.h"
37#include "if.h"
38
39#include "isisd/dict.h"
40#include "isisd/isis_constants.h"
41#include "isisd/isis_common.h"
42#include "isisd/isis_circuit.h"
43#include "isisd/isisd.h"
44#include "isisd/isis_tlv.h"
45#include "isisd/isis_lsp.h"
46#include "isisd/isis_pdu.h"
47#include "isisd/isis_dynhn.h"
48#include "isisd/isis_misc.h"
49#include "isisd/isis_flags.h"
50#include "isisd/iso_checksum.h"
51#include "isisd/isis_csm.h"
52#include "isisd/isis_adjacency.h"
53#include "isisd/isis_spf.h"
54
55#ifdef TOPOLOGY_GENERATE
56#include "spgrid.h"
57#endif
58
59#define LSP_MEMORY_PREASSIGN
60
61extern struct isis *isis;
62extern struct thread_master *master;
jardineb5d44e2003-12-23 08:09:43 +000063
64int
65lsp_id_cmp (u_char *id1, u_char *id2)
66{
67 return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
68}
69
70dict_t *
71lsp_db_init (void)
72{
73 dict_t *dict;
74
75 dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t)lsp_id_cmp);
76
77 return dict;
78}
79
80struct isis_lsp *
81lsp_search (u_char *id, dict_t *lspdb)
82{
83 dnode_t *node;
84
85#ifdef EXTREME_DEBUG
86 dnode_t *dn;
87
88 zlog_warn("searching db");
89 for (dn = dict_first(lspdb); dn; dn = dict_next(lspdb, dn)) {
90 zlog_warn("%s\t%pX", rawlspid_print((char *) dnode_getkey(dn)),
91 dnode_get(dn));
92 }
93#endif /* EXTREME DEBUG */
94
95 node = dict_lookup (lspdb, id);
96
97 if (node)
98 return (struct isis_lsp *)dnode_get (node);
99
100 return NULL;
101}
102
103void
104lsp_clear_data (struct isis_lsp *lsp)
105{
106 if (!lsp)
107 return;
108
109 if (lsp->own_lsp) {
110 if (lsp->tlv_data.nlpids)
111 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
112 if (lsp->tlv_data.hostname)
113 XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
114 }
115 if (lsp->tlv_data.is_neighs)
116 list_delete (lsp->tlv_data.is_neighs);
117 if (lsp->tlv_data.area_addrs)
118 list_delete (lsp->tlv_data.area_addrs);
119 if (lsp->tlv_data.es_neighs)
120 list_delete (lsp->tlv_data.es_neighs);
121 if (lsp->tlv_data.ipv4_addrs)
122 list_delete (lsp->tlv_data.ipv4_addrs);
123 if (lsp->tlv_data.ipv4_int_reachs)
124 list_delete (lsp->tlv_data.ipv4_int_reachs);
125 if (lsp->tlv_data.ipv4_ext_reachs)
126 list_delete (lsp->tlv_data.ipv4_ext_reachs);
127#ifdef HAVE_IPV6
128 if (lsp->tlv_data.ipv6_addrs)
129 list_delete (lsp->tlv_data.ipv6_addrs);
130 if (lsp->tlv_data.ipv6_reachs)
131 list_delete (lsp->tlv_data.ipv6_reachs);
132#endif /* HAVE_IPV6 */
133
134 memset (&lsp->tlv_data, 0, sizeof (struct tlvs));
135
136 return;
137}
138
139void
140lsp_destroy (struct isis_lsp *lsp)
141{
142 if (!lsp)
143 return;
144
145 lsp_clear_data (lsp);
146
147 if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags) {
148 list_delete (lsp->lspu.frags);
149 }
150
151 if (lsp->pdu)
152 stream_free (lsp->pdu);
153 XFREE (MTYPE_ISIS_LSP, lsp);
154}
155
156void
157lsp_db_destroy (dict_t *lspdb)
158{
159 dnode_t *dnode, *next;
160 struct isis_lsp *lsp;
161
162 dnode = dict_first (lspdb);
163 while (dnode) {
164 next = dict_next (lspdb, dnode);
165 lsp = dnode_get (dnode);
166 lsp_destroy (lsp);
167 dict_delete_free (lspdb, dnode);
168 dnode = next;
169 }
170
171 dict_free (lspdb);
172
173 return;
174}
175
176/*
177 * Remove all the frags belonging to the given lsp
178 */
179void
180lsp_remove_frags (struct list *frags, dict_t *lspdb)
181{
182 dnode_t *dnode;
183 struct listnode *lnode;
184 struct isis_lsp *lsp;
185
186 for (lnode = listhead (frags); lnode; nextnode (lnode)) {
187 lsp = getdata (lnode);
188 dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
189 lsp_destroy (lsp);
190 dnode_destroy (dict_delete(lspdb, dnode));
191 }
192
193 list_delete_all_node (frags);
194
195 return;
196}
197
198void
199lsp_search_and_destroy (u_char *id, dict_t *lspdb)
200{
201 dnode_t *node;
202 struct isis_lsp *lsp;
203
204 node = dict_lookup (lspdb, id);
205 if (node) {
206 node = dict_delete (lspdb, node);
207 lsp = dnode_get (node);
208 /*
209 * If this is a zero lsp, remove all the frags now
210 */
211 if (LSP_FRAGMENT(lsp->lsp_header->lsp_id) == 0) {
212 if (lsp->lspu.frags)
213 lsp_remove_frags (lsp->lspu.frags, lspdb);
214 } else {
215 /*
216 * else just remove this frag, from the zero lsps' frag list
217 */
218 if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
219 listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
220 }
221 lsp_destroy (lsp);
222 dnode_destroy (node);
223 }
224}
225
226/*
227 * Compares a LSP to given values
228 * Params are given in net order
229 */
230int
231lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num,
232 u_int16_t checksum, u_int16_t rem_lifetime)
233{
234 /* no point in double ntohl on seqnum */
235 if (lsp->lsp_header->seq_num == seq_num &&
236 lsp->lsp_header->checksum == checksum &&
237 /*comparing with 0, no need to do ntohl */
238 ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
239 (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0))) {
240 if (isis->debugs & DEBUG_SNP_PACKETS) {
241 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
242 " lifetime %us",
243 areatag,
244 rawlspid_print (lsp->lsp_header->lsp_id),
245 ntohl(lsp->lsp_header->seq_num),
246 ntohs(lsp->lsp_header->checksum),
247 ntohs(lsp->lsp_header->rem_lifetime) );
248 zlog_info ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
249 " cksum 0x%04x, lifetime %us",
250 areatag,
251 ntohl(seq_num),
252 ntohs(checksum),
253 ntohs(rem_lifetime));
254 }
255 return LSP_EQUAL;
256 }
257
258 if (ntohl(seq_num) >= ntohl(lsp->lsp_header->seq_num)) {
259 if (isis->debugs & DEBUG_SNP_PACKETS) {
260 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
261 " lifetime %us",
262 areatag,
263 rawlspid_print (lsp->lsp_header->lsp_id),
264 ntohl(seq_num),
265 ntohs(checksum),
266 ntohs(rem_lifetime ));
267 zlog_info ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
268 "cksum 0x%04x, lifetime %us",
269 areatag,
270 ntohl(lsp->lsp_header->seq_num),
271 ntohs(lsp->lsp_header->checksum),
272 ntohs(lsp->lsp_header->rem_lifetime) );
273 }
274 return LSP_NEWER;
275 }
276 if (isis->debugs & DEBUG_SNP_PACKETS) {
277 zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
278 areatag,
279 rawlspid_print (lsp->lsp_header->lsp_id),
280 ntohl(seq_num),
281 ntohs(checksum),
282 ntohs(rem_lifetime ));
283 zlog_info ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
284 " cksum 0x%04x, lifetime %us",
285 areatag,
286 ntohl(lsp->lsp_header->seq_num),
287 ntohs(lsp->lsp_header->checksum),
288 ntohs(lsp->lsp_header->rem_lifetime) );
289 }
290
291 return LSP_OLDER;
292}
293
294void
295lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
296{
297 u_int32_t newseq;
298
299 if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
300 newseq = ntohl (lsp->lsp_header->seq_num) + 1;
301 else
302 newseq = seq_num ++;
303
304 lsp->lsp_header->seq_num = htonl (newseq);
305 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
306 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
307
308 return;
309}
310
311/*
312 * Genetates checksum for LSP and its frags
313 */
314void
315lsp_seqnum_update (struct isis_lsp *lsp0)
316{
317 struct isis_lsp *lsp;
318 struct listnode *node;
319
320 lsp_inc_seqnum (lsp0, 0);
321
322 if (!lsp0->lspu.frags)
323 return;
324
325 for (node = listhead (lsp0->lspu.frags); node; nextnode (node)) {
326 lsp = getdata (node);
327 lsp_inc_seqnum(lsp, 0);
328 }
329
330 return;
331}
332
333int
334isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
335 int pdulen, struct isis_passwd *passwd)
336{
337 uint32_t expected = 0, found;
338 struct tlvs tlvs;
339 int retval = 0;
340
341 expected |= TLVFLAG_AUTH_INFO;
342 retval = parse_tlvs (area->area_tag, stream->data +
343 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
344 pdulen - ISIS_FIXED_HDR_LEN
345 - ISIS_LSP_HDR_LEN,
346 &expected, &found, &tlvs);
347 if (retval || !(found & TLVFLAG_AUTH_INFO))
348 return 1; /* Auth fail (parsing failed or no auth-tlv)*/
349
350 return authentication_check (passwd, &tlvs.auth_info);
351}
352
353void
354lsp_update_data (struct isis_lsp *lsp, struct stream *stream,
355 struct isis_area *area)
356{
357 uint32_t expected = 0,found;
358 int retval;
359
360 /* copying only the relevant part of our stream */
361 lsp->pdu = stream_new (stream->endp);
362 lsp->pdu->putp = stream->putp;
363 lsp->pdu->getp = stream->getp;
364 lsp->pdu->endp = stream->endp;
365 memcpy (lsp->pdu->data, stream->data, stream->endp);
366
367 /* setting pointers to the correct place */
368 lsp->isis_header = (struct isis_fixed_hdr *)(STREAM_DATA(lsp->pdu));
369 lsp->lsp_header = (struct isis_link_state_hdr *)(STREAM_DATA(lsp->pdu) +
370 ISIS_FIXED_HDR_LEN);
371 lsp->age_out = ZERO_AGE_LIFETIME;
372 lsp->installed = time(NULL);
373 /*
374 * Get LSP data i.e. TLVs
375 */
376 expected |= TLVFLAG_AUTH_INFO;
377 expected |= TLVFLAG_AREA_ADDRS;
378 expected |= TLVFLAG_IS_NEIGHS;
379 if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
380 expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
381 expected |= TLVFLAG_NLPID;
382 if (area->dynhostname)
383 expected |= TLVFLAG_DYN_HOSTNAME;
384 if (area->newmetric) {
385 expected |= TLVFLAG_TE_IS_NEIGHS;
386 expected |= TLVFLAG_TE_IPV4_REACHABILITY;
387 expected |= TLVFLAG_TE_ROUTER_ID;
388 }
389 expected |= TLVFLAG_IPV4_ADDR;
390 expected |= TLVFLAG_IPV4_INT_REACHABILITY;
391 expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
392#ifdef HAVE_IPV6
393 expected |= TLVFLAG_IPV6_ADDR;
394 expected |= TLVFLAG_IPV6_REACHABILITY;
395#endif /* HAVE_IPV6 */
396
397 retval = parse_tlvs (area->area_tag, lsp->pdu->data +
398 ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
399 ntohs(lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN
400 - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);
401
402 if (found & TLVFLAG_DYN_HOSTNAME) {
403 if (area->dynhostname)
404 isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
405 (lsp->lsp_header->lsp_bits & LSPBIT_IST) ==
406 IS_LEVEL_1_AND_2 ? IS_LEVEL_2 :
407 (lsp->lsp_header->lsp_bits & LSPBIT_IST));
408 }
409
410}
411
412void
413lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
414 struct stream *stream, struct isis_area *area)
415{
416
417 /* free the old lsp data*/
418 XFREE (MTYPE_STREAM_DATA, lsp->pdu);
419 lsp_clear_data (lsp);
420
421 /* rebuild the lsp data */
422 lsp_update_data (lsp, stream, area);
423
424 /* set the new values for lsp header */
425 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
426
427}
428
429
430/* creation of LSP directly from what we received */
431struct isis_lsp *
432lsp_new_from_stream_ptr (struct stream *stream,
433 u_int16_t pdu_len, struct isis_lsp *lsp0,
434 struct isis_area *area)
435{
436 struct isis_lsp *lsp;
437
438 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
439 memset (lsp, 0, sizeof (struct isis_lsp));
440
441 lsp_update_data (lsp, stream, area);
442
443 if (lsp0 == NULL) {
444 /*
445 * zero lsp -> create the list for fragments
446 */
447 lsp->lspu.frags = list_new ();
448 } else {
449 /*
450 * a fragment -> set the backpointer and add this to zero lsps frag list
451 */
452 lsp->lspu.zero_lsp = lsp0;
453 listnode_add (lsp0->lspu.frags, lsp);
454 }
455
456 return lsp;
457}
458
459struct isis_lsp *
460lsp_new (u_char *lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num,
461 u_int8_t lsp_bits, u_int16_t checksum, int level)
462{
463 struct isis_lsp *lsp;
464
465 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
466 if (!lsp) {
467 /* FIXME: set lspdbol bit */
468 zlog_warn ("lsp_new(): out of memory");
469 return NULL;
470 }
471 memset (lsp, 0, sizeof (struct isis_lsp));
472#ifdef LSP_MEMORY_PREASSIGN
473 lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup...*/
474#else
475 /* We need to do realloc on TLVs additions*/
476 lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
477#endif /* LSP_MEMORY_PREASSIGN */
478 if (LSP_FRAGMENT (lsp_id) == 0)
479 lsp->lspu.frags = list_new ();
480 lsp->isis_header = (struct isis_fixed_hdr*)(STREAM_DATA(lsp->pdu));
481 lsp->lsp_header = (struct isis_link_state_hdr*)
482 (STREAM_DATA(lsp->pdu) + ISIS_FIXED_HDR_LEN);
483
484 /* at first we fill the FIXED HEADER */
485 (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE):
486 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
487
488 /* now for the LSP HEADER */
489 /* Minimal LSP PDU size */
490 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
491 memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
492 lsp->lsp_header->checksum = checksum; /* Provided in network order */
493 lsp->lsp_header->seq_num = htonl (seq_num);
494 lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
495 lsp->lsp_header->lsp_bits = lsp_bits;
496 lsp->level = level;
497 lsp->age_out = ZERO_AGE_LIFETIME;
498
499 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
500
501 /* #ifdef EXTREME_DEBUG */
502 /* logging */
503 zlog_info ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
504 LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
505 LSP_FRAGMENT (lsp->lsp_header->lsp_id),
506 ntohl (lsp->lsp_header->seq_num));
507 /* #endif EXTREME DEBUG */
508
509 return lsp;
510}
511
512void
513lsp_insert (struct isis_lsp *lsp, dict_t *lspdb)
514{
515 dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
516}
517
518/*
519 * Build a list of LSPs with non-zero ht bounded by start and stop ids
520 */
521void
522lsp_build_list_nonzero_ht (u_char *start_id, u_char *stop_id,
523 struct list *list, dict_t *lspdb)
524{
525 dnode_t *first, *last, *curr;
526
527 first = dict_lower_bound (lspdb, start_id);
528 if (!first)
529 return;
530
531 last = dict_upper_bound (lspdb, stop_id);
532
533 curr = first;
534
535 if (((struct isis_lsp *)(curr->dict_data))->lsp_header->rem_lifetime)
536 listnode_add (list, first->dict_data);
537
538 while (curr) {
539 curr = dict_next (lspdb, curr);
540 if (curr &&
541 ((struct isis_lsp *)(curr->dict_data))->lsp_header->rem_lifetime)
542 listnode_add (list, curr->dict_data);
543 if (curr == last)
544 break;
545 }
546
547 return;
548}
549
550/*
551 * Build a list of all LSPs bounded by start and stop ids
552 */
553void
554lsp_build_list (u_char *start_id, u_char *stop_id,
555 struct list *list, dict_t *lspdb)
556{
557 dnode_t *first, *last, *curr;
558
559 first = dict_lower_bound (lspdb, start_id);
560 if (!first)
561 return;
562
563 last = dict_upper_bound (lspdb, stop_id);
564
565 curr = first;
566
567 listnode_add (list, first->dict_data);
568
569 while (curr) {
570 curr = dict_next (lspdb, curr);
571 if (curr)
572 listnode_add (list, curr->dict_data);
573 if (curr == last)
574 break;
575 }
576
577 return;
578}
579
580/*
581 * Build a list of LSPs with SSN flag set for the given circuit
582 */
583void
584lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list,
585 dict_t *lspdb)
586{
587 dnode_t *dnode, *next;
588 struct isis_lsp *lsp;
589
590 dnode = dict_first (lspdb);
591 while (dnode != NULL) {
592 next = dict_next (lspdb, dnode);
593 lsp = dnode_get (dnode);
594 if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
595 listnode_add (list, lsp);
596 dnode = next;
597 }
598
599 return;
600}
601
602void
603lsp_set_time (struct isis_lsp *lsp)
604{
605 assert (lsp);
606
607 if (lsp->lsp_header->rem_lifetime == 0) {
608 if (lsp->age_out != 0) lsp->age_out--;
609 return;
610 }
611
612 /* If we are turning 0 */
613 /* ISO 10589 - 7.3.16.4 first paragraph */
614
615 if (ntohs (lsp->lsp_header->rem_lifetime) == 1) {
616 /* 7.3.16.4 a) set SRM flags on all */
617 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
618 /* 7.3.16.4 b) retain only the header FIXME */
619 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it)*/
620 }
621
622 lsp->lsp_header->rem_lifetime =
623 htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
624}
625
626void
627lspid_print (u_char *lsp_id, u_char *trg, char dynhost, char frag)
628{
629 struct isis_dynhn *dyn = NULL;
630 u_char id [SYSID_STRLEN];
631
632 if (dynhost)
633 dyn = dynhn_find_by_id (lsp_id);
634 else
635 dyn = NULL;
636
637 if (dyn)
638 sprintf (id, "%.14s", dyn->name.name);
639 else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
jardin9e867fe2003-12-23 08:56:18 +0000640 sprintf (id, "%.14s", unix_hostname());
jardineb5d44e2003-12-23 08:09:43 +0000641 else {
642 memcpy(id, sysid_print (lsp_id), 15);
643 }
644 if (frag)
645 sprintf (trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID(lsp_id),
646 LSP_FRAGMENT(lsp_id));
647 else
648 sprintf (trg, "%s.%02x", id, LSP_PSEUDO_ID(lsp_id));
649}
650
651/* Convert the lsp attribute bits to attribute string */
652char *
653lsp_bits2string (u_char *lsp_bits) {
654
655 char *pos = lsp_bits_string;
656
657 if(!*lsp_bits)
658 return " none";
659
660 /* we only focus on the default metric */
661 pos += sprintf (pos, "%d/",
662 ISIS_MASK_LSP_ATT_DEFAULT_BIT(*lsp_bits) ?
663 1 : 0);
664
665 pos += sprintf (pos, "%d/",
666 ISIS_MASK_LSP_PARTITION_BIT(*lsp_bits) ?
667 1 : 0);
668
669 pos += sprintf (pos, "%d",
670 ISIS_MASK_LSP_OL_BIT(*lsp_bits) ?
671 1 : 0);
672
673 *(pos) = '\0';
674
675 return lsp_bits_string;
676
677}
678
679/* this function prints the lsp on show isis database */
680void
681lsp_print (dnode_t *node, struct vty *vty, char dynhost)
682{
683 struct isis_lsp *lsp = dnode_get(node);
684 u_char LSPid[255];
685
686 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
687 vty_out (vty, "%-21s%c ", LSPid,lsp->own_lsp?'*':' ');
688 vty_out (vty, "0x%08x ", ntohl(lsp->lsp_header->seq_num));
689 vty_out (vty, "0x%04x ", ntohs(lsp->lsp_header->checksum));
690
691 if (ntohs(lsp->lsp_header->rem_lifetime) == 0)
692 vty_out (vty, " (%2u)",lsp->age_out);
693 else
694 vty_out (vty, "%5u", ntohs(lsp->lsp_header->rem_lifetime));
695
696 vty_out (vty, " %s%s",
697 lsp_bits2string(&lsp->lsp_header->lsp_bits),
698 VTY_NEWLINE);
699}
700
701void
702lsp_print_detail (dnode_t *node, struct vty *vty, char dynhost)
703{
704 struct isis_lsp *lsp = dnode_get (node);
705 struct area_addr *area_addr;
706 char nlpidstr[2];
707 int i;
708 struct listnode *lnode;
709 struct is_neigh *is_neigh;
710 struct te_is_neigh *te_is_neigh;
711 struct ipv4_reachability *ipv4_reach;
712 struct in_addr *ipv4_addr;
713 struct te_ipv4_reachability *te_ipv4_reach;
714#ifdef HAVE_IPV6
715 struct ipv6_reachability *ipv6_reach;
716 struct in6_addr in6;
717#endif
718 u_char LSPid[255];
719 u_char hostname[255];
720 u_char buff[BUFSIZ];
721 u_int32_t now,helper;
722 u_char ipv4_reach_prefix[20];
723 u_char ipv4_reach_mask[20];
724 u_char ipv4_address[20];
725
726 lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
727 lsp_print(node, vty, dynhost);
728
729 /* for all area address */
730 if (lsp->tlv_data.area_addrs) {
731 LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode) {
732 vty_out (vty, " Area Address: %s%s",
733 isonet_print (area_addr->area_addr, area_addr->addr_len),
734 VTY_NEWLINE);
735 }
736 }
737
738 /* for the nlpid tlv */
739 if (lsp->tlv_data.nlpids) {
740 for (i = 0; i < lsp->tlv_data.nlpids->count; i++) {
741 switch (lsp->tlv_data.nlpids->nlpids[i]) {
742 case NLPID_IP:
743 case NLPID_IPV6:
744 vty_out (vty, " NLPID: 0x%X%s",
745 lsp->tlv_data.nlpids->nlpids[i],
746 VTY_NEWLINE);
747 break;
748 default:
749 vty_out (vty, " NLPID: %s%s",
750 "unknown",
751 VTY_NEWLINE);
752 break;
753 }
754 }
755 }
756
757 /* for the hostname tlv */
758 if (lsp->tlv_data.hostname) {
759 bzero (hostname, sizeof (hostname));
760 memcpy (hostname, lsp->tlv_data.hostname->name,
761 lsp->tlv_data.hostname->namelen);
762 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
763 }
764
765 if (lsp->tlv_data.ipv4_addrs) {
766 LIST_LOOP(lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode) {
hasso2097cd82003-12-23 11:51:08 +0000767 memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address));
jardineb5d44e2003-12-23 08:09:43 +0000768 vty_out (vty, " IP: %s%s",
769 ipv4_address,
770 VTY_NEWLINE);
771 }
772 }
773
774 /* for the internal reachable tlv */
775 if (lsp->tlv_data.ipv4_int_reachs)
776 LIST_LOOP(lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode) {
777 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), sizeof (ipv4_reach_prefix));
778 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask), sizeof (ipv4_reach_mask));
hasso2097cd82003-12-23 11:51:08 +0000779 vty_out (vty, " Metric: %d IP %s %s%s",
780 ipv4_reach->metrics.metric_default,
781 ipv4_reach_prefix,
782 ipv4_reach_mask,
783 VTY_NEWLINE);
784 }
785
786 /* for the external reachable tlv */
787 if (lsp->tlv_data.ipv4_ext_reachs)
788 LIST_LOOP(lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode) {
789 memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), sizeof (ipv4_reach_prefix));
790 memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask), sizeof (ipv4_reach_mask));
791 vty_out (vty, " Metric: %d IP-External %s %s%s",
jardineb5d44e2003-12-23 08:09:43 +0000792 ipv4_reach->metrics.metric_default,
793 ipv4_reach_prefix,
794 ipv4_reach_mask,
795 VTY_NEWLINE);
796 }
797
798 /* for the IS neighbor tlv */
799 if (lsp->tlv_data.is_neighs) {
800 LIST_LOOP(lsp->tlv_data.is_neighs,is_neigh,lnode) {
801 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
802 vty_out (vty, " Metric: %d IS %s%s",
803 is_neigh->metrics.metric_default,
804 LSPid,
805 VTY_NEWLINE);
806 }
807 }
808
hasso2097cd82003-12-23 11:51:08 +0000809 /* IPv6 tlv */
810#ifdef HAVE_IPV6
811 if (lsp->tlv_data.ipv6_reachs)
812 LIST_LOOP(lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode) {
813 memset(&in6, 0, sizeof(in6));
814 memcpy (in6.s6_addr, ipv6_reach->prefix, PSIZE(ipv6_reach->prefix_len));
815 inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
816 if ((ipv6_reach->control_info &&
817 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
818 vty_out (vty, " Metric: %d IPv6-Intern %s/%d%s",
819 ntohl (ipv6_reach->metric),
820 buff,
821 ipv6_reach->prefix_len,
822 VTY_NEWLINE);
823 else
824 vty_out (vty, " Metric: %d IPv6-Extern %s/%d%s",
825 ntohl (ipv6_reach->metric),
826 buff,
827 ipv6_reach->prefix_len,
828 VTY_NEWLINE);
829 }
830#endif
831
jardineb5d44e2003-12-23 08:09:43 +0000832/* FIXME: Other tlvs such as te or external tlv will be added later */
833#if 0
834 vty_out (vty, "%s %s %c%s",
835 VTY_NEWLINE,
836 LSPid,
837 lsp->own_lsp ? '*' : ' ',
838 VTY_NEWLINE);
839
840 vty_out (vty, " Sequence: 0x%08x Checksum: 0x%04x Lifetime: ",
841 ntohl (lsp->lsp_header->seq_num),
842 ntohs (lsp->lsp_header->checksum));
843
844 if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
845 vty_out (vty, " (%2u) ", lsp->age_out);
846 else
847 vty_out (vty, "%5u ", ntohs (lsp->lsp_header->rem_lifetime));
848
849 vty_out (vty, "%s Attributes:%s",
850 VTY_NEWLINE,
851 lsp_bits2string (&lsp->lsp_header->lsp_bits));
852
853 /* if this is a self originated LSP then print
854 * the generation time plus when we sent it last
855 * if it is a non self-originated LSP then print the
856 * time when the LSP has been installed
857 */
858
859 if (lsp->own_lsp) {
860
861 now = time (NULL);
862 helper = now - lsp->last_generated;
863 if (!lsp->last_generated)
864 helper = 0;
865
866 vty_out (vty, ", Generated: %s ago",
867 time2string (helper));
868
869 now = time (NULL);
870 helper = now - lsp->last_sent;
871 if (!lsp->last_sent)
872 helper = 0;
873
874 vty_out (vty, ", Last sent: %s ago",
875 time2string (helper));
876 } else {
877 now = time (NULL);
878 helper = now - lsp->installed;
879 if (!lsp->installed)
880 helper = 0;
881
882 vty_out (vty, ", Installed: %s ago",
883 time2string (helper));
884
885 }
886
887 vty_out (vty, "%s", VTY_NEWLINE);
888
889 if (lsp->tlv_data.nlpids) {
890 vty_out (vty, " Speaks: %s%s", nlpid2string (lsp->tlv_data.nlpids),
891 VTY_NEWLINE);
892 }
893
894 if (lsp->tlv_data.router_id) {
895 vty_out (vty, " Router ID: %s%s",
896 inet_ntoa (lsp->tlv_data.router_id->id), VTY_NEWLINE);
897 }
898
899 if (lsp->tlv_data.is_neighs)
900 LIST_LOOP(lsp->tlv_data.is_neighs,is_neigh,lnode) {
901 lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
902 vty_out (vty, " IS %s, Metric: %d%s",
903 LSPid,
904 is_neigh->metrics.metric_default,
905 VTY_NEWLINE);
906 }
907
908 if (lsp->tlv_data.te_is_neighs)
909 LIST_LOOP(lsp->tlv_data.te_is_neighs,te_is_neigh,lnode) {
910 /* FIXME: metric display is wrong */
911 lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
912 vty_out (vty, " extd-IS %s, Metric: %d%s",
913 LSPid,
914 te_is_neigh->te_metric[0],
915 VTY_NEWLINE);
916 }
917
918 if (lsp->tlv_data.ipv4_int_reachs)
919 LIST_LOOP(lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode) {
920 vty_out (vty, " int-IP %s/%d, Metric: %d%s",
921 inet_ntoa (ipv4_reach->prefix),
922 ip_masklen (ipv4_reach->mask),
923 ipv4_reach->metrics.metric_default,
924 VTY_NEWLINE);
925 }
926
927 if (lsp->tlv_data.ipv4_ext_reachs)
928 LIST_LOOP(lsp->tlv_data.ipv4_ext_reachs,ipv4_reach,lnode) {
929 vty_out (vty, " ext-IP %s/%d, Metric: %d%s",
930 inet_ntoa(ipv4_reach->prefix),
931 ip_masklen(ipv4_reach->mask),
932 ipv4_reach->metrics.metric_default,
933 VTY_NEWLINE);
934 }
935
936 if (lsp->tlv_data.te_ipv4_reachs)
937 LIST_LOOP(lsp->tlv_data.te_ipv4_reachs,te_ipv4_reach,lnode) {
938 vty_out (vty, " extd-IP %s/%d, Metric: %d%s",
939 inet_ntoa ( newprefix2inaddr (&te_ipv4_reach->prefix_start,
940 te_ipv4_reach->control)),
941 te_ipv4_reach->control & 0x3F,
942 ntohl (te_ipv4_reach->te_metric),
943 VTY_NEWLINE);
944 }
945
946#ifdef HAVE_IPV6
947 if (lsp->tlv_data.ipv6_reachs)
948 LIST_LOOP(lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode) {
949 memcpy (in6.s6_addr, ipv6_reach->prefix, 16);
950 inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
951 if ((ipv6_reach->control_info &&
952 CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
953 vty_out (vty, " int-IPv6 %s/%d, Metric: %d%s",
954 buff,
955 ipv6_reach->prefix_len,
956 ntohl (ipv6_reach->metric),
957 VTY_NEWLINE);
958 else
959 vty_out (vty, " ext-IPv6 %s/%d, Metric: %d%s",
960 buff,
961 ipv6_reach->prefix_len,
962 ntohl (ipv6_reach->metric),
963 VTY_NEWLINE);
964
965 }
966#endif
967 if (lsp->tlv_data.hostname) {
968 memset (hostname, 0, sizeof (hostname));
969 memcpy (hostname, lsp->tlv_data.hostname->name,
970 lsp->tlv_data.hostname->namelen);
971 vty_out (vty, " Hostname: %s%s", hostname, VTY_NEWLINE);
972 }
973#endif
974 return;
975}
976
977/* print all the lsps info in the local lspdb */
978int
979lsp_print_all (struct vty *vty, dict_t *lspdb, char detail, char dynhost)
980{
981
982 dnode_t *node = dict_first(lspdb), *next;
983 int lsp_count = 0;
984
985 /* print the title, for both modes */
986 vty_out (vty, "LSP ID LSP Seq Num LSP Checksum "
987 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
988
989 if (detail == ISIS_UI_LEVEL_BRIEF) {
990 while (node != NULL) {
991 /* dict_contains (lspdb, node); */ /* I think it is unnecessary, so I comment it out */
992 next = dict_next (lspdb, node);
993 lsp_print (node, vty, dynhost);
994 node = next;
995 lsp_count++;
996 }
997 } else if (detail == ISIS_UI_LEVEL_DETAIL) {
998 while (node != NULL) {
999 next = dict_next (lspdb, node);
1000 lsp_print_detail (node, vty, dynhost);
1001 node = next;
1002 lsp_count++;
1003 }
1004 }
1005
1006 return lsp_count;
1007}
1008
1009/* this function reallocate memory to an lsp pdu, with an additional
1010 * size of memory, it scans the lsp and moves all pointers the
1011 * way they should */
1012u_char *
1013lsppdu_realloc (struct isis_lsp *lsp, int memorytype, int size)
1014{
1015 u_char *retval;
1016
1017 retval = STREAM_DATA(lsp->pdu) + ntohs(lsp->lsp_header->pdu_len);
1018#ifdef LSP_MEMORY_PREASSIGN
1019 lsp->lsp_header->pdu_len = htons(ntohs(lsp->lsp_header->pdu_len) + size);
1020 return retval;
1021#else /* otherwise we have to move all pointers */
1022 u_char *newpdu;
1023 newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
1024 memcpy (STREAM_DATA (newpdu), STREAM_DATA(lsp->pdu),
1025 ntohs (lsp->lsp_header->pdu_len));
1026 XFREE (memorytype, lsp->pdu);
1027 lsp->pdu = newpdu;
1028 lsp->isis_header = (struct isis_fixed_hdr*)STREAM_DATA(lsp->pdu);
1029 lsp->lsp_header = (struct isis_link_state_hdr*)
1030 (STREAM_DATA(lsp->pdu) + ISIS_FIXED_HDR_LEN);
1031 htons (ntohs (lsp->lsp_header->pdu_len) += size);
1032 return STREAM_DATA(lsp->pdu) + (lsp->lsp_header->pdu_len - size);
1033#endif /* LSP_MEMORY_PREASSIGN */
1034}
1035
1036
1037#if 0 /* Saving the old one just in case :) */
1038/*
1039 * Builds the lsp->tlv_data
1040 * and writes the tlvs into lsp->pdu
1041 */
1042void
1043lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1044{
1045 struct is_neigh *is_neigh;
1046 struct listnode *node, *ipnode;
1047 int level = lsp->level;
1048 struct isis_circuit *circuit;
1049 struct prefix_ipv4 *ipv4;
1050 struct ipv4_reachability *ipreach;
1051 struct isis_adjacency *nei;
1052#ifdef HAVE_IPV6
1053 struct prefix_ipv6 *ipv6;
1054 struct ipv6_reachability *ip6reach;
1055#endif /* HAVE_IPV6 */
1056
1057 /*
1058 * First add the tlvs related to area
1059 */
1060
1061 /* Area addresses */
1062 if (lsp->tlv_data.area_addrs == NULL)
1063 lsp->tlv_data.area_addrs = list_new ();
1064 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1065 /* Protocols Supported */
1066 if (area->ip_circuits > 0
1067#ifdef HAVE_IPV6
1068 || area->ipv6_circuits > 0
1069#endif /* HAVE_IPV6 */
1070 )
1071 {
1072 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1073 lsp->tlv_data.nlpids->count = 0;
1074 if (area->ip_circuits > 0) {
1075 lsp->tlv_data.nlpids->count++;
1076 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1077 }
1078#ifdef HAVE_IPV6
1079 if (area->ipv6_circuits > 0) {
1080 lsp->tlv_data.nlpids->count++;
1081 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1082 NLPID_IPV6;
1083 }
1084#endif /* HAVE_IPV6 */
1085 }
1086 /* Dynamic Hostname */
1087 if (area->dynhostname) {
1088 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1089 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001090 memcpy (&lsp->tlv_data.hostname->name, unix_hostname(),
1091 strlen(unix_hostname()));
1092 lsp->tlv_data.hostname->namelen = strlen (unix_hostname());
jardineb5d44e2003-12-23 08:09:43 +00001093 }
1094#ifdef TOPOLOGY_GENERATE
1095 /*
1096 * If we have a topology in this area, we need to connect this lsp to
1097 * the first topology lsp
1098 */
1099 if ((area->topology) && (level == 1)) {
1100 if (lsp->tlv_data.is_neighs == NULL)
1101 lsp->tlv_data.is_neighs = list_new ();
1102 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1103 memset (is_neigh, 0, sizeof (struct is_neigh));
1104 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
1105 /* connected to the first */
1106 is_neigh->neigh_id[ISIS_SYS_ID_LEN-1] = (0x01);
1107 /* this is actually the same system, why mess the SPT */
1108 is_neigh->metrics.metric_default = 0;
1109 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
1110 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
1111 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
1112 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1113
1114 }
1115#endif
1116
1117 /*
1118 * Then add tlvs related to circuits
1119 */
1120 for (node = listhead (area->circuit_list); node; nextnode (node)) {
1121 circuit = getdata (node);
1122 if (circuit->state != C_STATE_UP)
1123 continue;
1124
1125 /*
1126 * Add IPv4 internal reachability of this circuit
1127 */
1128 if (circuit->ip_router && circuit->ip_addrs &&
1129 circuit->ip_addrs->count > 0) {
1130 if (lsp->tlv_data.ipv4_int_reachs == NULL) {
1131 lsp->tlv_data.ipv4_int_reachs = list_new ();
1132 lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
1133 }
1134 for (ipnode = listhead (circuit->ip_addrs); ipnode; nextnode (ipnode)) {
1135 ipv4 = getdata (ipnode);
1136 ipreach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1137 ipreach->metrics = circuit->metrics[level - 1];
1138 ipreach->prefix = ipv4->prefix;
1139 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1140 listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
1141 }
1142 }
1143#ifdef HAVE_IPV6
1144 /*
1145 * Add IPv6 reachability of this circuit
1146 */
1147 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1148 circuit->ipv6_non_link->count > 0) {
1149 if (lsp->tlv_data.ipv6_reachs == NULL) {
1150 lsp->tlv_data.ipv6_reachs = list_new ();
1151 lsp->tlv_data.ipv6_reachs->del = free_tlv;
1152 }
1153 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1154 nextnode (ipnode)) {
1155 ipv6 = getdata (ipnode);
1156 ip6reach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1157 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1158 ip6reach->metric = htonl(circuit->metrics[level - 1].metric_default);
1159 ip6reach->control_info = 0;
1160 ip6reach->prefix_len = ipv6->prefixlen;
1161 memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr,
1162 (ipv6->prefixlen + 7) / 8);
1163 listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
1164 }
1165 }
1166#endif /* HAVE_IPV6 */
1167
1168 switch (circuit->circ_type) {
1169 case CIRCUIT_T_BROADCAST:
1170 if (level & circuit->circuit_is_type) {
1171 if (lsp->tlv_data.is_neighs == NULL) {
1172 lsp->tlv_data.is_neighs = list_new ();
1173 lsp->tlv_data.is_neighs->del = free_tlv;
1174 }
1175 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1176 memset (is_neigh, 0, sizeof (struct is_neigh));
1177 if (level == 1)
1178 memcpy (&is_neigh->neigh_id,
1179 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1180 else
1181 memcpy (&is_neigh->neigh_id,
1182 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1183 is_neigh->metrics = circuit->metrics[level - 1];
1184 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1185 }
1186 break;
1187 case CIRCUIT_T_P2P:
1188 nei = circuit->u.p2p.neighbor;
1189 if (nei && (level & nei->circuit_t)) {
1190 if (lsp->tlv_data.is_neighs == NULL) {
1191 lsp->tlv_data.is_neighs = list_new ();
1192 lsp->tlv_data.is_neighs->del = free_tlv;
1193 }
1194 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1195 memset (is_neigh, 0, sizeof (struct is_neigh));
1196 memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1197 is_neigh->metrics = circuit->metrics[level - 1];
1198 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1199 }
1200 break;
1201 case CIRCUIT_T_STATIC_IN:
1202 zlog_warn ("lsp_area_create: unsupported circuit type");
1203 break;
1204 case CIRCUIT_T_STATIC_OUT:
1205 zlog_warn ("lsp_area_create: unsupported circuit type");
1206 break;
1207 case CIRCUIT_T_DA:
1208 zlog_warn ("lsp_area_create: unsupported circuit type");
1209 break;
1210 default:
1211 zlog_warn ("lsp_area_create: unknown circuit type");
1212 }
1213 }
1214
1215 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1216
1217 if (lsp->tlv_data.nlpids)
1218 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1219 if (lsp->tlv_data.hostname)
1220 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
1221 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0 )
1222 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1223 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1224 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1225 if (lsp->tlv_data.ipv4_int_reachs &&
1226 listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
1227 tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
1228#ifdef HAVE_IPV6
1229 if (lsp->tlv_data.ipv6_reachs &&
1230 listcount (lsp->tlv_data.ipv6_reachs) > 0)
1231 tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
1232#endif /* HAVE_IPV6 */
1233
1234 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1235
1236 return;
1237}
1238#endif
1239
1240#define FRAG_THOLD(S,T) \
1241((STREAM_SIZE(S)*T)/100)
1242
1243/* stream*, area->lsp_frag_threshold, increment */
1244#define FRAG_NEEDED(S,T,I) \
1245 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
1246
1247void
1248lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
1249 int tlvsize, int frag_thold,
1250 int tlv_build_func(struct list *, struct stream *))
1251{
1252 int count, i;
1253
1254 /* can we fit all ? */
1255 if (!FRAG_NEEDED(lsp->pdu, frag_thold,
1256 listcount(*from) * tlvsize + 2)) {
1257 tlv_build_func (*from, lsp->pdu);
1258 *to = *from;
1259 *from = NULL;
1260 } else if (!FRAG_NEEDED(lsp->pdu, frag_thold, tlvsize + 2)) {
1261 /* fit all we can */
1262 count = FRAG_THOLD(lsp->pdu,frag_thold) - 2 -
1263 (STREAM_SIZE(lsp->pdu) - STREAM_REMAIN(lsp->pdu));
1264 if (count)
1265 count = count / tlvsize;
1266 for (i = 0; i < count; i++) {
1267 listnode_add (*to, getdata(listhead(*from)));
1268 listnode_delete(*from, getdata(listhead(*from)));
1269 }
1270 tlv_build_func (*to, lsp->pdu);
1271 }
1272 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1273 return;
1274}
1275
1276struct isis_lsp *
1277lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area,
1278 int level )
1279{
1280 struct isis_lsp *lsp;
1281 u_char frag_id[ISIS_SYS_ID_LEN + 2];
1282
1283 memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
1284 LSP_FRAGMENT (frag_id) = frag_num;
1285 lsp = lsp_search (frag_id, area->lspdb[level - 1]);
1286 if (lsp) {
1287 /*
1288 * Clear the TLVs, but inherit the authinfo
1289 */
1290 lsp_clear_data (lsp);
1291 if (lsp0->tlv_data.auth_info.type) {
1292 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1293 sizeof (struct isis_passwd));
1294 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1295 lsp->tlv_data.auth_info.len,
1296 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1297 }
1298 return lsp;
1299 }
1300 lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
1301 0, level);
1302 lsp->own_lsp = 1;
1303 lsp_insert (lsp, area->lspdb[level-1]);
1304 listnode_add (lsp0->lspu.frags, lsp);
1305 lsp->lspu.zero_lsp = lsp0;
1306 /*
1307 * Copy the authinfo from zero LSP
1308 */
1309 if (lsp0->tlv_data.auth_info.type) {
1310 memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info,
1311 sizeof (struct isis_passwd));
1312 tlv_add_authinfo (lsp->tlv_data.auth_info.type,
1313 lsp->tlv_data.auth_info.len,
1314 lsp->tlv_data.auth_info.passwd, lsp->pdu);
1315 }
1316 return lsp;
1317}
1318
1319/*
1320 * Builds the LSP data part. This func creates a new frag whenever
1321 * area->lsp_frag_threshold is exceeded.
1322 */
1323#if 1
1324void
1325lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
1326{
1327 struct is_neigh *is_neigh;
1328 struct listnode *node, *ipnode;
1329 int level = lsp->level;
1330 struct isis_circuit *circuit;
1331 struct prefix_ipv4 *ipv4;
1332 struct ipv4_reachability *ipreach;
1333 struct isis_adjacency *nei;
1334#ifdef HAVE_IPV6
1335 struct prefix_ipv6 *ipv6;
1336 struct ipv6_reachability *ip6reach;
1337#endif /* HAVE_IPV6 */
1338 struct tlvs tlv_data;
1339 struct isis_lsp *lsp0 = lsp;
1340 struct isis_passwd *passwd;
1341
1342 /*
1343 * First add the tlvs related to area
1344 */
1345
1346 /* Area addresses */
1347 if (lsp->tlv_data.area_addrs == NULL)
1348 lsp->tlv_data.area_addrs = list_new ();
1349 list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
1350 /* Protocols Supported */
1351 if (area->ip_circuits > 0
1352#ifdef HAVE_IPV6
1353 || area->ipv6_circuits > 0
1354#endif /* HAVE_IPV6 */
1355 )
1356 {
1357 lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
1358 lsp->tlv_data.nlpids->count = 0;
1359 if (area->ip_circuits > 0) {
1360 lsp->tlv_data.nlpids->count++;
1361 lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
1362 }
1363#ifdef HAVE_IPV6
1364 if (area->ipv6_circuits > 0) {
1365 lsp->tlv_data.nlpids->count++;
1366 lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] =
1367 NLPID_IPV6;
1368 }
1369#endif /* HAVE_IPV6 */
1370 }
1371 /* Dynamic Hostname */
1372 if (area->dynhostname) {
1373 lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV,
1374 sizeof (struct hostname));
jardin9e867fe2003-12-23 08:56:18 +00001375
1376 memcpy (lsp->tlv_data.hostname->name, unix_hostname(),
1377 strlen (unix_hostname()));
1378 lsp->tlv_data.hostname->namelen = strlen (unix_hostname());
jardineb5d44e2003-12-23 08:09:43 +00001379 }
1380
1381 /*
1382 * Building the zero lsp
1383 */
1384 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1385 /*
1386 * Add the authentication info if its present
1387 */
1388 (level == 1) ? (passwd = &area->area_passwd) :
1389 (passwd = &area->domain_passwd);
1390 if (passwd->type) {
1391 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1392 tlv_add_authinfo (passwd->type, passwd->len,
1393 passwd->passwd, lsp->pdu);
1394 }
1395 if (lsp->tlv_data.nlpids)
1396 tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
1397 if (lsp->tlv_data.hostname)
1398 tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
1399 if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0 )
1400 tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
1401
1402 memset (&tlv_data, 0, sizeof (struct tlvs));
1403 /*
1404 * Then build lists of tlvs related to circuits
1405 */
1406 for (node = listhead (area->circuit_list); node; nextnode (node)) {
1407 circuit = getdata (node);
1408 if (circuit->state != C_STATE_UP)
1409 continue;
1410
1411 /*
1412 * Add IPv4 internal reachability of this circuit
1413 */
1414 if (circuit->ip_router && circuit->ip_addrs &&
1415 circuit->ip_addrs->count > 0) {
1416 if (tlv_data.ipv4_int_reachs == NULL) {
1417 tlv_data.ipv4_int_reachs = list_new ();
1418 }
1419 for (ipnode = listhead (circuit->ip_addrs); ipnode; nextnode (ipnode)) {
1420 ipv4 = getdata (ipnode);
1421 ipreach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
1422 ipreach->metrics = circuit->metrics[level - 1];
1423 ipreach->prefix = ipv4->prefix;
1424 masklen2ip (ipv4->prefixlen, &ipreach->mask);
1425 listnode_add (tlv_data.ipv4_int_reachs, ipreach);
1426 }
1427
1428 }
1429#ifdef HAVE_IPV6
1430 /*
1431 * Add IPv6 reachability of this circuit
1432 */
1433 if (circuit->ipv6_router && circuit->ipv6_non_link &&
1434 circuit->ipv6_non_link->count > 0) {
1435
1436 if (tlv_data.ipv6_reachs == NULL) {
1437 tlv_data.ipv6_reachs = list_new ();
1438 }
1439 for (ipnode = listhead (circuit->ipv6_non_link); ipnode;
1440 nextnode (ipnode)) {
1441 ipv6 = getdata (ipnode);
1442 ip6reach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
1443 memset (ip6reach, 0, sizeof (struct ipv6_reachability));
1444 ip6reach->metric = htonl(circuit->metrics[level - 1].metric_default);
1445 ip6reach->control_info = 0;
1446 ip6reach->prefix_len = ipv6->prefixlen;
1447 memcpy (ip6reach->prefix, ipv6->prefix.s6_addr,
1448 (ipv6->prefixlen + 7) / 8);
1449 listnode_add (tlv_data.ipv6_reachs, ip6reach);
1450 }
1451 }
1452#endif /* HAVE_IPV6 */
1453
1454 switch (circuit->circ_type) {
1455 case CIRCUIT_T_BROADCAST:
1456 if (level & circuit->circuit_is_type) {
1457 if (tlv_data.is_neighs == NULL) {
1458 tlv_data.is_neighs = list_new ();
1459 }
1460 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1461 memset (is_neigh, 0, sizeof (struct is_neigh));
1462 if (level == 1)
1463 memcpy (is_neigh->neigh_id,
1464 circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
1465 else
1466 memcpy (is_neigh->neigh_id,
1467 circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
1468 is_neigh->metrics = circuit->metrics[level - 1];
1469 listnode_add (tlv_data.is_neighs, is_neigh);
1470 }
1471 break;
1472 case CIRCUIT_T_P2P:
1473 nei = circuit->u.p2p.neighbor;
1474 if (nei && (level & nei->circuit_t)) {
1475 if (tlv_data.is_neighs == NULL) {
1476 tlv_data.is_neighs = list_new ();
1477 tlv_data.is_neighs->del = free_tlv;
1478 }
1479 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1480 memset (is_neigh, 0, sizeof (struct is_neigh));
1481 memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
1482 is_neigh->metrics = circuit->metrics[level - 1];
1483 listnode_add (tlv_data.is_neighs, is_neigh);
1484 }
1485 break;
1486 case CIRCUIT_T_STATIC_IN:
1487 zlog_warn ("lsp_area_create: unsupported circuit type");
1488 break;
1489 case CIRCUIT_T_STATIC_OUT:
1490 zlog_warn ("lsp_area_create: unsupported circuit type");
1491 break;
1492 case CIRCUIT_T_DA:
1493 zlog_warn ("lsp_area_create: unsupported circuit type");
1494 break;
1495 default:
1496 zlog_warn ("lsp_area_create: unknown circuit type");
1497 }
1498 }
1499
1500 while (tlv_data.ipv4_int_reachs && listcount(tlv_data.ipv4_int_reachs)) {
1501 if (lsp->tlv_data.ipv4_int_reachs == NULL)
1502 lsp->tlv_data.ipv4_int_reachs = list_new ();
1503 lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs,
1504 &lsp->tlv_data.ipv4_int_reachs,
1505 IPV4_REACH_LEN, area->lsp_frag_threshold,
1506 tlv_add_ipv4_reachs);
1507 if (tlv_data.ipv4_int_reachs && listcount(tlv_data.ipv4_int_reachs))
1508 lsp = lsp_next_frag (LSP_FRAGMENT(lsp->lsp_header->lsp_id) + 1,
1509 lsp0, area, level);
1510 }
1511
1512#ifdef HAVE_IPV6
1513 while (tlv_data.ipv6_reachs && listcount(tlv_data.ipv6_reachs)) {
1514 if (lsp->tlv_data.ipv6_reachs == NULL)
1515 lsp->tlv_data.ipv6_reachs = list_new ();
1516 lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs,
1517 &lsp->tlv_data.ipv6_reachs,
1518 IPV6_REACH_LEN, area->lsp_frag_threshold,
1519 tlv_add_ipv6_reachs);
1520 if (tlv_data.ipv6_reachs && listcount(tlv_data.ipv6_reachs))
1521 lsp = lsp_next_frag (LSP_FRAGMENT(lsp->lsp_header->lsp_id) + 1,
1522 lsp0, area, level);
1523 }
1524#endif /* HAVE_IPV6 */
1525
1526 while (tlv_data.is_neighs && listcount(tlv_data.is_neighs)) {
1527 if (lsp->tlv_data.is_neighs == NULL)
1528 lsp->tlv_data.is_neighs = list_new ();
1529 lsp_tlv_fit (lsp, &tlv_data.is_neighs,
1530 &lsp->tlv_data.is_neighs,
1531 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold,
1532 tlv_add_is_neighs);
1533 if (tlv_data.is_neighs && listcount(tlv_data.is_neighs))
1534 lsp = lsp_next_frag (LSP_FRAGMENT(lsp->lsp_header->lsp_id) + 1,
1535 lsp0, area, level);
1536 }
1537
1538
1539 return;
1540}
1541#endif
1542
1543void
1544build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
1545{
1546 struct list *circuit_list = area->circuit_list;
1547 struct isis_circuit *circuit;
1548 u_char *tlv_ptr;
1549 struct is_neigh *is_neigh;
1550
1551
1552 /* add our nlpids */
1553 /* the 2 is for the TL plus 1 for the nlpid*/
1554 tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 3);
1555 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
1556 *(tlv_ptr+1) = 1; /* one protocol */
1557#ifdef HAVE_IPV6 /*dunno if its right*/
1558 *(tlv_ptr+2) = NLPID_IPV6;
1559#else
1560 *(tlv_ptr+2) = NLPID_IP;
1561#endif /* HAVE_IPV6 */
1562
1563 /* we should add our areas here
1564 * FIXME: we need to figure out which should be added? Adj? All? First? */
1565
1566 /* first, lets add ourselves to the IS neighbours info */
1567 /* the 2 is for the TL plus 1 for the virtual field*/
1568 tlv_ptr = lsppdu_realloc(lsp,MTYPE_ISIS_TLV, 3);
1569 *tlv_ptr = IS_NEIGHBOURS; /* Type */
1570 *(tlv_ptr+2) = 0; /* virtual is zero */
1571 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
1572 /* assign space for the is_neigh at the pdu end */
1573 is_neigh = (struct is_neigh*) lsppdu_realloc(lsp,MTYPE_ISIS_TLV,
1574 sizeof(struct is_neigh));
1575 /* add this node to our list */
1576 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1577 /* FIXME: Do we need our designated address here? */
1578 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1);
1579 /* FIXME: Where should we really get our own LSPs metrics from? */
1580 circuit = (struct isis_circuit*)listhead(circuit_list);
1581 /* is_neigh->metrics = circuit->metrics[lsp->level -1];*/
1582 /* Length */
1583 *(tlv_ptr+1)=(lsp->tlv_data.is_neighs->count * sizeof(struct is_neigh) +1);
1584
1585 /* FIXME: scan for adjencecies and add them */
1586
1587 /* FIXME: add reachability info */
1588
1589 /* adding dynamic hostname if needed*/
1590 if (area->dynhostname) {
1591 tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
1592 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
jardin9e867fe2003-12-23 08:56:18 +00001593 *(tlv_ptr+1) = strlen (unix_hostname()); /* Length */
jardineb5d44e2003-12-23 08:09:43 +00001594 lsp->tlv_data.hostname = (struct hostname *)
1595 (lsppdu_realloc(lsp,
1596 MTYPE_ISIS_TLV,
1597 /* the -1 is to fit the length in the struct */
jardin9e867fe2003-12-23 08:56:18 +00001598 strlen (unix_hostname())) - 1);
1599 memcpy (lsp->tlv_data.hostname->name, unix_hostname(),
1600 strlen(unix_hostname()));
jardineb5d44e2003-12-23 08:09:43 +00001601 }
1602
1603}
1604
1605/*
1606 * 7.3.7 Generation on non-pseudonode LSPs
1607 */
1608int
1609lsp_generate_non_pseudo (struct isis_area *area, int level) {
1610
1611 struct isis_lsp *oldlsp, *newlsp;
1612 u_int32_t seq_num = 0;
1613 u_char lspid[ISIS_SYS_ID_LEN + 2];
1614
1615 memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
1616 memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);
1617
1618 /* only builds the lsp if the area shares the level */
1619 if ((area->is_type & level) == level) {
1620 oldlsp = lsp_search (lspid, area->lspdb[level-1]);
1621 if (oldlsp) {
1622 seq_num = ntohl (oldlsp->lsp_header->seq_num);
1623 lsp_search_and_destroy (oldlsp->lsp_header->lsp_id,
1624 area->lspdb[level-1]);
1625 /* FIXME: we should actually initiate a purge */
1626 }
1627 newlsp = lsp_new (lspid, area->max_lsp_lifetime[level-1], seq_num,
1628 area->is_type, 0, level);
1629 newlsp->own_lsp = 1;
1630
1631 lsp_insert (newlsp, area->lspdb[level-1]);
1632 /* build_lsp_data (newlsp, area); */
1633 lsp_build_nonpseudo (newlsp, area);
1634 /* time to calculate our checksum */
1635 lsp_seqnum_update (newlsp);
1636 }
1637
1638
1639 /* DEBUG_ADJ_PACKETS */
1640 if (isis->debugs & DEBUG_ADJ_PACKETS) {
1641 /* FIXME: is this place right? fix missing info */
1642 zlog_info ("ISIS-Upd (%s): Building L%d LSP",
1643 area->area_tag, level);
1644 }
1645
1646 return ISIS_OK;
1647}
1648
1649/*
1650 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1651 */
1652int
1653lsp_l1_generate (struct isis_area *area)
1654{
hassod70f99e2004-02-11 20:26:31 +00001655 THREAD_TIMER_ON(master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
jardineb5d44e2003-12-23 08:09:43 +00001656 MAX_LSP_GEN_INTERVAL);
1657
1658 return lsp_generate_non_pseudo (area, 1);
1659}
1660
1661
1662/*
1663 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1664 */
1665int
1666lsp_l2_generate (struct isis_area *area)
1667{
hassod70f99e2004-02-11 20:26:31 +00001668 THREAD_TIMER_ON(master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
jardineb5d44e2003-12-23 08:09:43 +00001669 MAX_LSP_GEN_INTERVAL);
1670
1671 return lsp_generate_non_pseudo (area, 2);
1672}
1673
1674int
1675lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1676{
1677 dict_t *lspdb = area->lspdb[level - 1];
1678 struct isis_lsp *lsp, *frag;
1679 struct listnode *node;
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 lsp = lsp_search (lspid, lspdb);
1686
1687 if (!lsp) {
1688 zlog_err ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1689 area->area_tag,
1690 level);
1691
1692 return ISIS_ERROR;
1693 }
1694
1695 lsp_clear_data (lsp);
1696 lsp_build_nonpseudo (lsp, area);
1697 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1698 (area->max_lsp_lifetime[level-1],
1699 MAX_AGE_JITTER));
1700 lsp_seqnum_update (lsp);
1701
1702 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1703 zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1704 "seq 0x%08x, cksum 0x%04x lifetime %us",
1705 area->area_tag,
1706 level,
1707 rawlspid_print (lsp->lsp_header->lsp_id),
1708 ntohl(lsp->lsp_header->seq_num),
1709 ntohs(lsp->lsp_header->checksum),
1710 ntohs(lsp->lsp_header->rem_lifetime));
1711 }
1712
1713 lsp->last_generated = time (NULL);
1714 area->lsp_regenerate_pending[level - 1] = 0;
1715 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1716 for (node = listhead (lsp->lspu.frags); node; nextnode(node)) {
1717 frag = getdata (node);
1718 frag->lsp_header->rem_lifetime = htons (isis_jitter
1719 (area->max_lsp_lifetime[level-1],
1720 MAX_AGE_JITTER));
1721 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1722 }
1723
1724 if (area->ip_circuits)
1725 isis_spf_schedule (area, level);
1726#ifdef HAVE_IPV6
1727 if (area->ipv6_circuits)
1728 isis_spf_schedule6 (area, level);
1729#endif
1730 return ISIS_OK;
1731}
1732
1733
1734/*
1735 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1736 * time and set SRM
1737 */
1738int
1739lsp_refresh_l1 (struct thread *thread)
1740{
1741 struct isis_area *area;
1742 unsigned long ref_time;
1743
1744 area = THREAD_ARG (thread);
1745 assert (area);
1746
1747 area->t_lsp_refresh[0] = NULL;
1748 if (area->is_type & IS_LEVEL_1)
1749 lsp_non_pseudo_regenerate (area, 1);
1750
1751 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
1752 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1753
hassod70f99e2004-02-11 20:26:31 +00001754 THREAD_TIMER_ON(master, area->t_lsp_refresh[0], lsp_refresh_l1, area,
1755 isis_jitter(ref_time, MAX_AGE_JITTER));
1756
jardineb5d44e2003-12-23 08:09:43 +00001757 return ISIS_OK;
1758}
1759
1760int
1761lsp_refresh_l2 (struct thread *thread)
1762{
1763 struct isis_area *area;
1764 unsigned long ref_time;
1765
1766 area = THREAD_ARG (thread);
1767 assert (area);
1768
1769 area->t_lsp_refresh[1] = NULL;
1770 if (area->is_type & IS_LEVEL_2)
1771 lsp_non_pseudo_regenerate (area, 2);
1772
1773 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
1774 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1775
hassod70f99e2004-02-11 20:26:31 +00001776 THREAD_TIMER_ON(master, area->t_lsp_refresh[1], lsp_refresh_l2, area,
1777 isis_jitter(ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00001778
jardineb5d44e2003-12-23 08:09:43 +00001779 return ISIS_OK;
1780}
1781
1782
1783/*
1784 * Something has changed -> regenerate LSP
1785 */
1786
1787int
1788lsp_l1_regenerate (struct thread *thread)
1789{
1790 struct isis_area *area;
1791
1792 area = THREAD_ARG (thread);
1793 area->lsp_regenerate_pending[0] = 0;
1794
1795 return lsp_non_pseudo_regenerate (area, 1);
1796}
1797
1798int
1799lsp_l2_regenerate (struct thread *thread)
1800{
1801 struct isis_area *area;
1802
1803 area = THREAD_ARG (thread);
1804 area->lsp_regenerate_pending[1] = 0;
1805
1806 return lsp_non_pseudo_regenerate (area, 2);
1807}
1808
1809int
1810lsp_regenerate_schedule (struct isis_area *area)
1811{
1812 struct isis_lsp *lsp;
1813 u_char id[ISIS_SYS_ID_LEN + 2];
1814 time_t now, diff;
1815 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
1816 LSP_PSEUDO_ID(id) = LSP_FRAGMENT(id) = 0;
1817 now = time (NULL);
1818 /*
1819 * First level 1
1820 */
1821 if (area->is_type & IS_LEVEL_1) {
1822 lsp = lsp_search (id, area->lspdb[0]);
1823 if (!lsp || area->lsp_regenerate_pending[0])
1824 goto L2;
1825 /*
1826 * Throttle avoidance
1827 */
1828 diff = now - lsp->last_generated;
1829 if (diff < MIN_LSP_GEN_INTERVAL) {
1830 area->lsp_regenerate_pending[0] = 1;
1831 thread_add_timer (master, lsp_l1_regenerate, area,
1832 MIN_LSP_GEN_INTERVAL - diff);
1833 return ISIS_OK;
1834 } else
1835 lsp_non_pseudo_regenerate (area, 1);
1836 }
1837 /*
1838 * then 2
1839 */
1840 L2:
1841 if (area->is_type & IS_LEVEL_2) {
1842 lsp = lsp_search (id, area->lspdb[1]);
1843 if (!lsp || area->lsp_regenerate_pending[1])
1844 return ISIS_OK;
1845 /*
1846 * Throttle avoidance
1847 */
1848 diff = now - lsp->last_generated;
1849 if (diff < MIN_LSP_GEN_INTERVAL) {
1850 area->lsp_regenerate_pending[1] = 1;
1851 thread_add_timer (master, lsp_l2_regenerate, area,
1852 MIN_LSP_GEN_INTERVAL - diff);
1853 return ISIS_OK;
1854 } else
1855 lsp_non_pseudo_regenerate (area, 2);
1856 }
1857
1858 return ISIS_OK;
1859}
1860
1861/*
1862 * Funcs for pseudonode LSPs
1863 */
1864
1865/*
1866 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1867 */
1868void
1869lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1870 int level)
1871{
1872 struct isis_adjacency *adj;
1873 struct is_neigh *is_neigh;
1874 struct es_neigh *es_neigh;
1875 struct list *adj_list;
1876 struct listnode *node;
1877 struct isis_passwd *passwd;
1878
1879 assert (circuit);
1880 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
1881
1882 if (!circuit->u.bc.is_dr[level - 1])
1883 return; /* we are not DIS on this circuit */
1884
1885 lsp->level = level;
1886 if (level == 1)
1887 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1888 else
1889 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1890
1891 /*
1892 * add self to IS neighbours
1893 */
1894 if (lsp->tlv_data.is_neighs == NULL) {
1895 lsp->tlv_data.is_neighs = list_new ();
1896 lsp->tlv_data.is_neighs->del = free_tlv;
1897 }
1898 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1899 memset (is_neigh, 0, sizeof (struct is_neigh));
1900 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1901 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1902
1903 adj_list = list_new();
1904 isis_adj_build_up_list (circuit->u.bc.adjdb[level-1], adj_list);
1905
1906 for (node = listhead (adj_list); node; nextnode (node)){
1907 adj = getdata (node);
1908 if (adj->circuit_t & level) {
1909 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1910 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1911 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1912 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) {
1913 /* an IS neighbour -> add it */
1914 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1915 memset (is_neigh, 0, sizeof (struct is_neigh));
1916 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1917 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1918 } else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES) {
1919 /* an ES neigbour add it, if we are building level 1 LSP */
1920 /* FIXME: the tlv-format is hard to use here */
1921 if (lsp->tlv_data.es_neighs == NULL) {
1922 lsp->tlv_data.es_neighs = list_new ();
1923 lsp->tlv_data.es_neighs->del = free_tlv;
1924 }
1925 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1926 memset (es_neigh, 0, sizeof (struct es_neigh));
1927 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
1928 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
1929 }
1930 }
1931 }
1932
1933 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1934 /*
1935 * Add the authentication info if it's present
1936 */
1937 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1938 (passwd = &circuit->area->domain_passwd);
1939 if (passwd->type) {
1940 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1941 tlv_add_authinfo (passwd->type, passwd->len,
1942 passwd->passwd, lsp->pdu);
1943 }
1944
1945 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1946 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1947
1948 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1949 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1950
1951 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1952 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1953 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
1954
1955 list_delete (adj_list);
1956
1957 return;
1958}
1959
1960int
1961lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1962{
1963 dict_t *lspdb = circuit->area->lspdb[level - 1];
1964 struct isis_lsp *lsp;
1965 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
1966
1967 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1968 LSP_PSEUDO_ID(lsp_id) = circuit->circuit_id;
1969 LSP_FRAGMENT(lsp_id) = 0;
1970
1971 lsp = lsp_search (lsp_id, lspdb);
1972
1973 if (!lsp) {
1974 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1975 rawlspid_print(lsp_id));
1976 return ISIS_ERROR;
1977 }
1978 lsp_clear_data (lsp);
1979
1980 lsp_build_pseudo (lsp, circuit, level);
1981
1982 lsp->lsp_header->rem_lifetime =
1983 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
1984 MAX_AGE_JITTER));
1985
1986 lsp_inc_seqnum (lsp, 0);
1987
1988 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1989 zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1990 circuit->area->area_tag, level,
1991 rawlspid_print (lsp->lsp_header->lsp_id));
1992 }
1993
1994 lsp->last_generated = time (NULL);
1995 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1996
1997 return ISIS_OK;
1998}
1999
2000
2001int
2002lsp_l1_refresh_pseudo (struct thread *thread)
2003{
2004 struct isis_circuit *circuit;
2005 int retval;
2006 unsigned long ref_time;
2007
2008 circuit = THREAD_ARG(thread);
2009
2010 if (!circuit->u.bc.is_dr[0])
2011 return ISIS_ERROR; /* FIXME: purge and such */
2012
2013 retval = lsp_pseudo_regenerate (circuit, 1);
2014
2015 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2016 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2017
hassod70f99e2004-02-11 20:26:31 +00002018 THREAD_TIMER_ON(master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2019 lsp_l1_refresh_pseudo, circuit, isis_jitter (ref_time, MAX_AGE_JITTER));
2020
jardineb5d44e2003-12-23 08:09:43 +00002021 return retval;
2022}
2023
2024int
2025lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2026{
2027 struct isis_lsp *lsp;
2028 u_char id[ISIS_SYS_ID_LEN + 2];
2029 unsigned long ref_time;
2030
2031 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
2032 LSP_FRAGMENT(id) = 0;
2033 LSP_PSEUDO_ID(id) = circuit->circuit_id;
2034
2035 /*
2036 * If for some reason have a pseudo LSP in the db already -> regenerate
2037 */
2038 if (lsp_search (id, circuit->area->lspdb[0]))
2039 return lsp_pseudo_regenerate (circuit, 1);
2040 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
2041 1, circuit->area->is_type, 0, 1);
2042
2043 lsp_build_pseudo (lsp, circuit, 1);
2044
2045 lsp->own_lsp = 1;
2046 lsp_insert (lsp, circuit->area->lspdb[0]);
2047 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2048
2049 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2050 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2051
hassod70f99e2004-02-11 20:26:31 +00002052 THREAD_TIMER_ON(master, circuit->u.bc.t_refresh_pseudo_lsp[0],
2053 lsp_l1_refresh_pseudo, circuit, isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002054
2055 return lsp_regenerate_schedule (circuit->area);
2056}
2057
2058int
2059lsp_l2_refresh_pseudo (struct thread *thread)
2060{
2061 struct isis_circuit *circuit;
2062 int retval;
2063 unsigned long ref_time;
2064 circuit = THREAD_ARG(thread);
2065
2066 if (!circuit->u.bc.is_dr[1])
2067 return ISIS_ERROR; /* FIXME: purge and such */
2068
2069 retval = lsp_pseudo_regenerate (circuit, 2);
2070
2071 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
2072 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2073
hassod70f99e2004-02-11 20:26:31 +00002074 THREAD_TIMER_ON(master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2075 lsp_l2_refresh_pseudo, circuit, isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002076
jardineb5d44e2003-12-23 08:09:43 +00002077 return retval;
2078}
2079
2080
2081int
2082lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2083{
2084 struct isis_lsp *lsp;
2085 u_char id[ISIS_SYS_ID_LEN + 2];
2086 unsigned long ref_time;
2087
2088 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
2089 LSP_FRAGMENT(id) = 0;
2090 LSP_PSEUDO_ID(id) = circuit->circuit_id;
2091
2092 if (lsp_search (id, circuit->area->lspdb[1]))
2093 return lsp_pseudo_regenerate (circuit, 2);
2094
2095 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
2096 1, circuit->area->is_type, 0, 2);
2097
2098 lsp_build_pseudo (lsp, circuit, 2);
2099
2100 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
2101 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2102
2103
2104 lsp->own_lsp = 1;
2105 lsp_insert (lsp, circuit->area->lspdb[1]);
2106 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2107
hassod70f99e2004-02-11 20:26:31 +00002108 THREAD_TIMER_ON(master, circuit->u.bc.t_refresh_pseudo_lsp[1],
2109 lsp_l2_refresh_pseudo, circuit, isis_jitter (ref_time, MAX_AGE_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002110
2111 return lsp_regenerate_schedule (circuit->area);
2112}
2113
2114
2115
2116/*
2117 * Walk through LSPs for an area
2118 * - set remaining lifetime
2119 * - set LSPs with SRMflag set for sending
2120 */
2121int
2122lsp_tick (struct thread *thread)
2123{
2124 struct isis_area *area;
2125 struct isis_circuit *circuit;
2126 struct isis_lsp *lsp;
2127 struct list *lsp_list;
2128 struct listnode *lspnode, *cnode;
2129 dnode_t *dnode, *dnode_next;
2130 int level;
2131
2132 lsp_list = list_new ();
2133
2134 area = THREAD_ARG (thread);
2135 assert (area);
hassod70f99e2004-02-11 20:26:31 +00002136 THREAD_TIMER_ON(master, area->t_tick, lsp_tick, area, 1);
jardineb5d44e2003-12-23 08:09:43 +00002137
2138 /*
2139 * Build a list of LSPs with (any) SRMflag set
2140 * and removed the ones that have aged out
2141 */
2142 for (level = 0; level < ISIS_LEVELS; level++) {
2143 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0) {
2144 dnode = dict_first (area->lspdb[level]);
2145 while (dnode != NULL) {
2146 dnode_next = dict_next (area->lspdb[level], dnode);
2147 lsp = dnode_get (dnode);
2148 lsp_set_time (lsp);
2149 if (lsp->age_out == 0) {
2150
2151 zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2152 area->area_tag,
2153 lsp->level,
2154 rawlspid_print (lsp->lsp_header->lsp_id),
2155 ntohl(lsp->lsp_header->seq_num));
2156
2157 lsp_destroy (lsp);
2158 dict_delete (area->lspdb[level], dnode);
2159 } else if (flags_any_set (lsp->SRMflags))
2160 listnode_add (lsp_list, lsp);
2161 dnode = dnode_next;
2162 }
2163
2164 /*
2165 * Send LSPs on circuits indicated by the SRMflags
2166 */
2167 if (listcount (lsp_list) > 0) {
2168 for (cnode = listhead (area->circuit_list); cnode; nextnode (cnode)) {
2169 circuit = getdata (cnode);
2170 for (lspnode = listhead (lsp_list); lspnode; nextnode (lspnode)) {
2171 lsp = getdata (lspnode);
2172 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit)) {
2173 /* FIXME: if same or elder lsp is already in lsp queue */
2174 listnode_add (circuit->lsp_queue, lsp);
2175 thread_add_event (master, send_lsp, circuit, 0);
2176 }
2177 }
2178 }
2179 }
2180 list_delete_all_node (lsp_list);
2181 }
2182 }
2183
2184 list_delete (lsp_list);
2185
2186 return ISIS_OK;
2187}
2188
2189
2190void
2191lsp_purge_dr (u_char *id, struct isis_circuit *circuit, int level)
2192{
2193 struct isis_lsp *lsp;
2194
2195 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
2196
2197 if (lsp && lsp->purged == 0) {
2198 lsp->lsp_header->rem_lifetime = htons (0);
2199 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2200 lsp->purged = 0;
2201 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2202 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
2203 ISIS_FLAGS_SET_ALL(lsp->SRMflags);
2204 }
2205
2206
2207 return;
2208}
2209
2210/*
2211 * Purge own LSP that is received and we don't have.
2212 * -> Do as in 7.3.16.4
2213 */
2214void
2215lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2216 struct isis_area *area)
2217{
2218 struct isis_lsp *lsp;
2219
2220 /*
2221 * We need to create the LSP to be purged
2222 */
2223 zlog_info ("LSP PURGE NON EXIST");
2224 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2225 memset (lsp, 0, sizeof (struct isis_lsp));
2226 /*FIXME: BUG BUG BUG! the lsp doesn't exist here!*/
2227 /*did smt here, maybe good probably not*/
2228 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2229 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2230 lsp->isis_header = (struct isis_fixed_hdr*)STREAM_DATA(lsp->pdu);
2231 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
2232 : L2_LINK_STATE);
2233 lsp->lsp_header = (struct isis_link_state_hdr*)(STREAM_DATA(lsp->pdu) +
2234 ISIS_FIXED_HDR_LEN);
2235 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
2236
2237 /*
2238 * Retain only LSP header
2239 */
2240 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2241 /*
2242 * Set the remaining lifetime to 0
2243 */
2244 lsp->lsp_header->rem_lifetime = 0;
2245 /*
2246 * Put the lsp into LSPdb
2247 */
2248 lsp_insert (lsp, area->lspdb[lsp->level-1]);
2249
2250 /*
2251 * Send in to whole area
2252 */
2253 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2254
2255 return;
2256}
2257
2258#ifdef TOPOLOGY_GENERATE
2259int
2260top_lsp_refresh (struct thread *thread)
2261{
2262 struct isis_lsp *lsp;
2263
2264 lsp = THREAD_ARG (thread);
2265 assert (lsp);
2266
2267 lsp->t_lsp_top_ref = NULL;
2268
2269 lsp->lsp_header->rem_lifetime = htons (isis_jitter(MAX_AGE,MAX_AGE_JITTER));
2270 lsp->lsp_header->seq_num = htonl(ntohl(lsp->lsp_header->seq_num) +1);
2271
2272 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2273 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
2274 zlog_info ("ISIS-Upd (): refreshing Topology L1 %s",
2275 rawlspid_print (lsp->lsp_header->lsp_id));
2276 }
2277
2278 /* time to calculate our checksum */
2279 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2280 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
hassod70f99e2004-02-11 20:26:31 +00002281 THREAD_TIMER_ON(master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2282 isis_jitter (MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002283
2284 return ISIS_OK;
2285}
2286
2287void
2288generate_topology_lsps (struct isis_area *area)
2289{
2290 struct listnode *node;
2291 int i, max = 0;
2292 struct arc *arc;
2293 u_char lspid[ISIS_SYS_ID_LEN + 2];
2294 struct isis_lsp *lsp;
2295
2296 /* first we find the maximal node */
2297 LIST_LOOP (area->topology, arc, node) {
2298 if (arc->from_node > max) max = arc->from_node;
2299 if (arc->to_node > max) max = arc->to_node;
2300 }
2301
2302
2303 for (i = 1; i < (max+1); i++) {
2304 memcpy (lspid,area->topology_baseis,ISIS_SYS_ID_LEN);
2305 LSP_PSEUDO_ID (lspid) = 0x00;
2306 LSP_FRAGMENT (lspid) = 0x00;
2307 lspid[ISIS_SYS_ID_LEN-1] = (i & 0xFF);
2308 lspid[ISIS_SYS_ID_LEN-2] = ((i >> 8) & 0xFF);
2309
2310 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2311 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0, 1);
2312 lsp->from_topology = 1;
2313 /* creating data based on topology */
2314 build_topology_lsp_data (lsp,area,i);
2315 /* time to calculate our checksum */
2316 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2317 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
hassod70f99e2004-02-11 20:26:31 +00002318 THREAD_TIMER_ON(master, lsp->t_lsp_top_ref, top_lsp_refresh, lsp,
2319 isis_jitter(MAX_LSP_GEN_INTERVAL, MAX_LSP_GEN_JITTER));
jardineb5d44e2003-12-23 08:09:43 +00002320
2321 ISIS_FLAGS_SET_ALL(lsp->SRMflags);
2322 lsp_insert (lsp,area->lspdb[0]);
2323
2324 }
2325}
2326
2327void
2328remove_topology_lsps (struct isis_area *area)
2329{
2330 struct isis_lsp *lsp;
2331 dnode_t *dnode, *dnode_next;
2332
2333 dnode = dict_first (area->lspdb[0]);
2334 while (dnode != NULL) {
2335 dnode_next = dict_next (area->lspdb[0], dnode);
2336 lsp = dnode_get (dnode);
2337 if (lsp->from_topology) {
hassod70f99e2004-02-11 20:26:31 +00002338 THREAD_TIMER_OFF(lsp->t_lsp_top_ref);
jardineb5d44e2003-12-23 08:09:43 +00002339 lsp_destroy (lsp);
2340 dict_delete (area->lspdb[0], dnode);
2341 }
2342 dnode = dnode_next;
2343 }
2344}
2345
2346void
2347build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
2348 int lsp_top_num)
2349{
2350 struct listnode *node;
2351 struct arc *arc;
2352 u_char *tlv_ptr;
2353 struct is_neigh *is_neigh;
2354 int to_lsp = 0;
2355 char buff[200];
2356
2357 /* add our nlpids */
2358 /* the 2 is for the TL plus 1 for the nlpid*/
2359 tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 3);
2360 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2361 *(tlv_ptr+1) = 1; /* one protocol */
2362 *(tlv_ptr+2) = NLPID_IP;
2363 lsp->tlv_data.nlpids = (struct nlpids*)(tlv_ptr+1);
2364
2365 /* first, lets add the tops */
2366 /* the 2 is for the TL plus 1 for the virtual field*/
2367 tlv_ptr = lsppdu_realloc (lsp ,MTYPE_ISIS_TLV, 3);
2368 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2369 *(tlv_ptr+1) = 1; /* this is the virtual char len*/
2370 *(tlv_ptr+2) = 0; /* virtual is zero */
2371 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
2372
2373 /* add reachability for this IS for simulated 1 */
2374 if (lsp_top_num == 1) {
2375 /* assign space for the is_neigh at the pdu end */
2376 is_neigh = (struct is_neigh*) lsppdu_realloc(lsp, MTYPE_ISIS_TLV,
2377 sizeof(struct is_neigh));
2378 /* add this node to our list */
2379 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2380 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2381 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2382 is_neigh->metrics.metric_default = 0x00; /* no special reason */
2383 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2384 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2385 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2386 /* don't forget the length */
2387 *(tlv_ptr+1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2388 /* no need to check for fragging here, it is a lonely is_reach */
2389 }
2390
2391 /* addding is reachabilities */
2392 LIST_LOOP (area->topology, arc, node) {
2393 if ((arc->from_node == lsp_top_num) ||
2394 (arc->to_node == lsp_top_num)) {
2395 if (arc->to_node == lsp_top_num) to_lsp = arc->from_node;
2396 if (arc->from_node == lsp_top_num) to_lsp = arc->to_node;
2397
2398 /* if the length here is about to cross the FF limit, we reTLV */
2399 if (*(tlv_ptr+1) >= (0xFF - IS_NEIGHBOURS_LEN)) {
2400 /* retlv */
2401 /* the 2 is for the TL plus 1 for the virtual field*/
2402 tlv_ptr = lsppdu_realloc(lsp,MTYPE_ISIS_TLV, 3);
2403 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2404 *(tlv_ptr+1) = 1; /* this is the virtual char len*/
2405 *(tlv_ptr+2) = 0; /* virtual is zero */
2406 }
2407 /* doing this here assures us that we won't add an "empty" tlv */
2408 /* assign space for the is_neigh at the pdu end */
2409 is_neigh = (struct is_neigh*) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2410 sizeof(struct is_neigh));
2411 /* add this node to our list */
2412 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2413 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2414 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2415 is_neigh->neigh_id[ISIS_SYS_ID_LEN-1] = (to_lsp & 0xFF);
2416 is_neigh->neigh_id[ISIS_SYS_ID_LEN-2] = ((to_lsp >> 8) & 0xFF);
2417 is_neigh->metrics.metric_default = arc->distance;
2418 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2419 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2420 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2421 /* don't forget the length */
2422 *(tlv_ptr+1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2423 }
2424 }
2425
2426 /* adding dynamic hostname if needed*/
2427 if (area->dynhostname) {
2428 memset (buff,0x00,200);
2429 sprintf (buff,"feedme%d",lsp_top_num);
2430 tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
2431 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2432 *(tlv_ptr+1) = strlen (buff); /* Length */
2433 /* the -1 is to fit the length in the struct */
2434 lsp->tlv_data.hostname = (struct hostname *)
2435 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen(buff)) - 1);
2436 memcpy (lsp->tlv_data.hostname->name, buff, strlen(buff));
2437 }
2438
2439 /* thanks to hannes, another bug bites the dust */
2440 lsp->pdu->putp = ntohs(lsp->lsp_header->pdu_len);
2441 lsp->pdu->endp = ntohs(lsp->lsp_header->pdu_len);
2442}
2443#endif /* TOPOLOGY_GENERATE */