Skip to content

Commit

Permalink
keep reference
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Gorski <[email protected]>
  • Loading branch information
KanjiMonster committed Apr 25, 2024
1 parent 4e4785a commit 3707482
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/netlink/nl_l3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,7 @@ int nl_l3::del_l3_unicast_route(rtnl_route *r, bool keep_route) {
std::unique_ptr<rtnl_route, decltype(&rtnl_route_put)> filter(
rtnl_route_alloc(), rtnl_route_put);
std::deque<rtnl_route *> routes;
bool found = false;

rtnl_route_set_type(filter.get(), RTN_UNICAST);
rtnl_route_set_dst(filter.get(), dst);
Expand All @@ -1972,30 +1973,37 @@ int nl_l3::del_l3_unicast_route(rtnl_route *r, bool keep_route) {
nl->get_cache(cnetlink::NL_ROUTE_CACHE), OBJ_CAST(filter.get()),
[](struct nl_object *o, void *arg) {
auto *route = (std::deque<rtnl_route *> *)arg;
nl_object_get(o);
route->push_back(ROUTE_CAST(o));
},
&routes);

for (auto route : routes) {
if (rtnl_route_get_nnexthops(route) != 1) {
LOG(WARNING) << " unexpected number of nexthops ("
<< rtnl_route_get_nnexthops(route) << ") for route "
<< route;
continue;
if (!found) {
if (rtnl_route_get_nnexthops(route) != 1) {
LOG(WARNING) << " unexpected number of nexthops ("
<< rtnl_route_get_nnexthops(route) << ") for route "
<< route;
} else {
auto nh = rtnl_route_nexthop_n(route, 0);
if (nl->is_switch_interface(rtnl_route_nh_get_ifindex(nh))) {
found = true;
}
}
}
rtnl_route_put(route);
}

auto nh = rtnl_route_nexthop_n(route, 0);
if (nl->is_switch_interface(rtnl_route_nh_get_ifindex(nh))) {
VLOG(2) << __FUNCTION__ << ": IPv6LL still has interfaces";
return 0;
}
if (found) {
VLOG(2) << __FUNCTION__ << ": IPv6LL still has interfaces";
return;
}
}

rv = del_l3_unicast_route(dst, vrf_id);
if (rv < 0) {
LOG(ERROR) << __FUNCTION__ << ": failed to remove dst=" << dst;
// fallthrough
rv = del_l3_unicast_route(dst, vrf_id);
if (rv < 0) {
LOG(ERROR) << __FUNCTION__ << ": failed to remove dst=" << dst;
// fallthrough
}
}
}

Expand Down

0 comments on commit 3707482

Please sign in to comment.