2005-04-16 22:20:36 +00:00
|
|
|
/* IP tables module for matching the value of the IPv4 and TCP ECN bits
|
|
|
|
*
|
|
|
|
* ipt_ecn.c,v 1.3 2002/05/29 15:09:00 laforge Exp
|
|
|
|
*
|
|
|
|
* (C) 2002 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
|
|
|
|
#include <linux/netfilter_ipv4/ip_tables.h>
|
|
|
|
#include <linux/netfilter_ipv4/ipt_ecn.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
|
|
|
|
MODULE_DESCRIPTION("iptables ECN matching module");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static inline int match_ip(const struct sk_buff *skb,
|
|
|
|
const struct ipt_ecn_info *einfo)
|
|
|
|
{
|
|
|
|
return ((skb->nh.iph->tos&IPT_ECN_IP_MASK) == einfo->ip_ect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int match_tcp(const struct sk_buff *skb,
|
|
|
|
const struct ipt_ecn_info *einfo,
|
|
|
|
int *hotdrop)
|
|
|
|
{
|
|
|
|
struct tcphdr _tcph, *th;
|
|
|
|
|
|
|
|
/* In practice, TCP match does this, so can't fail. But let's
|
|
|
|
* be good citizens.
|
|
|
|
*/
|
|
|
|
th = skb_header_pointer(skb, skb->nh.iph->ihl * 4,
|
|
|
|
sizeof(_tcph), &_tcph);
|
|
|
|
if (th == NULL) {
|
|
|
|
*hotdrop = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (einfo->operation & IPT_ECN_OP_MATCH_ECE) {
|
|
|
|
if (einfo->invert & IPT_ECN_OP_MATCH_ECE) {
|
|
|
|
if (th->ece == 1)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
if (th->ece == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (einfo->operation & IPT_ECN_OP_MATCH_CWR) {
|
|
|
|
if (einfo->invert & IPT_ECN_OP_MATCH_CWR) {
|
|
|
|
if (th->cwr == 1)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
if (th->cwr == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-21 02:02:56 +00:00
|
|
|
static int match(const struct sk_buff *skb,
|
|
|
|
const struct net_device *in, const struct net_device *out,
|
|
|
|
const struct xt_match *match, const void *matchinfo,
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
int offset, unsigned int protoff, int *hotdrop)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
const struct ipt_ecn_info *info = matchinfo;
|
|
|
|
|
|
|
|
if (info->operation & IPT_ECN_OP_MATCH_IP)
|
|
|
|
if (!match_ip(skb, info))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) {
|
|
|
|
if (skb->nh.iph->protocol != IPPROTO_TCP)
|
|
|
|
return 0;
|
|
|
|
if (!match_tcp(skb, info, hotdrop))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
static int checkentry(const char *tablename, const void *ip_void,
|
2006-03-21 02:02:56 +00:00
|
|
|
const struct xt_match *match,
|
2006-08-22 07:36:37 +00:00
|
|
|
void *matchinfo, unsigned int hook_mask)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
const struct ipt_ecn_info *info = matchinfo;
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
const struct ipt_ip *ip = ip_void;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (info->operation & IPT_ECN_OP_MATCH_MASK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (info->invert & IPT_ECN_OP_MATCH_MASK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)
|
|
|
|
&& ip->proto != IPPROTO_TCP) {
|
|
|
|
printk(KERN_WARNING "ipt_ecn: can't match TCP bits in rule for"
|
|
|
|
" non-tcp packets\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ipt_match ecn_match = {
|
|
|
|
.name = "ecn",
|
2006-03-21 02:01:14 +00:00
|
|
|
.match = match,
|
|
|
|
.matchsize = sizeof(struct ipt_ecn_info),
|
|
|
|
.checkentry = checkentry,
|
2005-04-16 22:20:36 +00:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2006-03-29 00:37:06 +00:00
|
|
|
static int __init ipt_ecn_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
return ipt_register_match(&ecn_match);
|
|
|
|
}
|
|
|
|
|
2006-03-29 00:37:06 +00:00
|
|
|
static void __exit ipt_ecn_fini(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
ipt_unregister_match(&ecn_match);
|
|
|
|
}
|
|
|
|
|
2006-03-29 00:37:06 +00:00
|
|
|
module_init(ipt_ecn_init);
|
|
|
|
module_exit(ipt_ecn_fini);
|