From 3e790eae01ce74f94a5233adeab12c64508916e0 Mon Sep 17 00:00:00 2001 From: Umut Tezduyar Lindskog Date: Tue, 1 Apr 2014 22:55:54 +0200 Subject: networkd: drop routes when lease expires --- src/network/networkd-link.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/network/networkd-link.c') 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; -- cgit v1.2.3-54-g00ecf