11 #include <linux/module.h>
14 #include <linux/errno.h>
15 #include <linux/random.h>
20 #include <linux/netfilter.h>
22 #include <linux/netfilter/ipset/ip_set.h>
24 #include <linux/netfilter/ipset/ip_set_hash.h>
26 #define REVISION_MIN 0
28 #define REVISION_MAX 2
41 #define hash_net4_same_set hash_net_same_set
42 #define hash_net6_same_set hash_net_same_set
68 return ip1->
ip == ip2->
ip &&
75 return elem->
cidr == 0;
102 elem->
ip &= ip_set_netmask(cidr);
122 goto nla_put_failure;
142 goto nla_put_failure;
149 #define IP_SET_HASH_WITH_NETS
163 hash_net4_kadt(
struct ip_set *
set,
const struct sk_buff *skb,
179 data.
ip &= ip_set_netmask(data.
cidr);
181 return adtfn(
set, &data, opt_timeout(opt, h), opt->
cmdflags);
201 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
208 data.
cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
216 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
222 flags |= (cadt_flags << 16);
227 ret = adtfn(
set, &data, timeout, flags);
228 return ip_set_eexist(ret, flags) ? 0 :
ret;
232 if (tb[IPSET_ATTR_IP_TO]) {
233 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &ip_to);
243 while (!
after(ip, ip_to)) {
246 ret = adtfn(
set, &data, timeout, flags);
247 if (ret && !ip_set_eexist(ret, flags))
289 return ipv6_addr_cmp(&ip1->
ip.
in6, &ip2->
ip.
in6) == 0 &&
296 return elem->
cidr == 0;
329 ip->
ip6[0] &= ip_set_netmask6(prefix)[0];
330 ip->
ip6[1] &= ip_set_netmask6(prefix)[1];
331 ip->
ip6[2] &= ip_set_netmask6(prefix)[2];
332 ip->
ip6[3] &= ip_set_netmask6(prefix)[3];
338 ip6_netmask(&elem->
ip, cidr);
348 nla_put_u8(skb, IPSET_ATTR_CIDR, data->
cidr) ||
351 goto nla_put_failure;
366 nla_put_u8(skb, IPSET_ATTR_CIDR, e->
cidr) ||
367 nla_put_net32(skb, IPSET_ATTR_TIMEOUT,
371 goto nla_put_failure;
382 #define HOST_MASK 128
392 hash_net6_kadt(
struct ip_set *
set,
const struct sk_buff *skb,
408 ip6_netmask(&data.
ip, data.
cidr);
410 return adtfn(
set, &data, opt_timeout(opt, h), opt->
cmdflags);
424 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
430 if (tb[IPSET_ATTR_LINENO])
431 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
437 if (tb[IPSET_ATTR_CIDR])
438 data.
cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
443 ip6_netmask(&data.
ip, data.
cidr);
445 if (tb[IPSET_ATTR_TIMEOUT]) {
448 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
454 flags |= (cadt_flags << 16);
457 ret = adtfn(
set, &data, timeout, flags);
459 return ip_set_eexist(ret, flags) ? 0 :
ret;
477 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT)))
481 hashsize = ip_set_get_h32(tb[IPSET_ATTR_HASHSIZE]);
487 maxelem = ip_set_get_h32(tb[IPSET_ATTR_MAXELEM]);
489 h = kzalloc(
sizeof(*h)
499 hbits = htable_bits(hashsize);
500 hsize = htable_size(hbits);
510 h->
table->htable_bits = hbits;
514 if (tb[IPSET_ATTR_TIMEOUT]) {
515 h->
timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
518 ? &hash_net4_tvariant : &hash_net6_tvariant;
521 hash_net4_gc_init(
set);
523 hash_net6_gc_init(
set);
526 ? &hash_net4_variant : &hash_net6_variant;
529 pr_debug(
"create %s hashsize %u (%u) maxelem %u: %p(%p)\n",
544 .create = hash_net_create,