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 /* Kernel module to match an IP set. */
13 #include <linux/module.h>
15 #include <linux/skbuff.h>
16 #include <linux/version.h>
18 #include <linux/netfilter_ipv4/ip_tables.h>
19 #include <linux/netfilter_ipv4/ip_set.h>
20 #include <linux/netfilter_ipv4/ipt_set.h>
23 match_set(const struct ipt_set_info *info,
24 const struct sk_buff *skb,
27 if (ip_set_testip_kernel(info->index, skb, info->flags))
33 match(const struct sk_buff *skb,
34 const struct net_device *in,
35 const struct net_device *out,
36 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
37 const struct xt_match *match,
39 const void *matchinfo,
40 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
41 int offset, unsigned int protoff, int *hotdrop)
43 int offset, int *hotdrop)
46 const struct ipt_set_info_match *info = matchinfo;
48 return match_set(&info->match_set,
50 info->match_set.flags[0] & IPSET_MATCH_INV);
54 checkentry(const char *tablename,
55 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
58 const struct ipt_ip *ip,
60 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
61 const struct xt_match *match,
64 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
65 unsigned int matchsize,
67 unsigned int hook_mask)
69 struct ipt_set_info_match *info =
70 (struct ipt_set_info_match *) matchinfo;
73 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
74 if (matchsize != IPT_ALIGN(sizeof(struct ipt_set_info_match))) {
75 ip_set_printk("invalid matchsize %d", matchsize);
80 index = ip_set_get_byindex(info->match_set.index);
82 if (index == IP_SET_INVALID_ID) {
83 ip_set_printk("Cannot find set indentified by id %u to match",
84 info->match_set.index);
87 if (info->match_set.flags[IP_SET_MAX_BINDINGS] != 0) {
88 ip_set_printk("That's nasty!");
96 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
97 const struct xt_match *match,
99 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
100 void *matchinfo, unsigned int matchsize)
105 struct ipt_set_info_match *info = matchinfo;
107 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
108 if (matchsize != IPT_ALIGN(sizeof(struct ipt_set_info_match))) {
109 ip_set_printk("invalid matchsize %d", matchsize);
113 ip_set_put(info->match_set.index);
116 static struct ipt_match set_match = {
119 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
120 .matchsize = sizeof(struct ipt_set_info_match),
122 .checkentry = &checkentry,
127 MODULE_LICENSE("GPL");
128 MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
129 MODULE_DESCRIPTION("iptables IP set match module");
131 static int __init ipt_ipset_init(void)
133 return ipt_register_match(&set_match);
136 static void __exit ipt_ipset_fini(void)
138 ipt_unregister_match(&set_match);
141 module_init(ipt_ipset_init);
142 module_exit(ipt_ipset_fini);