Ripples 1.0
High Performant Software Architecture For Transaction Processing
Loading...
Searching...
No Matches
NS Utilities

Detailed Description

Collection of utilities for working with DNS queries. These utilities were copied from glibc then modified.

Data Structures

struct  rip_ns_header_s
 

Macros

#define RIP_NS_PACKETSZ   512
 
#define RIP_NS_UDP_MAXMSG   4096
 
#define RIP_NS_MAXMSG   65535
 
#define RIP_NS_MAXCDNAME   255
 
#define RIP_NS_MAXLABEL   63
 
#define RIP_NS_QFIXEDSZ   4
 
#define RIP_NS_RRFIXEDSZ   10
 
#define RIP_NS_INT32SZ   4
 
#define RIP_NS_INT16SZ   2
 
#define RIP_NS_INT8SZ   1
 
#define RIP_NS_INADDRSZ   4
 
#define RIP_NS_IN6ADDRSZ   16
 
#define RIP_NS_CMPRSFLGS   0xc0
 
#define RIP_NS_RESP_MAX_ANSW   128
 
#define RIP_NS_RESP_MAX_NS   16
 
#define RIP_NS_RESP_MAX_ADDL   128
 
#define RIP_NS_CDNAME_COMP_BUF_LEN   256
 
#define RIP_NS_QUERY_SET_END_CODE_AND_RETURN(q, c)
 
#define RIP_NS_GET16(s, cp)
 
#define RIP_NS_PUT16(s, cp)
 
#define RIP_NS_GET32(l, cp)
 
#define RIP_NS_PUT32(l, cp)
 

Typedefs

typedef enum rip_ns_flag_e rip_ns_flag_t
 
typedef enum rip_ns_opcode_e rip_ns_opcode_t
 
typedef enum rip_ns_rcode_e rip_ns_rcode_t
 
typedef enum rip_ns_type_e rip_ns_type_t
 
typedef enum rip_ns_class_e rip_ns_class_t
 
typedef enum rip_ns_ext_opt_code_e rip_ns_ext_opt_code_t
 
typedef struct rip_ns_header_s rip_ns_header_t
 

Enumerations

enum  rip_ns_flag_e {
  rip_ns_f_qr , rip_ns_f_opcode , rip_ns_f_aa , rip_ns_f_tc ,
  rip_ns_f_rd , rip_ns_f_ra , rip_ns_f_z , rip_ns_f_ad ,
  rip_ns_f_cd , rip_ns_f_rcode , rip_ns_f_max
}
 
enum  rip_ns_opcode_e {
  rip_ns_o_query = 0 , rip_ns_o_iquery = 1 , rip_ns_o_status = 2 , rip_ns_o_notify = 4 ,
  rip_ns_o_update = 5 , rip_ns_o_max = 6
}
 
enum  rip_ns_rcode_e {
  rip_ns_r_noerror = 0 , rip_ns_r_formerr = 1 , rip_ns_r_servfail = 2 , rip_ns_r_nxdomain = 3 ,
  rip_ns_r_notimpl = 4 , rip_ns_r_refused = 5 , rip_ns_r_yxdomain = 6 , rip_ns_r_yxrrset = 7 ,
  rip_ns_r_nxrrset = 8 , rip_ns_r_notauth = 9 , rip_ns_r_notzone = 10 , rip_ns_r_max = 11 ,
  rip_ns_r_badvers = 16 , rip_ns_r_badsig = 16 , rip_ns_r_badkey = 17 , rip_ns_r_badtime = 18 ,
  rip_ns_r_rip_unknown = -1 , rip_ns_r_rip_shortheader = -2 , rip_ns_r_rip_toolarge = -3 , rip_ns_r_rip_query_tc = -4 ,
  rip_ns_r_rip_pack_rr_err = -5 , rip_ns_r_rip_tcp_write_err = -6 , rip_ns_r_rip_tcp_write_close = -7
}
 
enum  rip_ns_type_e {
  rip_ns_t_invalid = 0 , rip_ns_t_a = 1 , rip_ns_t_ns = 2 , rip_ns_t_md = 3 ,
  rip_ns_t_mf = 4 , rip_ns_t_cname = 5 , rip_ns_t_soa = 6 , rip_ns_t_mb = 7 ,
  rip_ns_t_mg = 8 , rip_ns_t_mr = 9 , rip_ns_t_null = 10 , rip_ns_t_wks = 11 ,
  rip_ns_t_ptr = 12 , rip_ns_t_hinfo = 13 , rip_ns_t_minfo = 14 , rip_ns_t_mx = 15 ,
  rip_ns_t_txt = 16 , rip_ns_t_rp = 17 , rip_ns_t_afsdb = 18 , rip_ns_t_x25 = 19 ,
  rip_ns_t_isdn = 20 , rip_ns_t_rt = 21 , rip_ns_t_nsap = 22 , rip_ns_t_nsap_ptr = 23 ,
  rip_ns_t_sig = 24 , rip_ns_t_key = 25 , rip_ns_t_px = 26 , rip_ns_t_gpos = 27 ,
  rip_ns_t_aaaa = 28 , rip_ns_t_loc = 29 , rip_ns_t_nxt = 30 , rip_ns_t_eid = 31 ,
  rip_ns_t_nimloc = 32 , rip_ns_t_srv = 33 , rip_ns_t_atma = 34 , rip_ns_t_naptr = 35 ,
  rip_ns_t_kx = 36 , rip_ns_t_cert = 37 , rip_ns_t_a6 = 38 , rip_ns_t_dname = 39 ,
  rip_ns_t_sink = 40 , rip_ns_t_opt = 41 , rip_ns_t_apl = 42 , rip_ns_t_ds = 43 ,
  rip_ns_t_sshfp = 44 , rip_ns_t_ipseckey = 45 , rip_ns_t_rrsig = 46 , rip_ns_t_nsec = 47 ,
  rip_ns_t_dnskey = 48 , rip_ns_t_dhcid = 49 , rip_ns_t_nsec3 = 50 , rip_ns_t_nsec3param = 51 ,
  rip_ns_t_tlsa = 52 , rip_ns_t_smimea = 53 , rip_ns_t_hip = 55 , rip_ns_t_ninfo = 56 ,
  rip_ns_t_rkey = 57 , rip_ns_t_talink = 58 , rip_ns_t_cds = 59 , rip_ns_t_cdnskey = 60 ,
  rip_ns_t_openpgpkey = 61 , rip_ns_t_csync = 62 , rip_ns_t_spf = 99 , rip_ns_t_uinfo = 100 ,
  rip_ns_t_uid = 101 , rip_ns_t_gid = 102 , rip_ns_t_unspec = 103 , rip_ns_t_nid = 104 ,
  rip_ns_t_l32 = 105 , rip_ns_t_l64 = 106 , rip_ns_t_lp = 107 , rip_ns_t_eui48 = 108 ,
  rip_ns_t_eui64 = 109 , rip_ns_t_tkey = 249 , rip_ns_t_tsig = 250 , rip_ns_t_ixfr = 251 ,
  rip_ns_t_axfr = 252 , rip_ns_t_mailb = 253 , rip_ns_t_maila = 254 , rip_ns_t_any = 255 ,
  rip_ns_t_uri = 256 , rip_ns_t_caa = 257 , rip_ns_t_avc = 258 , rip_ns_t_ta = 32768 ,
  rip_ns_t_dlv = 32769 , rip_ns_t_max = 65536
}
 
enum  rip_ns_class_e {
  rip_ns_c_invalid = 0 , rip_ns_c_in = 1 , rip_ns_c_2 = 2 , rip_ns_c_chaos = 3 ,
  rip_ns_c_hs = 4 , rip_ns_c_none = 254 , rip_ns_c_any = 255 , rip_ns_c_max = 65536
}
 
enum  rip_ns_ext_opt_code_e { rip_ns_ext_opt_c_cs = 8 }
 

