]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/ipv4/netfilter/ipt_addrtype.c
[IPV4]: inet_addr_type() annotations
[net-next-2.6.git] / net / ipv4 / netfilter / ipt_addrtype.c
CommitLineData
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>
19#include <linux/netfilter_ipv4/ip_tables.h>
20
21MODULE_LICENSE("GPL");
22MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
23MODULE_DESCRIPTION("iptables addrtype match");
24
fd683222 25static inline int match_type(__be32 addr, u_int16_t mask)
1da177e4
LT
26{
27 return !!(mask & (1 << inet_addr_type(addr)));
28}
29
c4986734
PM
30static int 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,
2e4e6a17 33 int offset, unsigned int protoff, int *hotdrop)
1da177e4
LT
34{
35 const struct ipt_addrtype_info *info = matchinfo;
36 const struct iphdr *iph = skb->nh.iph;
37 int ret = 1;
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
1da177e4
LT
47static struct ipt_match addrtype_match = {
48 .name = "addrtype",
49 .match = match,
1d5cd909 50 .matchsize = sizeof(struct ipt_addrtype_info),
1da177e4
LT
51 .me = THIS_MODULE
52};
53
65b4b4e8 54static int __init ipt_addrtype_init(void)
1da177e4
LT
55{
56 return ipt_register_match(&addrtype_match);
57}
58
65b4b4e8 59static void __exit ipt_addrtype_fini(void)
1da177e4
LT
60{
61 ipt_unregister_match(&addrtype_match);
62}
63
65b4b4e8
AM
64module_init(ipt_addrtype_init);
65module_exit(ipt_addrtype_fini);