* Detach export datagram from fib instance, if there is any. * If there is no, allocate a new one. */
| 366 | * If there is no, allocate a new one. |
| 367 | */ |
| 368 | item_p |
| 369 | get_export9_dgram(priv_p priv, fib_export_p fe, struct netflow_v9_packet_opt **tt) |
| 370 | { |
| 371 | item_p item = NULL; |
| 372 | struct netflow_v9_packet_opt *t = NULL; |
| 373 | |
| 374 | mtx_lock(&fe->export9_mtx); |
| 375 | if (fe->exp.item9 != NULL) { |
| 376 | item = fe->exp.item9; |
| 377 | fe->exp.item9 = NULL; |
| 378 | t = fe->exp.item9_opt; |
| 379 | fe->exp.item9_opt = NULL; |
| 380 | } |
| 381 | mtx_unlock(&fe->export9_mtx); |
| 382 | |
| 383 | if (item == NULL) { |
| 384 | struct netflow_v9_export_dgram *dgram; |
| 385 | struct mbuf *m; |
| 386 | uint16_t mtu = priv->mtu; |
| 387 | |
| 388 | /* Allocate entire packet at once, allowing easy m_append() calls */ |
| 389 | m = m_getm(NULL, mtu, M_NOWAIT, MT_DATA); |
| 390 | if (m == NULL) |
| 391 | return (NULL); |
| 392 | |
| 393 | t = malloc(sizeof(struct netflow_v9_packet_opt), M_NETFLOW_GENERAL, M_NOWAIT | M_ZERO); |
| 394 | if (t == NULL) { |
| 395 | m_free(m); |
| 396 | return (NULL); |
| 397 | } |
| 398 | |
| 399 | item = ng_package_data(m, NG_NOFLAGS); |
| 400 | if (item == NULL) { |
| 401 | free(t, M_NETFLOW_GENERAL); |
| 402 | return (NULL); |
| 403 | } |
| 404 | |
| 405 | dgram = mtod(m, struct netflow_v9_export_dgram *); |
| 406 | dgram->header.count = 0; |
| 407 | dgram->header.version = htons(NETFLOW_V9); |
| 408 | /* Set mbuf current data length */ |
| 409 | m->m_len = m->m_pkthdr.len = sizeof(struct netflow_v9_header); |
| 410 | |
| 411 | t->count = 0; |
| 412 | t->mtu = mtu; |
| 413 | t->flow_header = m->m_len; |
| 414 | |
| 415 | /* |
| 416 | * Check if we need to insert templates into packet |
| 417 | */ |
| 418 | |
| 419 | struct netflow_v9_flowset_header *fl; |
| 420 | |
| 421 | if ((time_uptime >= priv->templ_time + fe->templ_last_ts) || |
| 422 | (fe->sent_packets >= priv->templ_packets + fe->templ_last_pkt)) { |
| 423 | fe->templ_last_ts = time_uptime; |
| 424 | fe->templ_last_pkt = fe->sent_packets; |
| 425 |
no test coverage detected