Functions

const char * rip_ns_class_to_str (rip_ns_class_t class)
 
const char * rip_ns_rr_type_to_str (rip_ns_type_t type)
 
bool rip_ns_rr_type_supported (uint16_t query_type)
 
bool rip_ns_rr_class_supported (uint16_t query_class)
 
void rip_ns_put16 (unsigned char *dst, uint16_t num)
 
int rip_ns_name_unpack (const unsigned char *msg, const unsigned char *eom, const unsigned char *src, unsigned char *dst, size_t dstsiz)
 
int rip_ns_name_pack (const unsigned char *src, unsigned char *dst, int dstsiz, const unsigned char **dnptrs, const unsigned char **lastdnptr)
 
int rip_ns_name_pton (const unsigned char *src, unsigned char *dst, size_t dstsiz)
 
int rip_ns_name_ntop (const unsigned char *src, char *dst, size_t dstsiz)
 
int rip_rr_name_get (const unsigned char *msg, const unsigned char *eom, const unsigned char *src, unsigned char *dst, size_t dstsiz, uint16_t *query_label_len)
 
int rip_ns_name_put (const unsigned char *src, unsigned char *dst, int dstsiz, const unsigned char **dnptrs, const unsigned char **lastdnptr)
 

Macro Definition Documentation

◆ RIP_NS_CDNAME_COMP_BUF_LEN

#define RIP_NS_CDNAME_COMP_BUF_LEN   256

size of buffer used to compress CDNAME.

◆ RIP_NS_CMPRSFLGS

#define RIP_NS_CMPRSFLGS   0xc0

Flag bits indicating name compression.

◆ RIP_NS_GET16

#define RIP_NS_GET16 (   s,
  cp 
)
Value:
do { \
const unsigned char *t_cp = (const unsigned char *)(cp); \
(s) = ((uint16_t)t_cp[0] << 8) \
| ((uint16_t)t_cp[1]) \
; \
(cp) += RIP_NS_INT16SZ; \
} while (0)
#define RIP_NS_INT16SZ
Definition rip_ns_utils.h:63

Get a network order unsigned 16 bit integer from buffer "cp" and store it in "s" in host order. "cp" pointer is advanced by 2 bytes.

◆ RIP_NS_GET32

#define RIP_NS_GET32 (   l,
  cp 
)
Value:
do { \
const unsigned char *t_cp = (const unsigned char *)(cp); \
(l) = ((uint32_t)t_cp[0] << 24) \
| ((uint32_t)t_cp[1] << 16) \
| ((uint32_t)t_cp[2] << 8) \
| ((uint32_t)t_cp[3]) \
; \
(cp) += RIP_NS_INT32SZ; \
} while (0)
#define RIP_NS_INT32SZ
Definition rip_ns_utils.h:62

Get a network order unsigned 32 bit integer from buffer "cp" and store it in "l" in host order. "cp" pointer is advanced by 4 bytes.

◆ RIP_NS_IN6ADDRSZ

#define RIP_NS_IN6ADDRSZ   16

IPv6 T_AAAA

◆ RIP_NS_INADDRSZ

#define RIP_NS_INADDRSZ   4

IPv4 T_A

◆ RIP_NS_INT16SZ

#define RIP_NS_INT16SZ   2

#/bytes of data in a uint16_t

◆ RIP_NS_INT32SZ

#define RIP_NS_INT32SZ   4

#/bytes of data in a uint32_t

◆ RIP_NS_INT8SZ

#define RIP_NS_INT8SZ   1

#/bytes of data in a uint8_t

◆ RIP_NS_MAXCDNAME

#define RIP_NS_MAXCDNAME   255

maximum compressed domain name

◆ RIP_NS_MAXLABEL

#define RIP_NS_MAXLABEL   63

maximum length of domain label

◆ RIP_NS_MAXMSG

#define RIP_NS_MAXMSG   65535

maximum message size

◆ RIP_NS_PACKETSZ

