]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/ipv4/netfilter/ipt_iprange.c
[NETFILTER]: Update modules' descriptions
[mirror_ubuntu-artful-kernel.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("Xtables: arbitrary IPv4 range matching");
19
20 static bool
21 iprange_mt(const struct sk_buff *skb, const struct net_device *in,
22 const struct net_device *out, const struct xt_match *match,
23 const void *matchinfo, int offset, unsigned int protoff,
24 bool *hotdrop)
25 {
26 const struct ipt_iprange_info *info = matchinfo;
27 const struct iphdr *iph = ip_hdr(skb);
28
29 if (info->flags & IPRANGE_SRC) {
30 if ((ntohl(iph->saddr) < ntohl(info->src.min_ip)
31 || ntohl(iph->saddr) > ntohl(info->src.max_ip))
32 ^ !!(info->flags & IPRANGE_SRC_INV)) {
33 pr_debug("src IP %u.%u.%u.%u NOT in range %s"
34 "%u.%u.%u.%u-%u.%u.%u.%u\n",
35 NIPQUAD(iph->saddr),
36 info->flags & IPRANGE_SRC_INV ? "(INV) " : "",
37 NIPQUAD(info->src.min_ip),
38 NIPQUAD(info->src.max_ip));
39 return false;
40 }
41 }
42 if (info->flags & IPRANGE_DST) {
43 if ((ntohl(iph->daddr) < ntohl(info->dst.min_ip)
44 || ntohl(iph->daddr) > ntohl(info->dst.max_ip))
45 ^ !!(info->flags & IPRANGE_DST_INV)) {
46 pr_debug("dst IP %u.%u.%u.%u NOT in range %s"
47 "%u.%u.%u.%u-%u.%u.%u.%u\n",
48 NIPQUAD(iph->daddr),
49 info->flags & IPRANGE_DST_INV ? "(INV) " : "",
50 NIPQUAD(info->dst.min_ip),
51 NIPQUAD(info->dst.max_ip));
52 return false;
53 }
54 }
55 return true;
56 }
57
58 static struct xt_match iprange_mt_reg __read_mostly = {
59 .name = "iprange",
60 .family = AF_INET,
61 .match = iprange_mt,
62 .matchsize = sizeof(struct ipt_iprange_info),
63 .me = THIS_MODULE
64 };
65
66 static int __init iprange_mt_init(void)
67 {
68 return xt_register_match(&iprange_mt_reg);
69 }
70
71 static void __exit iprange_mt_exit(void)
72 {
73 xt_unregister_match(&iprange_mt_reg);
74 }
75
76 module_init(iprange_mt_init);
77 module_exit(iprange_mt_exit);