diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-07-12 02:36:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-12 02:36:16 +0200 |
commit | 6fa0524133ce54889f870d7ad17ab1d1832d7460 (patch) | |
tree | 245cbb12a8b6eb13722ba42885079ea995ebcc8b /src/network | |
parent | Merge pull request #13024 from poettering/errno-or-else (diff) | |
parent | test-network: add test for route reassignment (diff) | |
download | systemd-6fa0524133ce54889f870d7ad17ab1d1832d7460.tar.xz systemd-6fa0524133ce54889f870d7ad17ab1d1832d7460.zip |
Merge pull request #12971 from yuwata/network-reassign-static-routes
network: reassign static routes and process reply address messages
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-dhcp4.c | 20 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.c | 7 | ||||
-rw-r--r-- | src/network/networkd-ndisc.c | 35 |
3 files changed, 45 insertions, 17 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index c0d776f464..7ed91cebd1 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -75,8 +75,8 @@ static int route_scope_from_address(const Route *route, const struct in_addr *se assert(route); assert(self_addr); - if (in_addr_is_localhost(AF_INET, &route->dst) || - (self_addr->s_addr && route->dst.in.s_addr == self_addr->s_addr)) + if (in4_addr_is_localhost(&route->dst.in) || + (!in4_addr_is_null(self_addr) && in4_addr_equal(&route->dst.in, self_addr))) return RT_SCOPE_HOST; else if (in4_addr_is_null(&route->gw.in)) return RT_SCOPE_LINK; @@ -153,8 +153,8 @@ static int link_set_dhcp_routes(Link *link) { r = route_configure(route, link, dhcp4_route_handler); if (r < 0) return log_link_error_errno(link, r, "Could not set host route: %m"); - - link->dhcp4_messages++; + if (r > 0) + link->dhcp4_messages++; } r = sd_dhcp_lease_get_router(link->dhcp_lease, &router); @@ -192,8 +192,8 @@ static int link_set_dhcp_routes(Link *link) { r = route_configure(route_gw, link, dhcp4_route_handler); if (r < 0) return log_link_error_errno(link, r, "Could not set host route: %m"); - - link->dhcp4_messages++; + if (r > 0) + link->dhcp4_messages++; r = route_new(&route); if (r < 0) @@ -209,8 +209,8 @@ static int link_set_dhcp_routes(Link *link) { r = route_configure(route, link, dhcp4_route_handler); if (r < 0) return log_link_error_errno(link, r, "Could not set routes: %m"); - - link->dhcp4_messages++; + if (r > 0) + link->dhcp4_messages++; } return 0; @@ -460,8 +460,8 @@ static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link * link_enter_failed(link); return 1; } - - manager_rtnl_process_address(rtnl, m, link->manager); + if (r >= 0) + manager_rtnl_process_address(rtnl, m, link->manager); r = link_set_dhcp_routes(link); if (r < 0) { diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 286b9071ae..0a73ffc848 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -408,10 +408,13 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link * log_link_error_errno(link, r, "Could not set DHCPv6 address: %m"); link_enter_failed(link); - - } else if (r >= 0) + return 1; + } + if (r >= 0) manager_rtnl_process_address(rtnl, m, link->manager); + link_request_set_routes(link); + return 1; } diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 78f89e026e..39b66d8f6d 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -10,6 +10,7 @@ #include "missing_network.h" #include "networkd-dhcp6.h" +#include "networkd-manager.h" #include "networkd-ndisc.h" #include "networkd-route.h" #include "strv.h" @@ -18,7 +19,7 @@ #define NDISC_RDNSS_MAX 64U #define NDISC_PREFIX_LFT_MIN 7200U -static int ndisc_netlink_message_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { +static int ndisc_netlink_route_message_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { int r; assert(link); @@ -32,6 +33,30 @@ static int ndisc_netlink_message_handler(sd_netlink *rtnl, sd_netlink_message *m if (link->ndisc_messages == 0) { link->ndisc_configured = true; + link_request_set_routes(link); + link_check_ready(link); + } + + return 1; +} + +static int ndisc_netlink_address_message_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { + int r; + + assert(link); + assert(link->ndisc_messages > 0); + + link->ndisc_messages--; + + r = sd_netlink_message_get_errno(m); + if (r < 0 && r != -EEXIST) + log_link_error_errno(link, r, "Could not set NDisc route or address: %m"); + else if (r >= 0) + manager_rtnl_process_address(rtnl, m, link->manager); + + if (link->ndisc_messages == 0) { + link->ndisc_configured = true; + link_request_set_routes(link); link_check_ready(link); } @@ -116,7 +141,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { route->lifetime = time_now + lifetime * USEC_PER_SEC; route->mtu = mtu; - r = route_configure(route, link, ndisc_netlink_message_handler); + r = route_configure(route, link, ndisc_netlink_route_message_handler); if (r < 0) { log_link_warning_errno(link, r, "Could not set default route: %m"); link_enter_failed(link); @@ -204,7 +229,7 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r if (address->cinfo.ifa_valid == 0) return 0; - r = address_configure(address, link, ndisc_netlink_message_handler, true); + r = address_configure(address, link, ndisc_netlink_address_message_handler, true); if (r < 0) { log_link_warning_errno(link, r, "Could not set SLAAC address: %m"); link_enter_failed(link); @@ -254,7 +279,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) { if (r < 0) return log_link_error_errno(link, r, "Failed to get prefix address: %m"); - r = route_configure(route, link, ndisc_netlink_message_handler); + r = route_configure(route, link, ndisc_netlink_route_message_handler); if (r < 0) { log_link_warning_errno(link, r, "Could not set prefix route: %m"); link_enter_failed(link); @@ -315,7 +340,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) { if (r < 0) return log_link_error_errno(link, r, "Failed to get route address: %m"); - r = route_configure(route, link, ndisc_netlink_message_handler); + r = route_configure(route, link, ndisc_netlink_route_message_handler); if (r < 0) { log_link_warning_errno(link, r, "Could not set additional route: %m"); link_enter_failed(link); |