13 #include <linux/module.h>
17 #include <linux/errno.h>
18 #include <linux/if_ether.h>
19 #include <linux/netlink.h>
25 #include <linux/netfilter/ipset/ip_set.h>
27 #include <linux/netfilter/ipset/ip_set_bitmap.h>
29 #define REVISION_MIN 0
30 #define REVISION_MAX 0
83 return ip_set_timeout_test(elem->
timeout);
91 return ip_set_timeout_expired(elem->
timeout);
99 !ip_set_timeout_expired(elem->
timeout));
111 switch (elem->
match) {
123 bitmap_ipmac_add(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
127 struct ipmac_elem *elem = bitmap_ipmac_elem(map, data->
id);
129 switch (elem->
match) {
152 bitmap_ipmac_del(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
156 struct ipmac_elem *elem = bitmap_ipmac_elem(map, data->
id);
167 bitmap_ipmac_list(
const struct ip_set *
set,
172 struct nlattr *atd, *nested;
179 for (; cb->
args[2] <= last; cb->
args[2]++) {
181 elem = bitmap_ipmac_elem(map,
id);
187 nla_nest_cancel(skb, atd);
190 goto nla_put_failure;
197 goto nla_put_failure;
207 nla_nest_cancel(skb, nested);
219 bitmap_ipmac_ttest(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
223 const struct ipmac_elem *elem = bitmap_ipmac_elem(map, data->
id);
225 switch (elem->
match) {
231 ether_addr_equal(data->
ether, elem->
ether)) &&
232 !bitmap_expired(map, data->
id);
238 bitmap_ipmac_tadd(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
245 switch (elem->
match) {
247 if (!(data->
ether || flag_exist))
256 elem->
timeout = ip_set_timeout_set(timeout);
259 if (!(bitmap_expired(map, data->
id) || flag_exist))
272 elem->
timeout = data->
ether ? ip_set_timeout_set(timeout)
281 bitmap_ipmac_tdel(
struct ip_set *
set,
void *value,
u32 timeout,
u32 flags)
296 bitmap_ipmac_tlist(
const struct ip_set *
set,
301 struct nlattr *atd, *nested;
308 for (; cb->
args[2] <= last; cb->
args[2]++) {
310 elem = bitmap_ipmac_elem(map,
id);
311 if (!bitmap_ipmac_exist(elem))
316 nla_nest_cancel(skb, atd);
319 goto nla_put_failure;
326 goto nla_put_failure;
328 : ip_set_timeout_get(elem->
timeout);
330 goto nla_put_failure;
340 nla_nest_cancel(skb, nested);
346 bitmap_ipmac_kadt(
struct ip_set *
set,
const struct sk_buff *skb,
363 if (skb_mac_header(skb) < skb->
head ||
368 data.
ether = eth_hdr(skb)->h_source;
370 return adtfn(
set, &data, opt_timeout(opt, map), opt->
cmdflags);
388 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
398 data.
ether = nla_data(tb[IPSET_ATTR_ETHER]);
403 if (!with_timeout(map->
timeout))
405 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
410 ret = adtfn(
set, &data, timeout, flags);
412 return ip_set_eexist(ret, flags) ? 0 :
ret;
416 bitmap_ipmac_destroy(
struct ip_set *
set)
420 if (with_timeout(map->
timeout))
430 bitmap_ipmac_flush(
struct ip_set *
set)
446 goto nla_put_failure;
455 nla_put_net32(skb, IPSET_ATTR_TIMEOUT,
htonl(map->
timeout))))
456 goto nla_put_failure;
465 bitmap_ipmac_same_set(
const struct ip_set *
a,
const struct ip_set *
b)
476 .kadt = bitmap_ipmac_kadt,
477 .uadt = bitmap_ipmac_uadt,
483 .destroy = bitmap_ipmac_destroy,
484 .flush = bitmap_ipmac_flush,
485 .head = bitmap_ipmac_head,
486 .list = bitmap_ipmac_list,
487 .same_set = bitmap_ipmac_same_set,
491 .kadt = bitmap_ipmac_kadt,
492 .uadt = bitmap_ipmac_uadt,
498 .destroy = bitmap_ipmac_destroy,
499 .flush = bitmap_ipmac_flush,
500 .head = bitmap_ipmac_head,
501 .list = bitmap_ipmac_tlist,
502 .same_set = bitmap_ipmac_same_set,
506 bitmap_ipmac_gc(
unsigned long ul_set)
509 struct bitmap_ipmac *map =
set->data;
516 for (
id = 0;
id <= last;
id++) {
517 elem = bitmap_ipmac_elem(map,
id);
519 ip_set_timeout_expired(elem->
timeout))
529 bitmap_ipmac_gc_init(
struct ip_set *
set)
531 struct bitmap_ipmac *map =
set->data;
534 map->
gc.data = (
unsigned long)
set;
535 map->
gc.function = bitmap_ipmac_gc;
543 init_map_ipmac(
struct ip_set *
set,
struct bitmap_ipmac *map,
551 map->
timeout = IPSET_NO_TIMEOUT;
560 bitmap_ipmac_create(
struct ip_set *
set,
struct nlattr *tb[],
565 struct bitmap_ipmac *
map;
569 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT)))
577 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &last_ip);
580 if (first_ip > last_ip) {
587 u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
595 elements = (
u64)last_ip - first_ip + 1;
604 if (tb[IPSET_ATTR_TIMEOUT]) {
607 if (!init_map_ipmac(
set, map, first_ip, last_ip)) {
612 map->
timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
614 set->variant = &bitmap_tipmac;
616 bitmap_ipmac_gc_init(
set);
620 if (!init_map_ipmac(
set, map, first_ip, last_ip)) {
624 set->variant = &bitmap_ipmac;
631 .name =
"bitmap:ip,mac",
638 .create = bitmap_ipmac_create,
656 bitmap_ipmac_init(
void)
662 bitmap_ipmac_fini(
void)