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
;
88 struct isis_ipv6_reach
;
89 struct isis_ipv6_reach
{
90 struct isis_ipv6_reach
*next
;
96 struct prefix_ipv6 prefix
;
98 struct isis_subtlvs
*subtlvs
;
101 struct isis_protocols_supported
{
106 enum isis_threeway_state
{
107 ISIS_THREEWAY_DOWN
= 2,
108 ISIS_THREEWAY_INITIALIZING
= 1,
112 struct isis_threeway_adj
{
113 enum isis_threeway_state state
;
114 uint32_t local_circuit_id
;
116 uint8_t neighbor_id
[6];
117 uint32_t neighbor_circuit_id
;
122 struct isis_item
*next
;
125 struct isis_lan_neighbor
;
126 struct isis_lan_neighbor
{
127 struct isis_lan_neighbor
*next
;
132 struct isis_ipv4_address
;
133 struct isis_ipv4_address
{
134 struct isis_ipv4_address
*next
;
139 struct isis_ipv6_address
;
140 struct isis_ipv6_address
{
141 struct isis_ipv6_address
*next
;
143 struct in6_addr addr
;
146 struct isis_mt_router_info
;
147 struct isis_mt_router_info
{
148 struct isis_mt_router_info
*next
;
157 struct isis_auth
*next
;
166 size_t offset
; /* Only valid after packing */
169 struct isis_item_list
;
170 struct isis_item_list
{
171 struct isis_item
*head
;
172 struct isis_item
**tail
;
174 RB_ENTRY(isis_item_list
) mt_tree
;
179 RB_HEAD(isis_mt_item_list
, isis_item_list
);
181 struct isis_item_list
*isis_get_mt_items(struct isis_mt_item_list
*m
,
183 struct isis_item_list
*isis_lookup_mt_items(struct isis_mt_item_list
*m
,
187 struct isis_item_list isis_auth
;
188 struct isis_item_list area_addresses
;
189 struct isis_item_list oldstyle_reach
;
190 struct isis_item_list lan_neighbor
;
191 struct isis_item_list lsp_entries
;
192 struct isis_item_list extended_reach
;
193 struct isis_mt_item_list mt_reach
;
194 struct isis_item_list oldstyle_ip_reach
;
195 struct isis_protocols_supported protocols_supported
;
196 struct isis_item_list oldstyle_ip_reach_ext
;
197 struct isis_item_list ipv4_address
;
198 struct isis_item_list ipv6_address
;
199 struct isis_item_list mt_router_info
;
200 bool mt_router_info_empty
;
201 struct in_addr
*te_router_id
;
202 struct isis_item_list extended_ip_reach
;
203 struct isis_mt_item_list mt_ip_reach
;
205 struct isis_item_list ipv6_reach
;
206 struct isis_mt_item_list mt_ipv6_reach
;
207 struct isis_threeway_adj
*threeway_adj
;
210 struct isis_subtlvs
{
211 /* draft-baker-ipv6-isis-dst-src-routing-06 */
212 struct prefix_ipv6
*source_prefix
;
215 enum isis_tlv_context
{
217 ISIS_CONTEXT_SUBTLV_NE_REACH
,
218 ISIS_CONTEXT_SUBTLV_IP_REACH
,
219 ISIS_CONTEXT_SUBTLV_IPV6_REACH
,
224 ISIS_TLV_AREA_ADDRESSES
= 1,
225 ISIS_TLV_OLDSTYLE_REACH
= 2,
226 ISIS_TLV_LAN_NEIGHBORS
= 6,
227 ISIS_TLV_PADDING
= 8,
228 ISIS_TLV_LSP_ENTRY
= 9,
230 ISIS_TLV_EXTENDED_REACH
= 22,
232 ISIS_TLV_OLDSTYLE_IP_REACH
= 128,
233 ISIS_TLV_PROTOCOLS_SUPPORTED
= 129,
234 ISIS_TLV_OLDSTYLE_IP_REACH_EXT
= 130,
235 ISIS_TLV_IPV4_ADDRESS
= 132,
236 ISIS_TLV_TE_ROUTER_ID
= 134,
237 ISIS_TLV_EXTENDED_IP_REACH
= 135,
238 ISIS_TLV_DYNAMIC_HOSTNAME
= 137,
239 ISIS_TLV_MT_REACH
= 222,
240 ISIS_TLV_MT_ROUTER_INFO
= 229,
241 ISIS_TLV_IPV6_ADDRESS
= 232,
242 ISIS_TLV_MT_IP_REACH
= 235,
243 ISIS_TLV_IPV6_REACH
= 236,
244 ISIS_TLV_MT_IPV6_REACH
= 237,
245 ISIS_TLV_THREE_WAY_ADJ
= 240,
248 ISIS_SUBTLV_IPV6_SOURCE_PREFIX
= 22
251 #define IS_COMPAT_MT_TLV(tlv_type) \
252 ((tlv_type == ISIS_TLV_MT_REACH) || (tlv_type == ISIS_TLV_MT_IP_REACH) \
253 || (tlv_type == ISIS_TLV_MT_IPV6_REACH))
256 int isis_pack_tlvs(struct isis_tlvs
*tlvs
, struct stream
*stream
,
257 size_t len_pointer
, bool pad
, bool is_lsp
);
258 void isis_free_tlvs(struct isis_tlvs
*tlvs
);
259 struct isis_tlvs
*isis_alloc_tlvs(void);
260 int isis_unpack_tlvs(size_t avail_len
, struct stream
*stream
,
261 struct isis_tlvs
**dest
, const char **error_log
);
262 const char *isis_format_tlvs(struct isis_tlvs
*tlvs
);
263 struct isis_tlvs
*isis_copy_tlvs(struct isis_tlvs
*tlvs
);
264 struct list
*isis_fragment_tlvs(struct isis_tlvs
*tlvs
, size_t size
);
266 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
267 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
269 #define ISIS_IPV6_REACH_DOWN 0x80
270 #define ISIS_IPV6_REACH_EXTERNAL 0x40
271 #define ISIS_IPV6_REACH_SUBTLV 0x20
274 #define ISIS_MT_MASK 0x0fff
275 #define ISIS_MT_OL_MASK 0x8000
276 #define ISIS_MT_AT_MASK 0x4000
280 void isis_tlvs_add_auth(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
);
281 void isis_tlvs_add_area_addresses(struct isis_tlvs
*tlvs
,
282 struct list
*addresses
);
283 void isis_tlvs_add_lan_neighbors(struct isis_tlvs
*tlvs
,
284 struct list
*neighbors
);
285 void isis_tlvs_set_protocols_supported(struct isis_tlvs
*tlvs
,
286 struct nlpids
*nlpids
);
287 void isis_tlvs_add_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
,
288 bool overload
, bool attached
);
289 void isis_tlvs_add_ipv4_address(struct isis_tlvs
*tlvs
, struct in_addr
*addr
);
290 void isis_tlvs_add_ipv4_addresses(struct isis_tlvs
*tlvs
,
291 struct list
*addresses
);
292 void isis_tlvs_add_ipv6_addresses(struct isis_tlvs
*tlvs
,
293 struct list
*addresses
);
294 bool isis_tlvs_auth_is_valid(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
,
295 struct stream
*stream
, bool is_lsp
);
296 bool isis_tlvs_area_addresses_match(struct isis_tlvs
*tlvs
,
297 struct list
*addresses
);
298 struct isis_adjacency
;
299 void isis_tlvs_to_adj(struct isis_tlvs
*tlvs
, struct isis_adjacency
*adj
,
301 bool isis_tlvs_own_snpa_found(struct isis_tlvs
*tlvs
, uint8_t *snpa
);
302 void isis_tlvs_add_lsp_entry(struct isis_tlvs
*tlvs
, struct isis_lsp
*lsp
);
303 void isis_tlvs_add_csnp_entries(struct isis_tlvs
*tlvs
, uint8_t *start_id
,
304 uint8_t *stop_id
, uint16_t num_lsps
,
305 dict_t
*lspdb
, struct isis_lsp
**last_lsp
);
306 void isis_tlvs_set_dynamic_hostname(struct isis_tlvs
*tlvs
,
307 const char *hostname
);
308 void isis_tlvs_set_te_router_id(struct isis_tlvs
*tlvs
,
309 const struct in_addr
*id
);
310 void isis_tlvs_add_oldstyle_ip_reach(struct isis_tlvs
*tlvs
,
311 struct prefix_ipv4
*dest
, uint8_t metric
);
312 void isis_tlvs_add_extended_ip_reach(struct isis_tlvs
*tlvs
,
313 struct prefix_ipv4
*dest
, uint32_t metric
);
314 void isis_tlvs_add_ipv6_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
315 struct prefix_ipv6
*dest
, uint32_t metric
);
316 void isis_tlvs_add_ipv6_dstsrc_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
317 struct prefix_ipv6
*dest
,
318 struct prefix_ipv6
*src
,
320 void isis_tlvs_add_oldstyle_reach(struct isis_tlvs
*tlvs
, uint8_t *id
,
322 void isis_tlvs_add_extended_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
323 uint8_t *id
, uint32_t metric
,
324 uint8_t *subtlvs
, uint8_t subtlv_len
);
326 const char *isis_threeway_state_name(enum isis_threeway_state state
);
328 void isis_tlvs_add_threeway_adj(struct isis_tlvs
*tlvs
,
329 enum isis_threeway_state state
,
330 uint32_t local_circuit_id
,
331 const uint8_t *neighbor_id
,
332 uint32_t neighbor_circuit_id
);
334 struct isis_mt_router_info
*
335 isis_tlvs_lookup_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
);