]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_tlvs.h
fabricd: Add support for TLV 150 (Spine-Leaf-Extension)
[mirror_frr.git] / isisd / isis_tlvs.h
1 /*
2 * IS-IS TLV Serializer/Deserializer
3 *
4 * Copyright (C) 2015,2017 Christian Franke
5 *
6 * This file is part of FRR.
7 *
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
11 * later version.
12 *
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.
17 *
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
21 * 02111-1307, USA.
22 */
23 #ifndef ISIS_TLVS_H
24 #define ISIS_TLVS_H
25
26 #include "openbsd-tree.h"
27 #include "prefix.h"
28 #include "isisd/dict.h"
29
30 struct isis_subtlvs;
31
32 struct isis_area_address;
33 struct isis_area_address {
34 struct isis_area_address *next;
35
36 uint8_t addr[20];
37 uint8_t len;
38 };
39
40 struct isis_oldstyle_reach;
41 struct isis_oldstyle_reach {
42 struct isis_oldstyle_reach *next;
43
44 uint8_t id[7];
45 uint8_t metric;
46 };
47
48 struct isis_oldstyle_ip_reach;
49 struct isis_oldstyle_ip_reach {
50 struct isis_oldstyle_ip_reach *next;
51
52 uint8_t metric;
53 struct prefix_ipv4 prefix;
54 };
55
56 struct isis_lsp_entry;
57 struct isis_lsp_entry {
58 struct isis_lsp_entry *next;
59
60 uint16_t rem_lifetime;
61 uint8_t id[8];
62 uint16_t checksum;
63 uint32_t seqno;
64
65 struct isis_lsp *lsp;
66 };
67
68 struct isis_extended_reach;
69 struct isis_extended_reach {
70 struct isis_extended_reach *next;
71
72 uint8_t id[7];
73 uint32_t metric;
74
75 uint8_t *subtlvs;
76 uint8_t subtlv_len;
77 };
78
79 struct isis_extended_ip_reach;
80 struct isis_extended_ip_reach {
81 struct isis_extended_ip_reach *next;
82
83 uint32_t metric;
84 bool down;
85 struct prefix_ipv4 prefix;
86 };
87
88 struct isis_ipv6_reach;
89 struct isis_ipv6_reach {
90 struct isis_ipv6_reach *next;
91
92 uint32_t metric;
93 bool down;
94 bool external;
95
96 struct prefix_ipv6 prefix;
97
98 struct isis_subtlvs *subtlvs;
99 };
100
101 struct isis_protocols_supported {
102 uint8_t count;
103 uint8_t *protocols;
104 };
105
106 #define ISIS_TIER_UNDEFINED 15
107
108 struct isis_spine_leaf {
109 uint8_t tier;
110
111 bool has_tier;
112 bool is_leaf;
113 bool is_spine;
114 bool is_backup;
115 };
116
117 enum isis_threeway_state {
118 ISIS_THREEWAY_DOWN = 2,
119 ISIS_THREEWAY_INITIALIZING = 1,
120 ISIS_THREEWAY_UP = 0
121 };
122
123 struct isis_threeway_adj {
124 enum isis_threeway_state state;
125 uint32_t local_circuit_id;
126 bool neighbor_set;
127 uint8_t neighbor_id[6];
128 uint32_t neighbor_circuit_id;
129 };
130
131 struct isis_item;
132 struct isis_item {
133 struct isis_item *next;
134 };
135
136 struct isis_lan_neighbor;
137 struct isis_lan_neighbor {
138 struct isis_lan_neighbor *next;
139
140 uint8_t mac[6];
141 };
142
143 struct isis_ipv4_address;
144 struct isis_ipv4_address {
145 struct isis_ipv4_address *next;
146
147 struct in_addr addr;
148 };
149
150 struct isis_ipv6_address;
151 struct isis_ipv6_address {
152 struct isis_ipv6_address *next;
153
154 struct in6_addr addr;
155 };
156
157 struct isis_mt_router_info;
158 struct isis_mt_router_info {
159 struct isis_mt_router_info *next;
160
161 bool overload;
162 bool attached;
163 uint16_t mtid;
164 };
165
166 struct isis_auth;
167 struct isis_auth {
168 struct isis_auth *next;
169
170 uint8_t type;
171 uint8_t length;
172 uint8_t value[256];
173
174 uint8_t plength;
175 uint8_t passwd[256];
176
177 size_t offset; /* Only valid after packing */
178 };
179
180 struct isis_item_list;
181 struct isis_item_list {
182 struct isis_item *head;
183 struct isis_item **tail;
184
185 RB_ENTRY(isis_item_list) mt_tree;
186 uint16_t mtid;
187 unsigned int count;
188 };
189
190 RB_HEAD(isis_mt_item_list, isis_item_list);
191
192 struct isis_item_list *isis_get_mt_items(struct isis_mt_item_list *m,
193 uint16_t mtid);
194 struct isis_item_list *isis_lookup_mt_items(struct isis_mt_item_list *m,
195 uint16_t mtid);
196
197 struct isis_tlvs {
198 struct isis_item_list isis_auth;
199 struct isis_item_list area_addresses;
200 struct isis_item_list oldstyle_reach;
201 struct isis_item_list lan_neighbor;
202 struct isis_item_list lsp_entries;
203 struct isis_item_list extended_reach;
204 struct isis_mt_item_list mt_reach;
205 struct isis_item_list oldstyle_ip_reach;
206 struct isis_protocols_supported protocols_supported;
207 struct isis_item_list oldstyle_ip_reach_ext;
208 struct isis_item_list ipv4_address;
209 struct isis_item_list ipv6_address;
210 struct isis_item_list mt_router_info;
211 bool mt_router_info_empty;
212 struct in_addr *te_router_id;
213 struct isis_item_list extended_ip_reach;
214 struct isis_mt_item_list mt_ip_reach;
215 char *hostname;
216 struct isis_item_list ipv6_reach;
217 struct isis_mt_item_list mt_ipv6_reach;
218 struct isis_threeway_adj *threeway_adj;
219 struct isis_spine_leaf *spine_leaf;
220 };
221
222 struct isis_subtlvs {
223 /* draft-baker-ipv6-isis-dst-src-routing-06 */
224 struct prefix_ipv6 *source_prefix;
225 };
226
227 enum isis_tlv_context {
228 ISIS_CONTEXT_LSP,
229 ISIS_CONTEXT_SUBTLV_NE_REACH,
230 ISIS_CONTEXT_SUBTLV_IP_REACH,
231 ISIS_CONTEXT_SUBTLV_IPV6_REACH,
232 ISIS_CONTEXT_MAX
233 };
234
235 enum isis_tlv_type {
236 ISIS_TLV_AREA_ADDRESSES = 1,
237 ISIS_TLV_OLDSTYLE_REACH = 2,
238 ISIS_TLV_LAN_NEIGHBORS = 6,
239 ISIS_TLV_PADDING = 8,
240 ISIS_TLV_LSP_ENTRY = 9,
241 ISIS_TLV_AUTH = 10,
242 ISIS_TLV_EXTENDED_REACH = 22,
243
244 ISIS_TLV_OLDSTYLE_IP_REACH = 128,
245 ISIS_TLV_PROTOCOLS_SUPPORTED = 129,
246 ISIS_TLV_OLDSTYLE_IP_REACH_EXT = 130,
247 ISIS_TLV_IPV4_ADDRESS = 132,
248 ISIS_TLV_TE_ROUTER_ID = 134,
249 ISIS_TLV_EXTENDED_IP_REACH = 135,
250 ISIS_TLV_DYNAMIC_HOSTNAME = 137,
251 ISIS_TLV_SPINE_LEAF_EXT = 150,
252 ISIS_TLV_MT_REACH = 222,
253 ISIS_TLV_MT_ROUTER_INFO = 229,
254 ISIS_TLV_IPV6_ADDRESS = 232,
255 ISIS_TLV_MT_IP_REACH = 235,
256 ISIS_TLV_IPV6_REACH = 236,
257 ISIS_TLV_MT_IPV6_REACH = 237,
258 ISIS_TLV_THREE_WAY_ADJ = 240,
259 ISIS_TLV_MAX = 256,
260
261 ISIS_SUBTLV_IPV6_SOURCE_PREFIX = 22
262 };
263
264 #define IS_COMPAT_MT_TLV(tlv_type) \
265 ((tlv_type == ISIS_TLV_MT_REACH) || (tlv_type == ISIS_TLV_MT_IP_REACH) \
266 || (tlv_type == ISIS_TLV_MT_IPV6_REACH))
267
268 struct stream;
269 int isis_pack_tlvs(struct isis_tlvs *tlvs, struct stream *stream,
270 size_t len_pointer, bool pad, bool is_lsp);
271 void isis_free_tlvs(struct isis_tlvs *tlvs);
272 struct isis_tlvs *isis_alloc_tlvs(void);
273 int isis_unpack_tlvs(size_t avail_len, struct stream *stream,
274 struct isis_tlvs **dest, const char **error_log);
275 const char *isis_format_tlvs(struct isis_tlvs *tlvs);
276 struct isis_tlvs *isis_copy_tlvs(struct isis_tlvs *tlvs);
277 struct list *isis_fragment_tlvs(struct isis_tlvs *tlvs, size_t size);
278
279 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
280 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
281
282 #define ISIS_IPV6_REACH_DOWN 0x80
283 #define ISIS_IPV6_REACH_EXTERNAL 0x40
284 #define ISIS_IPV6_REACH_SUBTLV 0x20
285
286 #ifndef ISIS_MT_MASK
287 #define ISIS_MT_MASK 0x0fff
288 #define ISIS_MT_OL_MASK 0x8000
289 #define ISIS_MT_AT_MASK 0x4000
290 #endif
291
292
293 void isis_tlvs_add_auth(struct isis_tlvs *tlvs, struct isis_passwd *passwd);
294 void isis_tlvs_add_area_addresses(struct isis_tlvs *tlvs,
295 struct list *addresses);
296 void isis_tlvs_add_lan_neighbors(struct isis_tlvs *tlvs,
297 struct list *neighbors);
298 void isis_tlvs_set_protocols_supported(struct isis_tlvs *tlvs,
299 struct nlpids *nlpids);
300 void isis_tlvs_add_mt_router_info(struct isis_tlvs *tlvs, uint16_t mtid,
301 bool overload, bool attached);
302 void isis_tlvs_add_ipv4_address(struct isis_tlvs *tlvs, struct in_addr *addr);
303 void isis_tlvs_add_ipv4_addresses(struct isis_tlvs *tlvs,
304 struct list *addresses);
305 void isis_tlvs_add_ipv6_addresses(struct isis_tlvs *tlvs,
306 struct list *addresses);
307 bool isis_tlvs_auth_is_valid(struct isis_tlvs *tlvs, struct isis_passwd *passwd,
308 struct stream *stream, bool is_lsp);
309 bool isis_tlvs_area_addresses_match(struct isis_tlvs *tlvs,
310 struct list *addresses);
311 struct isis_adjacency;
312 void isis_tlvs_to_adj(struct isis_tlvs *tlvs, struct isis_adjacency *adj,
313 bool *changed);
314 bool isis_tlvs_own_snpa_found(struct isis_tlvs *tlvs, uint8_t *snpa);
315 void isis_tlvs_add_lsp_entry(struct isis_tlvs *tlvs, struct isis_lsp *lsp);
316 void isis_tlvs_add_csnp_entries(struct isis_tlvs *tlvs, uint8_t *start_id,
317 uint8_t *stop_id, uint16_t num_lsps,
318 dict_t *lspdb, struct isis_lsp **last_lsp);
319 void isis_tlvs_set_dynamic_hostname(struct isis_tlvs *tlvs,
320 const char *hostname);
321 void isis_tlvs_set_te_router_id(struct isis_tlvs *tlvs,
322 const struct in_addr *id);
323 void isis_tlvs_add_oldstyle_ip_reach(struct isis_tlvs *tlvs,
324 struct prefix_ipv4 *dest, uint8_t metric);
325 void isis_tlvs_add_extended_ip_reach(struct isis_tlvs *tlvs,
326 struct prefix_ipv4 *dest, uint32_t metric);
327 void isis_tlvs_add_ipv6_reach(struct isis_tlvs *tlvs, uint16_t mtid,
328 struct prefix_ipv6 *dest, uint32_t metric);
329 void isis_tlvs_add_ipv6_dstsrc_reach(struct isis_tlvs *tlvs, uint16_t mtid,
330 struct prefix_ipv6 *dest,
331 struct prefix_ipv6 *src,
332 uint32_t metric);
333 void isis_tlvs_add_oldstyle_reach(struct isis_tlvs *tlvs, uint8_t *id,
334 uint8_t metric);
335 void isis_tlvs_add_extended_reach(struct isis_tlvs *tlvs, uint16_t mtid,
336 uint8_t *id, uint32_t metric,
337 uint8_t *subtlvs, uint8_t subtlv_len);
338
339 const char *isis_threeway_state_name(enum isis_threeway_state state);
340
341 void isis_tlvs_add_threeway_adj(struct isis_tlvs *tlvs,
342 enum isis_threeway_state state,
343 uint32_t local_circuit_id,
344 const uint8_t *neighbor_id,
345 uint32_t neighbor_circuit_id);
346
347 void isis_tlvs_add_spine_leaf(struct isis_tlvs *tlvs, uint8_t tier,
348 bool has_tier, bool is_leaf, bool is_spine,
349 bool is_backup);
350
351 struct isis_mt_router_info *
352 isis_tlvs_lookup_mt_router_info(struct isis_tlvs *tlvs, uint16_t mtid);
353 #endif