]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_tlvs.h
Merge pull request #964 from opensourcerouting/plist-trie-corruption-3.0
[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 struct isis_item;
107 struct isis_item {
108 struct isis_item *next;
109 };
110
111 struct isis_lan_neighbor;
112 struct isis_lan_neighbor {
113 struct isis_lan_neighbor *next;
114
115 uint8_t mac[6];
116 };
117
118 struct isis_ipv4_address;
119 struct isis_ipv4_address {
120 struct isis_ipv4_address *next;
121
122 struct in_addr addr;
123 };
124
125 struct isis_ipv6_address;
126 struct isis_ipv6_address {
127 struct isis_ipv6_address *next;
128
129 struct in6_addr addr;
130 };
131
132 struct isis_mt_router_info;
133 struct isis_mt_router_info {
134 struct isis_mt_router_info *next;
135
136 bool overload;
137 bool attached;
138 uint16_t mtid;
139 };
140
141 struct isis_auth;
142 struct isis_auth {
143 struct isis_auth *next;
144
145 uint8_t type;
146 uint8_t length;
147 uint8_t value[256];
148
149 uint8_t plength;
150 uint8_t passwd[256];
151
152 size_t offset; /* Only valid after packing */
153 };
154
155 struct isis_item_list;
156 struct isis_item_list {
157 struct isis_item *head;
158 struct isis_item **tail;
159
160 RB_ENTRY(isis_item_list) mt_tree;
161 uint16_t mtid;
162 unsigned int count;
163 };
164
165 RB_HEAD(isis_mt_item_list, isis_item_list);
166
167 struct isis_item_list *isis_get_mt_items(struct isis_mt_item_list *m,
168 uint16_t mtid);
169 struct isis_item_list *isis_lookup_mt_items(struct isis_mt_item_list *m,
170 uint16_t mtid);
171
172 struct isis_tlvs {
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;
190 char *hostname;
191 struct isis_item_list ipv6_reach;
192 struct isis_mt_item_list mt_ipv6_reach;
193 };
194
195 struct isis_subtlvs {
196 /* draft-baker-ipv6-isis-dst-src-routing-06 */
197 struct prefix_ipv6 *source_prefix;
198 };
199
200 enum isis_tlv_context {
201 ISIS_CONTEXT_LSP,
202 ISIS_CONTEXT_SUBTLV_NE_REACH,
203 ISIS_CONTEXT_SUBTLV_IP_REACH,
204 ISIS_CONTEXT_SUBTLV_IPV6_REACH,
205 ISIS_CONTEXT_MAX
206 };
207
208 enum isis_tlv_type {
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,
214 ISIS_TLV_AUTH = 10,
215 ISIS_TLV_EXTENDED_REACH = 22,
216
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,
230 ISIS_TLV_MAX = 256,
231
232 ISIS_SUBTLV_IPV6_SOURCE_PREFIX = 22
233 };
234
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))
238
239 struct stream;
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);
249
250 #define ISIS_EXTENDED_IP_REACH_DOWN 0x80
251 #define ISIS_EXTENDED_IP_REACH_SUBTLV 0x40
252
253 #define ISIS_IPV6_REACH_DOWN 0x80
254 #define ISIS_IPV6_REACH_EXTERNAL 0x40
255 #define ISIS_IPV6_REACH_SUBTLV 0x20
256
257 #ifndef ISIS_MT_MASK
258 #define ISIS_MT_MASK 0x0fff
259 #define ISIS_MT_OL_MASK 0x8000
260 #define ISIS_MT_AT_MASK 0x4000
261 #endif
262
263
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,
284 bool *changed);
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,
301 uint8_t metric);
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);
305
306 struct isis_mt_router_info *
307 isis_tlvs_lookup_mt_router_info(struct isis_tlvs *tlvs, uint16_t mtid);
308 #endif