}
static int address_add(Link *link, const Address *in, Address **ret) {
+ bool is_new = false;
Address *address;
int r;
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);
if (ret)
*ret = address;
-
- return 0;
+ return is_new;
}
static int address_update(Address *address, const Address *src) {
Address *acquired_address, *a;
uint32_t flags;
bool update;
- int r;
+ int r, k;
assert(address);
assert(IN_SET(address->family, AF_INET, AF_INET6));
if (r < 0)
return log_link_error_errno(link, r, "Could not append IFA_CACHEINFO attribute: %m");
- r = address_add(link, address, &a);
- if (r < 0)
- return log_link_error_errno(link, r, "Could not add address: %m");
+ k = address_add(link, address, &a);
+ if (k < 0)
+ return log_link_error_errno(link, k, "Could not add address: %m");
r = address_set_masquerade(a, true);
if (r < 0)
if (ret)
*ret = a;
- return 1;
+ return k;
}
static int static_address_ready_callback(Address *address) {
}
static int neighbor_add(Link *link, const Neighbor *in, Neighbor **ret) {
+ bool is_new = false;
Neighbor *neighbor;
int r;
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);
set_remove(link->neighbors_foreign, neighbor);
} else if (r == 1) {
/* Neighbor already exists */
+ ;
} else
return r;
if (ret)
*ret = neighbor;
- return 0;
+ return is_new;
}
static int neighbor_add_foreign(Link *link, const Neighbor *in, Neighbor **ret) {
if (r < 0)
return log_link_error_errno(link, r, "Could not add neighbor: %m");
- return 0;
+ return r;
}
int link_set_neighbors(Link *link) {
}
static int nexthop_add(Link *link, NextHop *in, NextHop **ret) {
+ bool is_new = false;
NextHop *nexthop;
int r;
r = nexthop_add_internal(link, &link->nexthops, in, &nexthop);
if (r < 0)
return r;
+ is_new = true;
} else if (r == 0) {
/* Take over a foreign nexthop */
r = set_ensure_put(&link->nexthops, &nexthop_hash_ops, nexthop);
if (ret)
*ret = nexthop;
-
- return 0;
+ return is_new;
}
static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Could not add nexthop: %m");
- return 1;
+ return r;
}
int link_set_nexthop(Link *link) {
static int route_add(Manager *manager, Link *link, const Route *in, const MultipathRoute *m, Route **ret) {
_cleanup_(route_freep) Route *tmp = NULL;
+ bool is_new = false;
Route *route;
int r;
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 */
if (link) {
if (ret)
*ret = route;
-
- return 0;
+ return is_new;
}
static bool route_type_is_reject(const Route *route) {
static int route_add_and_setup_timer(Link *link, const Route *route, const MultipathRoute *m, Route **ret) {
_cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL;
Route *nr;
- int r;
+ int r, k;
assert(link);
assert(route);
if (route_type_is_reject(route))
- r = route_add(link->manager, NULL, route, NULL, &nr);
+ k = route_add(link->manager, NULL, route, NULL, &nr);
else if (!m || m->ifindex == 0 || m->ifindex == link->ifindex)
- r = route_add(NULL, link, route, m, &nr);
+ k = route_add(NULL, link, route, m, &nr);
else {
Link *link_gw;
if (r < 0)
return log_link_error_errno(link, r, "Failed to get link with ifindex %d: %m", m->ifindex);
- r = route_add(NULL, link_gw, route, m, &nr);
+ k = route_add(NULL, link_gw, route, m, &nr);
}
- if (r < 0)
- return log_link_error_errno(link, r, "Could not add route: %m");
+ if (k < 0)
+ return log_link_error_errno(link, k, "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()) {
if (ret)
*ret = nr;
- return 0;
+ return k;
}
static int append_nexthop_one(const Route *route, const MultipathRoute *m, struct rtattr **rta, size_t offset) {
Route **ret) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
- int r;
+ int r, k = 0;
assert(link);
assert(link->manager);
if (ordered_set_isempty(route->multipath_routes)) {
Route *nr;
- r = route_add_and_setup_timer(link, route, NULL, &nr);
- if (r < 0)
- return r;
+ k = route_add_and_setup_timer(link, route, NULL, &nr);
+ if (k < 0)
+ return k;
if (ret)
*ret = nr;
r = route_add_and_setup_timer(link, route, m, NULL);
if (r < 0)
return r;
+ if (r > 0)
+ k = 1;
}
}
link_ref(link);
- return 0;
+ return k;
}
static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, int family, RoutingPolicyRule **ret) {
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *rule = NULL;
RoutingPolicyRule *existing;
+ bool is_new = false;
int r;
assert(m);
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);
if (ret)
*ret = existing;
-
- return 0;
+ return is_new;
}
static int routing_policy_rule_consume_foreign(Manager *m, RoutingPolicyRule *rule) {
if (r < 0)
return log_link_error_errno(link, r, "Could not add rule: %m");
- return 1;
+ return r;
}
static int routing_policy_rule_configure(const RoutingPolicyRule *rule, Link *link) {