Skip to contentSkip to conversation

hashlimit match errors and patches

PATCH Applied Nikolai Malykh 2 participants 2 messages Feb 4, 2005 – Feb 7, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

1. Incorrect parameters handling in libipt_hashlimit make impossible to save rule without error because --hashlimit-mode saved as --mode

Patch for this error in attachment

2. Incorrect parameter in jhash_3words() - port numbers not hashed in result
3. Incorrect parameter value in hashlimit_match() - matching packet = burst +1 instead burst

Patch for this errors in attachment

PS. Sorry for my English it's not my native.

Signature · 5 lines
Nikolai Malykh
[email protected]

phone +7 (812) 449 0770
ICQ UIN 30741141
libipt_hashlimit.c renamed from usr/src/iptables-1.3.0rc1/extensions/libipt_hashlimit.c +6 -2
@@ -7,6 +7,8 @@
  * Based on ipt_limit.c by
  * J�r�me de Vivie   <[email protected]>
  * Herv� Eychenne    <[email protected]>
+ * 
+ * Error corections by [email protected] (22.01.2005)
  */
 
 #include <stdio.h>
@@ -294,7 +296,7 @@
 		fputs("dstip", stdout);
 		prevmode = 1;
 	}
-	if (r->cfg.mode & IPT_HASHLIMIT_HASH_SPT) {
+	if (r->cfg.mode & IPT_HASHLIMIT_HASH_DPT) {
 		if (prevmode)
 			putchar(separator);
 		fputs("dstport", stdout);
@@ -334,8 +336,10 @@
 	if (r->cfg.burst != IPT_HASHLIMIT_BURST)
 		printf("--hashlimit-burst %u ", r->cfg.burst);
 
-	fputs("--mode ", stdout);
+	fputs("--hashlimit-mode ", stdout);
 	print_mode(r, ',');
+	
+	printf("--hashlimit-name %s ", r->name);
 
 	if (r->cfg.size)
 		printf("--hashlimit-htable-size %u ", r->cfg.size);
usr/src/linux/net/ipv4/netfilter/ipt_hashlimit.c renamed from ipt_hashlimit.c +8 -7
@@ -97,7 +97,7 @@
 	struct list_head hash[0];	/* hashtable itself */
 };
 
-DECLARE_RWLOCK(hashlimit_lock);		/* protects htables list */
+static DECLARE_RWLOCK(hashlimit_lock);		/* protects htables list */
 static LIST_HEAD(hashlimit_htables);
 static kmem_cache_t *hashlimit_cachep;
 
@@ -112,7 +112,7 @@
 static inline u_int32_t
 hash_dst(const struct ipt_hashlimit_htable *ht, const struct dsthash_dst *dst)
 {
-	return (jhash_3words(dst->dst_ip, (dst->dst_port<<16 & dst->src_port), 
+	return (jhash_3words(dst->dst_ip, (u32)((u32)dst->dst_port<<16 | dst->src_port), 
 			     dst->src_ip, ht->rnd) % ht->cfg.size);
 }
 
@@ -413,7 +413,6 @@
 			ports[0] = ports[1] = 0;
 			break;
 	}
-
 	return 0;
 }
 
@@ -471,7 +470,7 @@
 
 		dh->rateinfo.prev = jiffies;
 		dh->rateinfo.credit = user2credits(hinfo->cfg.avg * 
-							hinfo->cfg.burst);
+							(hinfo->cfg.burst-1));
 		dh->rateinfo.credit_cap = user2credits(hinfo->cfg.avg * 
 							hinfo->cfg.burst);
 		dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
@@ -480,6 +479,7 @@
 		return 1;
 	}
 
+//	unsigned long now = jiffies;
 	/* update expiration timeout */
 	dh->expires = now + MS2JIFFIES(hinfo->cfg.expire);
 
@@ -608,6 +608,9 @@
 	/* recalculate to show accurate numbers */
 	rateinfo_recalc(ent, jiffies);
 
+//	ent->rateinfo.credit += (jiffies - xchg(&ent->rateinfo.prev, jiffies)) 
+//					* CREDITS_PER_JIFFY;
+
 	return seq_printf(s, "%ld %u.%u.%u.%u:%u->%u.%u.%u.%u:%u %u %u %u\n",
 			(ent->expires - jiffies)/HZ,
 			NIPQUAD(ent->dst.src_ip), ntohs(ent->dst.src_port),
@@ -668,11 +671,9 @@
 		goto cleanup_nothing;
 	}
 
-	/* FIXME: do we really want HWCACHE_ALIGN since our objects are
-	 * quite small ? */
 	hashlimit_cachep = kmem_cache_create("ipt_hashlimit",
 					    sizeof(struct dsthash_ent), 0,
-					    SLAB_HWCACHE_ALIGN, NULL, NULL);
+					    0, NULL, NULL);
 	if (!hashlimit_cachep) {
 		printk(KERN_ERR "Unable to create ipt_hashlimit slab cache\n");
 		ret = -ENOMEM;
Applied
#1 lore raw
Quoted 2 lines · Nikolai Malykh

1. Incorrect parameters handling in libipt_hashlimit make impossible to save rule without error because --hashlimit-mode saved as --mode

thanks, applied your patch.
Committed revision 3653.

Quoted 5 lines

Patch for this error in attachment

2. Incorrect parameter in jhash_3words() - port numbers not hashed in result
3. Incorrect parameter value in hashlimit_match() - matching packet = burst +1 instead burst

Your kernel patches contained other changes than the bugs you mentioned above. Please try to separate such changes before submitting a fix. Thanks.

I'll grab the two hunks that actually fix bugs and hand the result over to Patrick.

It's good to see hashlimit bugreports and fixes during the last couple of weeks. This proves that it has it's applications and people are actually using it :)

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie