2 * IS-IS Rout(e)ing protocol - isis_lsp.c
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
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)
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
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.
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"
55 #ifdef TOPOLOGY_GENERATE
59 #define LSP_MEMORY_PREASSIGN
61 extern struct isis
*isis
;
62 extern struct thread_master
*master
;
63 extern struct in_addr router_id_zebra
;
65 /* staticly assigned vars for printing purposes */
66 char lsp_bits_string
[200]; /* FIXME: enough ? */
69 lsp_id_cmp (u_char
* id1
, u_char
* id2
)
71 return memcmp (id1
, id2
, ISIS_SYS_ID_LEN
+ 2);
79 dict
= dict_create (DICTCOUNT_T_MAX
, (dict_comp_t
) lsp_id_cmp
);
85 lsp_search (u_char
* id
, dict_t
* lspdb
)
92 zlog_debug ("searching db");
93 for (dn
= dict_first (lspdb
); dn
; dn
= dict_next (lspdb
, dn
))
95 zlog_debug ("%s\t%pX", rawlspid_print ((char *) dnode_getkey (dn
)),
98 #endif /* EXTREME DEBUG */
100 node
= dict_lookup (lspdb
, id
);
103 return (struct isis_lsp
*) dnode_get (node
);
109 lsp_clear_data (struct isis_lsp
*lsp
)
116 if (lsp
->tlv_data
.nlpids
)
117 XFREE (MTYPE_ISIS_TLV
, lsp
->tlv_data
.nlpids
);
118 if (lsp
->tlv_data
.hostname
)
119 XFREE (MTYPE_ISIS_TLV
, lsp
->tlv_data
.hostname
);
121 if (lsp
->tlv_data
.is_neighs
)
122 list_delete (lsp
->tlv_data
.is_neighs
);
123 if (lsp
->tlv_data
.te_is_neighs
)
124 list_delete (lsp
->tlv_data
.te_is_neighs
);
125 if (lsp
->tlv_data
.area_addrs
)
126 list_delete (lsp
->tlv_data
.area_addrs
);
127 if (lsp
->tlv_data
.es_neighs
)
128 list_delete (lsp
->tlv_data
.es_neighs
);
129 if (lsp
->tlv_data
.ipv4_addrs
)
130 list_delete (lsp
->tlv_data
.ipv4_addrs
);
131 if (lsp
->tlv_data
.ipv4_int_reachs
)
132 list_delete (lsp
->tlv_data
.ipv4_int_reachs
);
133 if (lsp
->tlv_data
.ipv4_ext_reachs
)
134 list_delete (lsp
->tlv_data
.ipv4_ext_reachs
);
135 if (lsp
->tlv_data
.te_ipv4_reachs
)
136 list_delete (lsp
->tlv_data
.te_ipv4_reachs
);
138 if (lsp
->tlv_data
.ipv6_addrs
)
139 list_delete (lsp
->tlv_data
.ipv6_addrs
);
140 if (lsp
->tlv_data
.ipv6_reachs
)
141 list_delete (lsp
->tlv_data
.ipv6_reachs
);
142 #endif /* HAVE_IPV6 */
144 memset (&lsp
->tlv_data
, 0, sizeof (struct tlvs
));
150 lsp_destroy (struct isis_lsp
*lsp
)
155 lsp_clear_data (lsp
);
157 if (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) == 0 && lsp
->lspu
.frags
)
159 list_delete (lsp
->lspu
.frags
);
163 stream_free (lsp
->pdu
);
164 XFREE (MTYPE_ISIS_LSP
, lsp
);
168 lsp_db_destroy (dict_t
* lspdb
)
170 dnode_t
*dnode
, *next
;
171 struct isis_lsp
*lsp
;
173 dnode
= dict_first (lspdb
);
176 next
= dict_next (lspdb
, dnode
);
177 lsp
= dnode_get (dnode
);
179 dict_delete_free (lspdb
, dnode
);
189 * Remove all the frags belonging to the given lsp
192 lsp_remove_frags (struct list
*frags
, dict_t
* lspdb
)
195 struct listnode
*lnode
, *lnnode
;
196 struct isis_lsp
*lsp
;
198 for (ALL_LIST_ELEMENTS (frags
, lnode
, lnnode
, lsp
))
200 dnode
= dict_lookup (lspdb
, lsp
->lsp_header
->lsp_id
);
202 dnode_destroy (dict_delete (lspdb
, dnode
));
205 list_delete_all_node (frags
);
211 lsp_search_and_destroy (u_char
* id
, dict_t
* lspdb
)
214 struct isis_lsp
*lsp
;
216 node
= dict_lookup (lspdb
, id
);
219 node
= dict_delete (lspdb
, node
);
220 lsp
= dnode_get (node
);
222 * If this is a zero lsp, remove all the frags now
224 if (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) == 0)
227 lsp_remove_frags (lsp
->lspu
.frags
, lspdb
);
232 * else just remove this frag, from the zero lsps' frag list
234 if (lsp
->lspu
.zero_lsp
&& lsp
->lspu
.zero_lsp
->lspu
.frags
)
235 listnode_delete (lsp
->lspu
.zero_lsp
->lspu
.frags
, lsp
);
238 dnode_destroy (node
);
243 * Compares a LSP to given values
244 * Params are given in net order
247 lsp_compare (char *areatag
, struct isis_lsp
*lsp
, u_int32_t seq_num
,
248 u_int16_t checksum
, u_int16_t rem_lifetime
)
250 /* no point in double ntohl on seqnum */
251 if (lsp
->lsp_header
->seq_num
== seq_num
&&
252 lsp
->lsp_header
->checksum
== checksum
&&
253 /*comparing with 0, no need to do ntohl */
254 ((lsp
->lsp_header
->rem_lifetime
== 0 && rem_lifetime
== 0) ||
255 (lsp
->lsp_header
->rem_lifetime
!= 0 && rem_lifetime
!= 0)))
257 if (isis
->debugs
& DEBUG_SNP_PACKETS
)
259 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
262 rawlspid_print (lsp
->lsp_header
->lsp_id
),
263 ntohl (lsp
->lsp_header
->seq_num
),
264 ntohs (lsp
->lsp_header
->checksum
),
265 ntohs (lsp
->lsp_header
->rem_lifetime
));
266 zlog_debug ("ISIS-Snp (%s): is equal to ours seq 0x%08x,"
267 " cksum 0x%04x, lifetime %us",
269 ntohl (seq_num
), ntohs (checksum
), ntohs (rem_lifetime
));
274 if (ntohl (seq_num
) >= ntohl (lsp
->lsp_header
->seq_num
))
276 if (isis
->debugs
& DEBUG_SNP_PACKETS
)
278 zlog_debug ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
281 rawlspid_print (lsp
->lsp_header
->lsp_id
),
282 ntohl (seq_num
), ntohs (checksum
), ntohs (rem_lifetime
));
283 zlog_debug ("ISIS-Snp (%s): is newer than ours seq 0x%08x, "
284 "cksum 0x%04x, lifetime %us",
286 ntohl (lsp
->lsp_header
->seq_num
),
287 ntohs (lsp
->lsp_header
->checksum
),
288 ntohs (lsp
->lsp_header
->rem_lifetime
));
292 if (isis
->debugs
& DEBUG_SNP_PACKETS
)
295 ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
296 areatag
, rawlspid_print (lsp
->lsp_header
->lsp_id
), ntohl (seq_num
),
297 ntohs (checksum
), ntohs (rem_lifetime
));
298 zlog_debug ("ISIS-Snp (%s): is older than ours seq 0x%08x,"
299 " cksum 0x%04x, lifetime %us", areatag
,
300 ntohl (lsp
->lsp_header
->seq_num
),
301 ntohs (lsp
->lsp_header
->checksum
),
302 ntohs (lsp
->lsp_header
->rem_lifetime
));
309 lsp_inc_seqnum (struct isis_lsp
*lsp
, u_int32_t seq_num
)
313 if (seq_num
== 0 || ntohl (lsp
->lsp_header
->seq_num
) > seq_num
)
314 newseq
= ntohl (lsp
->lsp_header
->seq_num
) + 1;
318 lsp
->lsp_header
->seq_num
= htonl (newseq
);
319 iso_csum_create (STREAM_DATA (lsp
->pdu
) + 12,
320 ntohs (lsp
->lsp_header
->pdu_len
) - 12, 12);
326 * Genetates checksum for LSP and its frags
329 lsp_seqnum_update (struct isis_lsp
*lsp0
)
331 struct isis_lsp
*lsp
;
332 struct listnode
*node
, *nnode
;
334 lsp_inc_seqnum (lsp0
, 0);
336 if (!lsp0
->lspu
.frags
)
339 for (ALL_LIST_ELEMENTS (lsp0
->lspu
.frags
, node
, nnode
, lsp
))
340 lsp_inc_seqnum (lsp
, 0);
346 isis_lsp_authinfo_check (struct stream
*stream
, struct isis_area
*area
,
347 int pdulen
, struct isis_passwd
*passwd
)
349 uint32_t expected
= 0, found
;
353 expected
|= TLVFLAG_AUTH_INFO
;
354 retval
= parse_tlvs (area
->area_tag
, stream
->data
+
355 ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
,
356 pdulen
- ISIS_FIXED_HDR_LEN
357 - ISIS_LSP_HDR_LEN
, &expected
, &found
, &tlvs
);
358 if (retval
|| !(found
& TLVFLAG_AUTH_INFO
))
359 return 1; /* Auth fail (parsing failed or no auth-tlv) */
361 return authentication_check (passwd
, &tlvs
.auth_info
);
365 lsp_update_data (struct isis_lsp
*lsp
, struct stream
*stream
,
366 struct isis_area
*area
)
368 uint32_t expected
= 0, found
;
371 /* copying only the relevant part of our stream */
372 lsp
->pdu
= stream_dup (stream
);
374 /* setting pointers to the correct place */
375 lsp
->isis_header
= (struct isis_fixed_hdr
*) (STREAM_DATA (lsp
->pdu
));
376 lsp
->lsp_header
= (struct isis_link_state_hdr
*) (STREAM_DATA (lsp
->pdu
) +
378 lsp
->age_out
= ZERO_AGE_LIFETIME
;
379 lsp
->installed
= time (NULL
);
381 * Get LSP data i.e. TLVs
383 expected
|= TLVFLAG_AUTH_INFO
;
384 expected
|= TLVFLAG_AREA_ADDRS
;
385 expected
|= TLVFLAG_IS_NEIGHS
;
386 if ((lsp
->lsp_header
->lsp_bits
& 3) == 3) /* a level 2 LSP */
387 expected
|= TLVFLAG_PARTITION_DESIG_LEVEL2_IS
;
388 expected
|= TLVFLAG_NLPID
;
389 if (area
->dynhostname
)
390 expected
|= TLVFLAG_DYN_HOSTNAME
;
393 expected
|= TLVFLAG_TE_IS_NEIGHS
;
394 expected
|= TLVFLAG_TE_IPV4_REACHABILITY
;
395 expected
|= TLVFLAG_TE_ROUTER_ID
;
397 expected
|= TLVFLAG_IPV4_ADDR
;
398 expected
|= TLVFLAG_IPV4_INT_REACHABILITY
;
399 expected
|= TLVFLAG_IPV4_EXT_REACHABILITY
;
401 expected
|= TLVFLAG_IPV6_ADDR
;
402 expected
|= TLVFLAG_IPV6_REACHABILITY
;
403 #endif /* HAVE_IPV6 */
405 retval
= parse_tlvs (area
->area_tag
, lsp
->pdu
->data
+
406 ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
,
407 ntohs (lsp
->lsp_header
->pdu_len
) - ISIS_FIXED_HDR_LEN
408 - ISIS_LSP_HDR_LEN
, &expected
, &found
, &lsp
->tlv_data
);
410 if (found
& TLVFLAG_DYN_HOSTNAME
)
412 if (area
->dynhostname
)
413 isis_dynhn_insert (lsp
->lsp_header
->lsp_id
, lsp
->tlv_data
.hostname
,
414 (lsp
->lsp_header
->lsp_bits
& LSPBIT_IST
) ==
415 IS_LEVEL_1_AND_2
? IS_LEVEL_2
:
416 (lsp
->lsp_header
->lsp_bits
& LSPBIT_IST
));
422 lsp_update (struct isis_lsp
*lsp
, struct isis_link_state_hdr
*lsp_hdr
,
423 struct stream
*stream
, struct isis_area
*area
, int level
)
425 dnode_t
*dnode
= NULL
;
427 /* Remove old LSP from LSP database. */
428 dnode
= dict_lookup (area
->lspdb
[level
- 1], lsp
->lsp_header
->lsp_id
);
430 dnode_destroy (dict_delete (area
->lspdb
[level
- 1], dnode
));
432 /* free the old lsp data */
433 XFREE (MTYPE_STREAM_DATA
, lsp
->pdu
);
434 lsp_clear_data (lsp
);
436 /* rebuild the lsp data */
437 lsp_update_data (lsp
, stream
, area
);
439 /* set the new values for lsp header */
440 memcpy (lsp
->lsp_header
, lsp_hdr
, ISIS_LSP_HDR_LEN
);
443 lsp_insert (lsp
, area
->lspdb
[level
- 1]);
446 /* creation of LSP directly from what we received */
448 lsp_new_from_stream_ptr (struct stream
*stream
,
449 u_int16_t pdu_len
, struct isis_lsp
*lsp0
,
450 struct isis_area
*area
)
452 struct isis_lsp
*lsp
;
454 lsp
= XCALLOC (MTYPE_ISIS_LSP
, sizeof (struct isis_lsp
));
455 lsp_update_data (lsp
, stream
, area
);
460 * zero lsp -> create the list for fragments
462 lsp
->lspu
.frags
= list_new ();
467 * a fragment -> set the backpointer and add this to zero lsps frag list
469 lsp
->lspu
.zero_lsp
= lsp0
;
470 listnode_add (lsp0
->lspu
.frags
, lsp
);
477 lsp_new (u_char
* lsp_id
, u_int16_t rem_lifetime
, u_int32_t seq_num
,
478 u_int8_t lsp_bits
, u_int16_t checksum
, int level
)
480 struct isis_lsp
*lsp
;
482 lsp
= XCALLOC (MTYPE_ISIS_LSP
, sizeof (struct isis_lsp
));
485 /* FIXME: set lspdbol bit */
486 zlog_warn ("lsp_new(): out of memory");
489 #ifdef LSP_MEMORY_PREASSIGN
490 lsp
->pdu
= stream_new (1514); /*Should be minimal mtu? yup... */
492 /* We need to do realloc on TLVs additions */
493 lsp
->pdu
= malloc (ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
494 #endif /* LSP_MEMORY_PREASSIGN */
495 if (LSP_FRAGMENT (lsp_id
) == 0)
496 lsp
->lspu
.frags
= list_new ();
497 lsp
->isis_header
= (struct isis_fixed_hdr
*) (STREAM_DATA (lsp
->pdu
));
498 lsp
->lsp_header
= (struct isis_link_state_hdr
*)
499 (STREAM_DATA (lsp
->pdu
) + ISIS_FIXED_HDR_LEN
);
501 /* at first we fill the FIXED HEADER */
502 (level
== 1) ? fill_fixed_hdr (lsp
->isis_header
, L1_LINK_STATE
) :
503 fill_fixed_hdr (lsp
->isis_header
, L2_LINK_STATE
);
505 /* now for the LSP HEADER */
506 /* Minimal LSP PDU size */
507 lsp
->lsp_header
->pdu_len
= htons (ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
508 memcpy (lsp
->lsp_header
->lsp_id
, lsp_id
, ISIS_SYS_ID_LEN
+ 2);
509 lsp
->lsp_header
->checksum
= checksum
; /* Provided in network order */
510 lsp
->lsp_header
->seq_num
= htonl (seq_num
);
511 lsp
->lsp_header
->rem_lifetime
= htons (rem_lifetime
);
512 lsp
->lsp_header
->lsp_bits
= lsp_bits
;
514 lsp
->age_out
= ZERO_AGE_LIFETIME
;
516 stream_forward_endp (lsp
->pdu
, ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
518 if (isis
->debugs
& DEBUG_EVENTS
)
519 zlog_debug ("New LSP with ID %s-%02x-%02x seqnum %08x",
520 sysid_print (lsp_id
), LSP_PSEUDO_ID (lsp
->lsp_header
->lsp_id
),
521 LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
),
522 ntohl (lsp
->lsp_header
->seq_num
));
528 lsp_insert (struct isis_lsp
*lsp
, dict_t
* lspdb
)
530 dict_alloc_insert (lspdb
, lsp
->lsp_header
->lsp_id
, lsp
);
534 * Build a list of LSPs with non-zero ht bounded by start and stop ids
537 lsp_build_list_nonzero_ht (u_char
* start_id
, u_char
* stop_id
,
538 struct list
*list
, dict_t
* lspdb
)
540 dnode_t
*first
, *last
, *curr
;
542 first
= dict_lower_bound (lspdb
, start_id
);
546 last
= dict_upper_bound (lspdb
, stop_id
);
550 if (((struct isis_lsp
*) (curr
->dict_data
))->lsp_header
->rem_lifetime
)
551 listnode_add (list
, first
->dict_data
);
555 curr
= dict_next (lspdb
, curr
);
557 ((struct isis_lsp
*) (curr
->dict_data
))->lsp_header
->rem_lifetime
)
558 listnode_add (list
, curr
->dict_data
);
567 * Build a list of all LSPs bounded by start and stop ids
570 lsp_build_list (u_char
* start_id
, u_char
* stop_id
,
571 struct list
*list
, dict_t
* lspdb
)
573 dnode_t
*first
, *last
, *curr
;
575 first
= dict_lower_bound (lspdb
, start_id
);
579 last
= dict_upper_bound (lspdb
, stop_id
);
583 listnode_add (list
, first
->dict_data
);
587 curr
= dict_next (lspdb
, curr
);
589 listnode_add (list
, curr
->dict_data
);
598 * Build a list of LSPs with SSN flag set for the given circuit
601 lsp_build_list_ssn (struct isis_circuit
*circuit
, struct list
*list
,
604 dnode_t
*dnode
, *next
;
605 struct isis_lsp
*lsp
;
607 dnode
= dict_first (lspdb
);
608 while (dnode
!= NULL
)
610 next
= dict_next (lspdb
, dnode
);
611 lsp
= dnode_get (dnode
);
612 if (ISIS_CHECK_FLAG (lsp
->SSNflags
, circuit
))
613 listnode_add (list
, lsp
);
621 lsp_set_time (struct isis_lsp
*lsp
)
625 if (lsp
->lsp_header
->rem_lifetime
== 0)
627 if (lsp
->age_out
!= 0)
632 /* If we are turning 0 */
633 /* ISO 10589 - 7.3.16.4 first paragraph */
635 if (ntohs (lsp
->lsp_header
->rem_lifetime
) == 1)
637 /* 7.3.16.4 a) set SRM flags on all */
638 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
639 /* 7.3.16.4 b) retain only the header FIXME */
640 /* 7.3.16.4 c) record the time to purge FIXME (other way to do it) */
643 lsp
->lsp_header
->rem_lifetime
=
644 htons (ntohs (lsp
->lsp_header
->rem_lifetime
) - 1);
648 lspid_print (u_char
* lsp_id
, u_char
* trg
, char dynhost
, char frag
)
650 struct isis_dynhn
*dyn
= NULL
;
651 u_char id
[SYSID_STRLEN
];
654 dyn
= dynhn_find_by_id (lsp_id
);
659 sprintf ((char *)id
, "%.14s", dyn
->name
.name
);
660 else if (!memcmp (isis
->sysid
, lsp_id
, ISIS_SYS_ID_LEN
) & dynhost
)
661 sprintf ((char *)id
, "%.14s", unix_hostname ());
664 memcpy (id
, sysid_print (lsp_id
), 15);
667 sprintf ((char *)trg
, "%s.%02x-%02x", id
, LSP_PSEUDO_ID (lsp_id
),
668 LSP_FRAGMENT (lsp_id
));
670 sprintf ((char *)trg
, "%s.%02x", id
, LSP_PSEUDO_ID (lsp_id
));
673 /* Convert the lsp attribute bits to attribute string */
675 lsp_bits2string (u_char
* lsp_bits
)
677 char *pos
= lsp_bits_string
;
682 /* we only focus on the default metric */
683 pos
+= sprintf (pos
, "%d/",
684 ISIS_MASK_LSP_ATT_DEFAULT_BIT (*lsp_bits
) ? 1 : 0);
686 pos
+= sprintf (pos
, "%d/",
687 ISIS_MASK_LSP_PARTITION_BIT (*lsp_bits
) ? 1 : 0);
689 pos
+= sprintf (pos
, "%d", ISIS_MASK_LSP_OL_BIT (*lsp_bits
) ? 1 : 0);
693 return lsp_bits_string
;
696 /* this function prints the lsp on show isis database */
698 lsp_print (dnode_t
* node
, struct vty
*vty
, char dynhost
)
700 struct isis_lsp
*lsp
= dnode_get (node
);
703 lspid_print (lsp
->lsp_header
->lsp_id
, LSPid
, dynhost
, 1);
704 vty_out (vty
, "%-21s%c ", LSPid
, lsp
->own_lsp
? '*' : ' ');
705 vty_out (vty
, "0x%08x ", ntohl (lsp
->lsp_header
->seq_num
));
706 vty_out (vty
, "0x%04x ", ntohs (lsp
->lsp_header
->checksum
));
708 if (ntohs (lsp
->lsp_header
->rem_lifetime
) == 0)
709 vty_out (vty
, " (%2u)", lsp
->age_out
);
711 vty_out (vty
, "%5u", ntohs (lsp
->lsp_header
->rem_lifetime
));
713 vty_out (vty
, " %s%s",
714 lsp_bits2string (&lsp
->lsp_header
->lsp_bits
), VTY_NEWLINE
);
718 lsp_print_detail (dnode_t
* node
, struct vty
*vty
, char dynhost
)
720 struct isis_lsp
*lsp
= dnode_get (node
);
721 struct area_addr
*area_addr
;
723 struct listnode
*lnode
, *lnnode
;
724 struct is_neigh
*is_neigh
;
725 struct te_is_neigh
*te_is_neigh
;
726 struct ipv4_reachability
*ipv4_reach
;
727 struct in_addr
*ipv4_addr
;
728 struct te_ipv4_reachability
*te_ipv4_reach
;
730 struct ipv6_reachability
*ipv6_reach
;
734 u_char hostname
[255];
736 u_char ipv4_reach_prefix
[20];
737 u_char ipv4_reach_mask
[20];
738 u_char ipv4_address
[20];
740 lspid_print (lsp
->lsp_header
->lsp_id
, LSPid
, dynhost
, 1);
741 lsp_print (node
, vty
, dynhost
);
743 /* for all area address */
744 if (lsp
->tlv_data
.area_addrs
)
745 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.area_addrs
, lnode
,
748 vty_out (vty
, " Area Address: %s%s",
749 isonet_print (area_addr
->area_addr
, area_addr
->addr_len
),
753 /* for the nlpid tlv */
754 if (lsp
->tlv_data
.nlpids
)
756 for (i
= 0; i
< lsp
->tlv_data
.nlpids
->count
; i
++)
758 switch (lsp
->tlv_data
.nlpids
->nlpids
[i
])
762 vty_out (vty
, " NLPID: 0x%X%s",
763 lsp
->tlv_data
.nlpids
->nlpids
[i
], VTY_NEWLINE
);
766 vty_out (vty
, " NLPID: %s%s", "unknown", VTY_NEWLINE
);
772 /* for the hostname tlv */
773 if (lsp
->tlv_data
.hostname
)
775 bzero (hostname
, sizeof (hostname
));
776 memcpy (hostname
, lsp
->tlv_data
.hostname
->name
,
777 lsp
->tlv_data
.hostname
->namelen
);
778 vty_out (vty
, " Hostname: %s%s", hostname
, VTY_NEWLINE
);
781 if (lsp
->tlv_data
.ipv4_addrs
)
782 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.ipv4_addrs
, lnode
,
785 memcpy (ipv4_address
, inet_ntoa (*ipv4_addr
), sizeof (ipv4_address
));
786 vty_out (vty
, " IP: %s%s", ipv4_address
, VTY_NEWLINE
);
790 if (lsp
->tlv_data
.router_id
)
792 memcpy (ipv4_address
, inet_ntoa (lsp
->tlv_data
.router_id
->id
),
793 sizeof (ipv4_address
));
794 vty_out (vty
, " Router ID: %s%s", ipv4_address
, VTY_NEWLINE
);
797 /* for the IS neighbor tlv */
798 if (lsp
->tlv_data
.is_neighs
)
799 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.is_neighs
, lnode
, lnnode
, is_neigh
))
801 lspid_print (is_neigh
->neigh_id
, LSPid
, dynhost
, 0);
802 vty_out (vty
, " Metric: %-10d IS %s%s",
803 is_neigh
->metrics
.metric_default
, LSPid
, VTY_NEWLINE
);
806 /* for the internal reachable tlv */
807 if (lsp
->tlv_data
.ipv4_int_reachs
)
808 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.ipv4_int_reachs
, lnode
,
811 memcpy (ipv4_reach_prefix
, inet_ntoa (ipv4_reach
->prefix
),
812 sizeof (ipv4_reach_prefix
));
813 memcpy (ipv4_reach_mask
, inet_ntoa (ipv4_reach
->mask
),
814 sizeof (ipv4_reach_mask
));
815 vty_out (vty
, " Metric: %-10d IP-Internal %s %s%s",
816 ipv4_reach
->metrics
.metric_default
, ipv4_reach_prefix
,
817 ipv4_reach_mask
, VTY_NEWLINE
);
820 /* for the external reachable tlv */
821 if (lsp
->tlv_data
.ipv4_ext_reachs
)
822 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.ipv4_ext_reachs
, lnode
,
825 memcpy (ipv4_reach_prefix
, inet_ntoa (ipv4_reach
->prefix
),
826 sizeof (ipv4_reach_prefix
));
827 memcpy (ipv4_reach_mask
, inet_ntoa (ipv4_reach
->mask
),
828 sizeof (ipv4_reach_mask
));
829 vty_out (vty
, " Metric: %-10d IP-External %s %s%s",
830 ipv4_reach
->metrics
.metric_default
, ipv4_reach_prefix
,
831 ipv4_reach_mask
, VTY_NEWLINE
);
836 if (lsp
->tlv_data
.ipv6_reachs
)
837 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.ipv6_reachs
, lnode
,
840 memset (&in6
, 0, sizeof (in6
));
841 memcpy (in6
.s6_addr
, ipv6_reach
->prefix
,
842 PSIZE (ipv6_reach
->prefix_len
));
843 inet_ntop (AF_INET6
, &in6
, (char *)buff
, BUFSIZ
);
844 if ((ipv6_reach
->control_info
&&
845 CTRL_INFO_DISTRIBUTION
) == DISTRIBUTION_INTERNAL
)
846 vty_out (vty
, " Metric: %-10d IPv6-Internal %s/%d%s",
847 ntohl (ipv6_reach
->metric
),
848 buff
, ipv6_reach
->prefix_len
, VTY_NEWLINE
);
850 vty_out (vty
, " Metric: %-10d IPv6-External %s/%d%s",
851 ntohl (ipv6_reach
->metric
),
852 buff
, ipv6_reach
->prefix_len
, VTY_NEWLINE
);
856 /* TE IS neighbor tlv */
857 if (lsp
->tlv_data
.te_is_neighs
)
858 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.te_is_neighs
, lnode
,
859 lnnode
, te_is_neigh
))
862 memcpy (&metric
, te_is_neigh
->te_metric
, 3);
863 lspid_print (te_is_neigh
->neigh_id
, LSPid
, dynhost
, 0);
864 vty_out (vty
, " Metric: %-10d IS-Extended %s%s",
865 ntohl (metric
<< 8), LSPid
, VTY_NEWLINE
);
869 if (lsp
->tlv_data
.te_ipv4_reachs
)
870 for (ALL_LIST_ELEMENTS (lsp
->tlv_data
.te_ipv4_reachs
, lnode
,
871 lnnode
, te_ipv4_reach
))
873 /* FIXME: There should be better way to output this stuff. */
874 vty_out (vty
, " Metric: %-10d IP-Extended %s/%d%s",
875 ntohl (te_ipv4_reach
->te_metric
),
876 inet_ntoa (newprefix2inaddr (&te_ipv4_reach
->prefix_start
,
877 te_ipv4_reach
->control
)),
878 te_ipv4_reach
->control
& 0x3F, VTY_NEWLINE
);
884 /* print all the lsps info in the local lspdb */
886 lsp_print_all (struct vty
*vty
, dict_t
* lspdb
, char detail
, char dynhost
)
889 dnode_t
*node
= dict_first (lspdb
), *next
;
892 /* print the title, for both modes */
893 vty_out (vty
, "LSP ID LSP Seq Num LSP Checksum "
894 "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE
);
896 if (detail
== ISIS_UI_LEVEL_BRIEF
)
900 /* I think it is unnecessary, so I comment it out */
901 /* dict_contains (lspdb, node); */
902 next
= dict_next (lspdb
, node
);
903 lsp_print (node
, vty
, dynhost
);
908 else if (detail
== ISIS_UI_LEVEL_DETAIL
)
912 next
= dict_next (lspdb
, node
);
913 lsp_print_detail (node
, vty
, dynhost
);
922 #define FRAG_THOLD(S,T) \
923 ((STREAM_SIZE(S)*T)/100)
925 /* stream*, area->lsp_frag_threshold, increment */
926 #define FRAG_NEEDED(S,T,I) \
927 (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))
929 /* FIXME: It shouldn't be necessary to pass tlvsize here, TLVs can have
930 * variable length (TE TLVs, sub TLVs). */
932 lsp_tlv_fit (struct isis_lsp
*lsp
, struct list
**from
, struct list
**to
,
933 int tlvsize
, int frag_thold
,
934 int tlv_build_func (struct list
*, struct stream
*))
938 /* can we fit all ? */
939 if (!FRAG_NEEDED (lsp
->pdu
, frag_thold
, listcount (*from
) * tlvsize
+ 2))
941 tlv_build_func (*from
, lsp
->pdu
);
945 else if (!FRAG_NEEDED (lsp
->pdu
, frag_thold
, tlvsize
+ 2))
948 count
= FRAG_THOLD (lsp
->pdu
, frag_thold
) - 2 -
949 (STREAM_SIZE (lsp
->pdu
) - STREAM_REMAIN (lsp
->pdu
));
951 count
= count
/ tlvsize
;
952 for (i
= 0; i
< count
; i
++)
954 listnode_add (*to
, listgetdata (listhead (*from
)));
955 listnode_delete (*from
, listgetdata (listhead (*from
)));
957 tlv_build_func (*to
, lsp
->pdu
);
959 lsp
->lsp_header
->pdu_len
= htons (stream_get_endp (lsp
->pdu
));
963 static struct isis_lsp
*
964 lsp_next_frag (u_char frag_num
, struct isis_lsp
*lsp0
, struct isis_area
*area
,
967 struct isis_lsp
*lsp
;
968 u_char frag_id
[ISIS_SYS_ID_LEN
+ 2];
970 memcpy (frag_id
, lsp0
->lsp_header
->lsp_id
, ISIS_SYS_ID_LEN
+ 1);
971 LSP_FRAGMENT (frag_id
) = frag_num
;
972 lsp
= lsp_search (frag_id
, area
->lspdb
[level
- 1]);
976 * Clear the TLVs, but inherit the authinfo
978 lsp_clear_data (lsp
);
979 if (lsp0
->tlv_data
.auth_info
.type
)
981 memcpy (&lsp
->tlv_data
.auth_info
, &lsp
->tlv_data
.auth_info
,
982 sizeof (struct isis_passwd
));
983 tlv_add_authinfo (lsp
->tlv_data
.auth_info
.type
,
984 lsp
->tlv_data
.auth_info
.len
,
985 lsp
->tlv_data
.auth_info
.passwd
, lsp
->pdu
);
989 lsp
= lsp_new (frag_id
, area
->max_lsp_lifetime
[level
- 1], 0, area
->is_type
,
992 lsp_insert (lsp
, area
->lspdb
[level
- 1]);
993 listnode_add (lsp0
->lspu
.frags
, lsp
);
994 lsp
->lspu
.zero_lsp
= lsp0
;
996 * Copy the authinfo from zero LSP
998 if (lsp0
->tlv_data
.auth_info
.type
)
1000 memcpy (&lsp
->tlv_data
.auth_info
, &lsp
->tlv_data
.auth_info
,
1001 sizeof (struct isis_passwd
));
1002 tlv_add_authinfo (lsp
->tlv_data
.auth_info
.type
,
1003 lsp
->tlv_data
.auth_info
.len
,
1004 lsp
->tlv_data
.auth_info
.passwd
, lsp
->pdu
);
1010 * Builds the LSP data part. This func creates a new frag whenever
1011 * area->lsp_frag_threshold is exceeded.
1014 lsp_build_nonpseudo (struct isis_lsp
*lsp
, struct isis_area
*area
)
1016 struct is_neigh
*is_neigh
;
1017 struct te_is_neigh
*te_is_neigh
;
1018 struct listnode
*node
, *nnode
, *ipnode
, *ipnnode
;
1019 int level
= lsp
->level
;
1020 struct isis_circuit
*circuit
;
1021 struct prefix_ipv4
*ipv4
;
1022 struct ipv4_reachability
*ipreach
;
1023 struct te_ipv4_reachability
*te_ipreach
;
1024 struct isis_adjacency
*nei
;
1026 struct prefix_ipv6
*ipv6
, *ip6prefix
;
1027 struct ipv6_reachability
*ip6reach
;
1028 #endif /* HAVE_IPV6 */
1029 struct tlvs tlv_data
;
1030 struct isis_lsp
*lsp0
= lsp
;
1031 struct isis_passwd
*passwd
;
1032 struct in_addr
*routerid
;
1035 * First add the tlvs related to area
1038 /* Area addresses */
1039 if (lsp
->tlv_data
.area_addrs
== NULL
)
1040 lsp
->tlv_data
.area_addrs
= list_new ();
1041 list_add_list (lsp
->tlv_data
.area_addrs
, area
->area_addrs
);
1042 /* Protocols Supported */
1043 if (area
->ip_circuits
> 0
1045 || area
->ipv6_circuits
> 0
1046 #endif /* HAVE_IPV6 */
1049 lsp
->tlv_data
.nlpids
= XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct nlpids
));
1050 lsp
->tlv_data
.nlpids
->count
= 0;
1051 if (area
->ip_circuits
> 0)
1053 lsp
->tlv_data
.nlpids
->count
++;
1054 lsp
->tlv_data
.nlpids
->nlpids
[0] = NLPID_IP
;
1057 if (area
->ipv6_circuits
> 0)
1059 lsp
->tlv_data
.nlpids
->count
++;
1060 lsp
->tlv_data
.nlpids
->nlpids
[lsp
->tlv_data
.nlpids
->count
- 1] =
1063 #endif /* HAVE_IPV6 */
1065 /* Dynamic Hostname */
1066 if (area
->dynhostname
)
1068 lsp
->tlv_data
.hostname
= XMALLOC (MTYPE_ISIS_TLV
,
1069 sizeof (struct hostname
));
1071 memcpy (lsp
->tlv_data
.hostname
->name
, unix_hostname (),
1072 strlen (unix_hostname ()));
1073 lsp
->tlv_data
.hostname
->namelen
= strlen (unix_hostname ());
1077 * Building the zero lsp
1080 /* Reset stream endp. Stream is always there and on every LSP refresh only
1081 * TLV part of it is overwritten. So we must seek past header we will not
1083 stream_reset (lsp
->pdu
);
1084 stream_forward_endp (lsp
->pdu
, ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
1087 * Add the authentication info if its present
1089 (level
== 1) ? (passwd
= &area
->area_passwd
) :
1090 (passwd
= &area
->domain_passwd
);
1093 memcpy (&lsp
->tlv_data
.auth_info
, passwd
, sizeof (struct isis_passwd
));
1094 tlv_add_authinfo (passwd
->type
, passwd
->len
, passwd
->passwd
, lsp
->pdu
);
1096 if (lsp
->tlv_data
.nlpids
)
1097 tlv_add_nlpid (lsp
->tlv_data
.nlpids
, lsp
->pdu
);
1098 if (lsp
->tlv_data
.hostname
)
1099 tlv_add_dynamic_hostname (lsp
->tlv_data
.hostname
, lsp
->pdu
);
1100 if (lsp
->tlv_data
.area_addrs
&& listcount (lsp
->tlv_data
.area_addrs
) > 0)
1101 tlv_add_area_addrs (lsp
->tlv_data
.area_addrs
, lsp
->pdu
);
1103 memset (&tlv_data
, 0, sizeof (struct tlvs
));
1105 * IPv4 address TLV. We don't follow "C" vendor, but "J" vendor behavior -
1106 * one IPv4 address is put into LSP and this address is same as router id.
1108 if (router_id_zebra
.s_addr
!= 0)
1110 if (lsp
->tlv_data
.ipv4_addrs
== NULL
)
1112 lsp
->tlv_data
.ipv4_addrs
= list_new ();
1113 lsp
->tlv_data
.ipv4_addrs
->del
= free_tlv
;
1116 routerid
= XMALLOC (MTYPE_ISIS_TLV
, sizeof (struct in_addr
));
1117 routerid
->s_addr
= router_id_zebra
.s_addr
;
1119 listnode_add (lsp
->tlv_data
.ipv4_addrs
, routerid
);
1122 * FIXME: Using add_tlv() directly is hack, but tlv_add_ip_addrs()
1123 * expects list of prefix_ipv4 structures, but we have list of
1124 * in_addr structures.
1126 add_tlv (IPV4_ADDR
, IPV4_MAX_BYTELEN
, (u_char
*) &routerid
->s_addr
,
1130 #ifdef TOPOLOGY_GENERATE
1131 /* If topology exists (and we create topology for level 1 only), create
1132 * (hardcoded) link to topology. */
1133 if (area
->topology
&& level
== 1)
1135 if (tlv_data
.is_neighs
== NULL
)
1137 tlv_data
.is_neighs
= list_new ();
1138 tlv_data
.is_neighs
->del
= free_tlv
;
1140 is_neigh
= XMALLOC (MTYPE_ISIS_TLV
, sizeof (struct is_neigh
));
1141 memset (is_neigh
, 0, sizeof (struct is_neigh
));
1143 memcpy (&is_neigh
->neigh_id
, area
->topology_baseis
, ISIS_SYS_ID_LEN
);
1144 is_neigh
->neigh_id
[ISIS_SYS_ID_LEN
- 1] = (1 & 0xFF);
1145 is_neigh
->neigh_id
[ISIS_SYS_ID_LEN
- 2] = ((1 >> 8) & 0xFF);
1146 is_neigh
->metrics
.metric_default
= 0x01;
1147 is_neigh
->metrics
.metric_delay
= METRICS_UNSUPPORTED
;
1148 is_neigh
->metrics
.metric_expense
= METRICS_UNSUPPORTED
;
1149 is_neigh
->metrics
.metric_error
= METRICS_UNSUPPORTED
;
1150 listnode_add (tlv_data
.is_neighs
, is_neigh
);
1152 #endif /* TOPOLOGY_GENERATE */
1155 * Then build lists of tlvs related to circuits
1157 for (ALL_LIST_ELEMENTS (area
->circuit_list
, node
, nnode
, circuit
))
1159 if (circuit
->state
!= C_STATE_UP
)
1163 * Add IPv4 internal reachability of this circuit
1165 if (circuit
->ip_router
&& circuit
->ip_addrs
&&
1166 circuit
->ip_addrs
->count
> 0)
1168 if (area
->oldmetric
)
1170 if (tlv_data
.ipv4_int_reachs
== NULL
)
1172 tlv_data
.ipv4_int_reachs
= list_new ();
1173 tlv_data
.ipv4_int_reachs
->del
= free_tlv
;
1175 for (ALL_LIST_ELEMENTS (circuit
->ip_addrs
, ipnode
, ipnnode
, ipv4
))
1178 XMALLOC (MTYPE_ISIS_TLV
, sizeof (struct ipv4_reachability
));
1179 ipreach
->metrics
= circuit
->metrics
[level
- 1];
1180 masklen2ip (ipv4
->prefixlen
, &ipreach
->mask
);
1181 ipreach
->prefix
.s_addr
= ((ipreach
->mask
.s_addr
) &
1182 (ipv4
->prefix
.s_addr
));
1183 listnode_add (tlv_data
.ipv4_int_reachs
, ipreach
);
1185 tlv_data
.ipv4_int_reachs
->del
= free_tlv
;
1187 if (area
->newmetric
)
1189 if (tlv_data
.te_ipv4_reachs
== NULL
)
1191 tlv_data
.te_ipv4_reachs
= list_new ();
1192 tlv_data
.te_ipv4_reachs
->del
= free_tlv
;
1194 for (ALL_LIST_ELEMENTS (circuit
->ip_addrs
, ipnode
, ipnnode
, ipv4
))
1196 /* FIXME All this assumes that we have no sub TLVs. */
1197 te_ipreach
= XCALLOC (MTYPE_ISIS_TLV
,
1198 sizeof (struct te_ipv4_reachability
) +
1199 ((ipv4
->prefixlen
+ 7)/8) - 1);
1200 te_ipreach
->te_metric
= htonl (*circuit
->te_metric
);
1201 te_ipreach
->control
= (ipv4
->prefixlen
& 0x3F);
1202 memcpy (&te_ipreach
->prefix_start
, &ipv4
->prefix
.s_addr
,
1203 (ipv4
->prefixlen
+ 7)/8);
1204 listnode_add (tlv_data
.te_ipv4_reachs
, te_ipreach
);
1210 * Add IPv6 reachability of this circuit
1212 if (circuit
->ipv6_router
&& circuit
->ipv6_non_link
&&
1213 circuit
->ipv6_non_link
->count
> 0)
1216 if (tlv_data
.ipv6_reachs
== NULL
)
1218 tlv_data
.ipv6_reachs
= list_new ();
1219 tlv_data
.ipv6_reachs
->del
= free_tlv
;
1221 for (ALL_LIST_ELEMENTS (circuit
->ipv6_non_link
, ipnode
, ipnnode
,
1225 XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct ipv6_reachability
));
1227 htonl (circuit
->metrics
[level
- 1].metric_default
);
1228 ip6reach
->control_info
= 0;
1229 ip6reach
->prefix_len
= ipv6
->prefixlen
;
1230 memcpy (&ip6prefix
, &ipv6
, sizeof(ip6prefix
));
1231 apply_mask_ipv6 (ip6prefix
);
1232 memcpy (ip6reach
->prefix
, ip6prefix
->prefix
.s6_addr
,
1233 sizeof (ip6reach
->prefix
));
1234 listnode_add (tlv_data
.ipv6_reachs
, ip6reach
);
1237 #endif /* HAVE_IPV6 */
1239 switch (circuit
->circ_type
)
1241 case CIRCUIT_T_BROADCAST
:
1242 if (level
& circuit
->circuit_is_type
)
1244 if (area
->oldmetric
)
1246 if (tlv_data
.is_neighs
== NULL
)
1248 tlv_data
.is_neighs
= list_new ();
1249 tlv_data
.is_neighs
->del
= free_tlv
;
1251 is_neigh
= XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct is_neigh
));
1253 memcpy (is_neigh
->neigh_id
,
1254 circuit
->u
.bc
.l1_desig_is
, ISIS_SYS_ID_LEN
+ 1);
1256 memcpy (is_neigh
->neigh_id
,
1257 circuit
->u
.bc
.l2_desig_is
, ISIS_SYS_ID_LEN
+ 1);
1258 is_neigh
->metrics
= circuit
->metrics
[level
- 1];
1259 listnode_add (tlv_data
.is_neighs
, is_neigh
);
1260 tlv_data
.is_neighs
->del
= free_tlv
;
1262 if (area
->newmetric
)
1266 if (tlv_data
.te_is_neighs
== NULL
)
1268 tlv_data
.te_is_neighs
= list_new ();
1269 tlv_data
.te_is_neighs
->del
= free_tlv
;
1271 te_is_neigh
= XCALLOC (MTYPE_ISIS_TLV
,
1272 sizeof (struct te_is_neigh
));
1274 memcpy (te_is_neigh
->neigh_id
,
1275 circuit
->u
.bc
.l1_desig_is
, ISIS_SYS_ID_LEN
+ 1);
1277 memcpy (te_is_neigh
->neigh_id
,
1278 circuit
->u
.bc
.l2_desig_is
, ISIS_SYS_ID_LEN
+ 1);
1279 metric
= ((htonl(*circuit
->te_metric
) >> 8) & 0xffffff);
1280 memcpy (te_is_neigh
->te_metric
, &metric
, 3);
1281 listnode_add (tlv_data
.te_is_neighs
, te_is_neigh
);
1286 nei
= circuit
->u
.p2p
.neighbor
;
1287 if (nei
&& (level
& nei
->circuit_t
))
1289 if (area
->oldmetric
)
1291 if (tlv_data
.is_neighs
== NULL
)
1293 tlv_data
.is_neighs
= list_new ();
1294 tlv_data
.is_neighs
->del
= free_tlv
;
1296 is_neigh
= XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct is_neigh
));
1297 memcpy (is_neigh
->neigh_id
, nei
->sysid
, ISIS_SYS_ID_LEN
);
1298 is_neigh
->metrics
= circuit
->metrics
[level
- 1];
1299 listnode_add (tlv_data
.is_neighs
, is_neigh
);
1301 if (area
->newmetric
)
1305 if (tlv_data
.te_is_neighs
== NULL
)
1307 tlv_data
.te_is_neighs
= list_new ();
1308 tlv_data
.te_is_neighs
->del
= free_tlv
;
1310 te_is_neigh
= XCALLOC (MTYPE_ISIS_TLV
,
1311 sizeof (struct te_is_neigh
));
1312 memcpy (te_is_neigh
->neigh_id
, nei
->sysid
, ISIS_SYS_ID_LEN
);
1313 metric
= ((htonl(*circuit
->te_metric
) >> 8) & 0xffffff);
1314 memcpy (te_is_neigh
->te_metric
, &metric
, 3);
1315 listnode_add (tlv_data
.te_is_neighs
, te_is_neigh
);
1319 case CIRCUIT_T_STATIC_IN
:
1320 zlog_warn ("lsp_area_create: unsupported circuit type");
1322 case CIRCUIT_T_STATIC_OUT
:
1323 zlog_warn ("lsp_area_create: unsupported circuit type");
1326 zlog_warn ("lsp_area_create: unsupported circuit type");
1329 zlog_warn ("lsp_area_create: unknown circuit type");
1333 while (tlv_data
.ipv4_int_reachs
&& listcount (tlv_data
.ipv4_int_reachs
))
1335 if (lsp
->tlv_data
.ipv4_int_reachs
== NULL
)
1336 lsp
->tlv_data
.ipv4_int_reachs
= list_new ();
1337 lsp_tlv_fit (lsp
, &tlv_data
.ipv4_int_reachs
,
1338 &lsp
->tlv_data
.ipv4_int_reachs
,
1339 IPV4_REACH_LEN
, area
->lsp_frag_threshold
,
1340 tlv_add_ipv4_reachs
);
1341 if (tlv_data
.ipv4_int_reachs
&& listcount (tlv_data
.ipv4_int_reachs
))
1342 lsp
= lsp_next_frag (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) + 1,
1345 /* FIXME: We pass maximum te_ipv4_reachability length to the lsp_tlv_fit()
1346 * for now. lsp_tlv_fit() needs to be fixed to deal with variable length
1347 * TLVs (sub TLVs!). */
1348 while (tlv_data
.te_ipv4_reachs
&& listcount (tlv_data
.te_ipv4_reachs
))
1350 if (lsp
->tlv_data
.te_ipv4_reachs
== NULL
)
1351 lsp
->tlv_data
.te_ipv4_reachs
= list_new ();
1352 lsp_tlv_fit (lsp
, &tlv_data
.te_ipv4_reachs
,
1353 &lsp
->tlv_data
.te_ipv4_reachs
,
1354 9, area
->lsp_frag_threshold
, tlv_add_te_ipv4_reachs
);
1355 if (tlv_data
.te_ipv4_reachs
&& listcount (tlv_data
.te_ipv4_reachs
))
1356 lsp
= lsp_next_frag (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) + 1,
1361 while (tlv_data
.ipv6_reachs
&& listcount (tlv_data
.ipv6_reachs
))
1363 if (lsp
->tlv_data
.ipv6_reachs
== NULL
)
1364 lsp
->tlv_data
.ipv6_reachs
= list_new ();
1365 lsp_tlv_fit (lsp
, &tlv_data
.ipv6_reachs
,
1366 &lsp
->tlv_data
.ipv6_reachs
,
1367 IPV6_REACH_LEN
, area
->lsp_frag_threshold
,
1368 tlv_add_ipv6_reachs
);
1369 if (tlv_data
.ipv6_reachs
&& listcount (tlv_data
.ipv6_reachs
))
1370 lsp
= lsp_next_frag (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) + 1,
1373 #endif /* HAVE_IPV6 */
1375 while (tlv_data
.is_neighs
&& listcount (tlv_data
.is_neighs
))
1377 if (lsp
->tlv_data
.is_neighs
== NULL
)
1378 lsp
->tlv_data
.is_neighs
= list_new ();
1379 lsp_tlv_fit (lsp
, &tlv_data
.is_neighs
,
1380 &lsp
->tlv_data
.is_neighs
,
1381 IS_NEIGHBOURS_LEN
, area
->lsp_frag_threshold
,
1383 if (tlv_data
.is_neighs
&& listcount (tlv_data
.is_neighs
))
1384 lsp
= lsp_next_frag (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) + 1,
1388 while (tlv_data
.te_is_neighs
&& listcount (tlv_data
.te_is_neighs
))
1390 if (lsp
->tlv_data
.te_is_neighs
== NULL
)
1391 lsp
->tlv_data
.te_is_neighs
= list_new ();
1392 lsp_tlv_fit (lsp
, &tlv_data
.te_is_neighs
, &lsp
->tlv_data
.te_is_neighs
,
1393 IS_NEIGHBOURS_LEN
, area
->lsp_frag_threshold
,
1394 tlv_add_te_is_neighs
);
1395 if (tlv_data
.te_is_neighs
&& listcount (tlv_data
.te_is_neighs
))
1396 lsp
= lsp_next_frag (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) + 1,
1400 free_tlvs (&tlv_data
);
1405 * 7.3.7 Generation on non-pseudonode LSPs
1408 lsp_generate_non_pseudo (struct isis_area
*area
, int level
)
1410 struct isis_lsp
*oldlsp
, *newlsp
;
1411 u_int32_t seq_num
= 0;
1412 u_char lspid
[ISIS_SYS_ID_LEN
+ 2];
1414 memset (&lspid
, 0, ISIS_SYS_ID_LEN
+ 2);
1415 memcpy (&lspid
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1417 /* only builds the lsp if the area shares the level */
1418 if ((area
->is_type
& level
) == level
)
1420 oldlsp
= lsp_search (lspid
, area
->lspdb
[level
- 1]);
1423 seq_num
= ntohl (oldlsp
->lsp_header
->seq_num
);
1424 lsp_search_and_destroy (oldlsp
->lsp_header
->lsp_id
,
1425 area
->lspdb
[level
- 1]);
1426 /* FIXME: we should actually initiate a purge */
1428 newlsp
= lsp_new (lspid
, area
->max_lsp_lifetime
[level
- 1], seq_num
,
1429 area
->is_type
, 0, level
);
1430 newlsp
->own_lsp
= 1;
1432 lsp_insert (newlsp
, area
->lspdb
[level
- 1]);
1433 /* build_lsp_data (newlsp, area); */
1434 lsp_build_nonpseudo (newlsp
, area
);
1435 /* time to calculate our checksum */
1436 lsp_seqnum_update (newlsp
);
1439 /* DEBUG_ADJ_PACKETS */
1440 if (isis
->debugs
& DEBUG_ADJ_PACKETS
)
1442 /* FIXME: is this place right? fix missing info */
1443 zlog_debug ("ISIS-Upd (%s): Building L%d LSP", area
->area_tag
, level
);
1450 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
1453 lsp_l1_generate (struct isis_area
*area
)
1455 THREAD_TIMER_ON (master
, area
->t_lsp_refresh
[0], lsp_refresh_l1
, area
,
1456 MAX_LSP_GEN_INTERVAL
);
1458 return lsp_generate_non_pseudo (area
, 1);
1462 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
1465 lsp_l2_generate (struct isis_area
*area
)
1467 THREAD_TIMER_ON (master
, area
->t_lsp_refresh
[1], lsp_refresh_l2
, area
,
1468 MAX_LSP_GEN_INTERVAL
);
1470 return lsp_generate_non_pseudo (area
, 2);
1474 lsp_non_pseudo_regenerate (struct isis_area
*area
, int level
)
1476 dict_t
*lspdb
= area
->lspdb
[level
- 1];
1477 struct isis_lsp
*lsp
, *frag
;
1478 struct listnode
*node
;
1479 u_char lspid
[ISIS_SYS_ID_LEN
+ 2];
1481 memset (lspid
, 0, ISIS_SYS_ID_LEN
+ 2);
1482 memcpy (lspid
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1484 lsp
= lsp_search (lspid
, lspdb
);
1489 ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
1490 area
->area_tag
, level
);
1495 lsp_clear_data (lsp
);
1496 lsp_build_nonpseudo (lsp
, area
);
1497 lsp
->lsp_header
->rem_lifetime
= htons (isis_jitter
1498 (area
->max_lsp_lifetime
[level
- 1],
1500 lsp_seqnum_update (lsp
);
1502 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
1504 zlog_debug ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
1505 "seq 0x%08x, cksum 0x%04x lifetime %us",
1508 rawlspid_print (lsp
->lsp_header
->lsp_id
),
1509 ntohl (lsp
->lsp_header
->seq_num
),
1510 ntohs (lsp
->lsp_header
->checksum
),
1511 ntohs (lsp
->lsp_header
->rem_lifetime
));
1514 lsp
->last_generated
= time (NULL
);
1515 area
->lsp_regenerate_pending
[level
- 1] = 0;
1516 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
1517 for (ALL_LIST_ELEMENTS_RO (lsp
->lspu
.frags
, node
, frag
))
1519 frag
->lsp_header
->rem_lifetime
= htons (isis_jitter
1521 max_lsp_lifetime
[level
- 1],
1523 ISIS_FLAGS_SET_ALL (frag
->SRMflags
);
1526 if (area
->ip_circuits
)
1527 isis_spf_schedule (area
, level
);
1529 if (area
->ipv6_circuits
)
1530 isis_spf_schedule6 (area
, level
);
1536 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
1540 lsp_refresh_l1 (struct thread
*thread
)
1542 struct isis_area
*area
;
1543 unsigned long ref_time
;
1545 area
= THREAD_ARG (thread
);
1548 area
->t_lsp_refresh
[0] = NULL
;
1549 if (area
->is_type
& IS_LEVEL_1
)
1550 lsp_non_pseudo_regenerate (area
, 1);
1552 ref_time
= area
->lsp_refresh
[0] > MAX_LSP_GEN_INTERVAL
?
1553 MAX_LSP_GEN_INTERVAL
: area
->lsp_refresh
[0];
1555 THREAD_TIMER_ON (master
, area
->t_lsp_refresh
[0], lsp_refresh_l1
, area
,
1556 isis_jitter (ref_time
, MAX_AGE_JITTER
));
1562 lsp_refresh_l2 (struct thread
*thread
)
1564 struct isis_area
*area
;
1565 unsigned long ref_time
;
1567 area
= THREAD_ARG (thread
);
1570 area
->t_lsp_refresh
[1] = NULL
;
1571 if (area
->is_type
& IS_LEVEL_2
)
1572 lsp_non_pseudo_regenerate (area
, 2);
1574 ref_time
= area
->lsp_refresh
[1] > MAX_LSP_GEN_INTERVAL
?
1575 MAX_LSP_GEN_INTERVAL
: area
->lsp_refresh
[1];
1577 THREAD_TIMER_ON (master
, area
->t_lsp_refresh
[1], lsp_refresh_l2
, area
,
1578 isis_jitter (ref_time
, MAX_AGE_JITTER
));
1584 * Something has changed -> regenerate LSP
1588 lsp_l1_regenerate (struct thread
*thread
)
1590 struct isis_area
*area
;
1592 area
= THREAD_ARG (thread
);
1593 area
->lsp_regenerate_pending
[0] = 0;
1595 return lsp_non_pseudo_regenerate (area
, 1);
1599 lsp_l2_regenerate (struct thread
*thread
)
1601 struct isis_area
*area
;
1603 area
= THREAD_ARG (thread
);
1604 area
->lsp_regenerate_pending
[1] = 0;
1606 return lsp_non_pseudo_regenerate (area
, 2);
1610 lsp_regenerate_schedule (struct isis_area
*area
)
1612 struct isis_lsp
*lsp
;
1613 u_char id
[ISIS_SYS_ID_LEN
+ 2];
1615 memcpy (id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1616 LSP_PSEUDO_ID (id
) = LSP_FRAGMENT (id
) = 0;
1621 if (area
->is_type
& IS_LEVEL_1
)
1623 lsp
= lsp_search (id
, area
->lspdb
[0]);
1624 if (!lsp
|| area
->lsp_regenerate_pending
[0])
1627 * Throttle avoidance
1629 diff
= now
- lsp
->last_generated
;
1630 if (diff
< MIN_LSP_GEN_INTERVAL
)
1632 area
->lsp_regenerate_pending
[0] = 1;
1633 thread_add_timer (master
, lsp_l1_regenerate
, area
,
1634 MIN_LSP_GEN_INTERVAL
- diff
);
1638 lsp_non_pseudo_regenerate (area
, 1);
1644 if (area
->is_type
& IS_LEVEL_2
)
1646 lsp
= lsp_search (id
, area
->lspdb
[1]);
1647 if (!lsp
|| area
->lsp_regenerate_pending
[1])
1650 * Throttle avoidance
1652 diff
= now
- lsp
->last_generated
;
1653 if (diff
< MIN_LSP_GEN_INTERVAL
)
1655 area
->lsp_regenerate_pending
[1] = 1;
1656 thread_add_timer (master
, lsp_l2_regenerate
, area
,
1657 MIN_LSP_GEN_INTERVAL
- diff
);
1661 lsp_non_pseudo_regenerate (area
, 2);
1668 * Funcs for pseudonode LSPs
1672 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs
1675 lsp_build_pseudo (struct isis_lsp
*lsp
, struct isis_circuit
*circuit
,
1678 struct isis_adjacency
*adj
;
1679 struct is_neigh
*is_neigh
;
1680 struct te_is_neigh
*te_is_neigh
;
1681 struct es_neigh
*es_neigh
;
1682 struct list
*adj_list
;
1683 struct listnode
*node
, *nnode
;
1684 struct isis_passwd
*passwd
;
1687 assert (circuit
->circ_type
== CIRCUIT_T_BROADCAST
);
1689 if (!circuit
->u
.bc
.is_dr
[level
- 1])
1690 return; /* we are not DIS on this circuit */
1694 lsp
->lsp_header
->lsp_bits
|= IS_LEVEL_1
;
1696 lsp
->lsp_header
->lsp_bits
|= IS_LEVEL_2
;
1699 * add self to IS neighbours
1701 if (circuit
->area
->oldmetric
)
1703 if (lsp
->tlv_data
.is_neighs
== NULL
)
1705 lsp
->tlv_data
.is_neighs
= list_new ();
1706 lsp
->tlv_data
.is_neighs
->del
= free_tlv
;
1708 is_neigh
= XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct is_neigh
));
1710 memcpy (&is_neigh
->neigh_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1711 listnode_add (lsp
->tlv_data
.is_neighs
, is_neigh
);
1713 if (circuit
->area
->newmetric
)
1715 if (lsp
->tlv_data
.te_is_neighs
== NULL
)
1717 lsp
->tlv_data
.te_is_neighs
= list_new ();
1718 lsp
->tlv_data
.te_is_neighs
->del
= free_tlv
;
1720 te_is_neigh
= XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct te_is_neigh
));
1722 memcpy (&te_is_neigh
->neigh_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1723 listnode_add (lsp
->tlv_data
.te_is_neighs
, te_is_neigh
);
1726 adj_list
= list_new ();
1727 isis_adj_build_up_list (circuit
->u
.bc
.adjdb
[level
- 1], adj_list
);
1729 for (ALL_LIST_ELEMENTS (adj_list
, node
, nnode
, adj
))
1731 if (adj
->circuit_t
& level
)
1733 if ((level
== 1 && adj
->sys_type
== ISIS_SYSTYPE_L1_IS
) ||
1734 (level
== 1 && adj
->sys_type
== ISIS_SYSTYPE_L2_IS
&&
1735 adj
->adj_usage
== ISIS_ADJ_LEVEL1AND2
) ||
1736 (level
== 2 && adj
->sys_type
== ISIS_SYSTYPE_L2_IS
))
1738 /* an IS neighbour -> add it */
1739 if (circuit
->area
->oldmetric
)
1741 is_neigh
= XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct is_neigh
));
1743 memcpy (&is_neigh
->neigh_id
, adj
->sysid
, ISIS_SYS_ID_LEN
);
1744 listnode_add (lsp
->tlv_data
.is_neighs
, is_neigh
);
1746 if (circuit
->area
->newmetric
)
1748 te_is_neigh
= XCALLOC (MTYPE_ISIS_TLV
,
1749 sizeof (struct te_is_neigh
));
1750 memcpy (&te_is_neigh
->neigh_id
, adj
->sysid
, ISIS_SYS_ID_LEN
);
1751 listnode_add (lsp
->tlv_data
.te_is_neighs
, te_is_neigh
);
1754 else if (level
== 1 && adj
->sys_type
== ISIS_SYSTYPE_ES
)
1756 /* an ES neigbour add it, if we are building level 1 LSP */
1757 /* FIXME: the tlv-format is hard to use here */
1758 if (lsp
->tlv_data
.es_neighs
== NULL
)
1760 lsp
->tlv_data
.es_neighs
= list_new ();
1761 lsp
->tlv_data
.es_neighs
->del
= free_tlv
;
1763 es_neigh
= XCALLOC (MTYPE_ISIS_TLV
, sizeof (struct es_neigh
));
1765 memcpy (&es_neigh
->first_es_neigh
, adj
->sysid
, ISIS_SYS_ID_LEN
);
1766 listnode_add (lsp
->tlv_data
.es_neighs
, es_neigh
);
1771 /* Reset endp of stream to overwrite only TLV part of it. */
1772 stream_reset (lsp
->pdu
);
1773 stream_forward_endp (lsp
->pdu
, ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
1776 * Add the authentication info if it's present
1778 (level
== 1) ? (passwd
= &circuit
->area
->area_passwd
) :
1779 (passwd
= &circuit
->area
->domain_passwd
);
1782 memcpy (&lsp
->tlv_data
.auth_info
, passwd
, sizeof (struct isis_passwd
));
1783 tlv_add_authinfo (passwd
->type
, passwd
->len
, passwd
->passwd
, lsp
->pdu
);
1786 if (lsp
->tlv_data
.is_neighs
&& listcount (lsp
->tlv_data
.is_neighs
) > 0)
1787 tlv_add_is_neighs (lsp
->tlv_data
.is_neighs
, lsp
->pdu
);
1789 if (lsp
->tlv_data
.te_is_neighs
&& listcount (lsp
->tlv_data
.te_is_neighs
) > 0)
1790 tlv_add_te_is_neighs (lsp
->tlv_data
.te_is_neighs
, lsp
->pdu
);
1792 if (lsp
->tlv_data
.es_neighs
&& listcount (lsp
->tlv_data
.es_neighs
) > 0)
1793 tlv_add_is_neighs (lsp
->tlv_data
.es_neighs
, lsp
->pdu
);
1795 lsp
->lsp_header
->pdu_len
= htons (stream_get_endp (lsp
->pdu
));
1796 iso_csum_create (STREAM_DATA (lsp
->pdu
) + 12,
1797 ntohs (lsp
->lsp_header
->pdu_len
) - 12, 12);
1799 list_delete (adj_list
);
1805 lsp_pseudo_regenerate (struct isis_circuit
*circuit
, int level
)
1807 dict_t
*lspdb
= circuit
->area
->lspdb
[level
- 1];
1808 struct isis_lsp
*lsp
;
1809 u_char lsp_id
[ISIS_SYS_ID_LEN
+ 2];
1811 memcpy (lsp_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1812 LSP_PSEUDO_ID (lsp_id
) = circuit
->circuit_id
;
1813 LSP_FRAGMENT (lsp_id
) = 0;
1815 lsp
= lsp_search (lsp_id
, lspdb
);
1819 zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level
,
1820 rawlspid_print (lsp_id
));
1823 lsp_clear_data (lsp
);
1825 lsp_build_pseudo (lsp
, circuit
, level
);
1827 lsp
->lsp_header
->rem_lifetime
=
1828 htons (isis_jitter (circuit
->area
->max_lsp_lifetime
[level
- 1],
1831 lsp_inc_seqnum (lsp
, 0);
1833 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
1835 zlog_debug ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s",
1836 circuit
->area
->area_tag
, level
,
1837 rawlspid_print (lsp
->lsp_header
->lsp_id
));
1840 lsp
->last_generated
= time (NULL
);
1841 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
1847 lsp_l1_refresh_pseudo (struct thread
*thread
)
1849 struct isis_circuit
*circuit
;
1851 unsigned long ref_time
;
1853 circuit
= THREAD_ARG (thread
);
1855 if (!circuit
->u
.bc
.is_dr
[0])
1856 return ISIS_ERROR
; /* FIXME: purge and such */
1858 circuit
->u
.bc
.t_refresh_pseudo_lsp
[0] = NULL
;
1860 retval
= lsp_pseudo_regenerate (circuit
, 1);
1862 ref_time
= circuit
->area
->lsp_refresh
[0] > MAX_LSP_GEN_INTERVAL
?
1863 MAX_LSP_GEN_INTERVAL
: circuit
->area
->lsp_refresh
[0];
1865 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_refresh_pseudo_lsp
[0],
1866 lsp_l1_refresh_pseudo
, circuit
,
1867 isis_jitter (ref_time
, MAX_AGE_JITTER
));
1873 lsp_l1_pseudo_generate (struct isis_circuit
*circuit
)
1875 struct isis_lsp
*lsp
;
1876 u_char id
[ISIS_SYS_ID_LEN
+ 2];
1877 unsigned long ref_time
;
1879 memcpy (id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1880 LSP_FRAGMENT (id
) = 0;
1881 LSP_PSEUDO_ID (id
) = circuit
->circuit_id
;
1884 * If for some reason have a pseudo LSP in the db already -> regenerate
1886 if (lsp_search (id
, circuit
->area
->lspdb
[0]))
1887 return lsp_pseudo_regenerate (circuit
, 1);
1888 lsp
= lsp_new (id
, circuit
->area
->max_lsp_lifetime
[0],
1889 1, circuit
->area
->is_type
, 0, 1);
1891 lsp_build_pseudo (lsp
, circuit
, 1);
1894 lsp_insert (lsp
, circuit
->area
->lspdb
[0]);
1895 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
1897 ref_time
= circuit
->area
->lsp_refresh
[0] > MAX_LSP_GEN_INTERVAL
?
1898 MAX_LSP_GEN_INTERVAL
: circuit
->area
->lsp_refresh
[0];
1900 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_refresh_pseudo_lsp
[0],
1901 lsp_l1_refresh_pseudo
, circuit
,
1902 isis_jitter (ref_time
, MAX_AGE_JITTER
));
1904 return lsp_regenerate_schedule (circuit
->area
);
1908 lsp_l2_refresh_pseudo (struct thread
*thread
)
1910 struct isis_circuit
*circuit
;
1912 unsigned long ref_time
;
1913 circuit
= THREAD_ARG (thread
);
1915 if (!circuit
->u
.bc
.is_dr
[1])
1916 return ISIS_ERROR
; /* FIXME: purge and such */
1918 circuit
->u
.bc
.t_refresh_pseudo_lsp
[1] = NULL
;
1920 retval
= lsp_pseudo_regenerate (circuit
, 2);
1922 ref_time
= circuit
->area
->lsp_refresh
[1] > MAX_LSP_GEN_INTERVAL
?
1923 MAX_LSP_GEN_INTERVAL
: circuit
->area
->lsp_refresh
[1];
1925 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_refresh_pseudo_lsp
[1],
1926 lsp_l2_refresh_pseudo
, circuit
,
1927 isis_jitter (ref_time
, MAX_AGE_JITTER
));
1933 lsp_l2_pseudo_generate (struct isis_circuit
*circuit
)
1935 struct isis_lsp
*lsp
;
1936 u_char id
[ISIS_SYS_ID_LEN
+ 2];
1937 unsigned long ref_time
;
1939 memcpy (id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
1940 LSP_FRAGMENT (id
) = 0;
1941 LSP_PSEUDO_ID (id
) = circuit
->circuit_id
;
1943 if (lsp_search (id
, circuit
->area
->lspdb
[1]))
1944 return lsp_pseudo_regenerate (circuit
, 2);
1946 lsp
= lsp_new (id
, circuit
->area
->max_lsp_lifetime
[1],
1947 1, circuit
->area
->is_type
, 0, 2);
1949 lsp_build_pseudo (lsp
, circuit
, 2);
1951 ref_time
= circuit
->area
->lsp_refresh
[1] > MAX_LSP_GEN_INTERVAL
?
1952 MAX_LSP_GEN_INTERVAL
: circuit
->area
->lsp_refresh
[1];
1956 lsp_insert (lsp
, circuit
->area
->lspdb
[1]);
1957 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
1959 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_refresh_pseudo_lsp
[1],
1960 lsp_l2_refresh_pseudo
, circuit
,
1961 isis_jitter (ref_time
, MAX_AGE_JITTER
));
1963 return lsp_regenerate_schedule (circuit
->area
);
1967 * Walk through LSPs for an area
1968 * - set remaining lifetime
1969 * - set LSPs with SRMflag set for sending
1972 lsp_tick (struct thread
*thread
)
1974 struct isis_area
*area
;
1975 struct isis_circuit
*circuit
;
1976 struct isis_lsp
*lsp
;
1977 struct list
*lsp_list
;
1978 struct listnode
*lspnode
, *lspnnode
, *cnode
;
1979 dnode_t
*dnode
, *dnode_next
;
1982 lsp_list
= list_new ();
1984 area
= THREAD_ARG (thread
);
1986 area
->t_tick
= NULL
;
1987 THREAD_TIMER_ON (master
, area
->t_tick
, lsp_tick
, area
, 1);
1990 * Build a list of LSPs with (any) SRMflag set
1991 * and removed the ones that have aged out
1993 for (level
= 0; level
< ISIS_LEVELS
; level
++)
1995 if (area
->lspdb
[level
] && dict_count (area
->lspdb
[level
]) > 0)
1997 dnode
= dict_first (area
->lspdb
[level
]);
1998 while (dnode
!= NULL
)
2000 dnode_next
= dict_next (area
->lspdb
[level
], dnode
);
2001 lsp
= dnode_get (dnode
);
2003 if (lsp
->age_out
== 0)
2006 zlog_debug ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
2009 rawlspid_print (lsp
->lsp_header
->lsp_id
),
2010 ntohl (lsp
->lsp_header
->seq_num
));
2011 #ifdef TOPOLOGY_GENERATE
2012 if (lsp
->from_topology
)
2013 THREAD_TIMER_OFF (lsp
->t_lsp_top_ref
);
2014 #endif /* TOPOLOGY_GENERATE */
2016 dict_delete (area
->lspdb
[level
], dnode
);
2018 else if (flags_any_set (lsp
->SRMflags
))
2019 listnode_add (lsp_list
, lsp
);
2024 * Send LSPs on circuits indicated by the SRMflags
2026 if (listcount (lsp_list
) > 0)
2028 for (ALL_LIST_ELEMENTS_RO (area
->circuit_list
, cnode
, circuit
))
2030 for (ALL_LIST_ELEMENTS (lsp_list
, lspnode
, lspnnode
, lsp
))
2032 if (ISIS_CHECK_FLAG (lsp
->SRMflags
, circuit
))
2034 /* FIXME: if same or elder lsp is already in lsp
2036 listnode_add (circuit
->lsp_queue
, lsp
);
2037 thread_add_event (master
, send_lsp
, circuit
, 0);
2042 list_delete_all_node (lsp_list
);
2046 list_delete (lsp_list
);
2052 lsp_purge_dr (u_char
* id
, struct isis_circuit
*circuit
, int level
)
2054 struct isis_lsp
*lsp
;
2056 lsp
= lsp_search (id
, circuit
->area
->lspdb
[level
- 1]);
2058 if (lsp
&& lsp
->purged
== 0)
2060 lsp
->lsp_header
->rem_lifetime
= htons (0);
2061 lsp
->lsp_header
->pdu_len
=
2062 htons (ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
2064 iso_csum_create (STREAM_DATA (lsp
->pdu
) + 12,
2065 ntohs (lsp
->lsp_header
->pdu_len
) - 12, 12);
2066 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
2073 * Purge own LSP that is received and we don't have.
2074 * -> Do as in 7.3.16.4
2077 lsp_purge_non_exist (struct isis_link_state_hdr
*lsp_hdr
,
2078 struct isis_area
*area
)
2080 struct isis_lsp
*lsp
;
2083 * We need to create the LSP to be purged
2085 zlog_debug ("LSP PURGE NON EXIST");
2086 lsp
= XCALLOC (MTYPE_ISIS_LSP
, sizeof (struct isis_lsp
));
2087 /*FIXME: BUG BUG BUG! the lsp doesn't exist here! */
2088 /*did smt here, maybe good probably not */
2089 lsp
->level
= ((lsp_hdr
->lsp_bits
& LSPBIT_IST
) == IS_LEVEL_1
) ? 1 : 2;
2090 lsp
->pdu
= stream_new (ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
2091 lsp
->isis_header
= (struct isis_fixed_hdr
*) STREAM_DATA (lsp
->pdu
);
2092 fill_fixed_hdr (lsp
->isis_header
, (lsp
->level
== 1) ? L1_LINK_STATE
2094 lsp
->lsp_header
= (struct isis_link_state_hdr
*) (STREAM_DATA (lsp
->pdu
) +
2095 ISIS_FIXED_HDR_LEN
);
2096 memcpy (lsp
->lsp_header
, lsp_hdr
, ISIS_LSP_HDR_LEN
);
2099 * Retain only LSP header
2101 lsp
->lsp_header
->pdu_len
= htons (ISIS_FIXED_HDR_LEN
+ ISIS_LSP_HDR_LEN
);
2103 * Set the remaining lifetime to 0
2105 lsp
->lsp_header
->rem_lifetime
= 0;
2107 * Put the lsp into LSPdb
2109 lsp_insert (lsp
, area
->lspdb
[lsp
->level
- 1]);
2112 * Send in to whole area
2114 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
2119 #ifdef TOPOLOGY_GENERATE
2121 top_lsp_refresh (struct thread
*thread
)
2123 struct isis_lsp
*lsp
;
2124 unsigned long ref_time
;
2126 lsp
= THREAD_ARG (thread
);
2129 lsp
->t_lsp_top_ref
= NULL
;
2131 lsp_seqnum_update (lsp
);
2133 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
2134 if (isis
->debugs
& DEBUG_UPDATE_PACKETS
)
2136 zlog_debug ("ISIS-Upd (): refreshing Topology L1 %s",
2137 rawlspid_print (lsp
->lsp_header
->lsp_id
));
2139 lsp
->lsp_header
->rem_lifetime
=
2140 htons (isis_jitter (lsp
->area
->max_lsp_lifetime
[0], MAX_AGE_JITTER
));
2142 ref_time
= lsp
->area
->lsp_refresh
[0] > MAX_LSP_GEN_INTERVAL
?
2143 MAX_LSP_GEN_INTERVAL
: lsp
->area
->lsp_refresh
[0];
2145 THREAD_TIMER_ON (master
, lsp
->t_lsp_top_ref
, top_lsp_refresh
, lsp
,
2146 isis_jitter (ref_time
, MAX_LSP_GEN_JITTER
));
2152 generate_topology_lsps (struct isis_area
*area
)
2154 struct listnode
*node
;
2157 u_char lspid
[ISIS_SYS_ID_LEN
+ 2];
2158 struct isis_lsp
*lsp
;
2159 unsigned long ref_time
;
2161 /* first we find the maximal node */
2162 for (ALL_LIST_ELEMENTS_RO (area
->topology
, node
, arc
))
2164 if (arc
->from_node
> max
)
2165 max
= arc
->from_node
;
2166 if (arc
->to_node
> max
)
2170 for (i
= 1; i
< (max
+ 1); i
++)
2172 memcpy (lspid
, area
->topology_baseis
, ISIS_SYS_ID_LEN
);
2173 LSP_PSEUDO_ID (lspid
) = 0x00;
2174 LSP_FRAGMENT (lspid
) = 0x00;
2175 lspid
[ISIS_SYS_ID_LEN
- 1] = (i
& 0xFF);
2176 lspid
[ISIS_SYS_ID_LEN
- 2] = ((i
>> 8) & 0xFF);
2178 lsp
= lsp_new (lspid
, isis_jitter (area
->max_lsp_lifetime
[0],
2179 MAX_AGE_JITTER
), 1, IS_LEVEL_1
, 0, 1);
2182 lsp
->from_topology
= 1;
2185 /* Creating LSP data based on topology info. */
2186 build_topology_lsp_data (lsp
, area
, i
);
2187 /* Checksum is also calculated here. */
2188 lsp_seqnum_update (lsp
);
2190 ref_time
= area
->lsp_refresh
[0] > MAX_LSP_GEN_INTERVAL
?
2191 MAX_LSP_GEN_INTERVAL
: area
->lsp_refresh
[0];
2193 THREAD_TIMER_ON (master
, lsp
->t_lsp_top_ref
, top_lsp_refresh
, lsp
,
2194 isis_jitter (ref_time
, MAX_LSP_GEN_JITTER
));
2195 ISIS_FLAGS_SET_ALL (lsp
->SRMflags
);
2196 lsp_insert (lsp
, area
->lspdb
[0]);
2201 remove_topology_lsps (struct isis_area
*area
)
2203 struct isis_lsp
*lsp
;
2204 dnode_t
*dnode
, *dnode_next
;
2206 dnode
= dict_first (area
->lspdb
[0]);
2207 while (dnode
!= NULL
)
2209 dnode_next
= dict_next (area
->lspdb
[0], dnode
);
2210 lsp
= dnode_get (dnode
);
2211 if (lsp
->from_topology
)
2213 THREAD_TIMER_OFF (lsp
->t_lsp_top_ref
);
2215 dict_delete (area
->lspdb
[0], dnode
);
2222 build_topology_lsp_data (struct isis_lsp
*lsp
, struct isis_area
*area
,
2225 struct listnode
*node
, *nnode
;
2227 struct is_neigh
*is_neigh
;
2229 struct tlvs tlv_data
;
2230 struct isis_lsp
*lsp0
= lsp
;
2232 /* Add area addresses. FIXME: Is it needed at all? */
2233 if (lsp
->tlv_data
.area_addrs
== NULL
)
2234 lsp
->tlv_data
.area_addrs
= list_new ();
2235 list_add_list (lsp
->tlv_data
.area_addrs
, area
->area_addrs
);
2237 if (lsp
->tlv_data
.nlpids
== NULL
)
2238 lsp
->tlv_data
.nlpids
= XMALLOC (MTYPE_ISIS_TLV
, sizeof (struct nlpids
));
2239 lsp
->tlv_data
.nlpids
->count
= 1;
2240 lsp
->tlv_data
.nlpids
->nlpids
[0] = NLPID_IP
;
2242 if (area
->dynhostname
)
2244 lsp
->tlv_data
.hostname
= XMALLOC (MTYPE_ISIS_TLV
,
2245 sizeof (struct hostname
));
2246 memset (buff
, 0x00, 200);
2247 sprintf (buff
, "%s%d", area
->topology_basedynh
? area
->topology_basedynh
:
2248 "feedme", lsp_top_num
);
2249 memcpy (lsp
->tlv_data
.hostname
->name
, buff
, strlen (buff
));
2250 lsp
->tlv_data
.hostname
->namelen
= strlen (buff
);
2253 if (lsp
->tlv_data
.nlpids
)
2254 tlv_add_nlpid (lsp
->tlv_data
.nlpids
, lsp
->pdu
);
2255 if (lsp
->tlv_data
.hostname
)
2256 tlv_add_dynamic_hostname (lsp
->tlv_data
.hostname
, lsp
->pdu
);
2257 if (lsp
->tlv_data
.area_addrs
&& listcount (lsp
->tlv_data
.area_addrs
) > 0)
2258 tlv_add_area_addrs (lsp
->tlv_data
.area_addrs
, lsp
->pdu
);
2260 memset (&tlv_data
, 0, sizeof (struct tlvs
));
2261 if (tlv_data
.is_neighs
== NULL
)
2262 tlv_data
.is_neighs
= list_new ();
2264 /* Add reachability for this IS for simulated 1. */
2265 if (lsp_top_num
== 1)
2267 is_neigh
= XMALLOC (MTYPE_ISIS_TLV
, sizeof (struct is_neigh
));
2268 memset (is_neigh
, 0, sizeof (struct is_neigh
));
2270 memcpy (&is_neigh
->neigh_id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
2271 LSP_PSEUDO_ID (is_neigh
->neigh_id
) = 0x00;
2272 /* Metric MUST NOT be 0, unless it's not alias TLV. */
2273 is_neigh
->metrics
.metric_default
= 0x01;
2274 is_neigh
->metrics
.metric_delay
= METRICS_UNSUPPORTED
;
2275 is_neigh
->metrics
.metric_expense
= METRICS_UNSUPPORTED
;
2276 is_neigh
->metrics
.metric_error
= METRICS_UNSUPPORTED
;
2277 listnode_add (tlv_data
.is_neighs
, is_neigh
);
2280 /* Add IS reachabilities. */
2281 for (ALL_LIST_ELEMENTS (area
->topology
, node
, nnode
, arc
))
2285 if ((lsp_top_num
!= arc
->from_node
) && (lsp_top_num
!= arc
->to_node
))
2288 if (lsp_top_num
== arc
->from_node
)
2289 to_lsp
= arc
->to_node
;
2291 to_lsp
= arc
->from_node
;
2293 is_neigh
= XMALLOC (MTYPE_ISIS_TLV
, sizeof (struct is_neigh
));
2294 memset (is_neigh
, 0, sizeof (struct is_neigh
));
2296 memcpy (&is_neigh
->neigh_id
, area
->topology_baseis
, ISIS_SYS_ID_LEN
);
2297 is_neigh
->neigh_id
[ISIS_SYS_ID_LEN
- 1] = (to_lsp
& 0xFF);
2298 is_neigh
->neigh_id
[ISIS_SYS_ID_LEN
- 2] = ((to_lsp
>> 8) & 0xFF);
2299 is_neigh
->metrics
.metric_default
= arc
->distance
;
2300 is_neigh
->metrics
.metric_delay
= METRICS_UNSUPPORTED
;
2301 is_neigh
->metrics
.metric_expense
= METRICS_UNSUPPORTED
;
2302 is_neigh
->metrics
.metric_error
= METRICS_UNSUPPORTED
;
2303 listnode_add (tlv_data
.is_neighs
, is_neigh
);
2306 while (tlv_data
.is_neighs
&& listcount (tlv_data
.is_neighs
))
2308 if (lsp
->tlv_data
.is_neighs
== NULL
)
2309 lsp
->tlv_data
.is_neighs
= list_new ();
2310 lsp_tlv_fit (lsp
, &tlv_data
.is_neighs
,
2311 &lsp
->tlv_data
.is_neighs
,
2312 IS_NEIGHBOURS_LEN
, area
->lsp_frag_threshold
,
2314 if (tlv_data
.is_neighs
&& listcount (tlv_data
.is_neighs
))
2315 lsp
= lsp_next_frag (LSP_FRAGMENT (lsp
->lsp_header
->lsp_id
) + 1,
2316 lsp0
, area
, IS_LEVEL_1
);
2319 free_tlvs (&tlv_data
);
2322 #endif /* TOPOLOGY_GENERATE */