Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf We need to have rump tests work in two modes:



details:   https://anonhg.NetBSD.org/src/rev/a20843c2c06d
branches:  trunk
changeset: 445439:a20843c2c06d
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Oct 29 15:37:06 2018 +0000

description:
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.

diffstat:

 sys/net/npf/npf_ctl.c   |  36 ++++++++++++++++--------------------
 sys/net/npf/npf_state.c |   6 +++---
 2 files changed, 19 insertions(+), 23 deletions(-)

diffs (141 lines):

diff -r 58722a427f64 -r a20843c2c06d sys/net/npf/npf_ctl.c
--- a/sys/net/npf/npf_ctl.c     Mon Oct 29 13:53:23 2018 +0000
+++ b/sys/net/npf/npf_ctl.c     Mon Oct 29 15:37:06 2018 +0000
@@ -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 @@
 #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 @@
         * 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 @@
                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 @@
        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 @@
        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 @@
        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 @@
                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);
diff -r 58722a427f64 -r a20843c2c06d sys/net/npf/npf_state.c
--- a/sys/net/npf/npf_state.c   Mon Oct 29 13:53:23 2018 +0000
+++ b/sys/net/npf/npf_state.c   Mon Oct 29 15:37:06 2018 +0000
@@ -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 @@
 /*
  * 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 @@
 #endif
 }
 
-#if defined(_NPF_TESTING) || defined(_NPF_RUMP)
+#if defined(_NPF_TESTING)
 void
 npf_state_setsampler(void (*func)(npf_state_t *, bool))
 {



Home | Main Index | Thread Index | Old Index