Date: Mon, 4 Feb 2019 22:38:34 +0000 (UTC) From: Brooks Davis <brooks@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r343756 - stable/12/sys/netinet Message-ID: <201902042238.x14McYi3026775@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: brooks Date: Mon Feb 4 22:38:34 2019 New Revision: 343756 URL: https://svnweb.freebsd.org/changeset/base/343756 Log: MFC r343587: Add a simple port filter to SIFTR. SIFTR does not allow any kind of filtering, but captures every packet processed by the TCP stack. Often, only a specific session or service is of interest, and doing the filtering in post-processing of the log adds to the overhead of SIFTR. This adds a new sysctl net.inet.siftr.port_filter. When set to zero, all packets get captured as previously. If set to any other value, only packets where either the source or the destination ports match, are captured in the log file. Submitted by: Richard Scheffenegger Reviewed by: Cheng Cui Differential Revision: https://reviews.freebsd.org/D18897 Modified: stable/12/sys/netinet/siftr.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/netinet/siftr.c ============================================================================== --- stable/12/sys/netinet/siftr.c Mon Feb 4 21:28:25 2019 (r343755) +++ stable/12/sys/netinet/siftr.c Mon Feb 4 22:38:34 2019 (r343756) @@ -272,6 +272,7 @@ static volatile unsigned int siftr_exit_pkt_manager_th static unsigned int siftr_enabled = 0; static unsigned int siftr_pkts_per_log = 1; static unsigned int siftr_generate_hashes = 0; +static uint16_t siftr_port_filter = 0; /* static unsigned int siftr_binary_log = 0; */ static char siftr_logfile[PATH_MAX] = "/var/log/siftr.log"; static char siftr_logfile_shadow[PATH_MAX] = "/var/log/siftr.log"; @@ -317,6 +318,10 @@ SYSCTL_UINT(_net_inet_siftr, OID_AUTO, genhashes, CTLF &siftr_generate_hashes, 0, "enable packet hash generation"); +SYSCTL_U16(_net_inet_siftr, OID_AUTO, port_filter, CTLFLAG_RW, + &siftr_port_filter, 0, + "enable packet filter on a TCP port"); + /* XXX: TODO SYSCTL_UINT(_net_inet_siftr, OID_AUTO, binary, CTLFLAG_RW, &siftr_binary_log, 0, @@ -907,6 +912,16 @@ siftr_chkpkt(void *arg, struct mbuf **m, struct ifnet goto inp_unlock; } + /* + * Only pkts selected by the tcp port filter + * can be inserted into the pkt_queue + */ + if ((siftr_port_filter != 0) && + (siftr_port_filter != ntohs(inp->inp_lport)) && + (siftr_port_filter != ntohs(inp->inp_fport))) { + goto inp_unlock; + } + pn = malloc(sizeof(struct pkt_node), M_SIFTR_PKTNODE, M_NOWAIT|M_ZERO); if (pn == NULL) { @@ -1080,6 +1095,16 @@ siftr_chkpkt6(void *arg, struct mbuf **m, struct ifnet else ss->nskip_out_tcpcb++; + goto inp_unlock6; + } + + /* + * Only pkts selected by the tcp port filter + * can be inserted into the pkt_queue + */ + if ((siftr_port_filter != 0) && + (siftr_port_filter != ntohs(inp->inp_lport)) && + (siftr_port_filter != ntohs(inp->inp_fport))) { goto inp_unlock6; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201902042238.x14McYi3026775>