#define RIP_NS_PACKETSZ   512

Define constants based on RFC 883, RFC 1034, RFC 1035 default UDP packet size

◆ RIP_NS_PUT16

#define RIP_NS_PUT16 (   s,
  cp 
)
Value:
do { \
uint16_t t_s = (uint16_t)(s); \
unsigned char *t_cp = (unsigned char *)(cp); \
*t_cp++ = t_s >> 8; \
*t_cp = t_s; \
(cp) += RIP_NS_INT16SZ; \
} while (0)

Pack an unsigned 16 bit integer "s" in host order into buffer "cp" in network order. "cp" pointer is advanced by 2 bytes.

◆ RIP_NS_PUT32

#define RIP_NS_PUT32 (   l,
  cp 
)
Value:
do { \
uint32_t t_l = (uint32_t)(l); \
unsigned char *t_cp = (unsigned char *)(cp); \
*t_cp++ = t_l >> 24; \
*t_cp++ = t_l >> 16; \
*t_cp++ = t_l >> 8; \
*t_cp = t_l; \
(cp) += RIP_NS_INT32SZ; \
} while (0)

Pack an unsigned 32 bit integer "l" in host order into buffer "cp" in network order. "cp" pointer is advanced by 4 bytes.

◆ RIP_NS_QFIXEDSZ

#define RIP_NS_QFIXEDSZ   4

#/bytes of fixed data in query

◆ RIP_NS_QUERY_SET_END_CODE_AND_RETURN

#define RIP_NS_QUERY_SET_END_CODE_AND_RETURN (   q,
 
)
Value:
do { \
(q)->end_code = c; \
return; \
} while (0)

Macro to set a query code and return from function. This is useful when handling a query and we want to: set query end code and stop any further processing.

◆ RIP_NS_RESP_MAX_ADDL

#define RIP_NS_RESP_MAX_ADDL   128

Maximum number of additional record query response could have, excluding EDNS.

◆ RIP_NS_RESP_MAX_ANSW

#define RIP_NS_RESP_MAX_ANSW   128

Maximum number of answer record query response could have.

◆ RIP_NS_RESP_MAX_NS

#define RIP_NS_RESP_MAX_NS   16

Maximum number of authority record query response could have.

◆ RIP_NS_RRFIXEDSZ

#define RIP_NS_RRFIXEDSZ   10

#/bytes of fixed data in r record

◆ RIP_NS_UDP_MAXMSG

#define RIP_NS_UDP_MAXMSG   4096

maximum UDP response message size

Typedef Documentation

◆ rip_ns_class_t

Values for DNS resource record class field

◆ rip_ns_ext_opt_code_t

EDNS extension option codes

◆ rip_ns_flag_t

DNS message header flags.

◆ rip_ns_header_t

Structure for DNS query header. The order of the fields is machine- and compiler-dependent, depending on the byte/bit order and the layout of bit fields. We use bit fields only in int variables, as this is all ANSI requires.

◆ rip_ns_opcode_t

DNS opcodes.

◆ rip_ns_rcode_t

DNS response codes.

◆ rip_ns_type_t

Currently defined type values for DNS resources and queries.

Enumeration Type Documentation

◆ rip_ns_class_e

Values for DNS resource record class field

Enumerator
rip_ns_c_invalid 

Cookie.

rip_ns_c_in 

Internet.

rip_ns_c_2 

unallocated/unsupported.

rip_ns_c_chaos 

MIT Chaos-net.

rip_ns_c_hs 

MIT Hesiod.

rip_ns_c_none 

for prereq. sections in update requests

rip_ns_c_any 

Wildcard match.

◆ rip_ns_ext_opt_code_e

EDNS extension option codes

◆ rip_ns_flag_e

DNS message header flags.

Enumerator
rip_ns_f_qr 

Question/Response.

rip_ns_f_opcode 

Operation code.

rip_ns_f_aa 

Authoritative Answer.

rip_ns_f_tc 

Truncation occurred.

rip_ns_f_rd 

