Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F174198214
D59907.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
19 KB
Referenced Files
None
Subscribers
None
D59907.diff
View Options
diff --git a/share/man/man4/siftr.4 b/share/man/man4/siftr.4
--- a/share/man/man4/siftr.4
+++ b/share/man/man4/siftr.4
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 29, 2023
+.Dd Sep 24, 2026
.Dt SIFTR 4
.Os
.Sh NAME
@@ -338,7 +338,8 @@
total_tcp_pkts=20 num_inbound_skipped_pkts_malloc=0 \\
num_outbound_skipped_pkts_malloc=0 num_inbound_skipped_pkts_tcpcb=2 \\
num_outbound_skipped_pkts_tcpcb=2 num_inbound_skipped_pkts_inpcb=0 \\
-num_outbound_skipped_pkts_inpcb=0 total_skipped_tcp_pkts=4 \\
+num_outbound_skipped_pkts_inpcb=0 num_skipped_pkts_pktpool=0 \\
+total_skipped_tcp_pkts=4 \\
flow_list=10.1.1.2;32291-10.1.1.3;5001,10.1.1.2;58544-10.1.1.3;5001,
.Ed
.Pp
@@ -402,6 +403,11 @@
the IP control block associated with the packet.
.El
.Bl -tag -offset indent -width Va
+.It Va num_skipped_pkts_pktpool
+Number of packets that were not processed because of failure to add the packet
+to the packet processing pool.
+.El
+.Bl -tag -offset indent -width Va
.It Va total_skipped_tcp_pkts
The summation of all skipped packet counters.
.El
@@ -469,11 +475,6 @@
----------------------------------
.Ed
.Pp
-.Nm
-uses the
-.Xr alq 9
-interface to manage writing data to disk.
-.Pp
At first glance, you might mistakenly think that
.Nm
extracts information from
@@ -589,7 +590,6 @@
.Xr tcpdump 1 ,
.Xr tcp 4 ,
.Xr sysctl 8 ,
-.Xr alq 9 ,
.Xr pfil 9
.Sh ACKNOWLEDGEMENTS
Development of this software was made possible in part by grants from the
diff --git a/sys/modules/siftr/Makefile b/sys/modules/siftr/Makefile
--- a/sys/modules/siftr/Makefile
+++ b/sys/modules/siftr/Makefile
@@ -1,6 +1,7 @@
.PATH: ${SRCTOP}/sys/netinet
KMOD= siftr
SRCS= siftr.c opt_kern_tls.h
+SRCS+= vnode_if.h
# Uncomment to add IPv6 support
#CFLAGS+=-DSIFTR_IPV6
diff --git a/sys/netinet/siftr.c b/sys/netinet/siftr.c
--- a/sys/netinet/siftr.c
+++ b/sys/netinet/siftr.c
@@ -61,13 +61,14 @@
******************************************************/
#include <sys/param.h>
-#include <sys/alq.h>
+#include <sys/systm.h>
+#include <sys/buf_ring.h>
#include <sys/errno.h>
#include <sys/eventhandler.h>
-#include <sys/hash.h>
+#include <sys/fcntl.h>
+#include <sys/file.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
-#include <sys/lock.h>
#include <sys/mbuf.h>
#include <sys/module.h>
#include <sys/mutex.h>
@@ -79,19 +80,21 @@
#include <sys/smp.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/unistd.h>
+#include <sys/vnode.h>
+
+#include <machine/in_cksum.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/pfil.h>
-#include <net/route.h>
#include <netinet/in.h>
#include <netinet/in_kdtrace.h>
#include <netinet/in_fib.h>
#include <netinet/in_pcb.h>
-#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
@@ -104,8 +107,6 @@
#include <netinet6/in6_pcb.h>
#endif /* SIFTR_IPV6 */
-#include <machine/in_cksum.h>
-
/*
* Three digit version number refers to X.Y.Z where:
* X is the major version number
@@ -113,7 +114,7 @@
* Z is bumped to mark backwards compatible changes
*/
#define V_MAJOR 1
-#define V_BACKBREAK 3
+#define V_BACKBREAK 4
#define V_BACKCOMPAT 0
#define MODVERSION __CONCAT(V_MAJOR, __CONCAT(V_BACKBREAK, V_BACKCOMPAT))
#define MODVERSION_STR __XSTRING(V_MAJOR) "." __XSTRING(V_BACKBREAK) "." \
@@ -134,9 +135,12 @@
* data fields such that the line length could exceed the below value.
*/
#define MAX_LOG_MSG_LEN 300
-#define MAX_LOG_BATCH_SIZE 3
-/* XXX: Make this a sysctl tunable. */
-#define SIFTR_ALQ_BUFLEN (1000*MAX_LOG_MSG_LEN)
+#define BATCHBUF_SIZE (PAGE_SIZE + MAX_LOG_MSG_LEN)
+#define RING_SIZE 16384
+
+/* Ensure RING_SIZE remains a power of two (and non-zero). */
+_Static_assert(RING_SIZE != 0 && ((RING_SIZE & (RING_SIZE - 1)) == 0),
+ "RING_SIZE must be a power of two");
#ifdef SIFTR_IPV6
#define SIFTR_IPMODE 6
@@ -145,8 +149,6 @@
#endif
static MALLOC_DEFINE(M_SIFTR, "siftr", "dynamic memory used by SIFTR");
-static MALLOC_DEFINE(M_SIFTR_PKTNODE, "siftr_pktnode",
- "SIFTR pkt_node struct");
static MALLOC_DEFINE(M_SIFTR_HASHNODE, "siftr_hashnode",
"SIFTR flow_hash_node struct");
@@ -253,6 +255,8 @@
/* # pkts skipped due to stack reinjection. */
uint32_t nskip_in_dejavu;
uint32_t nskip_out_dejavu;
+ /* # pkts skipped due to buf_ring overflow. */
+ uint32_t nskip_pkt_pool;
};
DPCPU_DEFINE_STATIC(struct siftr_stats, ss);
@@ -265,19 +269,27 @@
static char siftr_logfile[PATH_MAX] = "/var/log/siftr.log";
static char siftr_logfile_shadow[PATH_MAX] = "/var/log/siftr.log";
static u_long siftr_hashmask;
-STAILQ_HEAD(pkthead, pkt_node) pkt_queue = STAILQ_HEAD_INITIALIZER(pkt_queue);
LIST_HEAD(listhead, flow_hash_node) *counter_hash;
static int wait_for_pkt;
-static struct alq *siftr_alq = NULL;
-static struct mtx siftr_pkt_queue_mtx;
static struct mtx siftr_pkt_mgr_mtx;
static struct thread *siftr_pkt_manager_thr = NULL;
static char direction[2] = {'i','o'};
static eventhandler_tag siftr_shutdown_tag;
+static struct pkt_node pkt_pool[RING_SIZE];
+/* producer write index for pkt_pool */
+static uint32_t pkt_pool_write_idx = 0;
+/* a buf_ring that stores indexes to pkt_pool */
+static struct buf_ring *siftr_br = NULL;
+static struct mtx siftr_br_mtx;
+static struct vnode *siftr_vnode = NULL;
+static struct ucred *siftr_vnode_cred = NULL;
+
/* Required function prototypes. */
static int siftr_sysctl_enabled_handler(SYSCTL_HANDLER_ARGS);
static int siftr_sysctl_logfile_name_handler(SYSCTL_HANDLER_ARGS);
+static int siftr_open_log(struct thread *td);
+static int siftr_write_log(struct thread *td, char *buf, size_t len);
/* Declare the net.inet.siftr sysctl tree and populate it. */
@@ -439,21 +451,26 @@
pkt_node->flowid,
pkt_node->flowtype);
- return ret_sz;
+ KASSERT(ret_sz < MAX_LOG_MSG_LEN, ("SIFTR snprintf buffer truncated"));
+
+ return (ret_sz >= MAX_LOG_MSG_LEN) ? (MAX_LOG_MSG_LEN - 1) : ret_sz;
+}
+
+static inline uint32_t ptr_to_idx(void *p) {
+ return (uint32_t)(uintptr_t)p;
}
static void
siftr_pkt_manager_thread(void *arg)
{
- STAILQ_HEAD(pkthead, pkt_node) tmp_pkt_queue =
- STAILQ_HEAD_INITIALIZER(tmp_pkt_queue);
- struct pkt_node *pkt_node;
+ struct pkt_node *pn;
uint8_t draining;
- struct ale *log_buf;
- int ret_sz, cnt = 0;
- char *bufp;
+ char batchbuf[BATCHBUF_SIZE];
+ size_t linelen, sum, batchlen;
+ void *val;
draining = 2;
+ batchlen = 0;
mtx_lock(&siftr_pkt_mgr_mtx);
@@ -465,83 +482,59 @@
*/
mtx_sleep(&wait_for_pkt, &siftr_pkt_mgr_mtx, PWAIT, "pktwait",
1);
-
- /* Gain exclusive access to the pkt_node queue. */
- mtx_lock(&siftr_pkt_queue_mtx);
-
- /*
- * Move pkt_queue to tmp_pkt_queue, which leaves
- * pkt_queue empty and ready to receive more pkt_nodes.
- */
- STAILQ_CONCAT(&tmp_pkt_queue, &pkt_queue);
-
- /*
- * We've finished making changes to the list. Unlock it
- * so the pfil hooks can continue queuing pkt_nodes.
- */
- mtx_unlock(&siftr_pkt_queue_mtx);
-
- /*
- * We can't hold a mutex whilst calling siftr_process_pkt
- * because ALQ might sleep waiting for buffer space.
- */
mtx_unlock(&siftr_pkt_mgr_mtx);
- while ((pkt_node = STAILQ_FIRST(&tmp_pkt_queue)) != NULL) {
-
- log_buf = alq_getn(siftr_alq, MAX_LOG_MSG_LEN *
- ((STAILQ_NEXT(pkt_node, nodes) != NULL) ?
- MAX_LOG_BATCH_SIZE : 1),
- ALQ_WAITOK);
-
- if (log_buf != NULL) {
- log_buf->ae_bytesused = 0;
- bufp = log_buf->ae_data;
- } else {
- /*
- * Should only happen if the ALQ is shutting
- * down.
- */
- bufp = NULL;
+ /* Drain all indexed packets, provided by the pkt_pool. */
+ while (true) {
+ mtx_lock(&siftr_br_mtx);
+ val = buf_ring_dequeue_sc(siftr_br);
+ mtx_unlock(&siftr_br_mtx);
+ if (val == NULL) {
+ break;
}
+ pn = &pkt_pool[ptr_to_idx(val)];
+ linelen = siftr_process_pkt(pn, &batchbuf[batchlen]);
+
+ sum = batchlen + linelen;
+ if (sum < PAGE_SIZE) {
+ /* still within the current page */
+ batchlen = sum;
+ } else if (sum == PAGE_SIZE) {
+ /* perfect fit: write a full page */
+ siftr_write_log(curthread, batchbuf, PAGE_SIZE);
+ batchlen = 0;
+ } else {
+ /* crossing a page boundary: split the record */
+ size_t tail = linelen - (PAGE_SIZE - batchlen);
+ siftr_write_log(curthread, batchbuf, PAGE_SIZE);
- /* Flush all pkt_nodes to the log file. */
- STAILQ_FOREACH(pkt_node, &tmp_pkt_queue, nodes) {
- if (log_buf != NULL) {
- ret_sz = siftr_process_pkt(pkt_node,
- bufp);
- bufp += ret_sz;
- log_buf->ae_bytesused += ret_sz;
- }
- if (++cnt >= MAX_LOG_BATCH_SIZE)
- break;
- }
- if (log_buf != NULL) {
- alq_post_flags(siftr_alq, log_buf, 0);
- }
- for (; cnt > 0; cnt--) {
- pkt_node = STAILQ_FIRST(&tmp_pkt_queue);
- STAILQ_REMOVE_HEAD(&tmp_pkt_queue, nodes);
- free(pkt_node, M_SIFTR_PKTNODE);
+ /* Move the overflow (tail of the record) to the
+ * start of the buffer.
+ */
+ memmove(batchbuf, &batchbuf[PAGE_SIZE], tail);
+ batchlen = tail;
}
}
- KASSERT(STAILQ_EMPTY(&tmp_pkt_queue),
- ("SIFTR tmp_pkt_queue not empty after flush"));
+ /* Flush any accumulated batch if idle */
+ if (batchlen > 0) {
+ siftr_write_log(curthread, batchbuf, batchlen);
+ batchlen = 0;
+ }
mtx_lock(&siftr_pkt_mgr_mtx);
/*
* If siftr_exit_pkt_manager_thread gets set during the window
- * where we are draining the tmp_pkt_queue above, there might
- * still be pkts in pkt_queue that need to be drained.
+ * where we are draining the pkt_pool above, there might
+ * still be pkts in pkt_pool that need to be drained.
* Allow one further iteration to occur after
* siftr_exit_pkt_manager_thread has been set to ensure
- * pkt_queue is completely empty before we kill the thread.
+ * pkt_pool is completely empty before we kill the thread.
*
* siftr_exit_pkt_manager_thread is set only after the pfil
* hooks have been removed, so only 1 extra iteration
- * is needed to drain the queue.
+ * is needed to drain the pkt_pool.
*/
if (siftr_exit_pkt_manager_thread)
draining--;
@@ -710,6 +703,10 @@
TCP_PROBE1(siftr, pn);
}
+static inline void *idx_to_ptr(uint32_t idx) {
+ return (void *)(uintptr_t)idx;
+}
+
/*
* pfil hook that is called for each IPv4 packet making its way through the
* stack in either direction.
@@ -729,7 +726,7 @@
struct siftr_stats *ss;
unsigned int ip_hl;
int inp_locally_locked, dir;
- uint32_t hash_id, hash_type;
+ uint32_t hash_id, hash_type, idx;
struct listhead *counter_list;
struct flow_hash_node *hash_node;
@@ -758,7 +755,7 @@
/*
* Only pkts selected by the tcp port filter
- * can be inserted into the pkt_queue
+ * can be inserted into the pkt_pool
*/
if ((siftr_port_filter != 0) &&
(siftr_port_filter != ntohs(th->th_sport)) &&
@@ -835,25 +832,21 @@
goto inp_unlock;
}
- pn = malloc(sizeof(struct pkt_node), M_SIFTR_PKTNODE, M_NOWAIT|M_ZERO);
-
- if (pn == NULL) {
- if (dir == PFIL_IN)
- ss->nskip_in_malloc++;
- else
- ss->nskip_out_malloc++;
-
- goto inp_unlock;
- }
+ idx = atomic_fetchadd_32(&pkt_pool_write_idx, 1) & (RING_SIZE - 1);
+ pn = &pkt_pool[idx];
pn->flowid = hash_id;
pn->flowtype = hash_type;
siftr_siftdata(pn, inp, tp, INP_IPV4, dir, inp_locally_locked);
- mtx_lock(&siftr_pkt_queue_mtx);
- STAILQ_INSERT_TAIL(&pkt_queue, pn, nodes);
- mtx_unlock(&siftr_pkt_queue_mtx);
+ if (buf_ring_enqueue(siftr_br, idx_to_ptr(idx)) != 0) {
+ /* drop if full */
+ ss->nskip_pkt_pool++;
+ } else if (buf_ring_count(siftr_br) > (RING_SIZE >> 2)) {
+ /* nudge consumer when the buf_ring is at least 1/4 full */
+ wakeup(&wait_for_pkt);
+ }
goto ret;
inp_unlock:
@@ -876,7 +869,7 @@
struct siftr_stats *ss;
unsigned int ip6_hl;
int inp_locally_locked, dir;
- uint32_t hash_id, hash_type;
+ uint32_t hash_id, hash_type, idx;
struct listhead *counter_list;
struct flow_hash_node *hash_node;
@@ -909,7 +902,7 @@
/*
* Only pkts selected by the tcp port filter
- * can be inserted into the pkt_queue
+ * can be inserted into the pkt_pool
*/
if ((siftr_port_filter != 0) &&
(siftr_port_filter != ntohs(th->th_sport)) &&
@@ -984,25 +977,21 @@
goto inp_unlock6;
}
- pn = malloc(sizeof(struct pkt_node), M_SIFTR_PKTNODE, M_NOWAIT|M_ZERO);
-
- if (pn == NULL) {
- if (dir == PFIL_IN)
- ss->nskip_in_malloc++;
- else
- ss->nskip_out_malloc++;
-
- goto inp_unlock6;
- }
+ idx = atomic_fetchadd_32(&pkt_pool_write_idx, 1) & (RING_SIZE - 1);
+ pn = &pkt_pool[idx];
pn->flowid = hash_id;
pn->flowtype = hash_type;
siftr_siftdata(pn, inp, tp, INP_IPV6, dir, inp_locally_locked);
- mtx_lock(&siftr_pkt_queue_mtx);
- STAILQ_INSERT_TAIL(&pkt_queue, pn, nodes);
- mtx_unlock(&siftr_pkt_queue_mtx);
+ if (buf_ring_enqueue(siftr_br, idx_to_ptr(idx)) != 0) {
+ /* drop if full */
+ ss->nskip_pkt_pool++;
+ } else if (buf_ring_count(siftr_br) > (RING_SIZE >> 2)) {
+ /* nudge consumer when the buf_ring is at least 1/4 full */
+ wakeup(&wait_for_pkt);
+ }
goto ret6;
inp_unlock6:
@@ -1071,39 +1060,70 @@
static int
siftr_sysctl_logfile_name_handler(SYSCTL_HANDLER_ARGS)
{
- struct alq *new_alq;
int error;
error = sysctl_handle_string(oidp, arg1, arg2, req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+ /* Update active filename if changed */
+ if (strncmp(siftr_logfile, arg1, arg2) != 0)
+ strlcpy(siftr_logfile, arg1, arg2);
+ return (0);
+}
- /* Check for error or same filename */
- if (error != 0 || req->newptr == NULL ||
- strncmp(siftr_logfile, arg1, arg2) == 0)
- goto done;
+/*
+ * Open the log file for writing. The O_TRUNC flag will truncate the file to
+ * zero length if the file already exists, effectively cleaning it. O_CREAT
+ * creates the file if it does not already exist. UIO_SYSSPACE is used because
+ * the data being written is in kernel space.
+ */
+static int
+siftr_open_log(struct thread *td)
+{
+ struct file *fp;
+ int err, flags;
- /* file name changed */
- error = alq_open(&new_alq, arg1, curthread->td_ucred,
- SIFTR_LOG_FILE_MODE, SIFTR_ALQ_BUFLEN, 0);
- if (error != 0)
- goto done;
+ flags = FWRITE | O_NOFOLLOW | O_CREAT | O_TRUNC;
+ if ((err = kern_openatfp(td, AT_FDCWD, siftr_logfile, UIO_SYSSPACE,
+ flags, SIFTR_LOG_FILE_MODE, &fp)) != 0) {
+ return (err);
+ }
- /*
- * If disabled, siftr_alq == NULL so we simply close
- * the alq as we've proved it can be opened.
- * If enabled, close the existing alq and switch the old
- * for the new.
- */
- if (siftr_alq == NULL) {
- alq_close(new_alq);
- } else {
- alq_close(siftr_alq);
- siftr_alq = new_alq;
+ /* keep vnode around; increment ref */
+ siftr_vnode = fp->f_vnode;
+ siftr_vnode_cred = crhold(td->td_ucred);
+
+ return (err);
+}
+
+/* Write to logfile */
+static int
+siftr_write_log(struct thread *td, char *buf, size_t len)
+{
+ struct iovec iov;
+ struct uio uio;
+ int err;
+
+ /* Set up uio for writing */
+ iov.iov_base = buf;
+ iov.iov_len = len;
+
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+ uio.uio_offset = 0;
+ uio.uio_resid = iov.iov_len;
+ uio.uio_segflg = UIO_SYSSPACE;
+ uio.uio_rw = UIO_WRITE;
+ uio.uio_td = td;
+
+ /* Write the data */
+ vn_lock(siftr_vnode, LK_EXCLUSIVE | LK_RETRY);
+ if ((err = VOP_WRITE(siftr_vnode, &uio, IO_APPEND | IO_UNIT,
+ siftr_vnode_cred)) != 0) {
}
+ VOP_UNLOCK(siftr_vnode);
- /* Update filename upon success */
- strlcpy(siftr_logfile, arg1, arg2);
-done:
- return (error);
+ return err;
}
static int
@@ -1114,28 +1134,32 @@
struct flow_hash_node *counter, *tmp_counter;
struct sbuf *s;
int i, error;
- uint32_t bytes_to_write, total_skipped_pkts;
+ uint32_t total_skipped_pkts;
error = 0;
total_skipped_pkts = 0;
/* Init an autosizing sbuf that initially holds 200 chars. */
if ((s = sbuf_new(NULL, NULL, 200, SBUF_AUTOEXTEND)) == NULL)
- return (-1);
+ return (ENOMEM);
if (action == SIFTR_ENABLE && siftr_pkt_manager_thr == NULL) {
- /*
- * Create our alq
- * XXX: We should abort if alq_open fails!
- */
- alq_open(&siftr_alq, siftr_logfile, curthread->td_ucred,
- SIFTR_LOG_FILE_MODE, SIFTR_ALQ_BUFLEN, 0);
+ DPCPU_ZERO(ss);
- STAILQ_INIT(&pkt_queue);
+ /* Initialize buf_ring */
+ mtx_init(&siftr_br_mtx, "siftr buf_ring mtx", NULL, MTX_DEF);
+ siftr_br = buf_ring_alloc(RING_SIZE, M_SIFTR, M_NOWAIT,
+ &siftr_br_mtx);
+ if (siftr_br == NULL) {
+ return (ENOMEM);
+ }
- DPCPU_ZERO(ss);
+ if ((error = siftr_open_log(curthread)) != 0) {
+ return (error);
+ }
siftr_exit_pkt_manager_thread = 0;
+ pkt_pool_write_idx = 0;
kthread_add(&siftr_pkt_manager_thread, NULL, NULL,
&siftr_pkt_manager_thr, RFNOWAIT, 0,
@@ -1152,7 +1176,7 @@
SYS_NAME, __FreeBSD_version, SIFTR_IPMODE);
sbuf_finish(s);
- alq_writen(siftr_alq, sbuf_data(s), sbuf_len(s), ALQ_WAITOK);
+ error = siftr_write_log(curthread, sbuf_data(s), sbuf_len(s));
} else if (action == SIFTR_DISABLE && siftr_pkt_manager_thr != NULL) {
/*
@@ -1191,11 +1215,12 @@
totalss.nskip_out_tcpcb = DPCPU_VARSUM(ss, nskip_out_tcpcb);
totalss.nskip_in_inpcb = DPCPU_VARSUM(ss, nskip_in_inpcb);
totalss.nskip_out_inpcb = DPCPU_VARSUM(ss, nskip_out_inpcb);
+ totalss.nskip_pkt_pool = DPCPU_VARSUM(ss, nskip_pkt_pool);
total_skipped_pkts = totalss.nskip_in_malloc +
totalss.nskip_out_malloc + totalss.nskip_in_tcpcb +
totalss.nskip_out_tcpcb + totalss.nskip_in_inpcb +
- totalss.nskip_out_inpcb;
+ totalss.nskip_out_inpcb + totalss.nskip_pkt_pool;
microtime(&tval);
@@ -1208,6 +1233,7 @@
"num_outbound_skipped_pkts_tcpcb=%u\t"
"num_inbound_skipped_pkts_inpcb=%u\t"
"num_outbound_skipped_pkts_inpcb=%u\t"
+ "num_skipped_pkts_pktpool=%u\t"
"total_skipped_tcp_pkts=%u\tflow_list=",
(intmax_t)tval.tv_sec,
tval.tv_usec,
@@ -1220,6 +1246,7 @@
totalss.nskip_out_tcpcb,
totalss.nskip_in_inpcb,
totalss.nskip_out_inpcb,
+ totalss.nskip_pkt_pool,
total_skipped_pkts);
/*
@@ -1245,15 +1272,27 @@
sbuf_printf(s, "\n");
sbuf_finish(s);
- i = 0;
- do {
- bytes_to_write = min(SIFTR_ALQ_BUFLEN, sbuf_len(s)-i);
- alq_writen(siftr_alq, sbuf_data(s)+i, bytes_to_write, ALQ_WAITOK);
- i += bytes_to_write;
- } while (i < sbuf_len(s));
+ error = siftr_write_log(curthread, sbuf_data(s), sbuf_len(s));
+
+ pkt_pool_write_idx = 0;
- alq_close(siftr_alq);
- siftr_alq = NULL;
+ /* destroy ring */
+ if (siftr_br != NULL) {
+ buf_ring_free(siftr_br, M_SIFTR);
+ siftr_br = NULL;
+ }
+ if (mtx_initialized(&siftr_br_mtx) != 0) {
+ mtx_destroy(&siftr_br_mtx);
+ }
+ /* Close logfile vnode if opened */
+ if (siftr_vnode != NULL) {
+ vn_close(siftr_vnode, FWRITE, curthread->td_ucred, curthread);
+ siftr_vnode = NULL;
+ }
+ if (siftr_vnode_cred != NULL) {
+ crfree(siftr_vnode_cred);
+ siftr_vnode_cred = NULL;
+ }
} else
error = EINVAL;
@@ -1311,7 +1350,6 @@
EVENTHANDLER_DEREGISTER(shutdown_pre_sync, siftr_shutdown_tag);
siftr_manage_ops(SIFTR_DISABLE);
hashdestroy(counter_hash, M_SIFTR, siftr_hashmask);
- mtx_destroy(&siftr_pkt_queue_mtx);
mtx_destroy(&siftr_pkt_mgr_mtx);
return (0);
@@ -1330,7 +1368,6 @@
counter_hash = hashinit(SIFTR_EXPECTED_MAX_TCP_FLOWS, M_SIFTR,
&siftr_hashmask);
- mtx_init(&siftr_pkt_queue_mtx, "siftr_pkt_queue_mtx", NULL, MTX_DEF);
mtx_init(&siftr_pkt_mgr_mtx, "siftr_pkt_mgr_mtx", NULL, MTX_DEF);
/* Print message to the user's current terminal. */
@@ -1395,5 +1432,4 @@
* within the same subsystem as defined by param 3
*/
DECLARE_MODULE(siftr, siftr_mod, SI_SUB_LAST, SI_ORDER_ANY);
-MODULE_DEPEND(siftr, alq, 1, 1, 1);
MODULE_VERSION(siftr, MODVERSION);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 2, 7:42 AM (5 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40040153
Default Alt Text
D59907.diff (19 KB)
Attached To
Mode
D59907: siftr: replace alq(9) interface with native I/O code
Attached
Detach File
Event Timeline
Log In to Comment