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
{
108 struct isis_item
*next
;
111 struct isis_lan_neighbor
;
112 struct isis_lan_neighbor
{
113 struct isis_lan_neighbor
*next
;
118 struct isis_ipv4_address
;
119 struct isis_ipv4_address
{
120 struct isis_ipv4_address
*next
;
125 struct isis_ipv6_address
;
126 struct isis_ipv6_address
{
127 struct isis_ipv6_address
*next
;
129 struct in6_addr addr
;
132 struct isis_mt_router_info
;
133 struct isis_mt_router_info
{
134 struct isis_mt_router_info
*next
;
143 struct isis_auth
*next
;
152 size_t offset
; /* Only valid after packing */
155 struct isis_item_list
;
156 struct isis_item_list
{
157 struct isis_item
*head
;
158 struct isis_item
**tail
;
160 RB_ENTRY(isis_item_list
) mt_tree
;
165 RB_HEAD(isis_mt_item_list
, isis_item_list
);
167 struct isis_item_list
*isis_get_mt_items(struct isis_mt_item_list
*m
,
169 struct isis_item_list
*isis_lookup_mt_items(struct isis_mt_item_list
*m
,
173 struct isis_item_list isis_auth
;
174 struct isis_item_list area_addresses
;
175 struct isis_item_list oldstyle_reach
;
176 struct isis_item_list lan_neighbor
;
177 struct isis_item_list lsp_entries
;
178 struct isis_item_list extended_reach
;
179 struct isis_mt_item_list mt_reach
;
180 struct isis_item_list oldstyle_ip_reach
;
181 struct isis_protocols_supported protocols_supported
;
182 struct isis_item_list oldstyle_ip_reach_ext
;
183 struct isis_item_list ipv4_address
;
184 struct isis_item_list ipv6_address
;
185 struct isis_item_list mt_router_info
;
186 bool mt_router_info_empty
;
187 struct in_addr
*te_router_id
;
188 struct isis_item_list extended_ip_reach
;
189 struct isis_mt_item_list mt_ip_reach
;
191 struct isis_item_list ipv6_reach
;
192 struct isis_mt_item_list mt_ipv6_reach
;
195 struct isis_subtlvs
{
196 /* draft-baker-ipv6-isis-dst-src-routing-06 */
197 struct prefix_ipv6
*source_prefix
;
200 enum isis_tlv_context
{
202 ISIS_CONTEXT_SUBTLV_NE_REACH
,
203 ISIS_CONTEXT_SUBTLV_IP_REACH
,
204 ISIS_CONTEXT_SUBTLV_IPV6_REACH
,
209 ISIS_TLV_AREA_ADDRESSES
= 1,
210 ISIS_TLV_OLDSTYLE_REACH
= 2,
211 ISIS_TLV_LAN_NEIGHBORS
= 6,
212 ISIS_TLV_PADDING
= 8,
213 ISIS_TLV_LSP_ENTRY
= 9,
215 ISIS_TLV_EXTENDED_REACH
= 22,
217 ISIS_TLV_OLDSTYLE_IP_REACH
= 128,
218 ISIS_TLV_PROTOCOLS_SUPPORTED
= 129,
219 ISIS_TLV_OLDSTYLE_IP_REACH_EXT
= 130,
220 ISIS_TLV_IPV4_ADDRESS
= 132,
221 ISIS_TLV_TE_ROUTER_ID
= 134,
222 ISIS_TLV_EXTENDED_IP_REACH
= 135,
223 ISIS_TLV_DYNAMIC_HOSTNAME
= 137,
224 ISIS_TLV_MT_REACH
= 222,
225 ISIS_TLV_MT_ROUTER_INFO
= 229,
226 ISIS_TLV_IPV6_ADDRESS
= 232,
227 ISIS_TLV_MT_IP_REACH
= 235,
228 ISIS_TLV_IPV6_REACH
= 236,
229 ISIS_TLV_MT_IPV6_REACH
= 237,
232 ISIS_SUBTLV_IPV6_SOURCE_PREFIX
= 22
235 #define IS_COMPAT_MT_TLV(tlv_type) \
236 ((tlv_type == ISIS_TLV_MT_REACH) || (tlv_type == ISIS_TLV_MT_IP_REACH) \
237 || (tlv_type == ISIS_TLV_MT_IPV6_REACH))
240 int isis_pack_tlvs(struct isis_tlvs
*tlvs
, struct stream
*stream
,
241 size_t len_pointer
, bool pad
, bool is_lsp
);
242 void isis_free_tlvs(struct isis_tlvs
*tlvs
);
243 struct isis_tlvs
*isis_alloc_tlvs(void);
244 int isis_unpack_tlvs(size_t avail_len
, struct stream
*stream
,
245 struct isis_tlvs
**dest
, const char **error_log
);
246 const char *isis_format_tlvs(struct isis_tlvs
*tlvs
);
247 struct isis_tlvs
*isis_copy_tlvs(struct isis_tlvs
*tlvs
);
248 struct list
*isis_fragment_tlvs(struct isis_tlvs
*tlvs
, size_t size
);
250 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
251 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
253 #define ISIS_IPV6_REACH_DOWN 0x80
254 #define ISIS_IPV6_REACH_EXTERNAL 0x40
255 #define ISIS_IPV6_REACH_SUBTLV 0x20
258 #define ISIS_MT_MASK 0x0fff
259 #define ISIS_MT_OL_MASK 0x8000
260 #define ISIS_MT_AT_MASK 0x4000
264 void isis_tlvs_add_auth(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
);
265 void isis_tlvs_add_area_addresses(struct isis_tlvs
*tlvs
,
266 struct list
*addresses
);
267 void isis_tlvs_add_lan_neighbors(struct isis_tlvs
*tlvs
,
268 struct list
*neighbors
);
269 void isis_tlvs_set_protocols_supported(struct isis_tlvs
*tlvs
,
270 struct nlpids
*nlpids
);
271 void isis_tlvs_add_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
,
272 bool overload
, bool attached
);
273 void isis_tlvs_add_ipv4_address(struct isis_tlvs
*tlvs
, struct in_addr
*addr
);
274 void isis_tlvs_add_ipv4_addresses(struct isis_tlvs
*tlvs
,
275 struct list
*addresses
);
276 void isis_tlvs_add_ipv6_addresses(struct isis_tlvs
*tlvs
,
277 struct list
*addresses
);
278 bool isis_tlvs_auth_is_valid(struct isis_tlvs
*tlvs
, struct isis_passwd
*passwd
,
279 struct stream
*stream
, bool is_lsp
);
280 bool isis_tlvs_area_addresses_match(struct isis_tlvs
*tlvs
,
281 struct list
*addresses
);
282 struct isis_adjacency
;
283 void isis_tlvs_to_adj(struct isis_tlvs
*tlvs
, struct isis_adjacency
*adj
,
285 bool isis_tlvs_own_snpa_found(struct isis_tlvs
*tlvs
, uint8_t *snpa
);
286 void isis_tlvs_add_lsp_entry(struct isis_tlvs
*tlvs
, struct isis_lsp
*lsp
);
287 void isis_tlvs_add_csnp_entries(struct isis_tlvs
*tlvs
, uint8_t *start_id
,
288 uint8_t *stop_id
, uint16_t num_lsps
,
289 dict_t
*lspdb
, struct isis_lsp
**last_lsp
);
290 void isis_tlvs_set_dynamic_hostname(struct isis_tlvs
*tlvs
,
291 const char *hostname
);
292 void isis_tlvs_set_te_router_id(struct isis_tlvs
*tlvs
,
293 const struct in_addr
*id
);
294 void isis_tlvs_add_oldstyle_ip_reach(struct isis_tlvs
*tlvs
,
295 struct prefix_ipv4
*dest
, uint8_t metric
);
296 void isis_tlvs_add_extended_ip_reach(struct isis_tlvs
*tlvs
,
297 struct prefix_ipv4
*dest
, uint32_t metric
);
298 void isis_tlvs_add_ipv6_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
299 struct prefix_ipv6
*dest
, uint32_t metric
);
300 void isis_tlvs_add_oldstyle_reach(struct isis_tlvs
*tlvs
, uint8_t *id
,
302 void isis_tlvs_add_extended_reach(struct isis_tlvs
*tlvs
, uint16_t mtid
,
303 uint8_t *id
, uint32_t metric
,
304 uint8_t *subtlvs
, uint8_t subtlv_len
);
306 struct isis_mt_router_info
*
307 isis_tlvs_lookup_mt_router_info(struct isis_tlvs
*tlvs
, uint16_t mtid
);