* Function returning prefix match data along with the nexthop data. * Intended to be used by the control plane code. * Supported flags: * NHR_UNLOCKED: do not lock radix during lookup. * Returns pointer to rtentry and raw nexthop in @rnd. Both rtentry * and nexthop are safe to use within current epoch. Note: * Note: rnd_nhop can actually be the nexthop group. */
| 278 | * Note: rnd_nhop can actually be the nexthop group. |
| 279 | */ |
| 280 | struct rtentry * |
| 281 | fib4_lookup_rt(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, |
| 282 | uint32_t flags, struct route_nhop_data *rnd) |
| 283 | { |
| 284 | RIB_RLOCK_TRACKER; |
| 285 | struct rib_head *rh; |
| 286 | struct radix_node *rn; |
| 287 | struct rtentry *rt; |
| 288 | |
| 289 | KASSERT((fibnum < rt_numfibs), ("fib4_lookup_rt: bad fibnum")); |
| 290 | rh = rt_tables_get_rnh(fibnum, AF_INET); |
| 291 | if (rh == NULL) |
| 292 | return (NULL); |
| 293 | |
| 294 | /* Prepare lookup key */ |
| 295 | struct sockaddr_in sin4 = { |
| 296 | .sin_family = AF_INET, |
| 297 | .sin_len = sizeof(struct sockaddr_in), |
| 298 | .sin_addr = dst, |
| 299 | }; |
| 300 | |
| 301 | rt = NULL; |
| 302 | if (!(flags & NHR_UNLOCKED)) |
| 303 | RIB_RLOCK(rh); |
| 304 | rn = rh->rnh_matchaddr((void *)&sin4, &rh->head); |
| 305 | if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) { |
| 306 | rt = (struct rtentry *)rn; |
| 307 | rnd->rnd_nhop = rt->rt_nhop; |
| 308 | rnd->rnd_weight = rt->rt_weight; |
| 309 | } |
| 310 | if (!(flags & NHR_UNLOCKED)) |
| 311 | RIB_RUNLOCK(rh); |
| 312 | |
| 313 | return (rt); |
| 314 | } |
| 315 | |
| 316 | struct nhop_object * |
| 317 | fib4_lookup_debugnet(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, |
no test coverage detected