Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Use bpf_ops for bpf_mtap_softint



details:   https://anonhg.NetBSD.org/src/rev/fab742036974
branches:  trunk
changeset: 350862:fab742036974
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Jan 25 01:04:23 2017 +0000

description:
Use bpf_ops for bpf_mtap_softint

By doing so we don't need to care whether a kernel enables bpfilter or not.

diffstat:

 sys/net/bpf.c      |  18 +++++++++++-------
 sys/net/bpf.h      |  22 ++++++++++++++++++----
 sys/net/bpf_stub.c |   7 +++++--
 3 files changed, 34 insertions(+), 13 deletions(-)

diffs (137 lines):

diff -r 78a8739059b1 -r fab742036974 sys/net/bpf.c
--- a/sys/net/bpf.c     Tue Jan 24 23:31:03 2017 +0000
+++ b/sys/net/bpf.c     Wed Jan 25 01:04:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.c,v 1.205 2017/01/24 09:05:28 ozaki-r Exp $        */
+/*     $NetBSD: bpf.c,v 1.206 2017/01/25 01:04:23 ozaki-r Exp $        */
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.205 2017/01/24 09:05:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.206 2017/01/25 01:04:23 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -1666,15 +1666,16 @@
        }
 }
 
-void
-bpf_mtap_softint(struct ifnet *ifp, struct mbuf *m)
+static void
+_bpf_mtap_softint(struct ifnet *ifp, struct mbuf *m)
 {
        struct bpf_if *bp = ifp->if_bpf;
        struct mbuf *dup;
 
        KASSERT(cpu_intr_p());
 
-       if (bp == NULL || bp->bif_dlist == NULL)
+       /* To avoid extra invocations of the softint */
+       if (bp->bif_dlist == NULL)
                return;
        KASSERT(bp->bif_si != NULL);
 
@@ -1893,8 +1894,8 @@
 #endif
 }
 
-void
-bpf_mtap_softint_init(struct ifnet *ifp)
+static void
+_bpf_mtap_softint_init(struct ifnet *ifp)
 {
        struct bpf_if *bp;
 
@@ -2227,6 +2228,9 @@
        .bpf_mtap_af =          _bpf_mtap_af,
        .bpf_mtap_sl_in =       _bpf_mtap_sl_in,
        .bpf_mtap_sl_out =      _bpf_mtap_sl_out,
+
+       .bpf_mtap_softint =             _bpf_mtap_softint,
+       .bpf_mtap_softint_init =        _bpf_mtap_softint_init,
 };
 
 MODULE(MODULE_CLASS_DRIVER, bpf, "bpf_filter");
diff -r 78a8739059b1 -r fab742036974 sys/net/bpf.h
--- a/sys/net/bpf.h     Tue Jan 24 23:31:03 2017 +0000
+++ b/sys/net/bpf.h     Wed Jan 25 01:04:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.h,v 1.68 2017/01/24 09:05:28 ozaki-r Exp $ */
+/*     $NetBSD: bpf.h,v 1.69 2017/01/25 01:04:23 ozaki-r Exp $ */
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -423,6 +423,9 @@
        void (*bpf_mtap_af)(struct bpf_if *, uint32_t, struct mbuf *);
        void (*bpf_mtap_sl_in)(struct bpf_if *, u_char *, struct mbuf **);
        void (*bpf_mtap_sl_out)(struct bpf_if *, u_char *, struct mbuf *);
+
+       void (*bpf_mtap_softint_init)(struct ifnet *);
+       void (*bpf_mtap_softint)(struct ifnet *, struct mbuf *);
 };
 
 extern struct bpf_ops *bpf_ops;
@@ -498,6 +501,20 @@
                bpf_ops->bpf_mtap_sl_out(_ifp->if_bpf, _hdr, _m);
 }
 
+static inline void
+bpf_mtap_softint_init(struct ifnet *_ifp)
+{
+
+       bpf_ops->bpf_mtap_softint_init(_ifp);
+}
+
+static inline void
+bpf_mtap_softint(struct ifnet *_ifp, struct mbuf *_m)
+{
+
+       if (_ifp->if_bpf)
+               bpf_ops->bpf_mtap_softint(_ifp, _m);
+}
 
 void   bpf_setops(void);
 
@@ -517,9 +534,6 @@
 bpfjit_func_t bpf_jit_generate(bpf_ctx_t *, void *, size_t);
 void   bpf_jit_freecode(bpfjit_func_t);
 
-void   bpf_mtap_softint_init(struct ifnet *);
-void   bpf_mtap_softint(struct ifnet *, struct mbuf *);
-
 #endif
 
 int    bpf_validate(const struct bpf_insn *, int);
diff -r 78a8739059b1 -r fab742036974 sys/net/bpf_stub.c
--- a/sys/net/bpf_stub.c        Tue Jan 24 23:31:03 2017 +0000
+++ b/sys/net/bpf_stub.c        Wed Jan 25 01:04:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf_stub.c,v 1.6 2012/01/30 23:31:27 matt Exp $        */
+/*     $NetBSD: bpf_stub.c,v 1.7 2017/01/25 01:04:23 ozaki-r Exp $     */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf_stub.c,v 1.6 2012/01/30 23:31:27 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf_stub.c,v 1.7 2017/01/25 01:04:23 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -67,6 +67,9 @@
        .bpf_mtap_af =          (void *)bpf_stub_warn,
        .bpf_mtap_sl_in =       (void *)bpf_stub_warn,
        .bpf_mtap_sl_out =      (void *)bpf_stub_warn,
+
+       .bpf_mtap_softint_init =        (void *)bpf_stub_null,
+       .bpf_mtap_softint =             (void *)bpf_stub_warn,
 };
 struct bpf_ops *bpf_ops;
 



Home | Main Index | Thread Index | Old Index