Enable bpfjit for npftest.
This commit is contained in:
parent
6e88b59054
commit
467de1619d
@ -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
|
# Public Domain
|
||||||
#
|
#
|
||||||
@ -12,12 +12,13 @@ LIBNPFTEST!= cd ${.CURDIR}/libnpftest && ${MAKE} -V .OBJDIR
|
|||||||
DPADD+= ${LIBNPFTEST}/libnpftest.a
|
DPADD+= ${LIBNPFTEST}/libnpftest.a
|
||||||
LDADD+= -L${LIBNPFTEST} -lnpftest
|
LDADD+= -L${LIBNPFTEST} -lnpftest
|
||||||
|
|
||||||
LDADD+= -lrump -lrumpvfs -lrumpnet -lrumpnet_net -lrumpnet_npf
|
LDADD+= -lrump -lrumpvfs -lrumpnet -lrumpnet_net
|
||||||
LDADD+= -lrumpdev_bpf
|
LDADD+= -lrumpdev_bpf -lrumpkern_sljit -lrumpnet_bpfjit
|
||||||
|
LDADD+= -lrumpnet_npf
|
||||||
|
|
||||||
LDADD+= -lpcap -lprop -lpthread
|
LDADD+= -lpcap -lprop -lpthread
|
||||||
|
|
||||||
WARNS= 4
|
WARNS= 5
|
||||||
NOMAN= # no man page
|
NOMAN= # no man page
|
||||||
NOLINT= # disabled (note: deliberately)
|
NOLINT= # disabled (note: deliberately)
|
||||||
|
|
||||||
|
@ -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
|
# Public Domain
|
||||||
#
|
#
|
||||||
@ -24,7 +24,7 @@ CPPFLAGS+= -D_NPF_TESTING
|
|||||||
CPPFLAGS+= -I${.CURDIR}/../../../../sys/net/npf
|
CPPFLAGS+= -I${.CURDIR}/../../../../sys/net/npf
|
||||||
CPPFLAGS+= -I${RUMPTOP}/librump/rumpkern
|
CPPFLAGS+= -I${RUMPTOP}/librump/rumpkern
|
||||||
|
|
||||||
WARNS= 4
|
WARNS= 5
|
||||||
|
|
||||||
.include "${RUMPTOP}/Makefile.rump"
|
.include "${RUMPTOP}/Makefile.rump"
|
||||||
.include <bsd.lib.mk>
|
.include <bsd.lib.mk>
|
||||||
|
@ -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.
|
* Copyright (c) 2013 The NetBSD Foundation, Inc.
|
||||||
@ -40,6 +40,8 @@
|
|||||||
#include "npf_impl.h"
|
#include "npf_impl.h"
|
||||||
#include "npf_test.h"
|
#include "npf_test.h"
|
||||||
|
|
||||||
|
static bool lverbose = false;
|
||||||
|
|
||||||
static struct mbuf *
|
static struct mbuf *
|
||||||
fill_packet(int proto)
|
fill_packet(int proto)
|
||||||
{
|
{
|
||||||
@ -57,13 +59,14 @@ fill_packet(int proto)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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);
|
ifnet_t *dummy_ifp = npf_test_addif(IFNAME_TEST, false, false);
|
||||||
npf_cache_t npc = { .npc_info = 0 };
|
npf_cache_t npc = { .npc_info = 0 };
|
||||||
struct mbuf *m;
|
struct mbuf *m;
|
||||||
nbuf_t nbuf;
|
nbuf_t nbuf;
|
||||||
int ret;
|
int ret, jret;
|
||||||
|
void *jcode;
|
||||||
|
|
||||||
/* Layer 3 (IP + TCP). */
|
/* Layer 3 (IP + TCP). */
|
||||||
m = fill_packet(IPPROTO_TCP);
|
m = fill_packet(IPPROTO_TCP);
|
||||||
@ -71,6 +74,16 @@ test_bpf_code(const void *code)
|
|||||||
npf_cache_all(&npc, &nbuf);
|
npf_cache_all(&npc, &nbuf);
|
||||||
|
|
||||||
ret = npf_bpf_filter(&npc, &nbuf, code, NULL);
|
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);
|
m_freem(m);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -84,7 +97,7 @@ npf_bpfcop_run(u_int reg)
|
|||||||
BPF_STMT(BPF_LD+BPF_W+BPF_MEM, reg),
|
BPF_STMT(BPF_LD+BPF_W+BPF_MEM, reg),
|
||||||
BPF_STMT(BPF_RET+BPF_A, 0),
|
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
|
static bool
|
||||||
@ -97,7 +110,7 @@ npf_bpfcop_test(void)
|
|||||||
BPF_STMT(BPF_MISC+BPF_COP, NPF_COP_L3),
|
BPF_STMT(BPF_MISC+BPF_COP, NPF_COP_L3),
|
||||||
BPF_STMT(BPF_RET+BPF_A, 0),
|
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 */
|
/* BPF_MW_IPVERI <- IP version */
|
||||||
fail |= (npf_bpfcop_run(BPF_MW_IPVER) != IPVERSION);
|
fail |= (npf_bpfcop_run(BPF_MW_IPVER) != IPVERSION);
|
||||||
@ -116,6 +129,8 @@ npf_bpf_test(bool verbose)
|
|||||||
{
|
{
|
||||||
bool fail = false;
|
bool fail = false;
|
||||||
|
|
||||||
|
lverbose = verbose;
|
||||||
|
|
||||||
fail |= npf_bpfcop_test();
|
fail |= npf_bpfcop_test();
|
||||||
|
|
||||||
return !fail;
|
return !fail;
|
||||||
|
Loading…
Reference in New Issue
Block a user