2 * IS-IS TLV Serializer/Deserializer
4 * Copyright (C) 2015,2017 Christian Franke
6 * Copyright (C) 2019 Olivier Dugeon - Orange Labs (for TE and SR)
8 * This file is part of FRR.
10 * FRR is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
15 * FRR is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FRR; see the file COPYING. If not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #include "openbsd-tree.h"
31 DECLARE_MTYPE(ISIS_SUBTLV
)
37 struct isis_area_address
;
38 struct isis_area_address
{
39 struct isis_area_address
*next
;
45 struct isis_oldstyle_reach
;
46 struct isis_oldstyle_reach
{
47 struct isis_oldstyle_reach
*next
;
53 struct isis_oldstyle_ip_reach
;
54 struct isis_oldstyle_ip_reach
{
55 struct isis_oldstyle_ip_reach
*next
;
58 struct prefix_ipv4 prefix
;
61 struct isis_lsp_entry
;
62 struct isis_lsp_entry
{
63 struct isis_lsp_entry
*next
;
65 uint16_t rem_lifetime
;
73 struct isis_extended_reach
;
74 struct isis_ext_subtlvs
;
75 struct isis_extended_reach
{
76 struct isis_extended_reach
*next
;
81 struct isis_ext_subtlvs
*subtlvs
;
84 struct isis_extended_ip_reach
;
85 struct isis_extended_ip_reach
{
86 struct isis_extended_ip_reach
*next
;
90 struct prefix_ipv4 prefix
;
92 struct isis_subtlvs
*subtlvs
;
95 struct isis_ipv6_reach
;
96 struct isis_ipv6_reach
{
97 struct isis_ipv6_reach
*next
;
103 struct prefix_ipv6 prefix
;
105 struct isis_subtlvs
*subtlvs
;
108 struct isis_protocols_supported
{
113 #define ISIS_TIER_UNDEFINED 15
115 struct isis_spine_leaf
{
124 enum isis_threeway_state
{
125 ISIS_THREEWAY_DOWN
= 2,
126 ISIS_THREEWAY_INITIALIZING
= 1,
130 struct isis_threeway_adj
{
131 enum isis_threeway_state state
;
132 uint32_t local_circuit_id
;
134 uint8_t neighbor_id
[6];
135 uint32_t neighbor_circuit_id
;
138 /* Segment Routing subTLV's as per RFC8667 */
139 #define ISIS_SUBTLV_SRGB_FLAG_I 0x80
140 #define ISIS_SUBTLV_SRGB_FLAG_V 0x40
141 #define IS_SR_IPV4(srgb) (srgb.flags & ISIS_SUBTLV_SRGB_FLAG_I)
142 #define IS_SR_IPV6(srgb) (srgb.flags & ISIS_SUBTLV_SRGB_FLAG_V)
143 #define SUBTLV_SR_BLOCK_SIZE 6
144 #define SUBTLV_RANGE_INDEX_SIZE 10
145 #define SUBTLV_RANGE_LABEL_SIZE 9
147 /* Structure aggregating SR Global (SRGB) or Local (SRLB) Block info */
148 struct isis_sr_block
{
151 uint32_t lower_bound
;
154 /* Prefix-SID sub-TLVs flags */
155 #define ISIS_PREFIX_SID_READVERTISED 0x80
156 #define ISIS_PREFIX_SID_NODE 0x40
157 #define ISIS_PREFIX_SID_NO_PHP 0x20
158 #define ISIS_PREFIX_SID_EXPLICIT_NULL 0x10
159 #define ISIS_PREFIX_SID_VALUE 0x08
160 #define ISIS_PREFIX_SID_LOCAL 0x04
162 struct isis_prefix_sid
;
163 struct isis_prefix_sid
{
164 struct isis_prefix_sid
*next
;
171 /* Adj-SID and LAN-Ajd-SID sub-TLVs flags */
172 #define EXT_SUBTLV_LINK_ADJ_SID_FFLG 0x80
173 #define EXT_SUBTLV_LINK_ADJ_SID_BFLG 0x40
174 #define EXT_SUBTLV_LINK_ADJ_SID_VFLG 0x20
175 #define EXT_SUBTLV_LINK_ADJ_SID_LFLG 0x10
176 #define EXT_SUBTLV_LINK_ADJ_SID_SFLG 0x08
177 #define EXT_SUBTLV_LINK_ADJ_SID_PFLG 0x04
180 struct isis_adj_sid
{
181 struct isis_adj_sid
*next
;
189 struct isis_lan_adj_sid
;
190 struct isis_lan_adj_sid
{
191 struct isis_lan_adj_sid
*next
;
196 uint8_t neighbor_id
[ISIS_SYS_ID_LEN
];
200 /* RFC 4971 & RFC 7981 */
201 #define ISIS_ROUTER_CAP_FLAG_S 0x01
202 #define ISIS_ROUTER_CAP_FLAG_D 0x02
203 #define ISIS_ROUTER_CAP_SIZE 5
205 /* Number of supported algorithm for Segment Routing.
206 * Right now only 2 have been standardized:
210 #define SR_ALGORITHM_COUNT 2
211 #define SR_ALGORITHM_SPF 0
212 #define SR_ALGORITHM_STRICT_SPF 1
213 #define SR_ALGORITHM_UNSET 255
215 #define MSD_TYPE_BASE_MPLS_IMPOSITION 0x01
216 #define MSD_TLV_SIZE 2
218 struct isis_router_cap
{
219 struct in_addr router_id
;
222 /* RFC 8667 section #3 */
223 struct isis_sr_block srgb
;
224 struct isis_sr_block srlb
;
225 uint8_t algo
[SR_ALGORITHM_COUNT
];
232 struct isis_item
*next
;
235 struct isis_lan_neighbor
;
236 struct isis_lan_neighbor
{
237 struct isis_lan_neighbor
*next
;
242 struct isis_ipv4_address
;
243 struct isis_ipv4_address
{
244 struct isis_ipv4_address
*next
;
249 struct isis_ipv6_address
;
250 struct isis_ipv6_address
{
251 struct isis_ipv6_address
*next
;
253 struct in6_addr addr
;
256 struct isis_mt_router_info
;
257 struct isis_mt_router_info
{
258 struct isis_mt_router_info
*next
;
267 struct isis_auth
*next
;
276 size_t offset
; /* Only valid after packing */
279 struct isis_item_list
;
280 struct isis_item_list
{
281 struct isis_item
*head
;
282 struct isis_item
**tail
;
284 RB_ENTRY(isis_item_list
) mt_tree
;
289 struct isis_purge_originator
{
292 uint8_t generator
[6];
296 enum isis_auth_result
{
298 ISIS_AUTH_TYPE_FAILURE
,
300 ISIS_AUTH_NO_VALIDATOR
,
303 RB_HEAD(isis_mt_item_list
, isis_item_list
);
305 struct isis_item_list
*isis_get_mt_items(struct isis_mt_item_list
*m
,
307 struct isis_item_list
*isis_lookup_mt_items(struct isis_mt_item_list
*m
,
311 struct isis_item_list isis_auth
;
312 struct isis_purge_originator
*purge_originator
;
313 struct isis_item_list area_addresses
;
314 struct isis_item_list oldstyle_reach
;
315 struct isis_item_list lan_neighbor
;
316 struct isis_item_list lsp_entries
;
317 struct isis_item_list extended_reach
;
318 struct isis_mt_item_list mt_reach
;
319 struct isis_item_list oldstyle_ip_reach
;
320 struct isis_protocols_supported protocols_supported
;
321 struct isis_item_list oldstyle_ip_reach_ext
;
322 struct isis_item_list ipv4_address
;
323 struct isis_item_list ipv6_address
;
324 struct isis_item_list mt_router_info
;
325 bool mt_router_info_empty
;
326 struct in_addr
*te_router_id
;
327 struct isis_item_list extended_ip_reach
;
328 struct isis_mt_item_list mt_ip_reach
;
330 struct isis_item_list ipv6_reach
;
331 struct isis_mt_item_list mt_ipv6_reach
;
332 struct isis_threeway_adj
*threeway_adj
;
333 struct isis_router_cap
*router_cap
;
334 struct isis_spine_leaf
*spine_leaf
;
337 enum isis_tlv_context
{
339 ISIS_CONTEXT_SUBTLV_NE_REACH
,
340 ISIS_CONTEXT_SUBTLV_IP_REACH
,
341 ISIS_CONTEXT_SUBTLV_IPV6_REACH
,
345 struct isis_subtlvs
{
346 enum isis_tlv_context context
;
348 /* draft-baker-ipv6-isis-dst-src-routing-06 */
349 struct prefix_ipv6
*source_prefix
;
350 /* RFC 8667 section #2.4 */
351 struct isis_item_list prefix_sids
;
355 /* TLVs code point */
356 ISIS_TLV_AREA_ADDRESSES
= 1,
357 ISIS_TLV_OLDSTYLE_REACH
= 2,
358 ISIS_TLV_LAN_NEIGHBORS
= 6,
359 ISIS_TLV_PADDING
= 8,
360 ISIS_TLV_LSP_ENTRY
= 9,
362 ISIS_TLV_PURGE_ORIGINATOR
= 13,
363 ISIS_TLV_EXTENDED_REACH
= 22,
365 ISIS_TLV_OLDSTYLE_IP_REACH
= 128,
366 ISIS_TLV_PROTOCOLS_SUPPORTED
= 129,
367 ISIS_TLV_OLDSTYLE_IP_REACH_EXT
= 130,
368 ISIS_TLV_IPV4_ADDRESS
= 132,
369 ISIS_TLV_TE_ROUTER_ID
= 134,
370 ISIS_TLV_EXTENDED_IP_REACH
= 135,
371 ISIS_TLV_DYNAMIC_HOSTNAME
= 137,
372 ISIS_TLV_SPINE_LEAF_EXT
= 150,
373 ISIS_TLV_MT_REACH
= 222,
374 ISIS_TLV_MT_ROUTER_INFO
= 229,
375 ISIS_TLV_IPV6_ADDRESS
= 232,
376 ISIS_TLV_MT_IP_REACH
= 235,
377 ISIS_TLV_IPV6_REACH
= 236,
378 ISIS_TLV_MT_IPV6_REACH
= 237,
379 ISIS_TLV_THREE_WAY_ADJ
= 240,
380 ISIS_TLV_ROUTER_CAPABILITY
= 242,
383 /* subTLVs code point */
384 ISIS_SUBTLV_IPV6_SOURCE_PREFIX
= 22,
386 /* RFC 5305 & RFC 6119 */
387 ISIS_SUBTLV_ADMIN_GRP
= 3,
388 ISIS_SUBTLV_LOCAL_IPADDR
= 6,
389 ISIS_SUBTLV_RMT_IPADDR
= 8,
390 ISIS_SUBTLV_MAX_BW
= 9,
391 ISIS_SUBTLV_MAX_RSV_BW
= 10,
392 ISIS_SUBTLV_UNRSV_BW
= 11,
393 ISIS_SUBTLV_LOCAL_IPADDR6
= 12,
394 ISIS_SUBTLV_RMT_IPADDR6
= 13,
395 ISIS_SUBTLV_TE_METRIC
= 18,
398 ISIS_SUBTLV_LLRI
= 4,
401 ISIS_SUBTLV_NODE_MSD
= 23,
404 ISIS_SUBTLV_RAS
= 24,
405 ISIS_SUBTLV_RIP
= 25,
407 /* RFC 8667 section #4 IANA allocation */
408 ISIS_SUBTLV_SID_LABEL
= 1,
409 ISIS_SUBTLV_SID_LABEL_RANGE
= 2,
410 ISIS_SUBTLV_ALGORITHM
= 19,
411 ISIS_SUBTLV_SRLB
= 22,
412 ISIS_SUBTLV_PREFIX_SID
= 3,
413 ISIS_SUBTLV_ADJ_SID
= 31,
414 ISIS_SUBTLV_LAN_ADJ_SID
= 32,
417 ISIS_SUBTLV_AV_DELAY
= 33,
418 ISIS_SUBTLV_MM_DELAY
= 34,
419 ISIS_SUBTLV_DELAY_VAR
= 35,
420 ISIS_SUBTLV_PKT_LOSS
= 36,
421 ISIS_SUBTLV_RES_BW
= 37,
422 ISIS_SUBTLV_AVA_BW
= 38,
423 ISIS_SUBTLV_USE_BW
= 39,
428 /* subTLVs size for TE and SR */
429 enum ext_subtlv_size
{
431 ISIS_SUBTLV_LLRI_SIZE
= 8,
433 /* RFC 5305 & RFC 6119 */
434 ISIS_SUBTLV_UNRSV_BW_SIZE
= 32,
435 ISIS_SUBTLV_TE_METRIC_SIZE
= 3,
436 ISIS_SUBTLV_IPV6_ADDR_SIZE
= 16,
439 ISIS_SUBTLV_NODE_MSD_SIZE
= 2,
441 /* RFC 8667 sections #2 & #3 */
442 ISIS_SUBTLV_SID_LABEL_SIZE
= 3,
443 ISIS_SUBTLV_SID_LABEL_RANGE_SIZE
= 9,
444 ISIS_SUBTLV_ALGORITHM_SIZE
= 4,
445 ISIS_SUBTLV_ADJ_SID_SIZE
= 5,
446 ISIS_SUBTLV_LAN_ADJ_SID_SIZE
= 11,
447 ISIS_SUBTLV_PREFIX_SID_SIZE
= 5,
450 ISIS_SUBTLV_MM_DELAY_SIZE
= 8,
452 ISIS_SUBTLV_HDR_SIZE
= 2,
453 ISIS_SUBTLV_DEF_SIZE
= 4,
455 ISIS_SUBTLV_MAX_SIZE
= 180
458 /* Macros to manage the optional presence of EXT subTLVs */
459 #define SET_SUBTLV(s, t) ((s->status) |= (t))
460 #define UNSET_SUBTLV(s, t) ((s->status) &= ~(t))
461 #define IS_SUBTLV(s, t) (s->status & t)
463 #define EXT_DISABLE 0x000000
464 #define EXT_ADM_GRP 0x000001
465 #define EXT_LLRI 0x000002
466 #define EXT_LOCAL_ADDR 0x000004
467 #define EXT_NEIGH_ADDR 0x000008
468 #define EXT_LOCAL_ADDR6 0x000010
469 #define EXT_NEIGH_ADDR6 0x000020
470 #define EXT_MAX_BW 0x000040
471 #define EXT_MAX_RSV_BW 0x000080
472 #define EXT_UNRSV_BW 0x000100
473 #define EXT_TE_METRIC 0x000200
474 #define EXT_RMT_AS 0x000400
475 #define EXT_RMT_IP 0x000800
476 #define EXT_ADJ_SID 0x001000
477 #define EXT_LAN_ADJ_SID 0x002000
478 #define EXT_DELAY 0x004000
479 #define EXT_MM_DELAY 0x008000
480 #define EXT_DELAY_VAR 0x010000
481 #define EXT_PKT_LOSS 0x020000
482 #define EXT_RES_BW 0x040000
483 #define EXT_AVA_BW 0x080000
484 #define EXT_USE_BW 0x100000
487 * This structure groups all Extended IS Reachability subTLVs.
489 * Each bit of the status field indicates if a subTLVs is valid or not.
490 * SubTLVs values use following units:
491 * - Bandwidth in bytes/sec following IEEE format,
492 * - Delay in micro-seconds with only 24 bits significant
493 * - Packet Loss in percentage of total traffic with only 24 bits (2^24 - 2)
495 * For Delay and packet Loss, upper bit (A) indicates if the value is
496 * normal (0) or anomalous (1).
498 #define IS_ANORMAL(v) (v & 0x80000000)
500 struct isis_ext_subtlvs
{
504 uint32_t adm_group
; /* Resource Class/Color - RFC 5305 */
505 /* Link Local/Remote Identifiers - RFC 5307 */
507 uint32_t remote_llri
;
508 struct in_addr local_addr
; /* Local IP Address - RFC 5305 */
509 struct in_addr neigh_addr
; /* Neighbor IP Address - RFC 5305 */
510 struct in6_addr local_addr6
; /* Local IPv6 Address - RFC 6119 */
511 struct in6_addr neigh_addr6
; /* Neighbor IPv6 Address - RFC 6119 */
512 float max_bw
; /* Maximum Bandwidth - RFC 5305 */
513 float max_rsv_bw
; /* Maximum Reservable Bandwidth - RFC 5305 */
514 float unrsv_bw
[8]; /* Unreserved Bandwidth - RFC 5305 */
515 uint32_t te_metric
; /* Traffic Engineering Metric - RFC 5305 */
516 uint32_t remote_as
; /* Remote AS Number sub-TLV - RFC5316 */
517 struct in_addr remote_ip
; /* IPv4 Remote ASBR ID Sub-TLV - RFC5316 */
519 uint32_t delay
; /* Average Link Delay - RFC 8570 */
520 uint32_t min_delay
; /* Low Link Delay - RFC 8570 */
521 uint32_t max_delay
; /* High Link Delay - RFC 8570 */
522 uint32_t delay_var
; /* Link Delay Variation i.e. Jitter - RFC 8570 */
523 uint32_t pkt_loss
; /* Unidirectional Link Packet Loss - RFC 8570 */
524 float res_bw
; /* Unidirectional Residual Bandwidth - RFC 8570 */
525 float ava_bw
; /* Unidirectional Available Bandwidth - RFC 8570 */
526 float use_bw
; /* Unidirectional Utilized Bandwidth - RFC 8570 */
528 /* Segment Routing Adjacency & LAN Adjacency Segment ID */
529 struct isis_item_list adj_sid
;
530 struct isis_item_list lan_sid
;
533 #define IS_COMPAT_MT_TLV(tlv_type) \
534 ((tlv_type == ISIS_TLV_MT_REACH) || (tlv_type == ISIS_TLV_MT_IP_REACH) \
535 || (tlv_type == ISIS_TLV_MT_IPV6_REACH))
538 int isis_pack_tlvs(struct isis_tlvs
*tlvs
, struct stream
*stream
,
539 size_t len_pointer
, bool pad
, bool is_lsp
);
540 void isis_free_tlvs(struct isis_tlvs
*tlvs
);
541 struct isis_tlvs
*isis_alloc_tlvs(void);
542 int isis_unpack_tlvs(size_t avail_len
, struct stream
*stream
,
543 struct isis_tlvs
**dest
, const char **error_log
);
544 const char *isis_format_tlvs(struct isis_tlvs
*tlvs
);
545 struct isis_tlvs
*isis_copy_tlvs(struct isis_tlvs
*tlvs
);
546 struct list
*isis_fragment_tlvs(struct isis_tlvs
*tlvs
, size_t size
);
548 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
549 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
551 #define ISIS_IPV6_REACH_DOWN 0x80
552 #define ISIS_IPV6_REACH_EXTERNAL 0x40
553 #define ISIS_IPV6_REACH_SUBTLV 0x20
556 #define ISIS_MT_MASK 0x0fff
557 #define ISIS_MT_OL_MASK 0x8000
558 #define ISIS_MT_AT_MASK 0x4000
561 void isis_tlvs_add_auth(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
);
562 void isis_tlvs_add_area_addresses(struct isis_tlvs
*tlvs
,
563 struct list
*addresses
);
564 void isis_tlvs_add_lan_neighbors(struct isis_tlvs
*tlvs
,
565 struct list
*neighbors
);
566 void isis_tlvs_set_protocols_supported(struct isis_tlvs
*tlvs
,
567 struct nlpids
*nlpids
);
568 void isis_tlvs_add_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
,
569 bool overload
, bool attached
);
570 void isis_tlvs_add_ipv4_address(struct isis_tlvs
*tlvs
, struct in_addr
*addr
);
571 void isis_tlvs_add_ipv4_addresses(struct isis_tlvs
*tlvs
,
572 struct list
*addresses
);
573 void isis_tlvs_add_ipv6_addresses(struct isis_tlvs
*tlvs
,
574 struct list
*addresses
);
575 int isis_tlvs_auth_is_valid(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
,
576 struct stream
*stream
, bool is_lsp
);
577 bool isis_tlvs_area_addresses_match(struct isis_tlvs
*tlvs
,
578 struct list
*addresses
);
579 struct isis_adjacency
;
580 void isis_tlvs_to_adj(struct isis_tlvs
*tlvs
, struct isis_adjacency
*adj
,
582 bool isis_tlvs_own_snpa_found(struct isis_tlvs
*tlvs
, uint8_t *snpa
);
583 void isis_tlvs_add_lsp_entry(struct isis_tlvs
*tlvs
, struct isis_lsp
*lsp
);
584 void isis_tlvs_add_csnp_entries(struct isis_tlvs
*tlvs
, uint8_t *start_id
,
585 uint8_t *stop_id
, uint16_t num_lsps
,
586 struct lspdb_head
*lspdb
,
587 struct isis_lsp
**last_lsp
);
588 void isis_tlvs_set_dynamic_hostname(struct isis_tlvs
*tlvs
,
589 const char *hostname
);
590 void isis_tlvs_set_router_capability(struct isis_tlvs
*tlvs
,
591 const struct isis_router_cap
*cap
);
592 void isis_tlvs_set_te_router_id(struct isis_tlvs
*tlvs
,
593 const struct in_addr
*id
);
594 void isis_tlvs_add_oldstyle_ip_reach(struct isis_tlvs
*tlvs
,
595 struct prefix_ipv4
*dest
, uint8_t metric
);
596 void isis_tlvs_add_extended_ip_reach(struct isis_tlvs
*tlvs
,
597 struct prefix_ipv4
*dest
, uint32_t metric
,
598 bool external
, struct sr_prefix_cfg
*pcfg
);
599 void isis_tlvs_add_ipv6_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
600 struct prefix_ipv6
*dest
, uint32_t metric
,
601 bool external
, struct sr_prefix_cfg
*pcfg
);
602 void isis_tlvs_add_ipv6_dstsrc_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
603 struct prefix_ipv6
*dest
,
604 struct prefix_ipv6
*src
,
606 struct isis_ext_subtlvs
*isis_alloc_ext_subtlvs(void);
607 void isis_tlvs_add_adj_sid(struct isis_ext_subtlvs
*exts
,
608 struct isis_adj_sid
*adj
);
609 void isis_tlvs_del_adj_sid(struct isis_ext_subtlvs
*exts
,
610 struct isis_adj_sid
*adj
);
611 void isis_tlvs_add_lan_adj_sid(struct isis_ext_subtlvs
*exts
,
612 struct isis_lan_adj_sid
*lan
);
613 void isis_tlvs_del_lan_adj_sid(struct isis_ext_subtlvs
*exts
,
614 struct isis_lan_adj_sid
*lan
);
616 void isis_tlvs_add_oldstyle_reach(struct isis_tlvs
*tlvs
, uint8_t *id
,
618 void isis_tlvs_add_extended_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
619 uint8_t *id
, uint32_t metric
,
620 struct isis_ext_subtlvs
*subtlvs
);
622 const char *isis_threeway_state_name(enum isis_threeway_state state
);
624 void isis_tlvs_add_threeway_adj(struct isis_tlvs
*tlvs
,
625 enum isis_threeway_state state
,
626 uint32_t local_circuit_id
,
627 const uint8_t *neighbor_id
,
628 uint32_t neighbor_circuit_id
);
630 void isis_tlvs_add_spine_leaf(struct isis_tlvs
*tlvs
, uint8_t tier
,
631 bool has_tier
, bool is_leaf
, bool is_spine
,
634 struct isis_mt_router_info
*
635 isis_tlvs_lookup_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
);
637 void isis_tlvs_set_purge_originator(struct isis_tlvs
*tlvs
,
638 const uint8_t *generator
,
639 const uint8_t *sender
);