iPXE
Data Structures | Macros | Functions | Variables
dns_test.c File Reference

DNS self-tests. More...

#include <string.h>
#include <assert.h>
#include <ipxe/dns.h>
#include <ipxe/test.h>

Go to the source code of this file.

Data Structures

struct  dns_encode_test
 A DNS encoding test. More...
 
struct  dns_decode_test
 A DNS decoding test. More...
 
struct  dns_compare_test
 A DNS comparison test. More...
 
struct  dns_copy_test
 A DNS copying test. More...
 
struct  dns_list_test
 A DNS search list test. More...
 

Macros

#define DATA(...)   { __VA_ARGS__ }
 Define inline data. More...
 
#define DNS_ENCODE(_name, _string, _data)
 Define a DNS encoding test. More...
 
#define dns_encode_ok(test)   dns_encode_okx ( test, __FILE__, __LINE__ )
 
#define dns_encode_fail_ok(test)   dns_encode_fail_okx ( test, __FILE__, __LINE__ )
 
#define DNS_DECODE(_name, _data, _offset, _string)
 Define a DNS decoding test. More...
 
#define dns_decode_ok(test)   dns_decode_okx ( test, __FILE__, __LINE__ )
 
#define dns_decode_fail_ok(test)   dns_decode_fail_okx ( test, __FILE__, __LINE__ )
 
#define DNS_COMPARE(_name, _first_data, _first_offset, _second_data, _second_offset)
 Define a DNS comparison test. More...
 
#define dns_compare_ok(test)   dns_compare_okx ( test, __FILE__, __LINE__ )
 
#define dns_compare_fail_ok(test)   dns_compare_fail_okx ( test, __FILE__, __LINE__ )
 
#define DNS_COPY(_name, _src_data, _src_offset, _dst_data, _dst_offset)
 Define a DNS copying test. More...
 
#define dns_copy_ok(test)   dns_copy_okx ( test, __FILE__, __LINE__ )
 
#define dns_copy_fail_ok(test)   dns_copy_fail_okx ( test, __FILE__, __LINE__ )
 
#define DNS_LIST(_name, _list, _strings)
 Define a DNS search list test. More...
 
#define dns_list_ok(test)   dns_list_okx ( test, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void dns_encode_okx (struct dns_encode_test *test, const char *file, unsigned int line)
 Report DNS encoding test result. More...
 
static void dns_encode_fail_okx (struct dns_encode_test *test, const char *file, unsigned int line)
 Report DNS encoding failure test result. More...
 
static void dns_decode_okx (struct dns_decode_test *test, const char *file, unsigned int line)
 Report DNS decoding test result. More...
 
static void dns_decode_fail_okx (struct dns_decode_test *test, const char *file, unsigned int line)
 Report DNS decoding failure test result. More...
 
static void dns_compare_okx (struct dns_compare_test *test, const char *file, unsigned int line)
 Report DNS comparison test result. More...
 
static void dns_compare_fail_okx (struct dns_compare_test *test, const char *file, unsigned int line)
 Report DNS comparison test failure result. More...
 
static void dns_copy_okx (struct dns_copy_test *test, const char *file, unsigned int line)
 Report a DNS copying test result. More...
 
static void dns_copy_fail_okx (struct dns_copy_test *test, const char *file, unsigned int line)
 Report a DNS copying failure test result. More...
 
