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