]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: dhcp6: make UplinkInterface=:self imply WithoutRA=solicit
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 14 Oct 2021 10:10:49 +0000 (19:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 26 Oct 2021 15:33:44 +0000 (00:33 +0900)
src/network/networkd-dhcp6.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h

index 8bd69813a87b4b2e9a8ea4351a1165a5ff5d7760..3cc457a02d5d5c7296fa86602ea365c350d43800 100644 (file)
@@ -58,6 +58,25 @@ static int dhcp6_pd_resolve_uplink(Link *link, Link **ret) {
         return -ENOENT;
 }
 
+static DHCP6ClientStartMode link_get_dhcp6_client_start_mode(Link *link) {
+        Link *uplink;
+
+        assert(link);
+
+        if (!link->network)
+                return DHCP6_CLIENT_START_MODE_NO;
+
+        /* When WithoutRA= is explicitly specified, then honor it. */
+        if (link->network->dhcp6_client_start_mode >= 0)
+                return link->network->dhcp6_client_start_mode;
+
+        if (dhcp6_pd_resolve_uplink(link, &uplink) < 0)
+                return DHCP6_CLIENT_START_MODE_NO;
+
+        /* When this interface itself is an uplink interface, then start dhcp6 client in managed mode */
+        return uplink == link ? DHCP6_CLIENT_START_MODE_SOLICIT : DHCP6_CLIENT_START_MODE_NO;
+}
+
 static bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease) {
         uint32_t lifetime_preferred_sec, lifetime_valid_sec;
         struct in6_addr pd_prefix;
@@ -1319,7 +1338,7 @@ int dhcp6_start_on_ra(Link *link, bool information_request) {
         assert(link->network);
         assert(in6_addr_is_link_local(&link->ipv6ll_address));
 
-        if (link->network->dhcp6_without_ra != DHCP6_CLIENT_START_MODE_NO)
+        if (link_get_dhcp6_client_start_mode(link) != DHCP6_CLIENT_START_MODE_NO)
                 /* When WithoutRA= is specified, then the DHCPv6 client should be already runnging in
                  * the requested mode. Hence, ignore the requests by RA. */
                 return 0;
@@ -1359,6 +1378,7 @@ int dhcp6_start_on_ra(Link *link, bool information_request) {
 }
 
 int dhcp6_start(Link *link) {
+        DHCP6ClientStartMode start_mode;
         int r;
 
         assert(link);
@@ -1373,9 +1393,6 @@ int dhcp6_start(Link *link) {
         if (!link_has_carrier(link))
                 return 0;
 
-        if (link->network->dhcp6_without_ra == DHCP6_CLIENT_START_MODE_NO)
-                return 0;
-
         if (sd_dhcp6_client_is_running(link->dhcp6_client) > 0)
                 return 0;
 
@@ -1388,8 +1405,12 @@ int dhcp6_start(Link *link) {
         if (r < 0)
                 return r;
 
+        start_mode = link_get_dhcp6_client_start_mode(link);
+        if (start_mode == DHCP6_CLIENT_START_MODE_NO)
+                return 0;
+
         r = sd_dhcp6_client_set_information_request(link->dhcp6_client,
-                                                    link->network->dhcp6_without_ra == DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST);
+                                                    start_mode == DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST);
         if (r < 0)
                 return r;
 
index 3caf7c2bdd18aa3250b42b49a50329f48f392cf2..6631f5bc3e9d4bb93bdb0c31cde120a8e3415f19 100644 (file)
@@ -249,7 +249,7 @@ DHCPv6.UserClass,                            config_parse_dhcp_user_or_vendor_cl
 DHCPv6.VendorClass,                          config_parse_dhcp_user_or_vendor_class,                   AF_INET6,                      offsetof(Network, dhcp6_vendor_class)
 DHCPv6.SendVendorOption,                     config_parse_dhcp_send_option,                            AF_INET6,                      offsetof(Network, dhcp6_client_send_vendor_options)
 DHCPv6.PrefixDelegationHint,                 config_parse_dhcp6_pd_prefix_hint,                        0,                             0
-DHCPv6.WithoutRA,                            config_parse_dhcp6_client_start_mode,                     0,                             offsetof(Network, dhcp6_without_ra)
+DHCPv6.WithoutRA,                            config_parse_dhcp6_client_start_mode,                     0,                             offsetof(Network, dhcp6_client_start_mode)
 DHCPv6.SendOption,                           config_parse_dhcp_send_option,                            AF_INET6,                      offsetof(Network, dhcp6_client_send_options)
 DHCPv6.IAID,                                 config_parse_iaid,                                        AF_INET6,                      0
 DHCPv6.DUIDType,                             config_parse_duid_type,                                   0,                             offsetof(Network, dhcp6_duid)
index c3c792eb49862aa086fb7876bc28dbe6cf2e9f3b..5469cb4560bb9a72169a392f262d2c1d6bb157df 100644 (file)
@@ -405,6 +405,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
                 .dhcp6_use_hostname = true,
                 .dhcp6_use_ntp = true,
                 .dhcp6_duid.type = _DUID_TYPE_INVALID,
+                .dhcp6_client_start_mode = _DHCP6_CLIENT_START_MODE_INVALID,
 
                 .dhcp6_pd = -1,
                 .dhcp6_pd_announce = true,
index f8d62fee6c3717cf91f5533524ae32099118353d..d10119f58cf9c3252c24f481a771d8e5b05d47a4 100644 (file)
@@ -185,7 +185,7 @@ struct Network {
         char *dhcp6_mudurl;
         char **dhcp6_user_class;
         char **dhcp6_vendor_class;
-        DHCP6ClientStartMode dhcp6_without_ra;
+        DHCP6ClientStartMode dhcp6_client_start_mode;
         OrderedHashmap *dhcp6_client_send_options;
         OrderedHashmap *dhcp6_client_send_vendor_options;
         Set *dhcp6_request_options;