Module Name: src Committed By: christos Date: Mon Oct 29 15:37:07 UTC 2018
Modified Files: src/sys/net/npf: npf_ctl.c npf_state.c Log Message: We need to have rump tests work in two modes: 1. npf unit tests. In this case only the npf subsystem is created and dictionaries are passed directly. 2. kernel system tests (like the ipsec natt test). In this case, npf is instantiated regularly as part of the kernel and dictionaries are passed via ioctl. We differentiate between the two cases by checking the "mbufops" member which is NULL, regularly and non-NULL in the npf unit tests. Previously this was done using an ifdef which obviously can't work for both cases. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/sys/net/npf/npf_ctl.c cvs rdiff -u -r1.20 -r1.21 src/sys/net/npf/npf_state.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/npf/npf_ctl.c diff -u src/sys/net/npf/npf_ctl.c:1.51 src/sys/net/npf/npf_ctl.c:1.52 --- src/sys/net/npf/npf_ctl.c:1.51 Sat Sep 29 10:41:36 2018 +++ src/sys/net/npf/npf_ctl.c Mon Oct 29 11:37:06 2018 @@ -36,7 +36,7 @@ #ifdef _KERNEL #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.51 2018/09/29 14:41:36 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.52 2018/10/29 15:37:06 christos Exp $"); #include <sys/param.h> #include <sys/conf.h> @@ -76,28 +76,24 @@ npfctl_switch(void *data) #endif static int -npf_nvlist_copyin(u_long cmd, void *data, nvlist_t **nvl) +npf_nvlist_copyin(npf_t *npf, void *data, nvlist_t **nvl) { int error = 0; -#if defined(_NPF_TESTING) || defined(_NPF_STANDALONE) - *nvl = (nvlist_t *)data; -#else - error = nvlist_copyin(data, nvl, NPF_IOCTL_DATA_LIMIT); -#endif + if (npf->mbufops != NULL) + *nvl = (nvlist_t *)data; + else + error = nvlist_copyin(data, nvl, NPF_IOCTL_DATA_LIMIT); return error; } static int -npf_nvlist_copyout(u_long cmd, void *data, nvlist_t *nvl) +npf_nvlist_copyout(npf_t *npf, void *data, nvlist_t *nvl) { int error = 0; -#if defined(_NPF_TESTING) || defined(_NPF_STANDALONE) - (void)cmd; (void)data; -#else - error = nvlist_copyout(data, nvl); -#endif + if (npf->mbufops == NULL) + error = nvlist_copyout(data, nvl); nvlist_destroy(nvl); return error; } @@ -591,14 +587,14 @@ npfctl_load(npf_t *npf, u_long cmd, void * Retrieve the configuration and check the version. * Construct a response with error reporting. */ - error = npf_nvlist_copyin(cmd, data, &request); + error = npf_nvlist_copyin(npf, data, &request); if (error) { return error; } response = nvlist_create(0); error = npfctl_load_nvlist(npf, request, response); nvlist_add_number(response, "errno", error); - return npf_nvlist_copyout(cmd, data, response); + return npf_nvlist_copyout(npf, data, response); } /* @@ -644,7 +640,7 @@ npfctl_save(npf_t *npf, u_long cmd, void goto out; } nvlist_add_bool(npf_dict, "active", npf_pfil_registered_p()); - error = npf_nvlist_copyout(cmd, data, npf_dict); + error = npf_nvlist_copyout(npf, data, npf_dict); npf_dict = NULL; out: npf_config_exit(npf); @@ -663,7 +659,7 @@ npfctl_conn_lookup(npf_t *npf, u_long cm nvlist_t *conn_data, *conn_result; int error; - error = npf_nvlist_copyin(cmd, data, &conn_data); + error = npf_nvlist_copyin(npf, data, &conn_data); if (error) { return error; } @@ -671,7 +667,7 @@ npfctl_conn_lookup(npf_t *npf, u_long cm if (error) { goto out; } - error = npf_nvlist_copyout(cmd, data, conn_result); + error = npf_nvlist_copyout(npf, data, conn_result); out: nvlist_destroy(conn_data); return error; @@ -690,7 +686,7 @@ npfctl_rule(npf_t *npf, u_long cmd, void uint32_t rcmd; int error = 0; - error = npf_nvlist_copyin(cmd, data, &npf_rule); + error = npf_nvlist_copyin(npf, data, &npf_rule); if (error) { return error; } @@ -767,7 +763,7 @@ npfctl_rule(npf_t *npf, u_long cmd, void npf_rule_free(rl); } out: - if (retdict && npf_nvlist_copyout(cmd, data, retdict) != 0) { + if (retdict && npf_nvlist_copyout(npf, data, retdict) != 0) { error = EFAULT; // copyout failure } nvlist_destroy(npf_rule); Index: src/sys/net/npf/npf_state.c diff -u src/sys/net/npf/npf_state.c:1.20 src/sys/net/npf/npf_state.c:1.21 --- src/sys/net/npf/npf_state.c:1.20 Fri Oct 26 19:35:06 2018 +++ src/sys/net/npf/npf_state.c Mon Oct 29 11:37:06 2018 @@ -33,7 +33,7 @@ #ifdef _KERNEL #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: npf_state.c,v 1.20 2018/10/26 23:35:06 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_state.c,v 1.21 2018/10/29 15:37:06 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -76,7 +76,7 @@ static u_int npf_generic_timeout[] __rea /* * State sampler for debugging. */ -#if defined(_NPF_TESTING) || defined(_NPF_RUMP) +#if defined(_NPF_TESTING) static void (*npf_state_sample)(npf_state_t *, bool) = NULL; #define NPF_STATE_SAMPLE(n, r) if (npf_state_sample) (*npf_state_sample)(n, r); #else @@ -199,7 +199,7 @@ npf_state_dump(const npf_state_t *nst) #endif } -#if defined(_NPF_TESTING) || defined(_NPF_RUMP) +#if defined(_NPF_TESTING) void npf_state_setsampler(void (*func)(npf_state_t *, bool)) {