Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 103331
b: refs/heads/master
c: 4ad3f26
h: refs/heads/master
i:
  103329: d72c05e
  103327: 65f35b5
v: v3
  • Loading branch information
Joonwoo Park authored and David S. Miller committed Jul 8, 2008
1 parent 556816c commit 2f5b223
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dde77e604497dada6f224a685278dfb27747ae52
refs/heads/master: 4ad3f26162ece5aca3045fd45e15dd99acea4a0e
15 changes: 14 additions & 1 deletion trunk/include/linux/netfilter/xt_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@
#define XT_STRING_MAX_PATTERN_SIZE 128
#define XT_STRING_MAX_ALGO_NAME_SIZE 16

enum {
XT_STRING_FLAG_INVERT = 0x01,
XT_STRING_FLAG_IGNORECASE = 0x02
};

struct xt_string_info
{
u_int16_t from_offset;
u_int16_t to_offset;
char algo[XT_STRING_MAX_ALGO_NAME_SIZE];
char pattern[XT_STRING_MAX_PATTERN_SIZE];
u_int8_t patlen;
u_int8_t invert;
union {
struct {
u_int8_t invert;
} v0;

struct {
u_int8_t flags;
} v1;
} u;

/* Used internally by the kernel */
struct ts_config __attribute__((aligned(8))) *config;
Expand Down
38 changes: 36 additions & 2 deletions trunk/net/netfilter/xt_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ string_mt(const struct sk_buff *skb, const struct net_device *in,
{
const struct xt_string_info *conf = matchinfo;
struct ts_state state;
int invert;

memset(&state, 0, sizeof(struct ts_state));

invert = (match->revision == 0 ? conf->u.v0.invert :
conf->u.v1.flags & XT_STRING_FLAG_INVERT);

return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
conf->to_offset, conf->config, &state)
!= UINT_MAX) ^ conf->invert;
!= UINT_MAX) ^ invert;
}

#define STRING_TEXT_PRIV(m) ((struct xt_string_info *)(m))
Expand All @@ -46,6 +50,7 @@ string_mt_check(const char *tablename, const void *ip,
{
struct xt_string_info *conf = matchinfo;
struct ts_config *ts_conf;
int flags = TS_AUTOLOAD;

/* Damn, can't handle this case properly with iptables... */
if (conf->from_offset > conf->to_offset)
Expand All @@ -54,8 +59,15 @@ string_mt_check(const char *tablename, const void *ip,
return false;
if (conf->patlen > XT_STRING_MAX_PATTERN_SIZE)
return false;
if (match->revision == 1) {
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;
}
ts_conf = textsearch_prepare(conf->algo, conf->pattern, conf->patlen,
GFP_KERNEL, TS_AUTOLOAD);
GFP_KERNEL, flags);
if (IS_ERR(ts_conf))
return false;

Expand All @@ -72,6 +84,17 @@ static void string_mt_destroy(const struct xt_match *match, void *matchinfo)
static struct xt_match string_mt_reg[] __read_mostly = {
{
.name = "string",
.revision = 0,
.family = AF_INET,
.checkentry = string_mt_check,
.match = string_mt,
.destroy = string_mt_destroy,
.matchsize = sizeof(struct xt_string_info),
.me = THIS_MODULE
},
{
.name = "string",
.revision = 1,
.family = AF_INET,
.checkentry = string_mt_check,
.match = string_mt,
Expand All @@ -81,6 +104,17 @@ static struct xt_match string_mt_reg[] __read_mostly = {
},
{
.name = "string",
.revision = 0,
.family = AF_INET6,
.checkentry = string_mt_check,
.match = string_mt,
.destroy = string_mt_destroy,
.matchsize = sizeof(struct xt_string_info),
.me = THIS_MODULE
},
{
.name = "string",
.revision = 1,
.family = AF_INET6,
.checkentry = string_mt_check,
.match = string_mt,
Expand Down

0 comments on commit 2f5b223

Please sign in to comment.