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
14 #include "zebra/zserv.h"
23 #if defined(HAVE_RTADV)
25 PREDECL_SORTLIST_UNIQ(adv_if_list
);
26 /* Structure which hold status of router advertisement. */
30 struct adv_if_list_head adv_if
;
31 struct adv_if_list_head adv_msec_if
;
33 struct thread
*ra_read
;
34 struct thread
*ra_timer
;
37 PREDECL_RBTREE_UNIQ(rtadv_prefixes
);
39 /* Router advertisement parameter. From RFC4861, RFC6275 and RFC4191. */
41 /* A flag indicating whether or not the router sends periodic Router
42 Advertisements and responds to Router Solicitations.
44 int AdvSendAdvertisements
;
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].
51 Default: 600000 milliseconds */
52 int MaxRtrAdvInterval
;
53 #define RTADV_MAX_RTR_ADV_INTERVAL 600000
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.
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)
64 /* Unsolicited Router Advertisements' interval timer. */
67 /* The true/false value to be placed in the "Managed address
68 configuration" flag field in the Router Advertisement. See
73 struct timeval lastadvmanagedflag
;
76 /* The true/false value to be placed in the "Other stateful
77 configuration" flag field in the Router Advertisement. See
81 int AdvOtherConfigFlag
;
82 struct timeval lastadvotherconfigflag
;
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.
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).
97 uint32_t AdvReachableTime
;
98 #define RTADV_MAX_REACHABLE_TIME 3600000
99 struct timeval lastadvreachabletime
;
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).
107 struct timeval lastadvretranstimer
;
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).
114 Default: The value specified in the "Assigned Numbers" RFC
115 [ASSIGNED] that was in effect at the time of implementation. */
117 struct timeval lastadvcurhoplimit
;
119 #define RTADV_DEFAULT_HOPLIMIT 64 /* 64 hops */
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
127 Default: 3 * MaxRtrAdvInterval */
128 int AdvDefaultLifetime
;
129 #define RTADV_MAX_RTRLIFETIME 9000 /* 2.5 hours */
131 /* A list of prefixes to be placed in Prefix Information options in
132 Router Advertisement messages sent from the interface.
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];
140 /* The true/false value to be placed in the "Home agent"
141 flag field in the Router Advertisement. See [RFC6275 7.1].
144 int AdvHomeAgentFlag
;
145 #ifndef ND_RA_FLAG_HOME_AGENT
146 #define ND_RA_FLAG_HOME_AGENT 0x20
149 /* The value to be placed in Home Agent Information option if Home
152 int HomeAgentPreference
;
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
157 The value 0 has special meaning: use of AdvDefaultLifetime value.
160 int HomeAgentLifetime
;
161 #define RTADV_MAX_HALIFETIME 65520 /* 18.2 hours */
163 /* The true/false value to insert or not an Advertisement Interval
164 option. See [RFC 6275 7.3]
167 int AdvIntervalOption
;
169 /* The value to be placed in the Default Router Preference field of
170 a router advertisement. See [RFC 4191 2.1 & 2.2]
172 Default: 0 (medium) */
173 int DefaultPreference
;
174 #define RTADV_PREF_MEDIUM 0x0 /* Per RFC4191. */
177 * List of recursive DNS servers to include in the RDNSS option.
180 * Default: empty list; do not emit RDNSS option
182 struct list
*AdvRDNSSList
;
185 * List of DNS search domains to include in the DNSSL option.
188 * Default: empty list; do not emit DNSSL option
190 struct list
*AdvDNSSLList
;
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.
197 bool UseFastRexmit
; /* True if fast rexmits are enabled */
199 uint8_t inFastRexmit
; /* True if we're rexmits faster than usual */
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
210 #define RTADV_FAST_REXMIT_PERIOD 1 /* 1 sec */
211 #define RTADV_NUM_FAST_REXMITS 4 /* Fast Rexmit RA 4 times on certain events \
216 /* Address of recursive DNS server to advertise */
217 struct in6_addr addr
;
220 * Lifetime in seconds; all-ones means infinity, zero
225 /* If lifetime not set, use a default of 3*MaxRtrAdvInterval */
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.
233 #define RTADV_MAX_ENCODED_DOMAIN_NAME 255
236 /* Domain name without trailing root zone dot (NUL-terminated) */
237 char name
[RTADV_MAX_ENCODED_DOMAIN_NAME
- 1];
239 /* Name encoded as in [RFC1035 3.1] */
240 uint8_t encoded_name
[RTADV_MAX_ENCODED_DOMAIN_NAME
];
242 /* Actual length of encoded_name */
245 /* Lifetime as for RDNSS */
250 /* Router advertisement prefix. */
251 struct rtadv_prefix
{
252 struct rtadv_prefixes_item item
;
254 /* Prefix to be advertised. */
255 struct prefix_ipv6 prefix
;
257 /* The prefix was manually/automatically defined. */
260 /* The value to be placed in the Valid Lifetime in the Prefix */
261 uint32_t AdvValidLifetime
;
262 #define RTADV_VALID_LIFETIME 2592000
264 /* The value to be placed in the on-link flag */
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
272 /* The value to be placed in the Autonomous Flag. */
273 int AdvAutonomousFlag
;
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
282 /* RFC4861 minimum delay between RAs */
283 #ifndef MIN_DELAY_BETWEEN_RAS
284 #define MIN_DELAY_BETWEEN_RAS 3000
287 /* RFC4584 Extension to Sockets API for Mobile IPv6 */
289 #ifndef ND_OPT_ADV_INTERVAL
290 #define ND_OPT_ADV_INTERVAL 7 /* Adv Interval Option */
292 #ifndef ND_OPT_HA_INFORMATION
293 #define ND_OPT_HA_INFORMATION 8 /* HA Information Option */
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__
));
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
313 #ifndef ND_OPT_RTR_ADV_INTERVAL
314 #define ND_OPT_RTR_ADV_INTERVAL 7
316 #ifndef ND_OPT_HOME_AGENT_INFO
317 #define ND_OPT_HOME_AGENT_INFO 8
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__
));
331 #define ND_OPT_RDNSS 25
334 #define ND_OPT_DNSSL 31
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__
));
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
;
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.
358 } __attribute__((__packed__
));
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.
365 enum ipv6_nd_prefix_source
{
372 enum ipv6_nd_suppress_ra_status
{
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
);
388 #else /* !HAVE_RTADV */
390 /* empty structs aren't valid ISO C */
395 /* same again, empty structs aren't valid ISO C */
399 static inline void rtadv_vrf_init(struct zebra_vrf
*zvrf
)
402 static inline void rtadv_vrf_terminate(struct zebra_vrf
*zvrf
)
405 static inline void rtadv_cmd_init(void)
408 static inline void rtadv_if_init(struct zebra_if
*zif
)
411 static inline void rtadv_if_up(struct zebra_if
*zif
)
414 static inline void rtadv_if_fini(struct zebra_if
*zif
)
417 static inline void rtadv_add_prefix(struct zebra_if
*zif
,
418 const struct prefix_ipv6
*p
)
421 static inline void rtadv_delete_prefix(struct zebra_if
*zif
,
422 const struct prefix
*p
)
425 static inline void rtadv_stop_ra(struct interface
*ifp
)
428 static inline void rtadv_stop_ra_all(void)
433 extern void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS
);
434 extern void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS
);
436 extern uint32_t rtadv_get_interfaces_configured_from_bgp(void);
437 extern bool rtadv_compiled_in(void);
443 #endif /* _ZEBRA_RTADV_H */