2005-04-16 16:20:36 -06: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 14:30:04 -07:00
|
|
|
* Portions (C) 2005 by Harald Welte <laforge@netfilter.org>
|
2005-04-16 16:20:36 -06: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 14:30:04 -07:00
|
|
|
#include <linux/netfilter/xt_tcpmss.h>
|
|
|
|
#include <linux/netfilter/x_tables.h>
|
|
|
|
|
2005-04-16 16:20:36 -06: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 14:30:04 -07:00
|
|
|
#include <linux/netfilter_ipv6/ip6_tables.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
|
2008-01-15 00:42:28 -07:00
|
|
|
MODULE_DESCRIPTION("Xtables: TCP MSS match");
|
[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 14:30:04 -07:00
|
|
|
MODULE_ALIAS("ipt_tcpmss");
|
2007-10-11 15:36:40 -06:00
|
|
|
MODULE_ALIAS("ip6t_tcpmss");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-07-07 23:15:35 -06:00
|
|
|
static bool
|
2007-12-05 00:24:03 -07:00
|
|
|
tcpmss_mt(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,
|
|
|
|
bool *hotdrop)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-08-22 01:44:14 -06:00
|
|
|
const struct xt_tcpmss_match_info *info = matchinfo;
|
2008-04-14 01:56:05 -06:00
|
|
|
const struct tcphdr *th;
|
|
|
|
struct tcphdr _tcph;
|
2005-04-16 16:20:36 -06:00
|
|
|
/* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
|
2008-04-14 01:56:05 -06:00
|
|
|
const u_int8_t *op;
|
|
|
|
u8 _opt[15 * 4 - sizeof(_tcph)];
|
2005-04-16 16:20:36 -06:00
|
|
|
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 14:30:04 -07:00
|
|
|
th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
|
2005-04-16 16:20:36 -06: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 14:30:04 -07:00
|
|
|
op = skb_header_pointer(skb, protoff + sizeof(*th), optlen, _opt);
|
2005-04-16 16:20:36 -06: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];
|
2007-02-12 12:15:49 -07:00
|
|
|
|
2006-08-22 01:44:14 -06:00
|
|
|
return (mssval >= info->mss_min &&
|
2007-02-12 12:15:49 -07:00
|
|
|
mssval <= info->mss_max) ^ info->invert;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2006-08-22 01:44:14 -06:00
|
|
|
if (op[i] < 2)
|
|
|
|
i++;
|
|
|
|
else
|
|
|
|
i += op[i+1] ? : 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
out:
|
2006-08-22 01:44:14 -06:00
|
|
|
return info->invert;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-08-22 01:44:14 -06:00
|
|
|
dropit:
|
2007-07-07 23:15:12 -06:00
|
|
|
*hotdrop = true;
|
2007-07-07 23:15:35 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
static struct xt_match tcpmss_mt_reg[] __read_mostly = {
|
2006-08-22 01:34:04 -06:00
|
|
|
{
|
|
|
|
.name = "tcpmss",
|
|
|
|
.family = AF_INET,
|
2007-12-05 00:24:03 -07:00
|
|
|
.match = tcpmss_mt,
|
2006-08-22 01:34:04 -06:00
|
|
|
.matchsize = sizeof(struct xt_tcpmss_match_info),
|
|
|
|
.proto = IPPROTO_TCP,
|
|
|
|
.me = THIS_MODULE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "tcpmss",
|
|
|
|
.family = AF_INET6,
|
2007-12-05 00:24:03 -07:00
|
|
|
.match = tcpmss_mt,
|
2006-08-22 01:34:04 -06:00
|
|
|
.matchsize = sizeof(struct xt_tcpmss_match_info),
|
|
|
|
.proto = IPPROTO_TCP,
|
|
|
|
.me = THIS_MODULE,
|
|
|
|
},
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
static int __init tcpmss_mt_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-12-05 00:24:03 -07:00
|
|
|
return xt_register_matches(tcpmss_mt_reg, ARRAY_SIZE(tcpmss_mt_reg));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
static void __exit tcpmss_mt_exit(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-12-05 00:24:03 -07:00
|
|
|
xt_unregister_matches(tcpmss_mt_reg, ARRAY_SIZE(tcpmss_mt_reg));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
module_init(tcpmss_mt_init);
|
|
|
|
module_exit(tcpmss_mt_exit);
|