10 #include <linux/module.h>
13 #include <linux/errno.h>
14 #include <linux/netlink.h>
19 #include <linux/netfilter/ipset/ip_set.h>
20 #include <linux/netfilter/ipset/ip_set_bitmap.h>
22 #define IP_SET_BITMAP_TIMEOUT
25 #define REVISION_MIN 0
26 #define REVISION_MAX 0
67 bitmap_port_del(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
79 bitmap_port_list(
const struct ip_set *
set,
83 struct nlattr *atd, *nested;
90 for (; cb->
args[2] <= last; cb->
args[2]++) {
97 nla_nest_cancel(skb, atd);
100 goto nla_put_failure;
104 goto nla_put_failure;
114 nla_nest_cancel(skb, nested);
126 bitmap_port_ttest(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
132 return ip_set_timeout_test(members[
id]);
136 bitmap_port_tadd(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
145 members[
id] = ip_set_timeout_set(timeout);
151 bitmap_port_tdel(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
154 unsigned long *members = map->
members;
158 if (ip_set_timeout_test(members[
id]))
161 members[
id] = IPSET_ELEM_UNSET;
166 bitmap_port_tlist(
const struct ip_set *
set,
170 struct nlattr *adt, *nested;
173 const unsigned long *members = map->
members;
178 for (; cb->
args[2] <= last; cb->
args[2]++) {
180 if (!ip_set_timeout_test(members[
id]))
185 nla_nest_cancel(skb, adt);
188 goto nla_put_failure;
193 htonl(ip_set_timeout_get(members[
id]))))
194 goto nla_put_failure;
205 nla_nest_cancel(skb, nested);
215 bitmap_port_kadt(
struct ip_set *
set,
const struct sk_buff *skb,
228 port =
ntohs(__port);
235 return adtfn(
set, &port, opt_timeout(opt, map), opt->
cmdflags);
255 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
262 if (!with_timeout(map->
timeout))
264 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
269 return adtfn(
set, &
id, timeout, flags);
273 port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
274 if (port > port_to) {
285 for (; port <= port_to; port++) {
287 ret = adtfn(
set, &
id, timeout, flags);
289 if (ret && !ip_set_eexist(ret, flags))
298 bitmap_port_destroy(
struct ip_set *
set)
302 if (with_timeout(map->
timeout))
312 bitmap_port_flush(
struct ip_set *
set)
327 goto nla_put_failure;
334 nla_put_net32(skb, IPSET_ATTR_TIMEOUT,
htonl(map->
timeout))))
335 goto nla_put_failure;
344 bitmap_port_same_set(
const struct ip_set *
a,
const struct ip_set *
b)
355 .kadt = bitmap_port_kadt,
356 .uadt = bitmap_port_uadt,
362 .destroy = bitmap_port_destroy,
363 .flush = bitmap_port_flush,
364 .head = bitmap_port_head,
365 .list = bitmap_port_list,
366 .same_set = bitmap_port_same_set,
370 .kadt = bitmap_port_kadt,
371 .uadt = bitmap_port_uadt,
377 .destroy = bitmap_port_destroy,
378 .flush = bitmap_port_flush,
379 .head = bitmap_port_head,
380 .list = bitmap_port_tlist,
381 .same_set = bitmap_port_same_set,
385 bitmap_port_gc(
unsigned long ul_set)
388 struct bitmap_port *map =
set->data;
396 for (
id = 0;
id <= last;
id++)
397 if (ip_set_timeout_expired(table[
id]))
398 table[
id] = IPSET_ELEM_UNSET;
406 bitmap_port_gc_init(
struct ip_set *
set)
408 struct bitmap_port *map =
set->data;
411 map->
gc.data = (
unsigned long)
set;
412 map->
gc.function = bitmap_port_gc;
420 init_map_port(
struct ip_set *
set,
struct bitmap_port *map,
428 map->
timeout = IPSET_NO_TIMEOUT;
437 bitmap_port_create(
struct ip_set *
set,
struct nlattr *tb[],
440 struct bitmap_port *
map;
444 !ip_set_attr_netorder(tb, IPSET_ATTR_PORT_TO) ||
445 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT)))
449 last_port = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
450 if (first_port > last_port) {
461 if (tb[IPSET_ATTR_TIMEOUT]) {
462 map->
memsize = (last_port - first_port + 1)
463 *
sizeof(
unsigned long);
465 if (!init_map_port(
set, map, first_port, last_port)) {
470 map->
timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
471 set->variant = &bitmap_tport;
473 bitmap_port_gc_init(
set);
475 map->
memsize = bitmap_bytes(0, last_port - first_port);
477 if (!init_map_port(
set, map, first_port, last_port)) {
482 set->variant = &bitmap_port;
488 .name =
"bitmap:port",
495 .create = bitmap_port_create,
511 bitmap_port_init(
void)
517 bitmap_port_fini(
void)