]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/radv-internal.h
nspawn, vmspawn, run0: add env var for turning off background tinting
[thirdparty/systemd.git] / src / libsystemd-network / radv-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 /***
5 Copyright © 2017 Intel Corporation. All rights reserved.
6 ***/
7
8 #include <netinet/icmp6.h>
9
10 #include "sd-radv.h"
11
12 #include "list.h"
13 #include "ndisc-option.h"
14 #include "network-common.h"
15 #include "sparse-endian.h"
16 #include "time-util.h"
17
18 /* RFC 4861 section 6.2.1.
19 * MaxRtrAdvInterval
20 * The maximum time allowed between sending unsolicited multicast Router Advertisements from the
21 * interface, in seconds. MUST be no less than 4 seconds and no greater than 1800 seconds.
22 * Default: 600 seconds */
23 #define RADV_MIN_MAX_TIMEOUT_USEC (4 * USEC_PER_SEC)
24 #define RADV_MAX_MAX_TIMEOUT_USEC (1800 * USEC_PER_SEC)
25 #define RADV_DEFAULT_MAX_TIMEOUT_USEC (600 * USEC_PER_SEC)
26 /* RFC 4861 section 6.2.1.
27 * MinRtrAdvInterval
28 * The minimum time allowed between sending unsolicited multicast Router Advertisements from the
29 * interface, in seconds. MUST be no less than 3 seconds and no greater than .75 * MaxRtrAdvInterval.
30 * Default: 0.33 * MaxRtrAdvInterval If MaxRtrAdvInterval >= 9 seconds; otherwise, the Default is
31 * MaxRtrAdvInterval (Note, this should be a typo. We use 0.75 * MaxRtrAdvInterval). */
32 #define RADV_MIN_MIN_TIMEOUT_USEC (3 * USEC_PER_SEC)
33 /* RFC 4861 section 6.2.4.
34 * AdvDefaultLifetime
35 * The value to be placed in the Router Lifetime field of Router Advertisements sent from the interface,
36 * in seconds. MUST be either zero or between MaxRtrAdvInterval and 9000 seconds. A value of zero
37 * indicates that the router is not to be used as a default router. These limits may be overridden by
38 * specific documents that describe how IPv6 operates over different link layers. For instance, in a
39 * point-to-point link the peers may have enough information about the number and status of devices at
40 * the other end so that advertisements are needed less frequently.
41 * Default: 3 * MaxRtrAdvInterval */
42 #define RADV_MIN_ROUTER_LIFETIME_USEC RADV_MIN_MAX_TIMEOUT_USEC
43 #define RADV_MAX_ROUTER_LIFETIME_USEC (9000 * USEC_PER_SEC)
44 #define RADV_DEFAULT_ROUTER_LIFETIME_USEC (3 * RADV_DEFAULT_MAX_TIMEOUT_USEC)
45 /* RFC 4861 section 4.2.
46 * Reachable Time and Retrans Timer
47 * 32-bit unsigned integer. The time, in milliseconds. */
48 #define RADV_MAX_UINT32_MSEC_USEC (UINT32_MAX * USEC_PER_MSEC)
49 #define RADV_MAX_REACHABLE_TIME_USEC RADV_MAX_UINT32_MSEC_USEC
50 #define RADV_MAX_RETRANSMIT_USEC RADV_MAX_UINT32_MSEC_USEC
51 /* draft-ietf-6man-slaac-renum-02 section 4.1.1.
52 * AdvPreferredLifetime: max(AdvDefaultLifetime, 3 * MaxRtrAdvInterval)
53 * AdvValidLifetime: 2 * AdvPreferredLifetime */
54 #define RADV_DEFAULT_PREFERRED_LIFETIME_USEC CONST_MAX(RADV_DEFAULT_ROUTER_LIFETIME_USEC, 3 * RADV_DEFAULT_MAX_TIMEOUT_USEC)
55 #define RADV_DEFAULT_VALID_LIFETIME_USEC (2 * RADV_DEFAULT_PREFERRED_LIFETIME_USEC)
56 /* RFC 4861 section 10.
57 * MAX_INITIAL_RTR_ADVERT_INTERVAL 16 seconds
58 * MAX_INITIAL_RTR_ADVERTISEMENTS 3 transmissions
59 * MAX_FINAL_RTR_ADVERTISEMENTS 3 transmissions
60 * MIN_DELAY_BETWEEN_RAS 3 seconds
61 * MAX_RA_DELAY_TIME .5 seconds */
62 #define RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC (16 * USEC_PER_SEC)
63 #define RADV_MAX_INITIAL_RTR_ADVERTISEMENTS 3
64 #define RADV_MAX_FINAL_RTR_ADVERTISEMENTS 3
65 #define RADV_MIN_DELAY_BETWEEN_RAS 3
66 #define RADV_MAX_RA_DELAY_TIME_USEC (500 * USEC_PER_MSEC)
67 /* From RFC 8781 section 4.1
68 * By default, the value of the Scaled Lifetime field SHOULD be set to the lesser of 3 x MaxRtrAdvInterval */
69 #define RADV_PREF64_DEFAULT_LIFETIME_USEC (3 * RADV_DEFAULT_MAX_TIMEOUT_USEC)
70
71 #define RADV_RDNSS_MAX_LIFETIME_USEC (UINT32_MAX * USEC_PER_SEC)
72 #define RADV_DNSSL_MAX_LIFETIME_USEC (UINT32_MAX * USEC_PER_SEC)
73 /* rfc6275 7.4 Neighbor Discovery Home Agent Lifetime.
74 * The default value is the same as the Router Lifetime.
75 * The maximum value corresponds to 18.2 hours. 0 MUST NOT be used. */
76 #define RADV_HOME_AGENT_MAX_LIFETIME_USEC (UINT16_MAX * USEC_PER_SEC)
77
78 #define RADV_OPT_ROUTE_INFORMATION 24
79 #define RADV_OPT_RDNSS 25
80 #define RADV_OPT_DNSSL 31
81 /* Pref64 option type (RFC8781, section 4) */
82 #define RADV_OPT_PREF64 38
83
84 typedef enum RAdvState {
85 RADV_STATE_IDLE = 0,
86 RADV_STATE_ADVERTISING = 1,
87 } RAdvState;
88
89 struct sd_radv_opt_dns {
90 uint8_t type;
91 uint8_t length;
92 uint16_t reserved;
93 be32_t lifetime;
94 } _packed_;
95
96 struct sd_radv {
97 unsigned n_ref;
98 RAdvState state;
99
100 int ifindex;
101 char *ifname;
102 struct in6_addr ipv6ll;
103
104 sd_event *event;
105 int event_priority;
106
107 struct ether_addr mac_addr;
108 uint8_t hop_limit;
109 uint8_t flags;
110 uint8_t preference;
111 uint32_t mtu;
112 usec_t reachable_usec;
113 usec_t retransmit_usec;
114 usec_t lifetime_usec; /* timespan */
115
116 int fd;
117 unsigned ra_sent;
118 sd_event_source *recv_event_source;
119 sd_event_source *timeout_event_source;
120
121 unsigned n_prefixes;
122 LIST_HEAD(sd_radv_prefix, prefixes);
123
124 unsigned n_route_prefixes;
125 LIST_HEAD(sd_radv_route_prefix, route_prefixes);
126
127 unsigned n_pref64_prefixes;
128 LIST_HEAD(sd_radv_pref64_prefix, pref64_prefixes);
129
130 size_t n_rdnss;
131 struct sd_radv_opt_dns *rdnss;
132 struct sd_radv_opt_dns *dnssl;
133
134 /* Mobile IPv6 extension: Home Agent Info. */
135 struct nd_opt_home_agent_info home_agent;
136 };
137
138 #define radv_prefix_opt__contents { \
139 uint8_t type; \
140 uint8_t length; \
141 uint8_t prefixlen; \
142 uint8_t flags; \
143 be32_t lifetime_valid; \
144 be32_t lifetime_preferred; \
145 uint32_t reserved; \
146 struct in6_addr in6_addr; \
147 }
148
149 struct radv_prefix_opt radv_prefix_opt__contents;
150
151 /* We need the opt substructure to be packed, because we use it in send(). But
152 * if we use _packed_, this means that the structure cannot be used directly in
153 * normal code in general, because the fields might not be properly aligned.
154 * But in this particular case, the structure is defined in a way that gives
155 * proper alignment, even without the explicit _packed_ attribute. To appease
156 * the compiler we use the "unpacked" structure, but we also verify that
157 * structure contains no holes, so offsets are the same when _packed_ is used.
158 */
159 struct radv_prefix_opt__packed radv_prefix_opt__contents _packed_;
160 assert_cc(sizeof(struct radv_prefix_opt) == sizeof(struct radv_prefix_opt__packed));
161
162 struct sd_radv_prefix {
163 unsigned n_ref;
164
165 struct radv_prefix_opt opt;
166
167 LIST_FIELDS(struct sd_radv_prefix, prefix);
168
169 /* These are timespans, NOT points in time. */
170 usec_t lifetime_valid_usec;
171 usec_t lifetime_preferred_usec;
172 /* These are points in time specified with clock_boottime_or_monotonic(), NOT timespans. */
173 usec_t valid_until;
174 usec_t preferred_until;
175 };
176
177 #define radv_route_prefix_opt__contents { \
178 uint8_t type; \
179 uint8_t length; \
180 uint8_t prefixlen; \
181 uint8_t flags_reserved; \
182 be32_t lifetime; \
183 struct in6_addr in6_addr; \
184 }
185
186 struct radv_route_prefix_opt radv_route_prefix_opt__contents;
187
188 struct radv_route_prefix_opt__packed radv_route_prefix_opt__contents _packed_;
189 assert_cc(sizeof(struct radv_route_prefix_opt) == sizeof(struct radv_route_prefix_opt__packed));
190
191 struct sd_radv_route_prefix {
192 unsigned n_ref;
193
194 struct radv_route_prefix_opt opt;
195
196 LIST_FIELDS(struct sd_radv_route_prefix, prefix);
197
198 /* This is a timespan, NOT a point in time. */
199 usec_t lifetime_usec;
200 /* This is a point in time specified with clock_boottime_or_monotonic(), NOT a timespan. */
201 usec_t valid_until;
202 };
203
204 struct sd_radv_pref64_prefix {
205 unsigned n_ref;
206
207 struct nd_opt_prefix64_info opt;
208
209 struct in6_addr in6_addr;
210 uint8_t prefixlen;
211
212 usec_t lifetime_usec;
213
214 LIST_FIELDS(struct sd_radv_pref64_prefix, prefix);
215 };
216
217 #define log_radv_errno(radv, error, fmt, ...) \
218 log_interface_prefix_full_errno( \
219 "RADV: ", \
220 sd_radv, radv, \
221 error, fmt, ##__VA_ARGS__)
222 #define log_radv(radv, fmt, ...) \
223 log_interface_prefix_full_errno_zerook( \
224 "RADV: ", \
225 sd_radv, radv, \
226 0, fmt, ##__VA_ARGS__)