]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - net/netfilter/xt_string.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mirror_ubuntu-eoan-kernel.git] / net / netfilter / xt_string.c
CommitLineData
7567662b 1/* String matching match for iptables
601e68e1 2 *
7567662b
PNA
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
5a0e3ad6 10#include <linux/gfp.h>
7567662b
PNA
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/skbuff.h>
2e4e6a17
HW
15#include <linux/netfilter/x_tables.h>
16#include <linux/netfilter/xt_string.h>
7567662b
PNA
17#include <linux/textsearch.h>
18
19MODULE_AUTHOR("Pablo Neira Ayuso <pablo@eurodev.net>");
2ae15b64 20MODULE_DESCRIPTION("Xtables: string-based matching");
7567662b 21MODULE_LICENSE("GPL");
2e4e6a17
HW
22MODULE_ALIAS("ipt_string");
23MODULE_ALIAS("ip6t_string");
7567662b 24
d3c5ee6d 25static bool
f7108a20 26string_mt(const struct sk_buff *skb, const struct xt_match_param *par)
7567662b 27{
f7108a20 28 const struct xt_string_info *conf = par->matchinfo;
7567662b 29 struct ts_state state;
4ad3f261 30 int invert;
7567662b
PNA
31
32 memset(&state, 0, sizeof(struct ts_state));
33
f7108a20 34 invert = (par->match->revision == 0 ? conf->u.v0.invert :
4ad3f261
JP
35 conf->u.v1.flags & XT_STRING_FLAG_INVERT);
36
601e68e1
YH
37 return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
38 conf->to_offset, conf->config, &state)
4ad3f261 39 != UINT_MAX) ^ invert;
7567662b
PNA
40}
41
e79ec50b 42#define STRING_TEXT_PRIV(m) ((struct xt_string_info *)(m))
7567662b 43
9b4fce7a 44static bool string_mt_check(const struct xt_mtchk_param *par)
7567662b 45{
9b4fce7a 46 struct xt_string_info *conf = par->matchinfo;
7567662b 47 struct ts_config *ts_conf;
4ad3f261 48 int flags = TS_AUTOLOAD;
7567662b 49
7567662b
PNA
50 /* Damn, can't handle this case properly with iptables... */
51 if (conf->from_offset > conf->to_offset)
ccb79bdc 52 return false;
3ab72088 53 if (conf->algo[XT_STRING_MAX_ALGO_NAME_SIZE - 1] != '\0')
ccb79bdc 54 return false;
3ab72088 55 if (conf->patlen > XT_STRING_MAX_PATTERN_SIZE)
ccb79bdc 56 return false;
9b4fce7a 57 if (par->match->revision == 1) {
4ad3f261
JP
58 if (conf->u.v1.flags &
59 ~(XT_STRING_FLAG_IGNORECASE | XT_STRING_FLAG_INVERT))
60 return false;
61 if (conf->u.v1.flags & XT_STRING_FLAG_IGNORECASE)
62 flags |= TS_IGNORECASE;
63 }
7567662b 64 ts_conf = textsearch_prepare(conf->algo, conf->pattern, conf->patlen,
4ad3f261 65 GFP_KERNEL, flags);
7567662b 66 if (IS_ERR(ts_conf))
ccb79bdc 67 return false;
7567662b
PNA
68
69 conf->config = ts_conf;
70
ccb79bdc 71 return true;
7567662b
PNA
72}
73
6be3d859 74static void string_mt_destroy(const struct xt_mtdtor_param *par)
7567662b 75{
6be3d859 76 textsearch_destroy(STRING_TEXT_PRIV(par->matchinfo)->config);
7567662b
PNA
77}
78
55b69e91 79static struct xt_match xt_string_mt_reg[] __read_mostly = {
4470bbc7
PM
80 {
81 .name = "string",
4ad3f261 82 .revision = 0,
55b69e91 83 .family = NFPROTO_UNSPEC,
4ad3f261
JP
84 .checkentry = string_mt_check,
85 .match = string_mt,
86 .destroy = string_mt_destroy,
87 .matchsize = sizeof(struct xt_string_info),
88 .me = THIS_MODULE
89 },
90 {
91 .name = "string",
92 .revision = 1,
55b69e91 93 .family = NFPROTO_UNSPEC,
d3c5ee6d
JE
94 .checkentry = string_mt_check,
95 .match = string_mt,
96 .destroy = string_mt_destroy,
4470bbc7
PM
97 .matchsize = sizeof(struct xt_string_info),
98 .me = THIS_MODULE
99 },
7567662b
PNA
100};
101
d3c5ee6d 102static int __init string_mt_init(void)
7567662b 103{
55b69e91
JE
104 return xt_register_matches(xt_string_mt_reg,
105 ARRAY_SIZE(xt_string_mt_reg));
7567662b
PNA
106}
107
d3c5ee6d 108static void __exit string_mt_exit(void)
7567662b 109{
55b69e91 110 xt_unregister_matches(xt_string_mt_reg, ARRAY_SIZE(xt_string_mt_reg));
7567662b
PNA
111}
112
d3c5ee6d
JE
113module_init(string_mt_init);
114module_exit(string_mt_exit);