From 3596fb3600c9656c461c8ca3aef05fd03d45ff93 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 8 Sep 2021 13:39:22 +0900 Subject: [PATCH] network: dhcp4: return earlier on failure --- src/network/networkd-dhcp4.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index d7c063267f3..31af7be71e2 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -135,6 +135,26 @@ static int dhcp4_after_route_configure(Request *req, void *object) { return 0; } +static int dhcp4_retry(Link *link) { + int r; + + assert(link); + + r = dhcp4_remove_all(link); + if (r < 0) + return r; + + r = link_request_static_nexthops(link, true); + if (r < 0) + return r; + + r = link_request_static_routes(link, true); + if (r < 0) + return r; + + return dhcp4_request_address_and_routes(link, false); +} + static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { int r; @@ -165,19 +185,7 @@ static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *li link->dhcp4_route_failed = false; link->dhcp4_route_retrying = true; - r = dhcp4_remove_all(link); - if (r < 0) - link_enter_failed(link); - - r = link_request_static_nexthops(link, true); - if (r < 0) - link_enter_failed(link); - - r = link_request_static_routes(link, true); - if (r < 0) - link_enter_failed(link); - - r = dhcp4_request_address_and_routes(link, false); + r = dhcp4_retry(link); if (r < 0) link_enter_failed(link);