11 #include <linux/module.h>
14 #include <linux/errno.h>
15 #include <linux/random.h>
21 #include <linux/netfilter.h>
23 #include <linux/netfilter/ipset/ip_set.h>
25 #include <linux/netfilter/ipset/ip_set_hash.h>
27 #define REVISION_MIN 0
28 #define REVISION_MAX 0
41 #define hash_ip4_same_set hash_ip_same_set
42 #define hash_ip6_same_set hash_ip_same_set
62 return ip1->
ip == ip2->
ip;
104 goto nla_put_failure;
112 #define IP_SET_HASH_WITH_NETMASK
133 ip &= ip_set_netmask(h->netmask);
137 return adtfn(
set, &ip, opt_timeout(opt, h), opt->
cmdflags);
155 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
161 ip &= ip_set_hostmask(h->netmask);
166 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
173 return adtfn(
set, &nip, timeout, flags);
178 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &ip_to);
184 u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
186 if (!cidr || cidr > 32)
191 hosts = h->netmask == 32 ? 1 : 2 << (32 - h->netmask - 1);
195 for (; !before(ip_to, ip); ip += hosts) {
199 ret = adtfn(
set, &nip, timeout, flags);
201 if (ret && !ip_set_eexist(ret, flags))
218 x->netmask == y->netmask;
237 return ipv6_addr_cmp(&ip1->
ip.
in6, &ip2->
ip.
in6) == 0;
243 return ipv6_addr_any(&elem->
ip.
in6);
255 ipv6_addr_set(&elem->
ip.
in6, 0, 0, 0, 0);
261 ip->
ip6[0] &= ip_set_netmask6(prefix)[0];
262 ip->
ip6[1] &= ip_set_netmask6(prefix)[1];
263 ip->
ip6[2] &= ip_set_netmask6(prefix)[2];
264 ip->
ip6[3] &= ip_set_netmask6(prefix)[3];
271 goto nla_put_failure;
285 nla_put_net32(skb, IPSET_ATTR_TIMEOUT,
287 goto nla_put_failure;
298 #define HOST_MASK 128
316 ip6_netmask(&ip, h->netmask);
317 if (ipv6_addr_any(&ip.in6))
320 return adtfn(
set, &ip, opt_timeout(opt, h), opt->
cmdflags);
340 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
341 tb[IPSET_ATTR_IP_TO] ||
342 tb[IPSET_ATTR_CIDR]))
345 if (tb[IPSET_ATTR_LINENO])
346 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
352 ip6_netmask(&ip, h->netmask);
353 if (ipv6_addr_any(&ip.in6))
356 if (tb[IPSET_ATTR_TIMEOUT]) {
359 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
362 ret = adtfn(
set, &ip, timeout, flags);
364 return ip_set_eexist(ret, flags) ? 0 :
ret;
380 pr_debug(
"Create set %s with family %s\n",
385 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT)))
389 hashsize = ip_set_get_h32(tb[IPSET_ATTR_HASHSIZE]);
395 maxelem = ip_set_get_h32(tb[IPSET_ATTR_MAXELEM]);
398 netmask = nla_get_u8(tb[IPSET_ATTR_NETMASK]);
411 h->netmask = netmask;
415 hbits = htable_bits(hashsize);
416 hsize = htable_size(hbits);
426 h->
table->htable_bits = hbits;
430 if (tb[IPSET_ATTR_TIMEOUT]) {
431 h->
timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
434 ? &hash_ip4_tvariant : &hash_ip6_tvariant;
437 hash_ip4_gc_init(
set);
439 hash_ip6_gc_init(
set);
442 ? &hash_ip4_variant : &hash_ip6_variant;
445 pr_debug(
"create %s hashsize %u (%u) maxelem %u: %p(%p)\n",
460 .create = hash_ip_create,