#include "network-common.h"
#include "sd-forward.h"
#include "socket-util.h"
+#include "tlv-util.h"
typedef enum DHCPState {
DHCP_STATE_STOPPED,
uint64_t discover_attempt;
uint64_t request_attempt;
uint64_t max_discover_attempts;
- OrderedHashmap *extra_options;
- OrderedHashmap *vendor_options;
+ TLV *extra_options;
+ TLV *vendor_options;
sd_event_source *timeout_t1;
sd_event_source *timeout_t2;
sd_event_source *timeout_expire;
void *userdata);
int dhcp_client_get_state(sd_dhcp_client *client);
+int dhcp_client_set_extra_options(sd_dhcp_client *client, TLV *options);
+int dhcp_client_set_vendor_options(sd_dhcp_client *client, TLV *options);
+
int client_receive_message_raw(
sd_event_source *s,
int fd,
#include "dns-domain.h"
#include "hostname-util.h"
#include "memory-util.h"
-#include "ordered-set.h"
#include "string-util.h"
#include "strv.h"
#include "utf8.h"
*offset += 3 + optlen;
break;
- case SD_DHCP_OPTION_VENDOR_SPECIFIC_INFORMATION: {
- /* When called with raw data (optlen > 0), e.g. from SendOption=, append as a plain TLV.
- * The structured handling below expects optval to be an OrderedSet*. */
- if (optlen > 0)
- return dhcp_option_append_tlv(options, size, offset, code, optlen, optval);
-
- OrderedSet *s = (OrderedSet *) optval;
- struct sd_dhcp_option *p;
- size_t l = 0;
-
- ORDERED_SET_FOREACH(p, s)
- l += p->length + 2;
-
- if (*offset + l + 2 > size)
- return -ENOBUFS;
-
- options[*offset] = code;
- options[*offset + 1] = l;
- *offset += 2;
-
- ORDERED_SET_FOREACH(p, s) {
- r = dhcp_option_append_tlv(options, size, offset, p->option, p->length, p->data);
- if (r < 0)
- return r;
- }
- break;
- }
case SD_DHCP_OPTION_RELAY_AGENT_INFORMATION: {
/* When called with raw data (optlen > 0), e.g. from SendOption=, append as a plain TLV.
* The structured handling below expects optval to be an sd_dhcp_server*. */
#include "sd-forward.h"
#include "network-common.h"
#include "sparse-endian.h"
+#include "tlv-util.h"
typedef enum DHCPRawOption {
DHCP_RAW_OPTION_DATA_UINT8,
char *boot_server_name;
char *boot_filename;
- OrderedSet *extra_options;
- OrderedSet *vendor_options;
+ TLV *extra_options;
+ TLV *vendor_options;
bool emit_router;
struct in_addr router_address;
triple_timestamp timestamp;
} DHCPRequest;
+int dhcp_server_set_extra_options(sd_dhcp_server *server, TLV *options);
+int dhcp_server_set_vendor_options(sd_dhcp_server *server, TLV *options);
+
int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
size_t length, const triple_timestamp *timestamp);
int dhcp_server_send_packet(sd_dhcp_server *server,
#include "event-util.h"
#include "hostname-util.h"
#include "iovec-util.h"
+#include "iovec-wrapper.h"
#include "memory-util.h"
#include "network-common.h"
#include "random-util.h"
return 0;
}
-int sd_dhcp_client_add_option(sd_dhcp_client *client, sd_dhcp_option *v) {
- int r;
-
- assert_return(client, -EINVAL);
- assert_return(!sd_dhcp_client_is_running(client), -EBUSY);
- assert_return(v, -EINVAL);
-
- r = ordered_hashmap_ensure_put(&client->extra_options, &dhcp_option_hash_ops, UINT_TO_PTR(v->option), v);
- if (r < 0)
- return r;
+int dhcp_client_set_extra_options(sd_dhcp_client *client, TLV *options) {
+ assert(client);
+ assert(!sd_dhcp_client_is_running(client));
- sd_dhcp_option_ref(v);
- return 0;
+ return unref_and_replace_new_ref(client->extra_options, options, tlv_ref, tlv_unref);
}
-int sd_dhcp_client_add_vendor_option(sd_dhcp_client *client, sd_dhcp_option *v) {
- int r;
-
- assert_return(client, -EINVAL);
- assert_return(!sd_dhcp_client_is_running(client), -EBUSY);
- assert_return(v, -EINVAL);
-
- r = ordered_hashmap_ensure_allocated(&client->vendor_options, &dhcp_option_hash_ops);
- if (r < 0)
- return -ENOMEM;
-
- r = ordered_hashmap_put(client->vendor_options, v, v);
- if (r < 0)
- return r;
-
- sd_dhcp_option_ref(v);
+int dhcp_client_set_vendor_options(sd_dhcp_client *client, TLV *options) {
+ assert(client);
+ assert(!sd_dhcp_client_is_running(client));
- return 1;
+ return unref_and_replace_new_ref(client->vendor_options, options, tlv_ref, tlv_unref);
}
int sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret) {
}
static int client_append_common_discover_request_options(sd_dhcp_client *client, DHCPPacket *packet, size_t *optoffset, size_t optlen) {
- sd_dhcp_option *j;
int r;
assert(client);
return r;
}
- ORDERED_HASHMAP_FOREACH(j, client->extra_options) {
- r = dhcp_option_append(&packet->dhcp, optlen, optoffset, 0,
- j->option, j->length, j->data);
+ if (client->extra_options) {
+ void *key;
+ struct iovec_wrapper *iovw;
+ HASHMAP_FOREACH_KEY(iovw, key, client->extra_options->entries) {
+ uint32_t tag = PTR_TO_UINT32(key);
+
+ FOREACH_ARRAY(iov, iovw->iovec, iovw->count) {
+ r = dhcp_option_append(&packet->dhcp, optlen, optoffset, 0,
+ tag, iov->iov_len, iov->iov_base);
+ if (r < 0)
+ return r;
+ }
+ }
+ }
+
+ if (!tlv_isempty(client->vendor_options)) {
+ _cleanup_(iovec_done) struct iovec iov = {};
+ r = tlv_build(client->vendor_options, &iov);
if (r < 0)
return r;
- }
- if (!ordered_hashmap_isempty(client->vendor_options)) {
r = dhcp_option_append(
&packet->dhcp, optlen, optoffset, 0,
SD_DHCP_OPTION_VENDOR_SPECIFIC_INFORMATION,
- /* optlen= */ 0, client->vendor_options);
+ iov.iov_len, iov.iov_base);
if (r < 0)
return r;
}
free(client->vendor_class_identifier);
free(client->mudurl);
client->user_class = strv_free(client->user_class);
- ordered_hashmap_free(client->extra_options);
- ordered_hashmap_free(client->vendor_options);
+ tlv_unref(client->extra_options);
+ tlv_unref(client->vendor_options);
free(client->ifname);
return mfree(client);
}
#include "dns-domain.h"
#include "errno-util.h"
#include "fd-util.h"
+#include "hashmap.h"
#include "in-addr-util.h"
#include "iovec-util.h"
+#include "iovec-wrapper.h"
#include "memory-util.h"
#include "network-common.h"
-#include "ordered-set.h"
#include "path-util.h"
#include "siphash24.h"
#include "socket-util.h"
server->static_leases_by_address = hashmap_free(server->static_leases_by_address);
server->static_leases_by_client_id = hashmap_free(server->static_leases_by_client_id);
- ordered_set_free(server->extra_options);
- ordered_set_free(server->vendor_options);
+ tlv_unref(server->extra_options);
+ tlv_unref(server->vendor_options);
free(server->agent_circuit_id);
free(server->agent_remote_id);
};
_cleanup_free_ DHCPPacket *packet = NULL;
- sd_dhcp_option *j;
be32_t lease_time;
size_t offset;
int r;
return r;
}
- ORDERED_SET_FOREACH(j, server->extra_options) {
- r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
- j->option, j->length, j->data);
+ if (server->extra_options) {
+ void *key;
+ struct iovec_wrapper *iovw;
+ HASHMAP_FOREACH_KEY(iovw, key, server->extra_options->entries) {
+ uint32_t tag = PTR_TO_UINT32(key);
+
+ FOREACH_ARRAY(iov, iovw->iovec, iovw->count) {
+ r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
+ tag, iov->iov_len, iov->iov_base);
+ if (r < 0)
+ return r;
+ }
+ }
+ }
+
+ if (!tlv_isempty(server->vendor_options)) {
+ _cleanup_(iovec_done) struct iovec iov = {};
+ r = tlv_build(server->vendor_options, &iov);
if (r < 0)
return r;
- }
- if (!ordered_set_isempty(server->vendor_options)) {
r = dhcp_option_append(
&packet->dhcp, req->max_optlen, &offset, 0,
SD_DHCP_OPTION_VENDOR_SPECIFIC_INFORMATION,
- /* optlen= */ 0, server->vendor_options);
+ iov.iov_len, iov.iov_base);
if (r < 0)
return r;
}
return 0;
}
-int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v) {
- int r;
-
- assert_return(server, -EINVAL);
- assert_return(v, -EINVAL);
-
- r = ordered_set_ensure_put(&server->extra_options, &dhcp_option_hash_ops, v);
- if (r < 0)
- return r;
-
- sd_dhcp_option_ref(v);
- return 0;
+int dhcp_server_set_extra_options(sd_dhcp_server *server, TLV *options) {
+ assert(server);
+ return unref_and_replace_new_ref(server->extra_options, options, tlv_ref, tlv_unref);
}
-int sd_dhcp_server_add_vendor_option(sd_dhcp_server *server, sd_dhcp_option *v) {
- int r;
-
- assert_return(server, -EINVAL);
- assert_return(v, -EINVAL);
-
- r = ordered_set_ensure_put(&server->vendor_options, &dhcp_option_hash_ops, v);
- if (r < 0)
- return r;
-
- sd_dhcp_option_ref(v);
-
- return 1;
+int dhcp_server_set_vendor_options(sd_dhcp_server *server, TLV *options) {
+ assert(server);
+ return unref_and_replace_new_ref(server->vendor_options, options, tlv_ref, tlv_unref);
}
int sd_dhcp_server_set_callback(sd_dhcp_server *server, sd_dhcp_server_callback_t cb, void *userdata) {
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
-#include "dhcp-option.h"
#include "dhcp6-option.h"
#include "escape.h"
#include "extract-word.h"
#include "hexdecoct.h"
#include "in-addr-prefix-util.h"
+#include "iovec-util.h"
#include "networkd-dhcp-common.h"
#include "networkd-dhcp-prefix-delegation.h"
#include "networkd-link.h"
}
}
-int config_parse_dhcp_send_option(
+int config_parse_dhcp6_send_option(
const char *unit,
const char *filename,
unsigned line,
void *data,
void *userdata) {
- _cleanup_(sd_dhcp_option_unrefp) sd_dhcp_option *opt4 = NULL;
_cleanup_(sd_dhcp6_option_unrefp) sd_dhcp6_option *opt6 = NULL;
- _unused_ _cleanup_(sd_dhcp_option_unrefp) sd_dhcp_option *old4 = NULL;
_unused_ _cleanup_(sd_dhcp6_option_unrefp) sd_dhcp6_option *old6 = NULL;
uint32_t uint32_data, enterprise_identifier = 0;
_cleanup_free_ char *word = NULL, *q = NULL;
- OrderedHashmap **options = ASSERT_PTR(data);
+ OrderedHashmap **dhcp6_options = ASSERT_PTR(data);
uint16_t u16, uint16_data;
union in_addr_union addr;
DHCPOptionDataType type;
- uint8_t u8, uint8_data;
+ uint8_t uint8_data;
const void *udata;
const char *p;
ssize_t sz;
assert(rvalue);
if (isempty(rvalue)) {
- *options = ordered_hashmap_free(*options);
+ *dhcp6_options = ordered_hashmap_free(*dhcp6_options);
return 0;
}
p = rvalue;
- if (ltype == AF_INET6 && streq(lvalue, "SendVendorOption")) {
+ if (streq(lvalue, "SendVendorOption")) {
r = extract_first_word(&p, &word, ":", 0);
if (r == -ENOMEM)
return log_oom();
return 0;
}
- if (ltype == AF_INET6) {
- r = safe_atou16(word, &u16);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid DHCP option, ignoring assignment: %s", rvalue);
- return 0;
- }
- if (u16 < 1 || u16 >= UINT16_MAX) {
- log_syntax(unit, LOG_WARNING, filename, line, 0,
- "Invalid DHCP option, valid range is 1-65535, ignoring assignment: %s", rvalue);
- return 0;
- }
- } else {
- r = safe_atou8(word, &u8);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid DHCP option, ignoring assignment: %s", rvalue);
- return 0;
- }
- if (u8 < 1 || u8 >= UINT8_MAX) {
- log_syntax(unit, LOG_WARNING, filename, line, 0,
- "Invalid DHCP option, valid range is 1-254, ignoring assignment: %s", rvalue);
- return 0;
- }
+ r = safe_atou16(word, &u16);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Invalid DHCP option, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+ if (u16 < 1 || u16 >= UINT16_MAX) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0,
+ "Invalid DHCP option, valid range is 1-65535, ignoring assignment: %s", rvalue);
+ return 0;
}
word = mfree(word);
return -EINVAL;
}
- if (ltype == AF_INET6) {
- r = sd_dhcp6_option_new(u16, udata, sz, enterprise_identifier, &opt6);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Failed to store DHCP option '%s', ignoring assignment: %m", rvalue);
- return 0;
- }
+ r = sd_dhcp6_option_new(u16, udata, sz, enterprise_identifier, &opt6);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Failed to store DHCP option '%s', ignoring assignment: %m", rvalue);
+ return 0;
+ }
+
+ r = ordered_hashmap_ensure_allocated(dhcp6_options, &dhcp6_option_hash_ops);
+ if (r < 0)
+ return log_oom();
+
+ /* Overwrite existing option */
+ old6 = ordered_hashmap_get(*dhcp6_options, UINT_TO_PTR(u16));
+ r = ordered_hashmap_replace(*dhcp6_options, UINT_TO_PTR(u16), opt6);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Failed to store DHCP option '%s', ignoring assignment: %m", rvalue);
+ return 0;
+ }
+ TAKE_PTR(opt6);
- r = ordered_hashmap_ensure_allocated(options, &dhcp6_option_hash_ops);
+ return 0;
+}
+
+int config_parse_dhcp_option(
+ 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) {
+
+ struct iovec *iov = ASSERT_PTR(data);
+ bool check_length = ltype;
+ int r;
+
+ if (isempty(rvalue)) {
+ iovec_done(iov);
+ return 0;
+ }
+
+ _cleanup_free_ char *word = NULL;
+ const char *p = rvalue;
+ r = extract_first_word(&p, &word, ":", 0);
+ if (r == -ENOMEM)
+ return log_oom();
+ if (r <= 0 || isempty(p))
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+ DHCPOptionDataType type = dhcp_option_data_type_from_string(word);
+ if (type < 0)
+ return log_syntax_parse_error(unit, filename, line, type, lvalue, rvalue);
+
+ switch (type) {
+ case DHCP_OPTION_DATA_UINT8:{
+ uint8_t u;
+
+ r = safe_atou8(p, &u);
+ if (r < 0)
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+ r = iovec_done_and_memdup(iov, &IOVEC_MAKE(&u, sizeof(u)));
if (r < 0)
return log_oom();
- /* Overwrite existing option */
- old6 = ordered_hashmap_get(*options, UINT_TO_PTR(u16));
- r = ordered_hashmap_replace(*options, UINT_TO_PTR(u16), opt6);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Failed to store DHCP option '%s', ignoring assignment: %m", rvalue);
- return 0;
- }
- TAKE_PTR(opt6);
- } else {
- r = sd_dhcp_option_new(u8, udata, sz, &opt4);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Failed to store DHCP option '%s', ignoring assignment: %m", rvalue);
- return 0;
- }
+ return 1;
+ }
+ case DHCP_OPTION_DATA_UINT16:{
+ uint16_t u;
- r = ordered_hashmap_ensure_allocated(options, &dhcp_option_hash_ops);
+ r = safe_atou16(p, &u);
+ if (r < 0)
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+ u = htobe16(u);
+ r = iovec_done_and_memdup(iov, &IOVEC_MAKE(&u, sizeof(u)));
if (r < 0)
return log_oom();
- /* Overwrite existing option */
- old4 = ordered_hashmap_get(*options, UINT_TO_PTR(u8));
- r = ordered_hashmap_replace(*options, UINT_TO_PTR(u8), opt4);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Failed to store DHCP option '%s', ignoring assignment: %m", rvalue);
- return 0;
- }
- TAKE_PTR(opt4);
+ return 1;
+ }
+ case DHCP_OPTION_DATA_UINT32: {
+ uint32_t u;
+
+ r = safe_atou32(p, &u);
+ if (r < 0)
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+ u = htobe32(u);
+ r = iovec_done_and_memdup(iov, &IOVEC_MAKE(&u, sizeof(u)));
+ if (r < 0)
+ return log_oom();
+
+ return 1;
+ }
+ case DHCP_OPTION_DATA_IPV4ADDRESS: {
+ union in_addr_union a;
+
+ r = in_addr_from_string(AF_INET, p, &a);
+ if (r < 0)
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+ r = iovec_done_and_memdup(iov, &IOVEC_MAKE(&a.in, sizeof(a.in)));
+ if (r < 0)
+ return log_oom();
+
+ return 1;
+ }
+ case DHCP_OPTION_DATA_IPV6ADDRESS: {
+ union in_addr_union a;
+
+ r = in_addr_from_string(AF_INET6, p, &a);
+ if (r < 0)
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+ r = iovec_done_and_memdup(iov, &IOVEC_MAKE(&a.in6, sizeof(a.in6)));
+ if (r < 0)
+ return log_oom();
+
+ return 1;
+ }
+ case DHCP_OPTION_DATA_STRING: {
+ _cleanup_free_ char *s = NULL;
+ ssize_t sz = cunescape(p, UNESCAPE_ACCEPT_NUL, &s);
+ if (sz < 0)
+ return log_syntax_parse_error(unit, filename, line, sz, lvalue, rvalue);
+ if (check_length && sz > UINT8_MAX)
+ return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue);
+
+ iovec_done(iov);
+ *iov = IOVEC_MAKE(TAKE_PTR(s), sz);
+ return 1;
+ }
+ default:
+ return -EINVAL;
}
+}
+
+int config_parse_dhcp_option_tlv(
+ 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) {
+
+ TLV *options = ASSERT_PTR(data);
+ int r;
+
+ if (isempty(rvalue)) {
+ tlv_done(options);
+ return 0;
+ }
+
+ _cleanup_free_ char *word = NULL;
+ const char *p = rvalue;
+ r = extract_first_word(&p, &word, ":", 0);
+ if (r == -ENOMEM)
+ return log_oom();
+ if (r <= 0 || isempty(p))
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+ uint8_t code;
+ r = safe_atou8(word, &code);
+ if (r < 0)
+ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+ if (code < 1 || code >= UINT8_MAX)
+ return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue);
+
+ _cleanup_(iovec_done) struct iovec iov = {};
+ r = config_parse_dhcp_option(unit, filename, line, section, section_line, lvalue, ltype, p, &iov, userdata);
+ if (r <= 0)
+ return r;
+
+ r = tlv_append_iov(options, code, &iov);
+ if (r < 0)
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Failed to store '%s=%s', ignoring assignment: %m", lvalue, rvalue);
+
return 0;
}
CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_or_ra_route_table);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_or_vendor_class);
-CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_send_option);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_option);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_option_tlv);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_request_options);
CONFIG_PARSER_PROTOTYPE(config_parse_duid_type);
CONFIG_PARSER_PROTOTYPE(config_parse_manager_duid_type);
#include "conf-parser.h"
#include "dhcp-protocol.h"
+#include "dhcp-server-internal.h"
#include "dhcp-server-lease-internal.h"
#include "dns-domain.h"
#include "errno-util.h"
static int dhcp4_server_configure(Link *link) {
bool acquired_uplink = false;
- sd_dhcp_option *p;
DHCPStaticLease *static_lease;
Link *uplink = NULL;
Address *address;
else if (r < 0)
return log_link_error_errno(link, r, "Failed to set domain name for DHCP server: %m");
- ORDERED_HASHMAP_FOREACH(p, link->network->dhcp_server_send_options) {
- r = sd_dhcp_server_add_option(link->dhcp_server, p);
- if (r == -EEXIST)
- continue;
- if (r < 0)
- return log_link_error_errno(link, r, "Failed to set DHCPv4 option: %m");
- }
+ r = dhcp_server_set_extra_options(link->dhcp_server, &link->network->dhcp_server_extra_options);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to set DHCPv4 extra options: %m");
- ORDERED_HASHMAP_FOREACH(p, link->network->dhcp_server_send_vendor_options) {
- r = sd_dhcp_server_add_vendor_option(link->dhcp_server, p);
- if (r == -EEXIST)
- continue;
- if (r < 0)
- return log_link_error_errno(link, r, "Failed to set DHCPv4 option: %m");
- }
+ r = dhcp_server_set_vendor_options(link->dhcp_server, &link->network->dhcp_server_vendor_options);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to set DHCPv4 vendor options: %m");
HASHMAP_FOREACH(static_lease, link->network->dhcp_static_leases_by_section) {
r = sd_dhcp_server_set_static_lease(
}
static int dhcp4_configure(Link *link) {
- sd_dhcp_option *send_option;
void *request_options;
int r;
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for '%u': %m", option);
}
- ORDERED_HASHMAP_FOREACH(send_option, link->network->dhcp_client_send_options) {
- r = sd_dhcp_client_add_option(link->dhcp_client, send_option);
- if (r == -EEXIST)
- continue;
- if (r < 0)
- return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set send option: %m");
- }
+ r = dhcp_client_set_extra_options(link->dhcp_client, &link->network->dhcp_extra_options);
+ if (r < 0)
+ return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set extra options: %m");
- ORDERED_HASHMAP_FOREACH(send_option, link->network->dhcp_client_send_vendor_options) {
- r = sd_dhcp_client_add_vendor_option(link->dhcp_client, send_option);
- if (r == -EEXIST)
- continue;
- if (r < 0)
- return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set send option: %m");
- }
+ r = dhcp_client_set_vendor_options(link->dhcp_client, &link->network->dhcp_vendor_options);
+ if (r < 0)
+ return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set vendor options: %m");
r = dhcp4_set_hostname(link);
if (r < 0)
DHCPv4.AllowList, config_parse_in_addr_prefixes, AF_INET, offsetof(Network, dhcp_allow_listed_ip)
DHCPv4.IPServiceType, config_parse_dhcp_ip_service_type, 0, offsetof(Network, dhcp_ip_service_type)
DHCPv4.SocketPriority, config_parse_dhcp_socket_priority, 0, 0
-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.SendOption, config_parse_dhcp_option_tlv, 0, offsetof(Network, dhcp_extra_options)
+DHCPv4.SendVendorOption, config_parse_dhcp_option_tlv, 0, offsetof(Network, dhcp_vendor_options)
DHCPv4.RouteMTUBytes, config_parse_mtu, AF_INET, offsetof(Network, dhcp_route_mtu)
DHCPv4.InitialCongestionWindow, config_parse_tcp_window, 0, offsetof(Network, dhcp_initial_congestion_window)
DHCPv4.InitialAdvertisedReceiveWindow, config_parse_tcp_window, 0, offsetof(Network, dhcp_advertised_receive_window)
DHCPv6.RequestOptions, config_parse_dhcp_request_options, AF_INET6, 0
DHCPv6.UserClass, config_parse_dhcp_user_or_vendor_class, AF_INET6, offsetof(Network, dhcp6_user_class)
DHCPv6.VendorClass, config_parse_dhcp_user_or_vendor_class, AF_INET6, offsetof(Network, dhcp6_vendor_class)
-DHCPv6.SendVendorOption, config_parse_dhcp_send_option, AF_INET6, offsetof(Network, dhcp6_client_send_vendor_options)
+DHCPv6.SendVendorOption, config_parse_dhcp6_send_option, 0, offsetof(Network, dhcp6_client_send_vendor_options)
DHCPv6.PrefixDelegationHint, config_parse_dhcp6_pd_prefix_hint, 0, 0
DHCPv6.UnassignedSubnetPolicy, config_parse_dhcp_pd_prefix_route_type, 0, offsetof(Network, dhcp6_pd_prefix_route_type)
DHCPv6.WithoutRA, config_parse_dhcp6_client_start_mode, 0, offsetof(Network, dhcp6_client_start_mode)
-DHCPv6.SendOption, config_parse_dhcp_send_option, AF_INET6, offsetof(Network, dhcp6_client_send_options)
+DHCPv6.SendOption, config_parse_dhcp6_send_option, 0, offsetof(Network, dhcp6_client_send_options)
DHCPv6.IAID, config_parse_iaid, AF_INET6, 0
DHCPv6.DUIDType, config_parse_duid_type, 0, offsetof(Network, dhcp6_duid)
DHCPv6.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Network, dhcp6_duid)
DHCPServer.Domain, config_parse_dns_name, 0, offsetof(Network, dhcp_server_domain)
DHCPServer.PoolOffset, config_parse_uint32, 0, offsetof(Network, dhcp_server_pool_offset)
DHCPServer.PoolSize, config_parse_uint32, 0, offsetof(Network, dhcp_server_pool_size)
-DHCPServer.SendVendorOption, config_parse_dhcp_send_option, 0, offsetof(Network, dhcp_server_send_vendor_options)
-DHCPServer.SendOption, config_parse_dhcp_send_option, 0, offsetof(Network, dhcp_server_send_options)
+DHCPServer.SendOption, config_parse_dhcp_option_tlv, 0, offsetof(Network, dhcp_server_extra_options)
+DHCPServer.SendVendorOption, config_parse_dhcp_option_tlv, 0, offsetof(Network, dhcp_server_vendor_options)
DHCPServer.BindToInterface, config_parse_bool, 0, offsetof(Network, dhcp_server_bind_to_interface)
DHCPServer.BootServerAddress, config_parse_in_addr_non_null, AF_INET, offsetof(Network, dhcp_server_boot_server_address)
DHCPServer.BootServerName, config_parse_dns_name, 0, offsetof(Network, dhcp_server_boot_server_name)
.dhcp_use_gateway = -1,
.dhcp_send_hostname = true,
.dhcp_send_release = true,
+ .dhcp_extra_options = TLV_INIT(TLV_DHCP4),
+ .dhcp_vendor_options = TLV_INIT(TLV_DHCP4_SUBOPTION),
.dhcp_route_metric = DHCP_ROUTE_METRIC,
.dhcp_use_rapid_commit = -1,
.dhcp_client_identifier = _DHCP_CLIENT_ID_INVALID,
.dhcp_server_emit_router = true,
.dhcp_server_emit_timezone = true,
.dhcp_server_rapid_commit = true,
+ .dhcp_server_extra_options = TLV_INIT(TLV_DHCP4),
+ .dhcp_server_vendor_options = TLV_INIT(TLV_DHCP4_SUBOPTION),
.dhcp_server_persist_leases = _DHCP_SERVER_PERSIST_LEASES_INVALID,
.router_lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC,
free(network->dhcp_server_uplink_name);
for (sd_dhcp_lease_server_type_t t = 0; t < _SD_DHCP_LEASE_SERVER_TYPE_MAX; t++)
free(network->dhcp_server_emit[t].addresses);
- ordered_hashmap_free(network->dhcp_server_send_options);
- ordered_hashmap_free(network->dhcp_server_send_vendor_options);
+ tlv_done(&network->dhcp_server_extra_options);
+ tlv_done(&network->dhcp_server_vendor_options);
free(network->dhcp_server_local_lease_domain);
/* DHCP client */
set_free(network->dhcp_allow_listed_ip);
strv_free(network->dhcp_user_class);
set_free(network->dhcp_request_options);
- ordered_hashmap_free(network->dhcp_client_send_options);
- ordered_hashmap_free(network->dhcp_client_send_vendor_options);
+ tlv_done(&network->dhcp_extra_options);
+ tlv_done(&network->dhcp_vendor_options);
free(network->dhcp_netlabel);
nft_set_context_clear(&network->dhcp_nft_set_context);
#include "networkd-sysctl.h"
#include "networkd-wwan-bus.h"
#include "resolve-util.h"
+#include "tlv-util.h"
typedef enum KeepConfiguration {
KEEP_CONFIGURATION_NO = 0,
Set *dhcp_deny_listed_ip;
Set *dhcp_allow_listed_ip;
Set *dhcp_request_options;
- OrderedHashmap *dhcp_client_send_options;
- OrderedHashmap *dhcp_client_send_vendor_options;
+ TLV dhcp_extra_options;
+ TLV dhcp_vendor_options;
char *dhcp_netlabel;
NFTSetContext dhcp_nft_set_context;
usec_t dhcp_server_default_lease_time_usec, dhcp_server_max_lease_time_usec;
uint32_t dhcp_server_pool_offset;
uint32_t dhcp_server_pool_size;
- OrderedHashmap *dhcp_server_send_options;
- OrderedHashmap *dhcp_server_send_vendor_options;
+ TLV dhcp_server_extra_options;
+ TLV dhcp_server_vendor_options;
struct in_addr dhcp_server_boot_server_address;
char *dhcp_server_boot_server_name;
char *dhcp_server_boot_filename;
int bootp);
int sd_dhcp_client_set_send_release(sd_dhcp_client *client, int enable);
-int sd_dhcp_client_add_option(sd_dhcp_client *client, sd_dhcp_option *v);
-int sd_dhcp_client_add_vendor_option(sd_dhcp_client *client, sd_dhcp_option *v);
-
int sd_dhcp_client_is_running(sd_dhcp_client *client);
int sd_dhcp_client_stop(sd_dhcp_client *client);
int sd_dhcp_client_start(sd_dhcp_client *client);
int sd_dhcp_server_set_pop3(sd_dhcp_server *server, const struct in_addr pop3[], size_t n);
int sd_dhcp_server_set_smtp(sd_dhcp_server *server, const struct in_addr smtp[], size_t n);
-int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v);
-int sd_dhcp_server_add_vendor_option(sd_dhcp_server *server, sd_dhcp_option *v);
int sd_dhcp_server_set_static_lease(
sd_dhcp_server *server,
const struct in_addr *address,