summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorPatrik Flykt <Patrik.Flykt@linux.intel.com>2014-06-26 16:18:43 +0300
committerTom Gundersen <teg@jklm.no>2014-06-29 15:18:21 +0200
commit68ceb9df6a39a7f86ffc3cf8266ca677a5d5271b (patch)
treee9cc615604eb921ce54bdf1bdcb9bf4a9a1d9f14 /src/network/networkd-link.c
parent7c16313f11e3953f3fe4dbf544f2d36f58d14138 (diff)
sd-dhcp-client/networkd: set lifetimes for IPv4 addresses
Note that /proc/sys/net/ipv4/ip_dynaddr needs to be non-zero. [tomegun: hook up DHCP renew events to increase the lifetime when necessary]
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 5527489364..6bff73d42d 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -600,6 +600,7 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
static int link_enter_set_addresses(Link *link) {
Address *ad;
int r;
+ uint32_t lifetime = CACHE_INFO_INFINITY_LIFE_TIME;
assert(link);
assert(link->network);
@@ -676,6 +677,16 @@ static int link_enter_set_addresses(Link *link) {
return r;
}
+ if (!link->network->dhcp_critical) {
+ r = sd_dhcp_lease_get_lifetime(link->dhcp_lease,
+ &lifetime);
+ if (r < 0) {
+ log_warning_link(link, "DHCP error: no lifetime: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
if (r < 0) {
log_warning_link(link, "DHCP error: no netmask: %s",
@@ -694,6 +705,8 @@ static int link_enter_set_addresses(Link *link) {
address->family = AF_INET;
address->in_addr.in = addr;
+ address->cinfo.ifa_prefered = lifetime;
+ address->cinfo.ifa_valid = lifetime;
address->prefixlen = prefixlen;
address->broadcast.s_addr = addr.s_addr | ~netmask.s_addr;
@@ -967,6 +980,25 @@ static int dhcp_lease_lost(Link *link) {
return 0;
}
+static int dhcp_lease_renew(sd_dhcp_client *client, Link *link) {
+ sd_dhcp_lease *lease;
+ int r;
+
+ r = sd_dhcp_client_get_lease(client, &lease);
+ if (r < 0) {
+ log_warning_link(link, "DHCP error: no lease %s",
+ strerror(-r));
+ return r;
+ }
+
+ sd_dhcp_lease_unref(link->dhcp_lease);
+ link->dhcp_lease = lease;
+
+ link_enter_set_addresses(link);
+
+ return 0;
+}
+
static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
sd_dhcp_lease *lease;
struct in_addr address;
@@ -1118,6 +1150,13 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
}
break;
+ case DHCP_EVENT_RENEW:
+ r = dhcp_lease_renew(client, link);
+ if (r < 0) {
+ link_enter_failed(link);
+ return;
+ }
+ break;
case DHCP_EVENT_IP_ACQUIRE:
r = dhcp_lease_acquired(client, link);
if (r < 0) {