Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd/ipf/netinet Back out my last change, which ...
details: https://anonhg.NetBSD.org/src/rev/66da9dea4a9b
branches: trunk
changeset: 783811:66da9dea4a9b
user: christos <christos%NetBSD.org@localhost>
date: Wed Jan 09 13:23:20 2013 +0000
description:
Back out my last change, which was a partial fix for hash code computation problems.
Apply Darren's more complete reworking of hash code computation.
Ensure that the struct containing the red-black tree head is properly initialized.
>From Geoff Adams
diffstat:
sys/external/bsd/ipf/netinet/fil.c | 5 +-
sys/external/bsd/ipf/netinet/ip_compat.h | 3 +-
sys/external/bsd/ipf/netinet/ip_nat.c | 187 +++++++++++++-----------------
sys/external/bsd/ipf/netinet/ip_nat.h | 25 +++-
sys/external/bsd/ipf/netinet/ip_nat6.c | 74 ++++++-----
sys/external/bsd/ipf/netinet/ip_state.c | 10 +-
sys/external/bsd/ipf/netinet/ipf_rb.h | 3 +-
7 files changed, 151 insertions(+), 156 deletions(-)
diffs (truncated from 591 to 300 lines):
diff -r 25c194971fcd -r 66da9dea4a9b sys/external/bsd/ipf/netinet/fil.c
--- a/sys/external/bsd/ipf/netinet/fil.c Wed Jan 09 08:49:44 2013 +0000
+++ b/sys/external/bsd/ipf/netinet/fil.c Wed Jan 09 13:23:20 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fil.c,v 1.7 2012/12/20 21:42:27 christos Exp $ */
+/* $NetBSD: fil.c,v 1.8 2013/01/09 13:23:20 christos Exp $ */
/*
* Copyright (C) 2012 by Darren Reed.
@@ -138,7 +138,7 @@
#if !defined(lint)
#if defined(__NetBSD__)
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.7 2012/12/20 21:42:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fil.c,v 1.8 2013/01/09 13:23:20 christos Exp $");
#else
static const char sccsid[] = "@(#)fil.c 1.36 6/5/96 (C) 1993-2000 Darren Reed";
static const char rcsid[] = "@(#)Id: fil.c,v 1.1.1.2 2012/07/22 13:45:07 darrenr Exp $";
@@ -9664,6 +9664,7 @@
void
ipf_rb_ht_init(host_track_t *head)
{
+ memset(head, 0, sizeof(*head));
RBI_INIT(ipf_rb, &head->ht_root);
}
diff -r 25c194971fcd -r 66da9dea4a9b sys/external/bsd/ipf/netinet/ip_compat.h
--- a/sys/external/bsd/ipf/netinet/ip_compat.h Wed Jan 09 08:49:44 2013 +0000
+++ b/sys/external/bsd/ipf/netinet/ip_compat.h Wed Jan 09 13:23:20 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_compat.h,v 1.5 2012/12/20 21:42:28 christos Exp $ */
+/* $NetBSD: ip_compat.h,v 1.6 2013/01/09 13:23:20 christos Exp $ */
/*
* Copyright (C) 2012 by Darren Reed.
@@ -928,6 +928,7 @@
# if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 499004900))
# define POLLWAKEUP(x) selnotify(softc->ipf_selwait+x, 0, 0)
# endif
+# define ASSERT(x) KASSERT(x)
typedef struct mbuf mb_t;
# endif /* _KERNEL */
# if (NetBSD <= 1991011) && (NetBSD >= 199606)
diff -r 25c194971fcd -r 66da9dea4a9b sys/external/bsd/ipf/netinet/ip_nat.c
--- a/sys/external/bsd/ipf/netinet/ip_nat.c Wed Jan 09 08:49:44 2013 +0000
+++ b/sys/external/bsd/ipf/netinet/ip_nat.c Wed Jan 09 13:23:20 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_nat.c,v 1.8 2013/01/05 16:34:43 christos Exp $ */
+/* $NetBSD: ip_nat.c,v 1.9 2013/01/09 13:23:20 christos Exp $ */
/*
* Copyright (C) 2012 by Darren Reed.
@@ -113,7 +113,7 @@
#if !defined(lint)
#if defined(__NetBSD__)
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_nat.c,v 1.8 2013/01/05 16:34:43 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_nat.c,v 1.9 2013/01/09 13:23:20 christos Exp $");
#else
static const char sccsid[] = "@(#)ip_nat.c 1.11 6/5/96 (C) 1995 Darren Reed";
static const char rcsid[] = "@(#)Id: ip_nat.c,v 1.1.1.2 2012/07/22 13:45:27 darrenr Exp";
@@ -226,7 +226,6 @@
static int ipf_nat_builddivertmp(ipf_nat_softc_t *, ipnat_t *);
static int ipf_nat_clearlist(ipf_main_softc_t *, ipf_nat_softc_t *);
static int ipf_nat_cmp_rules(ipnat_t *, ipnat_t *);
-static void ipf_nat_compute_hashes(nat_t *nat);
static int ipf_nat_decap(fr_info_t *, nat_t *);
static void ipf_nat_delrule(ipf_main_softc_t *, ipf_nat_softc_t *,
ipnat_t *, int);
@@ -2255,26 +2254,13 @@
{
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
int madeorphan = 0, removed = 0;
- u_int hv0;
- u_int hv1;
+ u_int bkt;
nat_stat_side_t *nss;
struct ipnat *ipn;
if (logtype != 0 && softn->ipf_nat_logging != 0)
ipf_nat_log(softc, softn, nat, logtype);
- /* Get the hash values, swapped as necessary. */
- hv0 = nat->nat_hv[0] % softn->ipf_nat_table_sz;
- hv1 = nat->nat_hv[1] % softn->ipf_nat_table_sz;
-
- if (nat->nat_dir == NAT_INBOUND || nat->nat_dir == NAT_DIVERTIN) {
- u_int swap;
-
- swap = hv0;
- hv0 = hv1;
- hv1 = swap;
- }
-
/*
* Take it as a general indication that all the pointers are set if
* nat_pnext is set.
@@ -2282,15 +2268,19 @@
if (nat->nat_pnext != NULL) {
removed = 1;
+ bkt = nat->nat_hv[0] % softn->ipf_nat_table_sz;
nss = &softn->ipf_nat_stats.ns_side[0];
- nss->ns_bucketlen[hv0]--;
- if (nss->ns_bucketlen[hv0] == 0) {
+ ASSERT(nss->ns_bucketlen[bkt] > 0);
+ nss->ns_bucketlen[bkt]--;
+ if (nss->ns_bucketlen[bkt] == 0) {
nss->ns_inuse--;
}
+ bkt = nat->nat_hv[1] % softn->ipf_nat_table_sz;
nss = &softn->ipf_nat_stats.ns_side[1];
- nss->ns_bucketlen[hv1]--;
- if (nss->ns_bucketlen[hv1] == 0) {
+ ASSERT(nss->ns_bucketlen[bkt] > 0);
+ nss->ns_bucketlen[bkt]--;
+ if (nss->ns_bucketlen[bkt] == 0) {
nss->ns_inuse--;
}
@@ -3350,68 +3340,6 @@
/* ------------------------------------------------------------------------ */
-/* Function: ipf_nat_compute_hashes */
-/* Parameters: nat(I) - pointer to NAT structure */
-/* Write Lock: ipf_nat */
-/* */
-/* Compute and set the values for nat->nat_hv[0] and nat->nat_hv[1] */
-/* ------------------------------------------------------------------------ */
-void
-ipf_nat_compute_hashes(nat_t *nat)
-{
- u_int hv0, hv1;
- u_int sport, dport;
-
- if ((nat->nat_flags & (SI_W_SPORT|SI_W_DPORT)) == 0) {
- if ((nat->nat_flags & IPN_TCPUDP) != 0) {
- sport = nat->nat_osport;
- dport = nat->nat_odport;
- } else if ((nat->nat_flags & IPN_ICMPQUERY) != 0) {
- sport = 0;
- dport = nat->nat_oicmpid;
- } else {
- sport = 0;
- dport = 0;
- }
- hv0 = NAT_HASH_FN(nat->nat_osrcaddr, sport, 0xffffffff);
- hv0 = NAT_HASH_FN(nat->nat_odstaddr, hv0 + dport, 0xffffffff);
- /*
- * TRACE nat_osrcaddr, nat_osport, nat_odstaddr,
- * nat_odport, hv0
- */
-
- if ((nat->nat_flags & IPN_TCPUDP) != 0) {
- sport = nat->nat_nsport;
- dport = nat->nat_ndport;
- } else if ((nat->nat_flags & IPN_ICMPQUERY) != 0) {
- sport = 0;
- dport = nat->nat_nicmpid;
- } else {
- sport = 0;
- dport = 0;
- }
- hv1 = NAT_HASH_FN(nat->nat_nsrcaddr, sport, 0xffffffff);
- hv1 = NAT_HASH_FN(nat->nat_ndstaddr, hv1 + dport, 0xffffffff);
- /*
- * TRACE nat_nsrcaddr, nat_nsport, nat_ndstaddr,
- * nat_ndport, hv1
- */
- } else {
- hv0 = NAT_HASH_FN(nat->nat_osrcaddr, 0, 0xffffffff);
- hv0 = NAT_HASH_FN(nat->nat_odstaddr, hv0, 0xffffffff);
- /* TRACE nat_osrcaddr, nat_odstaddr, hv0 */
-
- hv1 = NAT_HASH_FN(nat->nat_nsrcaddr, 0, 0xffffffff);
- hv1 = NAT_HASH_FN(nat->nat_ndstaddr, hv1, 0xffffffff);
- /* TRACE nat_nsrcaddr, nat_ndstaddr, hv1 */
- }
-
- nat->nat_hv[0] = hv0;
- nat->nat_hv[1] = hv1;
-}
-
-
-/* ------------------------------------------------------------------------ */
/* Function: ipf_nat_insert */
/* Returns: int - 0 == sucess, -1 == failure */
/* Parameters: softc(I) - pointer to soft context main structure */
@@ -3425,6 +3353,8 @@
int
ipf_nat_insert(ipf_main_softc_t *softc, ipf_nat_softc_t *softn, nat_t *nat)
{
+ u_int hv0, hv1;
+ u_int sp, dp;
ipnat_t *in;
int ret;
@@ -3432,7 +3362,57 @@
* Try and return an error as early as possible, so calculate the hash
* entry numbers first and then proceed.
*/
- ipf_nat_compute_hashes(nat);
+ if ((nat->nat_flags & (SI_W_SPORT|SI_W_DPORT)) == 0) {
+ if ((nat->nat_flags & IPN_TCPUDP) != 0) {
+ sp = nat->nat_osport;
+ dp = nat->nat_odport;
+ } else if ((nat->nat_flags & IPN_ICMPQUERY) != 0) {
+ sp = 0;
+ dp = nat->nat_oicmpid;
+ } else {
+ sp = 0;
+ dp = 0;
+ }
+ hv0 = NAT_HASH_FN(nat->nat_osrcaddr, sp, 0xffffffff);
+ hv0 = NAT_HASH_FN(nat->nat_odstaddr, hv0 + dp, 0xffffffff);
+ /*
+ * TRACE nat_osrcaddr, nat_osport, nat_odstaddr,
+ * nat_odport, hv0
+ */
+
+ if ((nat->nat_flags & IPN_TCPUDP) != 0) {
+ sp = nat->nat_nsport;
+ dp = nat->nat_ndport;
+ } else if ((nat->nat_flags & IPN_ICMPQUERY) != 0) {
+ sp = 0;
+ dp = nat->nat_nicmpid;
+ } else {
+ sp = 0;
+ dp = 0;
+ }
+ hv1 = NAT_HASH_FN(nat->nat_nsrcaddr, sp, 0xffffffff);
+ hv1 = NAT_HASH_FN(nat->nat_ndstaddr, hv1 + dp, 0xffffffff);
+ /*
+ * TRACE nat_nsrcaddr, nat_nsport, nat_ndstaddr,
+ * nat_ndport, hv1
+ */
+ } else {
+ hv0 = NAT_HASH_FN(nat->nat_osrcaddr, 0, 0xffffffff);
+ hv0 = NAT_HASH_FN(nat->nat_odstaddr, hv0, 0xffffffff);
+ /* TRACE nat_osrcaddr, nat_odstaddr, hv0 */
+
+ hv1 = NAT_HASH_FN(nat->nat_nsrcaddr, 0, 0xffffffff);
+ hv1 = NAT_HASH_FN(nat->nat_ndstaddr, hv1, 0xffffffff);
+ /* TRACE nat_nsrcaddr, nat_ndstaddr, hv1 */
+ }
+
+ if ((nat->nat_dir & NAT_OUTBOUND) == NAT_OUTBOUND) {
+ nat->nat_hv[0] = hv0;
+ nat->nat_hv[1] = hv1;
+ } else {
+ nat->nat_hv[0] = hv1;
+ nat->nat_hv[1] = hv0;
+ }
MUTEX_INIT(&nat->nat_lock, "nat entry lock");
@@ -3473,9 +3453,11 @@
/* ------------------------------------------------------------------------ */
/* Function: ipf_nat_hashtab_add */
+/* Returns: int - 0 == sucess, -1 == failure */
/* Parameters: softc(I) - pointer to soft context main structure */
/* softn(I) - pointer to NAT context structure */
/* nat(I) - pointer to NAT structure */
+/* Write Lock: ipf_nat */
/* */
/* Handle the insertion of a NAT entry into the table/list. */
/* ------------------------------------------------------------------------ */
@@ -3489,14 +3471,6 @@
hv0 = nat->nat_hv[0] % softn->ipf_nat_table_sz;
hv1 = nat->nat_hv[1] % softn->ipf_nat_table_sz;
- if (nat->nat_dir == NAT_INBOUND || nat->nat_dir == NAT_DIVERTIN) {
- u_int swap;
-
- swap = hv0;
- hv0 = hv1;
- hv1 = swap;
- }
-
if (softn->ipf_nat_stats.ns_side[0].ns_bucketlen[hv0] >=
softn->ipf_nat_maxbucket) {
DT1(ns_bucket_max_0, int,
@@ -4298,12 +4272,15 @@
nat->nat_hnext[0]->nat_phnext[0] = nat->nat_phnext[0];
*nat->nat_phnext[0] = nat->nat_hnext[0];
hv0 = nat->nat_hv[0] % softn->ipf_nat_table_sz;
+ hv1 = nat->nat_hv[1] % softn->ipf_nat_table_sz;
+
+ ASSERT(nsp->ns_side[0].ns_bucketlen[hv0] > 0);
nsp->ns_side[0].ns_bucketlen[hv0]--;
if (nat->nat_hnext[1])
nat->nat_hnext[1]->nat_phnext[1] = nat->nat_phnext[1];
*nat->nat_phnext[1] = nat->nat_hnext[1];
- hv1 = nat->nat_hv[1] % softn->ipf_nat_table_sz;
+ ASSERT(nsp->ns_side[1].ns_bucketlen[hv1] > 0);
nsp->ns_side[1].ns_bucketlen[hv1]--;
Home |
Main Index |
Thread Index |
Old Index