2019-01-21 09:17:54 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 	BIRD  Internet  Routing  Daemon  - -  Filter  instructions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 	( c )  1999  Pavel  Machek  < pavel @ ucw . cz > 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-21 09:17:54 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 	( c )  2018 - - 2019  Maria  Matejka  < mq @ jmq . cz > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 	Can  be  freely  distributed  and  used  under  the  terms  of  the  GNU  GPL . 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-06 15:01:10 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 	Filter  interpreter  data  structures  and  internal  API . 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-15 13:19:01 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 	See  filter / f - inst . c  for  documentation . 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-21 09:17:54 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# ifndef _BIRD_F_INST_H_ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define _BIRD_F_INST_H_ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-08 13:38:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "nest/bird.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "conf/conf.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "filter/filter.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-08 13:38:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "filter/data.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-07 19:21:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "lib/buffer.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-09 04:23:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "lib/flowspec.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-15 23:59:44 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* Flags for instructions */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								enum  f_instruction_flags  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-06 02:18:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  FIF_RECURSIVE  =  1 , 		/* FI_CALL: function is directly recursive */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-15 23:59:44 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}  PACKED ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-08 13:38:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* Include generated filter instruction declarations */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-11 16:44:14 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "filter/inst-gen.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-08 13:38:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__) 
 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-21 09:17:54 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Convert the instruction back to the enum name */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-05 15:13:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								const  char  * f_instruction_name_ ( enum  f_instruction_code  fi ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  inline  const  char  * f_instruction_name ( enum  f_instruction_code  fi ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{  return  f_instruction_name_ ( fi )  +  3 ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-21 09:17:54 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-03 03:38:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  f_arg  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  struct  symbol  * arg ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  struct  f_arg  * next ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* Filter structures for execution */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Line of instructions to be unconditionally executed one after another */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  f_line  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  uint  len ; 				/* Line length */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-26 16:44:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  u8  args ; 				/* Function: Args required */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 16:33:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  u8  vars ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-09 02:32:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  u8  results ; 				/* Results left on stack: cmd -> 0, term -> 1 */ 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-03 03:38:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  struct  f_arg  * arg_list ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  struct  f_line_item  items [ 0 ] ; 		/* The items themselves */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-21 09:17:54 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* Convert the f_inst infix tree to the f_line structures */ 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-09 02:32:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  f_line  * f_linearize_concat ( const  struct  f_inst  *  const  inst [ ] ,  uint  count ,  uint  results ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  inline  struct  f_line  * f_linearize ( const  struct  f_inst  * root ,  uint  results ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{  return  f_linearize_concat ( & root ,  1 ,  results ) ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-15 23:59:44 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  f_dump_line ( const  struct  f_line  * ,  uint  indent ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-07 19:21:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Recursive iteration over filter instructions */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  filter_iterator  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  BUFFER_ ( const  struct  f_line  * )  lines ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  f_add_lines ( const  struct  f_line_item  * what ,  struct  filter_iterator  * fit ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define FILTER_ITERATE_INIT(fit, filter, pool)			\ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ( { 								\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    BUFFER_INIT ( ( fit ) - > lines ,  ( pool ) ,  32 ) ; 			\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    BUFFER_PUSH ( ( fit ) - > lines )  =  ( filter ) - > root ; 			\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define FILTER_ITERATE(fit, fi) ({				\ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const  struct  f_line  * fl_ ; 					\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  while  ( ! BUFFER_EMPTY ( ( fit ) - > lines ) ) 				\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { 								\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    BUFFER_POP ( ( fit ) - > lines ) ; 					\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    fl_  =  ( fit ) - > lines . data [ ( fit ) - > lines . used ] ; 			\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    for  ( uint  i_  =  0 ;  i_  <  fl_ - > len ;  i_ + + ) 			\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 								\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      const  struct  f_line_item  * fi  =  & fl_ - > items [ i_ ] ; 		\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      f_add_lines ( fi ,  ( fit ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define FILTER_ITERATE_END } } }) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define FILTER_ITERATE_CLEANUP(fit)				\ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  ( { 								\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    mb_free ( ( fit ) - > lines . data ) ; 					\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    memset ( ( fit ) ,  0 ,  sizeof ( struct  filter_iterator ) ) ; 		\
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-28 11:08:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  filter  * f_new_where ( struct  f_inst  * ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-03 00:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  inline  struct  f_dynamic_attr  f_new_dynamic_attr ( u8  type ,  enum  f_type  f_type ,  uint  code )  /* Type as core knows it, type as filters know it, and code of dynamic attribute */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{  return  ( struct  f_dynamic_attr )  {  . type  =  type ,  . f_type  =  f_type ,  . ea_code  =  code  } ;  }    /* f_type currently unused; will be handy for static type checking */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  inline  struct  f_dynamic_attr  f_new_dynamic_attr_bit ( u8  bit ,  enum  f_type  f_type ,  uint  code )  /* Type as core knows it, type as filters know it, and code of dynamic attribute */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{  return  ( struct  f_dynamic_attr )  {  . type  =  EAF_TYPE_BITFIELD ,  . bit  =  bit ,  . f_type  =  f_type ,  . ea_code  =  code  } ;  }    /* f_type currently unused; will be handy for static type checking */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  inline  struct  f_static_attr  f_new_static_attr ( int  f_type ,  int  code ,  int  readonly ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{  return  ( struct  f_static_attr )  {  . f_type  =  f_type ,  . sa_code  =  code ,  . readonly  =  readonly  } ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Hook for call bt_assert() function in configuration */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								extern  void  ( * bt_assert_hook ) ( int  result ,  const  struct  f_line_item  * assert ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Bird Tests */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  f_bt_test_suite  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  node  n ; 			/* Node in config->tests */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-15 13:53:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  const  struct  f_line  * fn ; 	/* Root of function */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const  struct  f_line  * cmp ; 	/* Compare to this function */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  const  char  * fn_name ; 		/* Name of test */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const  char  * dsc ; 		/* Description */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 12:25:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  int  result ; 			/* Desired result */ 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-21 09:17:54 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 21:25:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# endif