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