summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorSusant Sahani <ssahani@vmware.com>2019-09-26 20:06:02 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-10-14 17:14:02 +0200
commitcb29c1560515f758e6122d111e82ab302b805671 (patch)
treebf08bf944ab07d4ecb0db448ca17594c44ba239c /src/network
parentMerge pull request #13749 from keszybz/pyparsing-2.4 (diff)
downloadsystemd-cb29c1560515f758e6122d111e82ab302b805671.tar.xz
systemd-cb29c1560515f758e6122d111e82ab302b805671.zip
network: DHCPv4 client: add support to send arbitary option and data
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-dhcp4.c93
-rw-r--r--src/network/networkd-dhcp4.h1
-rw-r--r--src/network/networkd-network-gperf.gperf1
-rw-r--r--src/network/networkd-network.c2
-rw-r--r--src/network/networkd-network.h5
5 files changed, 100 insertions, 2 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index 6b85428758..70ab9b2a54 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -5,6 +5,8 @@
#include <linux/if_arp.h>
#include "alloc-util.h"
+#include "dhcp-client-internal.h"
+#include "hexdecoct.h"
#include "hostname-util.h"
#include "parse-util.h"
#include "network-internal.h"
@@ -1186,6 +1188,7 @@ int dhcp4_set_client_identifier(Link *link) {
}
int dhcp4_configure(Link *link) {
+ sd_dhcp_option *send_option;
void *request_options;
Iterator i;
int r;
@@ -1292,6 +1295,12 @@ int dhcp4_configure(Link *link) {
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set request flag for '%u': %m", option);
}
+ ORDERED_HASHMAP_FOREACH(send_option, link->network->dhcp_send_options, i) {
+ r = sd_dhcp_client_set_dhcp_option(link->dhcp_client, send_option);
+ if (r < 0)
+ return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to set send option: %m");
+ }
+
r = dhcp4_set_hostname(link);
if (r < 0)
return r;
@@ -1557,6 +1566,90 @@ int config_parse_dhcp_request_options(
return 0;
}
+int config_parse_dhcp_send_options(
+ 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_(sd_dhcp_option_unrefp) sd_dhcp_option *opt = NULL, *old = NULL;
+ _cleanup_free_ char *word = NULL;
+ _cleanup_free_ void *q = NULL;
+ Network *network = data;
+ const char *p;
+ uint8_t u;
+ size_t sz;
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ if (isempty(rvalue)) {
+ network->dhcp_send_options = ordered_hashmap_free(network->dhcp_send_options);
+ return 0;
+ }
+
+ p = rvalue;
+ r = extract_first_word(&p, &word, ":", 0);
+ if (r == -ENOMEM)
+ return log_oom();
+ if (r <= 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Invalid DHCP send option, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ r = safe_atou8(word, &u);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Invalid DHCP send option, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+ if (u < 1 || u >= 255) {
+ log_syntax(unit, LOG_ERR, filename, line, 0,
+ "Invalid DHCP send option, valid range is 1-254, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ r = unbase64mem(p, (size_t) -1, &q, &sz);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Failed to decode base64 data, ignoring assignment: %s", p);
+ return 0;
+ }
+
+ r = sd_dhcp_option_new(u, q, sz, &opt);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Failed to store DHCP send option '%s', ignoring assignment: %m", rvalue);
+ return 0;
+ }
+
+ r = ordered_hashmap_ensure_allocated(&network->dhcp_send_options, &dhcp_option_hash_ops);
+ if (r < 0)
+ return log_oom();
+
+ /* Overwrite existing option */
+ old = ordered_hashmap_remove(network->dhcp_send_options, UINT_TO_PTR(u));
+ r = ordered_hashmap_put(network->dhcp_send_options, UINT_TO_PTR(u), opt);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Failed to store DHCP send option '%s'", rvalue);
+ return 0;
+ }
+
+ TAKE_PTR(opt);
+ return 0;
+}
+
static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
[DHCP_CLIENT_ID_MAC] = "mac",
[DHCP_CLIENT_ID_DUID] = "duid",
diff --git a/src/network/networkd-dhcp4.h b/src/network/networkd-dhcp4.h
index fce11ef671..dbaec18781 100644
--- a/src/network/networkd-dhcp4.h
+++ b/src/network/networkd-dhcp4.h
@@ -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_user_class);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_options);
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 689b1a123e..220564c5eb 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -168,6 +168,7 @@ DHCPv4.ListenPort, config_parse_uint16,
DHCPv4.SendRelease, config_parse_bool, 0, offsetof(Network, dhcp_send_release)
DHCPv4.BlackList, config_parse_dhcp_black_listed_ip_address, 0, 0
DHCPv4.IPServiceType, config_parse_ip_service_type, 0, offsetof(Network, ip_service_type)
+DHCPv4.SendOptions, config_parse_dhcp_send_options, 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)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 3ea76a034a..f18d611b36 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -619,6 +619,8 @@ static Network *network_free(Network *network) {
set_free_free(network->dnssec_negative_trust_anchors);
+ ordered_hashmap_free(network->dhcp_send_options);
+
return mfree(network);
}
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index 35469c05ed..86135c62e5 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -86,10 +86,11 @@ struct Network {
unsigned dhcp_route_metric;
uint32_t dhcp_route_table;
uint16_t dhcp_client_port;
+ int dhcp_critical;
+ int ip_service_type;
bool dhcp_anonymize;
bool dhcp_send_hostname;
bool dhcp_broadcast;
- int dhcp_critical;
bool dhcp_use_dns;
bool dhcp_routes_to_dns;
bool dhcp_use_ntp;
@@ -104,7 +105,7 @@ struct Network {
DHCPUseDomains dhcp_use_domains;
Set *dhcp_black_listed_ip;
Set *dhcp_request_options;
- int ip_service_type;
+ OrderedHashmap *dhcp_send_options;
/* DHCPv6 Client support*/
bool dhcp6_use_dns;