The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Functions
dns.h File Reference

Functions to manipulate DNS labels. More...

Go to the source code of this file.

Data Structures

struct  fr_dns_block_t
 
struct  fr_dns_labels_t
 

Functions

ssize_t fr_dns_label_from_value_box (size_t *need, uint8_t *buf, size_t buflen, uint8_t *where, bool compression, fr_value_box_t const *value, fr_dns_labels_t *lb)
 Encode a single value box of type string, serializing its contents to a dns label. More...
 
ssize_t fr_dns_label_from_value_box_dbuff (fr_dbuff_t *dbuff, bool compression, fr_value_box_t const *value, fr_dns_labels_t *lb)
 Encode a single value box of type string, serializing its contents to a dns label in a dbuff. More...
 
ssize_t fr_dns_label_to_value_box (TALLOC_CTX *ctx, fr_value_box_t *dst, uint8_t const *src, size_t len, uint8_t const *label, bool tainted, fr_dns_labels_t *lb)
 Decode a fr_value_box_t from one DNS label. More...
 
ssize_t fr_dns_label_uncompressed_length (uint8_t const *packet, uint8_t const *buf, size_t buf_len, uint8_t const **p_label, fr_dns_labels_t *lb)
 Get the uncompressed length of a DNS label in a network buffer. More...
 
ssize_t fr_dns_labels_network_verify (uint8_t const *packet, uint8_t const *buf, size_t buf_len, uint8_t const *start, fr_dns_labels_t *lb))
 Verify that a network buffer contains valid DNS labels. More...
 

Detailed Description

Functions to manipulate DNS labels.

Definition in file dns.h.


Data Structure Documentation

◆ fr_dns_block_t

struct fr_dns_block_t

Definition at line 30 of file dns.h.

Data Fields
uint16_t end
uint16_t start

◆ fr_dns_labels_t

struct fr_dns_labels_t

Definition at line 35 of file dns.h.

+ Collaboration diagram for fr_dns_labels_t:
Data Fields
fr_dns_block_t * blocks maximum number of labels

array holding "max" labels

uint8_t const * end end of the packet
uint8_t * mark markup buffer used for decoding.
int max
int num number of used labels
uint8_t const * start start of packet

Function Documentation

◆ fr_dns_label_from_value_box()

ssize_t fr_dns_label_from_value_box ( size_t need,
uint8_t buf,
size_t  buf_len,
uint8_t where,
bool  compression,
fr_value_box_t const *  value,
fr_dns_labels_t lb 
)

Encode a single value box of type string, serializing its contents to a dns label.

This functions takes a large buffer and encodes the label in part of the buffer. This API is necessary in order to allow DNS label compression.

Parameters
[out]needif not NULL, how long "buf_len" should be to serialize the rest of the data. Note: Only variable length types will be partially encoded. Fixed length types will not be partially encoded.
[out]bufBuffer where labels are stored
[in]buf_lenThe length of the output buffer
[out]whereWhere to write this label
[in]compressionWhether or not to do DNS label compression.
[in]valueto encode.
[in]lblabel tracking data structure
Returns
  • 0 no bytes were written, see need value to determine
  • >0 the number of bytes written to "where", NOT "buf + where + outlen"
  • <0 on error.

Definition at line 639 of file dns.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dns_label_from_value_box_dbuff()

ssize_t fr_dns_label_from_value_box_dbuff ( fr_dbuff_t dbuff,
bool  compression,
fr_value_box_t const *  value,
fr_dns_labels_t lb 
)

Encode a single value box of type string, serializing its contents to a dns label in a dbuff.

Parameters
[in]dbuffBuffer where labels are written
[in]compressionWhether or not to do DNS label compression.
[in]valueto encode.
[in]lblabel tracking data structure.
Returns
  • >0 the number of bytes written to the dbuff
  • 0 could not encode anything, an error has occurred.
  • <0 the number of bytes the dbuff should have had, instead of "remaining".

Definition at line 604 of file dns.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dns_label_to_value_box()

ssize_t fr_dns_label_to_value_box ( TALLOC_CTX *  ctx,
fr_value_box_t dst,
uint8_t const *  src,
size_t  len,
uint8_t const *  label,
bool  tainted,
fr_dns_labels_t lb 
)

Decode a fr_value_box_t from one DNS label.

The output type is always FR_TYPE_STRING

Note that the caller MUST call fr_dns_labels_network_verify(src, len, start) before calling this function. Otherwise bad things will happen.

Parameters
[in]ctxWhere to allocate any talloc buffers required.
[out]dstvalue_box to write the result to.
[in]srcStart of the buffer containing DNS labels
[in]lenLength of the buffer to decode
[in]labelThis particular label
[in]taintedWhether the value came from a trusted source.
[in]lblabel tracking data structure
Returns
  • >= 0 The number of network bytes consumed.
  • <0 on error.

Definition at line 1225 of file dns.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dns_label_uncompressed_length()

ssize_t fr_dns_label_uncompressed_length ( uint8_t const *  packet,
uint8_t const *  buf,
size_t  buf_len,
uint8_t const **  next,
fr_dns_labels_t lb 
)

Get the uncompressed length of a DNS label in a network buffer.

i.e. how bytes are required to store the uncompressed version of the label.

Note that a bare 0x00 byte has length 1, to account for '.'

Parameters
[in]packetwhere the packet starts
[in]bufbuffer holding one or more DNS labels
[in]buf_lentotal length of the buffer
[in,out]nextthe DNS label to check, updated to point to the next label
[in]lblabel tracking data structure
Returns
  • <=0 on error, offset from buf where the invalid label is located.
  • > 0 decoded size of this particular DNS label

Definition at line 884 of file dns.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dns_labels_network_verify()

ssize_t fr_dns_labels_network_verify ( uint8_t const *  packet,
uint8_t const *  buf,
size_t  buf_len,
uint8_t const *  start,
fr_dns_labels_t lb 
)

Verify that a network buffer contains valid DNS labels.

Parameters
[in]packetwhere the packet starts
[in]bufbuffer holding one or more DNS labels
[in]buf_lentotal length of the buffer
[in]startwhere to start looking
[in]lblabel tracking data structure
Returns
  • <=0 on error, where in the buffer the invalid label is located.
  • > 0 total size of the encoded label(s). Will be <= buf_len

Definition at line 1137 of file dns.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: