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_ipv4/ip_tables.h>
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
23 MODULE_DESCRIPTION("iptables addrtype match");
25 static inline int match_type(u_int32_t addr
, u_int16_t mask
)
27 return !!(mask
& (1 << inet_addr_type(addr
)));
30 static int match(const struct sk_buff
*skb
, const struct net_device
*in
,
31 const struct net_device
*out
, const void *matchinfo
,
32 int offset
, unsigned int protoff
, int *hotdrop
)
34 const struct ipt_addrtype_info
*info
= matchinfo
;
35 const struct iphdr
*iph
= skb
->nh
.iph
;
39 ret
&= match_type(iph
->saddr
, info
->source
)^info
->invert_source
;
41 ret
&= match_type(iph
->daddr
, info
->dest
)^info
->invert_dest
;
46 static int checkentry(const char *tablename
, const void *ip
,
47 void *matchinfo
, unsigned int matchsize
,
48 unsigned int hook_mask
)
50 if (matchsize
!= IPT_ALIGN(sizeof(struct ipt_addrtype_info
))) {
51 printk(KERN_ERR
"ipt_addrtype: invalid size (%u != %Zu)\n",
52 matchsize
, IPT_ALIGN(sizeof(struct ipt_addrtype_info
)));
59 static struct ipt_match addrtype_match
= {
62 .checkentry
= checkentry
,
66 static int __init
init(void)
68 return ipt_register_match(&addrtype_match
);
71 static void __exit
fini(void)
73 ipt_unregister_match(&addrtype_match
);