summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-01 22:29:50 +0200
committerTom Gundersen <teg@jklm.no>2015-10-30 12:32:49 +0100
commit0bc70f1d9c5453ba614ec0ed041dc30b9cd52071 (patch)
treed20f295d7f498f754a7cd4c20a05b4da8615a314 /src
parentc4a03a5669af8abd752bff9084c29683ae78e11e (diff)
networkd: link - (de)serialize IPv4LL and DHCPv4 addresses
This initializes the clients to try rebinding the preexisting addresses before doing anything else.
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-dhcp4.c8
-rw-r--r--src/network/networkd-ipv4ll.c8
-rw-r--r--src/network/networkd-link.c68
3 files changed, 73 insertions, 11 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index 05a16f4033..b58fc5808c 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -533,9 +533,11 @@ int dhcp4_configure(Link *link) {
assert(link->network);
assert(link->network->dhcp & ADDRESS_FAMILY_IPV4);
- r = sd_dhcp_client_new(&link->dhcp_client);
- if (r < 0)
- return r;
+ if (!link->dhcp_client) {
+ r = sd_dhcp_client_new(&link->dhcp_client);
+ if (r < 0)
+ return r;
+ }
r = sd_dhcp_client_attach_event(link->dhcp_client, NULL, 0);
if (r < 0)
diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c
index 59abb1e8d4..ed0d861e7a 100644
--- a/src/network/networkd-ipv4ll.c
+++ b/src/network/networkd-ipv4ll.c
@@ -208,9 +208,11 @@ int ipv4ll_configure(Link *link) {
assert(link->network);
assert(link->network->link_local & ADDRESS_FAMILY_IPV4);
- r = sd_ipv4ll_new(&link->ipv4ll);
- if (r < 0)
- return r;
+ if (!link->ipv4ll) {
+ r = sd_ipv4ll_new(&link->ipv4ll);
+ if (r < 0)
+ return r;
+ }
if (link->udev_device) {
r = net_get_unique_predictable_data(link->udev_device, seed);
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 4243f8cba9..5dcd862c21 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2133,7 +2133,11 @@ int link_initialized(Link *link, struct udev_device *device) {
}
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;
assert(link);
@@ -2141,6 +2145,8 @@ static int link_load(Link *link) {
r = parse_env_file(link->state_file, NEWLINE,
"NETWORK_FILE", &network_file,
"ADDRESSES", &addresses,
+ "DHCP4_ADDRESS", &dhcp4_address,
+ "IPV4LL_ADDRESS", &ipv4ll_address,
NULL);
if (r < 0 && r != -ENOENT)
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;
int family;
unsigned char prefixlen;
- union in_addr_union address;
prefixlen_str = strchr(*address_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;
}
@@ -2696,15 +2737,21 @@ int link_save(Link *link) {
}
if (link->dhcp_lease) {
+ struct in_addr address;
const char *tz = NULL;
+ assert(link->network);
+
r = sd_dhcp_lease_get_timezone(link->dhcp_lease, &tz);
if (r >= 0)
fprintf(f, "TIMEZONE=%s\n", tz);
- }
- if (link->dhcp_lease) {
- assert(link->network);
+ r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
+ 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);
if (r < 0)
@@ -2716,6 +2763,17 @@ int link_save(Link *link) {
} else
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) {
assert(link->network);