OVS only cares about AF_INET and AF_INET6 routes. However, the current route dumping request uses AF_UNSPEC as rtm_family, which makes the linux kernel inspect other subsystems such as ipmr (IP multicast routing) for potential routes. Even if there are none, ipmr currently requires acquiring the RTNL mutex while IPv4/IPv6 route dumping do not (since 2017) which means that on RTNL-contended scenarios, this unnecessary lookup can be expensive.
This patch adds concrete rtm_family to the netlink requests. Signed-off-by: Adrian Moreno <[email protected]> --- lib/route-table.c | 9 +++++---- lib/route-table.h | 2 +- tests/test-lib-route-table.c | 6 +++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/route-table.c b/lib/route-table.c index 9cc744876..2a13a5cc7 100644 --- a/lib/route-table.c +++ b/lib/route-table.c @@ -190,7 +190,7 @@ route_table_wait(void) } bool -route_table_dump_one_table(uint32_t id, +route_table_dump_one_table(uint32_t id, sa_family_t family, route_table_handle_msg_callback *handle_msg_cb, void *aux) { @@ -205,7 +205,7 @@ route_table_dump_one_table(uint32_t id, nl_msg_put_nlmsghdr(&request, sizeof *rq_msg, RTM_GETROUTE, NLM_F_REQUEST); rq_msg = ofpbuf_put_zeros(&request, sizeof *rq_msg); - rq_msg->rtm_family = AF_UNSPEC; + rq_msg->rtm_family = family; if (id > UCHAR_MAX) { rq_msg->rtm_table = RT_TABLE_UNSPEC; @@ -285,9 +285,10 @@ rule_handle_msg(const struct route_table_msg *change) { if (change->relevant) { const struct rule_data *rd = &change->rud; + sa_family_t family = rd->ipv4 ? AF_INET : AF_INET6; - route_table_dump_one_table(rd->lookup_table, route_table_handle_msg, - NULL); + route_table_dump_one_table(rd->lookup_table, family, + route_table_handle_msg, NULL); ovs_router_rule_add(rd->prio, rd->invert, false, rd->src_len, &rd->from_addr, rd->lookup_table, rd->ipv4); } diff --git a/lib/route-table.h b/lib/route-table.h index b90d431fc..b49fbb14e 100644 --- a/lib/route-table.h +++ b/lib/route-table.h @@ -176,7 +176,7 @@ bool route_table_fallback_lookup(const struct in6_addr *ip6_dst, typedef void route_table_handle_msg_callback(const struct route_table_msg *, void *aux, uint32_t table); -bool route_table_dump_one_table(uint32_t id, +bool route_table_dump_one_table(uint32_t id, sa_family_t family, route_table_handle_msg_callback *, void *aux); int route_table_parse(struct ofpbuf *, void *change); diff --git a/tests/test-lib-route-table.c b/tests/test-lib-route-table.c index 740a02a73..f99f056c8 100644 --- a/tests/test-lib-route-table.c +++ b/tests/test-lib-route-table.c @@ -112,7 +112,11 @@ test_lib_route_table_handle_msg(const struct route_table_msg *change, static void test_lib_route_table_dump(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { - route_table_dump_one_table(RT_TABLE_UNSPEC, + + route_table_dump_one_table(RT_TABLE_UNSPEC, AF_INET, + test_lib_route_table_handle_msg, + NULL); + route_table_dump_one_table(RT_TABLE_UNSPEC, AF_INET6, test_lib_route_table_handle_msg, NULL); } -- 2.52.0 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
