MCPcopy Create free account
hub / github.com/F-Stack/f-stack / siftr_pkt_manager_thread

Function siftr_pkt_manager_thread

freebsd/netinet/siftr.c:561–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

559}
560
561static void
562siftr_pkt_manager_thread(void *arg)
563{
564 STAILQ_HEAD(pkthead, pkt_node) tmp_pkt_queue =
565 STAILQ_HEAD_INITIALIZER(tmp_pkt_queue);
566 struct pkt_node *pkt_node, *pkt_node_temp;
567 uint8_t draining;
568
569 draining = 2;
570
571 mtx_lock(&siftr_pkt_mgr_mtx);
572
573 /* draining == 0 when queue has been flushed and it's safe to exit. */
574 while (draining) {
575 /*
576 * Sleep until we are signalled to wake because thread has
577 * been told to exit or until 1 tick has passed.
578 */
579 mtx_sleep(&wait_for_pkt, &siftr_pkt_mgr_mtx, PWAIT, "pktwait",
580 1);
581
582 /* Gain exclusive access to the pkt_node queue. */
583 mtx_lock(&siftr_pkt_queue_mtx);
584
585 /*
586 * Move pkt_queue to tmp_pkt_queue, which leaves
587 * pkt_queue empty and ready to receive more pkt_nodes.
588 */
589 STAILQ_CONCAT(&tmp_pkt_queue, &pkt_queue);
590
591 /*
592 * We've finished making changes to the list. Unlock it
593 * so the pfil hooks can continue queuing pkt_nodes.
594 */
595 mtx_unlock(&siftr_pkt_queue_mtx);
596
597 /*
598 * We can't hold a mutex whilst calling siftr_process_pkt
599 * because ALQ might sleep waiting for buffer space.
600 */
601 mtx_unlock(&siftr_pkt_mgr_mtx);
602
603 /* Flush all pkt_nodes to the log file. */
604 STAILQ_FOREACH_SAFE(pkt_node, &tmp_pkt_queue, nodes,
605 pkt_node_temp) {
606 siftr_process_pkt(pkt_node);
607 STAILQ_REMOVE_HEAD(&tmp_pkt_queue, nodes);
608 free(pkt_node, M_SIFTR_PKTNODE);
609 }
610
611 KASSERT(STAILQ_EMPTY(&tmp_pkt_queue),
612 ("SIFTR tmp_pkt_queue not empty after flush"));
613
614 mtx_lock(&siftr_pkt_mgr_mtx);
615
616 /*
617 * If siftr_exit_pkt_manager_thread gets set during the window
618 * where we are draining the tmp_pkt_queue above, there might

Callers

nothing calls this directly

Calls 4

mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50
freeFunction · 0.50
kthread_exitFunction · 0.50

Tested by

no test coverage detected