network: further unification of MUD url parsers

Follow-up for 89fa9a6b7b.
This commit is contained in:
Yu Watanabe
2021-07-14 15:47:40 +09:00
committed by Luca Boccassi
parent 534b5abce1
commit 77976a6877
6 changed files with 16 additions and 79 deletions

View File

@@ -1719,26 +1719,6 @@ 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) {
Network *network = data;
assert(network);
return config_parse_mud_url(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
&network->dhcp_mudurl);
}
int config_parse_dhcp_fallback_lease_lifetime(const char *unit,
const char *filename,
unsigned line,

View File

@@ -1788,26 +1788,6 @@ 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) {
Network *network = data;
assert(network);
return config_parse_mud_url(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
&network->dhcp6_mudurl);
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode,
"Failed to parse WithoutRA= setting");

View File

@@ -414,26 +414,6 @@ void link_lldp_emit_stop(Link *link) {
link->lldp_emit_event_source = sd_event_source_unref(link->lldp_emit_event_source);
}
int config_parse_lldp_mud(
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) {
Network *network = data;
assert(network);
return config_parse_mud_url(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
&network->lldp_mud);
}
static const char * const lldp_emit_table[_LLDP_EMIT_MAX] = {
[LLDP_EMIT_NO] = "no",
[LLDP_EMIT_NEAREST_BRIDGE] = "nearest-bridge",

View File

@@ -214,7 +214,7 @@ DHCPv4.SendHostname, config_parse_bool,
DHCPv4.Hostname, config_parse_hostname, 0, offsetof(Network, dhcp_hostname)
DHCPv4.RequestBroadcast, config_parse_tristate, 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.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.IAID, config_parse_iaid, AF_INET, 0
@@ -239,7 +239,7 @@ DHCPv6.UseHostname, config_parse_bool,
DHCPv6.UseDomains, config_parse_dhcp_use_domains, 0, 0
DHCPv6.UseNTP, config_parse_dhcp_use_ntp, 0, 0
DHCPv6.RapidCommit, config_parse_bool, 0, offsetof(Network, dhcp6_rapid_commit)
DHCPv6.MUDURL, config_parse_dhcp6_mud_url, 0, 0
DHCPv6.MUDURL, config_parse_mud_url, 0, offsetof(Network, dhcp6_mudurl)
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)
@@ -342,7 +342,7 @@ IPv6Prefix.Assign, config_parse_prefix_assign,
IPv6Prefix.RouteMetric, config_parse_prefix_metric, 0, 0
IPv6RoutePrefix.Route, config_parse_route_prefix, 0, 0
IPv6RoutePrefix.LifetimeSec, config_parse_route_prefix_lifetime, 0, 0
LLDP.MUDURL, config_parse_lldp_mud, 0, 0
LLDP.MUDURL, config_parse_mud_url, 0, offsetof(Network, lldp_mud)
CAN.BitRate, config_parse_can_bitrate, 0, offsetof(Network, can_bitrate)
CAN.SamplePoint, config_parse_permille, 0, offsetof(Network, can_sample_point)
CAN.DataBitRate, config_parse_can_bitrate, 0, offsetof(Network, can_data_bitrate)

View File

@@ -171,15 +171,22 @@ int config_parse_mud_url(
const char *lvalue,
int ltype,
const char *rvalue,
char **ret) {
void *data,
void *userdata) {
_cleanup_free_ char *unescaped = NULL;
char **url = data;
ssize_t l;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(ret);
assert(url);
_cleanup_free_ char *unescaped = NULL;
ssize_t l;
if (isempty(rvalue)) {
*url = mfree(*url);
return 0;
}
l = cunescape(rvalue, 0, &unescaped);
if (l < 0) {
@@ -194,7 +201,7 @@ int config_parse_mud_url(
return 0;
}
return free_and_replace(*ret, unescaped);
return free_and_replace(*url, unescaped);
}
/* Router lifetime can be set with netlink interface since kernel >= 4.5

View File

@@ -22,17 +22,7 @@ typedef struct NetworkConfigSection {
CONFIG_PARSER_PROTOTYPE(config_parse_link_local_address_family);
CONFIG_PARSER_PROTOTYPE(config_parse_address_family_with_kernel);
CONFIG_PARSER_PROTOTYPE(config_parse_ip_masquerade);
int config_parse_mud_url(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
char **ret);
CONFIG_PARSER_PROTOTYPE(config_parse_mud_url);
const char *address_family_to_string(AddressFamily b) _const_;
AddressFamily address_family_from_string(const char *s) _pure_;