1 /* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
2 * Patrick Schaaf <bof@bof.de>
3 * Martin Josefsson <gandalf@wlug.westbo.se>
4 * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 /* ipt_SET.c - netfilter target to manipulate IP sets */
13 #include <linux/types.h>
15 #include <linux/timer.h>
16 #include <linux/module.h>
17 #include <linux/netfilter.h>
18 #include <linux/netdevice.h>
20 #include <linux/inetdevice.h>
21 #include <linux/version.h>
22 #include <net/protocol.h>
23 #include <net/checksum.h>
24 #include <linux/netfilter_ipv4.h>
25 #include <linux/netfilter_ipv4/ip_nat_rule.h>
26 #include <linux/netfilter_ipv4/ipt_set.h>
29 target(struct sk_buff **pskb,
30 const struct net_device *in,
31 const struct net_device *out,
33 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
34 const struct xt_target *target,
36 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
43 const struct ipt_set_info_target *info = targinfo;
45 if (info->add_set.index != IP_SET_INVALID_ID)
46 ip_set_addip_kernel(info->add_set.index,
49 if (info->del_set.index != IP_SET_INVALID_ID)
50 ip_set_delip_kernel(info->del_set.index,
58 checkentry(const char *tablename,
59 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
62 const struct ipt_entry *e,
64 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
65 const struct xt_target *target,
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
69 unsigned int targinfosize,
71 unsigned int hook_mask)
73 struct ipt_set_info_target *info =
74 (struct ipt_set_info_target *) targinfo;
77 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
78 if (targinfosize != IPT_ALIGN(sizeof(*info))) {
79 DP("bad target info size %u", targinfosize);
84 if (info->add_set.index != IP_SET_INVALID_ID) {
85 index = ip_set_get_byindex(info->add_set.index);
86 if (index == IP_SET_INVALID_ID) {
87 ip_set_printk("cannot find add_set index %u as target",
93 if (info->del_set.index != IP_SET_INVALID_ID) {
94 index = ip_set_get_byindex(info->del_set.index);
95 if (index == IP_SET_INVALID_ID) {
96 ip_set_printk("cannot find del_set index %u as target",
101 if (info->add_set.flags[IP_SET_MAX_BINDINGS] != 0
102 || info->del_set.flags[IP_SET_MAX_BINDINGS] != 0) {
103 ip_set_printk("That's nasty!");
104 return 0; /* error */
111 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
112 const struct xt_target *target,
114 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
115 void *targetinfo, unsigned int targetsize)
120 struct ipt_set_info_target *info = targetinfo;
122 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
123 if (targetsize != IPT_ALIGN(sizeof(struct ipt_set_info_target))) {
124 ip_set_printk("invalid targetsize %d", targetsize);
128 if (info->add_set.index != IP_SET_INVALID_ID)
129 ip_set_put(info->add_set.index);
130 if (info->del_set.index != IP_SET_INVALID_ID)
131 ip_set_put(info->del_set.index);
134 static struct ipt_target SET_target = {
137 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
138 .targetsize = sizeof(struct ipt_set_info_target),
140 .checkentry = checkentry,
145 MODULE_LICENSE("GPL");
146 MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
147 MODULE_DESCRIPTION("iptables IP set target module");
149 static int __init ipt_SET_init(void)
151 return ipt_register_target(&SET_target);
154 static void __exit ipt_SET_fini(void)
156 ipt_unregister_target(&SET_target);
159 module_init(ipt_SET_init);
160 module_exit(ipt_SET_fini);