]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: DHCPv4 - introduce The Manufacturer Usage Description (MUD) 15229/head
authorSusant Sahani <ssahani@vmware.com>
Mon, 30 Mar 2020 14:43:28 +0000 (16:43 +0200)
committerSusant Sahani <ssahani@vmware.com>
Mon, 30 Mar 2020 18:27:48 +0000 (20:27 +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.c
src/network/networkd-network.h
test/fuzz/fuzz-network-parser/directives.network

index 2ead483519e7810fc9f18e6073fe2fae6b2da7d9..bb6c35f9babf49e4a7a9b3f6f8df59cc8e55e08f 100644 (file)
             sent even if this is set to true.</para>
           </listitem>
         </varlistentry>
+
+        <varlistentry>
+          <term><varname>MUDURL=</varname></term>
+          <listitem>
+            <para>When configured, the Manufacturer Usage Descriptions (MUD) URL will be sent to the
+            DHCPv4 server. Takes an URL of length up to 255 characters. A superficial verification that
+            the string is a valid URL will be performed. DHCPv4 clients are intended to have at most one
+            MUD URL associated with them. See
+            <ulink url="https://tools.ietf.org/html/rfc8520">RFC 8520</ulink>.</para>
+          </listitem>
+        </varlistentry>
+
         <varlistentry>
           <term><varname>UseHostname=</varname></term>
           <listitem>
index 83fb25264ab5fdbd07b57bd75ec8c21e43bb905e..48e5c15fd09c1aead15d6c51d9a6658bad6559f6 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/if.h>
 #include <linux/if_arp.h>
 
+#include "escape.h"
 #include "alloc-util.h"
 #include "dhcp-client-internal.h"
 #include "hostname-util.h"
@@ -17,6 +18,7 @@
 #include "string-table.h"
 #include "string-util.h"
 #include "sysctl-util.h"
+#include "web-util.h"
 
 static int dhcp_remove_routes(Link *link, sd_dhcp_lease *lease, const struct in_addr *address, bool remove_all);
 static int dhcp_remove_router(Link *link, sd_dhcp_lease *lease, const struct in_addr *address, bool remove_all);
@@ -1456,6 +1458,13 @@ int dhcp4_configure(Link *link) {
                         return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set vendor class identifier: %m");
         }
 
+       if (link->network->dhcp_mudurl) {
+                r = sd_dhcp_client_set_mud_url(link->dhcp_client,
+                                               link->network->dhcp_mudurl);
+                if (r < 0)
+                        return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set MUD URL: %m");
+        }
+
         if (link->network->dhcp_user_class) {
                 r = sd_dhcp_client_set_user_class(link->dhcp_client, (const char **) link->network->dhcp_user_class);
                 if (r < 0)
@@ -1744,6 +1753,48 @@ int config_parse_dhcp_ip_service_type(
         return 0;
 }
 
+int config_parse_dhcp_mud_url(
+                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) {
+
+        _cleanup_free_ char *unescaped = NULL;
+        Network *network = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                network->dhcp_mudurl = mfree(network->dhcp_mudurl);
+                return 0;
+        }
+
+        r = cunescape(rvalue, 0, &unescaped);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, r,
+                           "Failed to Failed to unescape MUD URL, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        if (!http_url_is_valid(unescaped) || strlen(unescaped) > 255) {
+                log_syntax(unit, LOG_ERR, filename, line, 0,
+                           "Failed to parse MUD URL '%s', ignoring: %m", rvalue);
+
+                return 0;
+        }
+
+        return free_and_strdup_warn(&network->dhcp_mudurl, unescaped);
+}
+
 static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
         [DHCP_CLIENT_ID_MAC] = "mac",
         [DHCP_CLIENT_ID_DUID] = "duid",
index 95fa5ee4b5bce81c8e42c306658cbc186b6ffee2..b0c30b598ce9ce8cc1962856c289462dbcf3b1e1 100644 (file)
@@ -28,3 +28,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_ip_service_type);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_mud_url);
index 04d411c4adbc9e9577256824bb345adea5c1d785..18ba23bfc8bcb6af4497bfe8447c94bd8295396f 100644 (file)
@@ -170,6 +170,7 @@ DHCPv4.SendHostname,                         config_parse_bool,
 DHCPv4.Hostname,                             config_parse_hostname,                                    0,                             offsetof(Network, dhcp_hostname)
 DHCPv4.RequestBroadcast,                     config_parse_bool,                                        0,                             offsetof(Network, dhcp_broadcast)
 DHCPv4.VendorClassIdentifier,                config_parse_string,                                      0,                             offsetof(Network, dhcp_vendor_class_identifier)
+DHCPv4.MUDURL,                               config_parse_dhcp_mud_url,                                0,                             0
 DHCPv4.MaxAttempts,                          config_parse_dhcp_max_attempts,                           0,                             0
 DHCPv4.UserClass,                            config_parse_dhcp_user_class,                             0,                             offsetof(Network, dhcp_user_class)
 DHCPv4.DUIDType,                             config_parse_duid_type,                                   0,                             offsetof(Network, duid)
index a71fac6790be5bc454634e0e7c90e5212f031ca6..6afe29d53bf911c1e41b7cf3b05832480e07b7e9 100644 (file)
@@ -640,6 +640,7 @@ static Network *network_free(Network *network) {
 
         free(network->description);
         free(network->dhcp_vendor_class_identifier);
+        free(network->dhcp_mudurl);
         strv_free(network->dhcp_user_class);
         free(network->dhcp_hostname);
         set_free(network->dhcp_black_listed_ip);
index fe2878978470e5fe6e7b3f5ae0a8dc232d4ee5f1..66ee01d7f3fbaac34461fb0ce5d3628238807956 100644 (file)
@@ -91,6 +91,7 @@ struct Network {
         AddressFamily dhcp;
         DHCPClientIdentifier dhcp_client_identifier;
         char *dhcp_vendor_class_identifier;
+        char *dhcp_mudurl;
         char **dhcp_user_class;
         char *dhcp_hostname;
         uint64_t dhcp_max_attempts;
index e1af20694171d73a05d5bdebabb756b7e6f7cef9..01b1b50ff6a26bea7eb25f122613590cf935ea24 100644 (file)
@@ -102,6 +102,7 @@ IPServiceType=
 SendOption=
 SendVendorOption=
 SendDecline=
+MUDURL=
 RouteMTUBytes=
 [DHCPv6]
 UseNTP=