1 /* Router advertisement
2 * Copyright (C) 2005 6WIND <jean-mickael.guerin@6wind.com>
3 * Copyright (C) 1999 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
22 #ifndef _ZEBRA_RTADV_H
23 #define _ZEBRA_RTADV_H
29 #include "zebra/zserv.h"
38 #if defined(HAVE_RTADV)
40 PREDECL_SORTLIST_UNIQ(adv_if_list
);
41 /* Structure which hold status of router advertisement. */
45 struct adv_if_list_head adv_if
;
46 struct adv_if_list_head adv_msec_if
;
48 struct thread
*ra_read
;
49 struct thread
*ra_timer
;
52 PREDECL_RBTREE_UNIQ(rtadv_prefixes
);
54 /* Router advertisement parameter. From RFC4861, RFC6275 and RFC4191. */
56 /* A flag indicating whether or not the router sends periodic Router
57 Advertisements and responds to Router Solicitations.
59 int AdvSendAdvertisements
;
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].
66 Default: 600000 milliseconds */
67 int MaxRtrAdvInterval
;
68 #define RTADV_MAX_RTR_ADV_INTERVAL 600000
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.
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)
79 /* Unsolicited Router Advertisements' interval timer. */
82 /* The true/false value to be placed in the "Managed address
83 configuration" flag field in the Router Advertisement. See
88 struct timeval lastadvmanagedflag
;
91 /* The true/false value to be placed in the "Other stateful
92 configuration" flag field in the Router Advertisement. See
96 int AdvOtherConfigFlag
;
97 struct timeval lastadvotherconfigflag
;
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.
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).
112 uint32_t AdvReachableTime
;
113 #define RTADV_MAX_REACHABLE_TIME 3600000
114 struct timeval lastadvreachabletime
;
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).
122 struct timeval lastadvretranstimer
;
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).
129 Default: The value specified in the "Assigned Numbers" RFC
130 [ASSIGNED] that was in effect at the time of implementation. */
132 struct timeval lastadvcurhoplimit
;
134 #define RTADV_DEFAULT_HOPLIMIT 64 /* 64 hops */
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
142 Default: 3 * MaxRtrAdvInterval */
143 int AdvDefaultLifetime
;
144 #define RTADV_MAX_RTRLIFETIME 9000 /* 2.5 hours */
146 /* A list of prefixes to be placed in Prefix Information options in
147 Router Advertisement messages sent from the interface.
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];
155 /* The true/false value to be placed in the "Home agent"
156 flag field in the Router Advertisement. See [RFC6275 7.1].
159 int AdvHomeAgentFlag
;
160 #ifndef ND_RA_FLAG_HOME_AGENT
161 #define ND_RA_FLAG_HOME_AGENT 0x20
164 /* The value to be placed in Home Agent Information option if Home
167 int HomeAgentPreference
;
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
172 The value 0 has special meaning: use of AdvDefaultLifetime value.
175 int HomeAgentLifetime
;
176 #define RTADV_MAX_HALIFETIME 65520 /* 18.2 hours */
178 /* The true/false value to insert or not an Advertisement Interval
179 option. See [RFC 6275 7.3]
182 int AdvIntervalOption
;
184 /* The value to be placed in the Default Router Preference field of
185 a router advertisement. See [RFC 4191 2.1 & 2.2]
187 Default: 0 (medium) */
188 int DefaultPreference
;
189 #define RTADV_PREF_MEDIUM 0x0 /* Per RFC4191. */
192 * List of recursive DNS servers to include in the RDNSS option.
195 * Default: empty list; do not emit RDNSS option
197 struct list
*AdvRDNSSList
;
200 * List of DNS search domains to include in the DNSSL option.
203 * Default: empty list; do not emit DNSSL option
205 struct list
*AdvDNSSLList
;
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.
212 bool UseFastRexmit
; /* True if fast rexmits are enabled */
214 uint8_t inFastRexmit
; /* True if we're rexmits faster than usual */
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
225 #define RTADV_FAST_REXMIT_PERIOD 1 /* 1 sec */
226 #define RTADV_NUM_FAST_REXMITS 4 /* Fast Rexmit RA 4 times on certain events \
231 /* Address of recursive DNS server to advertise */
232 struct in6_addr addr
;
235 * Lifetime in seconds; all-ones means infinity, zero
240 /* If lifetime not set, use a default of 3*MaxRtrAdvInterval */
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.
248 #define RTADV_MAX_ENCODED_DOMAIN_NAME 255
251 /* Domain name without trailing root zone dot (NUL-terminated) */
252 char name
[RTADV_MAX_ENCODED_DOMAIN_NAME
- 1];
254 /* Name encoded as in [RFC1035 3.1] */
255 uint8_t encoded_name
[RTADV_MAX_ENCODED_DOMAIN_NAME
];
257 /* Actual length of encoded_name */
260 /* Lifetime as for RDNSS */
265 /* Router advertisement prefix. */
266 struct rtadv_prefix
{
267 struct rtadv_prefixes_item item
;
269 /* Prefix to be advertised. */
270 struct prefix_ipv6 prefix
;
272 /* The prefix was manually/automatically defined. */
275 /* The value to be placed in the Valid Lifetime in the Prefix */
276 uint32_t AdvValidLifetime
;
277 #define RTADV_VALID_LIFETIME 2592000
279 /* The value to be placed in the on-link flag */
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
287 /* The value to be placed in the Autonomous Flag. */
288 int AdvAutonomousFlag
;
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
297 /* RFC4861 minimum delay between RAs */
298 #ifndef MIN_DELAY_BETWEEN_RAS
299 #define MIN_DELAY_BETWEEN_RAS 3000
302 /* RFC4584 Extension to Sockets API for Mobile IPv6 */
304 #ifndef ND_OPT_ADV_INTERVAL
305 #define ND_OPT_ADV_INTERVAL 7 /* Adv Interval Option */
307 #ifndef ND_OPT_HA_INFORMATION
308 #define ND_OPT_HA_INFORMATION 8 /* HA Information Option */
311 #ifndef HAVE_STRUCT_ND_OPT_ADV_INTERVAL
312 struct nd_opt_adv_interval
{ /* Advertisement interval option */
313 uint8_t nd_opt_ai_type
;
314 uint8_t nd_opt_ai_len
;
315 uint16_t nd_opt_ai_reserved
;
316 uint32_t nd_opt_ai_interval
;
317 } __attribute__((__packed__
));
319 #ifndef HAVE_STRUCT_ND_OPT_ADV_INTERVAL_ND_OPT_AI_TYPE
320 /* fields may have to be renamed */
321 #define nd_opt_ai_type nd_opt_adv_interval_type
322 #define nd_opt_ai_len nd_opt_adv_interval_len
323 #define nd_opt_ai_reserved nd_opt_adv_interval_reserved
324 #define nd_opt_ai_interval nd_opt_adv_interval_ival
328 #ifndef HAVE_STRUCT_ND_OPT_HOMEAGENT_INFO
329 struct nd_opt_homeagent_info
{ /* Home Agent info */
330 uint8_t nd_opt_hai_type
;
331 uint8_t nd_opt_hai_len
;
332 uint16_t nd_opt_hai_reserved
;
333 uint16_t nd_opt_hai_preference
;
334 uint16_t nd_opt_hai_lifetime
;
335 } __attribute__((__packed__
));
339 #define ND_OPT_RDNSS 25
342 #define ND_OPT_DNSSL 31
345 #ifndef HAVE_STRUCT_ND_OPT_RDNSS
346 struct nd_opt_rdnss
{ /* Recursive DNS server option [RFC8106 5.1] */
347 uint8_t nd_opt_rdnss_type
;
348 uint8_t nd_opt_rdnss_len
;
349 uint16_t nd_opt_rdnss_reserved
;
350 uint32_t nd_opt_rdnss_lifetime
;
351 /* Followed by one or more IPv6 addresses */
352 } __attribute__((__packed__
));
355 #ifndef HAVE_STRUCT_ND_OPT_DNSSL
356 struct nd_opt_dnssl
{ /* DNS search list option [RFC8106 5.2] */
357 uint8_t nd_opt_dnssl_type
;
358 uint8_t nd_opt_dnssl_len
;
359 uint16_t nd_opt_dnssl_reserved
;
360 uint32_t nd_opt_dnssl_lifetime
;
362 * Followed by one or more domain names encoded as in [RFC1035 3.1].
363 * Multiple domain names are concatenated after encoding. In any case,
364 * the result is zero-padded to a multiple of 8 octets.
366 } __attribute__((__packed__
));
370 * ipv6 nd prefixes can be manually defined, derived from the kernel interface
371 * configs or both. If both, manual flag/timer settings are used.
373 enum ipv6_nd_prefix_source
{
380 enum ipv6_nd_suppress_ra_status
{
385 extern void rtadv_vrf_init(struct zebra_vrf
*zvrf
);
386 extern void rtadv_vrf_terminate(struct zebra_vrf
*zvrf
);
387 extern void rtadv_stop_ra(struct interface
*ifp
);
388 extern void rtadv_stop_ra_all(void);
389 extern void rtadv_cmd_init(void);
390 extern void rtadv_if_init(struct zebra_if
*zif
);
391 extern void rtadv_if_up(struct zebra_if
*zif
);
392 extern void rtadv_if_fini(struct zebra_if
*zif
);
393 extern void rtadv_add_prefix(struct zebra_if
*zif
, const struct prefix_ipv6
*p
);
394 extern void rtadv_delete_prefix(struct zebra_if
*zif
, const struct prefix
*p
);
396 #else /* !HAVE_RTADV */
398 /* empty structs aren't valid ISO C */
403 /* same again, empty structs aren't valid ISO C */
407 static inline void rtadv_vrf_init(struct zebra_vrf
*zvrf
)
410 static inline void rtadv_vrf_terminate(struct zebra_vrf
*zvrf
)
413 static inline void rtadv_cmd_init(void)
416 static inline void rtadv_if_init(struct zebra_if
*zif
)
419 static inline void rtadv_if_up(struct zebra_if
*zif
)
422 static inline void rtadv_if_fini(struct zebra_if
*zif
)
425 static inline void rtadv_add_prefix(struct zebra_if
*zif
,
426 const struct prefix_ipv6
*p
)
429 static inline void rtadv_delete_prefix(struct zebra_if
*zif
,
430 const struct prefix
*p
)
433 static inline void rtadv_stop_ra(struct interface
*ifp
)
436 static inline void rtadv_stop_ra_all(void)
441 extern void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS
);
442 extern void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS
);
444 extern uint32_t rtadv_get_interfaces_configured_from_bgp(void);
445 extern bool rtadv_compiled_in(void);
451 #endif /* _ZEBRA_RTADV_H */