unbound 0.1
replay.c File Reference

Store and use a replay of events for the DNS resolver. More...

#include "config.h"
#include <math.h>
#include <ctype.h>
#include <time.h>
#include "util/log.h"
#include "util/net_help.h"
#include "util/config_file.h"
#include "testcode/replay.h"
#include "testcode/testpkts.h"
#include "testcode/fake_event.h"
#include "sldns/str2wire.h"
#include "util/timeval_func.h"

Macros

#define MAX_LINE_LEN   10240
 max length of lines in file
#define tb_assert(x)

Functions

static char * macro_expand (rbtree_type *store, struct replay_runtime *runtime, char **text)
 Expand a macro.
static int parse_keyword (char **line, const char *keyword)
 parse keyword in string.
static void replay_moment_delete (struct replay_moment *mom)
 delete moment
static void replay_range_delete (struct replay_range *rng)
 delete range
void strip_end_white (char *p)
 strip whitespace from end of string
static struct replay_range * replay_range_read (char *remain, FILE *in, const char *name, struct sldns_file_parse_state *pstate, char *line)
 Read a range from file.
static void read_file_content (FILE *in, int *lineno, struct replay_moment *mom)
 Read FILE match content.
static void read_assign_step (char *remain, struct replay_moment *mom)
 read assign step info
static struct replay_moment * replay_moment_read (char *remain, FILE *in, const char *name, struct sldns_file_parse_state *pstate)
 Read a replay moment 'STEP' from file.
static struct replay_scenario * make_scenario (char *line)
 makes scenario with title on rest of line
struct replay_scenario * replay_scenario_read (FILE *in, const char *name, int *lineno)
 Read a replay scenario from the file.
void replay_scenario_delete (struct replay_scenario *scen)
 Delete scenario.
static struct fake_timer * first_timer (struct replay_runtime *runtime)
 fetch oldest timer in list that is enabled
struct fake_timer * replay_get_oldest_timer (struct replay_runtime *runtime)
 get oldest enabled fake timer
int replay_var_compare (const void *a, const void *b)
 compare two replay_vars
rbtree_type * macro_store_create (void)
 Create variable storage.
static void del_macro (rbnode_type *x, void *ATTR_UNUSED(arg))
 helper function to delete macro values
void macro_store_delete (rbtree_type *store)
 Delete variable storage.
static size_t macro_length (char *text)
 return length of macro
static int do_buf_insert (char *buf, size_t remain, char *after, char *inserted)
 insert new stuff at start of buffer
static char * do_macro_recursion (rbtree_type *store, struct replay_runtime *runtime, char *at, size_t remain)
 do macro recursion
static struct replay_var * macro_getvar (rbtree_type *store, char *name)
 get var from store
static char * do_macro_variable (rbtree_type *store, char *buf, size_t remain)
 do macro variable
static char * do_macro_ctime (char *arg)
 do ctime macro on argument
static double perform_arith (double x, char op, double y, double *res)
 perform arithmetic operator
static char * do_macro_arith (char *orig, size_t remain, char **arithstart)
 do macro arithmetic on two numbers and operand
static char * do_macro_range (char *buf)
 Do range macro on expanded buffer.
char * macro_process (rbtree_type *store, struct replay_runtime *runtime, char *text)
 Apply macro substitution to string.
char * macro_lookup (rbtree_type *store, char *name)
 Look up a macro value.
void macro_print_debug (rbtree_type *store)
 Print macro variables stored as debug info.
int macro_assign (rbtree_type *store, char *name, char *value)
 Set macro value.
void testbound_selftest (void)
 testbounds self test

Detailed Description

Store and use a replay of events for the DNS resolver.

Used to test known scenarios to get known outcomes.

Macro Definition Documentation

◆ MAX_LINE_LEN

#define MAX_LINE_LEN   10240

◆ tb_assert

