Source-Changes-HG archive

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

[src/trunk]: src NPF: add nbuf_t * into npf_cache_t and remove unnecessary ca...



details:   https://anonhg.NetBSD.org/src/rev/042df3aa0508
branches:  trunk
changeset: 797506:042df3aa0508
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Jul 20 00:37:41 2014 +0000

description:
NPF: add nbuf_t * into npf_cache_t and remove unnecessary carrying by argument.

diffstat:

 sys/net/npf/npf.h                                |  80 ++++++++++++-----------
 sys/net/npf/npf_alg.c                            |  16 ++--
 sys/net/npf/npf_alg_icmp.c                       |  38 ++++++-----
 sys/net/npf/npf_bpf.c                            |   8 +-
 sys/net/npf/npf_conn.c                           |  22 +++---
 sys/net/npf/npf_conn.h                           |   9 +-
 sys/net/npf/npf_ext_log.c                        |   8 +-
 sys/net/npf/npf_ext_normalize.c                  |  10 +-
 sys/net/npf/npf_ext_rndblock.c                   |   6 +-
 sys/net/npf/npf_handler.c                        |  31 +++++----
 sys/net/npf/npf_impl.h                           |  39 +++++------
 sys/net/npf/npf_inet.c                           |  18 +++--
 sys/net/npf/npf_nat.c                            |  31 ++++----
 sys/net/npf/npf_rproc.c                          |  12 +-
 sys/net/npf/npf_ruleset.c                        |  13 +--
 sys/net/npf/npf_sendpkt.c                        |  12 +-
 sys/net/npf/npf_state.c                          |  13 +--
 sys/net/npf/npf_state_tcp.c                      |  15 ++--
 usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c   |   5 +-
 usr.sbin/npf/npftest/libnpftest/npf_nat_test.c   |   5 +-
 usr.sbin/npf/npftest/libnpftest/npf_rule_test.c  |   7 +-
 usr.sbin/npf/npftest/libnpftest/npf_state_test.c |   9 +-
 22 files changed, 211 insertions(+), 196 deletions(-)

diffs (truncated from 1348 to 300 lines):

diff -r 86231c6451a8 -r 042df3aa0508 sys/net/npf/npf.h
--- a/sys/net/npf/npf.h Sat Jul 19 22:08:54 2014 +0000
+++ b/sys/net/npf/npf.h Sun Jul 20 00:37:41 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf.h,v 1.43 2014/07/19 18:24:16 rmind Exp $   */
+/*     $NetBSD: npf.h,v 1.44 2014/07/20 00:37:41 rmind Exp $   */
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -78,9 +78,6 @@
 #define        NPF_EXT_MODULE(name, req)       \
     MODULE(MODULE_CLASS_MISC, name, (sizeof(req) - 1) ? ("npf," req) : "npf")
 
-/*
- * Packet information cache.
- */
 #include <net/if.h>
 #include <netinet/ip.h>
 #include <netinet/ip6.h>
@@ -89,6 +86,43 @@
 #include <netinet/ip_icmp.h>
 #include <netinet/icmp6.h>
 
+/*
+ * Network buffer interface.
+ */
+
+#define        NBUF_DATAREF_RESET      0x01
+
+typedef struct {
+       struct mbuf *   nb_mbuf0;
+       struct mbuf *   nb_mbuf;
+       void *          nb_nptr;
+       const ifnet_t * nb_ifp;
+       unsigned        nb_ifid;
+       int             nb_flags;
+} nbuf_t;
+
+void           nbuf_init(nbuf_t *, struct mbuf *, const ifnet_t *);
+void           nbuf_reset(nbuf_t *);
+struct mbuf *  nbuf_head_mbuf(nbuf_t *);
+
+bool           nbuf_flag_p(const nbuf_t *, int);
+void           nbuf_unset_flag(nbuf_t *, int);
+
+void *         nbuf_dataptr(nbuf_t *);
+size_t         nbuf_offset(const nbuf_t *);
+void *         nbuf_advance(nbuf_t *, size_t, size_t);
+
+void *         nbuf_ensure_contig(nbuf_t *, size_t);
+void *         nbuf_ensure_writable(nbuf_t *, size_t);
+
+bool           nbuf_cksum_barrier(nbuf_t *, int);
+int            nbuf_add_tag(nbuf_t *, uint32_t, uint32_t);
+int            nbuf_find_tag(nbuf_t *, uint32_t, void **);
+
+/*
+ * Packet information cache.
+ */
+
 #define        NPC_IP4         0x01    /* Indicates IPv4 header. */
 #define        NPC_IP6         0x02    /* Indicates IPv6 header. */
 #define        NPC_IPFRAG      0x04    /* IPv4/IPv6 fragment. */
