Enable bpfjit for npftest.

This commit is contained in:
rmind 2013-11-16 01:41:43 +00:00
parent 6e88b59054
commit 467de1619d
3 changed files with 27 additions and 11 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.4 2013/02/09 03:35:33 rmind Exp $
# $NetBSD: Makefile,v 1.5 2013/11/16 01:41:43 rmind Exp $
#
# Public Domain
#
@ -12,12 +12,13 @@ LIBNPFTEST!= cd ${.CURDIR}/libnpftest && ${MAKE} -V .OBJDIR
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)

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.7 2013/09/24 02:04:21 rmind Exp $
# $NetBSD: Makefile,v 1.8 2013/11/16 01:41:43 rmind Exp $
#
# Public Domain
#
@ -24,7 +24,7 @@ CPPFLAGS+= -D_NPF_TESTING
CPPFLAGS+= -I${.CURDIR}/../../../../sys/net/npf
CPPFLAGS+= -I${RUMPTOP}/librump/rumpkern
WARNS= 4
WARNS= 5
.include "${RUMPTOP}/Makefile.rump"
.include <bsd.lib.mk>

View File

@ -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 @@ fill_packet(int proto)
}
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 @@ test_bpf_code(const void *code)
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 @@ npf_bpfcop_run(u_int reg)
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 @@ npf_bpfcop_test(void)
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 @@ npf_bpf_test(bool verbose)
{
bool fail = false;
lverbose = verbose;
fail |= npf_bpfcop_test();
return !fail;