41 #define DATA(...) { __VA_ARGS__ } 61 #define DNS_ENCODE( _name, _string, _data ) \ 62 static const uint8_t _name ## __data[] = _data; \ 63 static struct dns_encode_test _name = { \ 65 .data = _name ## __data, \ 66 .len = sizeof ( _name ## __data ), \ 85 okx (
len >= 0, file, line );
92 okx (
len >= 0, file, line );
100 #define dns_encode_ok( test ) dns_encode_okx ( test, __FILE__, __LINE__ ) 110 const char *file,
unsigned int line ) {
115 okx (
len < 0, file, line );
117 #define dns_encode_fail_ok( test ) \ 118 dns_encode_fail_okx ( test, __FILE__, __LINE__ ) 137 #define DNS_DECODE( _name, _data, _offset, _string ) \ 138 static uint8_t _name ## __data[] = _data; \ 139 static struct dns_decode_test _name = { \ 141 .data = _name ## __data, \ 143 .len = sizeof ( _name ## __data ), \ 156 unsigned int line ) {
162 okx (
len >= 0, file, line );
167 okx (
len >= 0, file, line );
170 DBGC (
test,
"DNS decoded \"%s\" from offset %#zx in:\n",
171 string,
test->name.offset );
175 #define dns_decode_ok( test ) dns_decode_okx ( test, __FILE__, __LINE__ ) 185 const char *file,
unsigned int line ) {
189 okx (
len < 0, file, line );
191 #define dns_decode_fail_ok( test ) \ 192 dns_decode_fail_okx ( test, __FILE__, __LINE__ ) 212 #define DNS_COMPARE( _name, _first_data, _first_offset, _second_data, \ 214 static uint8_t _name ## __first_data[] = _first_data; \ 215 static uint8_t _name ## __second_data[] = _second_data; \ 216 static struct dns_compare_test _name = { \ 218 .data = _name ## __first_data, \ 219 .offset = _first_offset, \ 220 .len = sizeof ( _name ## __first_data ), \ 223 .data = _name ## __second_data, \ 224 .offset = _second_offset, \ 225 .len = sizeof ( _name ## __second_data ), \ 237 unsigned int line ) {
241 #define dns_compare_ok( test ) dns_compare_okx ( test, __FILE__, __LINE__ ) 251 const char *file,
unsigned int line ) {
255 #define dns_compare_fail_ok( test ) \ 256 dns_compare_fail_okx ( test, __FILE__, __LINE__ ) 276 #define DNS_COPY( _name, _src_data, _src_offset, _dst_data, \ 278 static uint8_t _name ## __src_data[] = _src_data; \ 279 static uint8_t _name ## __dst_data[] = _dst_data; \ 280 static struct dns_copy_test _name = { \ 282 .data = _name ## __src_data, \ 283 .offset = _src_offset, \ 284 .len = sizeof ( _name ## __src_data ), \ 287 .data = _name ## __dst_data, \ 288 .offset = _dst_offset, \ 289 .len = sizeof ( _name ## __dst_data ), \ 301 const char *file,
unsigned int line ) {
307 memset ( &dst, 0,
sizeof ( dst ) );
309 okx (
len >= 0, file, line );
319 okx (
len >= 0, file, line );
328 #define dns_copy_ok( test ) dns_copy_okx ( test, __FILE__, __LINE__ ) 338 const char *file,
unsigned int line ) {
342 memset ( &dst, 0,
sizeof ( dst ) );
344 okx (
len < 0, file, line );
346 #define dns_copy_fail_ok( test ) dns_copy_fail_okx ( test, __FILE__, __LINE__ ) 366 #define DNS_LIST( _name, _list, _strings ) \ 367 static uint8_t _name ## __list[] = _list; \ 368 static const char * _name ## __strings[] = _strings; \ 369 static struct dns_list_test _name = { \ 371 .data = _name ## __list, \ 373 .len = sizeof ( _name ## __list ), \ 375 .strings = _name ## __strings, \ 376 .count = ( sizeof ( _name ## __strings ) / \ 377 sizeof ( _name ## __strings[0] ) ), \ 388 unsigned int line ) {
392 DBGC (
test,
"DNS search list:\n" );
395 for ( i = 0 ; i <
test->count ; i++ ) {
402 okx (
len >= 0, file, line );
408 DBGC (
test,
"DNS search list found \"%s\" at offset " 409 "%#zx\n", buf,
name.offset );
421 #define dns_list_ok( test ) dns_list_okx ( test, __FILE__, __LINE__ ) 425 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ) );
428 DNS_ENCODE ( encode_single,
"foo",
DATA ( 3,
'f',
'o',
'o', 0 ) );
431 DNS_ENCODE ( encode_absolute,
"git.ipxe.org.",
432 DATA ( 3,
'g',
'i',
't', 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g',
455 "this-label-is-maliciously-long-in-an-attempt-to-overflow-the-" 456 "length-field-and-generate-a-length-which-looks-like-a-" 457 "compression-pointer",
DATA() );
461 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0,
466 DATA ( 3,
'o',
'r',
'g', 0, 3,
'g',
'i',
't', 4,
'i',
'p',
'x',
467 'e', 0xc0, 0x00 ), 5,
476 DATA ( 4,
'i',
'p',
'x',
'e' ), 0,
NULL );
480 DATA ( 4,
'i',
'p',
'x' ), 0,
NULL );
484 DATA ( 3,
'o',
'r',
'g', 0, 4,
'i',
'p',
'x',
'e', 0xc0 ), 5,
489 DATA ( 0xc0, 0x02, 3,
'f',
'o',
'o', 0 ), 0,
NULL );
493 DATA ( 4,
'i',
'p',
'x',
'e', 0xc0, 0x00 ), 0,
NULL );
501 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0,
502 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0 );
506 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0,
507 DATA ( 3,
'o',
'r',
'g', 0, 4,
'i',
'p',
'x',
'e',
512 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0,
513 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'O',
'R',
'G', 0 ), 0 );
517 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0,
518 DATA ( 4,
'g',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0 );
522 DATA ( 3,
'f',
'o',
'o', 0xc0, 0x00 ), 0,
523 DATA ( 3,
'f',
'o',
'o', 0xc0, 0x00 ), 0 );
527 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0,
528 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0 );
532 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0 ), 0,
533 DATA (
'f',
'o',
'o', 0, 4,
'i',
'p',
'x',
'e',
534 3,
'o',
'r',
'g', 0 ), 4 );
538 DATA ( 3,
'o',
'r',
'g', 0, 3,
'g',
'i',
't', 4,
'i',
'p',
'x',
'e',
540 DATA ( 3,
'g',
'i',
't', 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g',
545 DATA ( 4,
'l',
'o',
'o',
'p', 7,
'f',
'o',
'r',
'e',
'v',
'e',
'r',
551 DATA ( 4,
'i',
'p',
'x',
'e', 3,
'o',
'r',
'g', 0,
552 4,
'b',
'o',
'o',
't', 0xc0, 0x00,
553 3,
'd',
'e',
'v', 0xc0, 0x0a,
554 11,
'n',
'e',
't',
'w',
'o',
'r',
'k',
'b',
'o',
'o',
't',
556 DATA (
"ipxe.org",
"boot.ipxe.org",
"dev.boot.ipxe.org",
557 "networkboot.org" ) );
unsigned int count
Number of expected decoded string.
const char * string
String.
int dns_skip(struct dns_name *name)
Skip RFC1035-encoded DNS name.
static void dns_list_okx(struct dns_list_test *test, const char *file, unsigned int line)
Report DNS search list test result.
const char ** strings
Expected decoded search list.
#define dns_list_ok(test)
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
const char * string
Expected string.
Self-test infrastructure.
const char * name
Test set name.
static void dns_encode_okx(struct dns_encode_test *test, const char *file, unsigned int line)
Report DNS encoding test result.
void * data
Start of data.
struct dns_name name
Name.
#define dns_copy_ok(test)
static void dns_decode_fail_okx(struct dns_decode_test *test, const char *file, unsigned int line)
Report DNS decoding failure test result.
static void dns_compare_fail_okx(struct dns_compare_test *test, const char *file, unsigned int line)
Report DNS comparison test failure result.
struct dns_name src
Source name.
#define DNS_LIST(_name, _list, _strings)
Define a DNS search list test.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void dns_compare_okx(struct dns_compare_test *test, const char *file, unsigned int line)
Report DNS comparison test result.
#define okx(success, file, line)
Report test result.
An RFC1035-encoded DNS name.
static void dns_copy_fail_okx(struct dns_copy_test *test, const char *file, unsigned int line)
Report a DNS copying failure test result.
#define DATA(...)
Define inline data.
size_t offset
Offset of name within data.
#define DNS_COMPARE(_name, _first_data, _first_offset, _second_data, _second_offset)
Define a DNS comparison test.
#define DNS_COPY(_name, _src_data, _src_offset, _dst_data, _dst_offset)
Define a DNS copying test.
struct dns_name first
First name.
const void * data
Encoded string.
int dns_copy(struct dns_name *src, struct dns_name *dst)
Copy a DNS name.
#define dns_encode_ok(test)
size_t strlen(const char *src)
Get length of string.
int dns_encode(const char *string, struct dns_name *name)
Encode a DNS name using RFC1035 encoding.
static void dns_copy_okx(struct dns_copy_test *test, const char *file, unsigned int line)
Report a DNS copying test result.
struct dns_name dst
Expected copied name.
struct dns_name second
Second name.
#define DNS_DECODE(_name, _data, _offset, _string)
Define a DNS decoding test.
struct self_test dns_test __self_test
DNS self-test.
#define dns_compare_fail_ok(test)
static void dns_decode_okx(struct dns_decode_test *test, const char *file, unsigned int line)
Report DNS decoding test result.
int strcmp(const char *first, const char *second)
Compare strings.
struct dns_name list
Search list.
int len
Length of encoded string.
static void dns_encode_fail_okx(struct dns_encode_test *test, const char *file, unsigned int line)
Report DNS encoding failure test result.
uint8_t data[48]
Additional event data.
static void dns_test_exec(void)
Perform DNS self-test.
int dns_compare(struct dns_name *first, struct dns_name *second)
Compare DNS names for equality.
#define dns_decode_ok(test)
int dns_decode(struct dns_name *name, char *data, size_t len)
Decode RFC1035-encoded DNS name.
#define dns_compare_ok(test)
uint16_t offset
Offset to command line.
#define dns_decode_fail_ok(test)
#define dns_encode_fail_ok(test)
size_t len
Total length of data.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
#define NULL
NULL pointer (VOID *)
#define DNS_ENCODE(_name, _string, _data)
Define a DNS encoding test.
void * memset(void *dest, int character, size_t len) __nonnull
#define dns_copy_fail_ok(test)