1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
6 #include "conf-parser.h"
7 #include "firewall-util.h"
8 #include "memory-util.h"
9 #include "missing_network.h"
10 #include "netlink-util.h"
11 #include "networkd-address.h"
12 #include "networkd-manager.h"
13 #include "parse-util.h"
15 #include "socket-util.h"
16 #include "string-util.h"
20 #define ADDRESSES_PER_LINK_MAX 2048U
21 #define STATIC_ADDRESSES_PER_NETWORK_MAX 1024U
23 int address_new(Address
**ret
) {
24 _cleanup_(address_freep
) Address
*address
= NULL
;
26 address
= new(Address
, 1);
30 *address
= (Address
) {
32 .scope
= RT_SCOPE_UNIVERSE
,
33 .cinfo
.ifa_prefered
= CACHE_INFO_INFINITY_LIFE_TIME
,
34 .cinfo
.ifa_valid
= CACHE_INFO_INFINITY_LIFE_TIME
,
35 .duplicate_address_detection
= ADDRESS_FAMILY_IPV6
,
38 *ret
= TAKE_PTR(address
);
43 static int address_new_static(Network
*network
, const char *filename
, unsigned section_line
, Address
**ret
) {
44 _cleanup_(network_config_section_freep
) NetworkConfigSection
*n
= NULL
;
45 _cleanup_(address_freep
) Address
*address
= NULL
;
50 assert(!!filename
== (section_line
> 0));
53 r
= network_config_section_new(filename
, section_line
, &n
);
57 address
= hashmap_get(network
->addresses_by_section
, n
);
59 *ret
= TAKE_PTR(address
);
65 if (network
->n_static_addresses
>= STATIC_ADDRESSES_PER_NETWORK_MAX
)
68 r
= address_new(&address
);
72 address
->network
= network
;
73 LIST_APPEND(addresses
, network
->static_addresses
, address
);
74 network
->n_static_addresses
++;
77 address
->section
= TAKE_PTR(n
);
79 r
= hashmap_ensure_allocated(&network
->addresses_by_section
, &network_config_hash_ops
);
83 r
= hashmap_put(network
->addresses_by_section
, address
->section
, address
);
88 *ret
= TAKE_PTR(address
);
93 void address_free(Address
*address
) {
97 if (address
->network
) {
98 LIST_REMOVE(addresses
, address
->network
->static_addresses
, address
);
99 assert(address
->network
->n_static_addresses
> 0);
100 address
->network
->n_static_addresses
--;
102 if (address
->section
)
103 hashmap_remove(address
->network
->addresses_by_section
, address
->section
);
106 if (address
->link
&& !address
->acd
) {
107 set_remove(address
->link
->addresses
, address
);
108 set_remove(address
->link
->addresses_foreign
, address
);
110 if (in_addr_equal(AF_INET6
, &address
->in_addr
, (const union in_addr_union
*) &address
->link
->ipv6ll_address
))
111 memzero(&address
->link
->ipv6ll_address
, sizeof(struct in6_addr
));
114 sd_ipv4acd_unref(address
->acd
);
116 network_config_section_free(address
->section
);
117 free(address
->label
);
121 static uint32_t address_prefix(const Address
*a
) {
124 /* make sure we don't try to shift by 32.
125 * See ISO/IEC 9899:TC3 ยง 6.5.7.3. */
126 if (a
->prefixlen
== 0)
129 if (a
->in_addr_peer
.in
.s_addr
!= 0)
130 return be32toh(a
->in_addr_peer
.in
.s_addr
) >> (32 - a
->prefixlen
);
132 return be32toh(a
->in_addr
.in
.s_addr
) >> (32 - a
->prefixlen
);
135 static void address_hash_func(const Address
*a
, struct siphash
*state
) {
138 siphash24_compress(&a
->family
, sizeof(a
->family
), state
);
142 siphash24_compress(&a
->prefixlen
, sizeof(a
->prefixlen
), state
);
145 uint32_t prefix
= address_prefix(a
);
146 siphash24_compress(&prefix
, sizeof(prefix
), state
);
151 siphash24_compress(&a
->in_addr
, FAMILY_ADDRESS_SIZE(a
->family
), state
);
155 /* treat any other address family as AF_UNSPEC */
160 static int address_compare_func(const Address
*a1
, const Address
*a2
) {
163 r
= CMP(a1
->family
, a2
->family
);
167 switch (a1
->family
) {
168 /* use the same notion of equality as the kernel does */
170 r
= CMP(a1
->prefixlen
, a2
->prefixlen
);
174 uint32_t prefix1
= address_prefix(a1
);
175 uint32_t prefix2
= address_prefix(a2
);
176 r
= CMP(prefix1
, prefix2
);
182 return memcmp(&a1
->in_addr
, &a2
->in_addr
, FAMILY_ADDRESS_SIZE(a1
->family
));
184 /* treat any other address family as AF_UNSPEC */
189 DEFINE_PRIVATE_HASH_OPS(address_hash_ops
, Address
, address_hash_func
, address_compare_func
);
191 bool address_equal(Address
*a1
, Address
*a2
) {
198 return address_compare_func(a1
, a2
) == 0;
201 static int address_establish(Address
*address
, Link
*link
) {
208 masq
= link
->network
&&
209 link
->network
->ip_masquerade
&&
210 address
->family
== AF_INET
&&
211 address
->scope
< RT_SCOPE_LINK
;
213 /* Add firewall entry if this is requested */
214 if (address
->ip_masquerade_done
!= masq
) {
215 union in_addr_union masked
= address
->in_addr
;
216 in_addr_mask(address
->family
, &masked
, address
->prefixlen
);
218 r
= fw_add_masquerade(masq
, AF_INET
, 0, &masked
, address
->prefixlen
, NULL
, NULL
, 0);
222 address
->ip_masquerade_done
= masq
;
228 static int address_add_internal(Link
*link
, Set
**addresses
,
230 const union in_addr_union
*in_addr
,
231 unsigned char prefixlen
,
233 _cleanup_(address_freep
) Address
*address
= NULL
;
240 r
= address_new(&address
);
244 address
->family
= family
;
245 address
->in_addr
= *in_addr
;
246 address
->prefixlen
= prefixlen
;
247 /* Consider address tentative until we get the real flags from the kernel */
248 address
->flags
= IFA_F_TENTATIVE
;
250 r
= set_ensure_allocated(addresses
, &address_hash_ops
);
254 r
= set_put(*addresses
, address
);
260 address
->link
= link
;
270 int address_add_foreign(Link
*link
, int family
, const union in_addr_union
*in_addr
, unsigned char prefixlen
, Address
**ret
) {
271 return address_add_internal(link
, &link
->addresses_foreign
, family
, in_addr
, prefixlen
, ret
);
274 int address_add(Link
*link
, int family
, const union in_addr_union
*in_addr
, unsigned char prefixlen
, Address
**ret
) {
278 r
= address_get(link
, family
, in_addr
, prefixlen
, &address
);
280 /* Address does not exist, create a new one */
281 r
= address_add_internal(link
, &link
->addresses
, family
, in_addr
, prefixlen
, &address
);
285 /* Take over a foreign address */
286 r
= set_ensure_allocated(&link
->addresses
, &address_hash_ops
);
290 r
= set_put(link
->addresses
, address
);
294 set_remove(link
->addresses_foreign
, address
);
296 /* Already exists, do nothing */
307 static int address_release(Address
*address
) {
311 assert(address
->link
);
313 /* Remove masquerading firewall entry if it was added */
314 if (address
->ip_masquerade_done
) {
315 union in_addr_union masked
= address
->in_addr
;
316 in_addr_mask(address
->family
, &masked
, address
->prefixlen
);
318 r
= fw_add_masquerade(false, AF_INET
, 0, &masked
, address
->prefixlen
, NULL
, NULL
, 0);
322 address
->ip_masquerade_done
= false;
332 const struct ifa_cacheinfo
*cinfo
) {
339 assert_return(address
->link
, 1);
341 if (IN_SET(address
->link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
344 ready
= address_is_ready(address
);
346 address
->flags
= flags
;
347 address
->scope
= scope
;
348 address
->cinfo
= *cinfo
;
350 link_update_operstate(address
->link
, true);
351 link_check_ready(address
->link
);
354 address_is_ready(address
) &&
355 address
->family
== AF_INET6
&&
356 in_addr_is_link_local(AF_INET6
, &address
->in_addr
) > 0 &&
357 in_addr_is_null(AF_INET6
, (const union in_addr_union
*) &address
->link
->ipv6ll_address
) > 0) {
359 r
= link_ipv6ll_gained(address
->link
, &address
->in_addr
.in6
);
367 int address_drop(Address
*address
) {
374 ready
= address_is_ready(address
);
375 link
= address
->link
;
377 r
= address_release(address
);
379 log_link_warning_errno(link
, r
, "Failed to disable IP masquerading, ignoring: %m");
381 address_free(address
);
383 link_update_operstate(link
, true);
386 link_check_ready(link
);
391 int address_get(Link
*link
,
393 const union in_addr_union
*in_addr
,
394 unsigned char prefixlen
,
397 Address address
, *existing
;
402 address
= (Address
) {
405 .prefixlen
= prefixlen
,
408 existing
= set_get(link
->addresses
, &address
);
415 existing
= set_get(link
->addresses_foreign
, &address
);
425 static int address_remove_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
430 assert(link
->ifname
);
432 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
435 r
= sd_netlink_message_get_errno(m
);
436 if (r
< 0 && r
!= -EADDRNOTAVAIL
)
437 log_link_message_warning_errno(link
, m
, r
, "Could not drop address");
445 link_netlink_message_handler_t callback
) {
447 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
451 assert(IN_SET(address
->family
, AF_INET
, AF_INET6
));
453 assert(link
->ifindex
> 0);
454 assert(link
->manager
);
455 assert(link
->manager
->rtnl
);
458 _cleanup_free_
char *b
= NULL
;
460 (void) in_addr_to_string(address
->family
, &address
->in_addr
, &b
);
461 log_link_debug(link
, "Removing address %s", strna(b
));
464 r
= sd_rtnl_message_new_addr(link
->manager
->rtnl
, &req
, RTM_DELADDR
,
465 link
->ifindex
, address
->family
);
467 return log_link_error_errno(link
, r
, "Could not allocate RTM_DELADDR message: %m");
469 r
= sd_rtnl_message_addr_set_prefixlen(req
, address
->prefixlen
);
471 return log_link_error_errno(link
, r
, "Could not set prefixlen: %m");
473 r
= netlink_message_append_in_addr_union(req
, IFA_LOCAL
, address
->family
, &address
->in_addr
);
475 return log_link_error_errno(link
, r
, "Could not append IFA_LOCAL attribute: %m");
477 r
= netlink_call_async(link
->manager
->rtnl
, NULL
, req
,
478 callback
?: address_remove_handler
,
479 link_netlink_destroy_callback
, link
);
481 return log_link_error_errno(link
, r
, "Could not send rtnetlink message: %m");
488 static int address_acquire(Link
*link
, Address
*original
, Address
**ret
) {
489 union in_addr_union in_addr
= IN_ADDR_NULL
;
490 struct in_addr broadcast
= {};
491 _cleanup_(address_freep
) Address
*na
= NULL
;
498 /* Something useful was configured? just use it */
499 r
= in_addr_is_null(original
->family
, &original
->in_addr
);
503 /* The address is configured to be 0.0.0.0 or [::] by the user?
504 * Then let's acquire something more useful from the pool. */
505 r
= manager_address_pool_acquire(link
->manager
, original
->family
, original
->prefixlen
, &in_addr
);
511 if (original
->family
== AF_INET
) {
512 /* Pick first address in range for ourselves ... */
513 in_addr
.in
.s_addr
= in_addr
.in
.s_addr
| htobe32(1);
515 /* .. and use last as broadcast address */
516 if (original
->prefixlen
> 30)
517 broadcast
.s_addr
= 0;
519 broadcast
.s_addr
= in_addr
.in
.s_addr
| htobe32(0xFFFFFFFFUL
>> original
->prefixlen
);
520 } else if (original
->family
== AF_INET6
)
521 in_addr
.in6
.s6_addr
[15] |= 1;
523 r
= address_new(&na
);
527 na
->family
= original
->family
;
528 na
->prefixlen
= original
->prefixlen
;
529 na
->scope
= original
->scope
;
530 na
->cinfo
= original
->cinfo
;
532 if (original
->label
) {
533 na
->label
= strdup(original
->label
);
538 na
->broadcast
= broadcast
;
539 na
->in_addr
= in_addr
;
541 LIST_PREPEND(addresses
, link
->pool_addresses
, na
);
548 int address_configure(
551 link_netlink_message_handler_t callback
,
554 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
558 assert(IN_SET(address
->family
, AF_INET
, AF_INET6
));
560 assert(link
->ifindex
> 0);
561 assert(link
->manager
);
562 assert(link
->manager
->rtnl
);
565 /* If this is a new address, then refuse adding more than the limit */
566 if (address_get(link
, address
->family
, &address
->in_addr
, address
->prefixlen
, NULL
) <= 0 &&
567 set_size(link
->addresses
) >= ADDRESSES_PER_LINK_MAX
)
568 return log_link_error_errno(link
, SYNTHETIC_ERRNO(E2BIG
),
569 "Too many addresses are configured, refusing: %m");
571 r
= address_acquire(link
, address
, &address
);
573 return log_link_error_errno(link
, r
, "Failed to acquire an address from pool: %m");
576 r
= sd_rtnl_message_new_addr_update(link
->manager
->rtnl
, &req
,
577 link
->ifindex
, address
->family
);
579 r
= sd_rtnl_message_new_addr(link
->manager
->rtnl
, &req
, RTM_NEWADDR
,
580 link
->ifindex
, address
->family
);
582 return log_link_error_errno(link
, r
, "Could not allocate RTM_NEWADDR message: %m");
584 r
= sd_rtnl_message_addr_set_prefixlen(req
, address
->prefixlen
);
586 return log_link_error_errno(link
, r
, "Could not set prefixlen: %m");
588 address
->flags
|= IFA_F_PERMANENT
;
590 if (address
->home_address
)
591 address
->flags
|= IFA_F_HOMEADDRESS
;
593 if (!FLAGS_SET(address
->duplicate_address_detection
, ADDRESS_FAMILY_IPV6
))
594 address
->flags
|= IFA_F_NODAD
;
596 if (address
->manage_temporary_address
)
597 address
->flags
|= IFA_F_MANAGETEMPADDR
;
599 if (address
->prefix_route
)
600 address
->flags
|= IFA_F_NOPREFIXROUTE
;
602 if (address
->autojoin
)
603 address
->flags
|= IFA_F_MCAUTOJOIN
;
605 r
= sd_rtnl_message_addr_set_flags(req
, (address
->flags
& 0xff));
607 return log_link_error_errno(link
, r
, "Could not set flags: %m");
609 if (address
->flags
& ~0xff) {
610 r
= sd_netlink_message_append_u32(req
, IFA_FLAGS
, address
->flags
);
612 return log_link_error_errno(link
, r
, "Could not set extended flags: %m");
615 r
= sd_rtnl_message_addr_set_scope(req
, address
->scope
);
617 return log_link_error_errno(link
, r
, "Could not set scope: %m");
619 r
= netlink_message_append_in_addr_union(req
, IFA_LOCAL
, address
->family
, &address
->in_addr
);
621 return log_link_error_errno(link
, r
, "Could not append IFA_LOCAL attribute: %m");
623 if (in_addr_is_null(address
->family
, &address
->in_addr_peer
) == 0) {
624 r
= netlink_message_append_in_addr_union(req
, IFA_ADDRESS
, address
->family
, &address
->in_addr_peer
);
626 return log_link_error_errno(link
, r
, "Could not append IFA_ADDRESS attribute: %m");
627 } else if (address
->family
== AF_INET
&& address
->prefixlen
<= 30) {
628 r
= sd_netlink_message_append_in_addr(req
, IFA_BROADCAST
, &address
->broadcast
);
630 return log_link_error_errno(link
, r
, "Could not append IFA_BROADCAST attribute: %m");
633 if (address
->label
) {
634 r
= sd_netlink_message_append_string(req
, IFA_LABEL
, address
->label
);
636 return log_link_error_errno(link
, r
, "Could not append IFA_LABEL attribute: %m");
639 r
= sd_netlink_message_append_cache_info(req
, IFA_CACHEINFO
, &address
->cinfo
);
641 return log_link_error_errno(link
, r
, "Could not append IFA_CACHEINFO attribute: %m");
643 r
= address_establish(address
, link
);
645 log_link_warning_errno(link
, r
, "Could not enable IP masquerading, ignoring: %m");
647 r
= netlink_call_async(link
->manager
->rtnl
, NULL
, req
, callback
, link_netlink_destroy_callback
, link
);
649 address_release(address
);
650 return log_link_error_errno(link
, r
, "Could not send rtnetlink message: %m");
655 if (address
->family
== AF_INET6
&& !in_addr_is_null(address
->family
, &address
->in_addr_peer
))
656 r
= address_add(link
, address
->family
, &address
->in_addr_peer
, address
->prefixlen
, NULL
);
658 r
= address_add(link
, address
->family
, &address
->in_addr
, address
->prefixlen
, NULL
);
660 address_release(address
);
661 return log_link_error_errno(link
, r
, "Could not add address: %m");
665 assert(address
->family
== AF_INET
);
667 _cleanup_free_
char *pretty
= NULL
;
669 (void) in_addr_to_string(address
->family
, &address
->in_addr
, &pretty
);
670 log_debug("Starting IPv4ACD client. Probing address %s", strna(pretty
));
673 r
= sd_ipv4acd_start(address
->acd
, true);
675 log_link_warning_errno(link
, r
, "Failed to start IPv4ACD client, ignoring: %m");
681 static void static_address_on_acd(sd_ipv4acd
*acd
, int event
, void *userdata
) {
682 _cleanup_free_
char *pretty
= NULL
;
690 address
= (Address
*) userdata
;
691 link
= address
->link
;
693 (void) in_addr_to_string(address
->family
, &address
->in_addr
, &pretty
);
695 case SD_IPV4ACD_EVENT_STOP
:
696 log_link_debug(link
, "Stopping ACD client...");
699 case SD_IPV4ACD_EVENT_BIND
:
700 log_link_debug(link
, "Successfully claimed address %s", strna(pretty
));
701 link_check_ready(link
);
704 case SD_IPV4ACD_EVENT_CONFLICT
:
705 log_link_warning(link
, "DAD conflict. Dropping address %s", strna(pretty
));
706 r
= address_remove(address
, link
, NULL
);
708 log_link_error_errno(link
, r
, "Failed to drop DAD conflicted address %s", strna(pretty
));;
710 link_check_ready(link
);
714 assert_not_reached("Invalid IPv4ACD event.");
717 sd_ipv4acd_stop(acd
);
722 int configure_ipv4_duplicate_address_detection(Link
*link
, Address
*address
) {
727 assert(address
->family
== AF_INET
);
728 assert(!address
->link
&& address
->network
);
730 address
->link
= link
;
732 r
= sd_ipv4acd_new(&address
->acd
);
736 r
= sd_ipv4acd_attach_event(address
->acd
, NULL
, 0);
740 r
= sd_ipv4acd_set_ifindex(address
->acd
, link
->ifindex
);
744 r
= sd_ipv4acd_set_mac(address
->acd
, &link
->mac
);
748 r
= sd_ipv4acd_set_address(address
->acd
, &address
->in_addr
.in
);
752 r
= sd_ipv4acd_set_callback(address
->acd
, static_address_on_acd
, address
);
759 int config_parse_broadcast(
761 const char *filename
,
764 unsigned section_line
,
771 Network
*network
= userdata
;
772 _cleanup_(address_free_or_set_invalidp
) Address
*n
= NULL
;
781 r
= address_new_static(network
, filename
, section_line
, &n
);
785 if (n
->family
== AF_INET6
) {
786 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
787 "Broadcast is not valid for IPv6 addresses, ignoring assignment: %s", rvalue
);
791 r
= in_addr_from_string(AF_INET
, rvalue
, (union in_addr_union
*) &n
->broadcast
);
793 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
794 "Broadcast is invalid, ignoring assignment: %s", rvalue
);
804 int config_parse_address(const char *unit
,
805 const char *filename
,
808 unsigned section_line
,
815 Network
*network
= userdata
;
816 _cleanup_(address_free_or_set_invalidp
) Address
*n
= NULL
;
817 union in_addr_union buffer
;
818 unsigned char prefixlen
;
827 if (streq(section
, "Network")) {
828 /* we are not in an Address section, so treat
829 * this as the special '0' section */
830 r
= address_new_static(network
, NULL
, 0, &n
);
832 r
= address_new_static(network
, filename
, section_line
, &n
);
837 /* Address=address/prefixlen */
838 r
= in_addr_prefix_from_string_auto_internal(rvalue
, PREFIXLEN_REFUSE
, &f
, &buffer
, &prefixlen
);
840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
841 "An address '%s' is specified without prefix length. "
842 "The behavior of parsing addresses without prefix length will be changed in the future release. "
843 "Please specify prefix length explicitly.", rvalue
);
845 r
= in_addr_prefix_from_string_auto_internal(rvalue
, PREFIXLEN_LEGACY
, &f
, &buffer
, &prefixlen
);
848 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid address '%s', ignoring assignment: %m", rvalue
);
852 if (n
->family
!= AF_UNSPEC
&& f
!= n
->family
) {
853 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address is incompatible, ignoring assignment: %s", rvalue
);
857 if (in_addr_is_null(f
, &buffer
)) {
858 /* Will use address from address pool. Note that for ipv6 case, prefix of the address
859 * pool is 8, but 40 bit is used by the global ID and 16 bit by the subnet ID. So,
860 * let's limit the prefix length to 64 or larger. See RFC4193. */
861 if ((f
== AF_INET
&& prefixlen
< 8) ||
862 (f
== AF_INET6
&& prefixlen
< 64)) {
863 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
864 "Null address with invalid prefixlen='%u', ignoring assignment: %s",
871 n
->prefixlen
= prefixlen
;
873 if (streq(lvalue
, "Address"))
876 n
->in_addr_peer
= buffer
;
878 if (n
->family
== AF_INET
&& n
->broadcast
.s_addr
== 0 && n
->prefixlen
<= 30)
879 n
->broadcast
.s_addr
= n
->in_addr
.in
.s_addr
| htobe32(0xfffffffflu
>> n
->prefixlen
);
886 int config_parse_label(
888 const char *filename
,
891 unsigned section_line
,
898 _cleanup_(address_free_or_set_invalidp
) Address
*n
= NULL
;
899 Network
*network
= userdata
;
908 r
= address_new_static(network
, filename
, section_line
, &n
);
912 if (!address_label_valid(rvalue
)) {
913 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
914 "Interface label is too long or invalid, ignoring assignment: %s", rvalue
);
918 r
= free_and_strdup(&n
->label
, rvalue
);
926 int config_parse_lifetime(const char *unit
,
927 const char *filename
,
930 unsigned section_line
,
936 Network
*network
= userdata
;
937 _cleanup_(address_free_or_set_invalidp
) Address
*n
= NULL
;
947 r
= address_new_static(network
, filename
, section_line
, &n
);
951 /* We accept only "forever", "infinity", or "0". */
952 if (STR_IN_SET(rvalue
, "forever", "infinity"))
953 k
= CACHE_INFO_INFINITY_LIFE_TIME
;
954 else if (streq(rvalue
, "0"))
957 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
958 "Invalid PreferredLifetime= value, ignoring: %s", rvalue
);
962 n
->cinfo
.ifa_prefered
= k
;
968 int config_parse_address_flags(const char *unit
,
969 const char *filename
,
972 unsigned section_line
,
978 Network
*network
= userdata
;
979 _cleanup_(address_free_or_set_invalidp
) Address
*n
= NULL
;
988 r
= address_new_static(network
, filename
, section_line
, &n
);
992 r
= parse_boolean(rvalue
);
994 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
995 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
999 if (streq(lvalue
, "HomeAddress"))
1000 n
->home_address
= r
;
1001 else if (streq(lvalue
, "ManageTemporaryAddress"))
1002 n
->manage_temporary_address
= r
;
1003 else if (streq(lvalue
, "PrefixRoute"))
1004 n
->prefix_route
= r
;
1005 else if (streq(lvalue
, "AutoJoin"))
1008 assert_not_reached("Invalid address flag type.");
1014 int config_parse_address_scope(const char *unit
,
1015 const char *filename
,
1017 const char *section
,
1018 unsigned section_line
,
1024 Network
*network
= userdata
;
1025 _cleanup_(address_free_or_set_invalidp
) Address
*n
= NULL
;
1034 r
= address_new_static(network
, filename
, section_line
, &n
);
1038 if (streq(rvalue
, "host"))
1039 n
->scope
= RT_SCOPE_HOST
;
1040 else if (streq(rvalue
, "link"))
1041 n
->scope
= RT_SCOPE_LINK
;
1042 else if (streq(rvalue
, "global"))
1043 n
->scope
= RT_SCOPE_UNIVERSE
;
1045 r
= safe_atou8(rvalue
, &n
->scope
);
1047 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1048 "Could not parse address scope \"%s\", ignoring assignment: %m", rvalue
);
1057 int config_parse_duplicate_address_detection(
1059 const char *filename
,
1061 const char *section
,
1062 unsigned section_line
,
1068 Network
*network
= userdata
;
1069 _cleanup_(address_free_or_set_invalidp
) Address
*n
= NULL
;
1079 r
= address_new_static(network
, filename
, section_line
, &n
);
1083 r
= parse_boolean(rvalue
);
1085 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1086 "For historical reasons, %s=%s means %s=%s. "
1087 "Please use 'both', 'ipv4', 'ipv6' or 'none' instead.",
1088 lvalue
, rvalue
, lvalue
, r
? "none" : "both");
1089 n
->duplicate_address_detection
= r
? ADDRESS_FAMILY_NO
: ADDRESS_FAMILY_YES
;
1094 a
= duplicate_address_detection_address_family_from_string(rvalue
);
1096 log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
),
1097 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
1101 n
->duplicate_address_detection
= a
;
1106 bool address_is_ready(const Address
*a
) {
1109 return !(a
->flags
& IFA_F_TENTATIVE
);
1112 int address_section_verify(Address
*address
) {
1113 if (section_is_invalid(address
->section
))
1116 if (address
->family
== AF_UNSPEC
) {
1117 assert(address
->section
);
1119 return log_warning_errno(SYNTHETIC_ERRNO(EINVAL
),
1120 "%s: Address section without Address= field configured. "
1121 "Ignoring [Address] section from line %u.",
1122 address
->section
->filename
, address
->section
->line
);