static void dns_list_okx (struct dns_list_test *test, const char *file, unsigned int line)
 Report DNS search list test result. More...
 
 DNS_ENCODE (encode_simple, "ipxe.org", DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0))
 
 DNS_ENCODE (encode_single, "foo", DATA(3, 'f', 'o', 'o', 0))
 
 DNS_ENCODE (encode_absolute, "git.ipxe.org.", DATA(3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0))
 
 DNS_ENCODE (encode_empty, "", DATA(0))
 
 DNS_ENCODE (encode_root, ".", DATA(0))
 
 DNS_ENCODE (encode_initial_dot, ".foo", DATA())
 
 DNS_ENCODE (encode_double_dot, "ipxe..org", DATA())
 
 DNS_ENCODE (encode_solo_double_dot, "..", DATA())
 
 DNS_ENCODE (encode_trailing_double_dot, "ipxe.org..", DATA())
 
 DNS_ENCODE (encode_overlength, "this-label-is-maliciously-long-in-an-attempt-to-overflow-the-" "length-field-and-generate-a-length-which-looks-like-a-" "compression-pointer", DATA())
 
 DNS_DECODE (decode_simple, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0, "ipxe.org")
 
 DNS_DECODE (decode_ptr, DATA(3, 'o', 'r', 'g', 0, 3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 0xc0, 0x00), 5, "git.ipxe.org")
 
 DNS_DECODE (decode_root, DATA(0), 0, "")
 
 DNS_DECODE (decode_incomplete_name, DATA(4, 'i', 'p', 'x', 'e'), 0, NULL)
 
 DNS_DECODE (decode_incomplete_label, DATA(4, 'i', 'p', 'x'), 0, NULL)
 
 DNS_DECODE (decode_incomplete_ptr, DATA(3, 'o', 'r', 'g', 0, 4, 'i', 'p', 'x', 'e', 0xc0), 5, NULL)
 
 DNS_DECODE (decode_forward, DATA(0xc0, 0x02, 3, 'f', 'o', 'o', 0), 0, NULL)
 
 DNS_DECODE (decode_infinite, DATA(4, 'i', 'p', 'x', 'e', 0xc0, 0x00), 0, NULL)
 
 DNS_DECODE (decode_empty, DATA(), 0, NULL)
 
 DNS_COMPARE (compare_simple, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0)
 
 DNS_COMPARE (compare_ptr, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0, DATA(3, 'o', 'r', 'g', 0, 4, 'i', 'p', 'x', 'e', 0xc0, 0x00), 5)
 
 DNS_COMPARE (compare_case, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0, DATA(4, 'i', 'p', 'x', 'e', 3, 'O', 'R', 'G', 0), 0)
 
 DNS_COMPARE (compare_mismatch, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0, DATA(4, 'g', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0)
 
 DNS_COMPARE (compare_infinite, DATA(3, 'f', 'o', 'o', 0xc0, 0x00), 0, DATA(3, 'f', 'o', 'o', 0xc0, 0x00), 0)
 
 DNS_COPY (copy_simple, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0)
 
 DNS_COPY (copy_offset, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0, DATA( 'f', 'o', 'o', 0, 4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 4)
 
 DNS_COPY (copy_ptr, DATA(3, 'o', 'r', 'g', 0, 3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 0xc0, 0x00), 5, DATA(3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0), 0)
 
 DNS_COPY (copy_infinite, DATA(4, 'l', 'o', 'o', 'p', 7, 'f', 'o', 'r', 'e', 'v', 'e', 'r', 0xc0, 0x05), 0, DATA(), 0)
 
 DNS_LIST (search, DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0, 4, 'b', 'o', 'o', 't', 0xc0, 0x00, 3, 'd', 'e', 'v', 0xc0, 0x0a, 11, 'n', 'e', 't', 'w', 'o', 'r', 'k', 'b', 'o', 'o', 't', 0xc0, 0x05), DATA("ipxe.org", "boot.ipxe.org", "dev.boot.ipxe.org", "networkboot.org"))
 
static void dns_test_exec (void)
 Perform DNS self-test. More...
 

Variables

struct self_test dns_test __self_test
 DNS self-test. More...
 

Detailed Description

DNS self-tests.

Definition in file dns_test.c.

Macro Definition Documentation

◆ DATA

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 41 of file dns_test.c.

◆ DNS_ENCODE

#define DNS_ENCODE (   _name,
  _string,
  _data 
)
Value:
static const uint8_t _name ## __data[] = _data; \
static struct dns_encode_test _name = { \
.string = _string, \
.data = _name ## __data, \
.len = sizeof ( _name ## __data ), \
}
const char * string
String.
Definition: dns_test.c:46
A DNS encoding test.
Definition: dns_test.c:44
unsigned char uint8_t
Definition: stdint.h:10
int len
Length of encoded string.
Definition: dns_test.c:50

Define a DNS encoding test.

Parameters
_nameTest name
_stringTest string
_dataExpected encoded data
Return values
testDNS encoding test

Definition at line 61 of file dns_test.c.

◆ dns_encode_ok

#define dns_encode_ok (   test)    dns_encode_okx ( test, __FILE__, __LINE__ )

Definition at line 100 of file dns_test.c.

◆ dns_encode_fail_ok

#define dns_encode_fail_ok (   test)    dns_encode_fail_okx ( test, __FILE__, __LINE__ )

Definition at line 117 of file dns_test.c.

◆ DNS_DECODE

#define DNS_DECODE (   _name,
  _data,
  _offset,
  _string 
)
Value:
static uint8_t _name ## __data[] = _data; \
static struct dns_decode_test _name = { \
.name = { \
.data = _name ## __data, \
.offset = _offset, \
.len = sizeof ( _name ## __data ), \
}, \
.string = _string, \
}
const char * string
Expected string.
Definition: dns_test.c:125
void * data
Start of data.
Definition: dns.h:21
struct dns_name name
Name.
Definition: dns_test.c:123
A DNS decoding test.
Definition: dns_test.c:121
unsigned char uint8_t
Definition: stdint.h:10

Define a DNS decoding test.

Parameters
_nameTest name
_dataRFC1035-encoded data
_offsetStarting offset within encoded data
_stringExpected decoded string
Return values
testDNS decoding test

Definition at line 137 of file dns_test.c.

◆ dns_decode_ok

#define dns_decode_ok (   test)    dns_decode_okx ( test, __FILE__, __LINE__ )

Definition at line 175 of file dns_test.c.

◆ dns_decode_fail_ok

#define dns_decode_fail_ok (   test)    dns_decode_fail_okx ( test, __FILE__, __LINE__ )

Definition at line 191 of file dns_test.c.

◆ DNS_COMPARE

#define DNS_COMPARE (   _name,
  _first_data,
  _first_offset,
  _second_data,
  _second_offset 
)
Value:
static uint8_t _name ## __first_data[] = _first_data; \
static uint8_t _name ## __second_data[] = _second_data; \
static struct dns_compare_test _name = { \
.first = { \
.data = _name ## __first_data, \
.offset = _first_offset, \
.len = sizeof ( _name ## __first_data ), \
}, \
.second = { \
.data = _name ## __second_data, \
.offset = _second_offset, \
.len = sizeof ( _name ## __second_data ), \
}, \
}
A DNS comparison test.
Definition: dns_test.c:195
void * data
Start of data.
Definition: dns.h:21
struct dns_name first
First name.
Definition: dns_test.c:197
unsigned char uint8_t
Definition: stdint.h:10
struct dns_name second
Second name.
Definition: dns_test.c:199

Define a DNS comparison test.

Parameters
_nameTest name
_first_dataFirst RFC1035-encoded data
_first_offsetStarting offset within first encoded data
_second_dataSecond RFC1035-encoded data
_second_offsetStarting offset within second encoded data
Return values
testDNS comparison test

Definition at line 212 of file dns_test.c.

◆ dns_compare_ok

#define dns_compare_ok (   test)    dns_compare_okx ( test, __FILE__, __LINE__ )

Definition at line 241 of file dns_test.c.

◆ dns_compare_fail_ok

#define dns_compare_fail_ok (   test)    dns_compare_fail_okx ( test, __FILE__, __LINE__ )

Definition at line 255 of file dns_test.c.

◆ DNS_COPY

#define DNS_COPY (   _name,
  _src_data,
  _src_offset,
  _dst_data,
  _dst_offset 
)
Value:
static uint8_t _name ## __src_data[] = _src_data; \
static uint8_t _name ## __dst_data[] = _dst_data; \
static struct dns_copy_test _name = { \
.src = { \
.data = _name ## __src_data, \
.offset = _src_offset, \
.len = sizeof ( _name ## __src_data ), \
}, \
.dst = { \
.data = _name ## __dst_data, \
.offset = _dst_offset, \
.len = sizeof ( _name ## __dst_data ), \
}, \
}
void * data
Start of data.
Definition: dns.h:21
struct dns_name src
Source name.
Definition: dns_test.c:261
A DNS copying test.
Definition: dns_test.c:259
unsigned char uint8_t
Definition: stdint.h:10
struct dns_name dst
Expected copied name.
Definition: dns_test.c:263

Define a DNS copying test.

Parameters
_nameTest name
_src_dataSource RFC1035-encoded data
_src_offsetStarting offset within source encoded data
_dst_dataExpected copied RFC1035-encoded data
_dst_offsetStarting offset withint copied encoded data
Return values
testDNS copying test

Definition at line 276 of file dns_test.c.

◆ dns_copy_ok

#define dns_copy_ok (   test)    dns_copy_okx ( test, __FILE__, __LINE__ )

Definition at line 328 of file dns_test.c.

◆ dns_copy_fail_ok

#define dns_copy_fail_ok (   test)    dns_copy_fail_okx ( test, __FILE__, __LINE__ )

Definition at line 346 of file dns_test.c.

◆ DNS_LIST

#define DNS_LIST (   _name,
  _list,
  _strings 
)
Value:
static uint8_t _name ## __list[] = _list; \
static const char * _name ## __strings[] = _strings; \
static struct dns_list_test _name = { \
.list = { \
.data = _name ## __list, \
.offset = 0, \
.len = sizeof ( _name ## __list ), \
}, \
.strings = _name ## __strings, \
.count = ( sizeof ( _name ## __strings ) / \
sizeof ( _name ## __strings[0] ) ), \
}
unsigned int count
Number of expected decoded string.
Definition: dns_test.c:355
const char ** strings
Expected decoded search list.
Definition: dns_test.c:353
void * data
Start of data.
Definition: dns.h:21
unsigned char uint8_t
Definition: stdint.h:10
struct dns_name list
Search list.
Definition: dns_test.c:351
A DNS search list test.
Definition: dns_test.c:349

Define a DNS search list test.

Parameters
_nameTest name
_listRFC1035-encoded data
_stringsExpected decoded strings
Return values
testDNS search list test

Definition at line 366 of file dns_test.c.

◆ dns_list_ok

#define dns_list_ok (   test)    dns_list_okx ( test, __FILE__, __LINE__ )

Definition at line 421 of file dns_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dns_encode_okx()

static void dns_encode_okx ( struct dns_encode_test test,
const char *  file,
unsigned int  line 
)
static

Report DNS encoding test result.

Parameters
testDNS encoding test
fileTest code file
lineTest code line

Definition at line 76 of file dns_test.c.

77  {
78  uint8_t data[ test->len ];
79  struct dns_name name;
80  int len;
81 
82  /* Check ability to determine length with no buffer */
83  memset ( &name, 0, sizeof ( name ) );
84  len = dns_encode ( test->string, &name );
85  okx ( len >= 0, file, line );
86  okx ( len == test->len, file, line );
87 
88  /* Check encoded name */
89  name.data = data;
90  name.len = sizeof ( data );
91  len = dns_encode ( test->string, &name );
92  okx ( len >= 0, file, line );
93  if ( len >= 0 ) {
94  okx ( len == test->len, file, line );
95  okx ( memcmp ( data, test->data, test->len ) == 0, file, line );
96  DBGC ( test, "DNS encoded \"%s\" to:\n", test->string );
97  DBGC_HDA ( test, 0, data, len );
98  }
99 }
const char * name
Definition: ath9k_hw.c:1984
#define DBGC(...)
Definition: compiler.h:505
#define okx(success, file, line)
Report test result.
Definition: test.h:44
An RFC1035-encoded DNS name.
Definition: dns.h:19
#define DBGC_HDA(...)
Definition: compiler.h:506
int dns_encode(const char *string, struct dns_name *name)
Encode a DNS name using RFC1035 encoding.
Definition: dns.c:100
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
static int test
Definition: epic100.c:73
void * memset(void *dest, int character, size_t len) __nonnull

References data, DBGC, DBGC_HDA, dns_encode(), len, memcmp(), memset(), name, okx, and test.

◆ dns_encode_fail_okx()

static void dns_encode_fail_okx ( struct dns_encode_test test,
const char *  file,
unsigned int  line 
)
static

Report DNS encoding failure test result.

Parameters
testDNS encoding test
fileTest code file
lineTest code line

Definition at line 109 of file dns_test.c.

110  {
111  struct dns_name name = { .data = NULL, .len = 0 };
112  int len;
113 
114  len = dns_encode ( test->string, &name );
115  okx ( len < 0, file, line );
116 }
const char * name
Definition: ath9k_hw.c:1984
#define okx(success, file, line)
Report test result.
Definition: test.h:44
An RFC1035-encoded DNS name.
Definition: dns.h:19
int dns_encode(const char *string, struct dns_name *name)
Encode a DNS name using RFC1035 encoding.
Definition: dns.c:100
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int test
Definition: epic100.c:73

References dns_encode(), len, name, NULL, okx, and test.

◆ dns_decode_okx()

static void dns_decode_okx ( struct dns_decode_test test,
const char *  file,
unsigned int  line 
)
static

Report DNS decoding test result.

Parameters
testDNS decoding test
fileTest code file
lineTest code line

Definition at line 155 of file dns_test.c.

156  {
157  char string[ strlen ( test->string ) + 1 /* NUL */ ];
158  int len;
159 
160  /* Check ability to determine length with no buffer */
161  len = dns_decode ( &test->name, NULL, 0 );
162  okx ( len >= 0, file, line );
163  okx ( len == ( ( int ) strlen ( test->string ) ), file, line );
164 
165  /* Check decoded string */
166  len = dns_decode ( &test->name, string, sizeof ( string ) );
167  okx ( len >= 0, file, line );
168  if ( len >= 0 ) {
169  okx ( strcmp ( string, test->string ) == 0, file, line );
170  DBGC ( test, "DNS decoded \"%s\" from offset %#zx in:\n",
171  string, test->name.offset );
172  DBGC_HDA ( test, 0, test->name.data, test->name.len );
173  }
174 }
#define DBGC(...)
Definition: compiler.h:505
#define okx(success, file, line)
Report test result.
Definition: test.h:44
#define DBGC_HDA(...)
Definition: compiler.h:506
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint32_t len
Length.
Definition: ena.h:14
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
int dns_decode(struct dns_name *name, char *data, size_t len)
Decode RFC1035-encoded DNS name.
Definition: dns.c:216
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int test
Definition: epic100.c:73

References DBGC, DBGC_HDA, dns_decode(), len, NULL, okx, strcmp(), strlen(), and test.

◆ dns_decode_fail_okx()

static void dns_decode_fail_okx ( struct dns_decode_test test,
const char *  file,
unsigned int  line 
)
static

Report DNS decoding failure test result.

Parameters
testDNS decoding test
fileTest code file
lineTest code line

Definition at line 184 of file dns_test.c.

185  {
186  int len;
187 
188  len = dns_decode ( &test->name, NULL, 0 );
189  okx ( len < 0, file, line );
190 }
#define okx(success, file, line)
Report test result.
Definition: test.h:44
uint32_t len
Length.
Definition: ena.h:14
int dns_decode(struct dns_name *name, char *data, size_t len)
Decode RFC1035-encoded DNS name.
Definition: dns.c:216
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int test
Definition: epic100.c:73

References dns_decode(), len, NULL, okx, and test.

◆ dns_compare_okx()

static void dns_compare_okx ( struct dns_compare_test test,
const char *  file,
unsigned int  line 
)
static

Report DNS comparison test result.

Parameters
testDNS comparison test
fileTest code file
lineTest code line

Definition at line 236 of file dns_test.c.

237  {
238 
239  okx ( dns_compare ( &test->first, &test->second ) == 0, file, line );
240 }
#define okx(success, file, line)
Report test result.
Definition: test.h:44
int dns_compare(struct dns_name *first, struct dns_name *second)
Compare DNS names for equality.
Definition: dns.c:267
static int test
Definition: epic100.c:73

References dns_compare(), okx, and test.

◆ dns_compare_fail_okx()

static void dns_compare_fail_okx ( struct dns_compare_test test,
const char *  file,
unsigned int  line 
)
static

Report DNS comparison test failure result.

Parameters
testDNS comparison test
fileTest code file
lineTest code line

Definition at line 250 of file dns_test.c.

251  {
252 
253  okx ( dns_compare ( &test->first, &test->second ) != 0, file, line );
254 }
#define okx(success, file, line)
Report test result.
Definition: test.h:44
int dns_compare(struct dns_name *first, struct dns_name *second)
Compare DNS names for equality.
Definition: dns.c:267
static int test
Definition: epic100.c:73

References dns_compare(), okx, and test.

◆ dns_copy_okx()

static void dns_copy_okx ( struct dns_copy_test test,
const char *  file,
unsigned int  line 
)
static

Report a DNS copying test result.

Parameters
testDNS copying test
fileTest code file
lineTest code line

Definition at line 300 of file dns_test.c.

301  {
302  uint8_t data[ test->dst.len ];
303  struct dns_name dst;
304  int len;
305 
306  /* Check ability to determine length with no buffer */
307  memset ( &dst, 0, sizeof ( dst ) );
308  len = dns_copy ( &test->src, &dst );
309  okx ( len >= 0, file, line );
310  okx ( len == ( ( int ) ( test->dst.len - test->dst.offset ) ),
311  file, line );
312 
313  /* Check copied name */
314  dst.data = data;
315  dst.offset = test->dst.offset;
316  dst.len = sizeof ( data );
317  memcpy ( dst.data, test->dst.data, test->dst.offset );
318  len = dns_copy ( &test->src, &dst );
319  okx ( len >= 0, file, line );
320  okx ( len == ( ( int ) ( test->dst.len - test->dst.offset ) ),
321  file, line );
322  okx ( memcmp ( data, test->dst.data, sizeof ( data ) ) == 0,
323  file, line );
324  DBGC ( test, "DNS copied:\n" );
325  DBGC_HDA ( test, 0, test->src.data, test->src.len );
326  DBGC_HDA ( test, 0, data, ( test->dst.offset + len ) );
327 }
static void const void void * dst
Definition: crypto.h:244
#define DBGC(...)
Definition: compiler.h:505
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define okx(success, file, line)
Report test result.
Definition: test.h:44
An RFC1035-encoded DNS name.
Definition: dns.h:19
#define DBGC_HDA(...)
Definition: compiler.h:506
int dns_copy(struct dns_name *src, struct dns_name *dst)
Copy a DNS name.
Definition: dns.c:321
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
static int test
Definition: epic100.c:73
void * memset(void *dest, int character, size_t len) __nonnull

References data, DBGC, DBGC_HDA, dns_copy(), dst, len, memcmp(), memcpy(), memset(), okx, and test.

◆ dns_copy_fail_okx()

static void dns_copy_fail_okx ( struct dns_copy_test test,
const char *  file,
unsigned int  line 
)
static

Report a DNS copying failure test result.

Parameters
testDNS copying test
fileTest code file
lineTest code line

Definition at line 337 of file dns_test.c.

338  {
339  struct dns_name dst;
340  int len;
341 
342  memset ( &dst, 0, sizeof ( dst ) );
343  len = dns_copy ( &test->src, &dst );
344  okx ( len < 0, file, line );
345 }
static void const void void * dst
Definition: crypto.h:244
#define okx(success, file, line)
Report test result.
Definition: test.h:44
An RFC1035-encoded DNS name.
Definition: dns.h:19
int dns_copy(struct dns_name *src, struct dns_name *dst)
Copy a DNS name.
Definition: dns.c:321
uint32_t len
Length.
Definition: ena.h:14
static int test
Definition: epic100.c:73
void * memset(void *dest, int character, size_t len) __nonnull

References dns_copy(), dst, len, memset(), okx, and test.

◆ dns_list_okx()

static void dns_list_okx ( struct dns_list_test test,
const char *  file,
unsigned int  line 
)
static

Report DNS search list test result.

Parameters
testDNS search list test
fileTest code file
lineTest code line

Definition at line 387 of file dns_test.c.

388  {
389  struct dns_name name;
390  unsigned int i;
391 
392  DBGC ( test, "DNS search list:\n" );
393  DBGC_HDA ( test, 0, test->list.data, test->list.len );
394  memcpy ( &name, &test->list, sizeof ( name ) );
395  for ( i = 0 ; i < test->count ; i++ ) {
396  char buf[ strlen ( test->strings[i] ) + 1 /* NUL */ ];
397  int len;
398  int offset;
399 
400  /* Decode this name */
401  len = dns_decode ( &name, buf, sizeof ( buf ) );
402  okx ( len >= 0, file, line );
403  if ( len >= 0 ) {
404  okx ( len == ( ( int ) strlen ( test->strings[i] ) ),
405  file, line );
406  okx ( strcmp ( buf, test->strings[i] ) == 0,
407  file, line );
408  DBGC ( test, "DNS search list found \"%s\" at offset "
409  "%#zx\n", buf, name.offset );
410  }
411 
412  /* Skip to next name */
413  offset = dns_skip ( &name );
414  okx ( offset >= 0, file, line );
415  name.offset = offset;
416  }
417 
418  /* Check that we have consumed the whole search list */
419  okx ( name.offset == name.len, file, line );
420 }
const char * name
Definition: ath9k_hw.c:1984
int dns_skip(struct dns_name *name)
Skip RFC1035-encoded DNS name.
Definition: dns.c:364
#define DBGC(...)
Definition: compiler.h:505
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define okx(success, file, line)
Report test result.
Definition: test.h:44
An RFC1035-encoded DNS name.
Definition: dns.h:19
#define DBGC_HDA(...)
Definition: compiler.h:506
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint32_t len
Length.
Definition: ena.h:14
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
int dns_decode(struct dns_name *name, char *data, size_t len)
Decode RFC1035-encoded DNS name.
Definition: dns.c:216
static int test
Definition: epic100.c:73

References DBGC, DBGC_HDA, dns_decode(), dns_skip(), len, memcpy(), name, offset, okx, strcmp(), strlen(), and test.

◆ DNS_ENCODE() [1/10]

DNS_ENCODE ( encode_simple  ,
"ipxe.org"  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)   
)

◆ DNS_ENCODE() [2/10]

DNS_ENCODE ( encode_single  ,
"foo"  ,
DATA(3, 'f', 'o', 'o', 0)   
)

◆ DNS_ENCODE() [3/10]

DNS_ENCODE ( encode_absolute  ,
"git.ipxe.org."  ,
DATA(3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)   
)

◆ DNS_ENCODE() [4/10]

DNS_ENCODE ( encode_empty  ,
""  ,
DATA(0)   
)

◆ DNS_ENCODE() [5/10]

DNS_ENCODE ( encode_root  ,
"."  ,
DATA(0)   
)

◆ DNS_ENCODE() [6/10]

DNS_ENCODE ( encode_initial_dot  ,
".foo"  ,
DATA()   
)

◆ DNS_ENCODE() [7/10]

DNS_ENCODE ( encode_double_dot  ,
"ipxe..org"  ,
DATA()   
)

◆ DNS_ENCODE() [8/10]

DNS_ENCODE ( encode_solo_double_dot  ,
".."  ,
DATA()   
)

◆ DNS_ENCODE() [9/10]

DNS_ENCODE ( encode_trailing_double_dot  ,
"ipxe.org.."  ,
DATA()   
)

◆ DNS_ENCODE() [10/10]

DNS_ENCODE ( encode_overlength  ,
"this-label-is-maliciously-long-in-an-attempt-to-overflow-the-" "length-field-and-generate-a-length-which-looks-like-a-" "compression-pointer"  ,
DATA()   
)

◆ DNS_DECODE() [1/9]

DNS_DECODE ( decode_simple  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
,
"ipxe.org"   
)

◆ DNS_DECODE() [2/9]

DNS_DECODE ( decode_ptr  ,
DATA(3, 'o', 'r', 'g', 0, 3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 0xc0, 0x00)  ,
,
"git.ipxe.org"   
)

◆ DNS_DECODE() [3/9]

DNS_DECODE ( decode_root  ,
DATA(0)  ,
,
""   
)

◆ DNS_DECODE() [4/9]

DNS_DECODE ( decode_incomplete_name  ,
DATA(4, 'i', 'p', 'x', 'e')  ,
,
NULL   
)

◆ DNS_DECODE() [5/9]

DNS_DECODE ( decode_incomplete_label  ,
DATA(4, 'i', 'p', 'x')  ,
,
NULL   
)

◆ DNS_DECODE() [6/9]

DNS_DECODE ( decode_incomplete_ptr  ,
DATA(3, 'o', 'r', 'g', 0, 4, 'i', 'p', 'x', 'e', 0xc0)  ,
,
NULL   
)

◆ DNS_DECODE() [7/9]

DNS_DECODE ( decode_forward  ,
DATA(0xc0, 0x02, 3, 'f', 'o', 'o', 0)  ,
,
NULL   
)

◆ DNS_DECODE() [8/9]

DNS_DECODE ( decode_infinite  ,
DATA(4, 'i', 'p', 'x', 'e', 0xc0, 0x00)  ,
,
NULL   
)

◆ DNS_DECODE() [9/9]

DNS_DECODE ( decode_empty  ,
DATA()  ,
,
NULL   
)

◆ DNS_COMPARE() [1/5]

DNS_COMPARE ( compare_simple  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
 
)

◆ DNS_COMPARE() [2/5]

DNS_COMPARE ( compare_ptr  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
,
DATA(3, 'o', 'r', 'g', 0, 4, 'i', 'p', 'x', 'e', 0xc0, 0x00)  ,
 
)

◆ DNS_COMPARE() [3/5]

DNS_COMPARE ( compare_case  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
,
DATA(4, 'i', 'p', 'x', 'e', 3, 'O', 'R', 'G', 0)  ,
 
)

◆ DNS_COMPARE() [4/5]

DNS_COMPARE ( compare_mismatch  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
,
DATA(4, 'g', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
 
)

◆ DNS_COMPARE() [5/5]

DNS_COMPARE ( compare_infinite  ,
DATA(3, 'f', 'o', 'o', 0xc0, 0x00)  ,
,
DATA(3, 'f', 'o', 'o', 0xc0, 0x00)  ,
 
)

◆ DNS_COPY() [1/4]

DNS_COPY ( copy_simple  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
 
)

◆ DNS_COPY() [2/4]

DNS_COPY ( copy_offset  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
,
DATA('f', 'o', 'o', 0, 4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
 
)

◆ DNS_COPY() [3/4]

DNS_COPY ( copy_ptr  ,
DATA(3, 'o', 'r', 'g', 0, 3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 0xc0, 0x00)  ,
,
DATA(3, 'g', 'i', 't', 4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0)  ,
 
)

◆ DNS_COPY() [4/4]

DNS_COPY ( copy_infinite  ,
DATA(4, 'l', 'o', 'o', 'p', 7, 'f', 'o', 'r', 'e', 'v', 'e', 'r', 0xc0, 0x05)  ,
,
DATA()  ,
 
)

◆ DNS_LIST()

DNS_LIST ( search  ,
DATA(4, 'i', 'p', 'x', 'e', 3, 'o', 'r', 'g', 0, 4, 'b', 'o', 'o', 't', 0xc0, 0x00, 3, 'd', 'e', 'v', 0xc0, 0x0a, 11, 'n', 'e', 't', 'w', 'o', 'r', 'k', 'b', 'o', 'o', 't', 0xc0, 0x05)  ,
DATA("ipxe.org", "boot.ipxe.org", "dev.boot.ipxe.org", "networkboot.org")   
)

◆ dns_test_exec()

static void dns_test_exec ( void  )
static

Perform DNS self-test.

Definition at line 563 of file dns_test.c.

563  {
564 
565  /* Encoding tests */
566  dns_encode_ok ( &encode_simple );
567  dns_encode_ok ( &encode_single );
568  dns_encode_ok ( &encode_absolute );
569  dns_encode_ok ( &encode_empty );
570  dns_encode_ok ( &encode_root );
571  dns_encode_fail_ok ( &encode_initial_dot );
572  dns_encode_fail_ok ( &encode_double_dot );
573  dns_encode_fail_ok ( &encode_solo_double_dot );
574  dns_encode_fail_ok ( &encode_trailing_double_dot );
575  dns_encode_fail_ok ( &encode_overlength );
576 
577  /* Decoding tests */
578  dns_decode_ok ( &decode_simple );
579  dns_decode_ok ( &decode_ptr );
580  dns_decode_ok ( &decode_root );
581  dns_decode_fail_ok ( &decode_incomplete_name );
582  dns_decode_fail_ok ( &decode_incomplete_label );
583  dns_decode_fail_ok ( &decode_incomplete_ptr );
584  dns_decode_fail_ok ( &decode_forward );
585  dns_decode_fail_ok ( &decode_infinite );
586  dns_decode_fail_ok ( &decode_empty );
587 
588  /* Comparison tests */
589  dns_compare_ok ( &compare_simple );
590  dns_compare_ok ( &compare_ptr );
591  dns_compare_ok ( &compare_case );
592  dns_compare_fail_ok ( &compare_mismatch );
593  dns_compare_fail_ok ( &compare_infinite );
594 
595  /* Copying tests */
596  dns_copy_ok ( &copy_simple );
597  dns_copy_ok ( &copy_offset );
598  dns_copy_ok ( &copy_ptr );
599  dns_copy_fail_ok ( &copy_infinite );
600 
601  /* Search list tets */
602  dns_list_ok ( &search );
603 }
#define dns_list_ok(test)
Definition: dns_test.c:421
#define dns_copy_ok(test)
Definition: dns_test.c:328
#define dns_encode_ok(test)
Definition: dns_test.c:100
#define dns_compare_fail_ok(test)
Definition: dns_test.c:255
#define dns_decode_ok(test)
Definition: dns_test.c:175
#define dns_compare_ok(test)
Definition: dns_test.c:241
#define dns_decode_fail_ok(test)
Definition: dns_test.c:191
#define dns_encode_fail_ok(test)
Definition: dns_test.c:117
#define dns_copy_fail_ok(test)
Definition: dns_test.c:346

References dns_compare_fail_ok, dns_compare_ok, dns_copy_fail_ok, dns_copy_ok, dns_decode_fail_ok, dns_decode_ok, dns_encode_fail_ok, dns_encode_ok, and dns_list_ok.

Variable Documentation

◆ __self_test

struct self_test dns_test __self_test
Initial value:
= {
.name = "dns",
.exec = dns_test_exec,
}
static void dns_test_exec(void)
Perform DNS self-test.
Definition: dns_test.c:563

DNS self-test.

Definition at line 606 of file dns_test.c.