Skip to content

Commit

Permalink
nl_l3::{add,del}_unicast_route: only update neighs for link scope routes
Browse files Browse the repository at this point in the history
L3 Neighbours are always on-link, so we only need to update their state
when handling link scope routes.

Fixes enabling/disabling neighbours when handling default routes.

Fixes: 0fdba0d ("nl_l3: only route l3 neighs if we have a route for them")
Signed-off-by: Jonas Gorski <[email protected]>
  • Loading branch information
KanjiMonster committed May 30, 2024
1 parent 0ef6a03 commit fa06f41
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions src/netlink/nl_l3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1873,22 +1873,24 @@ int nl_l3::add_l3_unicast_route(rtnl_route *r, bool update_route) {
<< " rv=" << rv;
}

VLOG(2) << __FUNCTION__ << ": enabling l3 neighs reachable by route " << r;
auto l3_neighs =
get_l3_neighs_of_prefix(unroutable_l3_neighs, rtnl_route_get_dst(r));
for (auto n : l3_neighs) {
auto neigh = nl->get_neighbour(n.ifindex, n.nh);
if (!neigh) {
// should we remove it from unroutable?
VLOG(2) << __FUNCTION__ << ": unknown l3 neigh ifindex=" << n.ifindex
<< ", addr=" << n.nh;
continue;
}
if (rtnl_route_guess_scope(r) == RT_SCOPE_LINK) {
VLOG(2) << __FUNCTION__ << ": enabling l3 neighs reachable by route " << r;
auto l3_neighs =
get_l3_neighs_of_prefix(unroutable_l3_neighs, rtnl_route_get_dst(r));
for (auto n : l3_neighs) {
auto neigh = nl->get_neighbour(n.ifindex, n.nh);
if (!neigh) {
// should we remove it from unroutable?
VLOG(2) << __FUNCTION__ << ": unknown l3 neigh ifindex=" << n.ifindex
<< ", addr=" << n.nh;
continue;
}

VLOG(2) << __FUNCTION__ << ": enabling l3 neigh " << neigh;
unroutable_l3_neighs.erase(n);
add_l3_neigh(neigh);
rtnl_neigh_put(neigh);
VLOG(2) << __FUNCTION__ << ": enabling l3 neigh " << neigh;
unroutable_l3_neighs.erase(n);
add_l3_neigh(neigh);
rtnl_neigh_put(neigh);
}
}

// cleanup
Expand Down Expand Up @@ -1966,24 +1968,26 @@ int nl_l3::del_l3_unicast_route(rtnl_route *r, bool keep_route) {
}
}

VLOG(2) << __FUNCTION__ << ": disabling l3 neighs reachable by route " << r;
auto l3_neighs =
get_l3_neighs_of_prefix(routable_l3_neighs, rtnl_route_get_dst(r));
for (auto n : l3_neighs) {
auto neigh = nl->get_neighbour(n.ifindex, n.nh);
if (!neigh) {
// neigh is already purged from nl cache, so neigh will be
// removed when handling the DEL_NEIGH notification
VLOG(2) << __FUNCTION__
<< ": skipping non-existing l3 neigh ifindex=" << n.ifindex
<< ", addr=" << n.nh;
continue;
}
if (rtnl_route_guess_scope(r) == RT_SCOPE_LINK) {
VLOG(2) << __FUNCTION__ << ": disabling l3 neighs reachable by route " << r;
auto l3_neighs =
get_l3_neighs_of_prefix(routable_l3_neighs, rtnl_route_get_dst(r));
for (auto n : l3_neighs) {
auto neigh = nl->get_neighbour(n.ifindex, n.nh);
if (!neigh) {
// neigh is already purged from nl cache, so neigh will be
// removed when handling the DEL_NEIGH notification
VLOG(2) << __FUNCTION__
<< ": skipping non-existing l3 neigh ifindex=" << n.ifindex
<< ", addr=" << n.nh;
continue;
}

VLOG(2) << __FUNCTION__ << ": disabling l3 neigh " << neigh;
del_l3_neigh(neigh);
rtnl_neigh_put(neigh);
unroutable_l3_neighs.emplace(n);
VLOG(2) << __FUNCTION__ << ": disabling l3 neigh " << neigh;
del_l3_neigh(neigh);
rtnl_neigh_put(neigh);
unroutable_l3_neighs.emplace(n);
}
}

std::deque<struct rtnl_neigh *> neighs;
Expand Down

0 comments on commit fa06f41

Please sign in to comment.