2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* ebt_ip
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
|
|
*
|
|
|
|
* April, 2002
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* added ip-sport and ip-dport
|
|
|
|
* Innominate Security Technologies AG <mhopf@innominate.com>
|
|
|
|
* September, 2002
|
|
|
|
*/
|
|
|
|
#include <linux/ip.h>
|
2006-01-10 14:12:22 -07:00
|
|
|
#include <net/ip.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/module.h>
|
2008-10-08 03:35:13 -06:00
|
|
|
#include <linux/netfilter/x_tables.h>
|
|
|
|
#include <linux/netfilter_bridge/ebtables.h>
|
|
|
|
#include <linux/netfilter_bridge/ebt_ip.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
struct tcpudphdr {
|
2006-11-14 22:11:51 -07:00
|
|
|
__be16 src;
|
|
|
|
__be16 dst;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2008-10-08 03:35:15 -06:00
|
|
|
static bool
|
2008-10-08 03:35:18 -06:00
|
|
|
ebt_ip_mt(const struct sk_buff *skb, const struct xt_match_param *par)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:18 -06:00
|
|
|
const struct ebt_ip_info *info = par->matchinfo;
|
2008-01-31 04:59:24 -07:00
|
|
|
const struct iphdr *ih;
|
|
|
|
struct iphdr _iph;
|
|
|
|
const struct tcpudphdr *pptr;
|
|
|
|
struct tcpudphdr _ports;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
|
|
|
|
if (ih == NULL)
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->bitmask & EBT_IP_TOS &&
|
|
|
|
FWINV(info->tos != ih->tos, EBT_IP_TOS))
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->bitmask & EBT_IP_SOURCE &&
|
|
|
|
FWINV((ih->saddr & info->smsk) !=
|
|
|
|
info->saddr, EBT_IP_SOURCE))
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if ((info->bitmask & EBT_IP_DEST) &&
|
|
|
|
FWINV((ih->daddr & info->dmsk) !=
|
|
|
|
info->daddr, EBT_IP_DEST))
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->bitmask & EBT_IP_PROTO) {
|
|
|
|
if (FWINV(info->protocol != ih->protocol, EBT_IP_PROTO))
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!(info->bitmask & EBT_IP_DPORT) &&
|
|
|
|
!(info->bitmask & EBT_IP_SPORT))
|
2008-10-08 03:35:13 -06:00
|
|
|
return true;
|
2006-01-10 14:12:22 -07:00
|
|
|
if (ntohs(ih->frag_off) & IP_OFFSET)
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
pptr = skb_header_pointer(skb, ih->ihl*4,
|
|
|
|
sizeof(_ports), &_ports);
|
|
|
|
if (pptr == NULL)
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->bitmask & EBT_IP_DPORT) {
|
|
|
|
u32 dst = ntohs(pptr->dst);
|
|
|
|
if (FWINV(dst < info->dport[0] ||
|
2007-02-09 07:24:35 -07:00
|
|
|
dst > info->dport[1],
|
|
|
|
EBT_IP_DPORT))
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
if (info->bitmask & EBT_IP_SPORT) {
|
|
|
|
u32 src = ntohs(pptr->src);
|
|
|
|
if (FWINV(src < info->sport[0] ||
|
2007-02-09 07:24:35 -07:00
|
|
|
src > info->sport[1],
|
|
|
|
EBT_IP_SPORT))
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2008-10-08 03:35:13 -06:00
|
|
|
return true;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-10-08 03:35:18 -06:00
|
|
|
static bool ebt_ip_mt_check(const struct xt_mtchk_param *par)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:18 -06:00
|
|
|
const struct ebt_ip_info *info = par->matchinfo;
|
|
|
|
const struct ebt_entry *e = par->entryinfo;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (e->ethproto != htons(ETH_P_IP) ||
|
|
|
|
e->invflags & EBT_IPROTO)
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
|
|
|
|
if (info->invflags & EBT_IP_PROTO)
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->protocol != IPPROTO_TCP &&
|
2006-01-17 14:01:31 -07:00
|
|
|
info->protocol != IPPROTO_UDP &&
|
2007-02-07 16:07:43 -07:00
|
|
|
info->protocol != IPPROTO_UDPLITE &&
|
2006-01-17 14:01:31 -07:00
|
|
|
info->protocol != IPPROTO_SCTP &&
|
|
|
|
info->protocol != IPPROTO_DCCP)
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
|
2008-10-08 03:35:13 -06:00
|
|
|
return false;
|
|
|
|
return true;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-10-08 03:35:15 -06:00
|
|
|
static struct xt_match ebt_ip_mt_reg __read_mostly = {
|
|
|
|
.name = "ip",
|
2008-10-08 03:35:14 -06:00
|
|
|
.revision = 0,
|
|
|
|
.family = NFPROTO_BRIDGE,
|
2008-10-08 03:35:15 -06:00
|
|
|
.match = ebt_ip_mt,
|
|
|
|
.checkentry = ebt_ip_mt_check,
|
2010-02-15 10:16:26 -07:00
|
|
|
.matchsize = sizeof(struct ebt_ip_info),
|
2005-04-16 16:20:36 -06:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static int __init ebt_ip_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:15 -06:00
|
|
|
return xt_register_match(&ebt_ip_mt_reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static void __exit ebt_ip_fini(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:15 -06:00
|
|
|
xt_unregister_match(&ebt_ip_mt_reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
module_init(ebt_ip_init);
|
|
|
|
module_exit(ebt_ip_fini);
|
2008-01-31 05:00:30 -07:00
|
|
|
MODULE_DESCRIPTION("Ebtables: IPv4 protocol packet match");
|
2005-04-16 16:20:36 -06:00
|
|
|
MODULE_LICENSE("GPL");
|