msgencode.h File Reference


int reply_info_answer_encode (struct query_info *qinf, struct reply_info *rep, uint16_t id, uint16_t qflags, struct sldns_buffer *dest, time_t timenow, int cached, struct regional *region, uint16_t udpsize, struct edns_data *edns, int dnssec, int secure)
 Generate answer from reply_info. More...
int reply_info_encode (struct query_info *qinfo, struct reply_info *rep, uint16_t id, uint16_t flags, struct sldns_buffer *buffer, time_t timenow, struct regional *region, uint16_t udpsize, int dnssec, int minimise)
 Regenerate the wireformat from the stored msg reply. More...
void qinfo_query_encode (struct sldns_buffer *pkt, struct query_info *qinfo)
 Encode query packet. More...
uint16_t calc_edns_field_size (struct edns_data *edns)
 Estimate size of EDNS record in packet. More...
void attach_edns_record (struct sldns_buffer *pkt, struct edns_data *edns)
 Attach EDNS record to buffer. More...
void error_encode (struct sldns_buffer *pkt, int r, struct query_info *qinfo, uint16_t qid, uint16_t qflags, struct edns_data *edns)
 Encode an error. More...

Detailed Description

This file contains temporary data structures and routines to create compressed DNS messages.

Function Documentation

◆ reply_info_answer_encode()

int reply_info_answer_encode ( struct query_info qinf,
struct reply_info rep,
uint16_t  id,
uint16_t  qflags,
struct sldns_buffer dest,
time_t  timenow,
int  cached,
struct regional region,
uint16_t  udpsize,
struct edns_data edns,
int  dnssec,
int  secure 

Generate answer from reply_info.

qinfquery information that provides query section in packet.
repreply to fill in.
idid word from the query.
qflagsflags word from the query.
destbuffer to put message into; will truncate if it does not fit.
timenowtime to subtract.
cachedset true if a cached reply (so no AA bit). set false for the first reply.
regionwhere to allocate temp variables (for compression).
udpsizesize of the answer, 512, from EDNS, or 64k for TCP.
ednsEDNS data included in the answer, NULL for none. or if edns_present = 0, it is not included.
dnssecif 0 DNSSEC records are omitted from the answer.
secureif 1, the AD bit is set in the reply.
: 0 on error (server failure).

References reply_info::authoritative, BIT_AA, BIT_AD, BIT_CD, BIT_RD, reply_info::flags, FLAGS_GET_RCODE, and query_info::local_alias.

Referenced by auth_answer_encode(), local_encode(), and rpz_local_encode().

◆ reply_info_encode()

int reply_info_encode ( struct query_info qinfo,
struct reply_info rep,
uint16_t  id,
uint16_t  flags,
struct sldns_buffer buffer,
time_t  timenow,
struct regional region,
uint16_t  udpsize,
int  dnssec,
int  minimise 

Regenerate the wireformat from the stored msg reply.

If the buffer is too small then the message is truncated at a whole rrset and the TC bit set, or whole rrsets are left out of the additional and the TC bit is not set.

qinfoquery info to store.
repreply to store.
idid value to store, network order.
flagsflags value to store, host order.
bufferbuffer to store the packet into.
timenowtime now, to adjust ttl values.
regionto store temporary data in.
udpsizesize of the answer, 512, from EDNS, or 64k for TCP.
dnssecif 0 DNSSEC records are omitted from the answer.
minimiseif true, the answer is a minimal response, with authority and additional removed if possible.
: nonzero is success, or 0 on error: malloc failure (no log_err has been done).

References sldns_buffer_clear(), sldns_buffer_limit(), sldns_buffer_remaining(), and sldns_buffer_set_limit().

◆ qinfo_query_encode()

◆ calc_edns_field_size()

uint16_t calc_edns_field_size ( struct edns_data edns)

Estimate size of EDNS record in packet.

EDNS record will be no larger.

ednsedns data or NULL.
octets to reserve for EDNS.

References edns_data::edns_present, edns_option::next, edns_option::opt_len, edns_data::opt_list_inplace_cb_out, and edns_data::opt_list_out.

Referenced by error_encode(), and write_q().

◆ attach_edns_record()

void attach_edns_record ( struct sldns_buffer pkt,
struct edns_data edns 

Attach EDNS record to buffer.

Buffer has complete packet. There must be enough room left for the EDNS record.

pktpacket added to.
ednsif NULL or present=0, nothing is added to the packet.

References edns_data::edns_present.

Referenced by error_encode(), and write_q().

◆ error_encode()

void error_encode ( struct sldns_buffer pkt,
int  r,
struct query_info qinfo,
uint16_t  qid,
uint16_t  qflags,
struct edns_data edns 

Encode an error.

With QR and RA set.

pktwhere to store the packet.
rRCODE value to encode.
qinfoif not NULL, the query is included.
qidquery ID to set in packet. network order.
qflagsoriginal query flags (to copy RD and CD bits). host order.
ednsif not NULL, this is the query edns info, and an edns reply is attached. Only attached if EDNS record fits reply.

References attach_edns_record(), BIT_CD, BIT_QR, BIT_RA, BIT_RD, edns_data::bits, calc_edns_field_size(), packed_rrset_key::dname, packed_rrset_key::dname_len, EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, EDNS_DO, edns_data::edns_version, edns_data::ext_rcode, query_info::local_alias, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, ub_packed_rrset_key::rk, local_rrset::rrset, sldns_buffer_clear(), sldns_buffer_current(), sldns_buffer_flip(), sldns_buffer_limit(), sldns_buffer_skip(), sldns_buffer_write(), sldns_buffer_write_u16(), and edns_data::udp_size.

Referenced by auth_answer_encode(), auth_error_encode(), libworker_bg_done_cb(), local_encode(), and rpz_local_encode().