Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf npf_conn_conkey: adjust to return the key length...



details:   https://anonhg.NetBSD.org/src/rev/018a5ed8a47f
branches:  trunk
changeset: 330969:018a5ed8a47f
user:      rmind <rmind%NetBSD.org@localhost>
date:      Fri Jul 25 23:21:46 2014 +0000

description:
npf_conn_conkey: adjust to return the key length and add a comment
describing the key layout.

diffstat:

 sys/net/npf/npf_conn.c |  32 +++++++++++++++++++++-----------
 sys/net/npf/npf_conn.h |   4 ++--
 2 files changed, 23 insertions(+), 13 deletions(-)

diffs (103 lines):

diff -r c948319e6b05 -r 018a5ed8a47f sys/net/npf/npf_conn.c
--- a/sys/net/npf/npf_conn.c    Fri Jul 25 23:07:21 2014 +0000
+++ b/sys/net/npf/npf_conn.c    Fri Jul 25 23:21:46 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_conn.c,v 1.7 2014/07/25 23:07:21 rmind Exp $       */
+/*     $NetBSD: npf_conn.c,v 1.8 2014/07/25 23:21:46 rmind Exp $       */
 
 /*-
  * Copyright (c) 2014 Mindaugas Rasiukevicius <rmind at netbsd org>
@@ -99,7 +99,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.7 2014/07/25 23:07:21 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.8 2014/07/25 23:21:46 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -242,8 +242,10 @@
 
 /*
  * npf_conn_conkey: construct a key for the connection lookup.
+ *
+ * => Returns the key length in bytes or zero on failure.
  */
-bool
+unsigned
 npf_conn_conkey(const npf_cache_t *npc, npf_connkey_t *key, const bool forw)
 {
        const u_int alen = npc->npc_alen;
@@ -272,7 +274,7 @@
                        id[NPF_DST] = ic->icmp_id;
                        break;
                }
-               return false;
+               return 0;
        case IPPROTO_ICMPV6:
                if (npf_iscached(npc, NPC_ICMP_ID)) {
                        const struct icmp6_hdr *ic6 = npc->npc_l4.icmp6;
@@ -280,21 +282,30 @@
                        id[NPF_DST] = ic6->icmp6_id;
                        break;
                }
-               return false;
+               return 0;
        default:
                /* Unsupported protocol. */
-               return false;
+               return 0;
        }
 
-       /*
-        * Finally, construct a key formed out of 32-bit integers.
-        */
        if (__predict_true(forw)) {
                isrc = NPF_SRC, idst = NPF_DST;
        } else {
                isrc = NPF_DST, idst = NPF_SRC;
        }
 
+       /*
+        * Construct a key formed out of 32-bit integers.  The key layout:
+        *
+        * Field: | proto |  alen | src-id | dst-id | src-addr | dst-addr |
+        *        +-------+-------+--------+--------+----------+----------+
+        * Bits:  |   8   |   8   |   16   |   16   |  32-128  |  32-128  |
+        *
+        * The source and destination are inverted if they key is for the
+        * backwards stream (forw == false).  The address length depends
+        * on the 'alen' field; it is a length in bytes, either 4 or 16.
+        */
+
        key->ck_key[0] = ((uint32_t)npc->npc_proto << 16) | (alen & 0xffff);
        key->ck_key[1] = ((uint32_t)id[isrc] << 16) | id[idst];
 
@@ -308,8 +319,7 @@
                memcpy(&key->ck_key[2 + nwords], npc->npc_ips[idst], alen);
                keylen = (2 + (nwords * 2)) * sizeof(uint32_t);
        }
-       (void)keylen;
-       return true;
+       return keylen;
 }
 
 static __inline void
diff -r c948319e6b05 -r 018a5ed8a47f sys/net/npf/npf_conn.h
--- a/sys/net/npf/npf_conn.h    Fri Jul 25 23:07:21 2014 +0000
+++ b/sys/net/npf/npf_conn.h    Fri Jul 25 23:21:46 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_conn.h,v 1.4 2014/07/25 23:07:21 rmind Exp $       */
+/*     $NetBSD: npf_conn.h,v 1.5 2014/07/25 23:21:46 rmind Exp $       */
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -103,7 +103,7 @@
 void           npf_conn_tracking(bool);
 void           npf_conn_load(npf_conndb_t *, bool);
 
-bool           npf_conn_conkey(const npf_cache_t *, npf_connkey_t *, bool);
+unsigned       npf_conn_conkey(const npf_cache_t *, npf_connkey_t *, bool);
 npf_conn_t *   npf_conn_lookup(const npf_cache_t *, const int, bool *);
 npf_conn_t *   npf_conn_inspect(npf_cache_t *, const int, int *);
 npf_conn_t *   npf_conn_establish(npf_cache_t *, int, bool);



Home | Main Index | Thread Index | Old Index