@@ -104,8 +138,9 @@
 #define        NPC_IP46        (NPC_IP4|NPC_IP6)
 
 typedef struct {
-       /* Information flags. */
+       /* Information flags and the nbuf. */
        uint32_t                npc_info;
+       nbuf_t *                npc_nbuf;
 
        /*
         * Pointers to the IP source and destination addresses,
@@ -144,39 +179,6 @@
 #define        NPF_DST         1
 
 /*
- * Network buffer interface.
- */
-
-#define        NBUF_DATAREF_RESET      0x01
-
-typedef struct {
-       struct mbuf *   nb_mbuf0;
-       struct mbuf *   nb_mbuf;
-       void *          nb_nptr;
-       const ifnet_t * nb_ifp;
-       unsigned        nb_ifid;
-       int             nb_flags;
-} nbuf_t;
-
-void           nbuf_init(nbuf_t *, struct mbuf *, const ifnet_t *);
-void           nbuf_reset(nbuf_t *);
-struct mbuf *  nbuf_head_mbuf(nbuf_t *);
-
-bool           nbuf_flag_p(const nbuf_t *, int);
-void           nbuf_unset_flag(nbuf_t *, int);
-
-void *         nbuf_dataptr(nbuf_t *);
-size_t         nbuf_offset(const nbuf_t *);
-void *         nbuf_advance(nbuf_t *, size_t, size_t);
-
-void *         nbuf_ensure_contig(nbuf_t *, size_t);
-void *         nbuf_ensure_writable(nbuf_t *, size_t);
-
-bool           nbuf_cksum_barrier(nbuf_t *, int);
-int            nbuf_add_tag(nbuf_t *, uint32_t, uint32_t);
-int            nbuf_find_tag(nbuf_t *, uint32_t, void **);
-
-/*
  * NPF extensions and rule procedure interface.
  */
 
@@ -190,7 +192,7 @@
        void *          ctx;
        int             (*ctor)(npf_rproc_t *, prop_dictionary_t);
        void            (*dtor)(npf_rproc_t *, void *);
-       bool            (*proc)(npf_cache_t *, nbuf_t *, void *, int *);
+       bool            (*proc)(npf_cache_t *, void *, int *);
 } npf_ext_ops_t;
 
 void *         npf_ext_register(const char *, const npf_ext_ops_t *);
diff -r 86231c6451a8 -r 042df3aa0508 sys/net/npf/npf_alg.c
--- a/sys/net/npf/npf_alg.c     Sat Jul 19 22:08:54 2014 +0000
+++ b/sys/net/npf/npf_alg.c     Sun Jul 20 00:37:41 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_alg.c,v 1.13 2014/07/19 18:24:16 rmind Exp $       */
+/*     $NetBSD: npf_alg.c,v 1.14 2014/07/20 00:37:41 rmind Exp $       */
 
 /*-
  * Copyright (c) 2010-2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_alg.c,v 1.13 2014/07/19 18:24:16 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_alg.c,v 1.14 2014/07/20 00:37:41 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -189,7 +189,7 @@
  * npf_alg_match: call ALG matching inspectors, determine if any ALG matches.
  */
 bool
