[NETFILTER]: x_tables: consistent and unique symbol names
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / ipv4 / netfilter / ipt_addrtype.c
1 /*
2 * iptables module to match inet_addr_type() of an ip.
3 *
4 * Copyright (c) 2004 Patrick McHardy <kaber@trash.net>
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
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
15 #include <linux/ip.h>
16 #include <net/route.h>
17
18 #include <linux/netfilter_ipv4/ipt_addrtype.h>
19 #include <linux/netfilter/x_tables.h>
20
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
23 MODULE_DESCRIPTION("iptables addrtype match");
24
25 static inline bool match_type(__be32 addr, u_int16_t mask)
26 {
27 return !!(mask & (1 << inet_addr_type(addr)));
28 }
29
30 static bool
31 addrtype_mt(const struct sk_buff *skb, const struct net_device *in,
32 const struct net_device *out, const struct xt_match *match,
33 const void *matchinfo, int offset, unsigned int protoff,
34 bool *hotdrop)
35 {
36 const struct ipt_addrtype_info *info = matchinfo;
37 const struct iphdr *iph = ip_hdr(skb);
38 bool ret = true;
39
40 if (info->source)
41 ret &= match_type(iph->saddr, info->source)^info->invert_source;
42 if (info->dest)
43 ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
44
45 return ret;
46 }
47
48 static struct xt_match addrtype_mt_reg __read_mostly = {
49 .name = "addrtype",
50 .family = AF_INET,
51 .match = addrtype_mt,
52 .matchsize = sizeof(struct ipt_addrtype_info),
53 .me = THIS_MODULE
54 };
55
56 static int __init addrtype_mt_init(void)
57 {
58 return xt_register_match(&addrtype_mt_reg);
59 }
60
61 static void __exit addrtype_mt_exit(void)
62 {
63 xt_unregister_match(&addrtype_mt_reg);
64 }
65
66 module_init(addrtype_mt_init);
67 module_exit(addrtype_mt_exit);