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>
19 #include <linux/module.h>
26 static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
27 const struct net_device *out, const void *data,
30 struct ebt_ip_info *info = (struct ebt_ip_info *)data;
31 struct iphdr _iph, *ih;
32 struct tcpudphdr _ports, *pptr;
34 ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
37 if (info->bitmask & EBT_IP_TOS &&
38 FWINV(info->tos != ih->tos, EBT_IP_TOS))
40 if (info->bitmask & EBT_IP_SOURCE &&
41 FWINV((ih->saddr & info->smsk) !=
42 info->saddr, EBT_IP_SOURCE))
44 if ((info->bitmask & EBT_IP_DEST) &&
45 FWINV((ih->daddr & info->dmsk) !=
46 info->daddr, EBT_IP_DEST))
48 if (info->bitmask & EBT_IP_PROTO) {
49 if (FWINV(info->protocol != ih->protocol, EBT_IP_PROTO))
51 if (!(info->bitmask & EBT_IP_DPORT) &&
52 !(info->bitmask & EBT_IP_SPORT))
54 pptr = skb_header_pointer(skb, ih->ihl*4,
55 sizeof(_ports), &_ports);
58 if (info->bitmask & EBT_IP_DPORT) {
59 u32 dst = ntohs(pptr->dst);
60 if (FWINV(dst < info->dport[0] ||
65 if (info->bitmask & EBT_IP_SPORT) {
66 u32 src = ntohs(pptr->src);
67 if (FWINV(src < info->sport[0] ||
76 static int ebt_ip_check(const char *tablename, unsigned int hookmask,
77 const struct ebt_entry *e, void *data, unsigned int datalen)
79 struct ebt_ip_info *info = (struct ebt_ip_info *)data;
81 if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
83 if (e->ethproto != htons(ETH_P_IP) ||
84 e->invflags & EBT_IPROTO)
86 if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
88 if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
89 if (info->invflags & EBT_IP_PROTO)
91 if (info->protocol != IPPROTO_TCP &&
92 info->protocol != IPPROTO_UDP)
95 if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
97 if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
102 static struct ebt_match filter_ip =
104 .name = EBT_IP_MATCH,
105 .match = ebt_filter_ip,
106 .check = ebt_ip_check,
110 static int __init init(void)
112 return ebt_register_match(&filter_ip);
115 static void __exit fini(void)
117 ebt_unregister_match(&filter_ip);
122 MODULE_LICENSE("GPL");