Maintained by: NLnet Labs
Data Structures | Enumerations | Functions
testpkts.h File Reference

This is a debugging aid. More...

Data Structures

struct  reply_packet
 struct to keep a linked list of reply packets for a query More...
 
struct  entry
 data structure to keep the canned queries in. More...
 

Enumerations

enum  transport_type { transport_any = 0, transport_udp, transport_tcp }
 Type of transport, since some entries match based on UDP or TCP of query.
 

Functions

struct entryread_datafile (const char *name, int skip_whitespace)
 reads the canned reply file and returns a list of structs does an exit on error. More...
 
void delete_entry (struct entry *list)
 Delete linked list of entries.
 
struct entryread_entry (FILE *in, const char *name, struct sldns_file_parse_state *pstate, int skip_whitespace)
 Read one entry from the data file. More...
 
struct entryfind_match (struct entry *entries, uint8_t *query_pkt, size_t query_pkt_len, enum transport_type transport)
 finds entry in list, or returns NULL.
 
int match_all (uint8_t *q, size_t qlen, uint8_t *p, size_t plen, int mttl, int noloc)
 match two packets, all must match More...
 
void adjust_packet (struct entry *match, uint8_t **answer_pkt, size_t *answer_pkt_len, uint8_t *query_pkt, size_t query_pkt_len)
 copy & adjust packet, mallocs a copy. More...
 
void handle_query (uint8_t *inbuf, ssize_t inlen, struct entry *entries, int *count, enum transport_type transport, void(*sendfunc)(uint8_t *, size_t, void *), void *userdata, FILE *verbose_out)
 Parses data buffer to a query, finds the correct answer and calls the given function for every packet to send. More...
 

Detailed Description

This is a debugging aid.

It is not efficient, especially with a long config file, but it can give any reply to any query. This can help the developer pre-script replies for queries.

You can specify a packet RR by RR with header flags to return.

Missing features:

Function Documentation

◆ read_datafile()

struct entry* read_datafile ( const char *  name,
int  skip_whitespace 
)

reads the canned reply file and returns a list of structs does an exit on error.

Parameters
namename of the file to read.
skip_whitespaceskip leftside whitespace.

References error(), entry::next, prog_name, read_entry(), and verbose().

Referenced by dstest_file(), nsec3_hash_test(), and verifytest_file().

◆ read_entry()

struct entry* read_entry ( FILE *  in,
const char *  name,
struct sldns_file_parse_state pstate,
int  skip_whitespace 
)

Read one entry from the data file.

Parameters
infile to read from. Filepos must be at the start of a new line.
namename of the file for prettier errors.
pstatefile parse state with lineno, default_ttl, origin and prev_rr name.
skip_whitespaceskip leftside whitespace.
Returns
: The entry read (malloced) or NULL if no entry could be read.

References MAX_LINE.

Referenced by read_datafile(), and replay_range_read().

◆ match_all()

int match_all ( uint8_t *  q,
size_t  qlen,
uint8_t *  p,
size_t  plen,
int  mttl,
int  noloc 
)

match two packets, all must match

Parameters
qpacket 1
qlenlength of q.
ppacket 2
plenlength of p.
mttlif true, ttls must match, if false, ttls do not need to match
nolocif true, rrs may be reordered in their packet-section. rrs are then matches without location of the rr being important.
Returns
true if matched.

match two packets, all must match

References error(), lowercase_pkt(), match_noloc(), memdup(), sldns_wire2str_pkt(), verbose(), and zerottls().

Referenced by test_buffers().

◆ adjust_packet()

void adjust_packet ( struct entry match,
uint8_t **  answer_pkt,
size_t *  answer_pkt_len,
uint8_t *  query_pkt,
size_t  query_pkt_len 
)

copy & adjust packet, mallocs a copy.

Assume there is only one EDNS option, which is ECS. Copy source mask from query to scope mask in reply. Assume rest of ECS data in response (eg address) matches the query.

References entry::copy_query.

◆ handle_query()

void handle_query ( uint8_t *  inbuf,
ssize_t  inlen,
struct entry entries,
int *  count,
enum transport_type  transport,
void(*)(uint8_t *, size_t, void *)  sendfunc,
void *  userdata,
FILE *  verbose_out 
)

Parses data buffer to a query, finds the correct answer and calls the given function for every packet to send.

if verbose_out filename is given, packets are dumped there.

Parameters
inbufthe packet that came in
inlenlength of packet.
entriesentries read in from datafile.
countis increased to count number of queries answered.
transportset to UDP or TCP to match some types of entries.
sendfunccalled to send answer (buffer, size, userarg).
userdatauserarg to give to sendfunc.
verbose_outif not NULL, verbose messages are printed there.

References verbose().