The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
decode.c File Reference

Functions to decode DNS packets. More...

#include <freeradius-devel/io/test_point.h>
#include <freeradius-devel/util/dns.h>
#include <freeradius-devel/util/proto.h>
#include <freeradius-devel/util/struct.h>
#include "dns.h"
#include "attrs.h"
+ Include dependency graph for decode.c:

Go to the source code of this file.

Macros

#define DNS_GET_OPTION_LEN(_x)   fr_nbo_to_uint16((_x) + 2)
 
#define DNS_GET_OPTION_NUM(_x)   fr_nbo_to_uint16(_x)
 

Functions

static ssize_t decode_option (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
 
static ssize_t decode_proto (TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, void *proto_ctx)
 
static ssize_t decode_record (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *attr, uint8_t const *rr, uint8_t const *end, fr_dns_ctx_t *packet_ctx, uint8_t const *counter)
 
static ssize_t decode_rr (TALLOC_CTX *ctx, fr_pair_list_t *out, UNUSED fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
 Decode DNS RR. More...
 
static int decode_test_ctx (void **out, TALLOC_CTX *ctx)
 
static ssize_t decode_tlv_trampoline (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
 
static ssize_t decode_value (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
 
static ssize_t decode_value_trampoline (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
 
ssize_t fr_dns_decode (TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *packet, size_t packet_len, fr_dns_ctx_t *packet_ctx)
 Decode a DNS packet. More...
 

Variables

fr_test_point_pair_decode_t dns_tp_decode_pair
 
fr_test_point_proto_decode_t dns_tp_decode_proto
 
fr_table_num_ordered_t fr_dns_reason_fail_table []
 
size_t fr_dns_reason_fail_table_len = NUM_ELEMENTS(fr_dns_reason_fail_table)
 

Detailed Description

Functions to decode DNS packets.

Id
6097a513850db9c462ca00b8bf7555072dc178c0
Author
Alan DeKok (aland.nosp@m.@fre.nosp@m.eradi.nosp@m.us.o.nosp@m.rg)

Definition in file decode.c.

Macro Definition Documentation

◆ DNS_GET_OPTION_LEN

#define DNS_GET_OPTION_LEN (   _x)    fr_nbo_to_uint16((_x) + 2)

Definition at line 172 of file decode.c.

◆ DNS_GET_OPTION_NUM

#define DNS_GET_OPTION_NUM (   _x)    fr_nbo_to_uint16(_x)

Definition at line 171 of file decode.c.

Function Documentation

◆ decode_option()

static ssize_t decode_option ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t const  data_len,
void *  decode_ctx 
)
static

Definition at line 174 of file decode.c.

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

◆ decode_proto()

static ssize_t decode_proto ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
uint8_t const *  data,
size_t  data_len,
void *  proto_ctx 
)
static

Definition at line 415 of file decode.c.

+ Here is the call graph for this function:

◆ decode_record()

static ssize_t decode_record ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  attr,
uint8_t const *  rr,
uint8_t const *  end,
fr_dns_ctx_t packet_ctx,
uint8_t const *  counter 
)
static

Definition at line 230 of file decode.c.

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

◆ decode_rr()

static ssize_t decode_rr ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
UNUSED fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t  data_len,
void *  decode_ctx 
)
static

Decode DNS RR.

Parameters
[in]ctxcontext to alloc new attributes in.
[in,out]outWhere to write the decoded options.
[in]parentto lookup attributes in.
[in]datato parse.
[in]data_lenof data to parse.
[in]decode_ctxUnused.

Definition at line 338 of file decode.c.

+ Here is the call graph for this function:

◆ decode_test_ctx()

static int decode_test_ctx ( void **  out,
TALLOC_CTX *  ctx 
)
static

Definition at line 375 of file decode.c.

◆ decode_tlv_trampoline()

static ssize_t decode_tlv_trampoline ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t const  data_len,
void *  decode_ctx 
)
static

Definition at line 44 of file decode.c.

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

◆ decode_value()

static ssize_t decode_value ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t const  data_len,
void *  decode_ctx 
)
static

Definition at line 66 of file decode.c.

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

◆ decode_value_trampoline()

static ssize_t decode_value_trampoline ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t const  data_len,
void *  decode_ctx 
)
static

Definition at line 52 of file decode.c.

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

◆ fr_dns_decode()

ssize_t fr_dns_decode ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
uint8_t const *  packet,
size_t  packet_len,
fr_dns_ctx_t packet_ctx 
)

Decode a DNS packet.

Definition at line 265 of file decode.c.

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

Variable Documentation

◆ dns_tp_decode_pair

fr_test_point_pair_decode_t dns_tp_decode_pair
Initial value:
= {
.test_ctx = decode_test_ctx,
.func = decode_rr
}
static ssize_t decode_rr(TALLOC_CTX *ctx, fr_pair_list_t *out, UNUSED fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
Decode DNS RR.
Definition: decode.c:338
static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
Definition: decode.c:375

Definition at line 448 of file decode.c.

◆ dns_tp_decode_proto

fr_test_point_proto_decode_t dns_tp_decode_proto
Initial value:
= {
.test_ctx = decode_test_ctx,
.func = decode_proto
}
static ssize_t decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, void *proto_ctx)
Definition: decode.c:415

Definition at line 454 of file decode.c.

◆ fr_dns_reason_fail_table