#define tb_assert ( x)
Value:
do { if(!(x)) fatal_exit("%s:%d: %s: assertion %s failed", \
__FILE__, __LINE__, __func__, #x); \
num_asserts++; \
} while(0);
void fatal_exit(const char *format,...)
implementation of fatal_exit
Definition log.c:398

Function Documentation

◆ macro_expand()

char * macro_expand ( rbtree_type * store,
struct replay_runtime * runtime,
char ** text )
static

Expand a macro.

Parameters
storevalue storage
runtimereplay runtime for other stuff.
textthe macro text, after the ${, Updated to after the } when done (successfully).
Returns
expanded text, malloced. NULL on failure.

References do_macro_arith(), do_macro_ctime(), do_macro_range(), do_macro_recursion(), do_macro_variable(), first_timer(), macro_expand(), macro_length(), replay_runtime::now_secs, fake_timer::runtime, and fake_timer::tv.

Referenced by do_macro_recursion(), macro_expand(), and macro_process().

◆ parse_keyword()

int parse_keyword ( char ** line,
const char * keyword )
static

parse keyword in string.

Parameters
lineif found, the line is advanced to after the keyword.
keywordstring.
Returns
: true if found, false if not.

References parse_keyword().

Referenced by parse_keyword(), read_file_content(), replay_moment_read(), replay_range_read(), and replay_scenario_read().

◆ replay_moment_delete()

◆ replay_range_delete()

void replay_range_delete ( struct replay_range * rng)
static

◆ strip_end_white()

◆ replay_range_read()

struct replay_range * replay_range_read ( char * remain,
FILE * in,
const char * name,
struct sldns_file_parse_state * pstate,
char * line )
static

Read a range from file.

Parameters
remainRest of line (after RANGE keyword).
infile to read from.
namename to print in errors.
pstateread state structure with with lineno : incremented as lines are read. ttl, origin, prev for readentry.
lineline buffer.
Returns
: range object to add to list, or NULL on error.

References replay_range::addr, replay_range::addrlen, replay_range::end_step, extstrtoaddr(), fatal_exit(), sldns_file_parse_state::lineno, log_err(), replay_range::match, MAX_LINE_LEN, entry::next, parse_keyword(), read_entry(), replay_range_delete(), replay_range_read(), replay_range::start_step, and strip_end_white().

Referenced by replay_range_read(), and replay_scenario_read().

◆ read_file_content()

void read_file_content ( FILE * in,
int * lineno,
struct replay_moment * mom )
static

◆ read_assign_step()

void read_assign_step ( char * remain,
struct replay_moment * mom )
static

◆ replay_moment_read()

◆ make_scenario()

struct replay_scenario * make_scenario ( char * line)
static

makes scenario with title on rest of line

References log_err(), make_scenario(), and replay_scenario::title.

Referenced by make_scenario(), and replay_scenario_read().

◆ replay_scenario_read()

struct replay_scenario * replay_scenario_read ( FILE * in,
const char * name,
int * lineno )

◆ replay_scenario_delete()

◆ first_timer()

struct fake_timer * first_timer ( struct replay_runtime * runtime)
static

◆ replay_get_oldest_timer()

struct fake_timer * replay_get_oldest_timer ( struct replay_runtime * runtime)

◆ replay_var_compare()

int replay_var_compare ( const void * a,
const void * b )

compare two replay_vars

References replay_var::name.

◆ macro_store_create()

rbtree_type * macro_store_create ( void )

Create variable storage.

Returns
new or NULL on failure.

References macro_store_create(), and rbtree_create().

Referenced by macro_store_create(), and testbound_selftest().

◆ del_macro()

void del_macro ( rbnode_type * x,
void * ATTR_UNUSEDarg )
static

helper function to delete macro values

References del_macro(), replay_var::name, and replay_var::value.

Referenced by del_macro(), and macro_store_delete().

◆ macro_store_delete()

void macro_store_delete ( rbtree_type * store)

Delete variable storage.

Parameters
storethe macro storage to free up.

References del_macro(), macro_store_delete(), and traverse_postorder().

Referenced by comm_base_delete(), macro_store_delete(), and testbound_selftest().

◆ macro_length()

size_t macro_length ( char * text)
static

return length of macro

References macro_length().

Referenced by macro_expand(), macro_length(), and testbound_selftest().

◆ do_buf_insert()

int do_buf_insert ( char * buf,
size_t remain,
char * after,
char * inserted )
static

insert new stuff at start of buffer

References do_buf_insert().

Referenced by do_buf_insert(), do_macro_arith(), do_macro_recursion(), and do_macro_variable().

◆ do_macro_recursion()

char * do_macro_recursion ( rbtree_type * store,
struct replay_runtime * runtime,
char * at,
size_t remain )
static

do macro recursion

References do_buf_insert(), do_macro_recursion(), and macro_expand().

Referenced by do_macro_recursion(), and macro_expand().

◆ macro_getvar()

struct replay_var * macro_getvar ( rbtree_type * store,
char * name )
static

◆ do_macro_variable()

char * do_macro_variable ( rbtree_type * store,
char * buf,
size_t remain )
static

◆ do_macro_ctime()

char * do_macro_ctime ( char * arg)
static

do ctime macro on argument

References do_macro_ctime(), log_err(), and strip_end_white().

Referenced by do_macro_ctime(), and macro_expand().

◆ perform_arith()

double perform_arith ( double x,
char op,
double y,
double * res )
static

perform arithmetic operator

References perform_arith().

Referenced by do_macro_arith(), and perform_arith().

◆ do_macro_arith()

char * do_macro_arith ( char * orig,
size_t remain,
char ** arithstart )
static

do macro arithmetic on two numbers and operand

References do_buf_insert(), do_macro_arith(), log_err(), and perform_arith().

Referenced by do_macro_arith(), and macro_expand().

◆ do_macro_range()

char * do_macro_range ( char * buf)
static

Do range macro on expanded buffer.

References do_macro_range(), fatal_exit(), and log_err().

Referenced by do_macro_range(), and macro_expand().

◆ macro_process()

char * macro_process ( rbtree_type * store,
struct replay_runtime * runtime,
char * text )

Apply macro substitution to string.

Parameters
storevariable store.
runtimethe runtime to look up values as needed.
textstring to work on.
Returns
newly malloced string with result.

References macro_expand(), macro_process(), fake_timer::next, and fake_timer::runtime.

Referenced by autotrust_check(), macro_process(), moment_assign(), tempfile_check(), testbound_selftest(), and time_passes().

◆ macro_lookup()

char * macro_lookup ( rbtree_type * store,
char * name )

Look up a macro value.

Like calling ${$name}.

Parameters
storevariable store
namemacro name
Returns
newly malloced string with result or strdup("") if not found. or NULL on malloc failure.

References macro_getvar(), macro_lookup(), replay_var::name, and replay_var::value.

Referenced by macro_lookup(), and testbound_selftest().

◆ macro_print_debug()

void macro_print_debug ( rbtree_type * store)

Print macro variables stored as debug info.

References log_info(), macro_print_debug(), replay_var::name, RBTREE_FOR, and replay_var::value.

Referenced by macro_print_debug(), and moment_assign().

◆ macro_assign()

int macro_assign ( rbtree_type * store,
char * name,
char * value )

Set macro value.

Parameters
storevariable store
namemacro name
valuetext to set it to. Not expanded.
Returns
false on failure.

References rbnode_type::key, macro_assign(), macro_getvar(), replay_var::name, replay_var::node, rbtree_insert(), and replay_var::value.

Referenced by macro_assign(), moment_assign(), and testbound_selftest().

◆ testbound_selftest()

void testbound_selftest ( void )