]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: DHCPv4- Allow to set DHCP lease lifetime 15274/head
authorSusant Sahani <ssahani@vmware.com>
Wed, 20 May 2020 04:23:36 +0000 (06:23 +0200)
committerSusant Sahani <ssahani@vmware.com>
Wed, 20 May 2020 04:32:26 +0000 (06:32 +0200)
man/systemd.network.xml
src/network/networkd-dhcp4.c
src/network/networkd-dhcp4.h
src/network/networkd-network-gperf.gperf
src/network/networkd-network.h
test/fuzz/fuzz-network-parser/directives.network

index 19b49702f362b7a87aec5f454f263f80d48d7a35..61d7014187a238759fe840da611497b6bd74a0f6 100644 (file)
           </listitem>
         </varlistentry>
 
+         <varlistentry>
+          <term><varname>FallbackLeaseLifetimeSec=</varname></term>
+          <listitem>
+            <para>Allows to set DHCPv4 lease lifetime when DHCPv4 server does not send the lease lifetime.
+            Takes one of <literal>forever</literal> or <literal>infinity</literal> means that the address
+            never expires. Defaults to unset.</para>
+          </listitem>
+        </varlistentry>
+
         <varlistentry>
           <term><varname>SendRelease=</varname></term>
           <listitem>
index 6bfa6e6dd0945598339acbdd7842b6b1777bf832..42e6b5aef2a9aad329cd19ca416f90ffd1ebf5d1 100644 (file)
@@ -1488,6 +1488,12 @@ int dhcp4_configure(Link *link) {
                         return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set ip service type: %m");
         }
 
+        if (link->network->dhcp_fallback_lease_lifetime > 0) {
+                r = sd_dhcp_client_set_fallback_lease_lifetime(link->dhcp_client, link->network->dhcp_fallback_lease_lifetime);
+                if (r < 0)
+                        return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed set to lease lifetime: %m");
+        }
+
         if (link->network->dhcp_send_decline) {
                 r = configure_dhcpv4_duplicate_address_detection(link);
                 if (r < 0)
@@ -1674,6 +1680,44 @@ int config_parse_dhcp_mud_url(
         return free_and_strdup_warn(&network->dhcp_mudurl, unescaped);
 }
 
+int config_parse_dhcp_fallback_lease_lifetime(const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+        Network *network = userdata;
+        unsigned k;
+
+        assert(filename);
+        assert(section);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        if (isempty(rvalue)) {
+                network->dhcp_fallback_lease_lifetime = 0;
+                return 0;
+        }
+
+        /* We accept only "forever" or "infinity". */
+        if (STR_IN_SET(rvalue, "forever", "infinity"))
+                k = CACHE_INFO_INFINITY_LIFE_TIME;
+        else {
+                log_syntax(unit, LOG_ERR, filename, line, 0,
+                           "Invalid LeaseLifetime= value, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        network->dhcp_fallback_lease_lifetime = k;
+
+        return 0;
+}
+
 static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
         [DHCP_CLIENT_ID_MAC] = "mac",
         [DHCP_CLIENT_ID_DUID] = "duid",
index 93fa7d372cfa047a24feb7e4c289703415150535..a6e24be78d73744dbccaa84b71ac5e10d1450b99 100644 (file)
@@ -27,3 +27,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_black_listed_ip_address);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_ip_service_type);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_mud_url);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_fallback_lease_lifetime);
index 798781cfe4eb127c3f9fea0786a669a937041b4e..bafd500d9db5c2584673dd96ec956ade74ff5c91 100644 (file)
@@ -189,6 +189,7 @@ DHCPv4.IPServiceType,                        config_parse_dhcp_ip_service_type,
 DHCPv4.SendOption,                           config_parse_dhcp_send_option,                            AF_INET,                       offsetof(Network, dhcp_client_send_options)
 DHCPv4.SendVendorOption,                     config_parse_dhcp_send_option,                            0,                             offsetof(Network, dhcp_client_send_vendor_options)
 DHCPv4.RouteMTUBytes,                        config_parse_mtu,                                         AF_INET,                       offsetof(Network, dhcp_route_mtu)
+DHCPv4.FallbackLeaseLifetimeSec,             config_parse_dhcp_fallback_lease_lifetime,                0,                             0
 DHCPv6.UseDNS,                               config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_dns)
 DHCPv6.UseNTP,                               config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_ntp)
 DHCPv6.RapidCommit,                          config_parse_bool,                                        0,                             offsetof(Network, rapid_commit)
index 8a6de4df01b32b030a14c694d2e7dc6282c860a2..8a25d2bffed837f068f40e1f9781ecd8da5db4c6 100644 (file)
@@ -97,6 +97,7 @@ struct Network {
         uint64_t dhcp_max_attempts;
         unsigned dhcp_route_metric;
         uint32_t dhcp_route_table;
+        uint32_t dhcp_fallback_lease_lifetime;
         uint32_t dhcp_route_mtu;
         uint16_t dhcp_client_port;
         int dhcp_critical;
index 9ce0fc3f9995c5211c7c3ab857e111acb786e9d1..812508e04315449beea1a9ee66af5c2d2c189268 100644 (file)
@@ -105,6 +105,7 @@ SendVendorOption=
 SendDecline=
 MUDURL=
 RouteMTUBytes=
+FallbackLeaseLifetimeSec=
 [DHCPv6]
 UseNTP=
 UseDNS=