]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/blobdiff - include/linux/netfilter/ipset/ip_set_ahash.h
netfilter: ipset: fix hash size checking in kernel
[lisovros/linux_canprio.git] / include / linux / netfilter / ipset / ip_set_ahash.h
index 05a5d72680bed904c23687a69e43a7759bc61848..230a290e1973c63f4411154e581692669e37ee08 100644 (file)
@@ -99,6 +99,22 @@ struct ip_set_hash {
 #endif
 };
 
+static size_t
+htable_size(u8 hbits)
+{
+       size_t hsize;
+
+       /* We must fit both into u32 in jhash and size_t */
+       if (hbits > 31)
+               return 0;
+       hsize = jhash_size(hbits);
+       if ((((size_t)-1) - sizeof(struct htable))/sizeof(struct hbucket)
+           < hsize)
+               return 0;
+
+       return hsize * sizeof(struct hbucket) + sizeof(struct htable);
+}
+
 /* Compute htable_bits from the user input parameter hashsize */
 static u8
 htable_bits(u32 hashsize)