]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: always use RT_SCOPE_HOST for IPv4 loopback addresses
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Oct 2020 01:57:03 +0000 (10:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 6 Oct 2020 18:13:18 +0000 (03:13 +0900)
For IPv6 case, use RT_SCOPE_HOST only when scope is not explicitly specified.

src/network/networkd-address.c

index 000f8cfa93276e6545f12eeea892a70ad955050f..58d2ffe3f2cf67e9d4ae749c80731721f59022fb 100644 (file)
@@ -1867,8 +1867,19 @@ static int address_section_verify(Address *address) {
                                          address->section->filename, address->section->line);
         }
 
-        if (!address->scope_set && in_addr_is_localhost(address->family, &address->in_addr) > 0)
+        if (in_addr_is_localhost(address->family, &address->in_addr) > 0 &&
+            (address->family == AF_INET || !address->scope_set)) {
+                /* For IPv4, scope must be always RT_SCOPE_HOST.
+                 * For IPv6, use RT_SCOPE_HOST only when it is not explicitly specified. */
+
+                if (address->scope_set && address->scope != RT_SCOPE_HOST)
+                        log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
+                                          "%s: non-host scope is set in the [Address] section from line %u. "
+                                          "Ignoring Scope= setting.",
+                                          address->section->filename, address->section->line);
+
                 address->scope = RT_SCOPE_HOST;
+        }
 
         if (!FLAGS_SET(address->duplicate_address_detection, ADDRESS_FAMILY_IPV6))
                 address->flags |= IFA_F_NODAD;