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