unbound 0.1
testpkts.c File Reference

This is a debugging aid. More...

#include "config.h"
#include <errno.h>
#include <stdarg.h>
#include <ctype.h>
#include "testcode/testpkts.h"
#include "util/net_help.h"
#include "sldns/sbuffer.h"
#include "sldns/rrdef.h"
#include "sldns/pkthdr.h"
#include "sldns/str2wire.h"
#include "sldns/wire2str.h"

Macros

#define MAX_PACKETLEN   65536
 max size of a packet
#define MAX_LINE   10240
 max line length

Enumerations

enum  verbosity_value { NO_VERBOSE =0 }
 verbosity definition for compat

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 int isendline (char c)
 return if string is empty or comment
static int str_keyword (char **str, const char *keyword)
 true if the string starts with the keyword given.
static struct reply_packet * entry_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, uint8_t *reply, size_t reply_len, int *do_flag, int *co_flag)
 parse REPLY line
static void adjustline (char *line, struct entry *e, struct reply_packet *pkt)
 parse ADJUST line
static struct entry * new_entry (void)
 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 sldns_buffer * hex_buffer2wire (sldns_buffer *data_buffer)
 convert hex buffer to binary buffer
static void get_origin (const char *name, struct sldns_file_parse_state *pstate, char *parse)
 parse ORIGIN
static void add_rr (char *rrstr, uint8_t *pktbuf, size_t pktsize, size_t *pktlen, struct sldns_file_parse_state *pstate, sldns_pkt_section add_section, const char *fname)
 add RR to packet
static void add_edns (uint8_t *pktbuf, size_t pktsize, int do_flag, int co_flag, uint8_t *ednsdata, uint16_t ednslen, size_t *pktlen)
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 * read_datafile (const char *name, int skip_whitespace)
 reads the canned reply file and returns a list of structs does an exit on error.
static sldns_rr_type get_qtype (uint8_t *pkt, size_t pktlen)
 get qtype from packet
static size_t get_qname_len (uint8_t *pkt, size_t pktlen)
 get qtype from packet
static uint8_t * get_qname (uint8_t *pkt, size_t pktlen)
 returns owner from packet
static int get_opcode (uint8_t *pkt, size_t pktlen)
 returns opcode from packet
static int get_rcode (uint8_t *pkt, size_t pktlen)
 returns rcode from packet
static uint32_t get_serial (uint8_t *p, size_t plen)
 get authority section SOA serial value
static int pkt_find_edns_opt (uint8_t **p, size_t *plen)
 get ptr to EDNS OPT record (and remaining length); after the type u16
static int get_has_edns (uint8_t *pkt, size_t len)
 return true if the packet has EDNS OPT record
static int get_do_flag (uint8_t *pkt, size_t len)
 return true if the DO flag is set
static int get_co_flag (uint8_t *pkt, size_t len)
 return true if the CO flag is set
static int pkt_snip_edns_option (uint8_t *pkt, size_t len, sldns_edns_option code, uint8_t *buf)
 Snips the specified EDNS option out of the OPT record and puts it in the provided buffer.
static int extract_ede (uint8_t *pkt, size_t len)
 Snips the EDE option out of the OPT record and returns the EDNS EDE INFO-CODE if found, else -1.
static int extract_cookie (uint8_t *pkt, size_t len, uint8_t *cookie)
 Snips the DNS Cookie option out of the OPT record and puts it in the provided cookie buffer (should be at least 24 octets).
static void zerottls (uint8_t *pkt, size_t pktlen)
 zero TTLs in packet
static int get_line (char **s, char **n)
 get one line (
) from a string, move next to after the
, zero

static int match_noloc_section (char **q, char **nq, char **p, char **np, uint16_t num)
 match two RR sections without ordering
static int match_noloc (char *q, char *p, uint8_t *q_pkt, size_t q_pkt_len, uint8_t *p_pkt, size_t p_pkt_len)
 match two strings for unordered equality of RRs and everything else
static void lowercase_dname (uint8_t **p, size_t *remain)
 lowercase domain name - does not follow compression pointers
static void lowercase_rdata (uint8_t **p, size_t *remain, uint16_t rdatalen, uint16_t t)
 lowercase rdata of type
static void lowercase_pkt (uint8_t *pkt, size_t pktlen)
 lowercase all names in the message
static int match_question (uint8_t *q, size_t qlen, uint8_t *p, size_t plen, int mttl)
 match question section of packet
static int match_answer (uint8_t *q, size_t qlen, uint8_t *p, size_t plen, int mttl)
 match answer section of packet
static int ignore_edns_lines (char *str)
 ignore EDNS lines in the string by overwriting them with what's left or zero out if at end of the string
int match_all (uint8_t *q, size_t qlen, uint8_t *p, size_t plen, int mttl, int noloc, int noedns)
 match all of the packet
static int equal_dname (uint8_t *q, size_t qlen, uint8_t *p, size_t plen)
 see if domain names are equal
static int subdomain_dname (uint8_t *q, size_t qlen, uint8_t *p, size_t plen)
 see if domain names are subdomain q of p
static int match_ednsdata (uint8_t *q, size_t qlen, uint8_t *p, size_t plen)
 Match OPT RDATA (not the EDNS payload size or flags).
struct entry * find_match (struct entry *entries, uint8_t *query_pkt, size_t len, enum transport_type transport)
 finds entry in list, or returns NULL.
void adjust_packet (struct entry *match, uint8_t **answer_pkt, size_t *answer_len, uint8_t *query_pkt, size_t query_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.
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 = "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:

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

Macro Definition Documentation

◆ MAX_PACKETLEN

#define MAX_PACKETLEN   65536

max size of a packet

Referenced by hex_buffer2wire(), and read_entry().

◆ MAX_LINE

#define MAX_LINE   10240

max line length

Referenced by read_entry().

Function Documentation

◆ verbose()

void verbose ( enum verbosity_value lvl,
const char * msg,
... )

logging routine, provided by caller

References verbose().

Referenced by acl_list_insert(), add_open(), adjust_packet(), adjust_ttl(), allow_proxy_tree_insert(), already_validated(), anchor_read_bind_file(), anchor_read_bind_file_wild(), answer_from_cache(), apply_http(), apply_ixfr(), auth_xfer_probe_lookup_callback(), auth_xfer_probe_timer_callback(), auth_xfer_probe_udp_callback(), auth_xfer_transfer_http_callback(), auth_xfer_transfer_lookup_callback(), auth_xfer_transfer_tcp_callback(), auth_xfer_transfer_timer_callback(), auth_zone_delegpt(), auth_zone_generate_zonemd_check(), auth_zone_log(), auth_zone_read_zonefile(), auth_zone_write_rrset(), auth_zone_zonemd_check_hash(), auth_zone_zonemd_fail(), autr_probe_timer(), autr_process_prime(), autr_read_file(), autr_write_file(), az_insert_rr(), az_parse_file(), call_root_update(), caps_strip_reply(), check_dates(), check_waiting_queries(), check_xfer_packet(), checkrlimits(), chunkline_get_line(), chunkline_get_line_collated(), comm_base_create(), comm_point_close(), comm_point_http2_handle_read(), comm_point_http2_handle_write(), comm_point_http_handle_callback(), comm_point_http_handle_read(), comm_point_listen_for_rw(), comm_point_perform_accept(), comm_point_send_udp_msg(), comm_point_send_udp_msg_if(), comm_point_slow_accept(), comm_point_start_listening(), comm_point_stop_listening(), comm_point_tcp_handle_callback(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), config_read(), consume_pp2_header(), create_local_accept_sock(), create_tcp_accept_sock(), create_udp_sock(), createResponse(), daemon_create_workers(), daemon_reload_sslctxs(), daemon_remote_exec(), daemon_start_others(), daemon_stop_others(), decommission_pending_tcp(), delegpt_add_ns(), delegpt_add_ns_mlc(), detect_wrongly_truncated(), dns64_adjust_a(), dns64_adjust_ptr(), dns64_apply_cfg(), dns64_operate(), dns_cache_store(), dns_cache_store_msg(), dns_error_reporting(), dnsc_handle_curved_request(), dnsc_load_local_data(), dnsc_parse_certs(), dnsc_parse_keys(), dnskey_verify_rrset(), dnskey_verify_rrset_sig(), dnskeyset_verify_rrset(), dnskeyset_verify_rrset_sig(), dnstap_io(), donotq_insert(), donotq_str_cfg(), ds_digest_match_dnskey(), ds_response_to_ke(), dstest_entry(), dt_io_thread_stop(), dtio_check_nb_connect(), dtio_cmd_cb(), dtio_control_stop_flush(), dtio_control_stop_send(), dtio_read_accept_frame(), dtio_reconnect_enable_timeout(), dtio_reconnect_timeout_cb(), dynlibmod_get_mem(), dynlibmod_init(), edns_opt_list_append_ede(), error_response(), error_response(), error_response_cache(), error_supers(), fast_reload_thread_main(), fd_for_dest(), fill_nsec3_iter(), find_create_proxy(), find_match(), forward_request(), fr_main_handle_cmd(), fr_main_perform_cmd(), fr_main_perform_done(), fr_main_perform_reload_stop(), fr_poll_for_ack(), fr_poll_for_quit(), fr_poll_for_reload_start(), fr_read_ack_from_workers(), fr_send_cmd_to(), fr_send_notification(), generate_a_aaaa_check(), generate_dnskey_prefetch(), generate_keytag_query(), generate_ns_check(), generate_request(), get_origin(), get_serial(), handle_event_moddone(), handle_event_pass(), handle_ipv6_ptr(), handle_query(), handle_req(), hints_apply_cfg(), http_chunked_segment(), http_process_chunk_header(), http_process_initial_header(), http_read_more(), infra_ratelimit_inc(), ipset_operate(), iter_apply_cfg(), iter_filter_order(), iter_filter_unsuitable(), iter_handle(), iter_operate(), iter_prepend(), iter_server_selection(), iter_stub_fwd_no_cache(), ixfr_start_serial(), key_matches_a_ds(), list_is_secure(), listen_sslctx_setup_ticket_keys(), local_data_answer(), local_data_find_tag_action(), local_zone_enter_rr(), local_zones_answer(), log_addr(), log_edns_known_options(), log_edns_opt_list(), log_hex_f(), log_init(), log_name_addr(), log_reuse_tcp(), log_rrlist_position(), lz_enter_zone_tags(), match_all(), match_answer(), match_ednsdata(), match_noloc_section(), match_question(), mesh_add_sub(), mesh_make_new_space(), mesh_new_client(), mesh_query_done(), mesh_run(), mesh_send_reply(), mesh_serve_expired_callback(), mesh_serve_expired_lookup(), mesh_stats(), modstack_call_init(), modstack_call_startup(), modstack_config(), needs_validation(), nsec3_do_prove_nameerror(), nsec3_do_prove_nodata(), nsec3_iteration_count_high(), nsec3_prove_closest_encloser(), nsec3_prove_nameerror(), nsec3_prove_nodata(), nsec3_prove_nods(), nsec3_prove_nxornodata(), nsec3_prove_wildcard(), outnet_get_tcp_fd(), outnet_tcp_cb(), outnet_tcp_take_into_use(), outnet_tcp_take_query_setup(), outnet_tcptimer(), outnet_udp_cb(), packed_rr_to_string(), param_set_same(), parse_edns_options_from_query(), parse_get_cname_target(), pending_tcp_query(), pending_udp_query(), pending_udp_timer_cb(), pending_udp_timer_delay_cb(), perform_setup(), pkt_dname_len_budget(), portcomm_loweruse(), ports_create_if(), prime_root(), prime_stub(), prime_supers(), prime_trust_anchor(), primeResponseToKE(), probe_anchor(), process_dnskey_response(), process_ds_response(), process_request(), process_response(), processCollectClass(), processDSNSFind(), processFindKey(), processFinished(), processFinished(), processInit(), processInitRequest(), processLastResort(), processPrimeResponse(), processQueryResponse(), processQueryTargets(), processTargetResponse(), processValidate(), pythonmod_clear(), pythonmod_get_mem(), query_for_targets(), read_addrs(), read_datafile(), read_forwards(), read_names(), read_root_hints(), receive_bytes(), reset_worker_timer_at(), respip_action_cfg(), respip_data_answer(), respip_operate(), respip_rewrite_reply(), reuse_move_writewait_away(), reuse_tcp_close_oldest(), reuse_tcp_find(), reuse_tcp_remove_serviced_keep(), reuse_tcp_remove_tree_list(), rpz_callback_from_iterator_cname(), rpz_callback_from_iterator_module(), rpz_callback_from_worker_request(), rpz_clientip_remove_trigger_rr(), rpz_insert_response_ip_trigger(), rpz_insert_rr(), rpz_remove_local_zones_trigger(), rr_is_selfsigned_revoked(), rrset_cache_update_wildcard(), rrset_canonical(), rrset_canonicalize_to_buffer(), run_daemon(), scrub_normalize(), scrub_sanitize(), select_id(), select_ifport(), server_stats_obtain(), server_stats_reply(), service(), service_init(), service_loop(), service_main(), service_send(), service_start(), serviced_callbacks(), serviced_delete(), serviced_perturb_qname(), serviced_tcp_callback(), serviced_tcp_initiate(), serviced_timer_cb(), serviced_udp_callback(), serviced_udp_send(), set_auth_name_on_ssl(), set_next_probe(), set_tp_times(), setup_http_request(), sock_list_logentry(), ssl_handle_read(), ssl_http_read_more(), tcl_list_insert(), tcp_more_read_again(), tcp_more_read_again_cb(), tcp_read_again_cb(), tcp_relay_read(), tcp_relay_write(), tcp_req_info_add_result(), tcp_req_info_clear(), tcp_req_info_handle_read_close(), tcp_req_info_read_again(), time_passes(), val_blacklist(), val_check_nonsecure(), val_dsset_isusable(), val_find_signer(), val_handle(), val_inform_super(), val_new_getmsg(), val_nsec_prove_nodata_dsreply(), val_operate(), val_verify_DNSKEY_with_DS(), val_verify_DNSKEY_with_TA(), validate_any_response(), validate_cname_noanswer_response(), validate_cname_response(), validate_msg_signatures(), validate_nameerror_response(), validate_nodata_response(), validate_positive_response(), validate_referral_response(), validate_suspend_setup_timer(), validate_suspend_timer_cb(), verbose(), verbose(), verbose(), verbose_key(), verbose_print_addr(), verify_dnskey(), verify_dnskeys_with_ds_rr(), waitforit(), waitforubanchor(), win_do_cron(), worker_check_request(), worker_handle_request(), worker_handle_service_reply(), worker_init(), worker_mem_report(), worker_stop_and_wait(), worker_win_stop_cb(), wsvc_cron_cb(), xfer_target_equals_answer_name(), xfr_master_add_addrs(), xfr_probe_send_or_end(), xfr_probe_send_probe(), xfr_process_chunk_list(), xfr_set_timeout(), xfr_transfer_init_fetch(), xfr_transfer_nexttarget_or_end(), zone_write_after_update(), and zonemd_is_duplicate_scheme_hash().

◆ error()

◆ isendline()

int isendline ( char c)
static

return if string is empty or comment

References isendline().

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

◆ str_keyword()

int str_keyword ( char ** str,
const char * keyword )
static

true if the string starts with the keyword given.

Moves the str ahead.

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

References str_keyword().

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

◆ entry_add_reply()

◆ matchline()

◆ replyline()

void replyline ( char * line,
uint8_t * reply,
size_t reply_len,
int * do_flag,
int * co_flag )
static

parse REPLY line

References error(), isendline(), reply_packet::reply_len, replyline(), and str_keyword().

Referenced by read_entry(), and replyline().

◆ adjustline()

◆ new_entry()

◆ hexstr2bin()

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
hexstrstring of hex.
lenis the length of the string
bufis the buffer to store the result in
offsetis the starting position in the result buffer
buf_lenis the length of buf.
Returns
This function returns the length of the result

References hexstr2bin().

Referenced by hex_buffer2wire(), and hexstr2bin().

◆ hex_buffer2wire()

sldns_buffer * hex_buffer2wire ( sldns_buffer * data_buffer)
static

◆ get_origin()

◆ add_rr()

void add_rr ( char * rrstr,
uint8_t * pktbuf,
size_t pktsize,
size_t * pktlen,
struct sldns_file_parse_state * pstate,
sldns_pkt_section add_section,
const char * fname )
static

◆ 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 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, read_entry(), 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(), read_entry(), replay_moment_read(), and replay_range_read().

◆ 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_datafile(), read_entry(), and verbose().

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

◆ get_qtype()

sldns_rr_type get_qtype ( uint8_t * pkt,
size_t pktlen )
static

get qtype from packet

References get_qtype(), and sldns_wire2str_dname_scan().

Referenced by find_match(), and get_qtype().

◆ get_qname_len()

size_t get_qname_len ( uint8_t * pkt,
size_t pktlen )
static

get qtype from packet

References get_qname_len(), and sldns_wire2str_dname_scan().

Referenced by adjust_packet(), and get_qname_len().

◆ get_qname()

uint8_t * get_qname ( uint8_t * pkt,
size_t pktlen )
static

returns owner from packet

References get_qname().

Referenced by equal_dname(), get_qname(), and subdomain_dname().

◆ get_opcode()

int get_opcode ( uint8_t * pkt,
size_t pktlen )
static

returns opcode from packet

References get_opcode().

Referenced by find_match(), and get_opcode().

◆ get_rcode()

int get_rcode ( uint8_t * pkt,
size_t pktlen )
static

returns rcode from packet

References get_rcode().

Referenced by find_match(), and get_rcode().

◆ get_serial()

uint32_t get_serial ( uint8_t * p,
size_t plen )
static

◆ pkt_find_edns_opt()

int pkt_find_edns_opt ( uint8_t ** p,
size_t * plen )
static

◆ get_has_edns()

int get_has_edns ( uint8_t * pkt,
size_t len )
static

return true if the packet has EDNS OPT record

References get_has_edns(), and pkt_find_edns_opt().

Referenced by find_match(), and get_has_edns().

◆ get_do_flag()

int get_do_flag ( uint8_t * pkt,
size_t len )
static

return true if the DO flag is set

References get_do_flag(), and pkt_find_edns_opt().

Referenced by find_match(), and get_do_flag().

◆ get_co_flag()

int get_co_flag ( uint8_t * pkt,
size_t len )
static

return true if the CO flag is set

References get_co_flag(), and pkt_find_edns_opt().

Referenced by find_match(), and get_co_flag().

◆ pkt_snip_edns_option()

int pkt_snip_edns_option ( uint8_t * pkt,
size_t len,
sldns_edns_option code,
uint8_t * buf )
static

Snips the specified EDNS option out of the OPT record and puts it in the provided buffer.

The buffer should be able to hold any opt data ie 65535. Returns the length of the option written, or 0 if not found, else -1 on error.

References pkt_find_edns_opt(), and pkt_snip_edns_option().

Referenced by extract_cookie(), extract_ede(), and pkt_snip_edns_option().

◆ extract_ede()

int extract_ede ( uint8_t * pkt,
size_t len )
static

Snips the EDE option out of the OPT record and returns the EDNS EDE INFO-CODE if found, else -1.

References extract_ede(), and pkt_snip_edns_option().

Referenced by extract_ede(), and find_match().

◆ extract_cookie()

int extract_cookie ( uint8_t * pkt,
size_t len,
uint8_t * cookie )
static

Snips the DNS Cookie option out of the OPT record and puts it in the provided cookie buffer (should be at least 24 octets).

Returns the length of the cookie if found, else -1.

References extract_cookie(), and pkt_snip_edns_option().

Referenced by extract_cookie(), and find_match().

◆ zerottls()

void zerottls ( uint8_t * pkt,
size_t pktlen )
static

◆ get_line()

int get_line ( char ** s,
char ** n )
static

get one line (
) from a string, move next to after the
, zero

References get_line().

Referenced by get_line(), match_noloc(), and match_noloc_section().

◆ match_noloc_section()

int match_noloc_section ( char ** q,
char ** nq,
char ** p,
char ** np,
uint16_t num )
static

match two RR sections without ordering

References fatal_exit(), get_line(), match_noloc_section(), and verbose().

Referenced by match_noloc(), and match_noloc_section().

◆ match_noloc()

int match_noloc ( char * q,
char * p,
uint8_t * q_pkt,
size_t q_pkt_len,
uint8_t * p_pkt,
size_t p_pkt_len )
static

match two strings for unordered equality of RRs and everything else

References get_line(), match_noloc(), and match_noloc_section().

Referenced by match_all(), and match_noloc().

◆ lowercase_dname()

void lowercase_dname ( uint8_t ** p,
size_t * remain )
static

lowercase domain name - does not follow compression pointers

References lowercase_dname().

Referenced by lowercase_dname(), lowercase_pkt(), and lowercase_rdata().

◆ lowercase_rdata()

◆ lowercase_pkt()

void lowercase_pkt ( uint8_t * pkt,
size_t pktlen )
static

lowercase all names in the message

References lowercase_dname(), lowercase_pkt(), and lowercase_rdata().

Referenced by lowercase_pkt(), match_all(), match_answer(), and match_question().

◆ match_question()

int match_question ( uint8_t * q,
size_t qlen,
uint8_t * p,
size_t plen,
int mttl )
static

match question section of packet

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

Referenced by find_match(), and match_question().

◆ match_answer()

int match_answer ( uint8_t * q,
size_t qlen,
uint8_t * p,
size_t plen,
int mttl )
static

match answer section of packet

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

Referenced by find_match(), and match_answer().

◆ ignore_edns_lines()

int ignore_edns_lines ( char * str)
static

ignore EDNS lines in the string by overwriting them with what's left or zero out if at end of the string

References ignore_edns_lines().

Referenced by ignore_edns_lines(), and match_all().

◆ match_all()

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

match all of the packet

match two packets, all must match

match all of the packet

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.
noednsif true, edns is not compared, if false, edns must match.
Returns
true if matched.

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

Referenced by find_match(), match_all(), and test_buffers().

◆ equal_dname()

int equal_dname ( uint8_t * q,
size_t qlen,
uint8_t * p,
size_t plen )
static

see if domain names are equal

References equal_dname(), get_qname(), and sldns_wire2str_dname_scan().

Referenced by equal_dname(), and find_match().

◆ subdomain_dname()

int subdomain_dname ( uint8_t * q,
size_t qlen,
uint8_t * p,
size_t plen )
static

see if domain names are subdomain q of p

References get_qname(), sldns_wire2str_dname_scan(), and subdomain_dname().

Referenced by find_match(), and subdomain_dname().

◆ match_ednsdata()

int match_ednsdata ( uint8_t * q,
size_t qlen,
uint8_t * p,
size_t plen )
static

Match OPT RDATA (not the EDNS payload size or flags).

References match_ednsdata(), pkt_find_edns_opt(), and verbose().

Referenced by find_match(), and match_ednsdata().

◆ find_match()

◆ adjust_packet()

void adjust_packet ( struct entry * match,
uint8_t ** answer_pkt,
size_t * answer_len,
uint8_t * query_pkt,
size_t query_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 adjust_packet(), entry::copy_ednsdata_assume_clientsubnet, entry::copy_id, entry::copy_query, get_qname_len(), entry::increment_ecs_scope, memdup(), pkt_find_edns_opt(), entry::sleeptime, and verbose().

Referenced by adjust_packet(), 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
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 adjust_packet(), find_match(), handle_query(), 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().

Referenced by handle_query().

◆ delete_replylist()

void delete_replylist ( struct reply_packet * replist)

◆ delete_entry()

void delete_entry ( struct entry * list)

Variable Documentation

◆ prog_name

const char* prog_name = "testpkts"
static

string to show in warnings and errors

Referenced by error(), and read_datafile().