]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - net/ipv4/netfilter/ipt_iprange.c
Pull ec into release branch
[linux-2.6-omap-h63xx.git] / net / ipv4 / netfilter / ipt_iprange.c
1 /*
2  * iptables module to match IP address ranges
3  *
4  * (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5  *
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.
9  */
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/ip.h>
13 #include <linux/netfilter/x_tables.h>
14 #include <linux/netfilter_ipv4/ipt_iprange.h>
15
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
18 MODULE_DESCRIPTION("iptables arbitrary IP range match module");
19
20 static bool
21 match(const struct sk_buff *skb,
22       const struct net_device *in,
23       const struct net_device *out,
24       const struct xt_match *match,
25       const void *matchinfo,
26       int offset, unsigned int protoff, bool *hotdrop)
27 {
28         const struct ipt_iprange_info *info = matchinfo;
29         const struct iphdr *iph = ip_hdr(skb);
30
31         if (info->flags & IPRANGE_SRC) {
32                 if ((ntohl(iph->saddr) < ntohl(info->src.min_ip)
33                           || ntohl(iph->saddr) > ntohl(info->src.max_ip))
34                          ^ !!(info->flags & IPRANGE_SRC_INV)) {
35                         pr_debug("src IP %u.%u.%u.%u NOT in range %s"
36                                  "%u.%u.%u.%u-%u.%u.%u.%u\n",
37                                  NIPQUAD(iph->saddr),
38                                  info->flags & IPRANGE_SRC_INV ? "(INV) " : "",
39                                  NIPQUAD(info->src.min_ip),
40                                  NIPQUAD(info->src.max_ip));
41                         return false;
42                 }
43         }
44         if (info->flags & IPRANGE_DST) {
45                 if ((ntohl(iph->daddr) < ntohl(info->dst.min_ip)
46                           || ntohl(iph->daddr) > ntohl(info->dst.max_ip))
47                          ^ !!(info->flags & IPRANGE_DST_INV)) {
48                         pr_debug("dst IP %u.%u.%u.%u NOT in range %s"
49                                  "%u.%u.%u.%u-%u.%u.%u.%u\n",
50                                  NIPQUAD(iph->daddr),
51                                  info->flags & IPRANGE_DST_INV ? "(INV) " : "",
52                                  NIPQUAD(info->dst.min_ip),
53                                  NIPQUAD(info->dst.max_ip));
54                         return false;
55                 }
56         }
57         return true;
58 }
59
60 static struct xt_match iprange_match __read_mostly = {
61         .name           = "iprange",
62         .family         = AF_INET,
63         .match          = match,
64         .matchsize      = sizeof(struct ipt_iprange_info),
65         .me             = THIS_MODULE
66 };
67
68 static int __init ipt_iprange_init(void)
69 {
70         return xt_register_match(&iprange_match);
71 }
72
73 static void __exit ipt_iprange_fini(void)
74 {
75         xt_unregister_match(&iprange_match);
76 }
77
78 module_init(ipt_iprange_init);
79 module_exit(ipt_iprange_fini);