2005-06-24 08:00:58 +04:00
/*
* net / sched / em_text . c Textsearch ematch
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version
* 2 of the License , or ( at your option ) any later version .
*
* Authors : Thomas Graf < tgraf @ suug . ch >
*/
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/slab.h>
2005-06-24 08:00:58 +04:00
# include <linux/module.h>
# include <linux/types.h>
# include <linux/kernel.h>
# include <linux/string.h>
# include <linux/skbuff.h>
# include <linux/textsearch.h>
# include <linux/tc_ematch/tc_em_text.h>
# include <net/pkt_cls.h>
2011-01-19 22:26:56 +03:00
struct text_match {
2005-06-24 08:00:58 +04:00
u16 from_offset ;
u16 to_offset ;
u8 from_layer ;
u8 to_layer ;
struct ts_config * config ;
} ;
# define EM_TEXT_PRIV(m) ((struct text_match *) (m)->data)
static int em_text_match ( struct sk_buff * skb , struct tcf_ematch * m ,
struct tcf_pkt_info * info )
{
struct text_match * tm = EM_TEXT_PRIV ( m ) ;
int from , to ;
from = tcf_get_base_ptr ( skb , tm - > from_layer ) - skb - > data ;
from + = tm - > from_offset ;
to = tcf_get_base_ptr ( skb , tm - > to_layer ) - skb - > data ;
to + = tm - > to_offset ;
2015-02-22 13:46:35 +03:00
return skb_find_text ( skb , from , to , tm - > config ) ! = UINT_MAX ;
2005-06-24 08:00:58 +04:00
}
2014-10-06 08:27:53 +04:00
static int em_text_change ( struct net * net , void * data , int len ,
2005-06-24 08:00:58 +04:00
struct tcf_ematch * m )
{
struct text_match * tm ;
struct tcf_em_text * conf = data ;
struct ts_config * ts_conf ;
int flags = 0 ;
if ( len < sizeof ( * conf ) | | len < ( sizeof ( * conf ) + conf - > pattern_len ) )
return - EINVAL ;
if ( conf - > from_layer > conf - > to_layer )
return - EINVAL ;
if ( conf - > from_layer = = conf - > to_layer & &
conf - > from_offset > conf - > to_offset )
return - EINVAL ;
retry :
ts_conf = textsearch_prepare ( conf - > algo , ( u8 * ) conf + sizeof ( * conf ) ,
conf - > pattern_len , GFP_KERNEL , flags ) ;
if ( flags & TS_AUTOLOAD )
rtnl_lock ( ) ;
if ( IS_ERR ( ts_conf ) ) {
if ( PTR_ERR ( ts_conf ) = = - ENOENT & & ! ( flags & TS_AUTOLOAD ) ) {
rtnl_unlock ( ) ;
flags | = TS_AUTOLOAD ;
goto retry ;
} else
return PTR_ERR ( ts_conf ) ;
} else if ( flags & TS_AUTOLOAD ) {
textsearch_destroy ( ts_conf ) ;
return - EAGAIN ;
}
tm = kmalloc ( sizeof ( * tm ) , GFP_KERNEL ) ;
if ( tm = = NULL ) {
textsearch_destroy ( ts_conf ) ;
return - ENOBUFS ;
}
tm - > from_offset = conf - > from_offset ;
tm - > to_offset = conf - > to_offset ;
tm - > from_layer = conf - > from_layer ;
tm - > to_layer = conf - > to_layer ;
tm - > config = ts_conf ;
m - > datalen = sizeof ( * tm ) ;
m - > data = ( unsigned long ) tm ;
return 0 ;
}
2014-10-06 08:27:53 +04:00
static void em_text_destroy ( struct tcf_ematch * m )
2005-06-24 08:00:58 +04:00
{
2010-10-31 19:37:38 +03:00
if ( EM_TEXT_PRIV ( m ) & & EM_TEXT_PRIV ( m ) - > config )
textsearch_destroy ( EM_TEXT_PRIV ( m ) - > config ) ;
2005-06-24 08:00:58 +04:00
}
static int em_text_dump ( struct sk_buff * skb , struct tcf_ematch * m )
{
struct text_match * tm = EM_TEXT_PRIV ( m ) ;
struct tcf_em_text conf ;
strncpy ( conf . algo , tm - > config - > ops - > name , sizeof ( conf . algo ) - 1 ) ;
conf . from_offset = tm - > from_offset ;
conf . to_offset = tm - > to_offset ;
conf . from_layer = tm - > from_layer ;
conf . to_layer = tm - > to_layer ;
conf . pattern_len = textsearch_get_pattern_len ( tm - > config ) ;
conf . pad = 0 ;
2008-01-23 09:11:33 +03:00
if ( nla_put_nohdr ( skb , sizeof ( conf ) , & conf ) < 0 )
goto nla_put_failure ;
if ( nla_append ( skb , conf . pattern_len ,
textsearch_get_pattern ( tm - > config ) ) < 0 )
goto nla_put_failure ;
2005-06-24 08:00:58 +04:00
return 0 ;
2008-01-23 09:11:33 +03:00
nla_put_failure :
2005-06-24 08:00:58 +04:00
return - 1 ;
2007-02-09 17:25:16 +03:00
}
2005-06-24 08:00:58 +04:00
static struct tcf_ematch_ops em_text_ops = {
. kind = TCF_EM_TEXT ,
. change = em_text_change ,
. match = em_text_match ,
. destroy = em_text_destroy ,
. dump = em_text_dump ,
. owner = THIS_MODULE ,
. link = LIST_HEAD_INIT ( em_text_ops . link )
} ;
static int __init init_em_text ( void )
{
return tcf_em_register ( & em_text_ops ) ;
}
2007-02-09 17:25:16 +03:00
static void __exit exit_em_text ( void )
2005-06-24 08:00:58 +04:00
{
tcf_em_unregister ( & em_text_ops ) ;
}
MODULE_LICENSE ( " GPL " ) ;
module_init ( init_em_text ) ;
module_exit ( exit_em_text ) ;
2007-07-12 06:46:26 +04:00
MODULE_ALIAS_TCF_EMATCH ( TCF_EM_TEXT ) ;