-npf_alg_match(npf_cache_t *npc, nbuf_t *nbuf, npf_nat_t *nt, int di)
+npf_alg_match(npf_cache_t *npc, npf_nat_t *nt, int di)
 {
        bool match = false;
        int s;
@@ -198,7 +198,7 @@
        for (u_int i = 0; i < alg_count; i++) {
                const npfa_funcs_t *f = &alg_funcs[i];
 
-               if (f->match && f->match(npc, nbuf, nt, di)) {
+               if (f->match && f->match(npc, nt, di)) {
                        match = true;
                        break;
                }
@@ -211,7 +211,7 @@
  * npf_alg_exec: execute ALG hooks for translation.
  */
 void
-npf_alg_exec(npf_cache_t *npc, nbuf_t *nbuf, npf_nat_t *nt, bool forw)
+npf_alg_exec(npf_cache_t *npc, npf_nat_t *nt, bool forw)
 {
        int s;
 
@@ -220,14 +220,14 @@
                const npfa_funcs_t *f = &alg_funcs[i];
 
                if (f->translate) {
-                       f->translate(npc, nbuf, nt, forw);
+                       f->translate(npc, nt, forw);
                }
        }
        pserialize_read_exit(s);
 }
 
 npf_conn_t *
-npf_alg_conn(npf_cache_t *npc, nbuf_t *nbuf, int di)
+npf_alg_conn(npf_cache_t *npc, int di)
 {
        npf_conn_t *con = NULL;
        int s;
@@ -238,7 +238,7 @@
 
                if (!f->inspect)
                        continue;
-               if ((con = f->inspect(npc, nbuf, di)) != NULL)
+               if ((con = f->inspect(npc, di)) != NULL)
                        break;
        }
        pserialize_read_exit(s);
diff -r 86231c6451a8 -r 042df3aa0508 sys/net/npf/npf_alg_icmp.c
--- a/sys/net/npf/npf_alg_icmp.c        Sat Jul 19 22:08:54 2014 +0000
+++ b/sys/net/npf/npf_alg_icmp.c        Sun Jul 20 00:37:41 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_alg_icmp.c,v 1.22 2014/07/19 18:24:16 rmind Exp $  */
+/*     $NetBSD: npf_alg_icmp.c,v 1.23 2014/07/20 00:37:41 rmind Exp $  */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_alg_icmp.c,v 1.22 2014/07/19 18:24:16 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_alg_icmp.c,v 1.23 2014/07/20 00:37:41 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/module.h>
@@ -71,7 +71,7 @@
  * our ALG with the NAT entry.
  */
 static bool
-npfa_icmp_match(npf_cache_t *npc, nbuf_t *nbuf, npf_nat_t *nt, int di)
+npfa_icmp_match(npf_cache_t *npc, npf_nat_t *nt, int di)
 {
        const int proto = npc->npc_proto;
        const struct ip *ip = npc->npc_ip.v4;
@@ -121,8 +121,9 @@
  */
 
 static bool
-npfa_icmp4_inspect(const int type, npf_cache_t *npc, nbuf_t *nbuf)
+npfa_icmp4_inspect(const int type, npf_cache_t *npc)
 {
+       nbuf_t *nbuf = npc->npc_nbuf;
        u_int offby;
 
        /* Per RFC 792. */
@@ -139,7 +140,7 @@
                if (!nbuf_advance(nbuf, offsetof(struct icmp, icmp_ip), 0)) {
                        return false;
                }
-               return (npf_cache_all(npc, nbuf) & NPC_LAYER4) != 0;
+               return (npf_cache_all(npc) & NPC_LAYER4) != 0;
 
        case ICMP_ECHOREPLY:
        case ICMP_ECHO:
@@ -161,8 +162,9 @@
 }
 
 static bool
-npfa_icmp6_inspect(const int type, npf_cache_t *npc, nbuf_t *nbuf)
+npfa_icmp6_inspect(const int type, npf_cache_t *npc)
 {
+       nbuf_t *nbuf = npc->npc_nbuf;
        u_int offby;
 
        /* Per RFC 4443. */
@@ -178,7 +180,7 @@
                if (!nbuf_advance(nbuf, sizeof(struct icmp6_hdr), 0)) {
                        return false;
                }
-               return (npf_cache_all(npc, nbuf) & NPC_LAYER4) != 0;
+               return (npf_cache_all(npc) & NPC_LAYER4) != 0;
 
        case ICMP6_ECHO_REQUEST:
        case ICMP6_ECHO_REPLY:
@@ -201,8 +203,9 @@
  * => Returns true if "enpc" is filled.
  */
 static bool
-npfa_icmp_inspect(npf_cache_t *npc, nbuf_t *nbuf, npf_cache_t *enpc)
+npfa_icmp_inspect(npf_cache_t *npc, npf_cache_t *enpc)
 {
+       nbuf_t *nbuf = npc->npc_nbuf;
        bool ret;
 
        KASSERT(npf_iscached(npc, NPC_IP46));
@@ -213,6 +216,7 @@
        if (!nbuf_advance(nbuf, npc->npc_hlen, 0)) {
                return false;
        }
+       enpc->npc_nbuf = nbuf;
        enpc->npc_info = 0;
 
        /*
@@ -221,10 +225,10 @@
         */
        if (npf_iscached(npc, NPC_IP4)) {
                const struct icmp *ic = npc->npc_l4.icmp;
-               ret = npfa_icmp4_inspect(ic->icmp_type, enpc, nbuf);
+               ret = npfa_icmp4_inspect(ic->icmp_type, enpc);
        } else if (npf_iscached(npc, NPC_IP6)) {
                const struct icmp6_hdr *ic6 = npc->npc_l4.icmp6;
-               ret = npfa_icmp6_inspect(ic6->icmp6_type, enpc, nbuf);
+               ret = npfa_icmp6_inspect(ic6->icmp6_type, enpc);
        } else {
                ret = false;
        }
@@ -243,14 +247,14 @@
 }
 
 static npf_conn_t *
-npfa_icmp_conn(npf_cache_t *npc, nbuf_t *nbuf, int di)
+npfa_icmp_conn(npf_cache_t *npc, int di)
 {



Home | Main Index | Thread Index | Old Index