networkd: Add back static routes after DHCPv4 lease expires.

1. When the DHCPv4 lease expires kernel removes the route. So add it back
when we gain lease again.

Closes https://github.com/systemd/systemd/issues/12426

2. When UseRoutes=false do not remove router
This commit is contained in:
Susant Sahani 2019-04-29 10:32:34 +05:30 committed by Lennart Poettering
parent 6dc14d7366
commit b5799eeb07
3 changed files with 8 additions and 4 deletions

View File

@ -214,10 +214,7 @@ static int dhcp_lease_lost(Link *link) {
}
}
}
}
r = address_new(&address);
if (r >= 0) {
r = sd_dhcp_lease_get_router(link->dhcp_lease, &router);
if (r > 0 && !in4_addr_is_null(&router[0])) {
_cleanup_(route_freep) Route *route_gw = NULL;
@ -241,7 +238,10 @@ static int dhcp_lease_lost(Link *link) {
route_remove(route, link, NULL);
}
}
}
r = address_new(&address);
if (r >= 0) {
r = sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
if (r >= 0) {
r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
@ -308,6 +308,9 @@ static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
link_set_dhcp_routes(link);
/* Add back static routes since kernel removes while DHCPv4 address is removed from when lease expires */
link_request_set_routes(link);
if (link->dhcp4_messages == 0) {
link->dhcp4_configured = true;
link_check_ready(link);

View File

@ -913,7 +913,7 @@ static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
return 1;
}
static int link_request_set_routes(Link *link) {
int link_request_set_routes(Link *link) {
enum {
PHASE_NON_GATEWAY, /* First phase: Routes without a gateway */
PHASE_GATEWAY, /* Second phase: Routes with a gateway */

View File

@ -180,6 +180,7 @@ int link_send_changed(Link *link, const char *property, ...) _sentinel_;
uint32_t link_get_vrf_table(Link *link);
uint32_t link_get_dhcp_route_table(Link *link);
uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
int link_request_set_routes(Link *link);
#define ADDRESS_FMT_VAL(address) \
be32toh((address).s_addr) >> 24, \