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