svn commit: r255172 - in user/syuu/mq_bpf: contrib/libpcap contrib/libpcap/pcap contrib/tcpdump sbin/ifconfig sys/net

Takuya ASADA syuu at FreeBSD.org
Tue Sep 3 08:28:29 UTC 2013


Author: syuu
Date: Tue Sep  3 08:28:27 2013
New Revision: 255172
URL: http://svnweb.freebsd.org/changeset/base/255172

Log:
  bpf_qmask_bits_t(userland part)

Modified:
  user/syuu/mq_bpf/contrib/libpcap/pcap-bpf.c
  user/syuu/mq_bpf/contrib/libpcap/pcap-int.h
  user/syuu/mq_bpf/contrib/libpcap/pcap.c
  user/syuu/mq_bpf/contrib/libpcap/pcap/pcap.h
  user/syuu/mq_bpf/contrib/tcpdump/tcpdump.c
  user/syuu/mq_bpf/sbin/ifconfig/af_inet.c
  user/syuu/mq_bpf/sys/net/bpf.c
  user/syuu/mq_bpf/sys/net/bpf.h
  user/syuu/mq_bpf/sys/net/bpfdesc.h

Modified: user/syuu/mq_bpf/contrib/libpcap/pcap-bpf.c
==============================================================================
--- user/syuu/mq_bpf/contrib/libpcap/pcap-bpf.c	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/contrib/libpcap/pcap-bpf.c	Tue Sep  3 08:28:27 2013	(r255172)
@@ -2188,37 +2188,30 @@ pcap_activate_bpf(pcap_t *p)
 	}
 #endif
 
-	if (p->rxq_num != (uint32_t)-1 || p->txq_num != (uint32_t)-1 ||
-		p->other_mask != (uint32_t)-1) {
-		if (ioctl(fd, BIOCENAQMASK, NULL) < 0) {
-			snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCENAQMASK: %s",
+	if (p->qmask_enabled) {
+		if (ioctl(fd, BIOCQMASKENABLE, NULL) < 0) {
+			snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCQMASKENABLE: %s",
 			    pcap_strerror(errno));
 			status = PCAP_ERROR;
 			goto bad;
 		}
-		if (p->rxq_num != (uint32_t)-1) {
-			if (ioctl(fd, BIOCSTRXQMASK, &p->rxq_num) < 0) {
-				snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSTRXQMASK: %s",
-				    pcap_strerror(errno));
-				status = PCAP_ERROR;
-				goto bad;
-			}
+		if (ioctl(fd, BIOCSRXQMASK, &p->rxqmask) < 0) {
+			snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSRXQMASK: %s",
+			    pcap_strerror(errno));
+			status = PCAP_ERROR;
+			goto bad;
 		}
-		if (p->txq_num != (uint32_t)-1) {
-			if (ioctl(fd, BIOCSTTXQMASK, &p->txq_num) < 0) {
-				snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSTTXQMASK: %s",
-				    pcap_strerror(errno));
-				status = PCAP_ERROR;
-				goto bad;
-			}
+		if (ioctl(fd, BIOCSTXQMASK, &p->txqmask) < 0) {
+			snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSTXQMASK: %s",
+			    pcap_strerror(errno));
+			status = PCAP_ERROR;
+			goto bad;
 		}
-		if (p->other_mask != (uint32_t)-1) {
-			if (ioctl(fd, BIOCSTOTHERMASK, &p->other_mask) < 0) {
-				snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSTOTHERQMASK: %s",
-				    pcap_strerror(errno));
-				status = PCAP_ERROR;
-				goto bad;
-			}
+		if (ioctl(fd, BIOCSNOQMASK, &p->noqmask) < 0) {
+			snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSNOQMASK: %s",
+			    pcap_strerror(errno));
+			status = PCAP_ERROR;
+			goto bad;
 		}
 	}
 

Modified: user/syuu/mq_bpf/contrib/libpcap/pcap-int.h
==============================================================================
--- user/syuu/mq_bpf/contrib/libpcap/pcap-int.h	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/contrib/libpcap/pcap-int.h	Tue Sep  3 08:28:27 2013	(r255172)
@@ -338,8 +338,10 @@ struct pcap {
 
 	struct pcap_pkthdr pcap_header;	/* This is needed for the pcap_next_ex() to work */
 
-	uint32_t rxq_num, txq_num;
-	uint32_t other_mask;
+	int qmask_enabled;
+	struct bpf_qmask_bits rxqmask;
+	struct bpf_qmask_bits txqmask;
+	int noqmask;
 };
 
 /*

Modified: user/syuu/mq_bpf/contrib/libpcap/pcap.c
==============================================================================
--- user/syuu/mq_bpf/contrib/libpcap/pcap.c	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/contrib/libpcap/pcap.c	Tue Sep  3 08:28:27 2013	(r255172)
@@ -505,9 +505,7 @@ pcap_create_common(const char *source, c
 	p->opt.promisc = 0;
 	p->opt.buffer_size = 0;
 	p->opt.tstamp_type = -1;	/* default to not setting time stamp type */
