Merge pull request #23927 from AndreKalb/feature/ipv4-link-local-start-address
network: Feature IPv4 link-local start address
This commit is contained in:
@@ -1071,6 +1071,12 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
|
||||
if (link->ipv4ll) {
|
||||
log_link_debug(link, "DHCP client is stopped. Acquiring IPv4 link-local address");
|
||||
|
||||
if (in4_addr_is_set(&link->network->ipv4ll_start_address)) {
|
||||
r = sd_ipv4ll_set_address(link->ipv4ll, &link->network->ipv4ll_start_address);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set IPv4 link-local start address: %m");;
|
||||
}
|
||||
|
||||
r = sd_ipv4ll_start(link->ipv4ll);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m");
|
||||
@@ -1154,6 +1160,12 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
|
||||
if (link->ipv4ll && !sd_ipv4ll_is_running(link->ipv4ll)) {
|
||||
log_link_debug(link, "Problems acquiring DHCP lease, acquiring IPv4 link-local address");
|
||||
|
||||
if (in4_addr_is_set(&link->network->ipv4ll_start_address)) {
|
||||
r = sd_ipv4ll_set_address(link->ipv4ll, &link->network->ipv4ll_start_address);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set IPv4 link-local start address: %m");;
|
||||
}
|
||||
|
||||
r = sd_ipv4ll_start(link->ipv4ll);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m");
|
||||
|
||||
@@ -263,3 +263,44 @@ int config_parse_ipv4ll(
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_ipv4ll_address(
|
||||
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) {
|
||||
|
||||
union in_addr_union a;
|
||||
struct in_addr *ipv4ll_address = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*ipv4ll_address = (struct in_addr) {};
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = in_addr_from_string(AF_INET, rvalue, &a);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (!in4_addr_is_link_local(&a.in)) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Not a IPv4 link local address, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*ipv4ll_address = a.in;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,3 +11,4 @@ int ipv4ll_configure(Link *link);
|
||||
int ipv4ll_update_mac(Link *link);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ipv4ll_address);
|
||||
|
||||
@@ -611,6 +611,12 @@ static int link_acquire_dynamic_ipv4_conf(Link *link) {
|
||||
log_link_debug(link, "Acquiring DHCPv4 lease.");
|
||||
|
||||
} else if (link->ipv4ll) {
|
||||
if (in4_addr_is_set(&link->network->ipv4ll_start_address)) {
|
||||
r = sd_ipv4ll_set_address(link->ipv4ll, &link->network->ipv4ll_start_address);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set IPv4 link-local start address: %m");
|
||||
}
|
||||
|
||||
r = sd_ipv4ll_start(link->ipv4ll);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m");
|
||||
|
||||
@@ -106,6 +106,7 @@ Network.DHCPServer, config_parse_bool,
|
||||
Network.LinkLocalAddressing, config_parse_link_local_address_family, 0, offsetof(Network, link_local)
|
||||
Network.IPv6LinkLocalAddressGenerationMode, config_parse_ipv6_link_local_address_gen_mode, 0, offsetof(Network, ipv6ll_address_gen_mode)
|
||||
Network.IPv6StableSecretAddress, config_parse_in_addr_non_null, AF_INET6, offsetof(Network, ipv6ll_stable_secret)
|
||||
Network.IPv4LLStartAddress, config_parse_ipv4ll_address, 0, offsetof(Network, ipv4ll_start_address)
|
||||
Network.IPv4LLRoute, config_parse_bool, 0, offsetof(Network, ipv4ll_route)
|
||||
Network.DefaultRouteOnDevice, config_parse_bool, 0, offsetof(Network, default_route_on_device)
|
||||
Network.LLDP, config_parse_lldp_mode, 0, offsetof(Network, lldp_mode)
|
||||
|
||||
@@ -208,6 +208,7 @@ struct Network {
|
||||
AddressFamily link_local;
|
||||
IPv6LinkLocalAddressGenMode ipv6ll_address_gen_mode;
|
||||
struct in6_addr ipv6ll_stable_secret;
|
||||
struct in_addr ipv4ll_start_address;
|
||||
bool ipv4ll_route;
|
||||
|
||||
/* IPv6 RA support */
|
||||
|
||||
Reference in New Issue
Block a user