Recursion Desired.

rip_ns_f_ra 

Recursion Available.

rip_ns_f_z 

MBZ.

rip_ns_f_ad 

Authentic Data (DNSSEC).

rip_ns_f_cd 

Checking Disabled (DNSSEC).

rip_ns_f_rcode 

Response code.

◆ rip_ns_opcode_e

DNS opcodes.

Enumerator
rip_ns_o_query 

Standard query.

rip_ns_o_iquery 

Inverse query (deprecated/unsupported).

rip_ns_o_status 

Name server status query (unsupported).

rip_ns_o_notify 

Zone change notification.

rip_ns_o_update 

Zone update message.

◆ rip_ns_rcode_e

DNS response codes.

Enumerator
rip_ns_r_formerr 

Format error.

rip_ns_r_servfail 

Server failure.

rip_ns_r_nxdomain 

Name error.

rip_ns_r_notimpl 

Unimplemented.

rip_ns_r_refused 

Operation refused.

rip_ns_r_yxdomain 

Name exists

rip_ns_r_yxrrset 

RRset exists

rip_ns_r_nxrrset 

RRset does not exist

rip_ns_r_notauth 

Not authoritative for zone

rip_ns_r_notzone 

Zone of record different from zone section

rip_ns_r_rip_tcp_write_err 

TCP connection write error, query response not sent

rip_ns_r_rip_tcp_write_close 

TCP connection closed for write, query response not sent

◆ rip_ns_type_e

Currently defined type values for DNS resources and queries.

Function Documentation

◆ rip_ns_class_to_str()

const char * rip_ns_class_to_str ( rip_ns_class_t  class)

Convert Resource Record enum class to string.

Parameters
classRR class to get string representation for.
Returns
Returns pointer to string representation of RR class.
Here is the caller graph for this function:

◆ rip_ns_name_ntop()

int rip_ns_name_ntop ( const unsigned char *  src,
char *  dst,
size_t  dstsiz 
)

Converts an uncompressed, encoded domain name to printable ASCII as per RFC1035. Returns the number of bytes written to buffer, or -1 (with errno set). The root is returned as "." All other domains are returned in non absolute form.

Parameters
srcEncoded domain name to convert to printable ASCII.
dstDestination buffer where to store converted string.
dstsizSize of destination buffer.
Returns
On success returns length of string in destination buffer, otherwise returns -1 indicating and error occurred.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rip_ns_name_pack()

int rip_ns_name_pack ( const unsigned char *  src,
unsigned char *  dst,
int  dstsiz,
const unsigned char **  dnptrs,
const unsigned char **  lastdnptr 
)

Packs domain name SRC into DST. Domain name MUST be in "network" format. To convert C string to "network" format use rip_ns_name_pton().

DNPTRS is an array of pointers to previous compressed names. DNPTRS[0] is a pointer to the beginning of the message. The array ends with NULL. LASTDNPTR is a pointer to the end of the array pointed to by 'dnptrs'.

The list of pointers in DNPTRS is updated for labels inserted into the message as we compress the name. If DNPTRS is NULL, we don't try to compress names. If LASTDNPTR is NULL, we don't update the list.

Parameters
srcDomain name in "network" format to pack.
dstDestination buffer where to pack the domain name.
dstsizLength of destination buffer.
dnptrs
lastdnptr
Returns
Returns size of the compressed name, or -1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rip_ns_name_pton()

int rip_ns_name_pton ( const unsigned char *  src,
unsigned char *  dst,
size_t  dstsiz 
)

Converts an ASCII string into an encoded domain name as per RFC1035. Enforces label and domain length limits.

Parameters
srcString to encode.
dstDestination buffer to store encoded string.
dstsizSize of destination buffer.
Returns
Returns -1 if it fails, 1 if string was fully qualified, 0 is string was not fully qualified.
Here is the caller graph for this function:

◆ rip_ns_name_put()