- 	p->rxq_num = (uint32_t)-1;
- 	p->txq_num = (uint32_t)-1;
- 	p->other_mask = (uint32_t)-1;
+	p->qmask_enabled = 0;
 	return (p);
 }
 
@@ -641,29 +639,71 @@ pcap_activate(pcap_t *p)
 }
 
 int
-pcap_set_rxq_mask(pcap_t *p, uint32_t num)
+pcap_enable_qmask(pcap_t *p)
+{
+	p->qmask_enabled = 1;
+	BPFQ_ZERO(&p->rxqmask);
+	BPFQ_ZERO(&p->txqmask);
+	p->noqmask = 0;
+}
+
+int
+pcap_disable_qmask(pcap_t *p)
+{
+	p->qmask_enabled = 0;
+}
+
+int
+pcap_set_rxqmask(pcap_t *p, u_int queueid)
+{
+	if (pcap_check_activated(p))
+		return PCAP_ERROR_ACTIVATED;
+	BPFQ_SET(queueid, &p->rxqmask);
+	return 0;
+}
+
+int
+pcap_clear_rxqmask(pcap_t *p, u_int queueid)
+{
+	if (pcap_check_activated(p))
+		return PCAP_ERROR_ACTIVATED;
+	BPFQ_CLR(queueid, &p->rxqmask);
+	return 0;
+}
+
+int
+pcap_set_txqmask(pcap_t *p, u_int queueid)
+{
+	if (pcap_check_activated(p))
+		return PCAP_ERROR_ACTIVATED;
+	BPFQ_SET(queueid, &p->txqmask);
+	return 0;
+}
+
+int
+pcap_clear_txqmask(pcap_t *p, u_int queueid)
 {
 	if (pcap_check_activated(p))
 		return PCAP_ERROR_ACTIVATED;
-	p->rxq_num = num;
+	BPFQ_CLR(queueid, &p->txqmask);
 	return 0;
 }
 
 int
-pcap_set_txq_mask(pcap_t *p, uint32_t num)
+pcap_set_noqmask(pcap_t *p)
 {
 	if (pcap_check_activated(p))
 		return PCAP_ERROR_ACTIVATED;
-	p->txq_num = num;
+	p->noqmask = 1;
 	return 0;
 }
 
 int
-pcap_set_other_mask(pcap_t *p, uint32_t mask)
+pcap_clear_noqmask(pcap_t *p)
 {
 	if (pcap_check_activated(p))
 		return PCAP_ERROR_ACTIVATED;
-	p->other_mask = mask;
+	p->noqmask = 0;
 	return 0;
 }
 

Modified: user/syuu/mq_bpf/contrib/libpcap/pcap/pcap.h
==============================================================================
--- user/syuu/mq_bpf/contrib/libpcap/pcap/pcap.h	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/contrib/libpcap/pcap/pcap.h	Tue Sep  3 08:28:27 2013	(r255172)
@@ -331,9 +331,14 @@ const char *pcap_tstamp_type_val_to_desc
 #define PCAP_TSTAMP_ADAPTER		3	/* device-provided, synced with the system clock */
 #define PCAP_TSTAMP_ADAPTER_UNSYNCED	4	/* device-provided, not synced with the system clock */
 
-int	pcap_set_rxq_mask(pcap_t *, uint32_t);
-int	pcap_set_txq_mask(pcap_t *, uint32_t);
-int	pcap_set_other_mask(pcap_t *, uint32_t);
+int	pcap_enable_qmask(pcap_t *);
+int	pcap_disable_qmask(pcap_t *);
+int	pcap_set_rxqmask(pcap_t *, u_int);
+int	pcap_clear_rxqmask(pcap_t *, u_int);
+int	pcap_set_txqmask(pcap_t *, u_int);
+int	pcap_clear_txqmask(pcap_t *, u_int);
+int	pcap_set_noqmask(pcap_t *);
+int	pcap_clear_noqmask(pcap_t *);
 
 pcap_t	*pcap_open_live(const char *, int, int, int, char *);
 pcap_t	*pcap_open_dead(int, int);

