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"
34 struct isis_area_address
;
35 struct isis_area_address
{
36 struct isis_area_address
*next
;
42 struct isis_oldstyle_reach
;
43 struct isis_oldstyle_reach
{
44 struct isis_oldstyle_reach
*next
;
50 struct isis_oldstyle_ip_reach
;
51 struct isis_oldstyle_ip_reach
{
52 struct isis_oldstyle_ip_reach
*next
;
55 struct prefix_ipv4 prefix
;
58 struct isis_lsp_entry
;
59 struct isis_lsp_entry
{
60 struct isis_lsp_entry
*next
;
62 uint16_t rem_lifetime
;
70 struct isis_extended_reach
;
71 struct isis_ext_subtlvs
;
72 struct isis_extended_reach
{
73 struct isis_extended_reach
*next
;
78 struct isis_ext_subtlvs
*subtlvs
;
81 struct isis_extended_ip_reach
;
82 struct isis_extended_ip_reach
{
83 struct isis_extended_ip_reach
*next
;
87 struct prefix_ipv4 prefix
;
89 struct isis_subtlvs
*subtlvs
;
92 struct isis_ipv6_reach
;
93 struct isis_ipv6_reach
{
94 struct isis_ipv6_reach
*next
;
100 struct prefix_ipv6 prefix
;
102 struct isis_subtlvs
*subtlvs
;
105 struct isis_protocols_supported
{
110 #define ISIS_TIER_UNDEFINED 15
112 struct isis_spine_leaf
{
121 enum isis_threeway_state
{
122 ISIS_THREEWAY_DOWN
= 2,
123 ISIS_THREEWAY_INITIALIZING
= 1,
127 struct isis_threeway_adj
{
128 enum isis_threeway_state state
;
129 uint32_t local_circuit_id
;
131 uint8_t neighbor_id
[6];
132 uint32_t neighbor_circuit_id
;
136 * Segment Routing subTLV's as per
137 * draft-ietf-isis-segment-routing-extension-25
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)
144 /* Structure aggregating SRGB info */
148 uint32_t lower_bound
;
151 /* Prefix-SID sub-TLVs flags */
152 #define ISIS_PREFIX_SID_READVERTISED 0x80
153 #define ISIS_PREFIX_SID_NODE 0x40
154 #define ISIS_PREFIX_SID_NO_PHP 0x20
155 #define ISIS_PREFIX_SID_EXPLICIT_NULL 0x10
156 #define ISIS_PREFIX_SID_VALUE 0x08
157 #define ISIS_PREFIX_SID_LOCAL 0x04
159 struct isis_prefix_sid
;
160 struct isis_prefix_sid
{
161 struct isis_prefix_sid
*next
;
168 /* Adj-SID and LAN-Ajd-SID sub-TLVs flags */
169 #define EXT_SUBTLV_LINK_ADJ_SID_FFLG 0x80
170 #define EXT_SUBTLV_LINK_ADJ_SID_BFLG 0x40
171 #define EXT_SUBTLV_LINK_ADJ_SID_VFLG 0x20
172 #define EXT_SUBTLV_LINK_ADJ_SID_LFLG 0x10
173 #define EXT_SUBTLV_LINK_ADJ_SID_SFLG 0x08
174 #define EXT_SUBTLV_LINK_ADJ_SID_PFLG 0x04
177 struct isis_adj_sid
{
178 struct isis_adj_sid
*next
;
186 struct isis_lan_adj_sid
;
187 struct isis_lan_adj_sid
{
188 struct isis_lan_adj_sid
*next
;
193 uint8_t neighbor_id
[ISIS_SYS_ID_LEN
];
197 /* RFC 4971 & RFC 7981 */
198 #define ISIS_ROUTER_CAP_FLAG_S 0x01
199 #define ISIS_ROUTER_CAP_FLAG_D 0x02
200 #define ISIS_ROUTER_CAP_SIZE 5
202 /* Number of supported algorithm for Segment Routing.
203 * Right now only 2 have been standardized:
207 #define SR_ALGORITHM_COUNT 2
208 #define SR_ALGORITHM_SPF 0
209 #define SR_ALGORITHM_STRICT_SPF 1
210 #define SR_ALGORITHM_UNSET 255
212 struct isis_router_cap
{
213 struct in_addr router_id
;
216 /* draft-ietf-segment-routing-extensions-25 */
217 struct isis_srgb srgb
;
218 uint8_t algo
[SR_ALGORITHM_COUNT
];
220 #define MSD_TYPE_BASE_MPLS_IMPOSITION 0x01
226 struct isis_item
*next
;
229 struct isis_lan_neighbor
;
230 struct isis_lan_neighbor
{
231 struct isis_lan_neighbor
*next
;
236 struct isis_ipv4_address
;
237 struct isis_ipv4_address
{
238 struct isis_ipv4_address
*next
;
243 struct isis_ipv6_address
;
244 struct isis_ipv6_address
{
245 struct isis_ipv6_address
*next
;
247 struct in6_addr addr
;
250 struct isis_mt_router_info
;
251 struct isis_mt_router_info
{
252 struct isis_mt_router_info
*next
;
261 struct isis_auth
*next
;
270 size_t offset
; /* Only valid after packing */
273 struct isis_item_list
;
274 struct isis_item_list
{
275 struct isis_item
*head
;
276 struct isis_item
**tail
;
278 RB_ENTRY(isis_item_list
) mt_tree
;
283 struct isis_purge_originator
{
286 uint8_t generator
[6];
290 enum isis_auth_result
{
292 ISIS_AUTH_TYPE_FAILURE
,
294 ISIS_AUTH_NO_VALIDATOR
,
297 RB_HEAD(isis_mt_item_list
, isis_item_list
);
299 struct isis_item_list
*isis_get_mt_items(struct isis_mt_item_list
*m
,
301 struct isis_item_list
*isis_lookup_mt_items(struct isis_mt_item_list
*m
,
305 struct isis_item_list isis_auth
;
306 struct isis_purge_originator
*purge_originator
;
307 struct isis_item_list area_addresses
;
308 struct isis_item_list oldstyle_reach
;
309 struct isis_item_list lan_neighbor
;
310 struct isis_item_list lsp_entries
;
311 struct isis_item_list extended_reach
;
312 struct isis_mt_item_list mt_reach
;
313 struct isis_item_list oldstyle_ip_reach
;
314 struct isis_protocols_supported protocols_supported
;
315 struct isis_item_list oldstyle_ip_reach_ext
;
316 struct isis_item_list ipv4_address
;
317 struct isis_item_list ipv6_address
;
318 struct isis_item_list mt_router_info
;
319 bool mt_router_info_empty
;
320 struct in_addr
*te_router_id
;
321 struct isis_item_list extended_ip_reach
;
322 struct isis_mt_item_list mt_ip_reach
;
324 struct isis_item_list ipv6_reach
;
325 struct isis_mt_item_list mt_ipv6_reach
;
326 struct isis_threeway_adj
*threeway_adj
;
327 struct isis_router_cap
*router_cap
;
328 struct isis_spine_leaf
*spine_leaf
;
331 enum isis_tlv_context
{
333 ISIS_CONTEXT_SUBTLV_NE_REACH
,
334 ISIS_CONTEXT_SUBTLV_IP_REACH
,
335 ISIS_CONTEXT_SUBTLV_IPV6_REACH
,
339 struct isis_subtlvs
{
340 enum isis_tlv_context context
;
342 /* draft-baker-ipv6-isis-dst-src-routing-06 */
343 struct prefix_ipv6
*source_prefix
;
344 /* draft-ietf-isis-segment-routing-extensions-25 */
345 struct isis_item_list prefix_sids
;
349 /* TLVs code point */
350 ISIS_TLV_AREA_ADDRESSES
= 1,
351 ISIS_TLV_OLDSTYLE_REACH
= 2,
352 ISIS_TLV_LAN_NEIGHBORS
= 6,
353 ISIS_TLV_PADDING
= 8,
354 ISIS_TLV_LSP_ENTRY
= 9,
356 ISIS_TLV_PURGE_ORIGINATOR
= 13,
357 ISIS_TLV_EXTENDED_REACH
= 22,
359 ISIS_TLV_OLDSTYLE_IP_REACH
= 128,
360 ISIS_TLV_PROTOCOLS_SUPPORTED
= 129,
361 ISIS_TLV_OLDSTYLE_IP_REACH_EXT
= 130,
362 ISIS_TLV_IPV4_ADDRESS
= 132,
363 ISIS_TLV_TE_ROUTER_ID
= 134,
364 ISIS_TLV_EXTENDED_IP_REACH
= 135,
365 ISIS_TLV_DYNAMIC_HOSTNAME
= 137,
366 ISIS_TLV_SPINE_LEAF_EXT
= 150,
367 ISIS_TLV_MT_REACH
= 222,
368 ISIS_TLV_MT_ROUTER_INFO
= 229,
369 ISIS_TLV_IPV6_ADDRESS
= 232,
370 ISIS_TLV_MT_IP_REACH
= 235,
371 ISIS_TLV_IPV6_REACH
= 236,
372 ISIS_TLV_MT_IPV6_REACH
= 237,
373 ISIS_TLV_THREE_WAY_ADJ
= 240,
374 ISIS_TLV_ROUTER_CAPABILITY
= 242,
377 /* subTLVs code point */
378 ISIS_SUBTLV_IPV6_SOURCE_PREFIX
= 22,
380 /* RFC 5305 & RFC 6119 */
381 ISIS_SUBTLV_ADMIN_GRP
= 3,
382 ISIS_SUBTLV_LOCAL_IPADDR
= 6,
383 ISIS_SUBTLV_RMT_IPADDR
= 8,
384 ISIS_SUBTLV_MAX_BW
= 9,
385 ISIS_SUBTLV_MAX_RSV_BW
= 10,
386 ISIS_SUBTLV_UNRSV_BW
= 11,
387 ISIS_SUBTLV_LOCAL_IPADDR6
= 12,
388 ISIS_SUBTLV_RMT_IPADDR6
= 13,
389 ISIS_SUBTLV_TE_METRIC
= 18,
392 ISIS_SUBTLV_LLRI
= 4,
395 ISIS_SUBTLV_RAS
= 24,
396 ISIS_SUBTLV_RIP
= 25,
398 /* draft-isis-segment-routing-extension-25 */
399 ISIS_SUBTLV_SID_LABEL
= 1,
400 ISIS_SUBTLV_SID_LABEL_RANGE
= 2,
401 ISIS_SUBTLV_ALGORITHM
= 19,
402 ISIS_SUBTLV_NODE_MSD
= 23,
403 ISIS_SUBTLV_PREFIX_SID
= 3,
404 ISIS_SUBTLV_ADJ_SID
= 31,
405 ISIS_SUBTLV_LAN_ADJ_SID
= 32,
408 ISIS_SUBTLV_AV_DELAY
= 33,
409 ISIS_SUBTLV_MM_DELAY
= 34,
410 ISIS_SUBTLV_DELAY_VAR
= 35,
411 ISIS_SUBTLV_PKT_LOSS
= 36,
412 ISIS_SUBTLV_RES_BW
= 37,
413 ISIS_SUBTLV_AVA_BW
= 38,
414 ISIS_SUBTLV_USE_BW
= 39,
419 /* subTLVs size for TE and SR */
420 enum ext_subtlv_size
{
421 ISIS_SUBTLV_LLRI_SIZE
= 8,
423 ISIS_SUBTLV_UNRSV_BW_SIZE
= 32,
424 ISIS_SUBTLV_TE_METRIC_SIZE
= 3,
425 ISIS_SUBTLV_IPV6_ADDR_SIZE
= 16,
427 /* draft-isis-segment-routing-extension-25 */
428 ISIS_SUBTLV_SID_LABEL_SIZE
= 3,
429 ISIS_SUBTLV_SID_LABEL_RANGE_SIZE
= 9,
430 ISIS_SUBTLV_ALGORITHM_SIZE
= 4,
431 ISIS_SUBTLV_NODE_MSD_SIZE
= 2,
432 ISIS_SUBTLV_ADJ_SID_SIZE
= 5,
433 ISIS_SUBTLV_LAN_ADJ_SID_SIZE
= 11,
434 ISIS_SUBTLV_PREFIX_SID_SIZE
= 5,
436 ISIS_SUBTLV_MM_DELAY_SIZE
= 8,
438 ISIS_SUBTLV_HDR_SIZE
= 2,
439 ISIS_SUBTLV_DEF_SIZE
= 4,
441 ISIS_SUBTLV_MAX_SIZE
= 180
444 /* Macros to manage the optional presence of EXT subTLVs */
445 #define SET_SUBTLV(s, t) ((s->status) |= (t))
446 #define UNSET_SUBTLV(s, t) ((s->status) &= ~(t))
447 #define IS_SUBTLV(s, t) (s->status & t)
449 #define EXT_DISABLE 0x000000
450 #define EXT_ADM_GRP 0x000001
451 #define EXT_LLRI 0x000002
452 #define EXT_LOCAL_ADDR 0x000004
453 #define EXT_NEIGH_ADDR 0x000008
454 #define EXT_LOCAL_ADDR6 0x000010
455 #define EXT_NEIGH_ADDR6 0x000020
456 #define EXT_MAX_BW 0x000040
457 #define EXT_MAX_RSV_BW 0x000080
458 #define EXT_UNRSV_BW 0x000100
459 #define EXT_TE_METRIC 0x000200
460 #define EXT_RMT_AS 0x000400
461 #define EXT_RMT_IP 0x000800
462 #define EXT_ADJ_SID 0x001000
463 #define EXT_LAN_ADJ_SID 0x002000
464 #define EXT_DELAY 0x004000
465 #define EXT_MM_DELAY 0x008000
466 #define EXT_DELAY_VAR 0x010000
467 #define EXT_PKT_LOSS 0x020000
468 #define EXT_RES_BW 0x040000
469 #define EXT_AVA_BW 0x080000
470 #define EXT_USE_BW 0x100000
473 * This structure groups all Extended IS Reachability subTLVs.
475 * Each bit of the status field indicates if a subTLVs is valid or not.
476 * SubTLVs values use following units:
477 * - Bandwidth in bytes/sec following IEEE format,
478 * - Delay in micro-seconds with only 24 bits significant
479 * - Packet Loss in percentage of total traffic with only 24 bits (2^24 - 2)
481 * For Delay and packet Loss, upper bit (A) indicates if the value is
482 * normal (0) or anomalous (1).
484 #define IS_ANORMAL(v) (v & 0x80000000)
486 struct isis_ext_subtlvs
{
490 uint32_t adm_group
; /* Resource Class/Color - RFC 5305 */
491 /* Link Local/Remote Identifiers - RFC 5307 */
493 uint32_t remote_llri
;
494 struct in_addr local_addr
; /* Local IP Address - RFC 5305 */
495 struct in_addr neigh_addr
; /* Neighbor IP Address - RFC 5305 */
496 struct in6_addr local_addr6
; /* Local IPv6 Address - RFC 6119 */
497 struct in6_addr neigh_addr6
; /* Neighbor IPv6 Address - RFC 6119 */
498 float max_bw
; /* Maximum Bandwidth - RFC 5305 */
499 float max_rsv_bw
; /* Maximum Reservable Bandwidth - RFC 5305 */
500 float unrsv_bw
[8]; /* Unreserved Bandwidth - RFC 5305 */
501 uint32_t te_metric
; /* Traffic Engineering Metric - RFC 5305 */
502 uint32_t remote_as
; /* Remote AS Number sub-TLV - RFC5316 */
503 struct in_addr remote_ip
; /* IPv4 Remote ASBR ID Sub-TLV - RFC5316 */
505 uint32_t delay
; /* Average Link Delay - RFC 8570 */
506 uint32_t min_delay
; /* Low Link Delay - RFC 8570 */
507 uint32_t max_delay
; /* High Link Delay - RFC 8570 */
508 uint32_t delay_var
; /* Link Delay Variation i.e. Jitter - RFC 8570 */
509 uint32_t pkt_loss
; /* Unidirectional Link Packet Loss - RFC 8570 */
510 float res_bw
; /* Unidirectional Residual Bandwidth - RFC 8570 */
511 float ava_bw
; /* Unidirectional Available Bandwidth - RFC 8570 */
512 float use_bw
; /* Unidirectional Utilized Bandwidth - RFC 8570 */
514 /* Segment Routing Adjacency & LAN Adjacency Segment ID */
515 struct isis_item_list adj_sid
;
516 struct isis_item_list lan_sid
;
519 #define IS_COMPAT_MT_TLV(tlv_type) \
520 ((tlv_type == ISIS_TLV_MT_REACH) || (tlv_type == ISIS_TLV_MT_IP_REACH) \
521 || (tlv_type == ISIS_TLV_MT_IPV6_REACH))
524 int isis_pack_tlvs(struct isis_tlvs
*tlvs
, struct stream
*stream
,
525 size_t len_pointer
, bool pad
, bool is_lsp
);
526 void isis_free_tlvs(struct isis_tlvs
*tlvs
);
527 struct isis_tlvs
*isis_alloc_tlvs(void);
528 int isis_unpack_tlvs(size_t avail_len
, struct stream
*stream
,
529 struct isis_tlvs
**dest
, const char **error_log
);
530 const char *isis_format_tlvs(struct isis_tlvs
*tlvs
);
531 struct isis_tlvs
*isis_copy_tlvs(struct isis_tlvs
*tlvs
);
532 struct list
*isis_fragment_tlvs(struct isis_tlvs
*tlvs
, size_t size
);
534 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
535 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
537 #define ISIS_IPV6_REACH_DOWN 0x80
538 #define ISIS_IPV6_REACH_EXTERNAL 0x40
539 #define ISIS_IPV6_REACH_SUBTLV 0x20
542 #define ISIS_MT_MASK 0x0fff
543 #define ISIS_MT_OL_MASK 0x8000
544 #define ISIS_MT_AT_MASK 0x4000
547 void isis_tlvs_add_auth(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
);
548 void isis_tlvs_add_area_addresses(struct isis_tlvs
*tlvs
,
549 struct list
*addresses
);
550 void isis_tlvs_add_lan_neighbors(struct isis_tlvs
*tlvs
,
551 struct list
*neighbors
);
552 void isis_tlvs_set_protocols_supported(struct isis_tlvs
*tlvs
,
553 struct nlpids
*nlpids
);
554 void isis_tlvs_add_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
,
555 bool overload
, bool attached
);
556 void isis_tlvs_add_ipv4_address(struct isis_tlvs
*tlvs
, struct in_addr
*addr
);
557 void isis_tlvs_add_ipv4_addresses(struct isis_tlvs
*tlvs
,
558 struct list
*addresses
);
559 void isis_tlvs_add_ipv6_addresses(struct isis_tlvs
*tlvs
,
560 struct list
*addresses
);
561 int isis_tlvs_auth_is_valid(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
,
562 struct stream
*stream
, bool is_lsp
);
563 bool isis_tlvs_area_addresses_match(struct isis_tlvs
*tlvs
,
564 struct list
*addresses
);
565 struct isis_adjacency
;
566 void isis_tlvs_to_adj(struct isis_tlvs
*tlvs
, struct isis_adjacency
*adj
,
568 bool isis_tlvs_own_snpa_found(struct isis_tlvs
*tlvs
, uint8_t *snpa
);
569 void isis_tlvs_add_lsp_entry(struct isis_tlvs
*tlvs
, struct isis_lsp
*lsp
);
570 void isis_tlvs_add_csnp_entries(struct isis_tlvs
*tlvs
, uint8_t *start_id
,
571 uint8_t *stop_id
, uint16_t num_lsps
,
572 struct lspdb_head
*lspdb
,
573 struct isis_lsp
**last_lsp
);
574 void isis_tlvs_set_dynamic_hostname(struct isis_tlvs
*tlvs
,
575 const char *hostname
);
576 void isis_tlvs_set_router_capability(struct isis_tlvs
*tlvs
,
577 const struct isis_router_cap
*cap
);
578 void isis_tlvs_set_te_router_id(struct isis_tlvs
*tlvs
,
579 const struct in_addr
*id
);
580 void isis_tlvs_add_oldstyle_ip_reach(struct isis_tlvs
*tlvs
,
581 struct prefix_ipv4
*dest
, uint8_t metric
);
582 void isis_tlvs_add_extended_ip_reach(struct isis_tlvs
*tlvs
,
583 struct prefix_ipv4
*dest
, uint32_t metric
);
584 void isis_tlvs_add_ipv6_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
585 struct prefix_ipv6
*dest
, uint32_t metric
);
586 void isis_tlvs_add_ipv6_dstsrc_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
587 struct prefix_ipv6
*dest
,
588 struct prefix_ipv6
*src
,
590 struct isis_ext_subtlvs
*isis_alloc_ext_subtlvs(void);
591 void isis_tlvs_add_adj_sid(struct isis_ext_subtlvs
*exts
,
592 struct isis_adj_sid
*adj
);
593 void isis_tlvs_del_adj_sid(struct isis_ext_subtlvs
*exts
,
594 struct isis_adj_sid
*adj
);
595 void isis_tlvs_add_lan_adj_sid(struct isis_ext_subtlvs
*exts
,
596 struct isis_lan_adj_sid
*lan
);
597 void isis_tlvs_del_lan_adj_sid(struct isis_ext_subtlvs
*exts
,
598 struct isis_lan_adj_sid
*lan
);
600 void isis_tlvs_add_oldstyle_reach(struct isis_tlvs
*tlvs
, uint8_t *id
,
602 void isis_tlvs_add_extended_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
603 uint8_t *id
, uint32_t metric
,
604 struct isis_ext_subtlvs
*subtlvs
);
606 const char *isis_threeway_state_name(enum isis_threeway_state state
);
608 void isis_tlvs_add_threeway_adj(struct isis_tlvs
*tlvs
,
609 enum isis_threeway_state state
,
610 uint32_t local_circuit_id
,
611 const uint8_t *neighbor_id
,
612 uint32_t neighbor_circuit_id
);
614 void isis_tlvs_add_spine_leaf(struct isis_tlvs
*tlvs
, uint8_t tier
,
615 bool has_tier
, bool is_leaf
, bool is_spine
,
618 struct isis_mt_router_info
*
619 isis_tlvs_lookup_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
);
621 void isis_tlvs_set_purge_originator(struct isis_tlvs
*tlvs
,
622 const uint8_t *generator
,
623 const uint8_t *sender
);