5 * Bart De Schuymer <bdschuym@pandora.be>
10 * added ip-sport and ip-dport
11 * Innominate Security Technologies AG <mhopf@innominate.com>
15 #include <linux/netfilter_bridge/ebtables.h>
16 #include <linux/netfilter_bridge/ebt_ip.h>
20 #include <linux/module.h>
27 static int ebt_filter_ip(const struct sk_buff
*skb
, const struct net_device
*in
,
28 const struct net_device
*out
, const void *data
,
31 const struct ebt_ip_info
*info
= data
;
32 const struct iphdr
*ih
;
34 const struct tcpudphdr
*pptr
;
35 struct tcpudphdr _ports
;
37 ih
= skb_header_pointer(skb
, 0, sizeof(_iph
), &_iph
);
40 if (info
->bitmask
& EBT_IP_TOS
&&
41 FWINV(info
->tos
!= ih
->tos
, EBT_IP_TOS
))
43 if (info
->bitmask
& EBT_IP_SOURCE
&&
44 FWINV((ih
->saddr
& info
->smsk
) !=
45 info
->saddr
, EBT_IP_SOURCE
))
47 if ((info
->bitmask
& EBT_IP_DEST
) &&
48 FWINV((ih
->daddr
& info
->dmsk
) !=
49 info
->daddr
, EBT_IP_DEST
))
51 if (info
->bitmask
& EBT_IP_PROTO
) {
52 if (FWINV(info
->protocol
!= ih
->protocol
, EBT_IP_PROTO
))
54 if (!(info
->bitmask
& EBT_IP_DPORT
) &&
55 !(info
->bitmask
& EBT_IP_SPORT
))
57 if (ntohs(ih
->frag_off
) & IP_OFFSET
)
59 pptr
= skb_header_pointer(skb
, ih
->ihl
*4,
60 sizeof(_ports
), &_ports
);
63 if (info
->bitmask
& EBT_IP_DPORT
) {
64 u32 dst
= ntohs(pptr
->dst
);
65 if (FWINV(dst
< info
->dport
[0] ||
70 if (info
->bitmask
& EBT_IP_SPORT
) {
71 u32 src
= ntohs(pptr
->src
);
72 if (FWINV(src
< info
->sport
[0] ||
81 static int ebt_ip_check(const char *tablename
, unsigned int hookmask
,
82 const struct ebt_entry
*e
, void *data
, unsigned int datalen
)
84 const struct ebt_ip_info
*info
= data
;
86 if (datalen
!= EBT_ALIGN(sizeof(struct ebt_ip_info
)))
88 if (e
->ethproto
!= htons(ETH_P_IP
) ||
89 e
->invflags
& EBT_IPROTO
)
91 if (info
->bitmask
& ~EBT_IP_MASK
|| info
->invflags
& ~EBT_IP_MASK
)
93 if (info
->bitmask
& (EBT_IP_DPORT
| EBT_IP_SPORT
)) {
94 if (info
->invflags
& EBT_IP_PROTO
)
96 if (info
->protocol
!= IPPROTO_TCP
&&
97 info
->protocol
!= IPPROTO_UDP
&&
98 info
->protocol
!= IPPROTO_UDPLITE
&&
99 info
->protocol
!= IPPROTO_SCTP
&&
100 info
->protocol
!= IPPROTO_DCCP
)
103 if (info
->bitmask
& EBT_IP_DPORT
&& info
->dport
[0] > info
->dport
[1])
105 if (info
->bitmask
& EBT_IP_SPORT
&& info
->sport
[0] > info
->sport
[1])
110 static struct ebt_match filter_ip __read_mostly
= {
111 .name
= EBT_IP_MATCH
,
112 .match
= ebt_filter_ip
,
113 .check
= ebt_ip_check
,
117 static int __init
ebt_ip_init(void)
119 return ebt_register_match(&filter_ip
);
122 static void __exit
ebt_ip_fini(void)
124 ebt_unregister_match(&filter_ip
);
127 module_init(ebt_ip_init
);
128 module_exit(ebt_ip_fini
);
129 MODULE_DESCRIPTION("Ebtables: IPv4 protocol packet match");
130 MODULE_LICENSE("GPL");