Modified: user/syuu/mq_bpf/contrib/tcpdump/tcpdump.c
==============================================================================
--- user/syuu/mq_bpf/contrib/tcpdump/tcpdump.c	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/contrib/tcpdump/tcpdump.c	Tue Sep  3 08:28:27 2013	(r255172)
@@ -702,7 +702,10 @@ main(int argc, char **argv)
 #endif
 	int status;
 	FILE *VFile;
-	uint32_t rxq = (uint32_t)-1, txq = (uint32_t)-1, other = (uint32_t)-1;
+	int qmask = 0;
+	u_int rxq = (u_int)-1, txq = (u_int)-1;
+	int noq = -1;
+	
 #ifdef WIN32
 	if(wsockinit() != 0) return 1;
 #endif /* WIN32 */
@@ -817,6 +820,7 @@ main(int argc, char **argv)
 			break;
 
 		case 'g':
+			qmask = 1;
 			txq = atoi(optarg);
 			break;
 
@@ -925,8 +929,9 @@ main(int argc, char **argv)
 			break;
 
 		case 'k':
-			other = atoi(optarg);
-			if (other != 0 || other != 1)
+			qmask = 1;
+			noq = atoi(optarg);
+			if (noq != 0 || noq != 1)
 				usage();
 			break;
 
@@ -977,6 +982,7 @@ main(int argc, char **argv)
 			break;
 
 		case 'Q':
+			qmask = 1;
 			rxq = atoi(optarg);
 			break;
 
@@ -1289,12 +1295,14 @@ main(int argc, char **argv)
 			    	    device, pcap_statustostr(status));
 		}
 #endif
