Index: sys/net/route/mpath_ctl.c =================================================================== --- sys/net/route/mpath_ctl.c +++ sys/net/route/mpath_ctl.c @@ -117,7 +117,7 @@ * Refresh @rnd_orig data and retry. */ RIB_RLOCK(rnh); - lookup_prefix(rnh, info, rnd_orig); + lookup_prefix_byinfo(rnh, info, rnd_orig); RIB_RUNLOCK(rnh); continue; } Index: sys/net/route/route_ctl.h =================================================================== --- sys/net/route/route_ctl.h +++ sys/net/route/route_ctl.h @@ -77,6 +77,8 @@ rib_walktree_f_t *wa_f, rib_walk_hook_f_t *hook_f, void *arg); void rib_walk_ext_locked(struct rib_head *rnh, rib_walktree_f_t *wa_f, rib_walk_hook_f_t *hook_f, void *arg); +void rib_walk_from_locked(struct rib_head *rnh, struct sockaddr *dst, + struct sockaddr *mask, rib_walktree_f_t *wa_f, void *arg); void rib_walk_del(u_int fibnum, int family, rib_filter_f_t *filter_f, void *arg, bool report); @@ -95,7 +97,7 @@ uint32_t rnd_weight; }; -const struct rtentry *rib_lookup_prefix(uint32_t fibnum, int family, +struct rtentry *rib_lookup_prefix_locked(struct rib_head *rnh, const struct sockaddr *dst, const struct sockaddr *netmask, struct route_nhop_data *rnd); const struct rtentry *rib_lookup_lpm(uint32_t fibnum, int family, Index: sys/net/route/route_ctl.c =================================================================== --- sys/net/route/route_ctl.c +++ sys/net/route/route_ctl.c @@ -490,8 +490,8 @@ * Returns matched @rtentry if found or NULL. * If rtentry was found, saves nexthop / weight value into @rnd. */ -static struct rtentry * -lookup_prefix_bysa(struct rib_head *rnh, const struct sockaddr *dst, +struct rtentry * +rib_lookup_prefix_locked(struct rib_head *rnh, const struct sockaddr *dst, const struct sockaddr *netmask, struct route_nhop_data *rnd) { struct rtentry *rt; @@ -518,12 +518,12 @@ * If rtentry was found, saves nexthop / weight value into @rnd. */ struct rtentry * -lookup_prefix(struct rib_head *rnh, const struct rt_addrinfo *info, +lookup_prefix_byinfo(struct rib_head *rnh, const struct rt_addrinfo *info, struct route_nhop_data *rnd) { struct rtentry *rt; - rt = lookup_prefix_bysa(rnh, info->rti_info[RTAX_DST], + rt = rib_lookup_prefix_locked(rnh, info->rti_info[RTAX_DST], info->rti_info[RTAX_NETMASK], rnd); return (rt); @@ -670,7 +670,7 @@ } /* addition failed. Lookup prefix in the rib to determine the cause */ - rt_orig = lookup_prefix(rnh, info, &rnd_orig); + rt_orig = lookup_prefix_byinfo(rnh, info, &rnd_orig); if (rt_orig == NULL) { /* No prefix -> rnh_addaddr() failed to allocate memory */ RIB_WUNLOCK(rnh); @@ -773,7 +773,7 @@ struct route_nhop_data rnd; int error; - rt = lookup_prefix(rnh, info, &rnd); + rt = lookup_prefix_byinfo(rnh, info, &rnd); if (rt == NULL) return (ESRCH); Index: sys/net/route/route_helpers.c =================================================================== --- sys/net/route/route_helpers.c +++ sys/net/route/route_helpers.c @@ -78,6 +78,13 @@ hook_f(rnh, RIB_WALK_HOOK_POST, arg); } +void +rib_walk_from_locked(struct rib_head *rnh, struct sockaddr *dst, + struct sockaddr *mask, rib_walktree_f_t *wa_f, void *arg) +{ + rnh->rnh_walktree_from(&rnh->head, dst, mask, (walktree_f_t *)wa_f, arg); +} + /* * Calls @wa_f with @arg for each entry in the table specified by * @af and @fibnum. Index: sys/net/route/route_var.h =================================================================== --- sys/net/route/route_var.h +++ sys/net/route/route_var.h @@ -227,7 +227,7 @@ int change_route_conditional(struct rib_head *rnh, struct rtentry *rt, struct rt_addrinfo *info, struct route_nhop_data *nhd_orig, struct route_nhop_data *nhd_new, struct rib_cmd_info *rc); -struct rtentry *lookup_prefix(struct rib_head *rnh, +struct rtentry *lookup_prefix_byinfo(struct rib_head *rnh, const struct rt_addrinfo *info, struct route_nhop_data *rnd); bool nhop_can_multipath(const struct nhop_object *nh); Index: tests/sys/net/routing/rtsock_print.h =================================================================== --- tests/sys/net/routing/rtsock_print.h +++ tests/sys/net/routing/rtsock_print.h @@ -40,7 +40,10 @@ #define RTSOCK_ATF_REQUIRE_MSG(_rtm, _cond, _fmt, ...) do { \ if (!(_cond)) { \ printf("-- CONDITION FAILED, rtm dump --\n\n");\ - rtsock_print_message(_rtm); \ + rtsock_print_message(_rtm); \ + rtsock_print_table(AF_INET); \ + rtsock_print_table(AF_INET6); \ + printf("===================================\n");\ } \ ATF_REQUIRE_MSG(_cond, _fmt, ##__VA_ARGS__); \ } while (0); @@ -381,4 +384,32 @@ } } +static void +print_command(char *cmd) +{ + char line[1024]; + + FILE *fp = popen(cmd, "r"); + if (fp != NULL) { + while (fgets(line, sizeof(line), fp) != NULL) + printf("%s", line); + pclose(fp); + } +} + +void +rtsock_print_table(int family) +{ + char cmdbuf[128]; + char line[1024]; + char *key = (family == AF_INET) ? "4" : "6"; + + snprintf(cmdbuf, sizeof(cmdbuf), "/usr/bin/netstat -%srnW", key); + printf("==== %s ===\n", cmdbuf); + print_command(cmdbuf); + snprintf(cmdbuf, sizeof(cmdbuf), "/usr/bin/netstat -%sonW", key); + printf("==== %s ===\n", cmdbuf); + print_command(cmdbuf); +} + #endif