2 * iptables module to match inet_addr_type() of an ip.
4 * Copyright (c) 2004 Patrick McHardy <kaber@trash.net>
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.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
16 #include <net/route.h>
18 #include <linux/netfilter_ipv4/ipt_addrtype.h>
19 #include <linux/netfilter/x_tables.h>
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
23 MODULE_DESCRIPTION("iptables addrtype match");
25 static inline bool match_type(__be32 addr
, u_int16_t mask
)
27 return !!(mask
& (1 << inet_addr_type(addr
)));
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
,
36 const struct ipt_addrtype_info
*info
= matchinfo
;
37 const struct iphdr
*iph
= ip_hdr(skb
);
41 ret
&= match_type(iph
->saddr
, info
->source
)^info
->invert_source
;
43 ret
&= match_type(iph
->daddr
, info
->dest
)^info
->invert_dest
;
48 static struct xt_match addrtype_mt_reg __read_mostly
= {
52 .matchsize
= sizeof(struct ipt_addrtype_info
),
56 static int __init
addrtype_mt_init(void)
58 return xt_register_match(&addrtype_mt_reg
);
61 static void __exit
addrtype_mt_exit(void)
63 xt_unregister_match(&addrtype_mt_reg
);
66 module_init(addrtype_mt_init
);
67 module_exit(addrtype_mt_exit
);