- 		if (rxq != (uint32_t)-1)
- 			pcap_set_rxq_mask(pd, rxq);
- 		if (txq != (uint32_t)-1)
- 			pcap_set_txq_mask(pd, txq);
- 		if (other != (uint32_t)-1)
- 			pcap_set_other_mask(pd, other);
+		if (qmask)
+			pcap_enable_qmask(pd);
+ 		if (rxq != (u_int)-1)
+ 			pcap_set_rxqmask(pd, rxq);
+ 		if (txq != (u_int)-1)
+ 			pcap_set_txqmask(pd, txq);
+ 		if (noq != -1)
+			noq ? pcap_set_noqmask(pd) : pcap_clear_noqmask(pd);
 
 		status = pcap_activate(pd);
 		if (status < 0) {

Modified: user/syuu/mq_bpf/sbin/ifconfig/af_inet.c
==============================================================================
--- user/syuu/mq_bpf/sbin/ifconfig/af_inet.c	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/sbin/ifconfig/af_inet.c	Tue Sep  3 08:28:27 2013	(r255172)
@@ -101,7 +101,9 @@ static struct sockaddr_in *sintab[] = {
 static void
 in_getaddr(const char *s, int which)
 {
+#ifndef MIN
 #define	MIN(a,b)	((a)<(b)?(a):(b))
+#endif
 	struct sockaddr_in *sin = sintab[which];
 	struct hostent *hp;
 	struct netent *np;

Modified: user/syuu/mq_bpf/sys/net/bpf.c
==============================================================================
--- user/syuu/mq_bpf/sys/net/bpf.c	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/sys/net/bpf.c	Tue Sep  3 08:28:27 2013	(r255172)
@@ -1754,7 +1754,7 @@ bpfioctl(struct cdev *dev, u_long cmd, c
 
 	case BIOCGRXQMASK:
 		{
-			bpf_qmask_bits_t *qmask = (bpf_qmask_bits_t *)addr;
+			struct bpf_qmask_bits *qmask = (struct bpf_qmask_bits *)addr;
 
 			if (d->bd_bif == NULL) {
 				/*
@@ -1777,7 +1777,7 @@ bpfioctl(struct cdev *dev, u_long cmd, c
 
 	case BIOCSRXQMASK:
 		{
-			bpf_qmask_bits_t *qmask = (bpf_qmask_bits_t *)addr;
+			struct bpf_qmask_bits *qmask = (struct bpf_qmask_bits *)addr;
 
 			if (d->bd_bif == NULL) {
 				/*
@@ -1799,7 +1799,7 @@ bpfioctl(struct cdev *dev, u_long cmd, c
 
 	case BIOCGTXQMASK:
 		{
-			bpf_qmask_bits_t *qmask = (bpf_qmask_bits_t *)addr;
+			struct bpf_qmask_bits *qmask = (struct bpf_qmask_bits *)addr;
 
 			if (d->bd_bif == NULL) {
 				/*
@@ -1821,7 +1821,7 @@ bpfioctl(struct cdev *dev, u_long cmd, c
 
 	case BIOCSTXQMASK:
 		{
-			bpf_qmask_bits_t *qmask = (bpf_qmask_bits_t *)addr;
+			struct bpf_qmask_bits *qmask = (struct bpf_qmask_bits *)addr;
 
 			if (d->bd_bif == NULL) {
 				/*

Modified: user/syuu/mq_bpf/sys/net/bpf.h
==============================================================================
--- user/syuu/mq_bpf/sys/net/bpf.h	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/sys/net/bpf.h	Tue Sep  3 08:28:27 2013	(r255172)
@@ -115,6 +115,36 @@ struct bpf_zbuf {
 	size_t	 bz_buflen;	/* Size of zero-copy buffers. */
 };
 
+#ifndef _KERNEL
+#include <sys/param.h>
+#include <sys/bitset.h>
+#include <sys/_bitset.h>
+
+#define BPFQ_BITS			256
+BITSET_DEFINE(bpf_qmask_bits, BPFQ_BITS);
+
+#define	BPFQ_CLR(n, p)			BIT_CLR(BPFQ_BITS, n, p)
+#define	BPFQ_COPY(f, t)			BIT_COPY(BPFQ_BITS, f, t)
+#define	BPFQ_ISSET(n, p)		BIT_ISSET(BPFQ_BITS, n, p)
+#define	BPFQ_SET(n, p)			BIT_SET(BPFQ_BITS, n, p)
+#define	BPFQ_ZERO(p) 			BIT_ZERO(BPFQ_BITS, p)
+#define	BPFQ_FILL(p) 			BIT_FILL(BPFQ_BITS, p)
+#define	BPFQ_SETOF(n, p)		BIT_SETOF(BPFQ_BITS, n, p)
+#define	BPFQ_EMPTY(p)			BIT_EMPTY(BPFQ_BITS, p)
+#define	BPFQ_ISFULLSET(p)		BIT_ISFULLSET(BPFQ_BITS, p)
+#define	BPFQ_SUBSET(p, c)		BIT_SUBSET(BPFQ_BITS, p, c)
+#define	BPFQ_OVERLAP(p, c)		BIT_OVERLAP(BPFQ_BITS, p, c)
+#define	BPFQ_CMP(p, c)			BIT_CMP(BPFQ_BITS, p, c)
+#define	BPFQ_OR(d, s)			BIT_OR(BPFQ_BITS, d, s)
+#define	BPFQ_AND(d, s)			BIT_AND(BPFQ_BITS, d, s)
+#define	BPFQ_NAND(d, s)			BIT_NAND(BPFQ_BITS, d, s)
+#define	BPFQ_CLR_ATOMIC(n, p)		BIT_CLR_ATOMIC(BPFQ_BITS, n, p)
+#define	BPFQ_SET_ATOMIC(n, p)		BIT_SET_ATOMIC(BPFQ_BITS, n, p)
+#define	BPFQ_OR_ATOMIC(d, s)		BIT_OR_ATOMIC(BPFQ_BITS, d, s)
+#define	BPFQ_COPY_STORE_REL(f, t)	BIT_COPY_STORE_REL(BPFQ_BITS, f, t)
+#define	BPFQ_FFS(p)			BIT_FFS(BPFQ_BITS, p)
+#endif
+
 #define	BIOCGBLEN	_IOR('B', 102, u_int)
 #define	BIOCSBLEN	_IOWR('B', 102, u_int)
 #define	BIOCSETF	_IOW('B', 103, struct bpf_program)
@@ -149,12 +179,12 @@ struct bpf_zbuf {
 #define	BIOCSTSTAMP	_IOW('B', 132, u_int)
 #define	BIOCQMASKENABLE	_IO('B', 133)
 #define	BIOCQMASKDISABLE _IO('B', 134)
-#define	BIOCGRXQMASK	_IOR('B', 135, bpf_qmask_bits_t)
-#define	BIOCSRXQMASK	_IOW('B', 135, bpf_qmask_bits_t)
-#define	BIOCGTXQMASK	_IOR('B', 136, bpf_qmask_bits_t)
-#define	BIOCSTXQMASK	_IOW('B', 137, bpf_qmask_bits_t)
-#define	BIOCGNOQMASK	_IOR('B', 138, boolean_t)
-#define	BIOCSNOQMASK	_IOW('B', 139, boolean_t)
+#define	BIOCGRXQMASK	_IOR('B', 135, struct bpf_qmask_bits)
+#define	BIOCSRXQMASK	_IOW('B', 135, struct bpf_qmask_bits)
+#define	BIOCGTXQMASK	_IOR('B', 136, struct bpf_qmask_bits)
+#define	BIOCSTXQMASK	_IOW('B', 137, struct bpf_qmask_bits)
+#define	BIOCGNOQMASK	_IOR('B', 138, int)
+#define	BIOCSNOQMASK	_IOW('B', 139, int)
 
 /* Obsolete */
 #define	BIOCGSEESENT	BIOCGDIRECTION

Modified: user/syuu/mq_bpf/sys/net/bpfdesc.h
==============================================================================
--- user/syuu/mq_bpf/sys/net/bpfdesc.h	Tue Sep  3 08:19:06 2013	(r255171)
+++ user/syuu/mq_bpf/sys/net/bpfdesc.h	Tue Sep  3 08:28:27 2013	(r255172)
@@ -43,16 +43,18 @@
 #include <sys/selinfo.h>
 #include <sys/queue.h>
 #include <sys/conf.h>
-#include <sys/cpuset.h>
+#include <sys/bitset.h>
+#include <sys/_bitset.h>
 #include <net/if.h>
 
-typedef cpuset_t bpf_qmask_bits_t;
+#define BPFQ_BITS			256
+BITSET_DEFINE(bpf_qmask_bits, BPFQ_BITS);
 
 struct bpf_qmask {
-	boolean_t	qm_enabled;
-	bpf_qmask_bits_t qm_rxqmask;
-	bpf_qmask_bits_t qm_txqmask;
-	boolean_t	qm_noqmask;
+	int		qm_enabled;
+	struct bpf_qmask_bits qm_rxqmask;
+	struct bpf_qmask_bits qm_txqmask;
+	int		qm_noqmask;
 	struct rwlock	qm_lock;
 };
 
@@ -62,9 +64,27 @@ struct bpf_qmask {
 #define BPFQ_RUNLOCK(qm)	rw_runlock(&(qm)->qm_lock)
 #define BPFQ_WLOCK(qm)		rw_wlock(&(qm)->qm_lock)
 #define BPFQ_WUNLOCK(qm)	rw_wunlock(&(qm)->qm_lock)
-#define BPFQ_ZERO		CPU_ZERO
-#define BPFQ_COPY		CPU_COPY
-#define BPFQ_ISSET		CPU_ISSET
+
+#define	BPFQ_CLR(n, p)			BIT_CLR(BPFQ_BITS, n, p)
+#define	BPFQ_COPY(f, t)			BIT_COPY(BPFQ_BITS, f, t)
+#define	BPFQ_ISSET(n, p)		BIT_ISSET(BPFQ_BITS, n, p)
+#define	BPFQ_SET(n, p)			BIT_SET(BPFQ_BITS, n, p)
+#define	BPFQ_ZERO(p) 			BIT_ZERO(BPFQ_BITS, p)
+#define	BPFQ_FILL(p) 			BIT_FILL(BPFQ_BITS, p)
+#define	BPFQ_SETOF(n, p)		BIT_SETOF(BPFQ_BITS, n, p)
+#define	BPFQ_EMPTY(p)			BIT_EMPTY(BPFQ_BITS, p)
+#define	BPFQ_ISFULLSET(p)		BIT_ISFULLSET(BPFQ_BITS, p)
+#define	BPFQ_SUBSET(p, c)		BIT_SUBSET(BPFQ_BITS, p, c)
+#define	BPFQ_OVERLAP(p, c)		BIT_OVERLAP(BPFQ_BITS, p, c)
+#define	BPFQ_CMP(p, c)			BIT_CMP(BPFQ_BITS, p, c)
+#define	BPFQ_OR(d, s)			BIT_OR(BPFQ_BITS, d, s)
+#define	BPFQ_AND(d, s)			BIT_AND(BPFQ_BITS, d, s)
+#define	BPFQ_NAND(d, s)			BIT_NAND(BPFQ_BITS, d, s)
+#define	BPFQ_CLR_ATOMIC(n, p)		BIT_CLR_ATOMIC(BPFQ_BITS, n, p)
+#define	BPFQ_SET_ATOMIC(n, p)		BIT_SET_ATOMIC(BPFQ_BITS, n, p)
+#define	BPFQ_OR_ATOMIC(d, s)		BIT_OR_ATOMIC(BPFQ_BITS, d, s)
+#define	BPFQ_COPY_STORE_REL(f, t)	BIT_COPY_STORE_REL(BPFQ_BITS, f, t)
+#define	BPFQ_FFS(p)			BIT_FFS(BPFQ_BITS, p)
 
 /*
  * Descriptor associated with each open bpf file.


More information about the svn-src-user mailing list