]> git.proxmox.com Git - mirror_frr.git/blob - zebra/rtadv.h
Merge pull request #11843 from ARShreenidhi/ecmp_testcase
[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 #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__));
318 #else
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
325 #endif
326 #endif
327
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__));
336 #endif
337
338 #ifndef ND_OPT_RDNSS
339 #define ND_OPT_RDNSS 25
340 #endif
341 #ifndef ND_OPT_DNSSL
342 #define ND_OPT_DNSSL 31
343 #endif
344
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__));
353 #endif
354
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;
361 /*
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.
365 */
366 } __attribute__((__packed__));
367 #endif
368
369 /*
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.
372 */
373 enum ipv6_nd_prefix_source {
374 PREFIX_SRC_NONE = 0,
375 PREFIX_SRC_MANUAL,
376 PREFIX_SRC_AUTO,
377 PREFIX_SRC_BOTH,
378 };
379
380 enum ipv6_nd_suppress_ra_status {
381 RA_ENABLE = 0,
382 RA_SUPPRESS,
383 };
384
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);
395
396 #else /* !HAVE_RTADV */
397 struct rtadv {
398 /* empty structs aren't valid ISO C */
399 char dummy;
400 };
401
402 struct rtadvconf {
403 /* same again, empty structs aren't valid ISO C */
404 char dummy;
405 };
406
407 static inline void rtadv_vrf_init(struct zebra_vrf *zvrf)
408 {
409 }
410 static inline void rtadv_vrf_terminate(struct zebra_vrf *zvrf)
411 {
412 }
413 static inline void rtadv_cmd_init(void)
414 {
415 }
416 static inline void rtadv_if_init(struct zebra_if *zif)
417 {
418 }
419 static inline void rtadv_if_up(struct zebra_if *zif)
420 {
421 }
422 static inline void rtadv_if_fini(struct zebra_if *zif)
423 {
424 }
425 static inline void rtadv_add_prefix(struct zebra_if *zif,
426 const struct prefix_ipv6 *p)
427 {
428 }
429 static inline void rtadv_delete_prefix(struct zebra_if *zif,
430 const struct prefix *p)
431 {
432 }
433 static inline void rtadv_stop_ra(struct interface *ifp)
434 {
435 }
436 static inline void rtadv_stop_ra_all(void)
437 {
438 }
439 #endif
440
441 extern void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS);
442 extern void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS);
443
444 extern uint32_t rtadv_get_interfaces_configured_from_bgp(void);
445 extern bool rtadv_compiled_in(void);
446
447 #ifdef __cplusplus
448 }
449 #endif
450
451 #endif /* _ZEBRA_RTADV_H */