| 318 | */ |
| 319 | #ifdef INET |
| 320 | static int |
| 321 | hash_insert(priv_p priv, struct flow_hash_entry *hsh, struct flow_rec *r, |
| 322 | int plen, uint8_t flags, uint8_t tcp_flags) |
| 323 | { |
| 324 | struct flow_entry *fle; |
| 325 | |
| 326 | mtx_assert(&hsh->mtx, MA_OWNED); |
| 327 | |
| 328 | fle = uma_zalloc_arg(priv->zone, priv, M_NOWAIT); |
| 329 | if (fle == NULL) { |
| 330 | priv->nfinfo_alloc_failed++; |
| 331 | return (ENOMEM); |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * Now fle is totally ours. It is detached from all lists, |
| 336 | * we can safely edit it. |
| 337 | */ |
| 338 | fle->f.version = IPVERSION; |
| 339 | bcopy(r, &fle->f.r, sizeof(struct flow_rec)); |
| 340 | fle->f.bytes = plen; |
| 341 | fle->f.packets = 1; |
| 342 | fle->f.tcp_flags = tcp_flags; |
| 343 | |
| 344 | fle->f.first = fle->f.last = time_uptime; |
| 345 | |
| 346 | /* |
| 347 | * First we do route table lookup on destination address. So we can |
| 348 | * fill in out_ifx, dst_mask, nexthop, and dst_as in future releases. |
| 349 | */ |
| 350 | if ((flags & NG_NETFLOW_CONF_NODSTLOOKUP) == 0) { |
| 351 | struct rtentry *rt; |
| 352 | struct route_nhop_data rnd; |
| 353 | |
| 354 | rt = fib4_lookup_rt(r->fib, fle->f.r.r_dst, 0, NHR_NONE, &rnd); |
| 355 | if (rt != NULL) { |
| 356 | struct in_addr addr; |
| 357 | uint32_t scopeid; |
| 358 | struct nhop_object *nh = nhop_select_func(rnd.rnd_nhop, 0); |
| 359 | int plen; |
| 360 | |
| 361 | rt_get_inet_prefix_plen(rt, &addr, &plen, &scopeid); |
| 362 | fle->f.fle_o_ifx = nh->nh_ifp->if_index; |
| 363 | if (nh->gw_sa.sa_len == AF_INET) |
| 364 | fle->f.next_hop = nh->gw4_sa.sin_addr; |
| 365 | fle->f.dst_mask = plen; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /* Do route lookup on source address, to fill in src_mask. */ |
| 370 | if ((flags & NG_NETFLOW_CONF_NOSRCLOOKUP) == 0) { |
| 371 | struct rtentry *rt; |
| 372 | struct route_nhop_data rnd; |
| 373 | |
| 374 | rt = fib4_lookup_rt(r->fib, fle->f.r.r_src, 0, NHR_NONE, &rnd); |
| 375 | if (rt != NULL) { |
| 376 | struct in_addr addr; |
| 377 | uint32_t scopeid; |
no test coverage detected