]> git.proxmox.com Git - mirror_frr.git/blob - zebra/rtadv.h
zebra: Consolidate the stream_failure section with normal return
[mirror_frr.git] / zebra / rtadv.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Router advertisement
3 * Copyright (C) 2005 6WIND <jean-mickael.guerin@6wind.com>
4 * Copyright (C) 1999 Kunihiro Ishiguro
5 */
6
7 #ifndef _ZEBRA_RTADV_H
8 #define _ZEBRA_RTADV_H
9
10 #include "zebra.h"
11 #include "vty.h"
12 #include "typesafe.h"
13
14 #include "zebra/zserv.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 struct interface;
21 struct zebra_if;
22
23 #if defined(HAVE_RTADV)
24
25 PREDECL_SORTLIST_UNIQ(adv_if_list);
26 /* Structure which hold status of router advertisement. */
27 struct rtadv {
28 int sock;
29
30 struct adv_if_list_head adv_if;
31 struct adv_if_list_head adv_msec_if;
32
33 struct event *ra_read;
34 struct event *ra_timer;
35 };
36
37 PREDECL_RBTREE_UNIQ(rtadv_prefixes);
38
39 /* Router advertisement parameter. From RFC4861, RFC6275 and RFC4191. */
40 struct rtadvconf {
41 /* A flag indicating whether or not the router sends periodic Router
42 Advertisements and responds to Router Solicitations.
43 Default: false */
44 int AdvSendAdvertisements;
45
46 /* The maximum time allowed between sending unsolicited multicast
47 Router Advertisements from the interface, in milliseconds.
48 MUST be no less than 70 ms [RFC6275 7.5] and no greater
49 than 1800000 ms [RFC4861 6.2.1].
50
51 Default: 600000 milliseconds */
52 int MaxRtrAdvInterval;
53 #define RTADV_MAX_RTR_ADV_INTERVAL 600000
54
55 /* The minimum time allowed between sending unsolicited multicast
56 Router Advertisements from the interface, in milliseconds.
57 MUST be no less than 30 ms [RFC6275 7.5].
58 MUST be no greater than .75 * MaxRtrAdvInterval.
59
60 Default: 0.33 * MaxRtrAdvInterval */
61 int MinRtrAdvInterval; /* This field is currently unused. */
62 #define RTADV_MIN_RTR_ADV_INTERVAL (0.33 * RTADV_MAX_RTR_ADV_INTERVAL)
63
64 /* Unsolicited Router Advertisements' interval timer. */
65 int AdvIntervalTimer;
66
67 /* The true/false value to be placed in the "Managed address
68 configuration" flag field in the Router Advertisement. See
69 [ADDRCONF].
70
71 Default: false */
72 int AdvManagedFlag;
73 struct timeval lastadvmanagedflag;
74
75
76 /* The true/false value to be placed in the "Other stateful
77 configuration" flag field in the Router Advertisement. See
78 [ADDRCONF].
79
80 Default: false */
81 int AdvOtherConfigFlag;
82 struct timeval lastadvotherconfigflag;
83
84 /* The value to be placed in MTU options sent by the router. A
85 value of zero indicates that no MTU options are sent.
86
87 Default: 0 */
88 int AdvLinkMTU;
89
90
91 /* The value to be placed in the Reachable Time field in the Router
92 Advertisement messages sent by the router. The value zero means
93 unspecified (by this router). MUST be no greater than 3,600,000
94 milliseconds (1 hour).
95
96 Default: 0 */
97 uint32_t AdvReachableTime;
98 #define RTADV_MAX_REACHABLE_TIME 3600000
99 struct timeval lastadvreachabletime;
100
101 /* The value to be placed in the Retrans Timer field in the Router
102 Advertisement messages sent by the router. The value zero means
103 unspecified (by this router).
104
105 Default: 0 */
106 int AdvRetransTimer;
107 struct timeval lastadvretranstimer;
108
109 /* The default value to be placed in the Cur Hop Limit field in the
110 Router Advertisement messages sent by the router. The value
111 should be set to that current diameter of the Internet. The
112 value zero means unspecified (by this router).
113
114 Default: The value specified in the "Assigned Numbers" RFC
115 [ASSIGNED] that was in effect at the time of implementation. */
116 int AdvCurHopLimit;
117 struct timeval lastadvcurhoplimit;
118
119 #define RTADV_DEFAULT_HOPLIMIT 64 /* 64 hops */
120
121 /* The value to be placed in the Router Lifetime field of Router
122 Advertisements sent from the interface, in seconds. MUST be
123 either zero or between MaxRtrAdvInterval and 9000 seconds. A
124 value of zero indicates that the router is not to be used as a
125 default router.
126
127 Default: 3 * MaxRtrAdvInterval */
128 int AdvDefaultLifetime;
129 #define RTADV_MAX_RTRLIFETIME 9000 /* 2.5 hours */
130
131 /* A list of prefixes to be placed in Prefix Information options in
132 Router Advertisement messages sent from the interface.
133
134 Default: all prefixes that the router advertises via routing
135 protocols as being on-link for the interface from which the
136 advertisement is sent. The link-local prefix SHOULD NOT be
137 included in the list of advertised prefixes. */
138 struct rtadv_prefixes_head prefixes[1];
139
140 /* The true/false value to be placed in the "Home agent"
141 flag field in the Router Advertisement. See [RFC6275 7.1].
142
143 Default: false */
144 int AdvHomeAgentFlag;
145 #ifndef ND_RA_FLAG_HOME_AGENT
146 #define ND_RA_FLAG_HOME_AGENT 0x20
147 #endif
148
149 /* The value to be placed in Home Agent Information option if Home
150 Flag is set.
151 Default: 0 */
152 int HomeAgentPreference;
153
154 /* The value to be placed in Home Agent Information option if Home
155 Flag is set. Lifetime (seconds) MUST not be greater than 18.2
156 hours.
157 The value 0 has special meaning: use of AdvDefaultLifetime value.
158
159 Default: 0 */
160 int HomeAgentLifetime;
161 #define RTADV_MAX_HALIFETIME 65520 /* 18.2 hours */
162
163 /* The true/false value to insert or not an Advertisement Interval
164 option. See [RFC 6275 7.3]
165
166 Default: false */
167 int AdvIntervalOption;
168
169 /* The value to be placed in the Default Router Preference field of
170 a router advertisement. See [RFC 4191 2.1 & 2.2]
171
172 Default: 0 (medium) */
173 int DefaultPreference;
174 #define RTADV_PREF_MEDIUM 0x0 /* Per RFC4191. */
175
176 /*
177 * List of recursive DNS servers to include in the RDNSS option.
178 * See [RFC8106 5.1]
179 *
180 * Default: empty list; do not emit RDNSS option
181 */
182 struct list *AdvRDNSSList;
183
184 /*
185 * List of DNS search domains to include in the DNSSL option.
186 * See [RFC8106 5.2]
187 *
188 * Default: empty list; do not emit DNSSL option
189 */
190 struct list *AdvDNSSLList;
191
192 /*
193 * rfc4861 states RAs must be sent at least 3 seconds apart.
194 * We allow faster retransmits to speed up convergence but can
195 * turn that capability off to meet the rfc if needed.
196 */
197 bool UseFastRexmit; /* True if fast rexmits are enabled */
198
199 uint8_t inFastRexmit; /* True if we're rexmits faster than usual */
200
201 /* Track if RA was configured by BGP or by the Operator or both */
202 uint8_t ra_configured; /* Was RA configured? */
203 #define BGP_RA_CONFIGURED (1 << 0) /* BGP configured RA? */
204 #define VTY_RA_CONFIGURED (1 << 1) /* Operator configured RA? */
205 #define VTY_RA_INTERVAL_CONFIGURED \
206 (1 << 2) /* Operator configured RA interval */
207 int NumFastReXmitsRemain; /* Loaded first with number of fast
208 rexmits to do */
209
210 #define RTADV_FAST_REXMIT_PERIOD 1 /* 1 sec */
211 #define RTADV_NUM_FAST_REXMITS 4 /* Fast Rexmit RA 4 times on certain events \
212 */
213 };
214
215 struct rtadv_rdnss {
216 /* Address of recursive DNS server to advertise */
217 struct in6_addr addr;
218
219 /*
220 * Lifetime in seconds; all-ones means infinity, zero
221 * stop using it.
222 */
223 uint32_t lifetime;
224
225 /* If lifetime not set, use a default of 3*MaxRtrAdvInterval */
226 int lifetime_set;
227 };
228
229 /*
230 * [RFC1035 2.3.4] sets the maximum length of a domain name (a sequence of
231 * labels, each prefixed by a length octet) at 255 octets.
232 */
233 #define RTADV_MAX_ENCODED_DOMAIN_NAME 255
234
235 struct rtadv_dnssl {
236 /* Domain name without trailing root zone dot (NUL-terminated) */
237 char name[RTADV_MAX_ENCODED_DOMAIN_NAME - 1];
238
239 /* Name encoded as in [RFC1035 3.1] */
240 uint8_t encoded_name[RTADV_MAX_ENCODED_DOMAIN_NAME];
241
242 /* Actual length of encoded_name */
243 size_t encoded_len;
244
245 /* Lifetime as for RDNSS */
246 uint32_t lifetime;
247 int lifetime_set;
248 };
249
250 /* Router advertisement prefix. */
251 struct rtadv_prefix {
252 struct rtadv_prefixes_item item;
253
254 /* Prefix to be advertised. */
255 struct prefix_ipv6 prefix;
256
257 /* The prefix was manually/automatically defined. */
258 int AdvPrefixCreate;
259
260 /* The value to be placed in the Valid Lifetime in the Prefix */
261 uint32_t AdvValidLifetime;
262 #define RTADV_VALID_LIFETIME 2592000
263
264 /* The value to be placed in the on-link flag */
265 int AdvOnLinkFlag;
266
267 /* The value to be placed in the Preferred Lifetime in the Prefix
268 Information option, in seconds.*/
269 uint32_t AdvPreferredLifetime;
270 #define RTADV_PREFERRED_LIFETIME 604800
271
272 /* The value to be placed in the Autonomous Flag. */
273 int AdvAutonomousFlag;
274
275 /* The value to be placed in the Router Address Flag [RFC6275 7.2]. */
276 int AdvRouterAddressFlag;
277 #ifndef ND_OPT_PI_FLAG_RADDR
278 #define ND_OPT_PI_FLAG_RADDR 0x20
279 #endif
280 };
281
282 /* RFC4861 minimum delay between RAs */
283 #ifndef MIN_DELAY_BETWEEN_RAS
284 #define MIN_DELAY_BETWEEN_RAS 3000
285 #endif
286
287 /* RFC4584 Extension to Sockets API for Mobile IPv6 */
288
289 #ifndef ND_OPT_ADV_INTERVAL
290 #define ND_OPT_ADV_INTERVAL 7 /* Adv Interval Option */
291 #endif
292 #ifndef ND_OPT_HA_INFORMATION
293 #define ND_OPT_HA_INFORMATION 8 /* HA Information Option */
294 #endif
295
296
297 #ifndef HAVE_STRUCT_ND_OPT_ADV_INTERVAL
298 struct nd_opt_adv_interval { /* Advertisement interval option */
299 uint8_t nd_opt_ai_type;
300 uint8_t nd_opt_ai_len;
301 uint16_t nd_opt_ai_reserved;
302 uint32_t nd_opt_ai_interval;
303 } __attribute__((__packed__));
304 #else
305 #ifndef HAVE_STRUCT_ND_OPT_ADV_INTERVAL_ND_OPT_AI_TYPE
306 /* fields may have to be renamed */
307 #define nd_opt_ai_type nd_opt_adv_interval_type
308 #define nd_opt_ai_len nd_opt_adv_interval_len
309 #define nd_opt_ai_reserved nd_opt_adv_interval_reserved
310 #define nd_opt_ai_interval nd_opt_adv_interval_ival
311 #endif
312 #endif
313 #ifndef ND_OPT_RTR_ADV_INTERVAL
314 #define ND_OPT_RTR_ADV_INTERVAL 7
315 #endif
316 #ifndef ND_OPT_HOME_AGENT_INFO
317 #define ND_OPT_HOME_AGENT_INFO 8
318 #endif
319
320 #ifndef HAVE_STRUCT_ND_OPT_HOMEAGENT_INFO
321 struct nd_opt_homeagent_info { /* Home Agent info */
322 uint8_t nd_opt_hai_type;
323 uint8_t nd_opt_hai_len;
324 uint16_t nd_opt_hai_reserved;
325 uint16_t nd_opt_hai_preference;
326 uint16_t nd_opt_hai_lifetime;
327 } __attribute__((__packed__));
328 #endif
329
330 #ifndef ND_OPT_RDNSS
331 #define ND_OPT_RDNSS 25
332 #endif
333 #ifndef ND_OPT_DNSSL
334 #define ND_OPT_DNSSL 31
335 #endif
336
337 #ifndef HAVE_STRUCT_ND_OPT_RDNSS
338 struct nd_opt_rdnss { /* Recursive DNS server option [RFC8106 5.1] */
339 uint8_t nd_opt_rdnss_type;
340 uint8_t nd_opt_rdnss_len;
341 uint16_t nd_opt_rdnss_reserved;
342 uint32_t nd_opt_rdnss_lifetime;
343 /* Followed by one or more IPv6 addresses */
344 } __attribute__((__packed__));
345 #endif
346
347 #ifndef HAVE_STRUCT_ND_OPT_DNSSL
348 struct nd_opt_dnssl { /* DNS search list option [RFC8106 5.2] */
349 uint8_t nd_opt_dnssl_type;
350 uint8_t nd_opt_dnssl_len;
351 uint16_t nd_opt_dnssl_reserved;
352 uint32_t nd_opt_dnssl_lifetime;
353 /*
354 * Followed by one or more domain names encoded as in [RFC1035 3.1].
355 * Multiple domain names are concatenated after encoding. In any case,
356 * the result is zero-padded to a multiple of 8 octets.
357 */
358 } __attribute__((__packed__));
359 #endif
360
361 /*
362 * ipv6 nd prefixes can be manually defined, derived from the kernel interface
363 * configs or both. If both, manual flag/timer settings are used.
364 */
365 enum ipv6_nd_prefix_source {
366 PREFIX_SRC_NONE = 0,
367 PREFIX_SRC_MANUAL,
368 PREFIX_SRC_AUTO,
369 PREFIX_SRC_BOTH,
370 };
371
372 enum ipv6_nd_suppress_ra_status {
373 RA_ENABLE = 0,
374 RA_SUPPRESS,
375 };
376
377 extern void rtadv_vrf_init(struct zebra_vrf *zvrf);
378 extern void rtadv_vrf_terminate(struct zebra_vrf *zvrf);
379 extern void rtadv_stop_ra(struct interface *ifp);
380 extern void rtadv_stop_ra_all(void);
381 extern void rtadv_cmd_init(void);
382 extern void rtadv_if_init(struct zebra_if *zif);
383 extern void rtadv_if_up(struct zebra_if *zif);
384 extern void rtadv_if_fini(struct zebra_if *zif);
385 extern void rtadv_add_prefix(struct zebra_if *zif, const struct prefix_ipv6 *p);
386 extern void rtadv_delete_prefix(struct zebra_if *zif, const struct prefix *p);
387
388 #else /* !HAVE_RTADV */
389 struct rtadv {
390 /* empty structs aren't valid ISO C */
391 char dummy;
392 };
393
394 struct rtadvconf {
395 /* same again, empty structs aren't valid ISO C */
396 char dummy;
397 };
398
399 static inline void rtadv_vrf_init(struct zebra_vrf *zvrf)
400 {
401 }
402 static inline void rtadv_vrf_terminate(struct zebra_vrf *zvrf)
403 {
404 }
405 static inline void rtadv_cmd_init(void)
406 {
407 }
408 static inline void rtadv_if_init(struct zebra_if *zif)
409 {
410 }
411 static inline void rtadv_if_up(struct zebra_if *zif)
412 {
413 }
414 static inline void rtadv_if_fini(struct zebra_if *zif)
415 {
416 }
417 static inline void rtadv_add_prefix(struct zebra_if *zif,
418 const struct prefix_ipv6 *p)
419 {
420 }
421 static inline void rtadv_delete_prefix(struct zebra_if *zif,
422 const struct prefix *p)
423 {
424 }
425 static inline void rtadv_stop_ra(struct interface *ifp)
426 {
427 }
428 static inline void rtadv_stop_ra_all(void)
429 {
430 }
431 #endif
432
433 extern void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS);
434 extern void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS);
435
436 extern uint32_t rtadv_get_interfaces_configured_from_bgp(void);
437 extern bool rtadv_compiled_in(void);
438
439 #ifdef __cplusplus
440 }
441 #endif
442
443 #endif /* _ZEBRA_RTADV_H */