Hi!

Yesterday I got sick and tired of guessing what the enormous traffic in our
default queue was, and filled an item from my wishlist since OpenBSD 4.7.

It works like this:

# tcpdump -Q queuename -ni em0
tcpdump: listening on vic0, queue a, link-type EN10MB
... usual output ...

This mail contains changes required to the kernel, subsequent ones have the 
(most complicated) tcpdump(8) bit and (untested) pcap(3) bit.

Any thoughts?  I find it extremely useful and very small change.  Will test it
on a system with thousands of queues, but don't expect anything bad with it.
--
Martin Pelikan


Index: altq/altq_hfsc.c
===================================================================
RCS file: /cvs/src/sys/altq/altq_hfsc.c,v
retrieving revision 1.29
diff -u -p -r1.29 altq_hfsc.c
--- altq/altq_hfsc.c    18 Sep 2011 20:34:29 -0000      1.29
+++ altq/altq_hfsc.c    19 Mar 2013 14:54:43 -0000
@@ -592,6 +592,7 @@ altq_hfsc_enqueue(struct ifaltq *ifq, st
                        m_freem(m);
                        return (ENOBUFS);
                }
+               m->m_pkthdr.pf.qid = cl->cl_handle;
                cl->cl_pktattr = NULL;
        }
 
Index: net/bpf.c
===================================================================
RCS file: /cvs/src/sys/net/bpf.c,v
retrieving revision 1.83
diff -u -p -r1.83 bpf.c
--- net/bpf.c   28 Dec 2012 17:52:06 -0000      1.83
+++ net/bpf.c   19 Mar 2013 14:54:47 -0000
@@ -849,6 +849,14 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t 
                    (BPF_DIRECTION_IN|BPF_DIRECTION_OUT);
                break;
 
+       case BIOCGQUEUE:        /* get queue */
+               *(u_int *)addr = d->bd_queue;
+               break;
+
+       case BIOCSQUEUE:        /* set queue */
+               d->bd_queue = *(u_int *)addr;
+               break;
+
        case FIONBIO:           /* Non-blocking I/O */
                if (*(int *)addr)
                        d->bd_rtout = -1;
@@ -1198,6 +1206,8 @@ bpf_mtap(caddr_t arg, struct mbuf *m, u_
        for (d = bp->bif_dlist; d != 0; d = d->bd_next) {
                ++d->bd_rcount;
                if ((direction & d->bd_dirfilt) != 0)
+                       slen = 0;
+               else if (d->bd_queue && m->m_pkthdr.pf.qid != d->bd_queue)
                        slen = 0;
                else
                        slen = bpf_filter(d->bd_rfilter, (u_char *)m,
Index: net/bpf.h
===================================================================
RCS file: /cvs/src/sys/net/bpf.h,v
retrieving revision 1.43
diff -u -p -r1.43 bpf.h
--- net/bpf.h   26 Mar 2012 19:37:42 -0000      1.43
+++ net/bpf.h   19 Mar 2013 14:54:48 -0000
@@ -119,6 +119,8 @@ struct bpf_version {
 #define BIOCGDLTLIST   _IOWR('B',123, struct bpf_dltlist)
 #define BIOCGDIRFILT   _IOR('B',124, u_int)
 #define BIOCSDIRFILT   _IOW('B',125, u_int)
+#define BIOCGQUEUE     _IOR('B',126, u_int32_t)
+#define BIOCSQUEUE     _IOW('B',127, u_int32_t)
 
 /*
  * Direction filters for BIOCSDIRFILT/BIOCGDIRFILT
Index: net/bpfdesc.h
===================================================================
RCS file: /cvs/src/sys/net/bpfdesc.h,v
retrieving revision 1.17
diff -u -p -r1.17 bpfdesc.h
--- net/bpfdesc.h       25 Mar 2006 22:41:47 -0000      1.17
+++ net/bpfdesc.h       19 Mar 2013 14:54:48 -0000
@@ -78,6 +78,7 @@ struct bpf_d {
        u_char          bd_locked;      /* true if descriptor is locked */
        u_char          bd_fildrop;     /* true if filtered packets will be 
dropped */
        u_char          bd_dirfilt;     /* direction filter */
+       u_int           bd_queue;       /* the queue the user wants to watch (0 
== all) */
        int             bd_hdrcmplt;    /* false to fill in src lladdr 
automatically */
        int             bd_async;       /* non-zero if packet reception should 
generate signal */
        int             bd_sig;         /* signal to send upon packet reception 
*/

Reply via email to