]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
04473969 | 2 | /*** |
810adae9 | 3 | Copyright © 2017 Intel Corporation. All rights reserved. |
04473969 PF |
4 | ***/ |
5 | ||
6 | #include <netinet/icmp6.h> | |
7 | #include <netinet/in.h> | |
204f99d2 | 8 | #include <arpa/inet.h> |
04473969 PF |
9 | |
10 | #include "sd-radv.h" | |
11 | ||
12 | #include "alloc-util.h" | |
e965d6ab | 13 | #include "dns-domain.h" |
ae25915d | 14 | #include "ether-addr-util.h" |
807a8ede | 15 | #include "event-util.h" |
04473969 PF |
16 | #include "fd-util.h" |
17 | #include "icmp6-util.h" | |
18 | #include "in-addr-util.h" | |
5cfa2c3d LP |
19 | #include "io-util.h" |
20 | #include "macro.h" | |
0a970718 | 21 | #include "memory-util.h" |
61a9fa8f | 22 | #include "network-common.h" |
04473969 | 23 | #include "radv-internal.h" |
5cfa2c3d | 24 | #include "random-util.h" |
04473969 PF |
25 | #include "socket-util.h" |
26 | #include "string-util.h" | |
e965d6ab | 27 | #include "strv.h" |
04473969 | 28 | |
17347053 | 29 | int sd_radv_new(sd_radv **ret) { |
204f99d2 PF |
30 | _cleanup_(sd_radv_unrefp) sd_radv *ra = NULL; |
31 | ||
32 | assert_return(ret, -EINVAL); | |
33 | ||
78f9d24f | 34 | ra = new(sd_radv, 1); |
204f99d2 PF |
35 | if (!ra) |
36 | return -ENOMEM; | |
37 | ||
78f9d24f YW |
38 | *ra = (sd_radv) { |
39 | .n_ref = 1, | |
40 | .fd = -1, | |
72db0a71 | 41 | .lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC, |
78f9d24f | 42 | }; |
204f99d2 | 43 | |
1cc6c93a | 44 | *ret = TAKE_PTR(ra); |
204f99d2 PF |
45 | |
46 | return 0; | |
47 | } | |
48 | ||
17347053 | 49 | int sd_radv_attach_event(sd_radv *ra, sd_event *event, int64_t priority) { |
204f99d2 PF |
50 | int r; |
51 | ||
52 | assert_return(ra, -EINVAL); | |
53 | assert_return(!ra->event, -EBUSY); | |
54 | ||
55 | if (event) | |
56 | ra->event = sd_event_ref(event); | |
57 | else { | |
58 | r = sd_event_default(&ra->event); | |
59 | if (r < 0) | |
60 | return 0; | |
61 | } | |
62 | ||
63 | ra->event_priority = priority; | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
17347053 | 68 | int sd_radv_detach_event(sd_radv *ra) { |
204f99d2 PF |
69 | |
70 | assert_return(ra, -EINVAL); | |
71 | ||
72 | ra->event = sd_event_unref(ra->event); | |
73 | return 0; | |
74 | } | |
75 | ||
17347053 | 76 | sd_event *sd_radv_get_event(sd_radv *ra) { |
204f99d2 PF |
77 | assert_return(ra, NULL); |
78 | ||
79 | return ra->event; | |
80 | } | |
81 | ||
17347053 | 82 | int sd_radv_is_running(sd_radv *ra) { |
96fe813c YW |
83 | assert_return(ra, false); |
84 | ||
d6fc0d67 | 85 | return ra->state != RADV_STATE_IDLE; |
96fe813c YW |
86 | } |
87 | ||
204fb681 | 88 | static void radv_reset(sd_radv *ra) { |
c4b6dda0 | 89 | assert(ra); |
204fb681 | 90 | |
807a8ede | 91 | (void) event_source_disable(ra->timeout_event_source); |
204fb681 | 92 | |
eb2f7502 | 93 | ra->recv_event_source = sd_event_source_disable_unref(ra->recv_event_source); |
88d5a3db | 94 | |
204fb681 PF |
95 | ra->ra_sent = 0; |
96 | } | |
97 | ||
8301aa0b | 98 | static sd_radv *radv_free(sd_radv *ra) { |
e866e17b LP |
99 | if (!ra) |
100 | return NULL; | |
204f99d2 PF |
101 | |
102 | while (ra->prefixes) { | |
103 | sd_radv_prefix *p = ra->prefixes; | |
104 | ||
105 | LIST_REMOVE(prefix, ra->prefixes, p); | |
106 | sd_radv_prefix_unref(p); | |
107 | } | |
108 | ||
69d7eba1 YW |
109 | while (ra->route_prefixes) { |
110 | sd_radv_route_prefix *p = ra->route_prefixes; | |
111 | ||
112 | LIST_REMOVE(prefix, ra->route_prefixes, p); | |
113 | sd_radv_route_prefix_unref(p); | |
114 | } | |
115 | ||
e9c6da38 | 116 | free(ra->rdnss); |
f9aa5417 | 117 | free(ra->dnssl); |
e9c6da38 | 118 | |
204fb681 PF |
119 | radv_reset(ra); |
120 | ||
eb2f7502 | 121 | sd_event_source_unref(ra->timeout_event_source); |
204f99d2 | 122 | sd_radv_detach_event(ra); |
c4b6dda0 LP |
123 | |
124 | ra->fd = safe_close(ra->fd); | |
61a9fa8f | 125 | free(ra->ifname); |
c4b6dda0 | 126 | |
204f99d2 PF |
127 | return mfree(ra); |
128 | } | |
129 | ||
8301aa0b YW |
130 | DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv, sd_radv, radv_free); |
131 | ||
09457670 YW |
132 | static bool router_lifetime_is_valid(usec_t lifetime_usec) { |
133 | return lifetime_usec == 0 || | |
134 | (lifetime_usec >= RADV_MIN_ROUTER_LIFETIME_USEC && | |
135 | lifetime_usec <= RADV_MAX_ROUTER_LIFETIME_USEC); | |
136 | } | |
137 | ||
95e104e0 YW |
138 | static be32_t usec_to_be32_sec(usec_t usec) { |
139 | if (usec == USEC_INFINITY) | |
140 | /* UINT32_MAX is handled as infinity. */ | |
141 | return htobe32(UINT32_MAX); | |
142 | ||
143 | if (usec >= UINT32_MAX * USEC_PER_SEC) | |
144 | /* Finite but too large. Let's use the largest finite value. */ | |
145 | return htobe32(UINT32_MAX - 1); | |
146 | ||
147 | return htobe32(usec / USEC_PER_SEC); | |
148 | } | |
149 | ||
7003b114 | 150 | static int radv_send(sd_radv *ra, const struct in6_addr *dst, usec_t lifetime_usec) { |
203d4df5 | 151 | sd_radv_route_prefix *rt; |
77baf5ae PF |
152 | sd_radv_prefix *p; |
153 | struct sockaddr_in6 dst_addr = { | |
154 | .sin6_family = AF_INET6, | |
155 | .sin6_addr = IN6ADDR_ALL_NODES_MULTICAST_INIT, | |
156 | }; | |
157 | struct nd_router_advert adv = {}; | |
158 | struct { | |
159 | struct nd_opt_hdr opthdr; | |
160 | struct ether_addr slladdr; | |
161 | } _packed_ opt_mac = { | |
162 | .opthdr = { | |
163 | .nd_opt_type = ND_OPT_SOURCE_LINKADDR, | |
164 | .nd_opt_len = (sizeof(struct nd_opt_hdr) + | |
165 | sizeof(struct ether_addr) - 1) /8 + 1, | |
166 | }, | |
167 | }; | |
168 | struct nd_opt_mtu opt_mtu = { | |
169 | .nd_opt_mtu_type = ND_OPT_MTU, | |
170 | .nd_opt_mtu_len = 1, | |
171 | }; | |
203d4df5 | 172 | /* Reserve iov space for RA header, linkaddr, MTU, N prefixes, N routes, RDNSS |
6852c0f6 | 173 | and DNSSL */ |
203d4df5 | 174 | struct iovec iov[5 + ra->n_prefixes + ra->n_route_prefixes]; |
77baf5ae PF |
175 | struct msghdr msg = { |
176 | .msg_name = &dst_addr, | |
177 | .msg_namelen = sizeof(dst_addr), | |
178 | .msg_iov = iov, | |
179 | }; | |
d601b566 PF |
180 | usec_t time_now; |
181 | int r; | |
182 | ||
dc0ec5e2 | 183 | assert(ra); |
09457670 | 184 | assert(router_lifetime_is_valid(lifetime_usec)); |
dc0ec5e2 | 185 | |
d601b566 PF |
186 | r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now); |
187 | if (r < 0) | |
188 | return r; | |
77baf5ae | 189 | |
94876904 | 190 | if (dst && in6_addr_is_set(dst)) |
77baf5ae | 191 | dst_addr.sin6_addr = *dst; |
88d5a3db | 192 | |
77baf5ae PF |
193 | adv.nd_ra_type = ND_ROUTER_ADVERT; |
194 | adv.nd_ra_curhoplimit = ra->hop_limit; | |
195 | adv.nd_ra_flags_reserved = ra->flags; | |
09457670 YW |
196 | assert_cc(RADV_MAX_ROUTER_LIFETIME_USEC <= UINT16_MAX * USEC_PER_SEC); |
197 | adv.nd_ra_router_lifetime = htobe16(DIV_ROUND_UP(lifetime_usec, USEC_PER_SEC)); | |
5cfa2c3d | 198 | iov[msg.msg_iovlen++] = IOVEC_MAKE(&adv, sizeof(adv)); |
77baf5ae PF |
199 | |
200 | /* MAC address is optional, either because the link does not use L2 | |
201 | addresses or load sharing is desired. See RFC 4861, Section 4.2 */ | |
ae25915d | 202 | if (!ether_addr_is_null(&ra->mac_addr)) { |
77baf5ae | 203 | opt_mac.slladdr = ra->mac_addr; |
5cfa2c3d | 204 | iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mac, sizeof(opt_mac)); |
77baf5ae PF |
205 | } |
206 | ||
41521417 | 207 | if (ra->mtu > 0) { |
77baf5ae | 208 | opt_mtu.nd_opt_mtu_mtu = htobe32(ra->mtu); |
5cfa2c3d | 209 | iov[msg.msg_iovlen++] = IOVEC_MAKE(&opt_mtu, sizeof(opt_mtu)); |
77baf5ae PF |
210 | } |
211 | ||
212 | LIST_FOREACH(prefix, p, ra->prefixes) { | |
95e104e0 | 213 | usec_t lifetime_valid_usec, lifetime_preferred_usec; |
d601b566 | 214 | |
95e104e0 YW |
215 | lifetime_valid_usec = MIN(usec_sub_unsigned(p->valid_until, time_now), |
216 | p->lifetime_valid_usec); | |
217 | ||
218 | lifetime_preferred_usec = MIN3(usec_sub_unsigned(p->preferred_until, time_now), | |
219 | p->lifetime_preferred_usec, | |
220 | lifetime_valid_usec); | |
221 | ||
222 | p->opt.lifetime_valid = usec_to_be32_sec(lifetime_valid_usec); | |
223 | p->opt.lifetime_preferred = usec_to_be32_sec(lifetime_preferred_usec); | |
d601b566 | 224 | |
5cfa2c3d | 225 | iov[msg.msg_iovlen++] = IOVEC_MAKE(&p->opt, sizeof(p->opt)); |
77baf5ae PF |
226 | } |
227 | ||
95e104e0 YW |
228 | LIST_FOREACH(prefix, rt, ra->route_prefixes) { |
229 | rt->opt.lifetime = usec_to_be32_sec(MIN(usec_sub_unsigned(rt->valid_until, time_now), | |
230 | rt->lifetime_usec)); | |
231 | ||
203d4df5 | 232 | iov[msg.msg_iovlen++] = IOVEC_MAKE(&rt->opt, sizeof(rt->opt)); |
95e104e0 | 233 | } |
203d4df5 | 234 | |
5cfa2c3d LP |
235 | if (ra->rdnss) |
236 | iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->rdnss, ra->rdnss->length * 8); | |
e9c6da38 | 237 | |
5cfa2c3d LP |
238 | if (ra->dnssl) |
239 | iov[msg.msg_iovlen++] = IOVEC_MAKE(ra->dnssl, ra->dnssl->length * 8); | |
e965d6ab | 240 | |
77baf5ae PF |
241 | if (sendmsg(ra->fd, &msg, 0) < 0) |
242 | return -errno; | |
204fb681 | 243 | |
77baf5ae | 244 | return 0; |
204fb681 PF |
245 | } |
246 | ||
88d5a3db PF |
247 | static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdata) { |
248 | sd_radv *ra = userdata; | |
249 | _cleanup_free_ char *addr = NULL; | |
250 | struct in6_addr src; | |
251 | triple_timestamp timestamp; | |
252 | int r; | |
253 | ssize_t buflen; | |
254 | _cleanup_free_ char *buf = NULL; | |
255 | ||
256 | assert(s); | |
257 | assert(ra); | |
258 | assert(ra->event); | |
259 | ||
260 | buflen = next_datagram_size_fd(fd); | |
cfffddea LP |
261 | if (buflen < 0) |
262 | return (int) buflen; | |
88d5a3db PF |
263 | |
264 | buf = new0(char, buflen); | |
265 | if (!buf) | |
e55a6eae | 266 | return -ENOMEM; |
88d5a3db PF |
267 | |
268 | r = icmp6_receive(fd, buf, buflen, &src, ×tamp); | |
269 | if (r < 0) { | |
270 | switch (r) { | |
271 | case -EADDRNOTAVAIL: | |
c633628d | 272 | (void) in_addr_to_string(AF_INET6, (const union in_addr_union*) &src, &addr); |
35388783 | 273 | log_radv(ra, "Received RS from non-link-local address %s. Ignoring", addr); |
88d5a3db PF |
274 | break; |
275 | ||
276 | case -EMULTIHOP: | |
35388783 | 277 | log_radv(ra, "Received RS with invalid hop limit. Ignoring."); |
88d5a3db PF |
278 | break; |
279 | ||
280 | case -EPFNOSUPPORT: | |
35388783 | 281 | log_radv(ra, "Received invalid source address from ICMPv6 socket. Ignoring."); |
88d5a3db PF |
282 | break; |
283 | ||
8eb41f4c LP |
284 | case -EAGAIN: /* ignore spurious wakeups */ |
285 | break; | |
286 | ||
88d5a3db | 287 | default: |
35388783 | 288 | log_radv_errno(ra, r, "Unexpected error receiving from ICMPv6 socket, Ignoring: %m"); |
88d5a3db PF |
289 | break; |
290 | } | |
291 | ||
292 | return 0; | |
293 | } | |
294 | ||
cfffddea | 295 | if ((size_t) buflen < sizeof(struct nd_router_solicit)) { |
35388783 | 296 | log_radv(ra, "Too short packet received, ignoring"); |
cfffddea LP |
297 | return 0; |
298 | } | |
299 | ||
c633628d | 300 | (void) in_addr_to_string(AF_INET6, (const union in_addr_union*) &src, &addr); |
88d5a3db | 301 | |
7003b114 | 302 | r = radv_send(ra, &src, ra->lifetime_usec); |
88d5a3db | 303 | if (r < 0) |
35388783 | 304 | log_radv_errno(ra, r, "Unable to send solicited Router Advertisement to %s, ignoring: %m", strnull(addr)); |
88d5a3db | 305 | else |
35388783 | 306 | log_radv(ra, "Sent solicited Router Advertisement to %s", strnull(addr)); |
88d5a3db PF |
307 | |
308 | return 0; | |
309 | } | |
310 | ||
204fb681 | 311 | static int radv_timeout(sd_event_source *s, uint64_t usec, void *userdata) { |
7003b114 | 312 | usec_t min_timeout, max_timeout, time_now, timeout; |
204fb681 | 313 | sd_radv *ra = userdata; |
7003b114 | 314 | int r; |
204fb681 PF |
315 | |
316 | assert(s); | |
317 | assert(ra); | |
318 | assert(ra->event); | |
80477557 | 319 | assert(router_lifetime_is_valid(ra->lifetime_usec)); |
204fb681 | 320 | |
204fb681 PF |
321 | r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now); |
322 | if (r < 0) | |
323 | goto fail; | |
324 | ||
7003b114 | 325 | r = radv_send(ra, NULL, ra->lifetime_usec); |
204fb681 | 326 | if (r < 0) |
35388783 | 327 | log_radv_errno(ra, r, "Unable to send Router Advertisement: %m"); |
204fb681 PF |
328 | |
329 | /* RFC 4861, Section 6.2.4, sending initial Router Advertisements */ | |
80477557 | 330 | if (ra->ra_sent < RADV_MAX_INITIAL_RTR_ADVERTISEMENTS) |
d6fc0d67 | 331 | max_timeout = RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC; |
80477557 | 332 | else |
03ec10fd | 333 | max_timeout = RADV_DEFAULT_MAX_TIMEOUT_USEC; |
204fb681 | 334 | |
ef90b6a4 | 335 | /* RFC 4861, Section 6.2.1, lifetime must be at least MaxRtrAdvInterval, |
80477557 YW |
336 | * so lower the interval here */ |
337 | if (ra->lifetime_usec > 0) | |
338 | max_timeout = MIN(max_timeout, ra->lifetime_usec); | |
339 | ||
340 | if (max_timeout >= 9 * USEC_PER_SEC) | |
ef90b6a4 | 341 | min_timeout = max_timeout / 3; |
80477557 YW |
342 | else |
343 | min_timeout = max_timeout * 3 / 4; | |
ef90b6a4 | 344 | |
80477557 YW |
345 | /* RFC 4861, Section 6.2.1. |
346 | * MaxRtrAdvInterval MUST be no less than 4 seconds and no greater than 1800 seconds. | |
347 | * MinRtrAdvInterval MUST be no less than 3 seconds and no greater than .75 * MaxRtrAdvInterval. */ | |
348 | assert(max_timeout >= RADV_MIN_MAX_TIMEOUT_USEC); | |
349 | assert(max_timeout <= RADV_MAX_MAX_TIMEOUT_USEC); | |
350 | assert(min_timeout >= RADV_MIN_MIN_TIMEOUT_USEC); | |
351 | assert(min_timeout <= max_timeout * 3 / 4); | |
ef90b6a4 | 352 | |
80477557 | 353 | timeout = min_timeout + random_u64_range(max_timeout - min_timeout); |
5291f26d | 354 | log_radv(ra, "Next Router Advertisement in %s", FORMAT_TIMESPAN(timeout, USEC_PER_SEC)); |
204fb681 | 355 | |
807a8ede YW |
356 | r = event_reset_time(ra->event, &ra->timeout_event_source, |
357 | clock_boottime_or_monotonic(), | |
80477557 | 358 | usec_add(time_now, timeout), MSEC_PER_SEC, |
807a8ede YW |
359 | radv_timeout, ra, |
360 | ra->event_priority, "radv-timeout", true); | |
204fb681 PF |
361 | if (r < 0) |
362 | goto fail; | |
363 | ||
364 | ra->ra_sent++; | |
365 | ||
807a8ede YW |
366 | return 0; |
367 | ||
204fb681 | 368 | fail: |
290696e5 | 369 | sd_radv_stop(ra); |
204fb681 PF |
370 | |
371 | return 0; | |
372 | } | |
373 | ||
17347053 | 374 | int sd_radv_stop(sd_radv *ra) { |
204fb681 PF |
375 | int r; |
376 | ||
c8bae363 YW |
377 | if (!ra) |
378 | return 0; | |
204f99d2 | 379 | |
d6fc0d67 | 380 | if (ra->state == RADV_STATE_IDLE) |
6f8a8b84 SS |
381 | return 0; |
382 | ||
35388783 | 383 | log_radv(ra, "Stopping IPv6 Router Advertisement daemon"); |
204f99d2 | 384 | |
290696e5 YW |
385 | /* RFC 4861, Section 6.2.5, send at least one Router Advertisement |
386 | with zero lifetime */ | |
387 | r = radv_send(ra, NULL, 0); | |
388 | if (r < 0) | |
35388783 | 389 | log_radv_errno(ra, r, "Unable to send last Router Advertisement with router lifetime set to zero: %m"); |
204fb681 PF |
390 | |
391 | radv_reset(ra); | |
77baf5ae | 392 | ra->fd = safe_close(ra->fd); |
d6fc0d67 | 393 | ra->state = RADV_STATE_IDLE; |
204f99d2 PF |
394 | |
395 | return 0; | |
396 | } | |
397 | ||
17347053 | 398 | int sd_radv_start(sd_radv *ra) { |
f474884c | 399 | int r; |
204fb681 | 400 | |
204f99d2 PF |
401 | assert_return(ra, -EINVAL); |
402 | assert_return(ra->event, -EINVAL); | |
403 | assert_return(ra->ifindex > 0, -EINVAL); | |
404 | ||
d6fc0d67 | 405 | if (ra->state != RADV_STATE_IDLE) |
204f99d2 PF |
406 | return 0; |
407 | ||
807a8ede YW |
408 | r = event_reset_time(ra->event, &ra->timeout_event_source, |
409 | clock_boottime_or_monotonic(), | |
410 | 0, 0, | |
411 | radv_timeout, ra, | |
412 | ra->event_priority, "radv-timeout", true); | |
204fb681 PF |
413 | if (r < 0) |
414 | goto fail; | |
415 | ||
77baf5ae PF |
416 | r = icmp6_bind_router_advertisement(ra->ifindex); |
417 | if (r < 0) | |
418 | goto fail; | |
419 | ||
420 | ra->fd = r; | |
88d5a3db PF |
421 | |
422 | r = sd_event_add_io(ra->event, &ra->recv_event_source, ra->fd, EPOLLIN, radv_recv, ra); | |
423 | if (r < 0) | |
424 | goto fail; | |
425 | ||
426 | r = sd_event_source_set_priority(ra->recv_event_source, ra->event_priority); | |
427 | if (r < 0) | |
428 | goto fail; | |
429 | ||
430 | (void) sd_event_source_set_description(ra->recv_event_source, "radv-receive-message"); | |
77baf5ae | 431 | |
d6fc0d67 | 432 | ra->state = RADV_STATE_ADVERTISING; |
204f99d2 | 433 | |
35388783 | 434 | log_radv(ra, "Started IPv6 Router Advertisement daemon"); |
204f99d2 PF |
435 | |
436 | return 0; | |
204fb681 PF |
437 | |
438 | fail: | |
439 | radv_reset(ra); | |
440 | ||
441 | return r; | |
204f99d2 PF |
442 | } |
443 | ||
17347053 | 444 | int sd_radv_set_ifindex(sd_radv *ra, int ifindex) { |
204f99d2 | 445 | assert_return(ra, -EINVAL); |
7fa69c0a | 446 | assert_return(ifindex > 0, -EINVAL); |
204f99d2 | 447 | |
d6fc0d67 | 448 | if (ra->state != RADV_STATE_IDLE) |
204f99d2 PF |
449 | return -EBUSY; |
450 | ||
451 | ra->ifindex = ifindex; | |
452 | ||
453 | return 0; | |
454 | } | |
455 | ||
61a9fa8f YW |
456 | int sd_radv_set_ifname(sd_radv *ra, const char *ifname) { |
457 | assert_return(ra, -EINVAL); | |
458 | assert_return(ifname, -EINVAL); | |
459 | ||
460 | if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE)) | |
461 | return -EINVAL; | |
462 | ||
463 | return free_and_strdup(&ra->ifname, ifname); | |
464 | } | |
465 | ||
5977b71f YW |
466 | int sd_radv_get_ifname(sd_radv *ra, const char **ret) { |
467 | int r; | |
468 | ||
469 | assert_return(ra, -EINVAL); | |
61a9fa8f | 470 | |
5977b71f YW |
471 | r = get_ifname(ra->ifindex, &ra->ifname); |
472 | if (r < 0) | |
473 | return r; | |
474 | ||
475 | if (ret) | |
476 | *ret = ra->ifname; | |
477 | ||
478 | return 0; | |
61a9fa8f YW |
479 | } |
480 | ||
17347053 | 481 | int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr) { |
204f99d2 PF |
482 | assert_return(ra, -EINVAL); |
483 | ||
d6fc0d67 | 484 | if (ra->state != RADV_STATE_IDLE) |
204f99d2 PF |
485 | return -EBUSY; |
486 | ||
487 | if (mac_addr) | |
488 | ra->mac_addr = *mac_addr; | |
489 | else | |
490 | zero(ra->mac_addr); | |
491 | ||
492 | return 0; | |
493 | } | |
494 | ||
17347053 | 495 | int sd_radv_set_mtu(sd_radv *ra, uint32_t mtu) { |
204f99d2 PF |
496 | assert_return(ra, -EINVAL); |
497 | assert_return(mtu >= 1280, -EINVAL); | |
498 | ||
204f99d2 PF |
499 | ra->mtu = mtu; |
500 | ||
501 | return 0; | |
502 | } | |
503 | ||
17347053 | 504 | int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit) { |
204f99d2 PF |
505 | assert_return(ra, -EINVAL); |
506 | ||
d6fc0d67 | 507 | if (ra->state != RADV_STATE_IDLE) |
204f99d2 PF |
508 | return -EBUSY; |
509 | ||
510 | ra->hop_limit = hop_limit; | |
511 | ||
512 | return 0; | |
513 | } | |
514 | ||
17347053 | 515 | int sd_radv_set_router_lifetime(sd_radv *ra, uint64_t lifetime_usec) { |
204f99d2 PF |
516 | assert_return(ra, -EINVAL); |
517 | ||
d6fc0d67 | 518 | if (ra->state != RADV_STATE_IDLE) |
204f99d2 PF |
519 | return -EBUSY; |
520 | ||
09457670 YW |
521 | if (!router_lifetime_is_valid(lifetime_usec)) |
522 | return -EINVAL; | |
523 | ||
ac138551 YW |
524 | /* RFC 4191, Section 2.2, "...If the Router Lifetime is zero, the preference value MUST be set |
525 | * to (00) by the sender..." */ | |
7003b114 | 526 | if (lifetime_usec == 0 && |
204f99d2 | 527 | (ra->flags & (0x3 << 3)) != (SD_NDISC_PREFERENCE_MEDIUM << 3)) |
09457670 | 528 | return -EINVAL; |
204f99d2 | 529 | |
7003b114 | 530 | ra->lifetime_usec = lifetime_usec; |
204f99d2 PF |
531 | |
532 | return 0; | |
533 | } | |
534 | ||
17347053 | 535 | int sd_radv_set_managed_information(sd_radv *ra, int managed) { |
204f99d2 PF |
536 | assert_return(ra, -EINVAL); |
537 | ||
d6fc0d67 | 538 | if (ra->state != RADV_STATE_IDLE) |
204f99d2 PF |
539 | return -EBUSY; |
540 | ||
541 | SET_FLAG(ra->flags, ND_RA_FLAG_MANAGED, managed); | |
542 | ||
543 | return 0; | |
544 | } | |
545 | ||
17347053 | 546 | int sd_radv_set_other_information(sd_radv *ra, int other) { |
204f99d2 PF |
547 | assert_return(ra, -EINVAL); |
548 | ||
d6fc0d67 | 549 | if (ra->state != RADV_STATE_IDLE) |
204f99d2 PF |
550 | return -EBUSY; |
551 | ||
552 | SET_FLAG(ra->flags, ND_RA_FLAG_OTHER, other); | |
553 | ||
554 | return 0; | |
555 | } | |
556 | ||
17347053 | 557 | int sd_radv_set_preference(sd_radv *ra, unsigned preference) { |
204f99d2 PF |
558 | assert_return(ra, -EINVAL); |
559 | assert_return(IN_SET(preference, | |
560 | SD_NDISC_PREFERENCE_LOW, | |
561 | SD_NDISC_PREFERENCE_MEDIUM, | |
562 | SD_NDISC_PREFERENCE_HIGH), -EINVAL); | |
563 | ||
dd1b1870 YW |
564 | /* RFC 4191, Section 2.2, "...If the Router Lifetime is zero, the preference value MUST be set |
565 | * to (00) by the sender..." */ | |
7003b114 | 566 | if (ra->lifetime_usec == 0 && preference != SD_NDISC_PREFERENCE_MEDIUM) |
dd1b1870 YW |
567 | return -EINVAL; |
568 | ||
204f99d2 PF |
569 | ra->flags = (ra->flags & ~(0x3 << 3)) | (preference << 3); |
570 | ||
dd1b1870 | 571 | return 0; |
204f99d2 PF |
572 | } |
573 | ||
17347053 | 574 | int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { |
95e104e0 | 575 | _cleanup_free_ char *addr_p = NULL; |
204f99d2 | 576 | sd_radv_prefix *cur; |
d601b566 | 577 | int r; |
204f99d2 PF |
578 | |
579 | assert_return(ra, -EINVAL); | |
acbb5500 | 580 | assert_return(p, -EINVAL); |
204f99d2 | 581 | |
59ea6e57 | 582 | /* Refuse prefixes that don't have a prefix set */ |
94876904 | 583 | if (in6_addr_is_null(&p->opt.in6_addr)) |
59ea6e57 LP |
584 | return -ENOEXEC; |
585 | ||
68cbac5b | 586 | (void) in6_addr_prefix_to_string(&p->opt.in6_addr, p->opt.prefixlen, &addr_p); |
5380707a | 587 | |
204f99d2 | 588 | LIST_FOREACH(prefix, cur, ra->prefixes) { |
204f99d2 PF |
589 | |
590 | r = in_addr_prefix_intersect(AF_INET6, | |
c633628d | 591 | (const union in_addr_union*) &cur->opt.in6_addr, |
204f99d2 | 592 | cur->opt.prefixlen, |
c633628d | 593 | (const union in_addr_union*) &p->opt.in6_addr, |
204f99d2 | 594 | p->opt.prefixlen); |
5380707a YW |
595 | if (r < 0) |
596 | return r; | |
597 | if (r == 0) | |
598 | continue; | |
204f99d2 | 599 | |
95e104e0 YW |
600 | if (cur->opt.prefixlen == p->opt.prefixlen) { |
601 | /* p and cur may be equivalent. First increment the counter. */ | |
602 | sd_radv_prefix_ref(p); | |
603 | ||
604 | /* Then, remove the old entry. */ | |
605 | LIST_REMOVE(prefix, ra->prefixes, cur); | |
606 | sd_radv_prefix_unref(cur); | |
607 | ||
608 | /* Finally, add the new entry. */ | |
609 | LIST_APPEND(prefix, ra->prefixes, p); | |
610 | ||
611 | log_radv(ra, "Updated/replaced IPv6 prefix %s (preferred: %s, valid: %s)", | |
612 | strna(addr_p), | |
613 | FORMAT_TIMESPAN(p->lifetime_preferred_usec, USEC_PER_SEC), | |
614 | FORMAT_TIMESPAN(p->lifetime_valid_usec, USEC_PER_SEC)); | |
615 | return 0; | |
616 | } | |
d601b566 | 617 | |
5380707a | 618 | _cleanup_free_ char *addr_cur = NULL; |
68cbac5b | 619 | (void) in6_addr_prefix_to_string(&cur->opt.in6_addr, cur->opt.prefixlen, &addr_cur); |
35388783 | 620 | return log_radv_errno(ra, SYNTHETIC_ERRNO(EEXIST), |
95e104e0 YW |
621 | "IPv6 prefix %s conflicts with %s, ignoring.", |
622 | strna(addr_p), strna(addr_cur)); | |
204f99d2 PF |
623 | } |
624 | ||
95e104e0 | 625 | sd_radv_prefix_ref(p); |
204f99d2 | 626 | LIST_APPEND(prefix, ra->prefixes, p); |
204f99d2 PF |
627 | ra->n_prefixes++; |
628 | ||
95e104e0 | 629 | if (ra->state == RADV_STATE_IDLE) { |
35388783 | 630 | log_radv(ra, "Added prefix %s", strna(addr_p)); |
d601b566 PF |
631 | return 0; |
632 | } | |
633 | ||
97efde65 MM |
634 | /* If RAs have already been sent, send an RA immediately to announce the newly-added prefix */ |
635 | if (ra->ra_sent > 0) { | |
7003b114 | 636 | r = radv_send(ra, NULL, ra->lifetime_usec); |
6333aa9d | 637 | if (r < 0) |
35388783 | 638 | log_radv_errno(ra, r, "Unable to send Router Advertisement for added prefix: %m"); |
6333aa9d | 639 | else |
35388783 | 640 | log_radv(ra, "Sent Router Advertisement for added prefix"); |
97efde65 MM |
641 | } |
642 | ||
204f99d2 PF |
643 | return 0; |
644 | } | |
645 | ||
17347053 | 646 | sd_radv_prefix *sd_radv_remove_prefix(sd_radv *ra, |
f5a5706a LP |
647 | const struct in6_addr *prefix, |
648 | unsigned char prefixlen) { | |
34c169c4 PF |
649 | sd_radv_prefix *cur, *next; |
650 | ||
651 | assert_return(ra, NULL); | |
652 | assert_return(prefix, NULL); | |
653 | ||
654 | LIST_FOREACH_SAFE(prefix, cur, next, ra->prefixes) { | |
655 | if (prefixlen != cur->opt.prefixlen) | |
656 | continue; | |
657 | ||
94876904 | 658 | if (!in6_addr_equal(prefix, &cur->opt.in6_addr)) |
34c169c4 PF |
659 | continue; |
660 | ||
661 | LIST_REMOVE(prefix, ra->prefixes, cur); | |
662 | ra->n_prefixes--; | |
62bbbedf | 663 | sd_radv_prefix_unref(cur); |
34c169c4 PF |
664 | |
665 | break; | |
666 | } | |
667 | ||
668 | return cur; | |
669 | } | |
670 | ||
17347053 | 671 | int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { |
68cbac5b | 672 | _cleanup_free_ char *addr_p = NULL; |
203d4df5 SS |
673 | sd_radv_route_prefix *cur; |
674 | int r; | |
675 | ||
676 | assert_return(ra, -EINVAL); | |
acbb5500 | 677 | assert_return(p, -EINVAL); |
203d4df5 | 678 | |
68cbac5b | 679 | (void) in6_addr_prefix_to_string(&p->opt.in6_addr, p->opt.prefixlen, &addr_p); |
203d4df5 SS |
680 | |
681 | LIST_FOREACH(prefix, cur, ra->route_prefixes) { | |
203d4df5 SS |
682 | |
683 | r = in_addr_prefix_intersect(AF_INET6, | |
c633628d | 684 | (const union in_addr_union*) &cur->opt.in6_addr, |
203d4df5 | 685 | cur->opt.prefixlen, |
c633628d | 686 | (const union in_addr_union*) &p->opt.in6_addr, |
203d4df5 SS |
687 | p->opt.prefixlen); |
688 | if (r < 0) | |
689 | return r; | |
690 | if (r == 0) | |
691 | continue; | |
692 | ||
95e104e0 YW |
693 | if (cur->opt.prefixlen == p->opt.prefixlen) { |
694 | /* p and cur may be equivalent. First increment the counter. */ | |
695 | sd_radv_route_prefix_ref(p); | |
696 | ||
697 | /* Then, remove the old entry. */ | |
698 | LIST_REMOVE(prefix, ra->route_prefixes, cur); | |
699 | sd_radv_route_prefix_unref(cur); | |
700 | ||
701 | /* Finally, add the new entry. */ | |
702 | LIST_APPEND(prefix, ra->route_prefixes, p); | |
703 | ||
704 | log_radv(ra, "Updated/replaced IPv6 route prefix %s (lifetime: %s)", | |
705 | strna(addr_p), | |
706 | FORMAT_TIMESPAN(p->lifetime_usec, USEC_PER_SEC)); | |
707 | return 0; | |
708 | } | |
203d4df5 | 709 | |
68cbac5b YW |
710 | _cleanup_free_ char *addr_cur = NULL; |
711 | (void) in6_addr_prefix_to_string(&cur->opt.in6_addr, cur->opt.prefixlen, &addr_cur); | |
35388783 | 712 | return log_radv_errno(ra, SYNTHETIC_ERRNO(EEXIST), |
95e104e0 YW |
713 | "IPv6 route prefix %s conflicts with %s, ignoring.", |
714 | strna(addr_p), strna(addr_cur)); | |
203d4df5 SS |
715 | } |
716 | ||
95e104e0 | 717 | sd_radv_route_prefix_ref(p); |
203d4df5 SS |
718 | LIST_APPEND(prefix, ra->route_prefixes, p); |
719 | ra->n_route_prefixes++; | |
720 | ||
95e104e0 YW |
721 | if (ra->state == RADV_STATE_IDLE) { |
722 | log_radv(ra, "Added route prefix %s", strna(addr_p)); | |
203d4df5 SS |
723 | return 0; |
724 | } | |
725 | ||
97efde65 MM |
726 | /* If RAs have already been sent, send an RA immediately to announce the newly-added route prefix */ |
727 | if (ra->ra_sent > 0) { | |
7003b114 | 728 | r = radv_send(ra, NULL, ra->lifetime_usec); |
6333aa9d | 729 | if (r < 0) |
35388783 | 730 | log_radv_errno(ra, r, "Unable to send Router Advertisement for added route prefix: %m"); |
6333aa9d | 731 | else |
35388783 | 732 | log_radv(ra, "Sent Router Advertisement for added route prefix"); |
97efde65 MM |
733 | } |
734 | ||
203d4df5 SS |
735 | return 0; |
736 | } | |
737 | ||
17347053 | 738 | int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime, |
e9c6da38 PF |
739 | const struct in6_addr *dns, size_t n_dns) { |
740 | _cleanup_free_ struct sd_radv_opt_dns *opt_rdnss = NULL; | |
741 | size_t len; | |
742 | ||
743 | assert_return(ra, -EINVAL); | |
744 | assert_return(n_dns < 128, -EINVAL); | |
745 | ||
746 | if (!dns || n_dns == 0) { | |
747 | ra->rdnss = mfree(ra->rdnss); | |
748 | ra->n_rdnss = 0; | |
749 | ||
750 | return 0; | |
751 | } | |
752 | ||
753 | len = sizeof(struct sd_radv_opt_dns) + sizeof(struct in6_addr) * n_dns; | |
754 | ||
755 | opt_rdnss = malloc0(len); | |
756 | if (!opt_rdnss) | |
757 | return -ENOMEM; | |
758 | ||
d6fc0d67 | 759 | opt_rdnss->type = RADV_OPT_RDNSS; |
e9c6da38 PF |
760 | opt_rdnss->length = len / 8; |
761 | opt_rdnss->lifetime = htobe32(lifetime); | |
762 | ||
763 | memcpy(opt_rdnss + 1, dns, n_dns * sizeof(struct in6_addr)); | |
764 | ||
1cc6c93a | 765 | free_and_replace(ra->rdnss, opt_rdnss); |
e9c6da38 PF |
766 | |
767 | ra->n_rdnss = n_dns; | |
768 | ||
769 | return 0; | |
770 | } | |
771 | ||
17347053 | 772 | int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime, |
e965d6ab PF |
773 | char **search_list) { |
774 | _cleanup_free_ struct sd_radv_opt_dns *opt_dnssl = NULL; | |
775 | size_t len = 0; | |
776 | char **s; | |
777 | uint8_t *p; | |
778 | ||
779 | assert_return(ra, -EINVAL); | |
780 | ||
97d7974b | 781 | if (strv_isempty(search_list)) { |
e965d6ab | 782 | ra->dnssl = mfree(ra->dnssl); |
e965d6ab PF |
783 | return 0; |
784 | } | |
785 | ||
786 | STRV_FOREACH(s, search_list) | |
787 | len += strlen(*s) + 2; | |
788 | ||
789 | len = (sizeof(struct sd_radv_opt_dns) + len + 7) & ~0x7; | |
790 | ||
791 | opt_dnssl = malloc0(len); | |
792 | if (!opt_dnssl) | |
793 | return -ENOMEM; | |
794 | ||
d6fc0d67 | 795 | opt_dnssl->type = RADV_OPT_DNSSL; |
e965d6ab PF |
796 | opt_dnssl->length = len / 8; |
797 | opt_dnssl->lifetime = htobe32(lifetime); | |
798 | ||
799 | p = (uint8_t *)(opt_dnssl + 1); | |
800 | len -= sizeof(struct sd_radv_opt_dns); | |
801 | ||
802 | STRV_FOREACH(s, search_list) { | |
803 | int r; | |
804 | ||
805 | r = dns_name_to_wire_format(*s, p, len, false); | |
806 | if (r < 0) | |
807 | return r; | |
808 | ||
809 | if (len < (size_t)r) | |
810 | return -ENOBUFS; | |
811 | ||
812 | p += r; | |
813 | len -= r; | |
814 | } | |
815 | ||
1cc6c93a | 816 | free_and_replace(ra->dnssl, opt_dnssl); |
e965d6ab PF |
817 | |
818 | return 0; | |
819 | } | |
820 | ||
17347053 | 821 | int sd_radv_prefix_new(sd_radv_prefix **ret) { |
d2c8eed2 | 822 | sd_radv_prefix *p; |
04473969 PF |
823 | |
824 | assert_return(ret, -EINVAL); | |
825 | ||
d2c8eed2 | 826 | p = new(sd_radv_prefix, 1); |
04473969 PF |
827 | if (!p) |
828 | return -ENOMEM; | |
829 | ||
d2c8eed2 LP |
830 | *p = (sd_radv_prefix) { |
831 | .n_ref = 1, | |
04473969 | 832 | |
d2c8eed2 LP |
833 | .opt.type = ND_OPT_PREFIX_INFORMATION, |
834 | .opt.length = (sizeof(p->opt) - 1)/8 + 1, | |
835 | .opt.prefixlen = 64, | |
04473969 | 836 | |
d2c8eed2 LP |
837 | /* RFC 4861, Section 6.2.1 */ |
838 | .opt.flags = ND_OPT_PI_FLAG_ONLINK|ND_OPT_PI_FLAG_AUTO, | |
204f99d2 | 839 | |
d951507d YW |
840 | .lifetime_valid_usec = RADV_DEFAULT_VALID_LIFETIME_USEC, |
841 | .lifetime_preferred_usec = RADV_DEFAULT_PREFERRED_LIFETIME_USEC, | |
95e104e0 YW |
842 | .valid_until = USEC_INFINITY, |
843 | .preferred_until = USEC_INFINITY, | |
d2c8eed2 | 844 | }; |
04473969 | 845 | |
d2c8eed2 | 846 | *ret = p; |
04473969 PF |
847 | return 0; |
848 | } | |
849 | ||
8301aa0b | 850 | DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_prefix, sd_radv_prefix, mfree); |
04473969 | 851 | |
17347053 | 852 | int sd_radv_prefix_set_prefix(sd_radv_prefix *p, const struct in6_addr *in6_addr, |
04473969 PF |
853 | unsigned char prefixlen) { |
854 | assert_return(p, -EINVAL); | |
855 | assert_return(in6_addr, -EINVAL); | |
856 | ||
857 | if (prefixlen < 3 || prefixlen > 128) | |
858 | return -EINVAL; | |
859 | ||
860 | if (prefixlen > 64) | |
861 | /* unusual but allowed, log it */ | |
35388783 | 862 | log_radv(NULL, "Unusual prefix length %d greater than 64", prefixlen); |
04473969 PF |
863 | |
864 | p->opt.in6_addr = *in6_addr; | |
865 | p->opt.prefixlen = prefixlen; | |
866 | ||
867 | return 0; | |
868 | } | |
869 | ||
17347053 | 870 | int sd_radv_prefix_get_prefix(sd_radv_prefix *p, struct in6_addr *ret_in6_addr, |
34332af2 SS |
871 | unsigned char *ret_prefixlen) { |
872 | assert_return(p, -EINVAL); | |
873 | assert_return(ret_in6_addr, -EINVAL); | |
874 | assert_return(ret_prefixlen, -EINVAL); | |
875 | ||
876 | *ret_in6_addr = p->opt.in6_addr; | |
877 | *ret_prefixlen = p->opt.prefixlen; | |
878 | ||
879 | return 0; | |
880 | } | |
881 | ||
17347053 | 882 | int sd_radv_prefix_set_onlink(sd_radv_prefix *p, int onlink) { |
04473969 PF |
883 | assert_return(p, -EINVAL); |
884 | ||
885 | SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_ONLINK, onlink); | |
886 | ||
887 | return 0; | |
888 | } | |
889 | ||
17347053 | 890 | int sd_radv_prefix_set_address_autoconfiguration(sd_radv_prefix *p, |
04473969 PF |
891 | int address_autoconfiguration) { |
892 | assert_return(p, -EINVAL); | |
893 | ||
894 | SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_AUTO, address_autoconfiguration); | |
895 | ||
896 | return 0; | |
897 | } | |
898 | ||
17347053 | 899 | int sd_radv_prefix_set_valid_lifetime(sd_radv_prefix *p, uint64_t lifetime_usec, uint64_t valid_until) { |
04473969 PF |
900 | assert_return(p, -EINVAL); |
901 | ||
95e104e0 YW |
902 | p->lifetime_valid_usec = lifetime_usec; |
903 | p->valid_until = valid_until; | |
04473969 PF |
904 | |
905 | return 0; | |
906 | } | |
907 | ||
17347053 | 908 | int sd_radv_prefix_set_preferred_lifetime(sd_radv_prefix *p, uint64_t lifetime_usec, uint64_t valid_until) { |
04473969 PF |
909 | assert_return(p, -EINVAL); |
910 | ||
95e104e0 YW |
911 | p->lifetime_preferred_usec = lifetime_usec; |
912 | p->preferred_until = valid_until; | |
04473969 PF |
913 | |
914 | return 0; | |
915 | } | |
203d4df5 | 916 | |
17347053 | 917 | int sd_radv_route_prefix_new(sd_radv_route_prefix **ret) { |
203d4df5 SS |
918 | sd_radv_route_prefix *p; |
919 | ||
920 | assert_return(ret, -EINVAL); | |
921 | ||
922 | p = new(sd_radv_route_prefix, 1); | |
923 | if (!p) | |
924 | return -ENOMEM; | |
925 | ||
926 | *p = (sd_radv_route_prefix) { | |
927 | .n_ref = 1, | |
928 | ||
d6fc0d67 | 929 | .opt.type = RADV_OPT_ROUTE_INFORMATION, |
203d4df5 SS |
930 | .opt.length = DIV_ROUND_UP(sizeof(p->opt), 8), |
931 | .opt.prefixlen = 64, | |
932 | ||
d951507d | 933 | .lifetime_usec = RADV_DEFAULT_VALID_LIFETIME_USEC, |
95e104e0 | 934 | .valid_until = USEC_INFINITY, |
203d4df5 SS |
935 | }; |
936 | ||
937 | *ret = p; | |
938 | return 0; | |
939 | } | |
940 | ||
941 | DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_route_prefix, sd_radv_route_prefix, mfree); | |
942 | ||
17347053 | 943 | int sd_radv_route_prefix_set_prefix(sd_radv_route_prefix *p, const struct in6_addr *in6_addr, |
203d4df5 SS |
944 | unsigned char prefixlen) { |
945 | assert_return(p, -EINVAL); | |
946 | assert_return(in6_addr, -EINVAL); | |
947 | ||
948 | if (prefixlen > 128) | |
949 | return -EINVAL; | |
950 | ||
951 | if (prefixlen > 64) | |
952 | /* unusual but allowed, log it */ | |
35388783 | 953 | log_radv(NULL, "Unusual prefix length %u greater than 64", prefixlen); |
203d4df5 SS |
954 | |
955 | p->opt.in6_addr = *in6_addr; | |
956 | p->opt.prefixlen = prefixlen; | |
957 | ||
958 | return 0; | |
959 | } | |
960 | ||
17347053 | 961 | int sd_radv_route_prefix_set_lifetime(sd_radv_route_prefix *p, uint64_t lifetime_usec, uint64_t valid_until) { |
203d4df5 SS |
962 | assert_return(p, -EINVAL); |
963 | ||
95e104e0 YW |
964 | p->lifetime_usec = lifetime_usec; |
965 | p->valid_until = valid_until; | |
203d4df5 SS |
966 | |
967 | return 0; | |
968 | } |