bc5d5e6091e476bf58fb79bfe886a1e44f876f71
2 * iptables module to match IP address ranges
4 * (C) 2003 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.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
13 #include <linux/netfilter/x_tables.h>
14 #include <linux/netfilter_ipv4/ipt_iprange.h>
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
18 MODULE_DESCRIPTION("iptables arbitrary IP range match module");
23 #define DEBUGP(format, args...)
27 match(const struct sk_buff
*skb
,
28 const struct net_device
*in
,
29 const struct net_device
*out
,
30 const struct xt_match
*match
,
31 const void *matchinfo
,
32 int offset
, unsigned int protoff
, int *hotdrop
)
34 const struct ipt_iprange_info
*info
= matchinfo
;
35 const struct iphdr
*iph
= skb
->nh
.iph
;
37 if (info
->flags
& IPRANGE_SRC
) {
38 if (((ntohl(iph
->saddr
) < ntohl(info
->src
.min_ip
))
39 || (ntohl(iph
->saddr
) > ntohl(info
->src
.max_ip
)))
40 ^ !!(info
->flags
& IPRANGE_SRC_INV
)) {
41 DEBUGP("src IP %u.%u.%u.%u NOT in range %s"
42 "%u.%u.%u.%u-%u.%u.%u.%u\n",
44 info
->flags
& IPRANGE_SRC_INV
? "(INV) " : "",
45 NIPQUAD(info
->src
.min_ip
),
46 NIPQUAD(info
->src
.max_ip
));
50 if (info
->flags
& IPRANGE_DST
) {
51 if (((ntohl(iph
->daddr
) < ntohl(info
->dst
.min_ip
))
52 || (ntohl(iph
->daddr
) > ntohl(info
->dst
.max_ip
)))
53 ^ !!(info
->flags
& IPRANGE_DST_INV
)) {
54 DEBUGP("dst IP %u.%u.%u.%u NOT in range %s"
55 "%u.%u.%u.%u-%u.%u.%u.%u\n",
57 info
->flags
& IPRANGE_DST_INV
? "(INV) " : "",
58 NIPQUAD(info
->dst
.min_ip
),
59 NIPQUAD(info
->dst
.max_ip
));
66 static struct xt_match iprange_match
= {
70 .matchsize
= sizeof(struct ipt_iprange_info
),
74 static int __init
ipt_iprange_init(void)
76 return xt_register_match(&iprange_match
);
79 static void __exit
ipt_iprange_fini(void)
81 xt_unregister_match(&iprange_match
);
84 module_init(ipt_iprange_init
);
85 module_exit(ipt_iprange_fini
);
This page took 0.038495 seconds and 5 git commands to generate.