/*
* packet.h -- low-level DNS packet encoding and decoding functions.
*
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
*
* See LICENSE for the license.
*
*/
#ifndef PACKET_H
#define PACKET_H
#include <sys/types.h>
#include "dns.h"
#include "namedb.h"
struct query;
/*
* Set of macro's to deal with the dns message header as specified
* in RFC1035 in portable way.
*
*/
/* Counter of the question section */
#define QDCOUNT(packet) (buffer_read_u16_at((packet), 4))
#define QDCOUNT_SET(packet, c) (buffer_write_u16_at((packet), 4, (c)))
/* Counter of the answer section */
#define ANCOUNT(packet) (buffer_read_u16_at((packet), 6))
#define ANCOUNT_SET(packet, c) (buffer_write_u16_at((packet), 6, (c)))
/* Counter of the authority section */
#define NSCOUNT(packet) (buffer_read_u16_at((packet), 8))
#define NSCOUNT_SET(packet, c) (buffer_write_u16_at((packet), 8, (c)))
/* Counter of the additional section */
#define ARCOUNT(packet) (buffer_read_u16_at((packet), 10))
#define ARCOUNT_SET(packet, c) (buffer_write_u16_at((packet), 10, (c)))
/* Miscellaneous limits */
#define MAX_PACKET_SIZE 65535 /* Maximum supported size of DNS packets. */
#define QIOBUFSZ (MAX_PACKET_SIZE + MAX_RR_SIZE)
#define MAXRRSPP 10240 /* Maximum number of rr's per packet */
#define MAX_COMPRESSED_DNAMES MAXRRSPP /* Maximum number of compressed domains. */
#define MAX_COMPRESSION_OFFSET 16383 /* Compression pointers are 14 bit. */
#define IPV4_MINIMAL_RESPONSE_SIZE 1232 /* Recommended minimal edns size for IPv4 */
#define IPV6_MINIMAL_RESPONSE_SIZE 1220 /* Recommended minimal edns size for IPv6 */
/* use round robin rotation */
extern int round_robin;
/* use minimal responses (more minimal, with additional only for referrals) */
extern int minimal_responses;
/*
* Encode RR with OWNER as owner name into QUERY. Returns the number
* of RRs successfully encoded.
*/
int packet_encode_rr(struct query *query,
domain_type *owner,
rr_type *rr,
uint32_t ttl);
/*
* Encode RRSET with OWNER as the owner name into QUERY. Returns the
* number of RRs successfully encoded. If TRUNCATE_RRSET the entire
* RRset is truncated in case an RR (or the RRsets signature) does not
* fit.
*/
int packet_encode_rrset(struct query *query,
domain_type *owner,
rrset_type *rrset,
int truncate_rrset,
size_t minimal_respsize,
int* done);
/*
* Skip the RR at the current position in PACKET.
*/
int packet_skip_rr(buffer_type *packet, int question_section);
/*
* Skip the dname at the current position in PACKET.
*/
int packet_skip_dname(buffer_type *packet);
/*
* Read the RR at the current position in PACKET.
*/
rr_type *packet_read_rr(region_type *region,
domain_table_type *owners,
buffer_type *packet,
int question_section);
/*
* read a query entry from network packet given in buffer.
* does not follow compression ptrs, checks for errors (returns 0).
* Dest must be at least MAXDOMAINLEN long.
*/
int packet_read_query_section(buffer_type *packet,
uint8_t* dest,
uint16_t* qtype,
uint16_t* qclass);
/* read notify SOA serial from packet. buffer position is unmodified on return.
* returns false on no-serial found or parse failure. */
int packet_find_notify_serial(buffer_type *packet, uint32_t* serial);