]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_tlvs.h
isisd: add support for TLV 240 P2P Three-Way Adjacency
[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 enum isis_threeway_state {
107 ISIS_THREEWAY_DOWN = 2,
108 ISIS_THREEWAY_INITIALIZING = 1,
109 ISIS_THREEWAY_UP = 0
110 };
111
112 struct isis_threeway_adj {
113 enum isis_threeway_state state;
114 uint32_t local_circuit_id;
115 bool neighbor_set;
116 uint8_t neighbor_id[6];
117 uint32_t neighbor_circuit_id;
118 };
119
120 struct isis_item;
121 struct isis_item {
122 struct isis_item *next;
123 };
124
125 struct isis_lan_neighbor;
126 struct isis_lan_neighbor {
127 struct isis_lan_neighbor *next;
128
129 uint8_t mac[6];
130 };
131
132 struct isis_ipv4_address;
133 struct isis_ipv4_address {
134 struct isis_ipv4_address *next;
135
136 struct in_addr addr;
137 };
138
139 struct isis_ipv6_address;
140 struct isis_ipv6_address {
141 struct isis_ipv6_address *next;
142
143 struct in6_addr addr;
144 };
145
146 struct isis_mt_router_info;
147 struct isis_mt_router_info {
148 struct isis_mt_router_info *next;
149
150 bool overload;
151 bool attached;
152 uint16_t mtid;
153 };
154
155 struct isis_auth;
156 struct isis_auth {
157 struct isis_auth *next;
158
159 uint8_t type;
160 uint8_t length;
161 uint8_t value[256];
162
163 uint8_t plength;
164 uint8_t passwd[256];
165
166 size_t offset; /* Only valid after packing */
167 };
168
169 struct isis_item_list;
170 struct isis_item_list {
171 struct isis_item *head;
172 struct isis_item **tail;
173
174 RB_ENTRY(isis_item_list) mt_tree;
175 uint16_t mtid;
176 unsigned int count;
177 };
178
179 RB_HEAD(isis_mt_item_list, isis_item_list);
180
181 struct isis_item_list *isis_get_mt_items(struct isis_mt_item_list *m,
182 uint16_t mtid);
183 struct isis_item_list *isis_lookup_mt_items(struct isis_mt_item_list *m,
184 uint16_t mtid);
185
186 struct isis_tlvs {
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;
204 char *hostname;
205 struct isis_item_list ipv6_reach;
206 struct isis_mt_item_list mt_ipv6_reach;
207 struct isis_threeway_adj *threeway_adj;
208 };
209
210 struct isis_subtlvs {
211 /* draft-baker-ipv6-isis-dst-src-routing-06 */
212 struct prefix_ipv6 *source_prefix;
213 };
214
215 enum isis_tlv_context {
216 ISIS_CONTEXT_LSP,
217 ISIS_CONTEXT_SUBTLV_NE_REACH,
218 ISIS_CONTEXT_SUBTLV_IP_REACH,
219 ISIS_CONTEXT_SUBTLV_IPV6_REACH,
220 ISIS_CONTEXT_MAX
221 };
222
223 enum isis_tlv_type {
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,
229 ISIS_TLV_AUTH = 10,
230 ISIS_TLV_EXTENDED_REACH = 22,
231
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,
246 ISIS_TLV_MAX = 256,
247
248 ISIS_SUBTLV_IPV6_SOURCE_PREFIX = 22
249 };
250
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))
254
255 struct stream;
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);
265
266 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
267 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
268
269 #define ISIS_IPV6_REACH_DOWN 0x80
270 #define ISIS_IPV6_REACH_EXTERNAL 0x40
271 #define ISIS_IPV6_REACH_SUBTLV 0x20
272
273 #ifndef ISIS_MT_MASK
274 #define ISIS_MT_MASK 0x0fff
275 #define ISIS_MT_OL_MASK 0x8000
276 #define ISIS_MT_AT_MASK 0x4000
277 #endif
278
279
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,
300 bool *changed);
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_oldstyle_reach(struct isis_tlvs *tlvs, uint8_t *id,
317 uint8_t metric);
318 void isis_tlvs_add_extended_reach(struct isis_tlvs *tlvs, uint16_t mtid,
319 uint8_t *id, uint32_t metric,
320 uint8_t *subtlvs, uint8_t subtlv_len);
321
322 const char *isis_threeway_state_name(enum isis_threeway_state state);
323
324 void isis_tlvs_add_threeway_adj(struct isis_tlvs *tlvs,
325 enum isis_threeway_state state,
326 uint32_t local_circuit_id,
327 const uint8_t *neighbor_id,
328 uint32_t neighbor_circuit_id);
329
330 struct isis_mt_router_info *
331 isis_tlvs_lookup_mt_router_info(struct isis_tlvs *tlvs, uint16_t mtid);
332 #endif