mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-27 01:55:32 +03:00
Merge pull request #15252 from ssahani/dhcpv6-mud
DHCPv6: Add support to send MUD URL
This commit is contained in:
commit
c51c6f2f57
@ -1704,6 +1704,16 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>MUDURL=</varname></term>
|
||||
<listitem>
|
||||
<para>When configured, the Manufacturer Usage Descriptions (MUD) URL will be sent to the DHCPV6 server.
|
||||
Takes an URL of length up to 255 characters. A superficial verification that the string is a valid URL
|
||||
will be performed. DHCPv6 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>ForceDHCPv6PDOtherInformation=</varname></term>
|
||||
<listitem>
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "socket-util.h"
|
||||
#include "string-table.h"
|
||||
#include "util.h"
|
||||
#include "web-util.h"
|
||||
|
||||
#define MAX_MAC_ADDR_LEN INFINIBAND_ALEN
|
||||
|
||||
@ -65,6 +66,7 @@ struct sd_dhcp6_client {
|
||||
size_t req_opts_allocated;
|
||||
size_t req_opts_len;
|
||||
char *fqdn;
|
||||
char *mudurl;
|
||||
sd_event_source *receive_message;
|
||||
usec_t retransmit_time;
|
||||
uint8_t retransmit_count;
|
||||
@ -363,6 +365,17 @@ int sd_dhcp6_client_set_request_option(sd_dhcp6_client *client, uint16_t option)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_dhcp6_client_set_request_mud_url(sd_dhcp6_client *client, char *mudurl) {
|
||||
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(client->state == DHCP6_STATE_STOPPED, -EBUSY);
|
||||
assert_return(mudurl, -EINVAL);
|
||||
assert_return(strlen(mudurl) <= 255, -EINVAL);
|
||||
assert_return(http_url_is_valid(mudurl), -EINVAL);
|
||||
|
||||
return free_and_strdup(&client->mudurl, mudurl);
|
||||
}
|
||||
|
||||
int sd_dhcp6_client_get_prefix_delegation(sd_dhcp6_client *client, int *delegation) {
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(delegation, -EINVAL);
|
||||
@ -484,6 +497,14 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
|
||||
case DHCP6_STATE_INFORMATION_REQUEST:
|
||||
message->type = DHCP6_INFORMATION_REQUEST;
|
||||
|
||||
if (client->mudurl) {
|
||||
r = dhcp6_option_append(&opt, &optlen,
|
||||
SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl),
|
||||
client->mudurl);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DHCP6_STATE_SOLICITATION:
|
||||
@ -507,6 +528,14 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
|
||||
return r;
|
||||
}
|
||||
|
||||
if (client->mudurl) {
|
||||
r = dhcp6_option_append(&opt, &optlen,
|
||||
SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl),
|
||||
client->mudurl);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD)) {
|
||||
r = dhcp6_option_append_pd(opt, optlen, &client->ia_pd, &client->hint_pd_prefix);
|
||||
if (r < 0)
|
||||
@ -545,6 +574,14 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
|
||||
return r;
|
||||
}
|
||||
|
||||
if (client->mudurl) {
|
||||
r = dhcp6_option_append(&opt, &optlen,
|
||||
SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl),
|
||||
client->mudurl);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD)) {
|
||||
r = dhcp6_option_append_pd(opt, optlen, &client->lease->pd, NULL);
|
||||
if (r < 0)
|
||||
@ -571,6 +608,14 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
|
||||
return r;
|
||||
}
|
||||
|
||||
if (client->mudurl) {
|
||||
r = dhcp6_option_append(&opt, &optlen,
|
||||
SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl),
|
||||
client->mudurl);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD)) {
|
||||
r = dhcp6_option_append_pd(opt, optlen, &client->lease->pd, NULL);
|
||||
if (r < 0)
|
||||
@ -1521,6 +1566,7 @@ static sd_dhcp6_client *dhcp6_client_free(sd_dhcp6_client *client) {
|
||||
|
||||
free(client->req_opts);
|
||||
free(client->fqdn);
|
||||
free(client->mudurl);
|
||||
return mfree(client);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "parse-util.h"
|
||||
#include "string-table.h"
|
||||
#include "strv.h"
|
||||
#include "web-util.h"
|
||||
|
||||
int config_parse_dhcp(
|
||||
const char* unit,
|
||||
@ -265,6 +266,48 @@ int config_parse_dhcp6_pd_hint(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_dhcp6_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->dhcp6_mudurl = mfree(network->dhcp6_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_replace(network->dhcp6_mudurl, unescaped);
|
||||
}
|
||||
|
||||
int config_parse_dhcp_send_option(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
@ -48,4 +48,5 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_sip);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_hint);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_mud_url);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
|
||||
|
@ -676,6 +676,12 @@ int dhcp6_configure(Link *link) {
|
||||
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set request flag for rapid commit: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp6_mudurl) {
|
||||
r = sd_dhcp6_client_set_request_mud_url(client, link->network->dhcp6_mudurl);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set MUD URL: %m");
|
||||
}
|
||||
|
||||
r = sd_dhcp6_client_set_callback(client, dhcp6_handler, link);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "DHCP6 CLIENT: Failed to set callback: %m");
|
||||
|
@ -191,6 +191,7 @@ DHCPv4.RouteMTUBytes, config_parse_mtu,
|
||||
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)
|
||||
DHCPv6.MUDURL, config_parse_dhcp6_mud_url, 0, 0
|
||||
DHCPv6.ForceDHCPv6PDOtherInformation, config_parse_bool, 0, offsetof(Network, dhcp6_force_pd_other_information)
|
||||
DHCPv6.PrefixDelegationHint, config_parse_dhcp6_pd_hint, 0, 0
|
||||
DHCPv6.WithoutRA, config_parse_bool, 0, offsetof(Network, dhcp6_without_ra)
|
||||
|
@ -646,6 +646,7 @@ static Network *network_free(Network *network) {
|
||||
set_free(network->dhcp_black_listed_ip);
|
||||
set_free(network->dhcp_request_options);
|
||||
free(network->mac);
|
||||
free(network->dhcp6_mudurl);
|
||||
|
||||
if (network->dhcp_acd)
|
||||
sd_ipv4acd_unref(network->dhcp_acd);
|
||||
|
@ -131,6 +131,7 @@ struct Network {
|
||||
bool dhcp6_use_ntp;
|
||||
bool dhcp6_without_ra;
|
||||
uint8_t dhcp6_pd_length;
|
||||
char *dhcp6_mudurl;
|
||||
struct in6_addr dhcp6_pd_address;
|
||||
|
||||
/* DHCP Server Support */
|
||||
|
@ -73,6 +73,7 @@ enum {
|
||||
SD_DHCP6_OPTION_FQDN = 39, /* RFC 4704 */
|
||||
|
||||
SD_DHCP6_OPTION_NTP_SERVER = 56, /* RFC 5908 */
|
||||
SD_DHCP6_OPTION_MUD_URL = 112, /* RFC 8250 */
|
||||
|
||||
/* option codes 89-142 are unassigned */
|
||||
/* option codes 144-65535 are unassigned */
|
||||
@ -120,6 +121,9 @@ int sd_dhcp6_client_get_information_request(
|
||||
int sd_dhcp6_client_set_request_option(
|
||||
sd_dhcp6_client *client,
|
||||
uint16_t option);
|
||||
int sd_dhcp6_client_set_request_mud_url(
|
||||
sd_dhcp6_client *client,
|
||||
char *mudurl);
|
||||
int sd_dhcp6_client_set_prefix_delegation_hint(
|
||||
sd_dhcp6_client *client,
|
||||
uint8_t prefixlen,
|
||||
|
@ -111,6 +111,7 @@ RapidCommit=
|
||||
ForceDHCPv6PDOtherInformation=
|
||||
PrefixDelegationHint=
|
||||
WithoutRA=
|
||||
MUDURL=
|
||||
[Route]
|
||||
Destination=
|
||||
Protocol=
|
||||
|
Loading…
Reference in New Issue
Block a user