CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Sat Apr 14 21:57:29 UTC 2012 Added Files: src/usr.sbin/npf/npftest: Makefile npftest.c npftest.h src/usr.sbin/npf/npftest/libnpftest: Makefile npf_mbuf_subr.c npf_nbuf_test.c npf_processor_test.c npf_table_test.c npf_test.h Log Message: Add initial NPF regression tests integrated with RUMP framework (running the kernel part of NPF in userland). Other tests will be added once converted to RUMP framework. All tests are in the public domain. Some Makefile fixes from christos@. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/usr.sbin/npf/npftest/Makefile \ src/usr.sbin/npf/npftest/npftest.c src/usr.sbin/npf/npftest/npftest.h cvs rdiff -u -r0 -r1.1 src/usr.sbin/npf/npftest/libnpftest/Makefile \ src/usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c \ src/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c \ src/usr.sbin/npf/npftest/libnpftest/npf_processor_test.c \ src/usr.sbin/npf/npftest/libnpftest/npf_table_test.c \ src/usr.sbin/npf/npftest/libnpftest/npf_test.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Added files: Index: src/usr.sbin/npf/npftest/Makefile diff -u /dev/null src/usr.sbin/npf/npftest/Makefile:1.1 --- /dev/null Sat Apr 14 21:57:30 2012 +++ src/usr.sbin/npf/npftest/Makefile Sat Apr 14 21:57:29 2012 @@ -0,0 +1,27 @@ +# $NetBSD: Makefile,v 1.1 2012/04/14 21:57:29 rmind Exp $ +# +# Public Domain +# + +PROG= npftest + +SRCS= npftest.c +CPPFLAGS+= -I${.CURDIR} + +LIBNPFTEST!= cd ${.CURDIR}/libnpftest && ${MAKE} -V .OBJDIR +DPADD+= ${LIBNPFTEST}/libnpftest.a +LDADD+= -L${LIBNPFTEST} -lnpftest + +LDADD+= -lrump -lrumpvfs -lrumpnet -lrump -lrumpnet_net +LDADD+= -lrumpnet_virtif -lrumpdev_npf -lpthread + +WARNS= 4 +NOMAN= # no man page +NOLINT= # disabled (note: deliberately) + +SUBDIR+= libnpftest + +${LIBNPFTEST}/libnpftest.a: all-libnpftest + +.include +.include Index: src/usr.sbin/npf/npftest/npftest.c diff -u /dev/null src/usr.sbin/npf/npftest/npftest.c:1.1 --- /dev/null Sat Apr 14 21:57:30 2012 +++ src/usr.sbin/npf/npftest/npftest.c Sat Apr 14 21:57:29 2012 @@ -0,0 +1,87 @@ +/* $NetBSD: npftest.c,v 1.1 2012/04/14 21:57:29 rmind Exp $ */ + +/* + * NPF testing framework. + * + * Public Domain. + */ + +#include +#include +#include +#include +#include + +#include + +#include "npftest.h" + +static bool benchmark, verbose, quiet; + +static void +usage(void) +{ + printf("%s: [ -b ] [ -v ]\n", getprogname()); + exit(EXIT_SUCCESS); +} + +static void +result(const char *test, bool ok) +{ + if (!quiet) { + printf("NPF %-10s\t%s\n", test, ok ? "OK" : "fail"); + } + if (verbose) { + puts("-"); + } + if (!ok) { + exit(EXIT_FAILURE); + } +} + +int +main(int argc, char **argv) +{ + bool ok; + int ch; + + benchmark = false; + verbose = false; + quiet = false; + + while ((ch = getopt(argc, argv, "bqv")) != -1) { + switch (ch) { + case 'b': + benchmark = true; + break; + case 'q': + quiet = true; + break; + case 'v': + verbose = true; + break; + default: + usage(); + } + } + + /* XXX rn_init */ + extern int rumpns_max_keylen; + rumpns_max_keylen = 1; + + rump_init(); + rump_schedule(); + + ok = rumpns_npf_nbuf_test(verbose); + result("nbuf", ok); + + ok = rumpns_npf_processor_test(verbose); + result("processor", ok); + + ok = rumpns_npf_table_test(verbose); + result("table", ok); + + rump_unschedule(); + + return EXIT_SUCCESS; +} Index: src/usr.sbin/npf/npftest/npftest.h diff -u /dev/null src/usr.sbin/npf/npftest/npftest.h:1.1 --- /dev/null Sat Apr 14 21:57:30 2012 +++ src/usr.sbin/npf/npftest/npftest.h Sat Apr 14 21:57:29 2012 @@ -0,0 +1,16 @@ +/* $NetBSD: npftest.h,v 1.1 2012/04/14 21:57:29 rmind Exp $ */ + +/* + * Public Domain. + */ + +#ifndef _NPF_TEST_H_ +#define _NPF_TEST_H_ + +#include + +bool rumpns_npf_nbuf_test(bool); +bool rumpns_npf_processor_test(bool); +bool rumpns_npf_table_test(bool); + +#endif Index: src/usr.sbin/npf/npftest/libnpftest/Makefile diff -u /dev/null src/usr.sbin/npf/npftest/libnpftest/Makefile:1.1 --- /dev/null Sat Apr 14 21:57:30 2012 +++ src/usr.sbin/npf/npftest/libnpftest/Makefile Sat Apr 14 21:57:29 2012 @@ -0,0 +1,24 @@ +# $NetBSD: Makefile,v 1.1 2012/04/14 21:57:29 rmind Exp $ +# +# Public Domain +# + +RUMPTOP= ${.CURDIR}/../../../../sys/rump + +LIB= npftest +LIBISPRIVATE= yes + +SRCS+= npf_mbuf_subr.c + +SRCS+= npf_nbuf_test.c +SRCS+= npf_processor_test.c +SRCS+= npf_table_test.c + +CPPFLAGS+= -I${.CURDIR}/../../../../sys/net/npf +CPPFLAGS+= -I${RUMPTOP}/librump/rumpkern + +WARNS= 4 + +.include "${RUMPTOP}/Makefile.rump" +.include +.include Index: src/usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c diff -u /dev/null src/usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c:1.1 --- /dev/null Sat Apr 14 21:57:30 2012 +++ src/usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c Sat Apr 14 21:57:29 2012 @@ -0,0 +1,110 @@ +/* $NetBSD: npf_mbuf_sub
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Mon Jun 4 00:28:34 UTC 2012 Modified Files: src/usr.sbin/npf/npftest: npftest.c npftest.h src/usr.sbin/npf/npftest/libnpftest: Makefile npf_test.h Added Files: src/usr.sbin/npf/npftest/libnpftest: npf_state_test.c Log Message: npftest: add a module for TCP state tracking and add few test cases. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/npf/npftest/npftest.c \ src/usr.sbin/npf/npftest/npftest.h cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/npf/npftest/libnpftest/Makefile \ src/usr.sbin/npf/npftest/libnpftest/npf_test.h cvs rdiff -u -r0 -r1.1 src/usr.sbin/npf/npftest/libnpftest/npf_state_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.2 src/usr.sbin/npf/npftest/npftest.c:1.3 --- src/usr.sbin/npf/npftest/npftest.c:1.2 Wed May 30 21:38:04 2012 +++ src/usr.sbin/npf/npftest/npftest.c Mon Jun 4 00:28:34 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.2 2012/05/30 21:38:04 rmind Exp $ */ +/* $NetBSD: npftest.c,v 1.3 2012/06/04 00:28:34 rmind Exp $ */ /* * NPF testing framework. @@ -179,6 +179,9 @@ main(int argc, char **argv) ok = rumpns_npf_table_test(verbose); result("table", ok); + + ok = rumpns_npf_state_test(verbose); + result("state", ok); } if (stream) { Index: src/usr.sbin/npf/npftest/npftest.h diff -u src/usr.sbin/npf/npftest/npftest.h:1.2 src/usr.sbin/npf/npftest/npftest.h:1.3 --- src/usr.sbin/npf/npftest/npftest.h:1.2 Wed May 30 21:38:04 2012 +++ src/usr.sbin/npf/npftest/npftest.h Mon Jun 4 00:28:34 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.h,v 1.2 2012/05/30 21:38:04 rmind Exp $ */ +/* $NetBSD: npftest.h,v 1.3 2012/06/04 00:28:34 rmind Exp $ */ /* * Public Domain. @@ -17,6 +17,7 @@ int rumpns_npf_test_handlepkt(const voi bool rumpns_npf_nbuf_test(bool); bool rumpns_npf_processor_test(bool); bool rumpns_npf_table_test(bool); +bool rumpns_npf_state_test(bool); int process_stream(const char *, const char *, unsigned); Index: src/usr.sbin/npf/npftest/libnpftest/Makefile diff -u src/usr.sbin/npf/npftest/libnpftest/Makefile:1.2 src/usr.sbin/npf/npftest/libnpftest/Makefile:1.3 --- src/usr.sbin/npf/npftest/libnpftest/Makefile:1.2 Wed May 30 21:38:04 2012 +++ src/usr.sbin/npf/npftest/libnpftest/Makefile Mon Jun 4 00:28:34 2012 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.2 2012/05/30 21:38:04 rmind Exp $ +# $NetBSD: Makefile,v 1.3 2012/06/04 00:28:34 rmind Exp $ # # Public Domain # @@ -14,6 +14,7 @@ SRCS+= npf_mbuf_subr.c SRCS+= npf_nbuf_test.c SRCS+= npf_processor_test.c SRCS+= npf_table_test.c +SRCS+= npf_state_test.c CPPFLAGS+= -D_NPF_TESTING CPPFLAGS+= -I${.CURDIR}/../../../../sys/net/npf Index: src/usr.sbin/npf/npftest/libnpftest/npf_test.h diff -u src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.2 src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.3 --- src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.2 Wed May 30 21:38:04 2012 +++ src/usr.sbin/npf/npftest/libnpftest/npf_test.h Mon Jun 4 00:28:34 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_test.h,v 1.2 2012/05/30 21:38:04 rmind Exp $ */ +/* $NetBSD: npf_test.h,v 1.3 2012/06/04 00:28:34 rmind Exp $ */ /* * Public Domain. @@ -37,5 +37,6 @@ void mbuf_icmp_append(struct mbuf *, st bool npf_nbuf_test(bool); bool npf_processor_test(bool); bool npf_table_test(bool); +bool npf_state_test(bool); #endif Added files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_state_test.c diff -u /dev/null src/usr.sbin/npf/npftest/libnpftest/npf_state_test.c:1.1 --- /dev/null Mon Jun 4 00:28:34 2012 +++ src/usr.sbin/npf/npftest/libnpftest/npf_state_test.c Mon Jun 4 00:28:34 2012 @@ -0,0 +1,165 @@ +/* $NetBSD: npf_state_test.c,v 1.1 2012/06/04 00:28:34 rmind Exp $ */ + +/* + * NPF state tracking test. + * + * Public Domain. + */ + +#include +#include + +#include "npf_impl.h" +#include "npf_test.h" + +typedef struct { + int tcpfl; /* TCP flags. */ + int tlen; /* TCP data length. */ + uint32_t seq; /* SEQ number. */ + uint32_t ack; /* ACK number. */ + uint32_t win; /* TCP Window. */ + int flags; /* Direction et al. */ +} tcp_meta_t; + +#define S TH_SYN +#define A TH_ACK +#define F TH_FIN +#define OUT 0x1 +#define IN 0x2 +#define ERR 0x4 +#define CLEAR .flags = 0 + +static const tcp_meta_t packet_sequence[] = { + /* + * TCP data SEQ ACK WIN + */ + + /* Out of order ACK. */ + { S, 0, , 0, 4096, OUT }, + { S|A, 0, 9, 1, 2048, IN }, + { A, 0, 1, 10, 4096, OUT }, + /* --- */ + { A, 0, 10, 1, 2048, IN }, + { A, 1000, 1, 10, 4096, OUT }, + { A, 1000, 11000, 10, 4096, OUT }, + { A, 0, 10, 12000, 2048, IN }, + { A, 0, 10, 13000, 2048, IN }, + { A, 1000, 12000, 10, 4096, OUT }, + { A, 0, 10, 11000, 1048, IN }, + /* --- */ + { A, 1000, 14000, 10, 4096, OUT }, + { A, 0, 10, 13000, 2
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Tue Aug 21 20:52:11 UTC 2012 Modified Files: src/usr.sbin/npf/npftest: npftest.c src/usr.sbin/npf/npftest/libnpftest: npf_nbuf_test.c npf_processor_test.c npf_rule_test.c npf_state_test.c npf_table_test.c Log Message: npftest: - Do not stop running other tests, if some tests fail. - Fix some endianness bugs in the test cases. Tested on sparc64 by martin@, all tests pass. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/npf/npftest/npftest.c cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c \ src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c cvs rdiff -u -r1.2 -r1.3 \ src/usr.sbin/npf/npftest/libnpftest/npf_processor_test.c \ src/usr.sbin/npf/npftest/libnpftest/npf_state_test.c cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/npf/npftest/libnpftest/npf_table_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.5 src/usr.sbin/npf/npftest/npftest.c:1.6 --- src/usr.sbin/npf/npftest/npftest.c:1.5 Wed Aug 15 19:47:38 2012 +++ src/usr.sbin/npf/npftest/npftest.c Tue Aug 21 20:52:11 2012 @@ -42,7 +42,7 @@ usage(void) exit(EXIT_FAILURE); } -static void +static bool result(const char *testcase, bool ok) { if (!quiet) { @@ -51,9 +51,7 @@ result(const char *testcase, bool ok) if (verbose) { puts("-"); } - if (!ok) { - exit(EXIT_FAILURE); - } + return !ok; } static void @@ -121,7 +119,7 @@ arc4random(void) int main(int argc, char **argv) { - bool benchmark, test, ok; + bool benchmark, test, ok, fail; char *config, *interface, *stream; int idx = -1, ch; @@ -188,27 +186,28 @@ main(int argc, char **argv) } srandom(1); + fail = false; if (test) { ok = rumpns_npf_nbuf_test(verbose); - result("nbuf", ok); + fail |= result("nbuf", ok); ok = rumpns_npf_processor_test(verbose); - result("processor", ok); + fail |= result("processor", ok); ok = rumpns_npf_table_test(verbose); - result("table", ok); + fail |= result("table", ok); ok = rumpns_npf_state_test(verbose); - result("state", ok); + fail |= result("state", ok); } if (test && config) { ok = rumpns_npf_rule_test(verbose); - result("rule", ok); + fail |= result("rule", ok); ok = rumpns_npf_nat_test(verbose); - result("nat", ok); + fail |= result("nat", ok); } if (stream) { @@ -217,5 +216,5 @@ main(int argc, char **argv) rump_unschedule(); - return EXIT_SUCCESS; + return fail ? EXIT_FAILURE : EXIT_SUCCESS; } Index: src/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c:1.1 src/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c:1.2 --- src/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c:1.1 Sat Apr 14 21:57:29 2012 +++ src/usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c Tue Aug 21 20:52:11 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_nbuf_test.c,v 1.1 2012/04/14 21:57:29 rmind Exp $ */ +/* $NetBSD: npf_nbuf_test.c,v 1.2 2012/08/21 20:52:11 rmind Exp $ */ /* * NPF nbuf interface test. @@ -157,20 +157,17 @@ npf_nbuf_test(bool verbose) { struct mbuf *m1, *m2; char *bufa, *bufb; + bool fail = false; m1 = mbuf_random_len(MBUF_CHAIN_LEN); bufa = mbuf_getstring(m1); bufb = parse_nbuf_chain(m1, m1->m_data); - if (!validate_mbuf_data(m1, verbose, bufa, bufb)) { - return false; - } + fail |= !validate_mbuf_data(m1, verbose, bufa, bufb); m2 = mbuf_bytesize(MBUF_CHAIN_LEN); bufa = mbuf_getstring(m2); bufb = parse_nbuf_chain(m2, m2->m_data); - if (!validate_mbuf_data(m2, verbose, bufa, bufb)) { - return false; - } + fail |= !validate_mbuf_data(m2, verbose, bufa, bufb); - return true; + return !fail; } Index: src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.1 src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.2 --- src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.1 Sun Aug 12 03:35:14 2012 +++ src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c Tue Aug 21 20:52:11 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_rule_test.c,v 1.1 2012/08/12 03:35:14 rmind Exp $ */ +/* $NetBSD: npf_rule_test.c,v 1.2 2012/08/21 20:52:11 rmind Exp $ */ /* * NPF ruleset test. @@ -99,10 +99,11 @@ npf_rule_raw_test(bool verbose, struct m bool npf_rule_test(bool verbose) { + bool fail = false; + for (unsigned i = 0; i < __arraycount(test_cases); i++) { const struct test_case *t = &test_cases[i]; ifnet_t *ifp = ifunit(t->ifname); - struct mbuf *m = fill_packet(t); int serror, error; if (ifp == NULL) { @@ -110,6 +111,7 @@ npf_rule_test(bool verbose) return false; } + struct mbuf *m = fill_packet(t); error = npf_rule_raw_test(verbose, m, ifp, t->di); serror = npf_packet_handler(NULL, &m, ifp, t->di); @@ -122,9 +124,7
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: martin Date: Wed Sep 12 08:47:14 UTC 2012 Modified Files: src/usr.sbin/npf/npftest: npftest.c Log Message: Add two new command line options to help integration into ATF: -L lists the available test cases, -T executes a single named test. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/npf/npftest/npftest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.6 src/usr.sbin/npf/npftest/npftest.c:1.7 --- src/usr.sbin/npf/npftest/npftest.c:1.6 Tue Aug 21 20:52:11 2012 +++ src/usr.sbin/npf/npftest/npftest.c Wed Sep 12 08:47:14 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.6 2012/08/21 20:52:11 rmind Exp $ */ +/* $NetBSD: npftest.c,v 1.7 2012/09/12 08:47:14 martin Exp $ */ /* * NPF testing framework. @@ -29,19 +29,37 @@ static bool verbose, quiet; static void usage(void) { - printf("usage: %s: [ -q | -v ] [ -c ] " - "[ -i ] < -b | -t | -s file >\n" + printf("usage:\n" + " %s [ -q | -v ] [ -c ] " + "[ -i ] < -b | -t | -s file >\n" + " %s -T -c \n" + " %s -L\n" + "where:\n" "\t-b: benchmark\n" "\t-t: regression test\n" + "\t-T : specific test\n" "\t-s : pcap stream\n" "\t-c : NPF configuration file\n" "\t-i : primary interface\n" + "\t-L: list testnames and description for -T\n" "\t-q: quiet mode\n" "\t-v: verbose mode\n", - getprogname()); + getprogname(), getprogname(), getprogname()); exit(EXIT_FAILURE); } +static void +describe_tests(void) +{ + printf( "nbuf\tbasic npf mbuf handling\n" + "processor\tncode processing\n" + "table\ttable handling\n" + "state\tstate handling and processing\n" + "rule\trule processing\n" + "nat\tNAT rule processing\n"); + exit(EXIT_SUCCESS); +} + static bool result(const char *testcase, bool ok) { @@ -119,13 +137,15 @@ arc4random(void) int main(int argc, char **argv) { - bool benchmark, test, ok, fail; - char *config, *interface, *stream; + bool benchmark, test, ok, fail, tname_matched; + char *config, *interface, *stream, *testname; int idx = -1, ch; benchmark = false; test = false; + tname_matched = false; + testname = NULL; config = NULL; interface = NULL; stream = NULL; @@ -133,7 +153,7 @@ main(int argc, char **argv) verbose = false; quiet = false; - while ((ch = getopt(argc, argv, "bqvc:i:s:t")) != -1) { + while ((ch = getopt(argc, argv, "bqvc:i:s:tT:L")) != -1) { switch (ch) { case 'b': benchmark = true; @@ -156,6 +176,12 @@ main(int argc, char **argv) case 't': test = true; break; + case 'T': + test = true; + testname = optarg; + break; + case 'L': + describe_tests(); default: usage(); } @@ -189,25 +215,43 @@ main(int argc, char **argv) fail = false; if (test) { - ok = rumpns_npf_nbuf_test(verbose); - fail |= result("nbuf", ok); + if (!testname || strcmp("nbuf", testname) == 0) { + ok = rumpns_npf_nbuf_test(verbose); + fail |= result("nbuf", ok); + tname_matched = true; + } - ok = rumpns_npf_processor_test(verbose); - fail |= result("processor", ok); + if (!testname || strcmp("processor", testname) == 0) { + ok = rumpns_npf_processor_test(verbose); + fail |= result("processor", ok); + tname_matched = true; + } - ok = rumpns_npf_table_test(verbose); - fail |= result("table", ok); + if (!testname || strcmp("table", testname) == 0) { + ok = rumpns_npf_table_test(verbose); + fail |= result("table", ok); + tname_matched = true; + } - ok = rumpns_npf_state_test(verbose); - fail |= result("state", ok); + if (!testname || strcmp("state", testname) == 0) { + ok = rumpns_npf_state_test(verbose); + fail |= result("state", ok); + tname_matched = true; + } } if (test && config) { - ok = rumpns_npf_rule_test(verbose); - fail |= result("rule", ok); + if (!testname || strcmp("rule", testname) == 0) { + ok = rumpns_npf_rule_test(verbose); + fail |= result("rule", ok); + tname_matched = true; + } - ok = rumpns_npf_nat_test(verbose); - fail |= result("nat", ok); + if (!testname || strcmp("nat", testname) == 0) { + ok = rumpns_npf_nat_test(verbose); + fail |= result("nat", ok); + tname_matched = true; + } } if (stream) { @@ -216,5 +260,8 @@ main(int argc, char **argv) rump_unschedule(); + if (testname && !tname_matched) + errx(EXIT_FAILURE, "test \"%s\" unknown", testname); + return fail ? EXIT_FAILURE : EXIT_SUCCESS; }
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: martin Date: Wed Sep 12 16:26:02 UTC 2012 Modified Files: src/usr.sbin/npf/npftest: npfstream.c Log Message: Fix printf format To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/npf/npftest/npfstream.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npfstream.c diff -u src/usr.sbin/npf/npftest/npfstream.c:1.3 src/usr.sbin/npf/npftest/npfstream.c:1.4 --- src/usr.sbin/npf/npftest/npfstream.c:1.3 Sun Aug 12 03:35:14 2012 +++ src/usr.sbin/npf/npftest/npfstream.c Wed Sep 12 16:26:02 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npfstream.c,v 1.3 2012/08/12 03:35:14 rmind Exp $ */ +/* $NetBSD: npfstream.c,v 1.4 2012/09/12 16:26:02 martin Exp $ */ /* * NPF stream processor. @@ -73,7 +73,7 @@ process_tcpip(const void *data, size_t l len = ntohs(ip->ip_len); error = rumpns_npf_test_handlepkt(ip, len, idx, forw, result); - fprintf(fp, "%s%2x %5d %3d %11u %11u %11u %11u %12lx", + fprintf(fp, "%s%2x %5d %3d %11u %11u %11u %11u %12" PRIxPTR, forw ? ">" : "<", (th->th_flags & (TH_SYN | TH_ACK | TH_FIN)), packetno, error, (u_int)seq, (u_int)ntohl(th->th_ack), tcpdlen, ntohs(th->th_win), (uintptr_t)result[0]);
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: joerg Date: Fri Sep 14 15:37:03 UTC 2012 Modified Files: src/usr.sbin/npf/npftest: npftest.c Log Message: More __dead To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/npf/npftest/npftest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.7 src/usr.sbin/npf/npftest/npftest.c:1.8 --- src/usr.sbin/npf/npftest/npftest.c:1.7 Wed Sep 12 08:47:14 2012 +++ src/usr.sbin/npf/npftest/npftest.c Fri Sep 14 15:37:03 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.7 2012/09/12 08:47:14 martin Exp $ */ +/* $NetBSD: npftest.c,v 1.8 2012/09/14 15:37:03 joerg Exp $ */ /* * NPF testing framework. @@ -26,7 +26,7 @@ static bool verbose, quiet; -static void +__dead static void usage(void) { printf("usage:\n" @@ -48,7 +48,7 @@ usage(void) exit(EXIT_FAILURE); } -static void +__dead static void describe_tests(void) { printf( "nbuf\tbasic npf mbuf handling\n"
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: knakahara Date: Mon Apr 25 02:01:32 UTC 2016 Modified Files: src/usr.sbin/npf/npftest: Makefile Log Message: fix ATF net/npf/t_npf failure To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/npf/npftest/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/Makefile diff -u src/usr.sbin/npf/npftest/Makefile:1.7 src/usr.sbin/npf/npftest/Makefile:1.8 --- src/usr.sbin/npf/npftest/Makefile:1.7 Sat Nov 16 17:12:35 2013 +++ src/usr.sbin/npf/npftest/Makefile Mon Apr 25 02:01:32 2016 @@ -16,7 +16,7 @@ LIBNPFTEST!= cd ${.CURDIR}/libnpftest && DPADD+= ${LIBNPFTEST}/libnpftest.a LDADD+= -L${LIBNPFTEST} -lnpftest -LDADD+= -lrump -lrumpvfs -lrumpnet -lrumpnet_net +LDADD+= -lrump -lrumpvfs -lrumpuser -lrumpnet -lrumpnet_net LDADD+= -lrumpdev_bpf .include
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: christos Date: Sun May 29 02:28:07 UTC 2016 Modified Files: src/usr.sbin/npf/npftest: Makefile Log Message: npftest needs to disable mprotect because it uses bpfjit To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/npf/npftest/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/Makefile diff -u src/usr.sbin/npf/npftest/Makefile:1.8 src/usr.sbin/npf/npftest/Makefile:1.9 --- src/usr.sbin/npf/npftest/Makefile:1.8 Sun Apr 24 22:01:32 2016 +++ src/usr.sbin/npf/npftest/Makefile Sat May 28 22:28:07 2016 @@ -5,6 +5,7 @@ PROG= npftest NOMAN= # no man page +PAXCTL_FLAGS.npftest += +m WARNS= 5 NOLINT= # disabled (note: deliberately)
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: kre Date: Mon Aug 8 16:31:53 UTC 2016 Modified Files: src/usr.sbin/npf/npftest: Makefile Log Message: Yet another -lrumpdev To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/npf/npftest/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/Makefile diff -u src/usr.sbin/npf/npftest/Makefile:1.9 src/usr.sbin/npf/npftest/Makefile:1.10 --- src/usr.sbin/npf/npftest/Makefile:1.9 Sun May 29 02:28:07 2016 +++ src/usr.sbin/npf/npftest/Makefile Mon Aug 8 16:31:53 2016 @@ -19,6 +19,7 @@ LDADD+= -L${LIBNPFTEST} -lnpftest LDADD+= -lrump -lrumpvfs -lrumpuser -lrumpnet -lrumpnet_net LDADD+= -lrumpdev_bpf +LDADD+= -lrumpdev .include
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: pooka Date: Mon Jan 25 12:24:41 UTC 2016 Modified Files: src/usr.sbin/npf/npftest: npftest.c Log Message: include proplib.h if you're going to useuseitit To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/npf/npftest/npftest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.18 src/usr.sbin/npf/npftest/npftest.c:1.19 --- src/usr.sbin/npf/npftest/npftest.c:1.18 Tue Jun 16 23:04:14 2015 +++ src/usr.sbin/npf/npftest/npftest.c Mon Jan 25 12:24:41 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.18 2015/06/16 23:04:14 christos Exp $ */ +/* $NetBSD: npftest.c,v 1.19 2016/01/25 12:24:41 pooka Exp $ */ /* * NPF testing framework. @@ -20,6 +20,8 @@ #include #include +#include + #include #include
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Wed Feb 5 03:30:13 UTC 2014 Modified Files: src/usr.sbin/npf/npftest: npftest.c src/usr.sbin/npf/npftest/libnpftest: npf_nat_test.c npf_test_subr.c Log Message: npftest: fix the failure of NAT test -- adjust for RUMP's conversion to the in-kernel CPRNG (hi pooka!). To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/npf/npftest/npftest.c cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.13 src/usr.sbin/npf/npftest/npftest.c:1.14 --- src/usr.sbin/npf/npftest/npftest.c:1.13 Fri Nov 8 00:38:26 2013 +++ src/usr.sbin/npf/npftest/npftest.c Wed Feb 5 03:30:13 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.13 2013/11/08 00:38:26 rmind Exp $ */ +/* $NetBSD: npftest.c,v 1.14 2014/02/05 03:30:13 rmind Exp $ */ /* * NPF testing framework. @@ -121,15 +121,6 @@ load_npf_config(const char *config) } } -/* - * Need to override for cprng_fast32(), since RUMP uses arc4random() for it. - */ -uint32_t -arc4random(void) -{ - return random(); -} - int main(int argc, char **argv) { Index: src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c:1.4 src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c:1.5 --- src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c:1.4 Tue Sep 24 02:04:21 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c Wed Feb 5 03:30:13 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_nat_test.c,v 1.4 2013/09/24 02:04:21 rmind Exp $ */ +/* $NetBSD: npf_nat_test.c,v 1.5 2014/02/05 03:30:13 rmind Exp $ */ /* * NPF NAT test. @@ -16,6 +16,8 @@ #define NPF_BINAT (NPF_NATIN | NPF_NATOUT) +#define RANDOM_PORT 45600 + static const struct test_case { const char * src; in_port_t sport; @@ -36,12 +38,12 @@ static const struct test_case { { LOCAL_IP1, 15000, REMOTE_IP1, 7000, NPF_NATOUT, IFNAME_EXT, PFIL_OUT, - RESULT_PASS, PUB_IP1, 53472 + RESULT_PASS, PUB_IP1, RANDOM_PORT }, { LOCAL_IP1, 15000, REMOTE_IP1, 7000, NPF_NATOUT, IFNAME_EXT, PFIL_OUT, - RESULT_PASS, PUB_IP1, 53472 + RESULT_PASS, PUB_IP1, RANDOM_PORT }, { LOCAL_IP1, 15000, REMOTE_IP1, 7000, @@ -54,12 +56,12 @@ static const struct test_case { RESULT_BLOCK, NULL, 0 }, { - REMOTE_IP1, 7000, PUB_IP1, 53472, + REMOTE_IP1, 7000, PUB_IP1, RANDOM_PORT, NPF_NATOUT, IFNAME_INT, PFIL_IN, RESULT_BLOCK, NULL, 0 }, { - REMOTE_IP1, 7000, PUB_IP1, 53472, + REMOTE_IP1, 7000, PUB_IP1, RANDOM_PORT, NPF_NATOUT, IFNAME_EXT, PFIL_IN, RESULT_PASS, LOCAL_IP1, 15000 }, Index: src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.6 src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.7 --- src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.6 Fri Nov 8 00:38:27 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c Wed Feb 5 03:30:13 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_test_subr.c,v 1.6 2013/11/08 00:38:27 rmind Exp $ */ +/* $NetBSD: npf_test_subr.c,v 1.7 2014/02/05 03:30:13 rmind Exp $ */ /* * NPF initialisation and handler routines. @@ -7,6 +7,7 @@ */ #include +#include #include #include @@ -114,3 +115,12 @@ npf_test_statetrack(const void *data, si return 0; } + +/* + * Need to override for cprng_fast32() -- we need deterministic PRNG. + */ +uint32_t +_arc4random(void) +{ + return random(); +}
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Wed Feb 5 03:49:48 UTC 2014 Modified Files: src/usr.sbin/npf/npftest: npftest.c npftest.h src/usr.sbin/npf/npftest/libnpftest: npf_nat_test.c npf_test.h npf_test_subr.c Log Message: npftest: fix previous harder - pass and use libc's random(3). To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/npf/npftest/npftest.c cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/npf/npftest/npftest.h cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/npf/npftest/libnpftest/npf_test.h cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.14 src/usr.sbin/npf/npftest/npftest.c:1.15 --- src/usr.sbin/npf/npftest/npftest.c:1.14 Wed Feb 5 03:30:13 2014 +++ src/usr.sbin/npf/npftest/npftest.c Wed Feb 5 03:49:48 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.14 2014/02/05 03:30:13 rmind Exp $ */ +/* $NetBSD: npftest.c,v 1.15 2014/02/05 03:49:48 rmind Exp $ */ /* * NPF testing framework. @@ -207,7 +207,7 @@ main(int argc, char **argv) rump_init(); rump_schedule(); - rumpns_npf_test_init(); + rumpns_npf_test_init(random); if (config) { load_npf_config(config); Index: src/usr.sbin/npf/npftest/npftest.h diff -u src/usr.sbin/npf/npftest/npftest.h:1.10 src/usr.sbin/npf/npftest/npftest.h:1.11 --- src/usr.sbin/npf/npftest/npftest.h:1.10 Fri Nov 8 00:38:27 2013 +++ src/usr.sbin/npf/npftest/npftest.h Wed Feb 5 03:49:48 2014 @@ -12,7 +12,7 @@ #include -void rumpns_npf_test_init(void); +void rumpns_npf_test_init(long (*)(void)); int rumpns_npf_test_load(const void *); ifnet_t * rumpns_npf_test_addif(const char *, bool, bool); ifnet_t * rumpns_npf_test_getif(const char *); Index: src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c:1.5 src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c:1.6 --- src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c:1.5 Wed Feb 5 03:30:13 2014 +++ src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c Wed Feb 5 03:49:48 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_nat_test.c,v 1.5 2014/02/05 03:30:13 rmind Exp $ */ +/* $NetBSD: npf_nat_test.c,v 1.6 2014/02/05 03:49:48 rmind Exp $ */ /* * NPF NAT test. @@ -16,7 +16,7 @@ #define NPF_BINAT (NPF_NATIN | NPF_NATOUT) -#define RANDOM_PORT 45600 +#define RANDOM_PORT 53472 static const struct test_case { const char * src; Index: src/usr.sbin/npf/npftest/libnpftest/npf_test.h diff -u src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.11 src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.12 --- src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.11 Fri Nov 8 00:38:27 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_test.h Wed Feb 5 03:49:48 2014 @@ -39,7 +39,7 @@ #define REMOTE_IP1 "192.0.2.3" #define REMOTE_IP2 "192.0.2.4" -void npf_test_init(void); +void npf_test_init(long (*)(void)); int npf_test_load(const void *); ifnet_t * npf_test_addif(const char *, bool, bool); ifnet_t * npf_test_getif(const char *); Index: src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.7 src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.8 --- src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.7 Wed Feb 5 03:30:13 2014 +++ src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c Wed Feb 5 03:49:48 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_test_subr.c,v 1.7 2014/02/05 03:30:13 rmind Exp $ */ +/* $NetBSD: npf_test_subr.c,v 1.8 2014/02/05 03:49:48 rmind Exp $ */ /* * NPF initialisation and handler routines. @@ -20,11 +20,13 @@ static void * cstream_ptr; static bool cstream_retval; static void npf_state_sample(npf_state_t *, bool); +static long (*npf_random_func)(void) = NULL; void -npf_test_init(void) +npf_test_init(long (*rndfunc)(void)) { npf_state_setsampler(npf_state_sample); + npf_random_func = rndfunc; } int @@ -122,5 +124,5 @@ npf_test_statetrack(const void *data, si uint32_t _arc4random(void) { - return random(); + return (uint32_t)(npf_random_func ? npf_random_func() : random()); }
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Wed May 14 21:46:50 UTC 2014 Modified Files: src/usr.sbin/npf/npftest: README Log Message: npftest: fix the example in the README file. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/npf/npftest/README Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/README diff -u src/usr.sbin/npf/npftest/README:1.4 src/usr.sbin/npf/npftest/README:1.5 --- src/usr.sbin/npf/npftest/README:1.4 Sat Feb 9 03:35:33 2013 +++ src/usr.sbin/npf/npftest/README Wed May 14 21:46:50 2014 @@ -1,4 +1,4 @@ -$NetBSD: README,v 1.4 2013/02/09 03:35:33 rmind Exp $ +$NetBSD: README,v 1.5 2014/05/14 21:46:50 rmind Exp $ npftest - a tool for regression testing and debugging NPF. It uses RUMP framework to run NPF kernel module in the userspace. @@ -13,8 +13,8 @@ npftest -c /tmp/npf.plist -t Stream: tcpdump -w stream.pcap -i $INTERFACE "host $HOST and tcp" -npfctl debug -npftest -c /tmp/npf.plist -s stream.pcap -o stream_npf_data.txt +npfctl debug npftest.conf /tmp/npf.plist +npftest -c /tmp/npf.plist -s stream.pcap > stream_npf_data.txt Preferably, use MALLOC_OPTIONS="AJ" and/or other facilities.
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Wed Jun 25 00:21:42 UTC 2014 Modified Files: src/usr.sbin/npf/npftest: README src/usr.sbin/npf/npftest/libnpftest: npf_perf_test.c Log Message: npftest: add an example in the README, fix the total in npf_test_conc(). To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/npf/npftest/README cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/README diff -u src/usr.sbin/npf/npftest/README:1.5 src/usr.sbin/npf/npftest/README:1.6 --- src/usr.sbin/npf/npftest/README:1.5 Wed May 14 21:46:50 2014 +++ src/usr.sbin/npf/npftest/README Wed Jun 25 00:21:42 2014 @@ -1,4 +1,4 @@ -$NetBSD: README,v 1.5 2014/05/14 21:46:50 rmind Exp $ +$NetBSD: README,v 1.6 2014/06/25 00:21:42 rmind Exp $ npftest - a tool for regression testing and debugging NPF. It uses RUMP framework to run NPF kernel module in the userspace. @@ -12,12 +12,16 @@ npftest -c /tmp/npf.plist -t Stream: -tcpdump -w stream.pcap -i $INTERFACE "host $HOST and tcp" +tcpdump -w stream.pcap -i $interface "host $host and tcp" npfctl debug npftest.conf /tmp/npf.plist npftest -c /tmp/npf.plist -s stream.pcap > stream_npf_data.txt Preferably, use MALLOC_OPTIONS="AJ" and/or other facilities. +Benchmark: + +npftest -b rule -c /tmp/npf.plist -p $ncpu + --- Update RUMP libraries once the kernel side has been changed. Hint: Index: src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.3 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.4 --- src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.3 Tue Sep 24 22:52:14 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Wed Jun 25 00:21:42 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_perf_test.c,v 1.3 2013/09/24 22:52:14 joerg Exp $ */ +/* $NetBSD: npf_perf_test.c,v 1.4 2014/06/25 00:21:42 rmind Exp $ */ /* * NPF benchmarking. @@ -99,5 +99,5 @@ npf_test_conc(bool st, unsigned nthreads kmem_free(npackets, sizeof(uint64_t) * nthreads); kmem_free(l, sizeof(lwp_t *) * nthreads); - printf("%u\t%" PRIu64 "\n", nthreads, total); + printf("%u\t%" PRIu64 "\n", nthreads, total / NSECS); }
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Mon Sep 23 15:30:32 UTC 2013 Modified Files: src/usr.sbin/npf/npftest: npftest.conf Log Message: Update npftest.conf for the recent syntax adjustments. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/npf/npftest/npftest.conf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.conf diff -u src/usr.sbin/npf/npftest/npftest.conf:1.2 src/usr.sbin/npf/npftest/npftest.conf:1.3 --- src/usr.sbin/npf/npftest/npftest.conf:1.2 Sat Feb 9 03:35:33 2013 +++ src/usr.sbin/npf/npftest/npftest.conf Mon Sep 23 15:30:32 2013 @@ -1,4 +1,4 @@ -# $NetBSD: npftest.conf,v 1.2 2013/02/09 03:35:33 rmind Exp $ +# $NetBSD: npftest.conf,v 1.3 2013/09/23 15:30:32 rmind Exp $ $ext_if = "npftest0" $int_if = "npftest1" @@ -22,7 +22,7 @@ map $ext_if dynamic $local_ip2 <-> $pub_ map $ext_if dynamic $local_net -> $pub_ip1 map $ext_if dynamic $local_ip1 port 6000 <- $pub_ip1 port 8000 -group (interface $ext_if) { +group "ext" on $ext_if { pass stateful out final proto tcp flags S/SA all pass stateful out final from $local_net pass stateful in final to any port $ports @@ -30,13 +30,13 @@ group (interface $ext_if) { block all } -group (interface $int_if) { - ruleset (name "test-rules", dynamic) +group "int" on $int_if { + ruleset "test-rules" pass stateful out final to $local_ip2 pass out final to $local_ip3 block final to $local_ip4 } -group (default) { +group default { block all }
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Tue Sep 24 02:04:22 UTC 2013 Modified Files: src/usr.sbin/npf/npftest: npfstream.c npftest.c npftest.h src/usr.sbin/npf/npftest/libnpftest: Makefile npf_nat_test.c npf_rule_test.c npf_test.h npf_test_subr.c Added Files: src/usr.sbin/npf/npftest/libnpftest: npf_perf_test.c Log Message: npftest: add some concurrency testing code. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/npf/npftest/npfstream.c cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/npf/npftest/npftest.c cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/npf/npftest/npftest.h cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/npf/npftest/libnpftest/Makefile cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/npf/npftest/libnpftest/npf_nat_test.c cvs rdiff -u -r0 -r1.1 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/npf/npftest/libnpftest/npf_test.h cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npfstream.c diff -u src/usr.sbin/npf/npftest/npfstream.c:1.4 src/usr.sbin/npf/npftest/npfstream.c:1.5 --- src/usr.sbin/npf/npftest/npfstream.c:1.4 Wed Sep 12 16:26:02 2012 +++ src/usr.sbin/npf/npftest/npfstream.c Tue Sep 24 02:04:21 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npfstream.c,v 1.4 2012/09/12 16:26:02 martin Exp $ */ +/* $NetBSD: npfstream.c,v 1.5 2013/09/24 02:04:21 rmind Exp $ */ /* * NPF stream processor. @@ -71,7 +71,7 @@ process_tcpip(const void *data, size_t l memset(result, 0, sizeof(result)); len = ntohs(ip->ip_len); - error = rumpns_npf_test_handlepkt(ip, len, idx, forw, result); + error = rumpns_npf_test_statetrack(ip, len, idx, forw, result); fprintf(fp, "%s%2x %5d %3d %11u %11u %11u %11u %12" PRIxPTR, forw ? ">" : "<", (th->th_flags & (TH_SYN | TH_ACK | TH_FIN)), Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.10 src/usr.sbin/npf/npftest/npftest.c:1.11 --- src/usr.sbin/npf/npftest/npftest.c:1.10 Thu Sep 19 01:49:07 2013 +++ src/usr.sbin/npf/npftest/npftest.c Tue Sep 24 02:04:21 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.10 2013/09/19 01:49:07 rmind Exp $ */ +/* $NetBSD: npftest.c,v 1.11 2013/09/24 02:04:21 rmind Exp $ */ /* * NPF testing framework. @@ -139,6 +139,7 @@ main(int argc, char **argv) { bool benchmark, test, ok, fail, tname_matched; char *config, *interface, *stream, *testname; + unsigned nthreads = 0; int idx = -1, ch; benchmark = false; @@ -153,7 +154,7 @@ main(int argc, char **argv) verbose = false; quiet = false; - while ((ch = getopt(argc, argv, "bqvc:i:s:tT:L")) != -1) { + while ((ch = getopt(argc, argv, "bqvc:i:s:tT:Lp:")) != -1) { switch (ch) { case 'b': benchmark = true; @@ -182,18 +183,34 @@ main(int argc, char **argv) break; case 'L': describe_tests(); + break; + case 'p': + /* Note: RUMP_NCPU must be high enough. */ + if ((nthreads = atoi(optarg)) > 0 && + getenv("RUMP_NCPU") == NULL) { +char *val; +asprintf(&val, "%u", nthreads + 1); +setenv("RUMP_NCPU", val, 1); +free(val); + } + break; default: usage(); } } /* - * Either benchmark or test. If stream analysis, then the interface - * is needed as well. + * Either benchmark or test. If stream analysis, then the + * interface should be specified. If benchmark, then the + * config should be loaded. */ if (benchmark == test && (stream && !interface)) { usage(); } + if (benchmark && (!config || !nthreads)) { + errx(EXIT_FAILURE, "missing config for the benchmark or " + "invalid thread count"); + } /* XXX rn_init */ extern int rumpns_max_keylen; @@ -258,6 +275,10 @@ main(int argc, char **argv) process_stream(stream, NULL, idx); } + if (benchmark) { + rumpns_npf_test_conc(nthreads); + } + rump_unschedule(); if (testname && !tname_matched) Index: src/usr.sbin/npf/npftest/npftest.h diff -u src/usr.sbin/npf/npftest/npftest.h:1.7 src/usr.sbin/npf/npftest/npftest.h:1.8 --- src/usr.sbin/npf/npftest/npftest.h:1.7 Thu Sep 19 01:49:07 2013 +++ src/usr.sbin/npf/npftest/npftest.h Tue Sep 24 02:04:21 2013 @@ -7,15 +7,17 @@ #ifndef _NPF_TEST_H_ #define _NPF_TEST_H_ -#include +#include #include void rumpns_npf_test_init(void); int rumpns_npf_test_load(const void *); unsigned rumpns_npf_test_addif(const char *, unsigned, bool); unsigned rumpns_npf_test_getif(const char *); -int rumpns_npf_test_handlepkt(const void *, size_t, + +int rumpns_npf_test_statetrack(const void *, size_t, unsigned, bool, int64_t *); +void rumpns_npf_test_conc(unsigned); bool rumpns_npf_nbuf_test(bool); bool rumpns_npf_bpf_test(bool); Index: src/usr.sbin/npf/npftest/libnpftest/Makefile diff -u src/usr.s
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Tue Sep 24 02:44:20 UTC 2013 Modified Files: src/usr.sbin/npf/npftest: npftest.c npftest.h src/usr.sbin/npf/npftest/libnpftest: npf_perf_test.c npf_test.h Log Message: npftest: add a choice of "rule" or "state" for -b option. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/npf/npftest/npftest.c cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/npf/npftest/npftest.h cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/npf/npftest/libnpftest/npf_test.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.11 src/usr.sbin/npf/npftest/npftest.c:1.12 --- src/usr.sbin/npf/npftest/npftest.c:1.11 Tue Sep 24 02:04:21 2013 +++ src/usr.sbin/npf/npftest/npftest.c Tue Sep 24 02:44:20 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.11 2013/09/24 02:04:21 rmind Exp $ */ +/* $NetBSD: npftest.c,v 1.12 2013/09/24 02:44:20 rmind Exp $ */ /* * NPF testing framework. @@ -137,12 +137,12 @@ arc4random(void) int main(int argc, char **argv) { - bool benchmark, test, ok, fail, tname_matched; - char *config, *interface, *stream, *testname; + bool test, ok, fail, tname_matched; + char *benchmark, *config, *interface, *stream, *testname; unsigned nthreads = 0; int idx = -1, ch; - benchmark = false; + benchmark = NULL; test = false; tname_matched = false; @@ -154,10 +154,10 @@ main(int argc, char **argv) verbose = false; quiet = false; - while ((ch = getopt(argc, argv, "bqvc:i:s:tT:Lp:")) != -1) { + while ((ch = getopt(argc, argv, "b:qvc:i:s:tT:Lp:")) != -1) { switch (ch) { case 'b': - benchmark = true; + benchmark = optarg; break; case 'q': quiet = true; @@ -204,7 +204,7 @@ main(int argc, char **argv) * interface should be specified. If benchmark, then the * config should be loaded. */ - if (benchmark == test && (stream && !interface)) { + if ((benchmark != NULL) == test && (stream && !interface)) { usage(); } if (benchmark && (!config || !nthreads)) { @@ -276,7 +276,12 @@ main(int argc, char **argv) } if (benchmark) { - rumpns_npf_test_conc(nthreads); + if (strcmp("rule", benchmark) == 0) { + rumpns_npf_test_conc(false, nthreads); + } + if (strcmp("state", benchmark) == 0) { + rumpns_npf_test_conc(true, nthreads); + } } rump_unschedule(); Index: src/usr.sbin/npf/npftest/npftest.h diff -u src/usr.sbin/npf/npftest/npftest.h:1.8 src/usr.sbin/npf/npftest/npftest.h:1.9 --- src/usr.sbin/npf/npftest/npftest.h:1.8 Tue Sep 24 02:04:21 2013 +++ src/usr.sbin/npf/npftest/npftest.h Tue Sep 24 02:44:20 2013 @@ -17,7 +17,7 @@ unsigned rumpns_npf_test_getif(const cha int rumpns_npf_test_statetrack(const void *, size_t, unsigned, bool, int64_t *); -void rumpns_npf_test_conc(unsigned); +void rumpns_npf_test_conc(bool, unsigned); bool rumpns_npf_nbuf_test(bool); bool rumpns_npf_bpf_test(bool); Index: src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.1 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.2 --- src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.1 Tue Sep 24 02:04:21 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Tue Sep 24 02:44:20 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_perf_test.c,v 1.1 2013/09/24 02:04:21 rmind Exp $ */ +/* $NetBSD: npf_perf_test.c,v 1.2 2013/09/24 02:44:20 rmind Exp $ */ /* * NPF benchmarking. @@ -16,24 +16,30 @@ #include "npf_impl.h" #include "npf_test.h" -#define NSECS 1 /* seconds */ +#define NSECS 10 /* seconds */ static volatile int run; static volatile int done; +static uint64_t * npackets; +static bool stateful; + static struct mbuf * -fill_packet(void) +fill_packet(unsigned i) { struct mbuf *m; struct ip *ip; - struct tcphdr *th; + struct udphdr *uh; + char buf[32]; + + m = mbuf_construct(IPPROTO_UDP); + uh = mbuf_return_hdrs(m, false, &ip); - m = mbuf_construct(IPPROTO_TCP); - th = mbuf_return_hdrs(m, false, &ip); + snprintf(buf, sizeof(buf), "192.0.2.%u", i + i); ip->ip_src.s_addr = inet_addr(PUB_IP1); - ip->ip_dst.s_addr = inet_addr(LOCAL_IP3); - th->th_sport = htons(80); - th->th_dport = htons(15000); + ip->ip_dst.s_addr = inet_addr(stateful ? LOCAL_IP2 : LOCAL_IP3); + uh->uh_sport = htons(80); + uh->uh_dport = htons(15000 + i); return m; } @@ -41,8 +47,9 @@ static void worker(void *arg) { ifnet_t *ifp = ifunit(IFNAME_INT); - uint64_t n = 0, *npackets = arg; - struct mbuf *m = fill_packet(); + unsigned int i = (uintptr_t)arg; + struct mbuf *m = fill_packet(i); + uint64_t n = 0; while (!run) /* spin-wait */; @@ -53,28 +60,29 @@ worker(void *arg) KASSERT(error == 0); n++; } - *npackets = n; + npackets[i] = n; kthread_exit(0); } void -npf_test_conc(unsigne
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Sat Nov 16 01:41:43 UTC 2013 Modified Files: src/usr.sbin/npf/npftest: Makefile src/usr.sbin/npf/npftest/libnpftest: Makefile npf_bpf_test.c Log Message: Enable bpfjit for npftest. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/npf/npftest/Makefile cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/npf/npftest/libnpftest/Makefile cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/Makefile diff -u src/usr.sbin/npf/npftest/Makefile:1.4 src/usr.sbin/npf/npftest/Makefile:1.5 --- src/usr.sbin/npf/npftest/Makefile:1.4 Sat Feb 9 03:35:33 2013 +++ src/usr.sbin/npf/npftest/Makefile Sat Nov 16 01:41:43 2013 @@ -12,12 +12,13 @@ LIBNPFTEST!= cd ${.CURDIR}/libnpftest && 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) Index: src/usr.sbin/npf/npftest/libnpftest/Makefile diff -u src/usr.sbin/npf/npftest/libnpftest/Makefile:1.7 src/usr.sbin/npf/npftest/libnpftest/Makefile:1.8 --- src/usr.sbin/npf/npftest/libnpftest/Makefile:1.7 Tue Sep 24 02:04:21 2013 +++ src/usr.sbin/npf/npftest/libnpftest/Makefile Sat Nov 16 01:41:43 2013 @@ -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 Index: src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c:1.2 src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c:1.3 --- src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c:1.2 Fri Nov 8 00:38:27 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c Sat Nov 16 01:41:43 2013 @@ -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;
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: alnsn Date: Sat Nov 16 15:58:30 UTC 2013 Modified Files: src/usr.sbin/npf/npftest: Makefile Log Message: Link to -lrumpnet_bpfjit and -lrumpkern_sljit iff MKSLJIT != "no". To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/npf/npftest/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/Makefile diff -u src/usr.sbin/npf/npftest/Makefile:1.5 src/usr.sbin/npf/npftest/Makefile:1.6 --- src/usr.sbin/npf/npftest/Makefile:1.5 Sat Nov 16 01:41:43 2013 +++ src/usr.sbin/npf/npftest/Makefile Sat Nov 16 15:58:30 2013 @@ -13,7 +13,12 @@ DPADD+= ${LIBNPFTEST}/libnpftest.a LDADD+= -L${LIBNPFTEST} -lnpftest LDADD+= -lrump -lrumpvfs -lrumpnet -lrumpnet_net -LDADD+= -lrumpdev_bpf -lrumpkern_sljit -lrumpnet_bpfjit +LDADD+= -lrumpdev_bpf + +.if ${MKSLJIT} != "no" +LDADD+= -lrumpkern_sljit -lrumpnet_bpfjit +.endif + LDADD+= -lrumpnet_npf LDADD+= -lpcap -lprop -lpthread
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: rmind Date: Sat Nov 16 17:12:35 UTC 2013 Modified Files: src/usr.sbin/npf/npftest: Makefile Log Message: Add bsd.own.mk for MKSLJIT, reorder some vars. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/npf/npftest/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/Makefile diff -u src/usr.sbin/npf/npftest/Makefile:1.6 src/usr.sbin/npf/npftest/Makefile:1.7 --- src/usr.sbin/npf/npftest/Makefile:1.6 Sat Nov 16 15:58:30 2013 +++ src/usr.sbin/npf/npftest/Makefile Sat Nov 16 17:12:35 2013 @@ -4,6 +4,10 @@ # PROG= npftest +NOMAN= # no man page + +WARNS= 5 +NOLINT= # disabled (note: deliberately) SRCS= npftest.c npfstream.c CPPFLAGS+= -I${.CURDIR} @@ -15,6 +19,8 @@ LDADD+= -L${LIBNPFTEST} -lnpftest LDADD+= -lrump -lrumpvfs -lrumpnet -lrumpnet_net LDADD+= -lrumpdev_bpf +.include + .if ${MKSLJIT} != "no" LDADD+= -lrumpkern_sljit -lrumpnet_bpfjit .endif @@ -23,10 +29,6 @@ LDADD+= -lrumpnet_npf LDADD+= -lpcap -lprop -lpthread -WARNS= 5 -NOMAN= # no man page -NOLINT= # disabled (note: deliberately) - SUBDIR+= libnpftest ${LIBNPFTEST}/libnpftest.a: all-libnpftest
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: christos Date: Wed May 17 18:55:13 UTC 2017 Modified Files: src/usr.sbin/npf/npftest: npftest.c Log Message: set "testing mode" for ioctl I/O To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/npf/npftest/npftest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/npftest.c diff -u src/usr.sbin/npf/npftest/npftest.c:1.20 src/usr.sbin/npf/npftest/npftest.c:1.21 --- src/usr.sbin/npf/npftest/npftest.c:1.20 Mon Dec 26 18:05:05 2016 +++ src/usr.sbin/npf/npftest/npftest.c Wed May 17 14:55:13 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: npftest.c,v 1.20 2016/12/26 23:05:05 christos Exp $ */ +/* $NetBSD: npftest.c,v 1.21 2017/05/17 18:55:13 christos Exp $ */ /* * NPF testing framework. @@ -195,6 +195,8 @@ npf_kern_fini(void) #endif } +extern int rumpns_npfctl_testing; + int main(int argc, char **argv) { @@ -276,6 +278,7 @@ main(int argc, char **argv) /* * Initialise the NPF kernel component. */ + rumpns_npfctl_testing = 1; npf_kern_init(); rumpns_npf_test_init(inet_pton, inet_ntop, random);
CVS commit: src/usr.sbin/npf/npftest
Module Name:src Committed By: christos Date: Sat May 16 12:42:11 UTC 2020 Modified Files: src/usr.sbin/npf/npftest: Makefile Log Message: more nofifofs lossage To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/npf/npftest/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/Makefile diff -u src/usr.sbin/npf/npftest/Makefile:1.12 src/usr.sbin/npf/npftest/Makefile:1.13 --- src/usr.sbin/npf/npftest/Makefile:1.12 Mon May 13 13:55:09 2019 +++ src/usr.sbin/npf/npftest/Makefile Sat May 16 08:42:11 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.12 2019/05/13 17:55:09 bad Exp $ +# $NetBSD: Makefile,v 1.13 2020/05/16 12:42:11 christos Exp $ # # Public Domain # @@ -17,8 +17,8 @@ LIBNPFTEST!= cd ${.CURDIR}/libnpftest && DPADD+= ${LIBNPFTEST}/libnpftest.a LDADD+= -L${LIBNPFTEST} -lnpftest -LDADD+= -lrump -lrumpvfs -lrumpuser -lrumpnet -lrumpnet_net -LDADD+= -lrumpdev_bpf +LDADD+= -lrump -lrumpvfs_nofifofs -lrumpvfs -lrumpuser +LDADD+= -lrumpnet -lrumpnet_net -lrumpdev_bpf .include
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: riastradh Date: Thu Aug 27 18:51:20 UTC 2020 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_gc_test.c Log Message: npftest: Wait at least one tick in each gc busy wait iteration. Otherwise the busy wait loop runs a little too fast for the gc about half the times I run the test. XXX We should really arrange mstohz to round up! To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/npf/npftest/libnpftest/npf_gc_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_gc_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_gc_test.c:1.1 src/usr.sbin/npf/npftest/libnpftest/npf_gc_test.c:1.2 --- src/usr.sbin/npf/npftest/libnpftest/npf_gc_test.c:1.1 Sat May 30 14:16:57 2020 +++ src/usr.sbin/npf/npftest/libnpftest/npf_gc_test.c Thu Aug 27 18:51:20 2020 @@ -222,7 +222,7 @@ run_worker_tests(npf_t *npf) /* Wait for the task to be done. */ while (!atomic_load_acquire(&task_done) && retry--) { npf_worker_signal(test_npf); - kpause("gctest", false, mstohz(1), NULL); + kpause("gctest", false, MAX(1, mstohz(1)), NULL); } CHECK_TRUE(atomic_load_acquire(&task_done));
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: rmind Date: Mon Feb 11 02:52:32 UTC 2013 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_rule_test.c Log Message: npftest: adjust for recent change. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.4 src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.5 --- src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.4 Sat Feb 9 03:35:33 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c Mon Feb 11 02:52:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_rule_test.c,v 1.4 2013/02/09 03:35:33 rmind Exp $ */ +/* $NetBSD: npf_rule_test.c,v 1.5 2013/02/11 02:52:32 rmind Exp $ */ /* * NPF ruleset test. @@ -171,8 +171,8 @@ npf_rule_test(bool verbose) error = npf_test_first(verbose); fail |= (error != RESULT_BLOCK); - rl = npf_ruleset_remove(rlset, "test-rules", (uintptr_t)rl); - fail |= (rl == NULL); + error = npf_ruleset_remove(rlset, "test-rules", (uintptr_t)rl); + fail |= error != 0; npf_config_exit();
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: rmind Date: Mon Feb 18 23:09:20 UTC 2013 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_rule_test.c Log Message: npftest/npf_blockall_rule: set NPF_RULE_DYNAMIC flag for the test rule. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.6 src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.7 --- src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.6 Sat Feb 16 21:11:16 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c Mon Feb 18 23:09:20 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_rule_test.c,v 1.6 2013/02/16 21:11:16 rmind Exp $ */ +/* $NetBSD: npf_rule_test.c,v 1.7 2013/02/18 23:09:20 rmind Exp $ */ /* * NPF ruleset test. @@ -120,7 +120,7 @@ npf_blockall_rule(void) rldict = prop_dictionary_create(); prop_dictionary_set_uint32(rldict, "attributes", - NPF_RULE_IN | NPF_RULE_OUT); + NPF_RULE_IN | NPF_RULE_OUT | NPF_RULE_DYNAMIC); return npf_rule_alloc(rldict); }
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: joerg Date: Tue Sep 24 22:52:14 UTC 2013 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_perf_test.c Log Message: Add missing dead. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.2 src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.3 --- src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c:1.2 Tue Sep 24 02:44:20 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_perf_test.c Tue Sep 24 22:52:14 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_perf_test.c,v 1.2 2013/09/24 02:44:20 rmind Exp $ */ +/* $NetBSD: npf_perf_test.c,v 1.3 2013/09/24 22:52:14 joerg Exp $ */ /* * NPF benchmarking. @@ -43,7 +43,7 @@ fill_packet(unsigned i) return m; } -static void +__dead static void worker(void *arg) { ifnet_t *ifp = ifunit(IFNAME_INT);
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: rmind Date: Sat Nov 23 19:40:11 UTC 2013 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_bpf_test.c Log Message: npftest: adjust for the npf_bpf_filter() change. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c:1.3 src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c:1.4 --- src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c:1.3 Sat Nov 16 01:41:43 2013 +++ src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c Sat Nov 23 19:40:11 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_bpf_test.c,v 1.3 2013/11/16 01:41:43 rmind Exp $ */ +/* $NetBSD: npf_bpf_test.c,v 1.4 2013/11/23 19:40:11 rmind Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -63,6 +63,7 @@ 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 }; + bpf_args_t bc_args; struct mbuf *m; nbuf_t nbuf; int ret, jret; @@ -73,12 +74,17 @@ test_bpf_code(void *code, size_t size) nbuf_init(&nbuf, m, dummy_ifp); npf_cache_all(&npc, &nbuf); - ret = npf_bpf_filter(&npc, &nbuf, code, NULL); + memset(&bc_args, 0, sizeof(bpf_args_t)); + bc_args.pkt = m; + bc_args.wirelen = m_length(m); + bc_args.arg = &npc; + + ret = npf_bpf_filter(&bc_args, code, NULL); /* JIT-compiled code. */ jcode = npf_bpf_compile(code, size); if (jcode) { - jret = npf_bpf_filter(&npc, &nbuf, NULL, jcode); + jret = npf_bpf_filter(&bc_args, NULL, jcode); assert(ret == jret); bpf_jit_freecode(jcode); } else if (lverbose) {
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: christos Date: Sun Jan 29 04:12:52 UTC 2017 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_rule_test.c Log Message: fix function argument. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 \ src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.13 src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.14 --- src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c:1.13 Mon Dec 26 18:05:05 2016 +++ src/usr.sbin/npf/npftest/libnpftest/npf_rule_test.c Sat Jan 28 23:12:52 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: npf_rule_test.c,v 1.13 2016/12/26 23:05:05 christos Exp $ */ +/* $NetBSD: npf_rule_test.c,v 1.14 2017/01/29 04:12:52 christos Exp $ */ /* * NPF ruleset test. @@ -80,7 +80,8 @@ npf_rule_raw_test(bool verbose, struct m npf_cache_t npc = { .npc_info = 0, .npc_ctx = npf }; nbuf_t nbuf; npf_rule_t *rl; - int retfl, error; + npf_match_info_t mi; + int error; nbuf_init(npf, &nbuf, m, ifp); npc.npc_nbuf = &nbuf; @@ -90,7 +91,7 @@ npf_rule_raw_test(bool verbose, struct m rl = npf_ruleset_inspect(&npc, npf_config_ruleset(npf), di, NPF_LAYER_3); if (rl) { - error = npf_rule_conclude(rl, &retfl); + error = npf_rule_conclude(rl, &mi); } else { error = ENOENT; }
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: joerg Date: Thu Apr 23 00:27:45 UTC 2020 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_test.h Log Message: npftest_mbufops and npftest_ifops are owned by npf_mbuf_subr.c To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/npf/npftest/libnpftest/npf_test.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_test.h diff -u src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.19 src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.20 --- src/usr.sbin/npf/npftest/libnpftest/npf_test.h:1.19 Tue Jul 23 00:52:02 2019 +++ src/usr.sbin/npf/npftest/libnpftest/npf_test.h Thu Apr 23 00:27:45 2020 @@ -84,8 +84,8 @@ struct mbuf { #define CHECK_TRUE(x) \ if (!(x)) { printf("FAIL: %s line %d\n", __func__, __LINE__); return 0; } -const npf_mbufops_t npftest_mbufops; -const npf_ifops_t npftest_ifops; +extern const npf_mbufops_t npftest_mbufops; +extern const npf_ifops_t npftest_ifops; struct mbuf * npfkern_m_get(int, int); size_t npfkern_m_length(const struct mbuf *);
CVS commit: src/usr.sbin/npf/npftest/libnpftest
Module Name:src Committed By: rmind Date: Sat May 30 21:00:31 UTC 2020 Modified Files: src/usr.sbin/npf/npftest/libnpftest: npf_test_subr.c Log Message: npftest -- npf_test_init(): add a workaround for NetBSD. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 \ src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c diff -u src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.17 src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.18 --- src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c:1.17 Sat May 30 14:16:57 2020 +++ src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c Sat May 30 21:00:31 2020 @@ -64,6 +64,13 @@ npf_test_init(int (*pton_func)(int, cons { npf_t *npf; +#ifdef __NetBSD__ + // XXX: Workaround for npf_init() + if ((npf = npf_getkernctx()) != NULL) { + npf_worker_discharge(npf); + npf_worker_sysfini(); + } +#endif npfk_sysinit(0); npf = npfk_create(0, &npftest_mbufops, &npftest_ifops, NULL); npfk_thread_register(npf);