Re: [NETFILTER][PATCH] Re: Question about the hashlimit network mask patch

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

 



On Tuesday 2008-04-01 14:49, Patrick McHardy wrote:

Jan Engelhardt wrote:
 [NETFILTER]: xt_hashlimit: add workaround for >>32 case

 Hardware surprisingly does nothing when a 32-bit right-shift is
 to be done. Worse yet, compilers do not even work around it.

Thats because the C standard states that the result is undefined.
Anyways, I think this patch is slightly nicer because it
gets rid of the double negation and the %32 == 0 special-casing
for IPv6.

Do you want to add an ACKed-by?


The special casing for %32==0 in the IPv6 block was not a workaround for '>>32', but speed. Assuming the C code is already perfect and gets transformed 1:1 into assembly without any further optimization, the cost of the operation is 4 simple 'mov' instructions for %32==0, whereas calling maskl() will involve a fair number of operations (at least 27 by the count). [With your patch, maskl() is now 28 + a branch.]

Not that it really matters to me, I submitted patch (no replies yet)
that replaces it with the pfxlen static map anyway :->

#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
static void hashlimit_ipv6_mask(__be32 *i, unsigned int p)
{
	switch (p) {
-	case 0:
-		i[0] = i[1] = 0;
-		i[2] = i[3] = 0;
-		break;
-	case 1 ... 31:
+	case 0 ... 31:
		i[0] = maskl(i[0], p);
		i[1] = i[2] = i[3] = 0;
		break;
-	case 32:
-		i[1] = i[2] = i[3] = 0;
-		break;
-	case 33 ... 63:
+	case 32 ... 63:
		i[1] = maskl(i[1], p - 32);
		i[2] = i[3] = 0;
		break;
-	case 64:
-		i[2] = i[3] = 0;
-		break;
-	case 65 ... 95:
+	case 64 ... 95:
		i[2] = maskl(i[2], p - 64);
		i[3] = 0;
-	case 96:
-		i[3] = 0;
-		break;
-	case 97 ... 127:
+	case 96 ... 127:
		i[3] = maskl(i[3], p - 96);
		break;
	case 128:
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux