From 730bfa28057405b44a0b55a4dc35cdc42144ff6d Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Fri, 12 Aug 2022 09:31:21 +0000 Subject: [PATCH] routing: add rib_match_gw() helper Finish 02e05b8faec1: * add gateway matcher function that can be used in rib_del_route_px() or any rib_walk-family functions. It will be used in the upcoming migration to the new KPI * rename gw_fulter_func to match_gw_one() to better signal the function purpose / semantic. MFC after: 1 month --- sys/net/route/route_ctl.c | 21 ++++++++++++++++++--- sys/net/route/route_ctl.h | 3 +++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c index a2ac05d2afc8..dbfa25500df4 100644 --- a/sys/net/route/route_ctl.c +++ b/sys/net/route/route_ctl.c @@ -290,13 +290,28 @@ match_nhop_gw(const struct nhop_object *nh, const struct sockaddr *gw) return (false); } +/* + * Matches all nexthop with given @gw. + * Can be used as rib_filter_f callback. + */ +int +rib_match_gw(const struct rtentry *rt, const struct nhop_object *nh, void *gw_sa) +{ + const struct sockaddr *gw = (const struct sockaddr *)gw_sa; + + return (match_nhop_gw(nh, gw)); +} + struct gw_filter_data { const struct sockaddr *gw; int count; }; +/* + * Matches first occurence of the gateway provided in @gwd + */ static int -gw_fulter_func(const struct rtentry *rt, const struct nhop_object *nh, void *_data) +match_gw_one(const struct rtentry *rt, const struct nhop_object *nh, void *_data) { struct gw_filter_data *gwd = (struct gw_filter_data *)_data; @@ -518,7 +533,7 @@ rib_del_route_px_gw(uint32_t fibnum, struct sockaddr *dst, int plen, { struct gw_filter_data gwd = { .gw = gw }; - return (rib_del_route_px(fibnum, dst, plen, gw_fulter_func, &gwd, op_flags, rc)); + return (rib_del_route_px(fibnum, dst, plen, match_gw_one, &gwd, op_flags, rc)); } /* @@ -955,7 +970,7 @@ rib_del_route(uint32_t fibnum, struct rt_addrinfo *info, struct rib_cmd_info *rc filter_func = info->rti_filter; filter_arg = info->rti_filterdata; } else if (gwd.gw != NULL) { - filter_func = gw_fulter_func; + filter_func = match_gw_one; filter_arg = &gwd; } diff --git a/sys/net/route/route_ctl.h b/sys/net/route/route_ctl.h index 299885d5be2b..19fe5362b6ec 100644 --- a/sys/net/route/route_ctl.h +++ b/sys/net/route/route_ctl.h @@ -77,6 +77,9 @@ int rib_action(uint32_t fibnum, int action, struct rt_addrinfo *info, struct rib_cmd_info *rc); int rib_handle_ifaddr_info(uint32_t fibnum, int cmd, struct rt_addrinfo *info); +int rib_match_gw(const struct rtentry *rt, const struct nhop_object *nh, + void *gw_sa); + typedef void route_notification_t(struct rib_cmd_info *rc, void *); void rib_decompose_notification(struct rib_cmd_info *rc, route_notification_t *cb, void *cbdata);