1 Index: linux-2.4.35.4/Documentation/Configure.help
2 ===================================================================
3 --- linux-2.4.35.4.orig/Documentation/Configure.help 2007-12-15 05:20:10.792455269 +0100
4 +++ linux-2.4.35.4/Documentation/Configure.help 2007-12-15 05:20:11.948521148 +0100
6 If you want to compile it as a module, say M here and read
7 <file:Documentation/modules.txt>. If unsure, say `N'.
10 +CONFIG_IP_NF_MATCH_IPRANGE
11 + This option makes possible to match IP addresses against
14 + If you want to compile it as a module, say M here and read
15 + <file:Documentation/modules.txt>. If unsure, say `N'.
17 Condition variable match support
18 CONFIG_IP_NF_MATCH_CONDITION
19 This option allows you to match firewall rules against condition
20 Index: linux-2.4.35.4/include/linux/netfilter_ipv4/ipt_iprange.h
21 ===================================================================
22 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
23 +++ linux-2.4.35.4/include/linux/netfilter_ipv4/ipt_iprange.h 2007-12-15 05:20:11.952521377 +0100
25 +#ifndef _IPT_IPRANGE_H
26 +#define _IPT_IPRANGE_H
28 +#define IPRANGE_SRC 0x01 /* Match source IP address */
29 +#define IPRANGE_DST 0x02 /* Match destination IP address */
30 +#define IPRANGE_SRC_INV 0x10 /* Negate the condition */
31 +#define IPRANGE_DST_INV 0x20 /* Negate the condition */
34 + /* Inclusive: network order. */
35 + u_int32_t min_ip, max_ip;
38 +struct ipt_iprange_info
40 + struct ipt_iprange src;
41 + struct ipt_iprange dst;
43 + /* Flags from above */
47 +#endif /* _IPT_IPRANGE_H */
48 Index: linux-2.4.35.4/net/ipv4/netfilter/Config.in
49 ===================================================================
50 --- linux-2.4.35.4.orig/net/ipv4/netfilter/Config.in 2007-12-15 05:20:11.688506331 +0100
51 +++ linux-2.4.35.4/net/ipv4/netfilter/Config.in 2007-12-15 05:20:11.960521836 +0100
53 if [ "$CONFIG_IP_NF_IPTABLES" != "n" ]; then
55 dep_tristate ' limit match support' CONFIG_IP_NF_MATCH_LIMIT $CONFIG_IP_NF_IPTABLES
56 + dep_tristate ' IP range match support' CONFIG_IP_NF_MATCH_IPRANGE $CONFIG_IP_NF_IPTABLES
57 dep_tristate ' quota match support' CONFIG_IP_NF_MATCH_QUOTA $CONFIG_IP_NF_IPTABLES
59 dep_tristate ' IP set support' CONFIG_IP_NF_SET $CONFIG_IP_NF_IPTABLES
60 Index: linux-2.4.35.4/net/ipv4/netfilter/ipt_iprange.c
61 ===================================================================
62 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
63 +++ linux-2.4.35.4/net/ipv4/netfilter/ipt_iprange.c 2007-12-15 05:20:11.964522063 +0100
66 + * iptables module to match IP address ranges
67 + * (c) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
69 + * Released under the terms of GNU GPLv2.
72 +#include <linux/module.h>
73 +#include <linux/skbuff.h>
74 +#include <linux/ip.h>
75 +#include <linux/netfilter_ipv4/ip_tables.h>
76 +#include <linux/netfilter_ipv4/ipt_iprange.h>
78 +MODULE_LICENSE("GPL");
79 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
80 +MODULE_DESCRIPTION("iptables arbitrary IP range match module");
83 +#define DEBUGP printk
85 +#define DEBUGP(format, args...)
89 +match(const struct sk_buff *skb,
90 + const struct net_device *in,
91 + const struct net_device *out,
92 + const void *matchinfo,
98 + const struct ipt_iprange_info *info = matchinfo;
99 + const struct iphdr *iph = skb->nh.iph;
102 + if (info->flags & IPRANGE_SRC) {
103 + if (((ntohl(iph->saddr) < ntohl(info->src.min_ip))
104 + || (ntohl(iph->saddr) > ntohl(info->src.max_ip)))
105 + ^ !!(info->flags & IPRANGE_SRC_INV)) {
106 + DEBUGP("src IP %u.%u.%u.%u NOT in range %s"
107 + "%u.%u.%u.%u-%u.%u.%u.%u\n",
108 + NIPQUAD(iph->saddr),
109 + info->flags & IPRANGE_SRC_INV ? "(INV) " : "",
110 + NIPQUAD(info->src.min_ip),
111 + NIPQUAD(info->src.max_ip));
115 + if (info->flags & IPRANGE_DST) {
116 + if (((ntohl(iph->daddr) < ntohl(info->dst.min_ip))
117 + || (ntohl(iph->daddr) > ntohl(info->dst.max_ip)))
118 + ^ !!(info->flags & IPRANGE_DST_INV)) {
119 + DEBUGP("dst IP %u.%u.%u.%u NOT in range %s"
120 + "%u.%u.%u.%u-%u.%u.%u.%u\n",
121 + NIPQUAD(iph->daddr),
122 + info->flags & IPRANGE_DST_INV ? "(INV) " : "",
123 + NIPQUAD(info->dst.min_ip),
124 + NIPQUAD(info->dst.max_ip));
131 +static int check(const char *tablename,
132 + const struct ipt_ip *ip,
134 + unsigned int matchsize,
135 + unsigned int hook_mask)
138 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_iprange_info)))
144 +static struct ipt_match iprange_match =
146 + .list = { NULL, NULL },
149 + .checkentry = &check,
154 +static int __init init(void)
156 + return ipt_register_match(&iprange_match);
159 +static void __exit fini(void)
161 + ipt_unregister_match(&iprange_match);
166 Index: linux-2.4.35.4/net/ipv4/netfilter/Makefile
167 ===================================================================
168 --- linux-2.4.35.4.orig/net/ipv4/netfilter/Makefile 2007-12-15 05:20:11.696506789 +0100
169 +++ linux-2.4.35.4/net/ipv4/netfilter/Makefile 2007-12-15 05:20:11.976522746 +0100
172 obj-$(CONFIG_IP_NF_MATCH_HELPER) += ipt_helper.o
173 obj-$(CONFIG_IP_NF_MATCH_LIMIT) += ipt_limit.o
174 +obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
175 obj-$(CONFIG_IP_NF_MATCH_QUOTA) += ipt_quota.o
176 obj-$(CONFIG_IP_NF_MATCH_MARK) += ipt_mark.o
177 obj-$(CONFIG_IP_NF_MATCH_SET) += ipt_set.o