]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: add KeepConfiguration=dhcp-on-stop
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Jun 2019 17:05:26 +0000 (02:05 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 Jun 2019 13:50:29 +0000 (22:50 +0900)
The option prevents to drop lease address on stop.
By setting this, we can safely restart networkd.

src/network/networkd-link.c
src/network/networkd-link.h
src/network/networkd-manager.c
src/network/networkd-network.c
src/network/networkd-network.h

index b38a3a00b207c808bf419ffaad76c1cf37fe4fdd..fb315dd39b942c1a733b895bc6f7485c855701ba 100644 (file)
@@ -680,14 +680,15 @@ static void link_enter_unmanaged(Link *link) {
         link_dirty(link);
 }
 
-int link_stop_clients(Link *link) {
+int link_stop_clients(Link *link, bool may_keep_dhcp) {
         int r = 0, k;
 
         assert(link);
         assert(link->manager);
         assert(link->manager->event);
 
-        if (link->dhcp_client) {
+        if (link->dhcp_client && (!may_keep_dhcp || !link->network ||
+                                  !FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP_ON_STOP))) {
                 k = sd_dhcp_client_stop(link->dhcp_client);
                 if (k < 0)
                         r = log_link_warning_errno(link, k, "Could not stop DHCPv4 client: %m");
@@ -731,7 +732,7 @@ void link_enter_failed(Link *link) {
 
         link_set_state(link, LINK_STATE_FAILED);
 
-        link_stop_clients(link);
+        link_stop_clients(link, false);
 
         link_dirty(link);
 }
@@ -2579,7 +2580,7 @@ static int link_configure(Link *link) {
         /* Drop foreign config, but ignore loopback or critical devices.
          * We do not want to remove loopback address or addresses used for root NFS. */
         if (!(link->flags & IFF_LOOPBACK) &&
-            !(link->network->keep_configuration & (KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC))) {
+            !(link->network->keep_configuration & (KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_STATIC))) {
                 r = link_drop_foreign_config(link);
                 if (r < 0)
                         return r;
@@ -3265,7 +3266,7 @@ static int link_carrier_lost(Link *link) {
         if (link->setting_mtu)
                 return 0;
 
-        r = link_stop_clients(link);
+        r = link_stop_clients(link, false);
         if (r < 0) {
                 link_enter_failed(link);
                 return r;
index d0290f7c7d56aae2d9454b0f2a5002d01ad3dc61..03db91bbd97e92100035842d7a0be8c915867e73 100644 (file)
@@ -175,7 +175,7 @@ int dhcp6_configure(Link *link);
 int dhcp6_request_address(Link *link, int ir);
 int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
 
-int link_stop_clients(Link *link);
+int link_stop_clients(Link *link, bool may_keep_dhcp);
 
 const char* link_state_to_string(LinkState s) _const_;
 LinkState link_state_from_string(const char *s) _pure_;
index 6984c5b9679421ccd773088d0de41330fd0183de..e1f4d7623f59902fd39fa9a8162cb02c996cded4 100644 (file)
@@ -1447,7 +1447,7 @@ void manager_free(Manager *m) {
                 if (link->dhcp6_client)
                         (void) dhcp6_lease_pd_prefix_lost(link->dhcp6_client, link);
 
-                link_stop_clients(link);
+                (void) link_stop_clients(link, true);
 
                 link_unref(link);
         }
index 941adebaf1e58f4675d863f08ae767235d1de221..0741dfe646de626b43a9703b65a590c2440f5cf0 100644 (file)
@@ -247,11 +247,13 @@ int network_verify(Network *network) {
                         /* CriticalConnection=yes also preserve foreign static configurations. */
                         network->keep_configuration = KEEP_CONFIGURATION_YES;
                 else
-                        network->keep_configuration = KEEP_CONFIGURATION_NO;
+                        /* For backward compatibility, we do not release DHCP addresses on manager stop. */
+                        network->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP;
         }
 
         if (network->keep_configuration < 0)
-                network->keep_configuration = KEEP_CONFIGURATION_NO;
+                /* For backward compatibility, we do not release DHCP addresses on manager stop. */
+                network->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP;
 
         LIST_FOREACH_SAFE(addresses, address, address_next, network->static_addresses)
                 if (address_section_verify(address) < 0)
@@ -1774,10 +1776,11 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_keep_configuration, keep_configuration, Ke
                          "Failed to parse KeepConfiguration= setting");
 
 static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
-        [KEEP_CONFIGURATION_NO]     = "no",
-        [KEEP_CONFIGURATION_DHCP]   = "dhcp",
-        [KEEP_CONFIGURATION_STATIC] = "static",
-        [KEEP_CONFIGURATION_YES]    = "yes",
+        [KEEP_CONFIGURATION_NO]           = "no",
+        [KEEP_CONFIGURATION_DHCP_ON_STOP] = "dhcp-on-stop",
+        [KEEP_CONFIGURATION_DHCP]         = "dhcp",
+        [KEEP_CONFIGURATION_STATIC]       = "static",
+        [KEEP_CONFIGURATION_YES]          = "yes",
 };
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES);
index ca1c6fcdb316f93c7a0eea773e2adc324b358bcb..7b92a5442666930c01476f89844e743f580ba58e 100644 (file)
@@ -79,10 +79,12 @@ typedef enum RADVPrefixDelegation {
 } RADVPrefixDelegation;
 
 typedef enum KeepConfiguration {
-        KEEP_CONFIGURATION_NO     = 0,
-        KEEP_CONFIGURATION_DHCP   = 1 << 0,
-        KEEP_CONFIGURATION_STATIC = 1 << 1,
-        KEEP_CONFIGURATION_YES    = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
+        KEEP_CONFIGURATION_NO            = 0,
+        KEEP_CONFIGURATION_DHCP_ON_START = 1 << 0,
+        KEEP_CONFIGURATION_DHCP_ON_STOP  = 1 << 1,
+        KEEP_CONFIGURATION_DHCP          = KEEP_CONFIGURATION_DHCP_ON_START | KEEP_CONFIGURATION_DHCP_ON_STOP,
+        KEEP_CONFIGURATION_STATIC        = 1 << 2,
+        KEEP_CONFIGURATION_YES           = KEEP_CONFIGURATION_DHCP | KEEP_CONFIGURATION_STATIC,
         _KEEP_CONFIGURATION_MAX,
         _KEEP_CONFIGURATION_INVALID = -1,
 } KeepConfiguration;