]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/sd-radv.c
Merge pull request #6830 from keszybz/generator-dirs
[thirdparty/systemd.git] / src / libsystemd-network / sd-radv.c
1 /***
2 This file is part of systemd.
3
4 Copyright (C) 2017 Intel Corporation. All rights reserved.
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <netinet/icmp6.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23 #include <linux/in6.h>
24
25 #include "sd-radv.h"
26
27 #include "macro.h"
28 #include "alloc-util.h"
29 #include "dns-domain.h"
30 #include "fd-util.h"
31 #include "icmp6-util.h"
32 #include "in-addr-util.h"
33 #include "radv-internal.h"
34 #include "socket-util.h"
35 #include "string-util.h"
36 #include "strv.h"
37 #include "util.h"
38 #include "random-util.h"
39
40 _public_ int sd_radv_new(sd_radv **ret) {
41 _cleanup_(sd_radv_unrefp) sd_radv *ra = NULL;
42
43 assert_return(ret, -EINVAL);
44
45 ra = new0(sd_radv, 1);
46 if (!ra)
47 return -ENOMEM;
48
49 ra->n_ref = 1;
50 ra->fd = -1;
51
52 LIST_HEAD_INIT(ra->prefixes);
53
54 *ret = ra;
55 ra = NULL;
56
57 return 0;
58 }
59
60 _public_ int sd_radv_attach_event(sd_radv *ra, sd_event *event, int64_t priority) {
61 int r;
62
63 assert_return(ra, -EINVAL);
64 assert_return(!ra->event, -EBUSY);
65
66 if (event)
67 ra->event = sd_event_ref(event);
68 else {
69 r = sd_event_default(&ra->event);
70 if (r < 0)
71 return 0;
72 }
73
74 ra->event_priority = priority;
75
76 return 0;
77 }
78
79 _public_ int sd_radv_detach_event(sd_radv *ra) {
80
81 assert_return(ra, -EINVAL);
82
83 ra->event = sd_event_unref(ra->event);
84 return 0;
85 }
86
87 _public_ sd_event *sd_radv_get_event(sd_radv *ra) {
88 assert_return(ra, NULL);
89
90 return ra->event;
91 }
92
93 static void radv_reset(sd_radv *ra) {
94
95 ra->timeout_event_source =
96 sd_event_source_unref(ra->timeout_event_source);
97
98 ra->recv_event_source =
99 sd_event_source_unref(ra->recv_event_source);
100
101 ra->ra_sent = 0;
102 }
103
104 _public_ sd_radv *sd_radv_ref(sd_radv *ra) {
105 if (!ra)
106 return NULL;
107
108 assert(ra->n_ref > 0);
109 ra->n_ref++;
110
111 return ra;
112 }
113
114 _public_ sd_radv *sd_radv_unref(sd_radv *ra) {
115 if (!ra)
116 return NULL;
117
118 assert(ra->n_ref > 0);
119 ra->n_ref--;
120
121 if (ra->n_ref > 0)
122 return NULL;
123
124 while (ra->prefixes) {
125 sd_radv_prefix *p = ra->prefixes;
126
127 LIST_REMOVE(prefix, ra->prefixes, p);
128 sd_radv_prefix_unref(p);
129 }
130
131 free(ra->rdnss);
132
133 radv_reset(ra);
134
135 sd_radv_detach_event(ra);
136 return mfree(ra);
137 }
138
139 static int radv_send(sd_radv *ra, const struct in6_addr *dst,
140 const uint32_t router_lifetime) {
141 static const struct ether_addr mac_zero = {};
142 sd_radv_prefix *p;
143 struct sockaddr_in6 dst_addr = {
144 .sin6_family = AF_INET6,
145 .sin6_addr = IN6ADDR_ALL_NODES_MULTICAST_INIT,
146 };
147 struct nd_router_advert adv = {};
148 struct {
149 struct nd_opt_hdr opthdr;
150 struct ether_addr slladdr;
151 } _packed_ opt_mac = {
152 .opthdr = {
153 .nd_opt_type = ND_OPT_SOURCE_LINKADDR,
154 .nd_opt_len = (sizeof(struct nd_opt_hdr) +
155 sizeof(struct ether_addr) - 1) /8 + 1,
156 },
157 };
158 struct nd_opt_mtu opt_mtu = {
159 .nd_opt_mtu_type = ND_OPT_MTU,
160 .nd_opt_mtu_len = 1,
161 };
162 /* Reserve iov space for RA header, linkaddr, MTU, N prefixes, RDNSS */
163 struct iovec iov[4 + ra->n_prefixes];
164 struct msghdr msg = {
165 .msg_name = &dst_addr,
166 .msg_namelen = sizeof(dst_addr),
167 .msg_iov = iov,
168 };
169
170 if (dst && !in_addr_is_null(AF_INET6, (union in_addr_union*) dst))
171 dst_addr.sin6_addr = *dst;
172
173 adv.nd_ra_type = ND_ROUTER_ADVERT;
174 adv.nd_ra_curhoplimit = ra->hop_limit;
175 adv.nd_ra_flags_reserved = ra->flags;
176 adv.nd_ra_router_lifetime = htobe16(router_lifetime);
177 iov[msg.msg_iovlen].iov_base = &adv;
178 iov[msg.msg_iovlen].iov_len = sizeof(adv);
179 msg.msg_iovlen++;
180
181 /* MAC address is optional, either because the link does not use L2
182 addresses or load sharing is desired. See RFC 4861, Section 4.2 */
183 if (memcmp(&mac_zero, &ra->mac_addr, sizeof(mac_zero))) {
184 opt_mac.slladdr = ra->mac_addr;
185 iov[msg.msg_iovlen].iov_base = &opt_mac;
186 iov[msg.msg_iovlen].iov_len = sizeof(opt_mac);
187 msg.msg_iovlen++;
188 }
189
190 if (ra->mtu) {
191 opt_mtu.nd_opt_mtu_mtu = htobe32(ra->mtu);
192 iov[msg.msg_iovlen].iov_base = &opt_mtu;
193 iov[msg.msg_iovlen].iov_len = sizeof(opt_mtu);
194 msg.msg_iovlen++;
195 }
196
197 LIST_FOREACH(prefix, p, ra->prefixes) {
198 iov[msg.msg_iovlen].iov_base = &p->opt;
199 iov[msg.msg_iovlen].iov_len = sizeof(p->opt);
200 msg.msg_iovlen++;
201 }
202
203 if (ra->rdnss) {
204 iov[msg.msg_iovlen].iov_base = ra->rdnss;
205 iov[msg.msg_iovlen].iov_len = ra->rdnss->length * 8;
206 msg.msg_iovlen++;
207 }
208
209 if (ra->dnssl) {
210 iov[msg.msg_iovlen].iov_base = ra->dnssl;
211 iov[msg.msg_iovlen].iov_len = ra->dnssl->length * 8;
212 msg.msg_iovlen++;
213 }
214
215 if (sendmsg(ra->fd, &msg, 0) < 0)
216 return -errno;
217
218 return 0;
219 }
220
221 static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
222 sd_radv *ra = userdata;
223 _cleanup_free_ char *addr = NULL;
224 struct in6_addr src;
225 triple_timestamp timestamp;
226 int r;
227 ssize_t buflen;
228 _cleanup_free_ char *buf = NULL;
229
230 assert(s);
231 assert(ra);
232 assert(ra->event);
233
234 buflen = next_datagram_size_fd(fd);
235
236 if ((unsigned) buflen < sizeof(struct nd_router_solicit))
237 return log_radv("Too short packet received");
238
239 buf = new0(char, buflen);
240 if (!buf)
241 return 0;
242
243 r = icmp6_receive(fd, buf, buflen, &src, &timestamp);
244 if (r < 0) {
245 switch (r) {
246 case -EADDRNOTAVAIL:
247 (void) in_addr_to_string(AF_INET6, (union in_addr_union*) &src, &addr);
248 log_radv("Received RS from non-link-local address %s. Ignoring", addr);
249 break;
250
251 case -EMULTIHOP:
252 log_radv("Received RS with invalid hop limit. Ignoring.");
253 break;
254
255 case -EPFNOSUPPORT:
256 log_radv("Received invalid source address from ICMPv6 socket. Ignoring.");
257 break;
258
259 default:
260 log_radv_warning_errno(r, "Error receiving from ICMPv6 socket: %m");
261 break;
262 }
263
264 return 0;
265 }
266
267 (void) in_addr_to_string(AF_INET6, (union in_addr_union*) &src, &addr);
268
269 r = radv_send(ra, &src, ra->lifetime);
270 if (r < 0)
271 log_radv_warning_errno(r, "Unable to send solicited Router Advertisment to %s: %m", addr);
272 else
273 log_radv("Sent solicited Router Advertisement to %s", addr);
274
275 return 0;
276 }
277
278 static usec_t radv_compute_timeout(usec_t min, usec_t max) {
279 assert_return(min <= max, SD_RADV_DEFAULT_MIN_TIMEOUT_USEC);
280
281 return min + (random_u32() % (max - min));
282 }
283
284 static int radv_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
285 int r;
286 sd_radv *ra = userdata;
287 usec_t min_timeout = SD_RADV_DEFAULT_MIN_TIMEOUT_USEC;
288 usec_t max_timeout = SD_RADV_DEFAULT_MAX_TIMEOUT_USEC;
289 usec_t time_now, timeout;
290 char time_string[FORMAT_TIMESPAN_MAX];
291
292 assert(s);
293 assert(ra);
294 assert(ra->event);
295
296 ra->timeout_event_source = sd_event_source_unref(ra->timeout_event_source);
297
298 r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now);
299 if (r < 0)
300 goto fail;
301
302 r = radv_send(ra, NULL, ra->lifetime);
303 if (r < 0)
304 log_radv_warning_errno(r, "Unable to send Router Advertisement: %m");
305
306 /* RFC 4861, Section 6.2.4, sending initial Router Advertisements */
307 if (ra->ra_sent < SD_RADV_MAX_INITIAL_RTR_ADVERTISEMENTS) {
308 max_timeout = SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC;
309 min_timeout = SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC / 3;
310 }
311
312 timeout = radv_compute_timeout(min_timeout, max_timeout);
313
314 log_radv("Next Router Advertisement in %s",
315 format_timespan(time_string, FORMAT_TIMESPAN_MAX,
316 timeout, USEC_PER_SEC));
317
318 r = sd_event_add_time(ra->event, &ra->timeout_event_source,
319 clock_boottime_or_monotonic(),
320 time_now + timeout, MSEC_PER_SEC,
321 radv_timeout, ra);
322 if (r < 0)
323 goto fail;
324
325 r = sd_event_source_set_priority(ra->timeout_event_source,
326 ra->event_priority);
327 if (r < 0)
328 goto fail;
329
330 r = sd_event_source_set_description(ra->timeout_event_source,
331 "radv-timeout");
332 if (r < 0)
333 goto fail;
334
335 ra->ra_sent++;
336
337 fail:
338 if (r < 0)
339 sd_radv_stop(ra);
340
341 return 0;
342 }
343
344 _public_ int sd_radv_stop(sd_radv *ra) {
345 int r;
346
347 assert_return(ra, -EINVAL);
348
349 log_radv("Stopping IPv6 Router Advertisement daemon");
350
351 /* RFC 4861, Section 6.2.5, send at least one Router Advertisement
352 with zero lifetime */
353 r = radv_send(ra, NULL, 0);
354 if (r < 0)
355 log_radv_warning_errno(r, "Unable to send last Router Advertisement with router lifetime set to zero: %m");
356
357 radv_reset(ra);
358 ra->fd = safe_close(ra->fd);
359 ra->state = SD_RADV_STATE_IDLE;
360
361 return 0;
362 }
363
364 _public_ int sd_radv_start(sd_radv *ra) {
365 int r = 0;
366
367 assert_return(ra, -EINVAL);
368 assert_return(ra->event, -EINVAL);
369 assert_return(ra->ifindex > 0, -EINVAL);
370
371 if (ra->state != SD_RADV_STATE_IDLE)
372 return 0;
373
374 r = sd_event_add_time(ra->event, &ra->timeout_event_source,
375 clock_boottime_or_monotonic(), 0, 0,
376 radv_timeout, ra);
377 if (r < 0)
378 goto fail;
379
380 r = sd_event_source_set_priority(ra->timeout_event_source,
381 ra->event_priority);
382 if (r < 0)
383 goto fail;
384
385 (void) sd_event_source_set_description(ra->timeout_event_source,
386 "radv-timeout");
387
388 r = icmp6_bind_router_advertisement(ra->ifindex);
389 if (r < 0)
390 goto fail;
391
392 ra->fd = r;
393
394 r = sd_event_add_io(ra->event, &ra->recv_event_source, ra->fd, EPOLLIN, radv_recv, ra);
395 if (r < 0)
396 goto fail;
397
398 r = sd_event_source_set_priority(ra->recv_event_source, ra->event_priority);
399 if (r < 0)
400 goto fail;
401
402 (void) sd_event_source_set_description(ra->recv_event_source, "radv-receive-message");
403
404 ra->state = SD_RADV_STATE_ADVERTISING;
405
406 log_radv("Started IPv6 Router Advertisement daemon");
407
408 return 0;
409
410 fail:
411 radv_reset(ra);
412
413 return r;
414 }
415
416 _public_ int sd_radv_set_ifindex(sd_radv *ra, int ifindex) {
417 assert_return(ra, -EINVAL);
418 assert_return(ifindex >= -1, -EINVAL);
419
420 if (ra->state != SD_RADV_STATE_IDLE)
421 return -EBUSY;
422
423 ra->ifindex = ifindex;
424
425 return 0;
426 }
427
428 _public_ int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr) {
429 assert_return(ra, -EINVAL);
430
431 if (ra->state != SD_RADV_STATE_IDLE)
432 return -EBUSY;
433
434 if (mac_addr)
435 ra->mac_addr = *mac_addr;
436 else
437 zero(ra->mac_addr);
438
439 return 0;
440 }
441
442 _public_ int sd_radv_set_mtu(sd_radv *ra, uint32_t mtu) {
443 assert_return(ra, -EINVAL);
444 assert_return(mtu >= 1280, -EINVAL);
445
446 if (ra->state != SD_RADV_STATE_IDLE)
447 return -EBUSY;
448
449 ra->mtu = mtu;
450
451 return 0;
452 }
453
454 _public_ int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit) {
455 assert_return(ra, -EINVAL);
456
457 if (ra->state != SD_RADV_STATE_IDLE)
458 return -EBUSY;
459
460 ra->hop_limit = hop_limit;
461
462 return 0;
463 }
464
465 _public_ int sd_radv_set_router_lifetime(sd_radv *ra, uint32_t router_lifetime) {
466 assert_return(ra, -EINVAL);
467
468 if (ra->state != SD_RADV_STATE_IDLE)
469 return -EBUSY;
470
471 /* RFC 4191, Section 2.2, "...If the Router Lifetime is zero, the
472 preference value MUST be set to (00) by the sender..." */
473 if (router_lifetime == 0 &&
474 (ra->flags & (0x3 << 3)) != (SD_NDISC_PREFERENCE_MEDIUM << 3))
475 return -ETIME;
476
477 ra->lifetime = router_lifetime;
478
479 return 0;
480 }
481
482 _public_ int sd_radv_set_managed_information(sd_radv *ra, int managed) {
483 assert_return(ra, -EINVAL);
484
485 if (ra->state != SD_RADV_STATE_IDLE)
486 return -EBUSY;
487
488 SET_FLAG(ra->flags, ND_RA_FLAG_MANAGED, managed);
489
490 return 0;
491 }
492
493 _public_ int sd_radv_set_other_information(sd_radv *ra, int other) {
494 assert_return(ra, -EINVAL);
495
496 if (ra->state != SD_RADV_STATE_IDLE)
497 return -EBUSY;
498
499 SET_FLAG(ra->flags, ND_RA_FLAG_OTHER, other);
500
501 return 0;
502 }
503
504 _public_ int sd_radv_set_preference(sd_radv *ra, unsigned preference) {
505 int r = 0;
506
507 assert_return(ra, -EINVAL);
508 assert_return(IN_SET(preference,
509 SD_NDISC_PREFERENCE_LOW,
510 SD_NDISC_PREFERENCE_MEDIUM,
511 SD_NDISC_PREFERENCE_HIGH), -EINVAL);
512
513 ra->flags = (ra->flags & ~(0x3 << 3)) | (preference << 3);
514
515 return r;
516 }
517
518 _public_ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) {
519 sd_radv_prefix *cur;
520 _cleanup_free_ char *addr_p = NULL;
521
522 assert_return(ra, -EINVAL);
523
524 if (!p)
525 return -EINVAL;
526
527 LIST_FOREACH(prefix, cur, ra->prefixes) {
528 int r;
529
530 r = in_addr_prefix_intersect(AF_INET6,
531 (union in_addr_union*) &cur->opt.in6_addr,
532 cur->opt.prefixlen,
533 (union in_addr_union*) &p->opt.in6_addr,
534 p->opt.prefixlen);
535 if (r > 0) {
536 _cleanup_free_ char *addr_cur = NULL;
537
538 (void) in_addr_to_string(AF_INET6,
539 (union in_addr_union*) &cur->opt.in6_addr,
540 &addr_cur);
541 (void) in_addr_to_string(AF_INET6,
542 (union in_addr_union*) &p->opt.in6_addr,
543 &addr_p);
544
545 log_radv("IPv6 prefix %s/%u already configured, ignoring %s/%u",
546 addr_cur, cur->opt.prefixlen,
547 addr_p, p->opt.prefixlen);
548
549 return -EEXIST;
550 }
551 }
552
553 p = sd_radv_prefix_ref(p);
554
555 LIST_APPEND(prefix, ra->prefixes, p);
556
557 ra->n_prefixes++;
558
559 (void) in_addr_to_string(AF_INET6, (union in_addr_union*) &p->opt.in6_addr, &addr_p);
560 log_radv("Added prefix %s/%d", addr_p, p->opt.prefixlen);
561
562 return 0;
563 }
564
565 _public_ int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime,
566 const struct in6_addr *dns, size_t n_dns) {
567 _cleanup_free_ struct sd_radv_opt_dns *opt_rdnss = NULL;
568 size_t len;
569
570 assert_return(ra, -EINVAL);
571 assert_return(n_dns < 128, -EINVAL);
572
573 if (!dns || n_dns == 0) {
574 ra->rdnss = mfree(ra->rdnss);
575 ra->n_rdnss = 0;
576
577 return 0;
578 }
579
580 len = sizeof(struct sd_radv_opt_dns) + sizeof(struct in6_addr) * n_dns;
581
582 opt_rdnss = malloc0(len);
583 if (!opt_rdnss)
584 return -ENOMEM;
585
586 opt_rdnss->type = SD_RADV_OPT_RDNSS;
587 opt_rdnss->length = len / 8;
588 opt_rdnss->lifetime = htobe32(lifetime);
589
590 memcpy(opt_rdnss + 1, dns, n_dns * sizeof(struct in6_addr));
591
592 free(ra->rdnss);
593 ra->rdnss = opt_rdnss;
594 opt_rdnss = NULL;
595
596 ra->n_rdnss = n_dns;
597
598 return 0;
599 }
600
601 _public_ int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime,
602 char **search_list) {
603 _cleanup_free_ struct sd_radv_opt_dns *opt_dnssl = NULL;
604 size_t len = 0;
605 char **s;
606 uint8_t *p;
607
608 assert_return(ra, -EINVAL);
609
610 if (!search_list || *search_list == NULL) {
611 ra->dnssl = mfree(ra->dnssl);
612
613 return 0;
614 }
615
616 STRV_FOREACH(s, search_list)
617 len += strlen(*s) + 2;
618
619 len = (sizeof(struct sd_radv_opt_dns) + len + 7) & ~0x7;
620
621 opt_dnssl = malloc0(len);
622 if (!opt_dnssl)
623 return -ENOMEM;
624
625 opt_dnssl->type = SD_RADV_OPT_DNSSL;
626 opt_dnssl->length = len / 8;
627 opt_dnssl->lifetime = htobe32(lifetime);
628
629 p = (uint8_t *)(opt_dnssl + 1);
630 len -= sizeof(struct sd_radv_opt_dns);
631
632 STRV_FOREACH(s, search_list) {
633 int r;
634
635 r = dns_name_to_wire_format(*s, p, len, false);
636 if (r < 0)
637 return r;
638
639 if (len < (size_t)r)
640 return -ENOBUFS;
641
642 p += r;
643 len -= r;
644 }
645
646 free(ra->dnssl);
647 ra->dnssl = opt_dnssl;
648 opt_dnssl = NULL;
649
650 return 0;
651 }
652
653 _public_ int sd_radv_prefix_new(sd_radv_prefix **ret) {
654 _cleanup_(sd_radv_prefix_unrefp) sd_radv_prefix *p = NULL;
655
656 assert_return(ret, -EINVAL);
657
658 p = new0(sd_radv_prefix, 1);
659 if (!p)
660 return -ENOMEM;
661
662 p->n_ref = 1;
663
664 p->opt.type = ND_OPT_PREFIX_INFORMATION;
665 p->opt.length = (sizeof(p->opt) - 1) /8 + 1;
666
667 p->opt.prefixlen = 64;
668
669 /* RFC 4861, Section 6.2.1 */
670 SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_ONLINK, true);
671 SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_AUTO, true);
672 p->opt.preferred_lifetime = htobe32(604800);
673 p->opt.valid_lifetime = htobe32(2592000);
674
675 LIST_INIT(prefix, p);
676
677 *ret = p;
678 p = NULL;
679
680 return 0;
681 }
682
683 _public_ sd_radv_prefix *sd_radv_prefix_ref(sd_radv_prefix *p) {
684 if (!p)
685 return NULL;
686
687 assert(p->n_ref > 0);
688 p->n_ref++;
689
690 return p;
691 }
692
693 _public_ sd_radv_prefix *sd_radv_prefix_unref(sd_radv_prefix *p) {
694 if (!p)
695 return NULL;
696
697 assert(p->n_ref > 0);
698 p->n_ref--;
699
700 if (p->n_ref > 0)
701 return NULL;
702
703 return mfree(p);
704 }
705
706 _public_ int sd_radv_prefix_set_prefix(sd_radv_prefix *p, struct in6_addr *in6_addr,
707 unsigned char prefixlen) {
708 assert_return(p, -EINVAL);
709 assert_return(in6_addr, -EINVAL);
710
711 if (prefixlen < 3 || prefixlen > 128)
712 return -EINVAL;
713
714 if (prefixlen > 64)
715 /* unusual but allowed, log it */
716 log_radv("Unusual prefix length %d greater than 64", prefixlen);
717
718 p->opt.in6_addr = *in6_addr;
719 p->opt.prefixlen = prefixlen;
720
721 return 0;
722 }
723
724 _public_ int sd_radv_prefix_set_onlink(sd_radv_prefix *p, int onlink) {
725 assert_return(p, -EINVAL);
726
727 SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_ONLINK, onlink);
728
729 return 0;
730 }
731
732 _public_ int sd_radv_prefix_set_address_autoconfiguration(sd_radv_prefix *p,
733 int address_autoconfiguration) {
734 assert_return(p, -EINVAL);
735
736 SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_AUTO, address_autoconfiguration);
737
738 return 0;
739 }
740
741 _public_ int sd_radv_prefix_set_valid_lifetime(sd_radv_prefix *p,
742 uint32_t valid_lifetime) {
743 assert_return(p, -EINVAL);
744
745 p->opt.valid_lifetime = htobe32(valid_lifetime);
746
747 return 0;
748 }
749
750 _public_ int sd_radv_prefix_set_preferred_lifetime(sd_radv_prefix *p,
751 uint32_t preferred_lifetime) {
752 assert_return(p, -EINVAL);
753
754 p->opt.preferred_lifetime = htobe32(preferred_lifetime);
755
756 return 0;
757 }