Index: sys/net/route.c =================================================================== --- sys/net/route.c +++ sys/net/route.c @@ -161,6 +161,7 @@ tmproutes_destroy(rh); + rib_flush_routes(rh); rn_walktree(&rh->rmhead.head, rt_freeentry, &rh->rmhead.head); nhops_destroy_rib(rh); Index: sys/net/route/route_ctl.c =================================================================== --- sys/net/route/route_ctl.c +++ sys/net/route/route_ctl.c @@ -1328,6 +1328,31 @@ NET_EPOCH_EXIT(et); } +static int +rt_delete_unconditional(struct radix_node *rn, void *arg) +{ + struct rtentry *rt = RNTORT(rn); + struct rib_head *rnh = (struct rib_head *)arg; + + rn = rnh->rnh_deladdr(rt_key(rt), rt_mask(rt), &rnh->head); + if (RNTORT(rn) == rt) + rtfree(rt); + + return (0); +} + +/* + * Removes all routes from the routing table without executing notifications. + * rtentres will be removed after the end of a current epoch. + */ +void +rib_flush_routes(struct rib_head *rnh) +{ + RIB_WLOCK(rnh); + rnh->rnh_walktree(&rnh->head, rt_delete_unconditional, rnh); + RIB_WUNLOCK(rnh); +} + static void rib_notify(struct rib_head *rnh, enum rib_subscription_type type, struct rib_cmd_info *rc) Index: sys/net/route/route_var.h =================================================================== --- sys/net/route/route_var.h +++ sys/net/route/route_var.h @@ -224,6 +224,8 @@ int can_override_nhop(const struct rt_addrinfo *info, const struct nhop_object *nh); +void rib_flush_routes(struct rib_head *rnh); + void vnet_rtzone_init(void); void vnet_rtzone_destroy(void);