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