networkd: link - (de)serialize IPv4LL and DHCPv4 addresses
This initializes the clients to try rebinding the preexisting addresses before doing anything else.
This commit is contained in:
parent
c4a03a5669
commit
0bc70f1d9c
|
@ -533,9 +533,11 @@ int dhcp4_configure(Link *link) {
|
||||||
assert(link->network);
|
assert(link->network);
|
||||||
assert(link->network->dhcp & ADDRESS_FAMILY_IPV4);
|
assert(link->network->dhcp & ADDRESS_FAMILY_IPV4);
|
||||||
|
|
||||||
r = sd_dhcp_client_new(&link->dhcp_client);
|
if (!link->dhcp_client) {
|
||||||
if (r < 0)
|
r = sd_dhcp_client_new(&link->dhcp_client);
|
||||||
return r;
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
r = sd_dhcp_client_attach_event(link->dhcp_client, NULL, 0);
|
r = sd_dhcp_client_attach_event(link->dhcp_client, NULL, 0);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
|
@ -208,9 +208,11 @@ int ipv4ll_configure(Link *link) {
|
||||||
assert(link->network);
|
assert(link->network);
|
||||||
assert(link->network->link_local & ADDRESS_FAMILY_IPV4);
|
assert(link->network->link_local & ADDRESS_FAMILY_IPV4);
|
||||||
|
|
||||||
r = sd_ipv4ll_new(&link->ipv4ll);
|
if (!link->ipv4ll) {
|
||||||
if (r < 0)
|
r = sd_ipv4ll_new(&link->ipv4ll);
|
||||||
return r;
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
if (link->udev_device) {
|
if (link->udev_device) {
|
||||||
r = net_get_unique_predictable_data(link->udev_device, seed);
|
r = net_get_unique_predictable_data(link->udev_device, seed);
|
||||||
|
|
|
@ -2133,7 +2133,11 @@ int link_initialized(Link *link, struct udev_device *device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int link_load(Link *link) {
|
static int link_load(Link *link) {
|
||||||
_cleanup_free_ char *network_file = NULL, *addresses = NULL;
|
_cleanup_free_ char *network_file = NULL,
|
||||||
|
*addresses = NULL,
|
||||||
|
*dhcp4_address = NULL,
|
||||||
|
*ipv4ll_address = NULL;
|
||||||
|
union in_addr_union address;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(link);
|
assert(link);
|
||||||
|
@ -2141,6 +2145,8 @@ static int link_load(Link *link) {
|
||||||
r = parse_env_file(link->state_file, NEWLINE,
|
r = parse_env_file(link->state_file, NEWLINE,
|
||||||
"NETWORK_FILE", &network_file,
|
"NETWORK_FILE", &network_file,
|
||||||
"ADDRESSES", &addresses,
|
"ADDRESSES", &addresses,
|
||||||
|
"DHCP4_ADDRESS", &dhcp4_address,
|
||||||
|
"IPV4LL_ADDRESS", &ipv4ll_address,
|
||||||
NULL);
|
NULL);
|
||||||
if (r < 0 && r != -ENOENT)
|
if (r < 0 && r != -ENOENT)
|
||||||
return log_link_error_errno(link, r, "Failed to read %s: %m", link->state_file);
|
return log_link_error_errno(link, r, "Failed to read %s: %m", link->state_file);
|
||||||
|
@ -2182,7 +2188,6 @@ network_file_fail:
|
||||||
char *prefixlen_str;
|
char *prefixlen_str;
|
||||||
int family;
|
int family;
|
||||||
unsigned char prefixlen;
|
unsigned char prefixlen;
|
||||||
union in_addr_union address;
|
|
||||||
|
|
||||||
prefixlen_str = strchr(*address_str, '/');
|
prefixlen_str = strchr(*address_str, '/');
|
||||||
if (!prefixlen_str) {
|
if (!prefixlen_str) {
|
||||||
|
@ -2210,6 +2215,42 @@ network_file_fail:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dhcp4_address) {
|
||||||
|
r = in_addr_from_string(AF_INET, dhcp4_address, &address);
|
||||||
|
if (r < 0) {
|
||||||
|
log_link_debug_errno(link, r, "Falied to parse DHCPv4 address %s: %m", dhcp4_address);
|
||||||
|
goto dhcp4_address_fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sd_dhcp_client_new(&link->dhcp_client);
|
||||||
|
if (r < 0)
|
||||||
|
return log_link_error_errno(link, r, "Falied to create DHCPv4 client: %m");
|
||||||
|
|
||||||
|
r = sd_dhcp_client_set_request_address(link->dhcp_client, &address.in);
|
||||||
|
if (r < 0)
|
||||||
|
return log_link_error_errno(link, r, "Falied to set inital DHCPv4 address %s: %m", dhcp4_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
dhcp4_address_fail:
|
||||||
|
|
||||||
|
if (ipv4ll_address) {
|
||||||
|
r = in_addr_from_string(AF_INET, ipv4ll_address, &address);
|
||||||
|
if (r < 0) {
|
||||||
|
log_link_debug_errno(link, r, "Falied to parse IPv4LL address %s: %m", ipv4ll_address);
|
||||||
|
goto ipv4ll_address_fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sd_ipv4ll_new(&link->ipv4ll);
|
||||||
|
if (r < 0)
|
||||||
|
return log_link_error_errno(link, r, "Falied to create IPv4LL client: %m");
|
||||||
|
|
||||||
|
r = sd_ipv4ll_set_address(link->ipv4ll, &address.in);
|
||||||
|
if (r < 0)
|
||||||
|
return log_link_error_errno(link, r, "Falied to set inital IPv4LL address %s: %m", ipv4ll_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
ipv4ll_address_fail:
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2696,15 +2737,21 @@ int link_save(Link *link) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (link->dhcp_lease) {
|
if (link->dhcp_lease) {
|
||||||
|
struct in_addr address;
|
||||||
const char *tz = NULL;
|
const char *tz = NULL;
|
||||||
|
|
||||||
|
assert(link->network);
|
||||||
|
|
||||||
r = sd_dhcp_lease_get_timezone(link->dhcp_lease, &tz);
|
r = sd_dhcp_lease_get_timezone(link->dhcp_lease, &tz);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
fprintf(f, "TIMEZONE=%s\n", tz);
|
fprintf(f, "TIMEZONE=%s\n", tz);
|
||||||
}
|
|
||||||
|
|
||||||
if (link->dhcp_lease) {
|
r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
|
||||||
assert(link->network);
|
if (r >= 0) {
|
||||||
|
fputs("DHCP4_ADDRESS=", f);
|
||||||
|
serialize_in_addrs(f, &address, 1);
|
||||||
|
fputc('\n', f);
|
||||||
|
}
|
||||||
|
|
||||||
r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
|
r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -2716,6 +2763,17 @@ int link_save(Link *link) {
|
||||||
} else
|
} else
|
||||||
unlink(link->lease_file);
|
unlink(link->lease_file);
|
||||||
|
|
||||||
|
if (link->ipv4ll) {
|
||||||
|
struct in_addr address;
|
||||||
|
|
||||||
|
r = sd_ipv4ll_get_address(link->ipv4ll, &address);
|
||||||
|
if (r >= 0) {
|
||||||
|
fputs("IPV4LL_ADDRESS=", f);
|
||||||
|
serialize_in_addrs(f, &address, 1);
|
||||||
|
fputc('\n', f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (link->lldp) {
|
if (link->lldp) {
|
||||||
assert(link->network);
|
assert(link->network);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue