2 * IS-IS TLV Serializer/Deserializer
4 * Copyright (C) 2015,2017 Christian Franke
6 * This file is part of FRR.
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FRR; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "openbsd-tree.h"
28 #include "isisd/dict.h"
32 struct isis_area_address
;
33 struct isis_area_address
{
34 struct isis_area_address
*next
;
40 struct isis_oldstyle_reach
;
41 struct isis_oldstyle_reach
{
42 struct isis_oldstyle_reach
*next
;
48 struct isis_oldstyle_ip_reach
;
49 struct isis_oldstyle_ip_reach
{
50 struct isis_oldstyle_ip_reach
*next
;
53 struct prefix_ipv4 prefix
;
56 struct isis_lsp_entry
;
57 struct isis_lsp_entry
{
58 struct isis_lsp_entry
*next
;
60 uint16_t rem_lifetime
;
68 struct isis_extended_reach
;
69 struct isis_extended_reach
{
70 struct isis_extended_reach
*next
;
79 struct isis_extended_ip_reach
;
80 struct isis_extended_ip_reach
{
81 struct isis_extended_ip_reach
*next
;
85 struct prefix_ipv4 prefix
;
87 struct isis_subtlvs
*subtlvs
;
90 struct isis_ipv6_reach
;
91 struct isis_ipv6_reach
{
92 struct isis_ipv6_reach
*next
;
98 struct prefix_ipv6 prefix
;
100 struct isis_subtlvs
*subtlvs
;
103 struct isis_protocols_supported
{
108 #define ISIS_TIER_UNDEFINED 15
110 struct isis_spine_leaf
{
119 enum isis_threeway_state
{
120 ISIS_THREEWAY_DOWN
= 2,
121 ISIS_THREEWAY_INITIALIZING
= 1,
125 struct isis_threeway_adj
{
126 enum isis_threeway_state state
;
127 uint32_t local_circuit_id
;
129 uint8_t neighbor_id
[6];
130 uint32_t neighbor_circuit_id
;
135 struct isis_item
*next
;
138 struct isis_lan_neighbor
;
139 struct isis_lan_neighbor
{
140 struct isis_lan_neighbor
*next
;
145 struct isis_ipv4_address
;
146 struct isis_ipv4_address
{
147 struct isis_ipv4_address
*next
;
152 struct isis_ipv6_address
;
153 struct isis_ipv6_address
{
154 struct isis_ipv6_address
*next
;
156 struct in6_addr addr
;
159 struct isis_mt_router_info
;
160 struct isis_mt_router_info
{
161 struct isis_mt_router_info
*next
;
170 struct isis_auth
*next
;
179 size_t offset
; /* Only valid after packing */
182 struct isis_item_list
;
183 struct isis_item_list
{
184 struct isis_item
*head
;
185 struct isis_item
**tail
;
187 RB_ENTRY(isis_item_list
) mt_tree
;
192 struct isis_purge_originator
{
195 uint8_t generator
[6];
199 enum isis_auth_result
{
201 ISIS_AUTH_TYPE_FAILURE
,
203 ISIS_AUTH_NO_VALIDATOR
,
206 RB_HEAD(isis_mt_item_list
, isis_item_list
);
208 struct isis_item_list
*isis_get_mt_items(struct isis_mt_item_list
*m
,
210 struct isis_item_list
*isis_lookup_mt_items(struct isis_mt_item_list
*m
,
214 struct isis_item_list isis_auth
;
215 struct isis_purge_originator
*purge_originator
;
216 struct isis_item_list area_addresses
;
217 struct isis_item_list oldstyle_reach
;
218 struct isis_item_list lan_neighbor
;
219 struct isis_item_list lsp_entries
;
220 struct isis_item_list extended_reach
;
221 struct isis_mt_item_list mt_reach
;
222 struct isis_item_list oldstyle_ip_reach
;
223 struct isis_protocols_supported protocols_supported
;
224 struct isis_item_list oldstyle_ip_reach_ext
;
225 struct isis_item_list ipv4_address
;
226 struct isis_item_list ipv6_address
;
227 struct isis_item_list mt_router_info
;
228 bool mt_router_info_empty
;
229 struct in_addr
*te_router_id
;
230 struct isis_item_list extended_ip_reach
;
231 struct isis_mt_item_list mt_ip_reach
;
233 struct isis_item_list ipv6_reach
;
234 struct isis_mt_item_list mt_ipv6_reach
;
235 struct isis_threeway_adj
*threeway_adj
;
236 struct isis_spine_leaf
*spine_leaf
;
239 #define ISIS_PREFIX_SID_READVERTISED 0x80
240 #define ISIS_PREFIX_SID_NODE 0x40
241 #define ISIS_PREFIX_SID_NO_PHP 0x20
242 #define ISIS_PREFIX_SID_EXPLICIT_NULL 0x10
243 #define ISIS_PREFIX_SID_VALUE 0x08
244 #define ISIS_PREFIX_SID_LOCAL 0x04
246 struct isis_prefix_sid
;
247 struct isis_prefix_sid
{
248 struct isis_prefix_sid
*next
;
256 enum isis_tlv_context
{
258 ISIS_CONTEXT_SUBTLV_NE_REACH
,
259 ISIS_CONTEXT_SUBTLV_IP_REACH
,
260 ISIS_CONTEXT_SUBTLV_IPV6_REACH
,
264 struct isis_subtlvs
{
265 enum isis_tlv_context context
;
267 /* draft-baker-ipv6-isis-dst-src-routing-06 */
268 struct prefix_ipv6
*source_prefix
;
269 /* draft-ietf-isis-segment-routing-extensions-16 */
270 struct isis_item_list prefix_sids
;
274 ISIS_TLV_AREA_ADDRESSES
= 1,
275 ISIS_TLV_OLDSTYLE_REACH
= 2,
276 ISIS_TLV_LAN_NEIGHBORS
= 6,
277 ISIS_TLV_PADDING
= 8,
278 ISIS_TLV_LSP_ENTRY
= 9,
280 ISIS_TLV_PURGE_ORIGINATOR
= 13,
281 ISIS_TLV_EXTENDED_REACH
= 22,
283 ISIS_TLV_OLDSTYLE_IP_REACH
= 128,
284 ISIS_TLV_PROTOCOLS_SUPPORTED
= 129,
285 ISIS_TLV_OLDSTYLE_IP_REACH_EXT
= 130,
286 ISIS_TLV_IPV4_ADDRESS
= 132,
287 ISIS_TLV_TE_ROUTER_ID
= 134,
288 ISIS_TLV_EXTENDED_IP_REACH
= 135,
289 ISIS_TLV_DYNAMIC_HOSTNAME
= 137,
290 ISIS_TLV_SPINE_LEAF_EXT
= 150,
291 ISIS_TLV_MT_REACH
= 222,
292 ISIS_TLV_MT_ROUTER_INFO
= 229,
293 ISIS_TLV_IPV6_ADDRESS
= 232,
294 ISIS_TLV_MT_IP_REACH
= 235,
295 ISIS_TLV_IPV6_REACH
= 236,
296 ISIS_TLV_MT_IPV6_REACH
= 237,
297 ISIS_TLV_THREE_WAY_ADJ
= 240,
300 ISIS_SUBTLV_PREFIX_SID
= 3,
301 ISIS_SUBTLV_IPV6_SOURCE_PREFIX
= 22
304 #define IS_COMPAT_MT_TLV(tlv_type) \
305 ((tlv_type == ISIS_TLV_MT_REACH) || (tlv_type == ISIS_TLV_MT_IP_REACH) \
306 || (tlv_type == ISIS_TLV_MT_IPV6_REACH))
309 int isis_pack_tlvs(struct isis_tlvs
*tlvs
, struct stream
*stream
,
310 size_t len_pointer
, bool pad
, bool is_lsp
);
311 void isis_free_tlvs(struct isis_tlvs
*tlvs
);
312 struct isis_tlvs
*isis_alloc_tlvs(void);
313 int isis_unpack_tlvs(size_t avail_len
, struct stream
*stream
,
314 struct isis_tlvs
**dest
, const char **error_log
);
315 const char *isis_format_tlvs(struct isis_tlvs
*tlvs
);
316 struct isis_tlvs
*isis_copy_tlvs(struct isis_tlvs
*tlvs
);
317 struct list
*isis_fragment_tlvs(struct isis_tlvs
*tlvs
, size_t size
);
319 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
320 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
322 #define ISIS_IPV6_REACH_DOWN 0x80
323 #define ISIS_IPV6_REACH_EXTERNAL 0x40
324 #define ISIS_IPV6_REACH_SUBTLV 0x20
327 #define ISIS_MT_MASK 0x0fff
328 #define ISIS_MT_OL_MASK 0x8000
329 #define ISIS_MT_AT_MASK 0x4000
333 void isis_tlvs_add_auth(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
);
334 void isis_tlvs_add_area_addresses(struct isis_tlvs
*tlvs
,
335 struct list
*addresses
);
336 void isis_tlvs_add_lan_neighbors(struct isis_tlvs
*tlvs
,
337 struct list
*neighbors
);
338 void isis_tlvs_set_protocols_supported(struct isis_tlvs
*tlvs
,
339 struct nlpids
*nlpids
);
340 void isis_tlvs_add_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
,
341 bool overload
, bool attached
);
342 void isis_tlvs_add_ipv4_address(struct isis_tlvs
*tlvs
, struct in_addr
*addr
);
343 void isis_tlvs_add_ipv4_addresses(struct isis_tlvs
*tlvs
,
344 struct list
*addresses
);
345 void isis_tlvs_add_ipv6_addresses(struct isis_tlvs
*tlvs
,
346 struct list
*addresses
);
347 int isis_tlvs_auth_is_valid(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
,
348 struct stream
*stream
, bool is_lsp
);
349 bool isis_tlvs_area_addresses_match(struct isis_tlvs
*tlvs
,
350 struct list
*addresses
);
351 struct isis_adjacency
;
352 void isis_tlvs_to_adj(struct isis_tlvs
*tlvs
, struct isis_adjacency
*adj
,
354 bool isis_tlvs_own_snpa_found(struct isis_tlvs
*tlvs
, uint8_t *snpa
);
355 void isis_tlvs_add_lsp_entry(struct isis_tlvs
*tlvs
, struct isis_lsp
*lsp
);
356 void isis_tlvs_add_csnp_entries(struct isis_tlvs
*tlvs
, uint8_t *start_id
,
357 uint8_t *stop_id
, uint16_t num_lsps
,
358 dict_t
*lspdb
, struct isis_lsp
**last_lsp
);
359 void isis_tlvs_set_dynamic_hostname(struct isis_tlvs
*tlvs
,
360 const char *hostname
);
361 void isis_tlvs_set_te_router_id(struct isis_tlvs
*tlvs
,
362 const struct in_addr
*id
);
363 void isis_tlvs_add_oldstyle_ip_reach(struct isis_tlvs
*tlvs
,
364 struct prefix_ipv4
*dest
, uint8_t metric
);
365 void isis_tlvs_add_extended_ip_reach(struct isis_tlvs
*tlvs
,
366 struct prefix_ipv4
*dest
, uint32_t metric
);
367 void isis_tlvs_add_ipv6_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
368 struct prefix_ipv6
*dest
, uint32_t metric
);
369 void isis_tlvs_add_ipv6_dstsrc_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
370 struct prefix_ipv6
*dest
,
371 struct prefix_ipv6
*src
,
373 void isis_tlvs_add_oldstyle_reach(struct isis_tlvs
*tlvs
, uint8_t *id
,
375 void isis_tlvs_add_extended_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
376 uint8_t *id
, uint32_t metric
,
377 uint8_t *subtlvs
, uint8_t subtlv_len
);
379 const char *isis_threeway_state_name(enum isis_threeway_state state
);
381 void isis_tlvs_add_threeway_adj(struct isis_tlvs
*tlvs
,
382 enum isis_threeway_state state
,
383 uint32_t local_circuit_id
,
384 const uint8_t *neighbor_id
,
385 uint32_t neighbor_circuit_id
);
387 void isis_tlvs_add_spine_leaf(struct isis_tlvs
*tlvs
, uint8_t tier
,
388 bool has_tier
, bool is_leaf
, bool is_spine
,
391 struct isis_mt_router_info
*
392 isis_tlvs_lookup_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
);
394 void isis_tlvs_set_purge_originator(struct isis_tlvs
*tlvs
,
395 const uint8_t *generator
,
396 const uint8_t *sender
);