2005-08-22 06:30:34 +00:00
|
|
|
/* String matching match for iptables
|
2007-02-12 19:15:49 +00:00
|
|
|
*
|
2005-08-22 06:30:34 +00:00
|
|
|
* (C) 2005 Pablo Neira Ayuso <pablo@eurodev.net>
|
|
|
|
*
|
|
|
|
* 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/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/skbuff.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/x_tables.h>
|
|
|
|
#include <linux/netfilter/xt_string.h>
|
2005-08-22 06:30:34 +00:00
|
|
|
#include <linux/textsearch.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Pablo Neira Ayuso <pablo@eurodev.net>");
|
2008-01-15 07:42:28 +00:00
|
|
|
MODULE_DESCRIPTION("Xtables: string-based matching");
|
2005-08-22 06:30:34 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
[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_string");
|
|
|
|
MODULE_ALIAS("ip6t_string");
|
2005-08-22 06:30:34 +00:00
|
|
|
|
2007-12-05 07:24:03 +00:00
|
|
|
static bool
|
2008-10-08 09:35:18 +00:00
|
|
|
string_mt(const struct sk_buff *skb, const struct xt_match_param *par)
|
2005-08-22 06:30:34 +00:00
|
|
|
{
|
2008-10-08 09:35:18 +00:00
|
|
|
const struct xt_string_info *conf = par->matchinfo;
|
2005-08-22 06:30:34 +00:00
|
|
|
struct ts_state state;
|
2008-07-08 09:38:56 +00:00
|
|
|
int invert;
|
2005-08-22 06:30:34 +00:00
|
|
|
|
|
|
|
memset(&state, 0, sizeof(struct ts_state));
|
|
|
|
|
2008-10-08 09:35:18 +00:00
|
|
|
invert = (par->match->revision == 0 ? conf->u.v0.invert :
|
2008-07-08 09:38:56 +00:00
|
|
|
conf->u.v1.flags & XT_STRING_FLAG_INVERT);
|
|
|
|
|
2007-02-12 19:15:49 +00:00
|
|
|
return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
|
|
|
|
conf->to_offset, conf->config, &state)
|
2008-07-08 09:38:56 +00:00
|
|
|
!= UINT_MAX) ^ invert;
|
2005-08-22 06:30:34 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 06:44:06 +00:00
|
|
|
#define STRING_TEXT_PRIV(m) ((struct xt_string_info *)(m))
|
2005-08-22 06:30:34 +00:00
|
|
|
|
2008-10-08 09:35:18 +00:00
|
|
|
static bool string_mt_check(const struct xt_mtchk_param *par)
|
2005-08-22 06:30:34 +00:00
|
|
|
{
|
2008-10-08 09:35:18 +00:00
|
|
|
struct xt_string_info *conf = par->matchinfo;
|
2005-08-22 06:30:34 +00:00
|
|
|
struct ts_config *ts_conf;
|
2008-07-08 09:38:56 +00:00
|
|
|
int flags = TS_AUTOLOAD;
|
2005-08-22 06:30:34 +00:00
|
|
|
|
|
|
|
/* Damn, can't handle this case properly with iptables... */
|
|
|
|
if (conf->from_offset > conf->to_offset)
|
2007-07-08 05:16:00 +00:00
|
|
|
return false;
|
2006-08-01 06:47:31 +00:00
|
|
|
if (conf->algo[XT_STRING_MAX_ALGO_NAME_SIZE - 1] != '\0')
|
2007-07-08 05:16:00 +00:00
|
|
|
return false;
|
2006-08-01 06:47:31 +00:00
|
|
|
if (conf->patlen > XT_STRING_MAX_PATTERN_SIZE)
|
2007-07-08 05:16:00 +00:00
|
|
|
return false;
|
2008-10-08 09:35:18 +00:00
|
|
|
if (par->match->revision == 1) {
|
2008-07-08 09:38:56 +00:00
|
|
|
if (conf->u.v1.flags &
|
|
|
|
~(XT_STRING_FLAG_IGNORECASE | XT_STRING_FLAG_INVERT))
|
|
|
|
return false;
|
|
|
|
if (conf->u.v1.flags & XT_STRING_FLAG_IGNORECASE)
|
|
|
|
flags |= TS_IGNORECASE;
|
|
|
|
}
|
2005-08-22 06:30:34 +00:00
|
|
|
ts_conf = textsearch_prepare(conf->algo, conf->pattern, conf->patlen,
|
2008-07-08 09:38:56 +00:00
|
|
|
GFP_KERNEL, flags);
|
2005-08-22 06:30:34 +00:00
|
|
|
if (IS_ERR(ts_conf))
|
2007-07-08 05:16:00 +00:00
|
|
|
return false;
|
2005-08-22 06:30:34 +00:00
|
|
|
|
|
|
|
conf->config = ts_conf;
|
|
|
|
|
2007-07-08 05:16:00 +00:00
|
|
|
return true;
|
2005-08-22 06:30:34 +00:00
|
|
|
}
|
|
|
|
|
2008-10-08 09:35:19 +00:00
|
|
|
static void string_mt_destroy(const struct xt_mtdtor_param *par)
|
2005-08-22 06:30:34 +00:00
|
|
|
{
|
2008-10-08 09:35:19 +00:00
|
|
|
textsearch_destroy(STRING_TEXT_PRIV(par->matchinfo)->config);
|
2005-08-22 06:30:34 +00:00
|
|
|
}
|
|
|
|
|
2008-10-08 09:35:01 +00:00
|
|
|
static struct xt_match xt_string_mt_reg[] __read_mostly = {
|
2006-08-22 07:34:04 +00:00
|
|
|
{
|
|
|
|
.name = "string",
|
2008-07-08 09:38:56 +00:00
|
|
|
.revision = 0,
|
2008-10-08 09:35:01 +00:00
|
|
|
.family = NFPROTO_UNSPEC,
|
2008-07-08 09:38:56 +00:00
|
|
|
.checkentry = string_mt_check,
|
|
|
|
.match = string_mt,
|
|
|
|
.destroy = string_mt_destroy,
|
|
|
|
.matchsize = sizeof(struct xt_string_info),
|
|
|
|
.me = THIS_MODULE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "string",
|
|
|
|
.revision = 1,
|
2008-10-08 09:35:01 +00:00
|
|
|
.family = NFPROTO_UNSPEC,
|
2007-12-05 07:24:03 +00:00
|
|
|
.checkentry = string_mt_check,
|
|
|
|
.match = string_mt,
|
|
|
|
.destroy = string_mt_destroy,
|
2006-08-22 07:34:04 +00:00
|
|
|
.matchsize = sizeof(struct xt_string_info),
|
|
|
|
.me = THIS_MODULE
|
|
|
|
},
|
2005-08-22 06:30:34 +00:00
|
|
|
};
|
|
|
|
|
2007-12-05 07:24:03 +00:00
|
|
|
static int __init string_mt_init(void)
|
2005-08-22 06:30:34 +00:00
|
|
|
{
|
2008-10-08 09:35:01 +00:00
|
|
|
return xt_register_matches(xt_string_mt_reg,
|
|
|
|
ARRAY_SIZE(xt_string_mt_reg));
|
2005-08-22 06:30:34 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 07:24:03 +00:00
|
|
|
static void __exit string_mt_exit(void)
|
2005-08-22 06:30:34 +00:00
|
|
|
{
|
2008-10-08 09:35:01 +00:00
|
|
|
xt_unregister_matches(xt_string_mt_reg, ARRAY_SIZE(xt_string_mt_reg));
|
2005-08-22 06:30:34 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 07:24:03 +00:00
|
|
|
module_init(string_mt_init);
|
|
|
|
module_exit(string_mt_exit);
|