Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/npf/npftest Enable bpfjit for npftest.



details:   https://anonhg.NetBSD.org/src/rev/6e5e7a2768e5
branches:  trunk
changeset: 791396:6e5e7a2768e5
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sat Nov 16 01:41:43 2013 +0000

description:
Enable bpfjit for npftest.

diffstat:

 usr.sbin/npf/npftest/Makefile                  |   7 ++++---
 usr.sbin/npf/npftest/libnpftest/Makefile       |   2 +-
 usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c |  25 ++++++++++++++++++++-----
 3 files changed, 25 insertions(+), 9 deletions(-)

diffs (111 lines):

diff -r 89eb9e8213b2 -r 6e5e7a2768e5 usr.sbin/npf/npftest/Makefile
--- a/usr.sbin/npf/npftest/Makefile     Sat Nov 16 01:39:17 2013 +0000
+++ b/usr.sbin/npf/npftest/Makefile     Sat Nov 16 01:41:43 2013 +0000
@@ -12,12 +12,13 @@
 DPADD+=                ${LIBNPFTEST}/libnpftest.a
 LDADD+=                -L${LIBNPFTEST} -lnpftest
 
-LDADD+=                -lrump -lrumpvfs -lrumpnet -lrumpnet_net -lrumpnet_npf
-LDADD+=                -lrumpdev_bpf
+LDADD+=                -lrump -lrumpvfs -lrumpnet -lrumpnet_net
+LDADD+=                -lrumpdev_bpf -lrumpkern_sljit -lrumpnet_bpfjit
+LDADD+=                -lrumpnet_npf
 
 LDADD+=                -lpcap -lprop -lpthread
 
-WARNS=         4
+WARNS=         5
 NOMAN=         # no man page
 NOLINT=                # disabled (note: deliberately)
 
diff -r 89eb9e8213b2 -r 6e5e7a2768e5 usr.sbin/npf/npftest/libnpftest/Makefile
--- a/usr.sbin/npf/npftest/libnpftest/Makefile  Sat Nov 16 01:39:17 2013 +0000
+++ b/usr.sbin/npf/npftest/libnpftest/Makefile  Sat Nov 16 01:41:43 2013 +0000
@@ -24,7 +24,7 @@
 CPPFLAGS+=     -I${.CURDIR}/../../../../sys/net/npf
 CPPFLAGS+=     -I${RUMPTOP}/librump/rumpkern
 
-WARNS=         4
+WARNS=         5
 
 .include "${RUMPTOP}/Makefile.rump"
 .include <bsd.lib.mk>
diff -r 89eb9e8213b2 -r 6e5e7a2768e5 usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c
--- a/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c    Sat Nov 16 01:39:17 2013 +0000
+++ b/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c    Sat Nov 16 01:41:43 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_bpf_test.c,v 1.2 2013/11/08 00:38:27 rmind Exp $   */
+/*     $NetBSD: npf_bpf_test.c,v 1.3 2013/11/16 01:41:43 rmind Exp $   */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -40,6 +40,8 @@
 #include "npf_impl.h"
 #include "npf_test.h"
 
+static bool    lverbose = false;
+
 static struct mbuf *
 fill_packet(int proto)
 {
@@ -57,13 +59,14 @@
 }
 
 static int
-test_bpf_code(const void *code)
+test_bpf_code(void *code, size_t size)
 {
        ifnet_t *dummy_ifp = npf_test_addif(IFNAME_TEST, false, false);
        npf_cache_t npc = { .npc_info = 0 };
        struct mbuf *m;
        nbuf_t nbuf;
-       int ret;
+       int ret, jret;
+       void *jcode;
 
        /* Layer 3 (IP + TCP). */
        m = fill_packet(IPPROTO_TCP);
@@ -71,6 +74,16 @@
        npf_cache_all(&npc, &nbuf);
 
        ret = npf_bpf_filter(&npc, &nbuf, code, NULL);
+
+       /* JIT-compiled code. */
+       jcode = npf_bpf_compile(code, size);
+       if (jcode) {
+               jret = npf_bpf_filter(&npc, &nbuf, NULL, jcode);
+               assert(ret == jret);
+               bpf_jit_freecode(jcode);
+       } else if (lverbose) {
+               printf("JIT-compilation failed\n");
+       }
        m_freem(m);
 
        return ret;
@@ -84,7 +97,7 @@
                BPF_STMT(BPF_LD+BPF_W+BPF_MEM, reg),
                BPF_STMT(BPF_RET+BPF_A, 0),
        };
-       return test_bpf_code(&insns_npf_bpfcop);
+       return test_bpf_code(&insns_npf_bpfcop, sizeof(insns_npf_bpfcop));
 }
 
 static bool
@@ -97,7 +110,7 @@
                BPF_STMT(BPF_MISC+BPF_COP, NPF_COP_L3),
                BPF_STMT(BPF_RET+BPF_A, 0),
        };
-       fail |= (test_bpf_code(&insns_ipver) != IPVERSION);
+       fail |= (test_bpf_code(&insns_ipver, sizeof(insns_ipver)) != IPVERSION);
 
        /* BPF_MW_IPVERI <- IP version */
        fail |= (npf_bpfcop_run(BPF_MW_IPVER) != IPVERSION);
@@ -116,6 +129,8 @@
 {
        bool fail = false;
 
+       lverbose = verbose;
+
        fail |= npf_bpfcop_test();
 
        return !fail;



Home | Main Index | Thread Index | Old Index