]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
6709dbbb | 19 | #include <linux/netfilter/x_tables.h> |
1da177e4 LT |
20 | |
21 | MODULE_LICENSE("GPL"); | |
22 | MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); | |
23 | MODULE_DESCRIPTION("iptables addrtype match"); | |
24 | ||
1d93a9cb | 25 | static inline bool match_type(__be32 addr, u_int16_t mask) |
1da177e4 LT |
26 | { |
27 | return !!(mask & (1 << inet_addr_type(addr))); | |
28 | } | |
29 | ||
d3c5ee6d JE |
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) | |
1da177e4 LT |
35 | { |
36 | const struct ipt_addrtype_info *info = matchinfo; | |
eddc9ec5 | 37 | const struct iphdr *iph = ip_hdr(skb); |
1d93a9cb | 38 | bool ret = true; |
1da177e4 LT |
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; | |
e905a9ed | 44 | |
1da177e4 LT |
45 | return ret; |
46 | } | |
47 | ||
d3c5ee6d | 48 | static struct xt_match addrtype_mt_reg __read_mostly = { |
1da177e4 | 49 | .name = "addrtype", |
6709dbbb | 50 | .family = AF_INET, |
d3c5ee6d | 51 | .match = addrtype_mt, |
1d5cd909 | 52 | .matchsize = sizeof(struct ipt_addrtype_info), |
1da177e4 LT |
53 | .me = THIS_MODULE |
54 | }; | |
55 | ||
d3c5ee6d | 56 | static int __init addrtype_mt_init(void) |
1da177e4 | 57 | { |
d3c5ee6d | 58 | return xt_register_match(&addrtype_mt_reg); |
1da177e4 LT |
59 | } |
60 | ||
d3c5ee6d | 61 | static void __exit addrtype_mt_exit(void) |
1da177e4 | 62 | { |
d3c5ee6d | 63 | xt_unregister_match(&addrtype_mt_reg); |
1da177e4 LT |
64 | } |
65 | ||
d3c5ee6d JE |
66 | module_init(addrtype_mt_init); |
67 | module_exit(addrtype_mt_exit); |