Source-Changes-HG archive

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

[src/trunk]: src Adjust some internal NPF APIs:



details:   https://anonhg.NetBSD.org/src/rev/4b338e9d9424
branches:  trunk
changeset: 1002710:4b338e9d9424
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Aug 11 20:26:33 2019 +0000

description:
Adjust some internal NPF APIs:
* npfkern: use the npfk_ prefix.
* NPF portmap: amend the API so it could be used elsewhere.
* Make npf_connkey_t public.

diffstat:

 sys/net/npf/npf.c                               |  22 +++---
 sys/net/npf/npf_conf.c                          |   4 +-
 sys/net/npf/npf_conn.h                          |  12 +--
 sys/net/npf/npf_ctl.c                           |   4 +-
 sys/net/npf/npf_handler.c                       |   6 +-
 sys/net/npf/npf_if.c                            |   6 +-
 sys/net/npf/npf_impl.h                          |  12 ++-
 sys/net/npf/npf_inet.c                          |  40 ++++++-----
 sys/net/npf/npf_nat.c                           |  20 +++--
 sys/net/npf/npf_os.c                            |  28 ++++----
 sys/net/npf/npf_params.c                        |   6 +-
 sys/net/npf/npf_portmap.c                       |  86 +++++++++++++-----------
 sys/net/npf/npf_worker.c                        |   4 +-
 sys/net/npf/npfkern.h                           |  30 ++++----
 usr.sbin/npf/npftest/libnpftest/npf_conn_test.c |   4 +-
 usr.sbin/npf/npftest/libnpftest/npf_nat_test.c  |   2 +-
 usr.sbin/npf/npftest/libnpftest/npf_perf_test.c |   2 +-
 usr.sbin/npf/npftest/libnpftest/npf_rule_test.c |   2 +-
 usr.sbin/npf/npftest/libnpftest/npf_test_subr.c |  18 ++--
 19 files changed, 163 insertions(+), 145 deletions(-)

diffs (truncated from 913 to 300 lines):

diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf.c
--- a/sys/net/npf/npf.c Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf.c Sun Aug 11 20:26:33 2019 +0000
@@ -33,7 +33,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.39 2019/08/06 11:40:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.40 2019/08/11 20:26:33 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -49,7 +49,7 @@
 static __read_mostly npf_t *   npf_kernel_ctx = NULL;
 
 __dso_public int
-npf_sysinit(unsigned nworkers)
+npfk_sysinit(unsigned nworkers)
 {
        npf_bpf_sysinit();
        npf_tableset_sysinit();
@@ -58,7 +58,7 @@
 }
 
 __dso_public void
-npf_sysfini(void)
+npfk_sysfini(void)
 {
        npf_worker_sysfini();
        npf_nat_sysfini();
@@ -67,7 +67,7 @@
 }
 
 __dso_public npf_t *
-npf_create(int flags, const npf_mbufops_t *mbufops, const npf_ifops_t *ifops)
+npfk_create(int flags, const npf_mbufops_t *mbufops, const npf_ifops_t *ifops)
 {
        npf_t *npf;
 
@@ -94,7 +94,7 @@
 }
 
 __dso_public void
