dhcp: use struct iovec_wrapper to manage user class
This commit is contained in:
@@ -636,7 +636,52 @@ int config_parse_iaid(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_dhcp_user_or_vendor_class(
|
||||
int config_parse_dhcp4_user_class(
|
||||
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_wrapper *iovw = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
iovw_done_free(iovw);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
|
||||
if (r < 0)
|
||||
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
size_t len = strlen(w);
|
||||
if (len > UINT8_MAX || len == 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"The length of the %s entry '%s' is not in the range 1…255, ignoring.", lvalue, w);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = iovw_consume(iovw, TAKE_PTR(w), len);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
int config_parse_dhcp6_user_or_vendor_class(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
@@ -653,7 +698,6 @@ int config_parse_dhcp_user_or_vendor_class(
|
||||
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(IN_SET(ltype, AF_INET, AF_INET6));
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*l = strv_free(*l);
|
||||
@@ -662,32 +706,18 @@ int config_parse_dhcp_user_or_vendor_class(
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *w = NULL;
|
||||
size_t len;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to split user classes option, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
len = strlen(w);
|
||||
if (ltype == AF_INET) {
|
||||
if (len > UINT8_MAX || len == 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"%s length is not in the range 1…255, ignoring.", w);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (len > UINT16_MAX || len == 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"%s length is not in the range 1…65535, ignoring.", w);
|
||||
continue;
|
||||
}
|
||||
size_t len = strlen(w);
|
||||
if (len > UINT16_MAX || len == 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"The length of the %s entry '%s' is not in the range 1…65535, ignoring.", lvalue, w);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = strv_consume(l, TAKE_PTR(w));
|
||||
|
||||
@@ -81,7 +81,8 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ndisc_route_metric);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_hostname);
|
||||
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_dhcp4_user_class);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_user_or_vendor_class);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_send_option);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_option);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_option_tlv);
|
||||
|
||||
@@ -1643,11 +1643,9 @@ static int dhcp4_configure(Link *link) {
|
||||
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set MUD URL: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp_user_class) {
|
||||
r = sd_dhcp_client_set_user_class(link->dhcp_client, link->network->dhcp_user_class);
|
||||
if (r < 0)
|
||||
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set user class: %m");
|
||||
}
|
||||
r = dhcp_client_set_user_class(link->dhcp_client, &link->network->dhcp_user_class);
|
||||
if (r < 0)
|
||||
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set user class: %m");
|
||||
}
|
||||
|
||||
if (link->network->dhcp_client_port > 0) {
|
||||
|
||||
@@ -278,7 +278,7 @@ DHCPv4.RequestBroadcast, config_parse_tristate,
|
||||
DHCPv4.VendorClassIdentifier, config_parse_string, CONFIG_PARSE_STRING_SAFE, offsetof(Network, dhcp_vendor_class_identifier)
|
||||
DHCPv4.MUDURL, config_parse_mud_url, 0, offsetof(Network, dhcp_mudurl)
|
||||
DHCPv4.MaxAttempts, config_parse_dhcp_max_attempts, 0, 0
|
||||
DHCPv4.UserClass, config_parse_dhcp_user_or_vendor_class, AF_INET, offsetof(Network, dhcp_user_class)
|
||||
DHCPv4.UserClass, config_parse_dhcp4_user_class, 0, offsetof(Network, dhcp_user_class)
|
||||
DHCPv4.IAID, config_parse_iaid, AF_INET, 0
|
||||
DHCPv4.DUIDType, config_parse_network_duid_type, 0, 0
|
||||
DHCPv4.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
|
||||
@@ -318,8 +318,8 @@ DHCPv6.MUDURL, config_parse_mud_url,
|
||||
DHCPv6.SendHostname, config_parse_dhcp_send_hostname, AF_INET6, 0
|
||||
DHCPv6.Hostname, config_parse_hostname, 0, offsetof(Network, dhcp6_hostname)
|
||||
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.UserClass, config_parse_dhcp6_user_or_vendor_class, 0, offsetof(Network, dhcp6_user_class)
|
||||
DHCPv6.VendorClass, config_parse_dhcp6_user_or_vendor_class, 0, offsetof(Network, dhcp6_vendor_class)
|
||||
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)
|
||||
@@ -664,7 +664,7 @@ DHCP.Hostname, config_parse_hostname,
|
||||
DHCP.RequestBroadcast, config_parse_tristate, 0, offsetof(Network, dhcp_broadcast)
|
||||
DHCP.CriticalConnection, config_parse_tristate, 0, offsetof(Network, dhcp_critical)
|
||||
DHCP.VendorClassIdentifier, config_parse_string, CONFIG_PARSE_STRING_SAFE, offsetof(Network, dhcp_vendor_class_identifier)
|
||||
DHCP.UserClass, config_parse_dhcp_user_or_vendor_class, AF_INET, offsetof(Network, dhcp_user_class)
|
||||
DHCP.UserClass, config_parse_dhcp4_user_class, 0, offsetof(Network, dhcp_user_class)
|
||||
DHCP.IAID, config_parse_iaid, AF_INET, 0
|
||||
DHCP.DUIDType, config_parse_network_duid_type, 0, 0
|
||||
DHCP.DUIDRawData, config_parse_network_duid_rawdata, 0, 0
|
||||
|
||||
@@ -786,7 +786,7 @@ static Network *network_free(Network *network) {
|
||||
free(network->dhcp_label);
|
||||
set_free(network->dhcp_deny_listed_ip);
|
||||
set_free(network->dhcp_allow_listed_ip);
|
||||
strv_free(network->dhcp_user_class);
|
||||
iovw_done_free(&network->dhcp_user_class);
|
||||
set_free(network->dhcp_request_options);
|
||||
tlv_done(&network->dhcp_extra_options);
|
||||
tlv_done(&network->dhcp_vendor_options);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "bridge.h"
|
||||
#include "firewall-util.h"
|
||||
#include "ipoib.h"
|
||||
#include "iovec-wrapper.h"
|
||||
#include "net-condition.h"
|
||||
#include "network-util.h"
|
||||
#include "networkd-bridge-vlan.h"
|
||||
@@ -124,7 +125,7 @@ typedef struct Network {
|
||||
bool dhcp_iaid_set;
|
||||
char *dhcp_vendor_class_identifier;
|
||||
char *dhcp_mudurl;
|
||||
char **dhcp_user_class;
|
||||
struct iovec_wrapper dhcp_user_class;
|
||||
char *dhcp_hostname;
|
||||
char *dhcp_label;
|
||||
uint64_t dhcp_max_attempts;
|
||||
|
||||
Reference in New Issue
Block a user