Introduce new filtering architecture
This change introduces new filtering architecture primitives: filter,
filter_action and bool_expression. Filtering is now done after decoding of
syscall and tcp->qual_flg stores filtering results.
* basic_actions.c: New file.
* filter_action.c: Likewise.
* filter_expression.c: Likewise.
* filter.c: Likewise.
* basic_filters.c (parse_syscall_filter, run_syscall_filter,
free_syscall_filter): New functions.
* defs.h (filter_syscall, filtering_parsing_finish): Add new declarations.
* filter.h: Add new declarations.
* filter_qualify.c (abbrev_set, raw_set, trace_set, verbose_set):
Remove set variables.
(qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw):
Use new filtering API.
(qual_flags): Remove QUAL_* flags for trace, abbrev, verbose, raw.
* strace.c (init): Call filtering_parse_finish after command line parsing.
(trace_syscall): Add filtering after syscall decoding.
* Makefile.am (strace_SOURCES): Add new files.
2017-08-26 16:50:25 +03:00
/*
* Copyright ( c ) 2017 Nikolay Marchuk < marchuk . nikolay . a @ gmail . com >
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
# include "defs.h"
# include "filter.h"
# define FILTER_TYPE(name) \
{ # name , parse_ # # name # # _filter , run_ # # name # # _filter , \
free_ # # name # # _filter }
/* End of FILTER_TYPE definition. */
static const struct filter_type {
const char * name ;
Implement new filtering language parsing
* basic_filters.c (lookup_class, qualify_syscall_class, qualify_syscall,
qualify_syscall_tokens, parse_syscall_filter, qualify_tokens,
parse_fd_filter, parse_path_filter): Add qualify_mode argument.
(qualify_tokens, qualify_syscall_tokens): Use set inversion only in
qualify mode.
(lookup_class): Use deprecated class names only in qualify mode.
* defs.h (qualify): Remove declaration.
(filtering_parse): Add new declaration.
* filter.c (struct filter_type, parse_filter):
Add bool argument to parse_*_filter declarations.
* filter.h (parse_filter_action, parse_qualify_action,
parse_filter_expression): Add new declarations.
(parse_filter, qualify_tokens, qualify_syscall_tokens):
Add qualify_mode argument.
(DECL_FILTER): Add bool argument to parse_*_filter declarations.
* filter_action.c (parse_filter_action): Add new parsing function.
(inject_path_tracing): Use filtering_parse instead of qualify.
* filter_expression.c (parse_filter_expression): Implement parsing of filter
expression.
(parse_operator, push_operator, is_higher_priority): Add helper functions.
(is_space_ascii, is_allowed_in_name): Add new declarations.
* filter_parse.c: New file.
* filter_qualify.c (qualify_read, qualify_write, qualify_signals,
qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw,
qualify_inject_common, qualify_fault, qualify_inject): Use main_part and args
arguments.
* strace.c (init): Use filtering_parse instead of qualify.
* Makefile.am (strace_SOURCES): Add filter_parse.c.
2017-08-28 07:28:57 +03:00
void * ( * parse_filter ) ( const char * , bool ) ;
Introduce new filtering architecture
This change introduces new filtering architecture primitives: filter,
filter_action and bool_expression. Filtering is now done after decoding of
syscall and tcp->qual_flg stores filtering results.
* basic_actions.c: New file.
* filter_action.c: Likewise.
* filter_expression.c: Likewise.
* filter.c: Likewise.
* basic_filters.c (parse_syscall_filter, run_syscall_filter,
free_syscall_filter): New functions.
* defs.h (filter_syscall, filtering_parsing_finish): Add new declarations.
* filter.h: Add new declarations.
* filter_qualify.c (abbrev_set, raw_set, trace_set, verbose_set):
Remove set variables.
(qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw):
Use new filtering API.
(qual_flags): Remove QUAL_* flags for trace, abbrev, verbose, raw.
* strace.c (init): Call filtering_parse_finish after command line parsing.
(trace_syscall): Add filtering after syscall decoding.
* Makefile.am (strace_SOURCES): Add new files.
2017-08-26 16:50:25 +03:00
bool ( * run_filter ) ( struct tcb * , void * ) ;
void ( * free_priv_data ) ( void * ) ;
} filter_types [ ] = {
FILTER_TYPE ( syscall ) ,
2017-08-27 15:42:28 +03:00
FILTER_TYPE ( fd ) ,
2017-08-28 05:34:03 +03:00
FILTER_TYPE ( path ) ,
Introduce new filtering architecture
This change introduces new filtering architecture primitives: filter,
filter_action and bool_expression. Filtering is now done after decoding of
syscall and tcp->qual_flg stores filtering results.
* basic_actions.c: New file.
* filter_action.c: Likewise.
* filter_expression.c: Likewise.
* filter.c: Likewise.
* basic_filters.c (parse_syscall_filter, run_syscall_filter,
free_syscall_filter): New functions.
* defs.h (filter_syscall, filtering_parsing_finish): Add new declarations.
* filter.h: Add new declarations.
* filter_qualify.c (abbrev_set, raw_set, trace_set, verbose_set):
Remove set variables.
(qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw):
Use new filtering API.
(qual_flags): Remove QUAL_* flags for trace, abbrev, verbose, raw.
* strace.c (init): Call filtering_parse_finish after command line parsing.
(trace_syscall): Add filtering after syscall decoding.
* Makefile.am (strace_SOURCES): Add new files.
2017-08-26 16:50:25 +03:00
} ;
# undef FILTER_TYPE
struct filter {
const struct filter_type * type ;
void * priv_data ;
} ;
static const struct filter_type *
lookup_filter_type ( const char * str )
{
unsigned int i ;
for ( i = 0 ; i < ARRAY_SIZE ( filter_types ) ; i + + ) {
if ( ! strcmp ( filter_types [ i ] . name , str ) )
return & filter_types [ i ] ;
}
return NULL ;
}
struct filter *
add_filter_to_array ( struct filter * * filters , unsigned int * nfilters ,
const char * name )
{
const struct filter_type * type = lookup_filter_type ( name ) ;
struct filter * filter ;
if ( ! type )
error_msg_and_die ( " invalid filter '%s' " , name ) ;
* filters = xreallocarray ( * filters , + + ( * nfilters ) ,
sizeof ( struct filter ) ) ;
filter = & ( ( * filters ) [ * nfilters - 1 ] ) ;
filter - > type = type ;
return filter ;
}
void
Implement new filtering language parsing
* basic_filters.c (lookup_class, qualify_syscall_class, qualify_syscall,
qualify_syscall_tokens, parse_syscall_filter, qualify_tokens,
parse_fd_filter, parse_path_filter): Add qualify_mode argument.
(qualify_tokens, qualify_syscall_tokens): Use set inversion only in
qualify mode.
(lookup_class): Use deprecated class names only in qualify mode.
* defs.h (qualify): Remove declaration.
(filtering_parse): Add new declaration.
* filter.c (struct filter_type, parse_filter):
Add bool argument to parse_*_filter declarations.
* filter.h (parse_filter_action, parse_qualify_action,
parse_filter_expression): Add new declarations.
(parse_filter, qualify_tokens, qualify_syscall_tokens):
Add qualify_mode argument.
(DECL_FILTER): Add bool argument to parse_*_filter declarations.
* filter_action.c (parse_filter_action): Add new parsing function.
(inject_path_tracing): Use filtering_parse instead of qualify.
* filter_expression.c (parse_filter_expression): Implement parsing of filter
expression.
(parse_operator, push_operator, is_higher_priority): Add helper functions.
(is_space_ascii, is_allowed_in_name): Add new declarations.
* filter_parse.c: New file.
* filter_qualify.c (qualify_read, qualify_write, qualify_signals,
qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw,
qualify_inject_common, qualify_fault, qualify_inject): Use main_part and args
arguments.
* strace.c (init): Use filtering_parse instead of qualify.
* Makefile.am (strace_SOURCES): Add filter_parse.c.
2017-08-28 07:28:57 +03:00
parse_filter ( struct filter * filter , const char * str , bool qualify_mode )
Introduce new filtering architecture
This change introduces new filtering architecture primitives: filter,
filter_action and bool_expression. Filtering is now done after decoding of
syscall and tcp->qual_flg stores filtering results.
* basic_actions.c: New file.
* filter_action.c: Likewise.
* filter_expression.c: Likewise.
* filter.c: Likewise.
* basic_filters.c (parse_syscall_filter, run_syscall_filter,
free_syscall_filter): New functions.
* defs.h (filter_syscall, filtering_parsing_finish): Add new declarations.
* filter.h: Add new declarations.
* filter_qualify.c (abbrev_set, raw_set, trace_set, verbose_set):
Remove set variables.
(qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw):
Use new filtering API.
(qual_flags): Remove QUAL_* flags for trace, abbrev, verbose, raw.
* strace.c (init): Call filtering_parse_finish after command line parsing.
(trace_syscall): Add filtering after syscall decoding.
* Makefile.am (strace_SOURCES): Add new files.
2017-08-26 16:50:25 +03:00
{
Implement new filtering language parsing
* basic_filters.c (lookup_class, qualify_syscall_class, qualify_syscall,
qualify_syscall_tokens, parse_syscall_filter, qualify_tokens,
parse_fd_filter, parse_path_filter): Add qualify_mode argument.
(qualify_tokens, qualify_syscall_tokens): Use set inversion only in
qualify mode.
(lookup_class): Use deprecated class names only in qualify mode.
* defs.h (qualify): Remove declaration.
(filtering_parse): Add new declaration.
* filter.c (struct filter_type, parse_filter):
Add bool argument to parse_*_filter declarations.
* filter.h (parse_filter_action, parse_qualify_action,
parse_filter_expression): Add new declarations.
(parse_filter, qualify_tokens, qualify_syscall_tokens):
Add qualify_mode argument.
(DECL_FILTER): Add bool argument to parse_*_filter declarations.
* filter_action.c (parse_filter_action): Add new parsing function.
(inject_path_tracing): Use filtering_parse instead of qualify.
* filter_expression.c (parse_filter_expression): Implement parsing of filter
expression.
(parse_operator, push_operator, is_higher_priority): Add helper functions.
(is_space_ascii, is_allowed_in_name): Add new declarations.
* filter_parse.c: New file.
* filter_qualify.c (qualify_read, qualify_write, qualify_signals,
qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw,
qualify_inject_common, qualify_fault, qualify_inject): Use main_part and args
arguments.
* strace.c (init): Use filtering_parse instead of qualify.
* Makefile.am (strace_SOURCES): Add filter_parse.c.
2017-08-28 07:28:57 +03:00
filter - > priv_data = filter - > type - > parse_filter ( str , qualify_mode ) ;
Introduce new filtering architecture
This change introduces new filtering architecture primitives: filter,
filter_action and bool_expression. Filtering is now done after decoding of
syscall and tcp->qual_flg stores filtering results.
* basic_actions.c: New file.
* filter_action.c: Likewise.
* filter_expression.c: Likewise.
* filter.c: Likewise.
* basic_filters.c (parse_syscall_filter, run_syscall_filter,
free_syscall_filter): New functions.
* defs.h (filter_syscall, filtering_parsing_finish): Add new declarations.
* filter.h: Add new declarations.
* filter_qualify.c (abbrev_set, raw_set, trace_set, verbose_set):
Remove set variables.
(qualify_trace, qualify_abbrev, qualify_verbose, qualify_raw):
Use new filtering API.
(qual_flags): Remove QUAL_* flags for trace, abbrev, verbose, raw.
* strace.c (init): Call filtering_parse_finish after command line parsing.
(trace_syscall): Add filtering after syscall decoding.
* Makefile.am (strace_SOURCES): Add new files.
2017-08-26 16:50:25 +03:00
}
static bool
run_filter ( struct tcb * tcp , struct filter * filter )
{
return filter - > type - > run_filter ( tcp , filter - > priv_data ) ;
}
void
run_filters ( struct tcb * tcp , struct filter * filters , unsigned int nfilters ,
bool * variables_buf )
{
unsigned int i ;
for ( i = 0 ; i < nfilters ; + + i )
variables_buf [ i ] = run_filter ( tcp , & filters [ i ] ) ;
}
void
free_filter ( struct filter * filter )
{
if ( ! filter )
return ;
filter - > type - > free_priv_data ( filter - > priv_data ) ;
}
void
set_filters_qualify_mode ( struct filter * * filters , unsigned int * nfilters ,
unsigned int filters_left )
{
unsigned int i ;
for ( i = 0 ; i < * nfilters - filters_left ; + + i )
free_filter ( * filters + i ) ;
for ( i = 0 ; i < filters_left ; + + i )
( * filters ) [ i ] = ( * filters ) [ * nfilters - filters_left + i ] ;
* filters = xreallocarray ( * filters , filters_left , sizeof ( struct filter ) ) ;
* nfilters = filters_left ;
}
2017-08-28 05:34:03 +03:00
void
set_filter_priv_data ( struct filter * filter , void * priv_data )
{
if ( filter )
filter - > priv_data = priv_data ;
}