int rip_ns_name_put ( const unsigned char *  src,
unsigned char *  dst,
int  dstsiz,
const unsigned char **  dnptrs,
const unsigned char **  lastdnptr 
)

Packs domain name SRC into DST. Domain name MUST be a C string. This function converts the C string into "network" format, then packs it into destination buffer.

DNPTRS is an array of pointers to previous compressed names. DNPTRS[0] is a pointer to the beginning of the message. The array ends with NULL. LASTDNPTR is a pointer to the end of the array pointed to by 'dnptrs'.

The list of pointers in DNPTRS is updated for labels inserted into the message as we compress the name. If DNPTRS is NULL, we don't try to compress names. If LASTDNPTR is NULL, we don't update the list.

DNPTRS should be initialized when ready to populate DNS response. It should then be used for all rip_ns_name_put() and rip_ns_name_pack() calls while adding RRs to DNS response.

Parameters
srcDomain name in "network" format to pack.
dstDestination buffer where to pack the domain name.
dstsizLength of destination buffer.
dnptrs
lastdnptr
Returns
Returns size of the compressed name, or -1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rip_ns_name_unpack()

int rip_ns_name_unpack ( const unsigned char *  msg,
const unsigned char *  eom,
const unsigned char *  src,
unsigned char *  dst,
size_t  dstsiz 
)

Unpack a domain name from a message Resource Record (RR), source may be compressed. Unpacked name will be in "network" format. Use rip_ns_name_ntop() function to convert from "network" to regular C string.

Note
msg passed in MUST be a continuous buffer.
Parameters
msgPointer to first byte of DNS message.
eomPointer to last byte DNS in message.
srcPointer to first byte of RR name.
dstPointer to buffer where to store the unpacked RR name.
dstsizSize of destination buffer.
Returns
Returns -1 if it fails, or consumed octets if it succeeds.
Here is the caller graph for this function:

◆ rip_ns_put16()

void rip_ns_put16 ( unsigned char *  dst,
uint16_t  num 
)
inline

Pack an unsigned 16 bit integer "num" in host order into buffer "dst" in network order.

Parameters
dstDestination where to store packed unsigned 16 bit integer.
numNumber to pack.
Here is the caller graph for this function:

◆ rip_ns_rr_class_supported()

bool rip_ns_rr_class_supported ( uint16_t  query_class)

Check if DNS resource record class is one of supported types.

Note
Currently only class of IN (Internet) is supported.
Parameters
query_classDNS resource record type to check.
Returns
Returns true if type is one of supported DNS resource record types, otherwise returns false.
Here is the caller graph for this function:

◆ rip_ns_rr_type_supported()

bool rip_ns_rr_type_supported ( uint16_t  query_type)

Check if DNS resource record type is one of supported types.

Parameters
query_typeDNS resource record type to check.
Returns
Returns true if type is one of supported DNS resource record types, otherwise returns false.
Here is the caller graph for this function:

◆ rip_ns_rr_type_to_str()

const char * rip_ns_rr_type_to_str ( rip_ns_type_t  type)

Convert Resource Record enum type to string.

Parameters
typeRR type to get string representation for.
Returns
Returns pointer to string representation of RR type.
Here is the caller graph for this function:

◆ rip_rr_name_get()

int rip_rr_name_get ( const unsigned char *  msg,
const unsigned char *  eom,
const unsigned char *  src,
unsigned char *  dst,
size_t  dstsiz,
uint16_t *  query_label_len 
)

Get a domain name from a message Resource Record (RR), source may be compressed. Unpacked name will be in stored in "dst" as to regular C string.

Note
msg passed in MUST be a continuous buffer.
Parameters
msgPointer to first byte of DNS message.
eomPointer to last byte DNS in message.
srcPointer to first byte of RR name.
dstPointer to buffer where to store the unpacked RR name.
dstsizSize of destination buffer.
query_label_lenPointer where to store length of label extracted and stored in dst.
Returns
Returns -1 if it fails, or consumed octets if it succeeds.
Here is the call graph for this function:
Here is the caller graph for this function: