ldns-testpkts.c File Reference

This is a debugging aid. More...

#include "config.h"
#include <ldns/ldns.h>
#include <errno.h>
#include "ldns-testpkts.h"

Defines

#define MAX_LINE   10240
 max line length

Enumerations

enum  verbosity_value {
  NO_VERBOSE = 0, NO_VERBOSE = 0, VERB_OPS, VERB_DETAIL,
  VERB_QUERY, VERB_ALGO, VERB_CLIENT
}
 

verbosity definition for compat

More...

Functions

void verbose (enum verbosity_value lvl, const char *msg,...) ATTR_FORMAT(printf
 logging routine, provided by caller
void static void error (const char *msg,...)
 print error and exit
static bool isendline (char c)
 return if string is empty or comment
static bool str_keyword (char **str, const char *keyword)
 true if the string starts with the keyword given.
static struct reply_packetentry_add_reply (struct entry *entry)
 Add reply packet to entry.
static void matchline (char *line, struct entry *e)
 parse MATCH line
static void replyline (char *line, ldns_pkt *reply)
 parse REPLY line
static void adjustline (char *line, struct entry *e, struct reply_packet *pkt)
 parse ADJUST line
static struct entrynew_entry ()
 create new entry
static size_t hexstr2bin (char *hexstr, int len, uint8_t *buf, size_t offset, size_t buf_len)
 Converts a hex string to binary data.
static ldns_buffer * data_buffer2wire (ldns_buffer *data_buffer)
 convert hex buffer to binary buffer
static void get_origin (const char *name, int lineno, ldns_rdf **origin, char *parse)
 parse ORIGIN
struct entryread_entry (FILE *in, const char *name, int *lineno, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev_rr)
 Read one entry from the data file.
struct entryread_datafile (const char *name)
 reads the canned reply file and returns a list of structs does an exit on error.
static ldns_rr_type get_qtype (ldns_pkt *p)
 get qtype from rr
static ldns_rdf * get_owner (ldns_pkt *p)
 returns owner from rr
static uint32_t get_serial (ldns_pkt *p)
 get authority section SOA serial value
static int match_list (ldns_rr_list *q, ldns_rr_list *p, bool mttl)
 match two rr lists
static int cmp_bool (int x, int y)
 compare two booleans
static int match_all (ldns_pkt *q, ldns_pkt *p, bool mttl)
 match all of the packet
struct entryfind_match (struct entry *entries, ldns_pkt *query_pkt, enum transport_type transport)
 finds entry in list, or returns NULL.
void adjust_packet (struct entry *match, ldns_pkt *answer_pkt, ldns_pkt *query_pkt)
 copy & adjust packet
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.
void delete_replylist (struct reply_packet *replist)
 delete the list of reply packets
void delete_entry (struct entry *list)
 Delete linked list of entries.

Variables

static const char * prog_name = "ldns-testpkts"
 string to show in warnings and errors

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:


Enumeration Type Documentation

verbosity definition for compat

Enumerator:
NO_VERBOSE 

0 - no verbose messages

VERB_OPS 

1 - operational information

VERB_DETAIL 

2 - detailed information

VERB_QUERY 

3 - query level information

VERB_ALGO 

4 - algorithm level information

VERB_CLIENT 

5 - querier client information


Function Documentation

static bool str_keyword ( char **  str,
const char *  keyword 
) [static]

true if the string starts with the keyword given.

Moves the str ahead.

Parameters:
str,: before keyword, afterwards after keyword and spaces.
keyword,: the keyword to match
Returns:
: true if keyword present. False otherwise, and str unchanged.

Referenced by adjustline(), matchline(), read_entry(), and replyline().

static size_t hexstr2bin ( char *  hexstr,
int  len,
uint8_t *  buf,
size_t  offset,
size_t  buf_len 
) [static]

Converts a hex string to binary data.

Parameters:
hexstr,: string of hex.
len,: is the length of the string
buf,: is the buffer to store the result in
offset,: is the starting position in the result buffer
buf_len,: is the length of buf.

This function returns the length of the result

Referenced by data_buffer2wire().

struct entry* read_entry ( FILE *  in,
const char *  name,
int *  lineno,
uint32_t *  default_ttl,
ldns_rdf **  origin,
ldns_rdf **  prev_rr 
) [read]

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.
lineno,: line number in file, incremented as lines are read. for prettier errors.
default_ttl,: on first call set to default TTL for entries, later it stores the $TTL value last seen. Try 3600 first call.
origin,: domain name for origin appending. Can be &NULL on first call. later it stores the $ORIGIN value last seen. Often &NULL or the zone name on first call.
prev_rr,: previous rr name for correcter parsing. &NULL on first call.
Returns:
: The entry read (malloced) or NULL if no entry could be read.

References adjustline(), data_buffer2wire(), entry_add_reply(), error(), get_origin(), isendline(), entry::lineno, matchline(), MAX_LINE, new_entry(), reply_packet::reply, reply_packet::reply_from_hex, replyline(), and str_keyword().

Referenced by read_datafile(), replay_moment_read(), and replay_range_read().

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:
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(), entry::copy_id, find_match(), reply_packet::next, reply_packet::packet_sleep, reply_packet::reply, reply_packet::reply_from_hex, entry::reply_list, and verbose().

Generated on Thu Apr 22 00:30:17 2010 for unbound by  doxygen 1.6.3