linux/net/sched/em_text.c
<<
>>
Prefs
   1/*
   2 * net/sched/em_text.c  Textsearch ematch
   3 *
   4 *              This program is free software; you can redistribute it and/or
   5 *              modify it under the terms of the GNU General Public License
   6 *              as published by the Free Software Foundation; either version
   7 *              2 of the License, or (at your option) any later version.
   8 *
   9 * Authors:     Thomas Graf <tgraf@suug.ch>
  10 */
  11
  12#include <linux/slab.h>
  13#include <linux/module.h>
  14#include <linux/types.h>
  15#include <linux/kernel.h>
  16#include <linux/string.h>
  17#include <linux/skbuff.h>
  18#include <linux/textsearch.h>
  19#include <linux/tc_ematch/tc_em_text.h>
  20#include <net/pkt_cls.h>
  21
  22struct text_match {
  23        u16                     from_offset;
  24        u16                     to_offset;
  25        u8                      from_layer;
  26        u8                      to_layer;
  27        struct ts_config        *config;
  28};
  29
  30#define EM_TEXT_PRIV(m) ((struct text_match *) (m)->data)
  31
  32static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
  33                         struct tcf_pkt_info *info)
  34{
  35        struct text_match *tm = EM_TEXT_PRIV(m);
  36        int from, to;
  37        struct ts_state state;
  38
  39        from = tcf_get_base_ptr(skb, tm->from_layer) - skb->data;
  40        from += tm->from_offset;
  41
  42        to = tcf_get_base_ptr(skb, tm->to_layer) - skb->data;
  43        to += tm->to_offset;
  44
  45        return skb_find_text(skb, from, to, tm->config, &state) != UINT_MAX;
  46}
  47
  48static int em_text_change(struct tcf_proto *tp, void *data, int len,
  49                          struct tcf_ematch *m)
  50{
  51        struct text_match *tm;
  52        struct tcf_em_text *conf = data;
  53        struct ts_config *ts_conf;
  54        int flags = 0;
  55
  56        if (len < sizeof(*conf) || len < (sizeof(*conf) + conf->pattern_len))
  57                return -EINVAL;
  58
  59        if (conf->from_layer > conf->to_layer)
  60                return -EINVAL;
  61
  62        if (conf->from_layer == conf->to_layer &&
  63            conf->from_offset > conf->to_offset)
  64                return -EINVAL;
  65
  66retry:
  67        ts_conf = textsearch_prepare(conf->algo, (u8 *) conf + sizeof(*conf),
  68                                     conf->pattern_len, GFP_KERNEL, flags);
  69
  70        if (flags & TS_AUTOLOAD)
  71                rtnl_lock();
  72
  73        if (IS_ERR(ts_conf)) {
  74                if (  65-xt.c#L54" id="L54" class="line" name="L54">  54   >
  v2.6.16.3