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:11.948521148 +0100
4 +++ linux-2.4.35.4/Documentation/Configure.help 2007-12-15 05:20:12.260538930 +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_RANDOM
11 + This option adds a `random' match,
12 + which allow you to match packets randomly
13 + following a given probability.
15 + If you want to compile it as a module, say M here and read
16 + Documentation/modules.txt. If unsure, say `N'.
18 Netfilter MARK match support
19 CONFIG_IP_NF_MATCH_MARK
20 Netfilter mark matching allows you to match packets based on the
22 If you want to compile it as a module, say M here and read
23 Documentation/modules.txt. If unsure, say `Y'.
27 CONFIG_IP_NF_MATCH_TCPMSS
28 This option adds a `tcpmss' match, which allows you to examine the
29 @@ -3376,6 +3386,14 @@
30 If you want to compile it as a module, say M here and read
31 <file:Documentation/modules.txt>. If unsure, say `N'.
33 +CONFIG_IP6_NF_MATCH_RANDOM
34 + This option adds a `random' match,
35 + which allow you to match packets randomly
36 + following a given probability.
38 + If you want to compile it as a module, say M here and read
39 + Documentation/modules.txt. If unsure, say `N'.
42 CONFIG_IP6_NF_MATCH_LENGTH
43 This option allows you to match the length of a packet against a
44 Index: linux-2.4.35.4/include/linux/netfilter_ipv4/ipt_random.h
45 ===================================================================
46 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
47 +++ linux-2.4.35.4/include/linux/netfilter_ipv4/ipt_random.h 2007-12-15 05:20:12.264539159 +0100
52 +#include <linux/param.h>
53 +#include <linux/types.h>
55 +struct ipt_rand_info {
59 +#endif /*_IPT_RAND_H*/
60 Index: linux-2.4.35.4/include/linux/netfilter_ipv6/ip6t_random.h
61 ===================================================================
62 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
63 +++ linux-2.4.35.4/include/linux/netfilter_ipv6/ip6t_random.h 2007-12-15 05:20:12.272539617 +0100
68 +#include <linux/param.h>
69 +#include <linux/types.h>
71 +struct ip6t_rand_info {
75 +#endif /*_IP6T_RAND_H*/
76 Index: linux-2.4.35.4/net/ipv4/netfilter/Config.in
77 ===================================================================
78 --- linux-2.4.35.4.orig/net/ipv4/netfilter/Config.in 2007-12-15 05:20:11.960521836 +0100
79 +++ linux-2.4.35.4/net/ipv4/netfilter/Config.in 2007-12-15 05:20:12.276539844 +0100
81 dep_tristate ' netfilter MARK match support' CONFIG_IP_NF_MATCH_MARK $CONFIG_IP_NF_IPTABLES
82 dep_tristate ' Multiple port match support' CONFIG_IP_NF_MATCH_MULTIPORT $CONFIG_IP_NF_IPTABLES
83 dep_tristate ' TOS match support' CONFIG_IP_NF_MATCH_TOS $CONFIG_IP_NF_IPTABLES
84 + dep_tristate ' random match support' CONFIG_IP_NF_MATCH_RANDOM $CONFIG_IP_NF_IPTABLES
85 dep_tristate ' TIME match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_TIME $CONFIG_IP_NF_IPTABLES
86 dep_tristate ' condition match support' CONFIG_IP_NF_MATCH_CONDITION $CONFIG_IP_NF_IPTABLES
87 dep_tristate ' recent match support' CONFIG_IP_NF_MATCH_RECENT $CONFIG_IP_NF_IPTABLES
88 Index: linux-2.4.35.4/net/ipv4/netfilter/ipt_random.c
89 ===================================================================
90 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
91 +++ linux-2.4.35.4/net/ipv4/netfilter/ipt_random.c 2007-12-15 05:20:12.276539844 +0100
94 + This is a module which is used for a "random" match support.
95 + This file is distributed under the terms of the GNU General Public
96 + License (GPL). Copies of the GPL can be obtained from:
97 + ftp://prep.ai.mit.edu/pub/gnu/GPL
99 + 2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
102 +#include <linux/module.h>
103 +#include <linux/skbuff.h>
104 +#include <linux/ip.h>
105 +#include <linux/random.h>
106 +#include <net/tcp.h>
107 +#include <linux/spinlock.h>
108 +#include <linux/netfilter_ipv4/ip_tables.h>
109 +#include <linux/netfilter_ipv4/ipt_random.h>
111 +MODULE_LICENSE("GPL");
114 +ipt_rand_match(const struct sk_buff *pskb,
115 + const struct net_device *in,
116 + const struct net_device *out,
117 + const void *matchinfo,
123 + /* Parameters from userspace */
124 + const struct ipt_rand_info *info = matchinfo;
125 + u_int8_t random_number;
127 + /* get 1 random number from the kernel random number generation routine */
128 + get_random_bytes((void *)(&random_number), 1);
130 + /* Do we match ? */
131 + if (random_number <= info->average)
138 +ipt_rand_checkentry(const char *tablename,
139 + const struct ipt_ip *e,
141 + unsigned int matchsize,
142 + unsigned int hook_mask)
144 + /* Parameters from userspace */
145 + const struct ipt_rand_info *info = matchinfo;
147 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_rand_info))) {
148 + printk("ipt_random: matchsize %u != %u\n", matchsize,
149 + IPT_ALIGN(sizeof(struct ipt_rand_info)));
153 + /* must be 1 <= average % <= 99 */
155 + /* 99 x 2.55 = 252 */
156 + if ((info->average < 2) || (info->average > 252)) {
157 + printk("ipt_random: invalid average %u\n", info->average);
164 +static struct ipt_match ipt_rand_reg = {
168 + ipt_rand_checkentry,
172 +static int __init init(void)
174 + if (ipt_register_match(&ipt_rand_reg))
177 + printk("ipt_random match loaded\n");
181 +static void __exit fini(void)
183 + ipt_unregister_match(&ipt_rand_reg);
184 + printk("ipt_random match unloaded\n");
189 Index: linux-2.4.35.4/net/ipv4/netfilter/Makefile
190 ===================================================================
191 --- linux-2.4.35.4.orig/net/ipv4/netfilter/Makefile 2007-12-15 05:20:11.976522746 +0100
192 +++ linux-2.4.35.4/net/ipv4/netfilter/Makefile 2007-12-15 05:20:12.276539844 +0100
194 obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
195 obj-$(CONFIG_IP_NF_MATCH_CONDITION) += ipt_condition.o
197 +obj-$(CONFIG_IP_NF_MATCH_RANDOM) += ipt_random.o
199 obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o
201 obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
202 Index: linux-2.4.35.4/net/ipv6/netfilter/Config.in
203 ===================================================================
204 --- linux-2.4.35.4.orig/net/ipv6/netfilter/Config.in 2007-12-15 05:20:10.816456638 +0100
205 +++ linux-2.4.35.4/net/ipv6/netfilter/Config.in 2007-12-15 05:20:12.276539844 +0100
207 dep_tristate ' limit match support' CONFIG_IP6_NF_MATCH_LIMIT $CONFIG_IP6_NF_IPTABLES
208 dep_tristate ' condition match support' CONFIG_IP6_NF_MATCH_CONDITION $CONFIG_IP6_NF_IPTABLES
209 dep_tristate ' MAC address match support' CONFIG_IP6_NF_MATCH_MAC $CONFIG_IP6_NF_IPTABLES
210 + dep_tristate ' Random match support' CONFIG_IP6_NF_MATCH_RANDOM $CONFIG_IP6_NF_IPTABLES
211 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
212 dep_tristate ' Routing header match support (EXPERIMENTAL)' CONFIG_IP6_NF_MATCH_RT $CONFIG_IP6_NF_IPTABLES
214 Index: linux-2.4.35.4/net/ipv6/netfilter/ip6t_random.c
215 ===================================================================
216 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
217 +++ linux-2.4.35.4/net/ipv6/netfilter/ip6t_random.c 2007-12-15 05:20:12.276539844 +0100
220 + This is a module which is used for a "random" match support.
221 + This file is distributed under the terms of the GNU General Public
222 + License (GPL). Copies of the GPL can be obtained from:
223 + ftp://prep.ai.mit.edu/pub/gnu/GPL
225 + 2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
226 + 2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
229 +#include <linux/module.h>
230 +#include <linux/skbuff.h>
231 +#include <linux/ip.h>
232 +#include <linux/random.h>
233 +#include <net/tcp.h>
234 +#include <linux/spinlock.h>
235 +#include <linux/netfilter_ipv6/ip6_tables.h>
236 +#include <linux/netfilter_ipv6/ip6t_random.h>
238 +MODULE_LICENSE("GPL");
241 +ip6t_rand_match(const struct sk_buff *pskb,
242 + const struct net_device *in,
243 + const struct net_device *out,
244 + const void *matchinfo,
250 + /* Parameters from userspace */
251 + const struct ip6t_rand_info *info = matchinfo;
252 + u_int8_t random_number;
254 + /* get 1 random number from the kernel random number generation routine */
255 + get_random_bytes((void *)(&random_number), 1);
257 + /* Do we match ? */
258 + if (random_number <= info->average)
265 +ip6t_rand_checkentry(const char *tablename,
266 + const struct ip6t_ip6 *e,
268 + unsigned int matchsize,
269 + unsigned int hook_mask)
271 + /* Parameters from userspace */
272 + const struct ip6t_rand_info *info = matchinfo;
274 + if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_rand_info))) {
275 + printk("ip6t_random: matchsize %u != %u\n", matchsize,
276 + IP6T_ALIGN(sizeof(struct ip6t_rand_info)));
280 + /* must be 1 <= average % <= 99 */
282 + /* 99 x 2.55 = 252 */
283 + if ((info->average < 2) || (info->average > 252)) {
284 + printk("ip6t_random: invalid average %u\n", info->average);
291 +static struct ip6t_match ip6t_rand_reg = {
295 + ip6t_rand_checkentry,
299 +static int __init init(void)
301 + if (ip6t_register_match(&ip6t_rand_reg))
304 + printk("ip6t_random match loaded\n");
308 +static void __exit fini(void)
310 + ip6t_unregister_match(&ip6t_rand_reg);
311 + printk("ip6t_random match unloaded\n");
316 Index: linux-2.4.35.4/net/ipv6/netfilter/Makefile
317 ===================================================================
318 --- linux-2.4.35.4.orig/net/ipv6/netfilter/Makefile 2007-12-15 05:20:10.816456638 +0100
319 +++ linux-2.4.35.4/net/ipv6/netfilter/Makefile 2007-12-15 05:20:12.280540069 +0100
321 obj-$(CONFIG_IP6_NF_TARGET_IMQ) += ip6t_IMQ.o
322 obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
323 obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
324 +obj-$(CONFIG_IP6_NF_MATCH_RANDOM) += ip6t_random.o
325 obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
327 include $(TOPDIR)/Rules.make