]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - net/ipv4/netfilter/ipt_addrtype.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/holtmann/bluetooth-2.6
[mirror_ubuntu-bionic-kernel.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 match(const struct sk_buff *skb,
31 const struct net_device *in, const struct net_device *out,
32 const struct xt_match *match, const void *matchinfo,
33 int offset, unsigned int protoff, bool *hotdrop)
34 {
35 const struct ipt_addrtype_info *info = matchinfo;
36 const struct iphdr *iph = ip_hdr(skb);
37 bool ret = true;
38
39 if (info->source)
40 ret &= match_type(iph->saddr, info->source)^info->invert_source;
41 if (info->dest)
42 ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
43
44 return ret;
45 }
46
47 static struct xt_match addrtype_match __read_mostly = {
48 .name = "addrtype",
49 .family = AF_INET,
50 .match = match,
51 .matchsize = sizeof(struct ipt_addrtype_info),
52 .me = THIS_MODULE
53 };
54
55 static int __init ipt_addrtype_init(void)
56 {
57 return xt_register_match(&addrtype_match);
58 }
59
60 static void __exit ipt_addrtype_fini(void)
61 {
62 xt_unregister_match(&addrtype_match);
63 }
64
65 module_init(ipt_addrtype_init);
66 module_exit(ipt_addrtype_fini);