2005-04-17 00:20:36 +02:00
|
|
|
/* Kernel module to match TCP MSS values. */
|
|
|
|
|
|
|
|
/* Copyright (C) 2000 Marc Boucher <marc@mbsi.ca>
|
[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 22:30:04 +01:00
|
|
|
* Portions (C) 2005 by Harald Welte <laforge@netfilter.org>
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* 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 <net/tcp.h>
|
|
|
|
|
[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 22:30:04 +01:00
|
|
|
#include <linux/netfilter/xt_tcpmss.h>
|
|
|
|
#include <linux/netfilter/x_tables.h>
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/netfilter_ipv4/ip_tables.h>
|
[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 22:30:04 +01:00
|
|
|
#include <linux/netfilter_ipv6/ip6_tables.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
|
|
|
|
MODULE_DESCRIPTION("iptables TCP MSS match module");
|
[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 22:30:04 +01:00
|
|
|
MODULE_ALIAS("ipt_tcpmss");
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-08-22 09:44:14 +02: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,
|
|
|
|
int offset,
|
|
|
|
unsigned int protoff,
|
|
|
|
int *hotdrop)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-08-22 09:44:14 +02:00
|
|
|
const struct xt_tcpmss_match_info *info = matchinfo;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct tcphdr _tcph, *th;
|
|
|
|
/* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
|
|
|
|
u8 _opt[15 * 4 - sizeof(_tcph)], *op;
|
|
|
|
unsigned int i, optlen;
|
|
|
|
|
|
|
|
/* If we don't have the whole header, drop packet. */
|
[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 22:30:04 +01:00
|
|
|
th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (th == NULL)
|
|
|
|
goto dropit;
|
|
|
|
|
|
|
|
/* Malformed. */
|
|
|
|
if (th->doff*4 < sizeof(*th))
|
|
|
|
goto dropit;
|
|
|
|
|
|
|
|
optlen = th->doff*4 - sizeof(*th);
|
|
|
|
if (!optlen)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Truncated options. */
|
[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 22:30:04 +01:00
|
|
|
op = skb_header_pointer(skb, protoff + sizeof(*th), optlen, _opt);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (op == NULL)
|
|
|
|
goto dropit;
|
|
|
|
|
|
|
|
for (i = 0; i < optlen; ) {
|
|
|
|
if (op[i] == TCPOPT_MSS
|
|
|
|
&& (optlen - i) >= TCPOLEN_MSS
|
|
|
|
&& op[i+1] == TCPOLEN_MSS) {
|
|
|
|
u_int16_t mssval;
|
|
|
|
|
|
|
|
mssval = (op[i+2] << 8) | op[i+3];
|
|
|
|
|
2006-08-22 09:44:14 +02:00
|
|
|
return (mssval >= info->mss_min &&
|
|
|
|
mssval <= info->mss_max) ^ info->invert;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2006-08-22 09:44:14 +02:00
|
|
|
if (op[i] < 2)
|
|
|
|
i++;
|
|
|
|
else
|
|
|
|
i += op[i+1] ? : 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
out:
|
2006-08-22 09:44:14 +02:00
|
|
|
return info->invert;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-08-22 09:44:14 +02:00
|
|
|
dropit:
|
2005-04-17 00:20:36 +02:00
|
|
|
*hotdrop = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-22 09:34:04 +02:00
|
|
|
static struct xt_match xt_tcpmss_match[] = {
|
|
|
|
{
|
|
|
|
.name = "tcpmss",
|
|
|
|
.family = AF_INET,
|
|
|
|
.match = match,
|
|
|
|
.matchsize = sizeof(struct xt_tcpmss_match_info),
|
|
|
|
.proto = IPPROTO_TCP,
|
|
|
|
.me = THIS_MODULE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "tcpmss",
|
|
|
|
.family = AF_INET6,
|
|
|
|
.match = match,
|
|
|
|
.matchsize = sizeof(struct xt_tcpmss_match_info),
|
|
|
|
.proto = IPPROTO_TCP,
|
|
|
|
.me = THIS_MODULE,
|
|
|
|
},
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static int __init xt_tcpmss_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-08-22 09:34:04 +02:00
|
|
|
return xt_register_matches(xt_tcpmss_match,
|
|
|
|
ARRAY_SIZE(xt_tcpmss_match));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static void __exit xt_tcpmss_fini(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-08-22 09:34:04 +02:00
|
|
|
xt_unregister_matches(xt_tcpmss_match, ARRAY_SIZE(xt_tcpmss_match));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
module_init(xt_tcpmss_init);
|
|
|
|
module_exit(xt_tcpmss_fini);
|