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("Xtables: arbitrary IPv4 range matching");
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
,
26 const struct ipt_iprange_info
*info
= matchinfo
;
27 const struct iphdr
*iph
= ip_hdr(skb
);
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",
36 info
->flags
& IPRANGE_SRC_INV
? "(INV) " : "",
37 NIPQUAD(info
->src
.min_ip
),
38 NIPQUAD(info
->src
.max_ip
));
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",
49 info
->flags
& IPRANGE_DST_INV
? "(INV) " : "",
50 NIPQUAD(info
->dst
.min_ip
),
51 NIPQUAD(info
->dst
.max_ip
));
58 static struct xt_match iprange_mt_reg __read_mostly
= {
62 .matchsize
= sizeof(struct ipt_iprange_info
),
66 static int __init
iprange_mt_init(void)
68 return xt_register_match(&iprange_mt_reg
);
71 static void __exit
iprange_mt_exit(void)
73 xt_unregister_match(&iprange_mt_reg
);
76 module_init(iprange_mt_init
);
77 module_exit(iprange_mt_exit
);