2005-08-22 14:30:34 +08:00
|
|
|
/* String matching match for iptables
|
|
|
|
*
|
|
|
|
* (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-13 05:30:04 +08:00
|
|
|
#include <linux/netfilter/x_tables.h>
|
|
|
|
#include <linux/netfilter/xt_string.h>
|
2005-08-22 14:30:34 +08:00
|
|
|
#include <linux/textsearch.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Pablo Neira Ayuso <pablo@eurodev.net>");
|
|
|
|
MODULE_DESCRIPTION("IP tables string match module");
|
|
|
|
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-13 05:30:04 +08:00
|
|
|
MODULE_ALIAS("ipt_string");
|
|
|
|
MODULE_ALIAS("ip6t_string");
|
2005-08-22 14:30:34 +08:00
|
|
|
|
|
|
|
static int match(const struct sk_buff *skb,
|
|
|
|
const struct net_device *in,
|
|
|
|
const struct net_device *out,
|
2006-03-21 10:02:56 +08:00
|
|
|
const struct xt_match *match,
|
2005-08-22 14:30:34 +08:00
|
|
|
const void *matchinfo,
|
|
|
|
int offset,
|
[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-13 05:30:04 +08:00
|
|
|
unsigned int protoff,
|
2005-08-22 14:30:34 +08:00
|
|
|
int *hotdrop)
|
|
|
|
{
|
2006-05-30 09:19:19 +08:00
|
|
|
const struct xt_string_info *conf = matchinfo;
|
2005-08-22 14:30:34 +08:00
|
|
|
struct ts_state state;
|
|
|
|
|
|
|
|
memset(&state, 0, sizeof(struct ts_state));
|
|
|
|
|
|
|
|
return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
|
|
|
|
conf->to_offset, conf->config, &state)
|
2006-08-14 09:05:35 +08:00
|
|
|
!= UINT_MAX) ^ conf->invert;
|
2005-08-22 14:30:34 +08: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-13 05:30:04 +08:00
|
|
|
#define STRING_TEXT_PRIV(m) ((struct xt_string_info *) m)
|
2005-08-22 14:30:34 +08:00
|
|
|
|
|
|
|
static int checkentry(const char *tablename,
|
[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-13 05:30:04 +08:00
|
|
|
const void *ip,
|
2006-03-21 10:02:56 +08:00
|
|
|
const struct xt_match *match,
|
2005-08-22 14:30:34 +08:00
|
|
|
void *matchinfo,
|
|
|
|
unsigned int matchsize,
|
|
|
|
unsigned int hook_mask)
|
|
|
|
{
|
[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-13 05:30:04 +08:00
|
|
|
struct xt_string_info *conf = matchinfo;
|
2005-08-22 14:30:34 +08:00
|
|
|
struct ts_config *ts_conf;
|
|
|
|
|
|
|
|
/* Damn, can't handle this case properly with iptables... */
|
|
|
|
if (conf->from_offset > conf->to_offset)
|
|
|
|
return 0;
|
2006-08-01 14:47:31 +08:00
|
|
|
if (conf->algo[XT_STRING_MAX_ALGO_NAME_SIZE - 1] != '\0')
|
|
|
|
return 0;
|
|
|
|
if (conf->patlen > XT_STRING_MAX_PATTERN_SIZE)
|
|
|
|
return 0;
|
2005-08-22 14:30:34 +08:00
|
|
|
ts_conf = textsearch_prepare(conf->algo, conf->pattern, conf->patlen,
|
|
|
|
GFP_KERNEL, TS_AUTOLOAD);
|
|
|
|
if (IS_ERR(ts_conf))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
conf->config = ts_conf;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-21 10:02:56 +08:00
|
|
|
static void destroy(const struct xt_match *match, void *matchinfo,
|
|
|
|
unsigned int matchsize)
|
2005-08-22 14:30:34 +08:00
|
|
|
{
|
|
|
|
textsearch_destroy(STRING_TEXT_PRIV(matchinfo)->config);
|
|
|
|
}
|
|
|
|
|
2006-08-22 15:34:04 +08:00
|
|
|
static struct xt_match xt_string_match[] = {
|
|
|
|
{
|
|
|
|
.name = "string",
|
|
|
|
.family = AF_INET,
|
|
|
|
.checkentry = checkentry,
|
|
|
|
.match = match,
|
|
|
|
.destroy = destroy,
|
|
|
|
.matchsize = sizeof(struct xt_string_info),
|
|
|
|
.me = THIS_MODULE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "string",
|
|
|
|
.family = AF_INET6,
|
|
|
|
.checkentry = checkentry,
|
|
|
|
.match = match,
|
|
|
|
.destroy = destroy,
|
|
|
|
.matchsize = sizeof(struct xt_string_info),
|
|
|
|
.me = THIS_MODULE
|
|
|
|
},
|
2005-08-22 14:30:34 +08:00
|
|
|
};
|
|
|
|
|
2006-03-29 08:37:06 +08:00
|
|
|
static int __init xt_string_init(void)
|
2005-08-22 14:30:34 +08:00
|
|
|
{
|
2006-08-22 15:34:04 +08:00
|
|
|
return xt_register_matches(xt_string_match, ARRAY_SIZE(xt_string_match));
|
2005-08-22 14:30:34 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 08:37:06 +08:00
|
|
|
static void __exit xt_string_fini(void)
|
2005-08-22 14:30:34 +08:00
|
|
|
{
|
2006-08-22 15:34:04 +08:00
|
|
|
xt_unregister_matches(xt_string_match, ARRAY_SIZE(xt_string_match));
|
2005-08-22 14:30:34 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 08:37:06 +08:00
|
|
|
module_init(xt_string_init);
|
|
|
|
module_exit(xt_string_fini);
|