-npf_destroy(npf_t *npf)
+npfk_destroy(npf_t *npf)
 {
        /*
         * Destroy the current configuration.  Note: at this point all
@@ -117,25 +117,25 @@
 }
 
 __dso_public int
-npf_load(npf_t *npf, void *config_ref, npf_error_t *err)
+npfk_load(npf_t *npf, void *config_ref, npf_error_t *err)
 {
        return npfctl_load(npf, 0, config_ref);
 }
 
 __dso_public void
-npf_gc(npf_t *npf)
+npfk_gc(npf_t *npf)
 {
        npf_conn_worker(npf);
 }
 
 __dso_public void
-npf_thread_register(npf_t *npf)
+npfk_thread_register(npf_t *npf)
 {
        pserialize_register(npf->qsbr);
 }
 
 __dso_public void
-npf_thread_unregister(npf_t *npf)
+npfk_thread_unregister(npf_t *npf)
 {
        pserialize_perform(npf->qsbr);
        pserialize_unregister(npf->qsbr);
@@ -198,14 +198,14 @@
  */
 
 __dso_public void
-npf_stats(npf_t *npf, uint64_t *buf)
+npfk_stats(npf_t *npf, uint64_t *buf)
 {
        memset(buf, 0, NPF_STATS_SIZE);
        percpu_foreach(npf->stats_percpu, npf_stats_collect, buf);
 }
 
 __dso_public void
-npf_stats_clear(npf_t *npf)
+npfk_stats_clear(npf_t *npf)
 {
        percpu_foreach(npf->stats_percpu, npf_stats_clear_cb, NULL);
 }
diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf_conf.c
--- a/sys/net/npf/npf_conf.c    Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf_conf.c    Sun Aug 11 20:26:33 2019 +0000
@@ -47,7 +47,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_conf.c,v 1.13 2019/07/23 00:52:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conf.c,v 1.14 2019/08/11 20:26:33 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -169,7 +169,7 @@
        /* Synchronise: drain all references. */
        pserialize_perform(npf->qsbr);
        if (flush) {
-               npf_portmap_flush(npf);
+               npf_portmap_flush(npf->portmap);
                npf_ifmap_flush(npf);
        }
 
diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf_conn.h
--- a/sys/net/npf/npf_conn.h    Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf_conn.h    Sun Aug 11 20:26:33 2019 +0000
@@ -38,8 +38,6 @@
 
 #include "npf_impl.h"
 
-typedef struct npf_connkey npf_connkey_t;
-
 #if defined(__NPF_CONN_PRIVATE)
 
 /*
@@ -91,6 +89,8 @@
        uint32_t                c_keys[];
 };
 
+#endif
+
 /*
  * Connection key interface.
  *
@@ -104,10 +104,10 @@
 #define        NPF_CONNKEY_ALEN(key)   ((key)->ck_key[0] & 0xffff)
 #define        NPF_CONNKEY_LEN(key)    (8 + (NPF_CONNKEY_ALEN(key) * 2))
 
-struct npf_connkey {
+typedef struct npf_connkey {
        /* Warning: ck_key has a variable length -- see above. */
        uint32_t                ck_key[NPF_CONNKEY_MAXWORDS];
-};
+} npf_connkey_t;
 
 unsigned       npf_conn_conkey(const npf_cache_t *, npf_connkey_t *, bool);
 npf_connkey_t *        npf_conn_getforwkey(npf_conn_t *);
@@ -119,8 +119,6 @@
 nvlist_t *     npf_connkey_export(const npf_connkey_t *);
 void           npf_connkey_print(const npf_connkey_t *);
 
-#endif
-
 /*
  * Connection tracking interface.
  */
@@ -140,7 +138,7 @@
 void           npf_conn_setpass(npf_conn_t *, const npf_match_info_t *,
                    npf_rproc_t *);
 int            npf_conn_setnat(const npf_cache_t *, npf_conn_t *,
-                   npf_nat_t *, u_int);
+                   npf_nat_t *, unsigned);
 npf_nat_t *    npf_conn_getnat(npf_conn_t *, const int, bool *);
 bool           npf_conn_expired(npf_t *, const npf_conn_t *, uint64_t);
 void           npf_conn_remove(npf_conndb_t *, npf_conn_t *);
diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf_ctl.c
--- a/sys/net/npf/npf_ctl.c     Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf_ctl.c     Sun Aug 11 20:26:33 2019 +0000
@@ -36,7 +36,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.54 2019/07/23 00:52:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.55 2019/08/11 20:26:33 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -121,7 +121,7 @@
                val = (int)nvlist_get_number(params, name);
                if (set) {
                        /* Actually set the parameter. */
-                       error = npf_param_set(npf, name, val);
+                       error = npfk_param_set(npf, name, val);
                        KASSERT(error == 0);
                        continue;
                }
diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf_handler.c
--- a/sys/net/npf/npf_handler.c Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf_handler.c Sun Aug 11 20:26:33 2019 +0000
@@ -35,7 +35,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_handler.c,v 1.46 2019/07/23 00:52:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_handler.c,v 1.47 2019/08/11 20:26:33 rmind Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -112,12 +112,12 @@
 }
 
 /*
- * npf_packet_handler: main packet handling routine for layer 3.
+ * npfk_packet_handler: main packet handling routine for layer 3.
  *
  * Note: packet flow and inspection logic is in strict order.
  */
 __dso_public int
-npf_packet_handler(npf_t *npf, struct mbuf **mp, ifnet_t *ifp, int di)
+npfk_packet_handler(npf_t *npf, struct mbuf **mp, ifnet_t *ifp, int di)
 {
        nbuf_t nbuf;
        npf_cache_t npc;
diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf_if.c
--- a/sys/net/npf/npf_if.c      Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf_if.c      Sun Aug 11 20:26:33 2019 +0000
@@ -44,7 +44,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.9 2018/09/29 14:41:36 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.10 2019/08/11 20:26:33 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -181,7 +181,7 @@
 }
 
 __dso_public void
-npf_ifmap_attach(npf_t *npf, ifnet_t *ifp)
+npfk_ifmap_attach(npf_t *npf, ifnet_t *ifp)
 {
        const npf_ifops_t *ifops = npf->ifops;
        u_int i;
@@ -193,7 +193,7 @@
 }
 
 __dso_public void
-npf_ifmap_detach(npf_t *npf, ifnet_t *ifp)
+npfk_ifmap_detach(npf_t *npf, ifnet_t *ifp)
 {
        /* Diagnostic. */
        npf_config_enter(npf);
diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf_impl.h
--- a/sys/net/npf/npf_impl.h    Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf_impl.h    Sun Aug 11 20:26:33 2019 +0000
@@ -185,7 +185,6 @@
        NPF_PARAMS_CONNDB = 0,
        NPF_PARAMS_GENERIC_STATE,
        NPF_PARAMS_TCP_STATE,
-       NPF_PARAMS_PORTMAP,
        NPF_PARAMS_COUNT
 } npf_paramgroup_t;
 
@@ -461,10 +460,13 @@
 void           npf_portmap_init(npf_t *);
 void           npf_portmap_fini(npf_t *);
 
-in_port_t      npf_portmap_get(npf_t *, int, const npf_addr_t *);
-bool           npf_portmap_take(npf_t *, int, const npf_addr_t *, in_port_t);
-void           npf_portmap_put(npf_t *, int, const npf_addr_t *, in_port_t);
-void           npf_portmap_flush(npf_t *);
+npf_portmap_t *        npf_portmap_create(int, int);
+void           npf_portmap_destroy(npf_portmap_t *);
+
+in_port_t      npf_portmap_get(npf_portmap_t *, int, const npf_addr_t *);
+bool           npf_portmap_take(npf_portmap_t *, int, const npf_addr_t *, in_port_t);
+void           npf_portmap_put(npf_portmap_t *, int, const npf_addr_t *, in_port_t);
+void           npf_portmap_flush(npf_portmap_t *);
 
 /* NAT. */
 void           npf_nat_sysinit(void);
diff -r 4e4b81a64dd3 -r 4b338e9d9424 sys/net/npf/npf_inet.c
--- a/sys/net/npf/npf_inet.c    Sun Aug 11 20:25:14 2019 +0000
+++ b/sys/net/npf/npf_inet.c    Sun Aug 11 20:26:33 2019 +0000
@@ -38,7 +38,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_inet.c,v 1.54 2019/07/23 00:52:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_inet.c,v 1.55 2019/08/11 20:26:34 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -712,7 +712,9 @@
        const npf_addr_t *oaddr = npc->npc_ips[which];
        const int proto = npc->npc_proto;
        const int alen = npc->npc_alen;
-       uint16_t *ocksum;
+       uint16_t cksum, *ocksum;
+       struct tcphdr *th;
+       struct udphdr *uh;
        in_port_t oport;
 
        KASSERT(npf_iscached(npc, NPC_LAYER4));
@@ -729,41 +731,43 @@
                KASSERT(npf_iscached(npc, NPC_IP6));



Home | Main Index | Thread Index | Old Index