[TCP]: Fix RFC2465 typo.
[deliverable/linux.git] / net / netfilter / xt_string.c
CommitLineData
7567662b
PNA
1/* String matching match for iptables
2 *
3 * (C) 2005 Pablo Neira Ayuso <pablo@eurodev.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/skbuff.h>
2e4e6a17
HW
14#include <linux/netfilter/x_tables.h>
15#include <linux/netfilter/xt_string.h>
7567662b
PNA
16#include <linux/textsearch.h>
17
18MODULE_AUTHOR("Pablo Neira Ayuso <pablo@eurodev.net>");
19MODULE_DESCRIPTION("IP tables string match module");
20MODULE_LICENSE("GPL");
2e4e6a17
HW
21MODULE_ALIAS("ipt_string");
22MODULE_ALIAS("ip6t_string");
7567662b
PNA
23
24static int match(const struct sk_buff *skb,
25 const struct net_device *in,
26 const struct net_device *out,
c4986734 27 const struct xt_match *match,
7567662b
PNA
28 const void *matchinfo,
29 int offset,
2e4e6a17 30 unsigned int protoff,
7567662b
PNA
31 int *hotdrop)
32{
33 struct ts_state state;
2e4e6a17 34 struct xt_string_info *conf = (struct xt_string_info *) matchinfo;
7567662b
PNA
35
36 memset(&state, 0, sizeof(struct ts_state));
37
38 return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
39 conf->to_offset, conf->config, &state)
40 != UINT_MAX) && !conf->invert;
41}
42
2e4e6a17 43#define STRING_TEXT_PRIV(m) ((struct xt_string_info *) m)
7567662b
PNA
44
45static int checkentry(const char *tablename,
2e4e6a17 46 const void *ip,
c4986734 47 const struct xt_match *match,
7567662b
PNA
48 void *matchinfo,
49 unsigned int matchsize,
50 unsigned int hook_mask)
51{
2e4e6a17 52 struct xt_string_info *conf = matchinfo;
7567662b
PNA
53 struct ts_config *ts_conf;
54
7567662b
PNA
55 /* Damn, can't handle this case properly with iptables... */
56 if (conf->from_offset > conf->to_offset)
57 return 0;
58
59 ts_conf = textsearch_prepare(conf->algo, conf->pattern, conf->patlen,
60 GFP_KERNEL, TS_AUTOLOAD);
61 if (IS_ERR(ts_conf))
62 return 0;
63
64 conf->config = ts_conf;
65
66 return 1;
67}
68
c4986734
PM
69static void destroy(const struct xt_match *match, void *matchinfo,
70 unsigned int matchsize)
7567662b
PNA
71{
72 textsearch_destroy(STRING_TEXT_PRIV(matchinfo)->config);
73}
74
2e4e6a17
HW
75static struct xt_match string_match = {
76 .name = "string",
77 .match = match,
5d04bff0 78 .matchsize = sizeof(struct xt_string_info),
2e4e6a17
HW
79 .checkentry = checkentry,
80 .destroy = destroy,
a45049c5 81 .family = AF_INET,
2e4e6a17
HW
82 .me = THIS_MODULE
83};
84static struct xt_match string6_match = {
7567662b
PNA
85 .name = "string",
86 .match = match,
5d04bff0 87 .matchsize = sizeof(struct xt_string_info),
7567662b
PNA
88 .checkentry = checkentry,
89 .destroy = destroy,
a45049c5 90 .family = AF_INET6,
7567662b
PNA
91 .me = THIS_MODULE
92};
93
94static int __init init(void)
95{
2e4e6a17
HW
96 int ret;
97
a45049c5 98 ret = xt_register_match(&string_match);
2e4e6a17
HW
99 if (ret)
100 return ret;
a45049c5 101 ret = xt_register_match(&string6_match);
2e4e6a17 102 if (ret)
a45049c5 103 xt_unregister_match(&string_match);
2e4e6a17
HW
104
105 return ret;
7567662b
PNA
106}
107
108static void __exit fini(void)
109{
a45049c5
PNA
110 xt_unregister_match(&string_match);
111 xt_unregister_match(&string6_match);
7567662b
PNA
112}
113
114module_init(init);
115module_exit(fini);
This page took 0.147605 seconds and 5 git commands to generate.