network: use RET_GATHER() macro

This commit is contained in:
Yu Watanabe 2023-12-25 20:18:34 +09:00 committed by Mike Yuan
parent 38617c516a
commit 372acaad58
5 changed files with 56 additions and 79 deletions

View file

@ -145,7 +145,7 @@ static int dhcp_pd_get_assigned_subnet_prefix(Link *link, const struct in6_addr
}
int dhcp_pd_remove(Link *link, bool only_marked) {
int k, r = 0;
int ret = 0;
assert(link);
assert(link->manager);
@ -170,10 +170,7 @@ int dhcp_pd_remove(Link *link, bool only_marked) {
link_remove_dhcp_pd_subnet_prefix(link, &route->dst.in6);
k = route_remove(route);
if (k < 0)
r = k;
RET_GATHER(ret, route_remove(route));
route_cancel_request(route, link);
}
} else {
@ -195,13 +192,11 @@ int dhcp_pd_remove(Link *link, bool only_marked) {
link_remove_dhcp_pd_subnet_prefix(link, &prefix);
k = address_remove_and_drop(address);
if (k < 0)
r = k;
RET_GATHER(ret, address_remove_and_drop(address));
}
}
return r;
return ret;
}
static int dhcp_pd_check_ready(Link *link);

View file

@ -243,7 +243,7 @@ static int dhcp4_find_gateway_for_destination(
static int dhcp4_remove_address_and_routes(Link *link, bool only_marked) {
Address *address;
Route *route;
int k, r = 0;
int ret = 0;
assert(link);
@ -253,10 +253,7 @@ static int dhcp4_remove_address_and_routes(Link *link, bool only_marked) {
if (only_marked && !route_is_marked(route))
continue;
k = route_remove(route);
if (k < 0)
r = k;
RET_GATHER(ret, route_remove(route));
route_cancel_request(route, link);
}
@ -266,12 +263,10 @@ static int dhcp4_remove_address_and_routes(Link *link, bool only_marked) {
if (only_marked && !address_is_marked(address))
continue;
k = address_remove_and_drop(address);
if (k < 0)
r = k;
RET_GATHER(ret, address_remove_and_drop(address));
}
return r;
return ret;
}
static int dhcp4_address_get(Link *link, Address **ret) {
@ -835,7 +830,7 @@ static int dhcp_reset_hostname(Link *link) {
}
int dhcp4_lease_lost(Link *link) {
int k, r = 0;
int r = 0;
assert(link);
assert(link->dhcp_lease);
@ -849,17 +844,9 @@ int dhcp4_lease_lost(Link *link) {
sd_dhcp_lease_has_6rd(link->dhcp_lease))
dhcp4_pd_prefix_lost(link);
k = dhcp4_remove_address_and_routes(link, /* only_marked = */ false);
if (k < 0)
r = k;
k = dhcp_reset_mtu(link);
if (k < 0)
r = k;
k = dhcp_reset_hostname(link);
if (k < 0)
r = k;
RET_GATHER(r, dhcp4_remove_address_and_routes(link, /* only_marked = */ false));
RET_GATHER(r, dhcp_reset_mtu(link));
RET_GATHER(r, dhcp_reset_hostname(link));
link->dhcp_lease = sd_dhcp_lease_unref(link->dhcp_lease);
link_dirty(link);

View file

@ -48,7 +48,7 @@ static DHCP6ClientStartMode link_get_dhcp6_client_start_mode(Link *link) {
static int dhcp6_remove(Link *link, bool only_marked) {
Address *address;
Route *route;
int k, r = 0;
int ret = 0;
assert(link);
@ -61,10 +61,7 @@ static int dhcp6_remove(Link *link, bool only_marked) {
if (only_marked && !route_is_marked(route))
continue;
k = route_remove(route);
if (k < 0)
r = k;
RET_GATHER(ret, route_remove(route));
route_cancel_request(route, link);
}
@ -74,12 +71,10 @@ static int dhcp6_remove(Link *link, bool only_marked) {
if (only_marked && !address_is_marked(address))
continue;
k = address_remove_and_drop(address);
if (k < 0)
r = k;
RET_GATHER(ret, address_remove_and_drop(address));
}
return r;
return ret;
}
static int dhcp6_address_ready_callback(Address *address) {

View file

@ -322,7 +322,7 @@ void link_set_state(Link *link, LinkState state) {
}
int link_stop_engines(Link *link, bool may_keep_dhcp) {
int r = 0, k;
int r, ret = 0;
assert(link);
assert(link->manager);
@ -335,50 +335,50 @@ int link_stop_engines(Link *link, bool may_keep_dhcp) {
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP_ON_STOP));
if (!keep_dhcp) {
k = sd_dhcp_client_stop(link->dhcp_client);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop DHCPv4 client: %m");
r = sd_dhcp_client_stop(link->dhcp_client);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop DHCPv4 client: %m"));
}
k = sd_dhcp_server_stop(link->dhcp_server);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop DHCPv4 server: %m");
r = sd_dhcp_server_stop(link->dhcp_server);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop DHCPv4 server: %m"));
k = sd_lldp_rx_stop(link->lldp_rx);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop LLDP Rx: %m");
r = sd_lldp_rx_stop(link->lldp_rx);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop LLDP Rx: %m"));
k = sd_lldp_tx_stop(link->lldp_tx);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop LLDP Tx: %m");
r = sd_lldp_tx_stop(link->lldp_tx);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop LLDP Tx: %m"));
k = sd_ipv4ll_stop(link->ipv4ll);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop IPv4 link-local: %m");
r = sd_ipv4ll_stop(link->ipv4ll);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop IPv4 link-local: %m"));
k = ipv4acd_stop(link);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop IPv4 ACD client: %m");
r = ipv4acd_stop(link);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop IPv4 ACD client: %m"));
k = sd_dhcp6_client_stop(link->dhcp6_client);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop DHCPv6 client: %m");
r = sd_dhcp6_client_stop(link->dhcp6_client);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop DHCPv6 client: %m"));
k = dhcp_pd_remove(link, /* only_marked = */ false);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not remove DHCPv6 PD addresses and routes: %m");
r = dhcp_pd_remove(link, /* only_marked = */ false);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not remove DHCPv6 PD addresses and routes: %m"));
k = ndisc_stop(link);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Discovery: %m");
r = ndisc_stop(link);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop IPv6 Router Discovery: %m"));
ndisc_flush(link);
k = sd_radv_stop(link->radv);
if (k < 0)
r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Advertisement: %m");
r = sd_radv_stop(link->radv);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop IPv6 Router Advertisement: %m"));
return r;
return ret;
}
void link_enter_failed(Link *link) {

View file

@ -1108,7 +1108,7 @@ static int ndisc_drop_outdated(Link *link, usec_t timestamp_usec) {
NDiscPREF64 *p64;
Address *address;
Route *route;
int r = 0, k;
int r, ret = 0;
assert(link);
@ -1125,9 +1125,9 @@ static int ndisc_drop_outdated(Link *link, usec_t timestamp_usec) {
if (route->lifetime_usec >= timestamp_usec)
continue; /* the route is still valid */
k = route_remove_and_drop(route);
if (k < 0)
r = log_link_warning_errno(link, k, "Failed to remove outdated SLAAC route, ignoring: %m");
r = route_remove_and_drop(route);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Failed to remove outdated SLAAC route, ignoring: %m"));
}
SET_FOREACH(address, link->addresses) {
@ -1137,9 +1137,9 @@ static int ndisc_drop_outdated(Link *link, usec_t timestamp_usec) {
if (address->lifetime_valid_usec >= timestamp_usec)
continue; /* the address is still valid */
k = address_remove_and_drop(address);
if (k < 0)
r = log_link_warning_errno(link, k, "Failed to remove outdated SLAAC address, ignoring: %m");
r = address_remove_and_drop(address);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Failed to remove outdated SLAAC address, ignoring: %m"));
}
SET_FOREACH(rdnss, link->ndisc_rdnss) {
@ -1178,7 +1178,7 @@ static int ndisc_drop_outdated(Link *link, usec_t timestamp_usec) {
if (updated)
link_dirty(link);
return r;
return ret;
}
static int ndisc_setup_expire(Link *link);