fr_table_num_ordered_t fr_dns_reason_fail_table[]
Initial value:
= {
{ L("none"), FR_DNS_DECODE_FAIL_NONE },
{ L("packet is smaller than DNS header"), FR_DNS_DECODE_FAIL_MIN_LENGTH_PACKET },
{ L("packet is larger than 65535"), FR_DNS_DECODE_FAIL_MAX_LENGTH_PACKET },
{ L("expected query / answer, got answer / query"), FR_DNS_DECODE_FAIL_UNEXPECTED },
{ L("no 'questions' in query packet"), FR_DNS_DECODE_FAIL_NO_QUESTIONS },
{ L("unexprected answers in query packet"), FR_DNS_DECODE_FAIL_ANSWERS_IN_QUESTION },
{ L("unexpected NS records in query packet"), FR_DNS_DECODE_FAIL_NS_IN_QUESTION },
{ L("invalid label for resource record"), FR_DNS_DECODE_FAIL_INVALID_RR_LABEL },
{ L("missing resource record header"), FR_DNS_DECODE_FAIL_MISSING_RR_HEADER },
{ L("missing resource record length field"), FR_DNS_DECODE_FAIL_MISSING_RR_LEN },
{ L("resource record length field is zero"), FR_DNS_DECODE_FAIL_ZERO_RR_LEN },
{ L("resource record length overflows the packet"), FR_DNS_DECODE_FAIL_RR_OVERFLOWS_PACKET },
{ L("more resource records than indicated in header"), FR_DNS_DECODE_FAIL_TOO_MANY_RRS },
{ L("fewer resource records than indicated in header"), FR_DNS_DECODE_FAIL_TOO_FEW_RRS },
{ L("pointer overflows packet"), FR_DNS_DECODE_FAIL_POINTER_OVERFLOWS_PACKET },
{ L("pointer points to packet header"), FR_DNS_DECODE_FAIL_POINTER_TO_HEADER },
{ L("pointer does not point to a label"), FR_DNS_DECODE_FAIL_POINTER_TO_NON_LABEL },
{ L("pointer creates a loop"), FR_DNS_DECODE_FAIL_POINTER_LOOPS },
{ L("invalid pointer"), FR_DNS_DECODE_FAIL_INVALID_POINTER },
{ L("label overflows the packet"), FR_DNS_DECODE_FAIL_LABEL_OVERFLOWS_PACKET },
{ L("too many characters in label"), FR_DNS_DECODE_FAIL_LABEL_TOO_LONG },
{ L("query record header is missing"), FR_DNS_DECODE_FAIL_MISSING_QD_HEADER },
{ L("missing TLV header in OPT RR"), FR_DNS_DECODE_FAIL_MISSING_TLV_HEADER },
{ L("TLV overflows enclosing RR"), FR_DNS_DECODE_FAIL_TLV_OVERFLOWS_RR },
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ FR_DNS_DECODE_FAIL_ANSWERS_IN_QUESTION
Definition: dns.h:108
@ FR_DNS_DECODE_FAIL_TOO_MANY_RRS
Definition: dns.h:115
@ FR_DNS_DECODE_FAIL_RR_OVERFLOWS_PACKET
Definition: dns.h:114
@ FR_DNS_DECODE_FAIL_INVALID_RR_LABEL
Definition: dns.h:110
@ FR_DNS_DECODE_FAIL_POINTER_TO_NON_LABEL
Definition: dns.h:117
@ FR_DNS_DECODE_FAIL_INVALID_POINTER
Definition: dns.h:121
@ FR_DNS_DECODE_FAIL_POINTER_OVERFLOWS_PACKET
Definition: dns.h:118
@ FR_DNS_DECODE_FAIL_LABEL_OVERFLOWS_PACKET
Definition: dns.h:122
@ FR_DNS_DECODE_FAIL_MISSING_TLV_HEADER
Definition: dns.h:125
@ FR_DNS_DECODE_FAIL_UNEXPECTED
Definition: dns.h:106
@ FR_DNS_DECODE_FAIL_POINTER_TO_HEADER
Definition: dns.h:119
@ FR_DNS_DECODE_FAIL_ZERO_RR_LEN
Definition: dns.h:113
@ FR_DNS_DECODE_FAIL_LABEL_TOO_LONG
Definition: dns.h:123
@ FR_DNS_DECODE_FAIL_TOO_FEW_RRS
Definition: dns.h:116
@ FR_DNS_DECODE_FAIL_MISSING_RR_LEN
Definition: dns.h:112
@ FR_DNS_DECODE_FAIL_MISSING_QD_HEADER
Definition: dns.h:124
@ FR_DNS_DECODE_FAIL_MAX_LENGTH_PACKET
Definition: dns.h:105
@ FR_DNS_DECODE_FAIL_NS_IN_QUESTION
Definition: dns.h:109
@ FR_DNS_DECODE_FAIL_NO_QUESTIONS
Definition: dns.h:107
@ FR_DNS_DECODE_FAIL_NONE
Definition: dns.h:103
@ FR_DNS_DECODE_FAIL_TLV_OVERFLOWS_RR
Definition: dns.h:126
@ FR_DNS_DECODE_FAIL_POINTER_LOOPS
Definition: dns.h:120
@ FR_DNS_DECODE_FAIL_MISSING_RR_HEADER
Definition: dns.h:111
@ FR_DNS_DECODE_FAIL_MIN_LENGTH_PACKET
Definition: dns.h:104

Definition at line 387 of file decode.c.

◆ fr_dns_reason_fail_table_len

size_t fr_dns_reason_fail_table_len = NUM_ELEMENTS(fr_dns_reason_fail_table)

Definition at line 413 of file decode.c.