@@ -68,7 +68,6 @@ int address_new(Address **ret) {
6868 .lifetime_valid_usec = USEC_INFINITY ,
6969 .lifetime_preferred_usec = USEC_INFINITY ,
7070 .set_broadcast = -1 ,
71- .duplicate_address_detection = ADDRESS_FAMILY_IPV6 ,
7271 };
7372
7473 * ret = TAKE_PTR (address );
@@ -106,6 +105,8 @@ static int address_new_static(Network *network, const char *filename, unsigned s
106105 address -> network = network ;
107106 address -> section = TAKE_PTR (n );
108107 address -> source = NETWORK_CONFIG_SOURCE_STATIC ;
108+ /* This will be adjusted in address_section_verify(). */
109+ address -> duplicate_address_detection = _ADDRESS_FAMILY_INVALID ;
109110
110111 r = ordered_hashmap_ensure_put (& network -> addresses_by_section , & config_section_hash_ops , address -> section , address );
111112 if (r < 0 )
@@ -1951,6 +1952,8 @@ static int address_section_verify(Address *address) {
19511952 address -> section -> filename , address -> section -> line );
19521953 }
19531954
1955+ assert (IN_SET (address -> family , AF_INET , AF_INET6 ));
1956+
19541957 if (in4_addr_is_set (& address -> broadcast ) &&
19551958 (address -> family == AF_INET6 || address -> prefixlen > 30 ||
19561959 in_addr_is_set (address -> family , & address -> in_addr_peer ))) {
@@ -1977,17 +1980,24 @@ static int address_section_verify(Address *address) {
19771980 address -> scope = RT_SCOPE_LINK ;
19781981 }
19791982
1983+ if (address -> duplicate_address_detection < 0 ) {
1984+ if (address -> family == AF_INET6 )
1985+ address -> duplicate_address_detection = ADDRESS_FAMILY_IPV6 ;
1986+ else if (in4_addr_is_link_local (& address -> in_addr .in ))
1987+ address -> duplicate_address_detection = ADDRESS_FAMILY_IPV4 ;
1988+ else
1989+ address -> duplicate_address_detection = ADDRESS_FAMILY_NO ;
1990+ } else if (address -> duplicate_address_detection == ADDRESS_FAMILY_IPV6 && address -> family == AF_INET )
1991+ log_warning ("%s: DuplicateAddressDetection=ipv6 is specified for IPv4 address, ignoring." ,
1992+ address -> section -> filename );
1993+ else if (address -> duplicate_address_detection == ADDRESS_FAMILY_IPV4 && address -> family == AF_INET6 )
1994+ log_warning ("%s: DuplicateAddressDetection=ipv4 is specified for IPv6 address, ignoring." ,
1995+ address -> section -> filename );
1996+
19801997 if (address -> family == AF_INET6 &&
19811998 !FLAGS_SET (address -> duplicate_address_detection , ADDRESS_FAMILY_IPV6 ))
19821999 address -> flags |= IFA_F_NODAD ;
19832000
1984- if (address -> family == AF_INET && in4_addr_is_link_local (& address -> in_addr .in ) &&
1985- !FLAGS_SET (address -> duplicate_address_detection , ADDRESS_FAMILY_IPV4 )) {
1986- log_debug ("%s: An IPv4 link-local address is specified, enabling IPv4 Address Conflict Detection (ACD)." ,
1987- address -> section -> filename );
1988- address -> duplicate_address_detection |= ADDRESS_FAMILY_IPV4 ;
1989- }
1990-
19912001 return 0 ;
19922002}
19932003
0 commit comments