blob: 3f6a57b939ac5491315a044b2fcbfc2ec77c444b [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{
1655
1656 area->t_lsp_refresh[0] = thread_add_timer (master, lsp_refresh_l1, area,
1657 MAX_LSP_GEN_INTERVAL);
1658
1659 return lsp_generate_non_pseudo (area, 1);
1660}
1661
1662
1663/*
1664 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1665 */
1666int
1667lsp_l2_generate (struct isis_area *area)
1668{
1669
1670 area->t_lsp_refresh[1] = thread_add_timer (master, lsp_refresh_l2, area,
1671 MAX_LSP_GEN_INTERVAL);
1672
1673 return lsp_generate_non_pseudo (area, 2);
1674}
1675
1676int
1677lsp_non_pseudo_regenerate (struct isis_area *area, int level)
1678{
1679 dict_t *lspdb = area->lspdb[level - 1];
1680 struct isis_lsp *lsp, *frag;
1681 struct listnode *node;
1682 u_char lspid[ISIS_SYS_ID_LEN + 2];
1683
1684 memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
1685 memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
1686
1687 lsp = lsp_search (lspid, lspdb);
1688
1689 if (!lsp) {
1690 zlog_err ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1691 area->area_tag,
1692 level);
1693
1694 return ISIS_ERROR;
1695 }
1696
1697 lsp_clear_data (lsp);
1698 lsp_build_nonpseudo (lsp, area);
1699 lsp->lsp_header->rem_lifetime = htons (isis_jitter
1700 (area->max_lsp_lifetime[level-1],
1701 MAX_AGE_JITTER));
1702 lsp_seqnum_update (lsp);
1703
1704 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1705 zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1706 "seq 0x%08x, cksum 0x%04x lifetime %us",
1707 area->area_tag,
1708 level,
1709 rawlspid_print (lsp->lsp_header->lsp_id),
1710 ntohl(lsp->lsp_header->seq_num),
1711 ntohs(lsp->lsp_header->checksum),
1712 ntohs(lsp->lsp_header->rem_lifetime));
1713 }
1714
1715 lsp->last_generated = time (NULL);
1716 area->lsp_regenerate_pending[level - 1] = 0;
1717 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1718 for (node = listhead (lsp->lspu.frags); node; nextnode(node)) {
1719 frag = getdata (node);
1720 frag->lsp_header->rem_lifetime = htons (isis_jitter
1721 (area->max_lsp_lifetime[level-1],
1722 MAX_AGE_JITTER));
1723 ISIS_FLAGS_SET_ALL (frag->SRMflags);
1724 }
1725
1726 if (area->ip_circuits)
1727 isis_spf_schedule (area, level);
1728#ifdef HAVE_IPV6
1729 if (area->ipv6_circuits)
1730 isis_spf_schedule6 (area, level);
1731#endif
1732 return ISIS_OK;
1733}
1734
1735
1736/*
1737 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1738 * time and set SRM
1739 */
1740int
1741lsp_refresh_l1 (struct thread *thread)
1742{
1743 struct isis_area *area;
1744 unsigned long ref_time;
1745
1746 area = THREAD_ARG (thread);
1747 assert (area);
1748
1749 area->t_lsp_refresh[0] = NULL;
1750 if (area->is_type & IS_LEVEL_1)
1751 lsp_non_pseudo_regenerate (area, 1);
1752
1753 ref_time = area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
1754 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];
1755
1756 area->t_lsp_refresh[0] = thread_add_timer (master, lsp_refresh_l1, area,
1757 isis_jitter (ref_time,
1758 MAX_AGE_JITTER));
1759 return ISIS_OK;
1760}
1761
1762int
1763lsp_refresh_l2 (struct thread *thread)
1764{
1765 struct isis_area *area;
1766 unsigned long ref_time;
1767
1768 area = THREAD_ARG (thread);
1769 assert (area);
1770
1771 area->t_lsp_refresh[1] = NULL;
1772 if (area->is_type & IS_LEVEL_2)
1773 lsp_non_pseudo_regenerate (area, 2);
1774
1775 ref_time = area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
1776 MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];
1777
1778
1779 area->t_lsp_refresh[1] = thread_add_timer (master, lsp_refresh_l2, area,
1780 isis_jitter (ref_time,
1781 MAX_AGE_JITTER));
1782 return ISIS_OK;
1783}
1784
1785
1786/*
1787 * Something has changed -> regenerate LSP
1788 */
1789
1790int
1791lsp_l1_regenerate (struct thread *thread)
1792{
1793 struct isis_area *area;
1794
1795 area = THREAD_ARG (thread);
1796 area->lsp_regenerate_pending[0] = 0;
1797
1798 return lsp_non_pseudo_regenerate (area, 1);
1799}
1800
1801int
1802lsp_l2_regenerate (struct thread *thread)
1803{
1804 struct isis_area *area;
1805
1806 area = THREAD_ARG (thread);
1807 area->lsp_regenerate_pending[1] = 0;
1808
1809 return lsp_non_pseudo_regenerate (area, 2);
1810}
1811
1812int
1813lsp_regenerate_schedule (struct isis_area *area)
1814{
1815 struct isis_lsp *lsp;
1816 u_char id[ISIS_SYS_ID_LEN + 2];
1817 time_t now, diff;
1818 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
1819 LSP_PSEUDO_ID(id) = LSP_FRAGMENT(id) = 0;
1820 now = time (NULL);
1821 /*
1822 * First level 1
1823 */
1824 if (area->is_type & IS_LEVEL_1) {
1825 lsp = lsp_search (id, area->lspdb[0]);
1826 if (!lsp || area->lsp_regenerate_pending[0])
1827 goto L2;
1828 /*
1829 * Throttle avoidance
1830 */
1831 diff = now - lsp->last_generated;
1832 if (diff < MIN_LSP_GEN_INTERVAL) {
1833 area->lsp_regenerate_pending[0] = 1;
1834 thread_add_timer (master, lsp_l1_regenerate, area,
1835 MIN_LSP_GEN_INTERVAL - diff);
1836 return ISIS_OK;
1837 } else
1838 lsp_non_pseudo_regenerate (area, 1);
1839 }
1840 /*
1841 * then 2
1842 */
1843 L2:
1844 if (area->is_type & IS_LEVEL_2) {
1845 lsp = lsp_search (id, area->lspdb[1]);
1846 if (!lsp || area->lsp_regenerate_pending[1])
1847 return ISIS_OK;
1848 /*
1849 * Throttle avoidance
1850 */
1851 diff = now - lsp->last_generated;
1852 if (diff < MIN_LSP_GEN_INTERVAL) {
1853 area->lsp_regenerate_pending[1] = 1;
1854 thread_add_timer (master, lsp_l2_regenerate, area,
1855 MIN_LSP_GEN_INTERVAL - diff);
1856 return ISIS_OK;
1857 } else
1858 lsp_non_pseudo_regenerate (area, 2);
1859 }
1860
1861 return ISIS_OK;
1862}
1863
1864/*
1865 * Funcs for pseudonode LSPs
1866 */
1867
1868/*
1869 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1870 */
1871void
1872lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit,
1873 int level)
1874{
1875 struct isis_adjacency *adj;
1876 struct is_neigh *is_neigh;
1877 struct es_neigh *es_neigh;
1878 struct list *adj_list;
1879 struct listnode *node;
1880 struct isis_passwd *passwd;
1881
1882 assert (circuit);
1883 assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
1884
1885 if (!circuit->u.bc.is_dr[level - 1])
1886 return; /* we are not DIS on this circuit */
1887
1888 lsp->level = level;
1889 if (level == 1)
1890 lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
1891 else
1892 lsp->lsp_header->lsp_bits |= IS_LEVEL_2;
1893
1894 /*
1895 * add self to IS neighbours
1896 */
1897 if (lsp->tlv_data.is_neighs == NULL) {
1898 lsp->tlv_data.is_neighs = list_new ();
1899 lsp->tlv_data.is_neighs->del = free_tlv;
1900 }
1901 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1902 memset (is_neigh, 0, sizeof (struct is_neigh));
1903 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
1904 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1905
1906 adj_list = list_new();
1907 isis_adj_build_up_list (circuit->u.bc.adjdb[level-1], adj_list);
1908
1909 for (node = listhead (adj_list); node; nextnode (node)){
1910 adj = getdata (node);
1911 if (adj->circuit_t & level) {
1912 if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
1913 (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
1914 adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
1915 (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) {
1916 /* an IS neighbour -> add it */
1917 is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
1918 memset (is_neigh, 0, sizeof (struct is_neigh));
1919 memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
1920 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
1921 } else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES) {
1922 /* an ES neigbour add it, if we are building level 1 LSP */
1923 /* FIXME: the tlv-format is hard to use here */
1924 if (lsp->tlv_data.es_neighs == NULL) {
1925 lsp->tlv_data.es_neighs = list_new ();
1926 lsp->tlv_data.es_neighs->del = free_tlv;
1927 }
1928 es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
1929 memset (es_neigh, 0, sizeof (struct es_neigh));
1930 memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
1931 listnode_add (lsp->tlv_data.es_neighs, is_neigh);
1932 }
1933 }
1934 }
1935
1936 stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
1937 /*
1938 * Add the authentication info if it's present
1939 */
1940 (level == 1) ? (passwd = &circuit->area->area_passwd) :
1941 (passwd = &circuit->area->domain_passwd);
1942 if (passwd->type) {
1943 memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
1944 tlv_add_authinfo (passwd->type, passwd->len,
1945 passwd->passwd, lsp->pdu);
1946 }
1947
1948 if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
1949 tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
1950
1951 if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
1952 tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);
1953
1954 lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
1955 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
1956 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
1957
1958 list_delete (adj_list);
1959
1960 return;
1961}
1962
1963int
1964lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
1965{
1966 dict_t *lspdb = circuit->area->lspdb[level - 1];
1967 struct isis_lsp *lsp;
1968 u_char lsp_id[ISIS_SYS_ID_LEN + 2];
1969
1970 memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
1971 LSP_PSEUDO_ID(lsp_id) = circuit->circuit_id;
1972 LSP_FRAGMENT(lsp_id) = 0;
1973
1974 lsp = lsp_search (lsp_id, lspdb);
1975
1976 if (!lsp) {
1977 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
1978 rawlspid_print(lsp_id));
1979 return ISIS_ERROR;
1980 }
1981 lsp_clear_data (lsp);
1982
1983 lsp_build_pseudo (lsp, circuit, level);
1984
1985 lsp->lsp_header->rem_lifetime =
1986 htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
1987 MAX_AGE_JITTER));
1988
1989 lsp_inc_seqnum (lsp, 0);
1990
1991 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
1992 zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1993 circuit->area->area_tag, level,
1994 rawlspid_print (lsp->lsp_header->lsp_id));
1995 }
1996
1997 lsp->last_generated = time (NULL);
1998 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
1999
2000 return ISIS_OK;
2001}
2002
2003
2004int
2005lsp_l1_refresh_pseudo (struct thread *thread)
2006{
2007 struct isis_circuit *circuit;
2008 int retval;
2009 unsigned long ref_time;
2010
2011 circuit = THREAD_ARG(thread);
2012
2013 if (!circuit->u.bc.is_dr[0])
2014 return ISIS_ERROR; /* FIXME: purge and such */
2015
2016 retval = lsp_pseudo_regenerate (circuit, 1);
2017
2018 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2019 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2020
2021 circuit->u.bc.t_refresh_pseudo_lsp[0] =
2022 thread_add_timer (master, lsp_l1_refresh_pseudo, circuit,
2023 isis_jitter (ref_time,
2024 MAX_AGE_JITTER));
2025 return retval;
2026}
2027
2028int
2029lsp_l1_pseudo_generate (struct isis_circuit *circuit)
2030{
2031 struct isis_lsp *lsp;
2032 u_char id[ISIS_SYS_ID_LEN + 2];
2033 unsigned long ref_time;
2034
2035 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
2036 LSP_FRAGMENT(id) = 0;
2037 LSP_PSEUDO_ID(id) = circuit->circuit_id;
2038
2039 /*
2040 * If for some reason have a pseudo LSP in the db already -> regenerate
2041 */
2042 if (lsp_search (id, circuit->area->lspdb[0]))
2043 return lsp_pseudo_regenerate (circuit, 1);
2044 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
2045 1, circuit->area->is_type, 0, 1);
2046
2047 lsp_build_pseudo (lsp, circuit, 1);
2048
2049 lsp->own_lsp = 1;
2050 lsp_insert (lsp, circuit->area->lspdb[0]);
2051 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2052
2053 ref_time = circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ?
2054 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];
2055
2056
2057 circuit->u.bc.t_refresh_pseudo_lsp[0] =
2058 thread_add_timer (master, lsp_l1_refresh_pseudo, circuit,
2059 isis_jitter (ref_time,
2060 MAX_AGE_JITTER));
2061
2062 return lsp_regenerate_schedule (circuit->area);
2063}
2064
2065int
2066lsp_l2_refresh_pseudo (struct thread *thread)
2067{
2068 struct isis_circuit *circuit;
2069 int retval;
2070 unsigned long ref_time;
2071 circuit = THREAD_ARG(thread);
2072
2073 if (!circuit->u.bc.is_dr[1])
2074 return ISIS_ERROR; /* FIXME: purge and such */
2075
2076 retval = lsp_pseudo_regenerate (circuit, 2);
2077
2078 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
2079 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2080
2081
2082 circuit->u.bc.t_refresh_pseudo_lsp[1] =
2083 thread_add_timer (master, lsp_l2_refresh_pseudo, circuit,
2084 isis_jitter (ref_time,
2085 MAX_AGE_JITTER));
2086 return retval;
2087}
2088
2089
2090int
2091lsp_l2_pseudo_generate (struct isis_circuit *circuit)
2092{
2093 struct isis_lsp *lsp;
2094 u_char id[ISIS_SYS_ID_LEN + 2];
2095 unsigned long ref_time;
2096
2097 memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
2098 LSP_FRAGMENT(id) = 0;
2099 LSP_PSEUDO_ID(id) = circuit->circuit_id;
2100
2101 if (lsp_search (id, circuit->area->lspdb[1]))
2102 return lsp_pseudo_regenerate (circuit, 2);
2103
2104 lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
2105 1, circuit->area->is_type, 0, 2);
2106
2107 lsp_build_pseudo (lsp, circuit, 2);
2108
2109 ref_time = circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ?
2110 MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];
2111
2112
2113 lsp->own_lsp = 1;
2114 lsp_insert (lsp, circuit->area->lspdb[1]);
2115 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2116
2117 circuit->u.bc.t_refresh_pseudo_lsp[1] =
2118 thread_add_timer (master, lsp_l2_refresh_pseudo, circuit,
2119 isis_jitter (ref_time,
2120 MAX_AGE_JITTER));
2121
2122 return lsp_regenerate_schedule (circuit->area);
2123}
2124
2125
2126
2127/*
2128 * Walk through LSPs for an area
2129 * - set remaining lifetime
2130 * - set LSPs with SRMflag set for sending
2131 */
2132int
2133lsp_tick (struct thread *thread)
2134{
2135 struct isis_area *area;
2136 struct isis_circuit *circuit;
2137 struct isis_lsp *lsp;
2138 struct list *lsp_list;
2139 struct listnode *lspnode, *cnode;
2140 dnode_t *dnode, *dnode_next;
2141 int level;
2142
2143 lsp_list = list_new ();
2144
2145 area = THREAD_ARG (thread);
2146 assert (area);
2147 area->t_tick = thread_add_timer (master, lsp_tick, area, 1);
2148
2149 /*
2150 * Build a list of LSPs with (any) SRMflag set
2151 * and removed the ones that have aged out
2152 */
2153 for (level = 0; level < ISIS_LEVELS; level++) {
2154 if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0) {
2155 dnode = dict_first (area->lspdb[level]);
2156 while (dnode != NULL) {
2157 dnode_next = dict_next (area->lspdb[level], dnode);
2158 lsp = dnode_get (dnode);
2159 lsp_set_time (lsp);
2160 if (lsp->age_out == 0) {
2161
2162 zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2163 area->area_tag,
2164 lsp->level,
2165 rawlspid_print (lsp->lsp_header->lsp_id),
2166 ntohl(lsp->lsp_header->seq_num));
2167
2168 lsp_destroy (lsp);
2169 dict_delete (area->lspdb[level], dnode);
2170 } else if (flags_any_set (lsp->SRMflags))
2171 listnode_add (lsp_list, lsp);
2172 dnode = dnode_next;
2173 }
2174
2175 /*
2176 * Send LSPs on circuits indicated by the SRMflags
2177 */
2178 if (listcount (lsp_list) > 0) {
2179 for (cnode = listhead (area->circuit_list); cnode; nextnode (cnode)) {
2180 circuit = getdata (cnode);
2181 for (lspnode = listhead (lsp_list); lspnode; nextnode (lspnode)) {
2182 lsp = getdata (lspnode);
2183 if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit)) {
2184 /* FIXME: if same or elder lsp is already in lsp queue */
2185 listnode_add (circuit->lsp_queue, lsp);
2186 thread_add_event (master, send_lsp, circuit, 0);
2187 }
2188 }
2189 }
2190 }
2191 list_delete_all_node (lsp_list);
2192 }
2193 }
2194
2195 list_delete (lsp_list);
2196
2197 return ISIS_OK;
2198}
2199
2200
2201void
2202lsp_purge_dr (u_char *id, struct isis_circuit *circuit, int level)
2203{
2204 struct isis_lsp *lsp;
2205
2206 lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
2207
2208 if (lsp && lsp->purged == 0) {
2209 lsp->lsp_header->rem_lifetime = htons (0);
2210 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2211 lsp->purged = 0;
2212 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2213 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
2214 ISIS_FLAGS_SET_ALL(lsp->SRMflags);
2215 }
2216
2217
2218 return;
2219}
2220
2221/*
2222 * Purge own LSP that is received and we don't have.
2223 * -> Do as in 7.3.16.4
2224 */
2225void
2226lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr,
2227 struct isis_area *area)
2228{
2229 struct isis_lsp *lsp;
2230
2231 /*
2232 * We need to create the LSP to be purged
2233 */
2234 zlog_info ("LSP PURGE NON EXIST");
2235 lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
2236 memset (lsp, 0, sizeof (struct isis_lsp));
2237 /*FIXME: BUG BUG BUG! the lsp doesn't exist here!*/
2238 /*did smt here, maybe good probably not*/
2239 lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
2240 lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2241 lsp->isis_header = (struct isis_fixed_hdr*)STREAM_DATA(lsp->pdu);
2242 fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
2243 : L2_LINK_STATE);
2244 lsp->lsp_header = (struct isis_link_state_hdr*)(STREAM_DATA(lsp->pdu) +
2245 ISIS_FIXED_HDR_LEN);
2246 memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
2247
2248 /*
2249 * Retain only LSP header
2250 */
2251 lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
2252 /*
2253 * Set the remaining lifetime to 0
2254 */
2255 lsp->lsp_header->rem_lifetime = 0;
2256 /*
2257 * Put the lsp into LSPdb
2258 */
2259 lsp_insert (lsp, area->lspdb[lsp->level-1]);
2260
2261 /*
2262 * Send in to whole area
2263 */
2264 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2265
2266 return;
2267}
2268
2269#ifdef TOPOLOGY_GENERATE
2270int
2271top_lsp_refresh (struct thread *thread)
2272{
2273 struct isis_lsp *lsp;
2274
2275 lsp = THREAD_ARG (thread);
2276 assert (lsp);
2277
2278 lsp->t_lsp_top_ref = NULL;
2279
2280 lsp->lsp_header->rem_lifetime = htons (isis_jitter(MAX_AGE,MAX_AGE_JITTER));
2281 lsp->lsp_header->seq_num = htonl(ntohl(lsp->lsp_header->seq_num) +1);
2282
2283 ISIS_FLAGS_SET_ALL (lsp->SRMflags);
2284 if (isis->debugs & DEBUG_UPDATE_PACKETS) {
2285 zlog_info ("ISIS-Upd (): refreshing Topology L1 %s",
2286 rawlspid_print (lsp->lsp_header->lsp_id));
2287 }
2288
2289 /* time to calculate our checksum */
2290 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2291 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
2292
2293 lsp->t_lsp_top_ref = thread_add_timer (master, top_lsp_refresh, lsp,
2294 isis_jitter (MAX_LSP_GEN_INTERVAL,
2295 MAX_LSP_GEN_JITTER));
2296
2297 return ISIS_OK;
2298}
2299
2300void
2301generate_topology_lsps (struct isis_area *area)
2302{
2303 struct listnode *node;
2304 int i, max = 0;
2305 struct arc *arc;
2306 u_char lspid[ISIS_SYS_ID_LEN + 2];
2307 struct isis_lsp *lsp;
2308
2309 /* first we find the maximal node */
2310 LIST_LOOP (area->topology, arc, node) {
2311 if (arc->from_node > max) max = arc->from_node;
2312 if (arc->to_node > max) max = arc->to_node;
2313 }
2314
2315
2316 for (i = 1; i < (max+1); i++) {
2317 memcpy (lspid,area->topology_baseis,ISIS_SYS_ID_LEN);
2318 LSP_PSEUDO_ID (lspid) = 0x00;
2319 LSP_FRAGMENT (lspid) = 0x00;
2320 lspid[ISIS_SYS_ID_LEN-1] = (i & 0xFF);
2321 lspid[ISIS_SYS_ID_LEN-2] = ((i >> 8) & 0xFF);
2322
2323 lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
2324 MAX_AGE_JITTER), 1, IS_LEVEL_1, 0, 1);
2325 lsp->from_topology = 1;
2326 /* creating data based on topology */
2327 build_topology_lsp_data (lsp,area,i);
2328 /* time to calculate our checksum */
2329 iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
2330 ntohs(lsp->lsp_header->pdu_len) - 12, 12);
2331 lsp->t_lsp_top_ref = thread_add_timer (master, top_lsp_refresh, lsp,
2332 isis_jitter(MAX_LSP_GEN_INTERVAL,
2333 MAX_LSP_GEN_JITTER));
2334
2335 ISIS_FLAGS_SET_ALL(lsp->SRMflags);
2336 lsp_insert (lsp,area->lspdb[0]);
2337
2338 }
2339}
2340
2341void
2342remove_topology_lsps (struct isis_area *area)
2343{
2344 struct isis_lsp *lsp;
2345 dnode_t *dnode, *dnode_next;
2346
2347 dnode = dict_first (area->lspdb[0]);
2348 while (dnode != NULL) {
2349 dnode_next = dict_next (area->lspdb[0], dnode);
2350 lsp = dnode_get (dnode);
2351 if (lsp->from_topology) {
2352 thread_cancel(lsp->t_lsp_top_ref);
2353 lsp_destroy (lsp);
2354 dict_delete (area->lspdb[0], dnode);
2355 }
2356 dnode = dnode_next;
2357 }
2358}
2359
2360void
2361build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area,
2362 int lsp_top_num)
2363{
2364 struct listnode *node;
2365 struct arc *arc;
2366 u_char *tlv_ptr;
2367 struct is_neigh *is_neigh;
2368 int to_lsp = 0;
2369 char buff[200];
2370
2371 /* add our nlpids */
2372 /* the 2 is for the TL plus 1 for the nlpid*/
2373 tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 3);
2374 *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
2375 *(tlv_ptr+1) = 1; /* one protocol */
2376 *(tlv_ptr+2) = NLPID_IP;
2377 lsp->tlv_data.nlpids = (struct nlpids*)(tlv_ptr+1);
2378
2379 /* first, lets add the tops */
2380 /* the 2 is for the TL plus 1 for the virtual field*/
2381 tlv_ptr = lsppdu_realloc (lsp ,MTYPE_ISIS_TLV, 3);
2382 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2383 *(tlv_ptr+1) = 1; /* this is the virtual char len*/
2384 *(tlv_ptr+2) = 0; /* virtual is zero */
2385 lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
2386
2387 /* add reachability for this IS for simulated 1 */
2388 if (lsp_top_num == 1) {
2389 /* assign space for the is_neigh at the pdu end */
2390 is_neigh = (struct is_neigh*) lsppdu_realloc(lsp, MTYPE_ISIS_TLV,
2391 sizeof(struct is_neigh));
2392 /* add this node to our list */
2393 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2394 memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
2395 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2396 is_neigh->metrics.metric_default = 0x00; /* no special reason */
2397 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2398 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2399 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2400 /* don't forget the length */
2401 *(tlv_ptr+1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2402 /* no need to check for fragging here, it is a lonely is_reach */
2403 }
2404
2405 /* addding is reachabilities */
2406 LIST_LOOP (area->topology, arc, node) {
2407 if ((arc->from_node == lsp_top_num) ||
2408 (arc->to_node == lsp_top_num)) {
2409 if (arc->to_node == lsp_top_num) to_lsp = arc->from_node;
2410 if (arc->from_node == lsp_top_num) to_lsp = arc->to_node;
2411
2412 /* if the length here is about to cross the FF limit, we reTLV */
2413 if (*(tlv_ptr+1) >= (0xFF - IS_NEIGHBOURS_LEN)) {
2414 /* retlv */
2415 /* the 2 is for the TL plus 1 for the virtual field*/
2416 tlv_ptr = lsppdu_realloc(lsp,MTYPE_ISIS_TLV, 3);
2417 *tlv_ptr = IS_NEIGHBOURS; /* Type */
2418 *(tlv_ptr+1) = 1; /* this is the virtual char len*/
2419 *(tlv_ptr+2) = 0; /* virtual is zero */
2420 }
2421 /* doing this here assures us that we won't add an "empty" tlv */
2422 /* assign space for the is_neigh at the pdu end */
2423 is_neigh = (struct is_neigh*) lsppdu_realloc (lsp, MTYPE_ISIS_TLV,
2424 sizeof(struct is_neigh));
2425 /* add this node to our list */
2426 listnode_add (lsp->tlv_data.is_neighs, is_neigh);
2427 memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
2428 LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
2429 is_neigh->neigh_id[ISIS_SYS_ID_LEN-1] = (to_lsp & 0xFF);
2430 is_neigh->neigh_id[ISIS_SYS_ID_LEN-2] = ((to_lsp >> 8) & 0xFF);
2431 is_neigh->metrics.metric_default = arc->distance;
2432 is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
2433 is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
2434 is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
2435 /* don't forget the length */
2436 *(tlv_ptr+1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
2437 }
2438 }
2439
2440 /* adding dynamic hostname if needed*/
2441 if (area->dynhostname) {
2442 memset (buff,0x00,200);
2443 sprintf (buff,"feedme%d",lsp_top_num);
2444 tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
2445 *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
2446 *(tlv_ptr+1) = strlen (buff); /* Length */
2447 /* the -1 is to fit the length in the struct */
2448 lsp->tlv_data.hostname = (struct hostname *)
2449 (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen(buff)) - 1);
2450 memcpy (lsp->tlv_data.hostname->name, buff, strlen(buff));
2451 }
2452
2453 /* thanks to hannes, another bug bites the dust */
2454 lsp->pdu->putp = ntohs(lsp->lsp_header->pdu_len);
2455 lsp->pdu->endp = ntohs(lsp->lsp_header->pdu_len);
2456}
2457#endif /* TOPOLOGY_GENERATE */