network: DHCPv4 - introduce The Manufacturer Usage Description (MUD)

This commit is contained in:
Susant Sahani 2020-03-30 16:43:28 +02:00
parent d11d4a6459
commit 7b8d23a9bb
7 changed files with 68 additions and 0 deletions

View File

@ -1430,6 +1430,18 @@
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>

View 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",

View 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);

View 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)

View 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);

View 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;

View File

@ -102,6 +102,7 @@ IPServiceType=
SendOption=
SendVendorOption=
SendDecline=
MUDURL=
RouteMTUBytes=
[DHCPv6]
UseNTP=