optionally set socket priority on DHCPv4 raw socket

This commit is contained in:
chris
2023-01-12 13:26:47 +09:00
committed by Yu Watanabe
parent c24b0bd1df
commit ea57796854
12 changed files with 111 additions and 9 deletions
+42
View File
@@ -1499,6 +1499,12 @@ static int dhcp4_configure(Link *link) {
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set IP service type: %m");
}
if (link->network->dhcp_socket_priority_set) {
r = sd_dhcp_client_set_socket_priority(link->dhcp_client, link->network->dhcp_socket_priority);
if (r < 0)
return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set socket priority: %m");
}
if (link->network->dhcp_fallback_lease_lifetime > 0) {
r = sd_dhcp_client_set_fallback_lease_lifetime(link->dhcp_client, link->network->dhcp_fallback_lease_lifetime);
if (r < 0)
@@ -1701,6 +1707,42 @@ int config_parse_dhcp_ip_service_type(
return 0;
}
int config_parse_dhcp_socket_priority(
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 = ASSERT_PTR(data);
int a, r;
assert(lvalue);
assert(rvalue);
if (isempty(rvalue)) {
network->dhcp_socket_priority_set = false;
return 0;
}
r = safe_atoi(rvalue, &a);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse socket priority, ignoring: %s", rvalue);
return 0;
}
network->dhcp_socket_priority_set = true;
network->dhcp_socket_priority = a;
return 0;
}
int config_parse_dhcp_fallback_lease_lifetime(
const char *unit,
const char *filename,
+1
View File
@@ -29,6 +29,7 @@ int link_request_dhcp4_client(Link *link);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_client_identifier);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_max_attempts);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_ip_service_type);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_socket_priority);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_mud_url);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_fallback_lease_lifetime);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_label);
+1
View File
@@ -243,6 +243,7 @@ DHCPv4.SendDecline, config_parse_bool,
DHCPv4.DenyList, config_parse_in_addr_prefixes, AF_INET, offsetof(Network, dhcp_deny_listed_ip)
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.RouteMTUBytes, config_parse_mtu, AF_INET, offsetof(Network, dhcp_route_mtu)
+2
View File
@@ -130,6 +130,8 @@ struct Network {
uint16_t dhcp_client_port;
int dhcp_critical;
int dhcp_ip_service_type;
int dhcp_socket_priority;
bool dhcp_socket_priority_set;
bool dhcp_anonymize;
bool dhcp_send_hostname;
int dhcp_broadcast;