]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-radv.c
network: rename settings about DHCPv6 Prefix Delegation
[thirdparty/systemd.git] / src / network / networkd-radv.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright © 2017 Intel Corporation. All rights reserved.
4 ***/
5
6 #include <netinet/icmp6.h>
7 #include <arpa/inet.h>
8
9 #include "dns-domain.h"
10 #include "networkd-address.h"
11 #include "networkd-manager.h"
12 #include "networkd-radv.h"
13 #include "parse-util.h"
14 #include "sd-radv.h"
15 #include "string-util.h"
16 #include "string-table.h"
17 #include "strv.h"
18
19 void prefix_free(Prefix *prefix) {
20 if (!prefix)
21 return;
22
23 if (prefix->network) {
24 LIST_REMOVE(prefixes, prefix->network->static_prefixes, prefix);
25 assert(prefix->network->n_static_prefixes > 0);
26 prefix->network->n_static_prefixes--;
27
28 if (prefix->section)
29 hashmap_remove(prefix->network->prefixes_by_section,
30 prefix->section);
31 }
32
33 network_config_section_free(prefix->section);
34 sd_radv_prefix_unref(prefix->radv_prefix);
35
36 free(prefix);
37 }
38
39 static int prefix_new(Prefix **ret) {
40 _cleanup_(prefix_freep) Prefix *prefix = NULL;
41
42 prefix = new0(Prefix, 1);
43 if (!prefix)
44 return -ENOMEM;
45
46 if (sd_radv_prefix_new(&prefix->radv_prefix) < 0)
47 return -ENOMEM;
48
49 *ret = TAKE_PTR(prefix);
50
51 return 0;
52 }
53
54 static int prefix_new_static(Network *network, const char *filename,
55 unsigned section_line, Prefix **ret) {
56 _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
57 _cleanup_(prefix_freep) Prefix *prefix = NULL;
58 int r;
59
60 assert(network);
61 assert(ret);
62 assert(!!filename == (section_line > 0));
63
64 if (filename) {
65 r = network_config_section_new(filename, section_line, &n);
66 if (r < 0)
67 return r;
68
69 if (section_line) {
70 prefix = hashmap_get(network->prefixes_by_section, n);
71 if (prefix) {
72 *ret = TAKE_PTR(prefix);
73
74 return 0;
75 }
76 }
77 }
78
79 r = prefix_new(&prefix);
80 if (r < 0)
81 return r;
82
83 prefix->network = network;
84 LIST_APPEND(prefixes, network->static_prefixes, prefix);
85 network->n_static_prefixes++;
86
87 if (filename) {
88 prefix->section = TAKE_PTR(n);
89
90 r = hashmap_ensure_allocated(&network->prefixes_by_section, &network_config_hash_ops);
91 if (r < 0)
92 return r;
93
94 r = hashmap_put(network->prefixes_by_section, prefix->section, prefix);
95 if (r < 0)
96 return r;
97 }
98
99 *ret = TAKE_PTR(prefix);
100
101 return 0;
102 }
103
104 static int route_prefix_new(RoutePrefix **ret) {
105 _cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL;
106
107 prefix = new0(RoutePrefix, 1);
108 if (!prefix)
109 return -ENOMEM;
110
111 if (sd_radv_route_prefix_new(&prefix->radv_route_prefix) < 0)
112 return -ENOMEM;
113
114 *ret = TAKE_PTR(prefix);
115
116 return 0;
117 }
118
119 void route_prefix_free(RoutePrefix *prefix) {
120 if (!prefix)
121 return;
122
123 if (prefix->network) {
124 LIST_REMOVE(route_prefixes, prefix->network->static_route_prefixes, prefix);
125 assert(prefix->network->n_static_route_prefixes > 0);
126 prefix->network->n_static_route_prefixes--;
127
128 if (prefix->section)
129 hashmap_remove(prefix->network->route_prefixes_by_section,
130 prefix->section);
131 }
132
133 network_config_section_free(prefix->section);
134 sd_radv_route_prefix_unref(prefix->radv_route_prefix);
135
136 free(prefix);
137 }
138
139 static int route_prefix_new_static(Network *network, const char *filename,
140 unsigned section_line, RoutePrefix **ret) {
141 _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
142 _cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL;
143 int r;
144
145 assert(network);
146 assert(ret);
147 assert(!!filename == (section_line > 0));
148
149 if (filename) {
150 r = network_config_section_new(filename, section_line, &n);
151 if (r < 0)
152 return r;
153
154 if (section_line) {
155 prefix = hashmap_get(network->route_prefixes_by_section, n);
156 if (prefix) {
157 *ret = TAKE_PTR(prefix);
158
159 return 0;
160 }
161 }
162 }
163
164 r = route_prefix_new(&prefix);
165 if (r < 0)
166 return r;
167
168 prefix->network = network;
169 LIST_APPEND(route_prefixes, network->static_route_prefixes, prefix);
170 network->n_static_route_prefixes++;
171
172 if (filename) {
173 prefix->section = TAKE_PTR(n);
174
175 r = hashmap_ensure_allocated(&network->route_prefixes_by_section, &network_config_hash_ops);
176 if (r < 0)
177 return r;
178
179 r = hashmap_put(network->route_prefixes_by_section, prefix->section, prefix);
180 if (r < 0)
181 return r;
182 }
183
184 *ret = TAKE_PTR(prefix);
185
186 return 0;
187 }
188
189 int config_parse_prefix(const char *unit,
190 const char *filename,
191 unsigned line,
192 const char *section,
193 unsigned section_line,
194 const char *lvalue,
195 int ltype,
196 const char *rvalue,
197 void *data,
198 void *userdata) {
199
200 Network *network = userdata;
201 _cleanup_(prefix_free_or_set_invalidp) Prefix *p = NULL;
202 uint8_t prefixlen = 64;
203 union in_addr_union in6addr;
204 int r;
205
206 assert(filename);
207 assert(section);
208 assert(lvalue);
209 assert(rvalue);
210 assert(data);
211
212 r = prefix_new_static(network, filename, section_line, &p);
213 if (r < 0)
214 return log_oom();
215
216 r = in_addr_prefix_from_string(rvalue, AF_INET6, &in6addr, &prefixlen);
217 if (r < 0) {
218 log_syntax(unit, LOG_WARNING, filename, line, r, "Prefix is invalid, ignoring assignment: %s", rvalue);
219 return 0;
220 }
221
222 r = sd_radv_prefix_set_prefix(p->radv_prefix, &in6addr.in6, prefixlen);
223 if (r < 0) {
224 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to set radv prefix, ignoring assignment: %s", rvalue);
225 return 0;
226 }
227
228 p = NULL;
229
230 return 0;
231 }
232
233 int config_parse_prefix_flags(const char *unit,
234 const char *filename,
235 unsigned line,
236 const char *section,
237 unsigned section_line,
238 const char *lvalue,
239 int ltype,
240 const char *rvalue,
241 void *data,
242 void *userdata) {
243 Network *network = userdata;
244 _cleanup_(prefix_free_or_set_invalidp) Prefix *p = NULL;
245 int r;
246
247 assert(filename);
248 assert(section);
249 assert(lvalue);
250 assert(rvalue);
251 assert(data);
252
253 r = prefix_new_static(network, filename, section_line, &p);
254 if (r < 0)
255 return log_oom();
256
257 r = parse_boolean(rvalue);
258 if (r < 0) {
259 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue);
260 return 0;
261 }
262
263 if (streq(lvalue, "OnLink"))
264 r = sd_radv_prefix_set_onlink(p->radv_prefix, r);
265 else if (streq(lvalue, "AddressAutoconfiguration"))
266 r = sd_radv_prefix_set_address_autoconfiguration(p->radv_prefix, r);
267 if (r < 0) {
268 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to set %s=, ignoring assignment: %m", lvalue);
269 return 0;
270 }
271
272 p = NULL;
273
274 return 0;
275 }
276
277 int config_parse_prefix_lifetime(const char *unit,
278 const char *filename,
279 unsigned line,
280 const char *section,
281 unsigned section_line,
282 const char *lvalue,
283 int ltype,
284 const char *rvalue,
285 void *data,
286 void *userdata) {
287 Network *network = userdata;
288 _cleanup_(prefix_free_or_set_invalidp) Prefix *p = NULL;
289 usec_t usec;
290 int r;
291
292 assert(filename);
293 assert(section);
294 assert(lvalue);
295 assert(rvalue);
296 assert(data);
297
298 r = prefix_new_static(network, filename, section_line, &p);
299 if (r < 0)
300 return log_oom();
301
302 r = parse_sec(rvalue, &usec);
303 if (r < 0) {
304 log_syntax(unit, LOG_WARNING, filename, line, r, "Lifetime is invalid, ignoring assignment: %s", rvalue);
305 return 0;
306 }
307
308 /* a value of 0xffffffff represents infinity */
309 if (streq(lvalue, "PreferredLifetimeSec"))
310 r = sd_radv_prefix_set_preferred_lifetime(p->radv_prefix,
311 DIV_ROUND_UP(usec, USEC_PER_SEC));
312 else if (streq(lvalue, "ValidLifetimeSec"))
313 r = sd_radv_prefix_set_valid_lifetime(p->radv_prefix,
314 DIV_ROUND_UP(usec, USEC_PER_SEC));
315 if (r < 0) {
316 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to set %s=, ignoring assignment: %m", lvalue);
317 return 0;
318 }
319
320 p = NULL;
321
322 return 0;
323 }
324
325 int config_parse_prefix_assign(
326 const char *unit,
327 const char *filename,
328 unsigned line,
329 const char *section,
330 unsigned section_line,
331 const char *lvalue,
332 int ltype,
333 const char *rvalue,
334 void *data,
335 void *userdata) {
336
337 Network *network = userdata;
338 _cleanup_(prefix_free_or_set_invalidp) Prefix *p = NULL;
339 int r;
340
341 assert(filename);
342 assert(section);
343 assert(lvalue);
344 assert(rvalue);
345 assert(data);
346
347 r = prefix_new_static(network, filename, section_line, &p);
348 if (r < 0)
349 return log_oom();
350
351 r = parse_boolean(rvalue);
352 if (r < 0) {
353 log_syntax(unit, LOG_WARNING, filename, line, r,
354 "Failed to parse %s=, ignoring assignment: %s",
355 lvalue, rvalue);
356 return 0;
357 }
358
359 p->assign = r;
360 p = NULL;
361
362 return 0;
363 }
364
365 int config_parse_route_prefix(const char *unit,
366 const char *filename,
367 unsigned line,
368 const char *section,
369 unsigned section_line,
370 const char *lvalue,
371 int ltype,
372 const char *rvalue,
373 void *data,
374 void *userdata) {
375
376 Network *network = userdata;
377 _cleanup_(route_prefix_free_or_set_invalidp) RoutePrefix *p = NULL;
378 uint8_t prefixlen = 64;
379 union in_addr_union in6addr;
380 int r;
381
382 assert(filename);
383 assert(section);
384 assert(lvalue);
385 assert(rvalue);
386 assert(data);
387
388 r = route_prefix_new_static(network, filename, section_line, &p);
389 if (r < 0)
390 return log_oom();
391
392 r = in_addr_prefix_from_string(rvalue, AF_INET6, &in6addr, &prefixlen);
393 if (r < 0) {
394 log_syntax(unit, LOG_WARNING, filename, line, r, "Route prefix is invalid, ignoring assignment: %s", rvalue);
395 return 0;
396 }
397
398 r = sd_radv_prefix_set_route_prefix(p->radv_route_prefix, &in6addr.in6, prefixlen);
399 if (r < 0) {
400 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to set route prefix, ignoring assignment: %m");
401 return 0;
402 }
403
404 p = NULL;
405
406 return 0;
407 }
408
409 int config_parse_route_prefix_lifetime(const char *unit,
410 const char *filename,
411 unsigned line,
412 const char *section,
413 unsigned section_line,
414 const char *lvalue,
415 int ltype,
416 const char *rvalue,
417 void *data,
418 void *userdata) {
419 Network *network = userdata;
420 _cleanup_(route_prefix_free_or_set_invalidp) RoutePrefix *p = NULL;
421 usec_t usec;
422 int r;
423
424 assert(filename);
425 assert(section);
426 assert(lvalue);
427 assert(rvalue);
428 assert(data);
429
430 r = route_prefix_new_static(network, filename, section_line, &p);
431 if (r < 0)
432 return log_oom();
433
434 r = parse_sec(rvalue, &usec);
435 if (r < 0) {
436 log_syntax(unit, LOG_WARNING, filename, line, r,
437 "Route lifetime is invalid, ignoring assignment: %s", rvalue);
438 return 0;
439 }
440
441 /* a value of 0xffffffff represents infinity */
442 r = sd_radv_route_prefix_set_lifetime(p->radv_route_prefix, DIV_ROUND_UP(usec, USEC_PER_SEC));
443 if (r < 0) {
444 log_syntax(unit, LOG_WARNING, filename, line, r,
445 "Failed to set route lifetime, ignoring assignment: %m");
446 return 0;
447 }
448
449 p = NULL;
450
451 return 0;
452 }
453
454 static int radv_get_ip6dns(Network *network, struct in6_addr **dns,
455 size_t *n_dns) {
456 _cleanup_free_ struct in6_addr *addresses = NULL;
457 size_t i, n_addresses = 0, n_allocated = 0;
458
459 assert(network);
460 assert(dns);
461 assert(n_dns);
462
463 for (i = 0; i < network->n_dns; i++) {
464 union in_addr_union *addr;
465
466 if (network->dns[i]->family != AF_INET6)
467 continue;
468
469 addr = &network->dns[i]->address;
470
471 if (in_addr_is_null(AF_INET6, addr) ||
472 in_addr_is_link_local(AF_INET6, addr) ||
473 in_addr_is_localhost(AF_INET6, addr))
474 continue;
475
476 if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1))
477 return -ENOMEM;
478
479 addresses[n_addresses++] = addr->in6;
480 }
481
482 if (addresses) {
483 *dns = TAKE_PTR(addresses);
484
485 *n_dns = n_addresses;
486 }
487
488 return n_addresses;
489 }
490
491 static int radv_set_dns(Link *link, Link *uplink) {
492 _cleanup_free_ struct in6_addr *dns = NULL;
493 usec_t lifetime_usec;
494 size_t n_dns;
495 int r;
496
497 if (!link->network->router_emit_dns)
498 return 0;
499
500 if (link->network->router_dns) {
501 struct in6_addr *p;
502
503 dns = new(struct in6_addr, link->network->n_router_dns);
504 if (!dns)
505 return -ENOMEM;
506
507 p = dns;
508 for (size_t i = 0; i < link->network->n_router_dns; i++)
509 if (IN6_IS_ADDR_UNSPECIFIED(&link->network->router_dns[i])) {
510 if (!IN6_IS_ADDR_UNSPECIFIED(&link->ipv6ll_address))
511 *(p++) = link->ipv6ll_address;
512 } else
513 *(p++) = link->network->router_dns[i];
514
515 n_dns = p - dns;
516 lifetime_usec = link->network->router_dns_lifetime_usec;
517
518 goto set_dns;
519 }
520
521 lifetime_usec = SD_RADV_DEFAULT_DNS_LIFETIME_USEC;
522
523 r = radv_get_ip6dns(link->network, &dns, &n_dns);
524 if (r > 0)
525 goto set_dns;
526
527 if (uplink) {
528 if (!uplink->network) {
529 log_link_debug(uplink, "Cannot fetch DNS servers as uplink interface is not managed by us");
530 return 0;
531 }
532
533 r = radv_get_ip6dns(uplink->network, &dns, &n_dns);
534 if (r > 0)
535 goto set_dns;
536 }
537
538 return 0;
539
540 set_dns:
541 return sd_radv_set_rdnss(link->radv,
542 DIV_ROUND_UP(lifetime_usec, USEC_PER_SEC),
543 dns, n_dns);
544 }
545
546 static int radv_set_domains(Link *link, Link *uplink) {
547 OrderedSet *search_domains;
548 usec_t lifetime_usec;
549 _cleanup_free_ char **s = NULL; /* just free() because the strings are owned by the set */
550
551 if (!link->network->router_emit_domains)
552 return 0;
553
554 search_domains = link->network->router_search_domains;
555 lifetime_usec = link->network->router_dns_lifetime_usec;
556
557 if (search_domains)
558 goto set_domains;
559
560 lifetime_usec = SD_RADV_DEFAULT_DNS_LIFETIME_USEC;
561
562 search_domains = link->network->search_domains;
563 if (search_domains)
564 goto set_domains;
565
566 if (uplink) {
567 if (!uplink->network) {
568 log_link_debug(uplink, "Cannot fetch DNS search domains as uplink interface is not managed by us");
569 return 0;
570 }
571
572 search_domains = uplink->network->search_domains;
573 if (search_domains)
574 goto set_domains;
575 }
576
577 return 0;
578
579 set_domains:
580 s = ordered_set_get_strv(search_domains);
581 if (!s)
582 return log_oom();
583
584 return sd_radv_set_dnssl(link->radv,
585 DIV_ROUND_UP(lifetime_usec, USEC_PER_SEC),
586 s);
587
588 }
589
590 int radv_emit_dns(Link *link) {
591 Link *uplink;
592 int r;
593
594 uplink = manager_find_uplink(link->manager, link);
595
596 r = radv_set_dns(link, uplink);
597 if (r < 0)
598 log_link_warning_errno(link, r, "Could not set RA DNS: %m");
599
600 r = radv_set_domains(link, uplink);
601 if (r < 0)
602 log_link_warning_errno(link, r, "Could not set RA Domains: %m");
603
604 return 0;
605 }
606
607 int radv_configure(Link *link) {
608 RoutePrefix *q;
609 Prefix *p;
610 int r;
611
612 assert(link);
613 assert(link->network);
614
615 r = sd_radv_new(&link->radv);
616 if (r < 0)
617 return r;
618
619 r = sd_radv_attach_event(link->radv, NULL, 0);
620 if (r < 0)
621 return r;
622
623 r = sd_radv_set_mac(link->radv, &link->mac);
624 if (r < 0)
625 return r;
626
627 r = sd_radv_set_ifindex(link->radv, link->ifindex);
628 if (r < 0)
629 return r;
630
631 r = sd_radv_set_managed_information(link->radv, link->network->router_managed);
632 if (r < 0)
633 return r;
634
635 r = sd_radv_set_other_information(link->radv, link->network->router_other_information);
636 if (r < 0)
637 return r;
638
639 /* a value of 0xffffffff represents infinity, 0x0 means this host is
640 not a router */
641 r = sd_radv_set_router_lifetime(link->radv,
642 DIV_ROUND_UP(link->network->router_lifetime_usec, USEC_PER_SEC));
643 if (r < 0)
644 return r;
645
646 if (link->network->router_lifetime_usec > 0) {
647 r = sd_radv_set_preference(link->radv,
648 link->network->router_preference);
649 if (r < 0)
650 return r;
651 }
652
653 if (link->network->router_prefix_delegation & RADV_PREFIX_DELEGATION_STATIC) {
654 LIST_FOREACH(prefixes, p, link->network->static_prefixes) {
655 r = sd_radv_add_prefix(link->radv, p->radv_prefix, false);
656 if (r == -EEXIST)
657 continue;
658 if (r == -ENOEXEC) {
659 log_link_warning_errno(link, r, "[IPv6Prefix] section configured without Prefix= setting, ignoring section.");
660 continue;
661 }
662 if (r < 0)
663 return r;
664 }
665
666 LIST_FOREACH(route_prefixes, q, link->network->static_route_prefixes) {
667 r = sd_radv_add_route_prefix(link->radv, q->radv_route_prefix, false);
668 if (r == -EEXIST)
669 continue;
670 if (r < 0)
671 return r;
672 }
673 }
674
675 return 0;
676 }
677
678 int radv_add_prefix(Link *link, const struct in6_addr *prefix, uint8_t prefix_len,
679 uint32_t lifetime_preferred, uint32_t lifetime_valid) {
680 _cleanup_(sd_radv_prefix_unrefp) sd_radv_prefix *p = NULL;
681 int r;
682
683 assert(link);
684 assert(link->radv);
685
686 r = sd_radv_prefix_new(&p);
687 if (r < 0)
688 return r;
689
690 r = sd_radv_prefix_set_prefix(p, prefix, prefix_len);
691 if (r < 0)
692 return r;
693
694 r = sd_radv_prefix_set_preferred_lifetime(p, lifetime_preferred);
695 if (r < 0)
696 return r;
697
698 r = sd_radv_prefix_set_valid_lifetime(p, lifetime_valid);
699 if (r < 0)
700 return r;
701
702 r = sd_radv_add_prefix(link->radv, p, true);
703 if (r < 0 && r != -EEXIST)
704 return r;
705
706 return 0;
707 }
708
709 int config_parse_radv_dns(
710 const char *unit,
711 const char *filename,
712 unsigned line,
713 const char *section,
714 unsigned section_line,
715 const char *lvalue,
716 int ltype,
717 const char *rvalue,
718 void *data,
719 void *userdata) {
720
721 Network *n = data;
722 int r;
723
724 assert(filename);
725 assert(lvalue);
726 assert(rvalue);
727
728 for (const char *p = rvalue;;) {
729 _cleanup_free_ char *w = NULL;
730 union in_addr_union a;
731
732 r = extract_first_word(&p, &w, NULL, 0);
733 if (r == -ENOMEM)
734 return log_oom();
735 if (r < 0) {
736 log_syntax(unit, LOG_WARNING, filename, line, r,
737 "Failed to extract word, ignoring: %s", rvalue);
738 return 0;
739 }
740 if (r == 0)
741 return 0;
742
743 if (streq(w, "_link_local"))
744 a = IN_ADDR_NULL;
745 else {
746 r = in_addr_from_string(AF_INET6, w, &a);
747 if (r < 0) {
748 log_syntax(unit, LOG_WARNING, filename, line, r,
749 "Failed to parse DNS server address, ignoring: %s", w);
750 continue;
751 }
752
753 if (in_addr_is_null(AF_INET6, &a)) {
754 log_syntax(unit, LOG_WARNING, filename, line, 0,
755 "DNS server address is null, ignoring: %s", w);
756 continue;
757 }
758 }
759
760 struct in6_addr *m;
761 m = reallocarray(n->router_dns, n->n_router_dns + 1, sizeof(struct in6_addr));
762 if (!m)
763 return log_oom();
764
765 m[n->n_router_dns++] = a.in6;
766 n->router_dns = m;
767 }
768 }
769
770 int config_parse_radv_search_domains(
771 const char *unit,
772 const char *filename,
773 unsigned line,
774 const char *section,
775 unsigned section_line,
776 const char *lvalue,
777 int ltype,
778 const char *rvalue,
779 void *data,
780 void *userdata) {
781
782 Network *n = data;
783 int r;
784
785 assert(filename);
786 assert(lvalue);
787 assert(rvalue);
788
789 for (const char *p = rvalue;;) {
790 _cleanup_free_ char *w = NULL, *idna = NULL;
791
792 r = extract_first_word(&p, &w, NULL, 0);
793 if (r == -ENOMEM)
794 return log_oom();
795 if (r < 0) {
796 log_syntax(unit, LOG_WARNING, filename, line, r,
797 "Failed to extract word, ignoring: %s", rvalue);
798 return 0;
799 }
800 if (r == 0)
801 return 0;
802
803 r = dns_name_apply_idna(w, &idna);
804 if (r < 0) {
805 log_syntax(unit, LOG_WARNING, filename, line, r,
806 "Failed to apply IDNA to domain name '%s', ignoring: %m", w);
807 continue;
808 } else if (r == 0)
809 /* transfer ownership to simplify subsequent operations */
810 idna = TAKE_PTR(w);
811
812 r = ordered_set_ensure_allocated(&n->router_search_domains, &string_hash_ops);
813 if (r < 0)
814 return log_oom();
815
816 r = ordered_set_consume(n->router_search_domains, TAKE_PTR(idna));
817 if (r < 0)
818 return log_oom();
819 }
820 }
821
822 static const char * const radv_prefix_delegation_table[_RADV_PREFIX_DELEGATION_MAX] = {
823 [RADV_PREFIX_DELEGATION_NONE] = "no",
824 [RADV_PREFIX_DELEGATION_STATIC] = "static",
825 [RADV_PREFIX_DELEGATION_DHCP6] = "dhcpv6",
826 [RADV_PREFIX_DELEGATION_BOTH] = "yes",
827 };
828
829 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(
830 radv_prefix_delegation,
831 RADVPrefixDelegation,
832 RADV_PREFIX_DELEGATION_BOTH);
833
834 DEFINE_CONFIG_PARSE_ENUM(config_parse_router_prefix_delegation,
835 radv_prefix_delegation,
836 RADVPrefixDelegation,
837 "Invalid router prefix delegation");
838
839 int config_parse_router_preference(const char *unit,
840 const char *filename,
841 unsigned line,
842 const char *section,
843 unsigned section_line,
844 const char *lvalue,
845 int ltype,
846 const char *rvalue,
847 void *data,
848 void *userdata) {
849 Network *network = userdata;
850
851 assert(filename);
852 assert(section);
853 assert(lvalue);
854 assert(rvalue);
855 assert(data);
856
857 if (streq(rvalue, "high"))
858 network->router_preference = SD_NDISC_PREFERENCE_HIGH;
859 else if (STR_IN_SET(rvalue, "medium", "normal", "default"))
860 network->router_preference = SD_NDISC_PREFERENCE_MEDIUM;
861 else if (streq(rvalue, "low"))
862 network->router_preference = SD_NDISC_PREFERENCE_LOW;
863 else
864 log_syntax(unit, LOG_WARNING, filename, line, 0,
865 "Invalid router preference, ignoring assignment: %s", rvalue);
866
867 return 0;
868 }