diff options
author | Umut Tezduyar Lindskog <umut.tezduyar@axis.com> | 2014-04-01 22:55:54 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-04-03 16:00:19 +0200 |
commit | 3e790eae01ce74f94a5233adeab12c64508916e0 (patch) | |
tree | d8b27e0d63ee5bbb1096b7f8f8257c7a8f1292ca /src/network | |
parent | 8016b904849a2d2bd8b0171ed8493db5524b5ff7 (diff) |
networkd: drop routes when lease expires
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-link.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 973755a3e3..4e0fe0a271 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -579,8 +579,11 @@ static int link_set_mtu(Link *link, uint32_t mtu) { static int dhcp_lease_lost(Link *link) { _cleanup_address_free_ Address *address = NULL; + _cleanup_route_free_ Route *route_gw = NULL; + _cleanup_route_free_ Route *route = NULL; struct in_addr addr; struct in_addr netmask; + struct in_addr gateway; unsigned prefixlen; int r; @@ -593,8 +596,27 @@ static int dhcp_lease_lost(Link *link) { if (r >= 0) { sd_dhcp_lease_get_address(link->dhcp_lease, &addr); sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask); + sd_dhcp_lease_get_router(link->dhcp_lease, &gateway); prefixlen = net_netmask_to_prefixlen(&netmask); + r = route_new_dynamic(&route_gw); + if (r >= 0) { + route_gw->family = AF_INET; + route_gw->dst_addr.in = gateway; + route_gw->dst_prefixlen = 32; + route_gw->scope = RT_SCOPE_LINK; + + route_drop(route_gw, link, &route_drop_handler); + } + + r = route_new_dynamic(&route); + if (r >= 0) { + route->family = AF_INET; + route->in_addr.in = gateway; + + route_drop(route, link, &route_drop_handler); + } + address->family = AF_INET; address->in_addr.in = addr; address->prefixlen = prefixlen; |