unbound: testcode/testpkts.h File Reference

unbound 0.1

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 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.
void | delete_entry (struct entry *list)
| Delete linked list of entries.
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.
struct entry * | find_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, int noedns)
| match two packets, all must match
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.
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.

## 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:

- matching content different from reply content.
- find way to adjust mangled packets?

## 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

  name | name of the file to read.
  skip_whitespace | skip 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

  in | file to read from. Filepos must be at the start of a new line.
  name | name of the file for prettier errors.
  pstate | file parse state with lineno, default_ttl, origin and prev_rr name.
  skip_whitespace | skip leftside whitespace.

Returns
  : The entry read (malloced) or NULL if no entry could be read.

References add_rr(), adjustline(), sldns_file_parse_state::default_ttl, entry_add_reply(), error(), get_origin(), hex_buffer2wire(), isendline(), entry::lineno, sldns_file_parse_state::lineno, matchline(), MAX_LINE, MAX_PACKETLEN, memdup(), new_entry(), reply_packet::raw_ednsdata, reply_packet::reply_from_hex, reply_packet::reply_len, reply_packet::reply_pkt, replyline(), sldns_buffer_begin(), sldns_buffer_free(), sldns_buffer_limit(), sldns_buffer_new(), and str_keyword().

Referenced by read_datafile(), replay_moment_read(), 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,
|  | int | noedns )

match two packets, all must match

Parameters

  q | packet 1
  qlen | length of q.
  p | packet 2
  plen | length of p.
  mttl | if true, ttls must match, if false, ttls do not need to match
  noloc | if true, rrs may be reordered in their packet-section. rrs are then matches without location of the rr being important.
  noedns | if true, edns is not compared, if false, edns must match.

Returns
  true if matched.

match two packets, all must match

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

Referenced by find_match(), and 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 get_qname_len(), match(), memdup(), pkt_find_edns_opt(), and verbose().

Referenced by fill_buffer_with_reply(), and handle_query().

## ◆ handle_query()

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.

if verbose_out filename is given, packets are dumped there.

Parameters

  inbuf | the packet that came in
  inlen | length of packet.
  entries | entries read in from datafile.
  count | is increased to count number of queries answered.
  transport | set to UDP or TCP to match some types of entries.
  sendfunc | called to send answer (buffer, size, userarg).
  userdata | userarg to give to sendfunc.
  verbose_out | if not NULL, verbose messages are printed there.

References adjust_packet(), find_match(), reply_packet::next, reply_packet::packet_sleep, reply_packet::reply_from_hex, reply_packet::reply_len, entry::reply_list, reply_packet::reply_pkt, sldns_buffer_begin(), sldns_buffer_limit(), sldns_wire2str_pkt(), and verbose().