1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-04 17:47:03 +03:00

network: make nexthop_add(), nexthop_configure() and friends return 0 on success

After request queue is introduced, the return value on success is unused.
This commit is contained in:
Yu Watanabe 2021-05-13 04:59:56 +09:00
parent 234106dbf9
commit 7b3a7581e3
5 changed files with 27 additions and 40 deletions

View File

@ -369,7 +369,6 @@ static int address_add_foreign(Link *link, const Address *in, Address **ret) {
}
static int address_add(Link *link, const Address *in, Address **ret) {
bool is_new = false;
Address *address;
int r;
@ -382,7 +381,6 @@ static int address_add(Link *link, const Address *in, Address **ret) {
r = address_add_internal(link, &link->addresses, in, &address);
if (r < 0)
return r;
is_new = true;
} else if (r == 0) {
/* Take over a foreign address */
r = set_ensure_put(&link->addresses, &address_hash_ops, address);
@ -398,7 +396,7 @@ static int address_add(Link *link, const Address *in, Address **ret) {
if (ret)
*ret = address;
return is_new;
return 0;
}
static int address_update(Address *address, const Address *src) {
@ -939,7 +937,7 @@ static int address_configure(
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
Address *acquired_address, *a;
bool update;
int r, k;
int r;
assert(address);
assert(IN_SET(address->family, AF_INET, AF_INET6));
@ -1006,9 +1004,9 @@ static int address_configure(
if (r < 0)
return log_link_error_errno(link, r, "Could not append IFA_RT_PRIORITY attribute: %m");
k = address_add(link, address, &a);
if (k < 0)
return log_link_error_errno(link, k, "Could not add address: %m");
r = address_add(link, address, &a);
if (r < 0)
return log_link_error_errno(link, r, "Could not add address: %m");
r = address_set_masquerade(a, true);
if (r < 0)
@ -1031,7 +1029,7 @@ static int address_configure(
if (ret)
*ret = a;
return k;
return 0;
}
static int static_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {

View File

@ -171,7 +171,6 @@ static int neighbor_add_internal(Link *link, Set **neighbors, const Neighbor *in
}
static int neighbor_add(Link *link, const Neighbor *in, Neighbor **ret) {
bool is_new = false;
Neighbor *neighbor;
int r;
@ -181,7 +180,6 @@ static int neighbor_add(Link *link, const Neighbor *in, Neighbor **ret) {
r = neighbor_add_internal(link, &link->neighbors, in, &neighbor);
if (r < 0)
return r;
is_new = true;
} else if (r == 0) {
/* Neighbor is foreign, claim it as recognized */
r = set_ensure_put(&link->neighbors, &neighbor_hash_ops, neighbor);
@ -197,7 +195,7 @@ static int neighbor_add(Link *link, const Neighbor *in, Neighbor **ret) {
if (ret)
*ret = neighbor;
return is_new;
return 0;
}
static int neighbor_add_foreign(Link *link, const Neighbor *in, Neighbor **ret) {

View File

@ -252,7 +252,6 @@ static int nexthop_add_foreign(Manager *manager, Link *link, const NextHop *in,
}
static int nexthop_add(Link *link, const NextHop *in, NextHop **ret) {
bool is_new = false;
NextHop *nexthop;
int r;
@ -271,7 +270,6 @@ static int nexthop_add(Link *link, const NextHop *in, NextHop **ret) {
in, &nexthop);
if (r < 0)
return r;
is_new = true;
} else if (r == 0) {
/* Take over a foreign nexthop */
r = set_ensure_put(in->blackhole ? &link->manager->nexthops : &link->nexthops,
@ -288,7 +286,7 @@ static int nexthop_add(Link *link, const NextHop *in, NextHop **ret) {
if (ret)
*ret = nexthop;
return is_new;
return 0;
}
static int nexthop_update(Manager *manager, Link *link, NextHop *nexthop, const NextHop *in) {
@ -443,7 +441,7 @@ static int nexthop_configure(
NextHop **ret) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
int r, k;
int r;
assert(link);
assert(link->manager);
@ -488,9 +486,9 @@ static int nexthop_configure(
}
}
k = nexthop_add(link, nexthop, ret);
if (k < 0)
return log_link_error_errno(link, k, "Could not add nexthop: %m");
r = nexthop_add(link, nexthop, ret);
if (r < 0)
return log_link_error_errno(link, r, "Could not add nexthop: %m");
r = netlink_call_async(link->manager->rtnl, NULL, req, callback,
link_netlink_destroy_callback, link);
@ -499,7 +497,7 @@ static int nexthop_configure(
link_ref(link);
return k;
return r;
}
static int static_nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {

View File

@ -586,7 +586,6 @@ static int route_add_foreign(Manager *manager, Link *link, const Route *in, Rout
static int route_add(Manager *manager, Link *link, const Route *in, const MultipathRoute *m, const NextHop *nh, Route **ret) {
_cleanup_(route_freep) Route *tmp = NULL;
bool is_new = false;
Route *route;
int r;
@ -617,7 +616,6 @@ static int route_add(Manager *manager, Link *link, const Route *in, const Multip
r = route_add_internal(manager, link, link ? &link->routes : &manager->routes, in, &route);
if (r < 0)
return r;
is_new = true;
} else if (r == 0) {
/* Take over a foreign route */
r = set_ensure_put(link ? &link->routes : &manager->routes, &route_hash_ops, route);
@ -633,7 +631,7 @@ static int route_add(Manager *manager, Link *link, const Route *in, const Multip
if (ret)
*ret = route;
return is_new;
return 0;
}
static bool route_type_is_reject(const Route *route) {
@ -1160,7 +1158,7 @@ static int route_add_and_setup_timer(Link *link, const Route *route, const Multi
_cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL;
NextHop *nh = NULL;
Route *nr;
int r, k;
int r;
assert(link);
assert(link->manager);
@ -1169,9 +1167,9 @@ static int route_add_and_setup_timer(Link *link, const Route *route, const Multi
(void) manager_get_nexthop_by_id(link->manager, route->nexthop_id, &nh);
if (route_type_is_reject(route) || (nh && nh->blackhole))
k = route_add(link->manager, NULL, route, NULL, nh, &nr);
r = route_add(link->manager, NULL, route, NULL, nh, &nr);
else if (!m || m->ifindex == 0 || m->ifindex == link->ifindex)
k = route_add(NULL, link, route, m, nh, &nr);
r = route_add(NULL, link, route, m, nh, &nr);
else {
Link *link_gw;
@ -1179,10 +1177,10 @@ static int route_add_and_setup_timer(Link *link, const Route *route, const Multi
if (r < 0)
return log_link_error_errno(link, r, "Failed to get link with ifindex %d: %m", m->ifindex);
k = route_add(NULL, link_gw, route, m, NULL, &nr);
r = route_add(NULL, link_gw, route, m, NULL, &nr);
}
if (k < 0)
return log_link_error_errno(link, k, "Could not add route: %m");
if (r < 0)
return log_link_error_errno(link, r, "Could not add route: %m");
/* TODO: drop expiration handling once it can be pushed into the kernel */
if (nr->lifetime != USEC_INFINITY && !kernel_route_expiration_supported()) {
@ -1198,7 +1196,7 @@ static int route_add_and_setup_timer(Link *link, const Route *route, const Multi
if (ret)
*ret = nr;
return k;
return 0;
}
static int append_nexthop_one(const Route *route, const MultipathRoute *m, struct rtattr **rta, size_t offset) {
@ -1312,7 +1310,7 @@ static int route_configure(
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
_cleanup_free_ Route **routes = NULL;
unsigned n_routes = 0; /* avoid false maybe-uninitialized warning */
int r, k;
int r;
assert(link);
assert(link->manager);
@ -1411,9 +1409,9 @@ static int route_configure(
return log_oom();
}
k = route_add_and_setup_timer(link, route, NULL, routes);
if (k < 0)
return k;
r = route_add_and_setup_timer(link, route, NULL, routes);
if (r < 0)
return r;
} else {
MultipathRoute *m;
Route **p;
@ -1429,14 +1427,11 @@ static int route_configure(
return log_oom();
}
k = 0;
p = routes;
ORDERED_SET_FOREACH(m, route->multipath_routes) {
r = route_add_and_setup_timer(link, route, m, ret_routes ? p++ : NULL);
if (r < 0)
return r;
if (r > 0)
k = 1;
}
}
@ -1452,7 +1447,7 @@ static int route_configure(
*ret_routes = TAKE_PTR(routes);
}
return k;
return 0;
}
static int static_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {

View File

@ -318,7 +318,6 @@ static int routing_policy_rule_get(Manager *m, const RoutingPolicyRule *rule, Ro
static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, RoutingPolicyRule **ret) {
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *rule = NULL;
RoutingPolicyRule *existing;
bool is_new = false;
int r;
assert(m);
@ -339,7 +338,6 @@ static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, Rout
rule->manager = m;
existing = TAKE_PTR(rule);
is_new = true;
} else if (r == 0) {
/* Take over a foreign rule. */
r = set_ensure_put(&m->rules, &routing_policy_rule_hash_ops, existing);
@ -356,7 +354,7 @@ static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, Rout
if (ret)
*ret = existing;
return is_new;
return 0;
}
static int routing_policy_rule_consume_foreign(Manager *m, RoutingPolicyRule *rule) {