Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
/*
 * Copyright (c) 2017 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/types.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <misc/printk.h>

#include <ztest.h>

#include <net/ethernet.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
#include <net/dns_resolve.h>

#define NET_LOG_ENABLED 1
#include "net_private.h"

#if defined(CONFIG_NET_DEBUG_DNS_RESOLVE)
#define DBG(fmt, ...) printk(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

#define NAME4 "4.zephyr.test"
#define NAME6 "6.zephyr.test"
#define NAME_IPV4 "192.0.2.1"
#define NAME_IPV6 "2001:db8::1"

#define DNS_TIMEOUT 500 /* ms */

#if defined(CONFIG_NET_IPV6)
/* Interface 1 addresses */
static struct in6_addr my_addr1 = { { { 0x20, 0x01, 0x0d, 0xb8, 1, 0, 0, 0,
					0, 0, 0, 0, 0, 0, 0, 0x1 } } };
static struct in6_addr my_addr3 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
					0, 0, 0, 0, 0, 0, 0, 0x1 } } };

/* Extra address is assigned to ll_addr */
static struct in6_addr ll_addr = { { { 0xfe, 0x80, 0x43, 0xb8, 0, 0, 0, 0,
				       0, 0, 0, 0xf2, 0xaa, 0x29, 0x02,
				       0x04 } } };
#endif

#if defined(CONFIG_NET_IPV4)
/* Interface 1 addresses */
static struct in_addr my_addr2 = { { { 192, 0, 2, 1 } } };
#endif

static struct net_if *iface1;

static bool test_failed;
static bool test_started;
static bool timeout_query;
static struct k_sem wait_data;
static struct k_sem wait_data2;
static u16_t current_dns_id;
static struct dns_addrinfo addrinfo;

/* this must be higher that the DNS_TIMEOUT */
#define WAIT_TIME (DNS_TIMEOUT + 300)

struct net_if_test {
	u8_t idx;
	u8_t mac_addr[sizeof(struct net_eth_addr)];
	struct net_linkaddr ll_addr;
};

static int net_iface_dev_init(struct device *dev)
{
	return 0;
}

static u8_t *net_iface_get_mac(struct device *dev)
{
	struct net_if_test *data = dev->driver_data;

	if (data->mac_addr[2] == 0x00) {
		/* 00-00-5E-00-53-xx Documentation RFC 7042 */
		data->mac_addr[0] = 0x00;
		data->mac_addr[1] = 0x00;
		data->mac_addr[2] = 0x5E;
		data->mac_addr[3] = 0x00;
		data->mac_addr[4] = 0x53;
		data->mac_addr[5] = sys_rand32_get();
	}

	data->ll_addr.addr = data->mac_addr;
	data->ll_addr.len = 6;

	return data->mac_addr;
}

static void net_iface_init(struct net_if *iface)
{
	u8_t *mac = net_iface_get_mac(net_if_get_device(iface));

	net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr),
			     NET_LINK_ETHERNET);
}

static inline int get_slot_by_id(struct dns_resolve_context *ctx,
				 u16_t dns_id)
{
	int i;

	for (i = 0; i < CONFIG_DNS_NUM_CONCUR_QUERIES; i++) {
		if (ctx->queries[i].cb && ctx->queries[i].id == dns_id) {
			return i;
		}
	}

	return -1;
}

static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
{
	if (!pkt->frags) {
		DBG("No data to send!\n");
		return -ENODATA;
	}

	if (!timeout_query) {
		struct net_if_test *data = iface->dev->driver_data;
		struct dns_resolve_context *ctx;
		int slot;

		DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
		    iface);

		if (net_pkt_iface(pkt) != iface) {
			DBG("Invalid interface %p, expecting %p\n",
				 net_pkt_iface(pkt), iface);
			test_failed = true;
		}

		if (net_if_get_by_iface(iface) != data->idx) {
			DBG("Invalid interface %d index, expecting %d\n",
				 data->idx, net_if_get_by_iface(iface));
			test_failed = true;
		}

		ctx = dns_resolve_get_default();

		slot = get_slot_by_id(ctx, current_dns_id);
		if (slot < 0) {
			DBG("Skipping this query dns id %u\n", current_dns_id);
			goto out;
		}

		/* We need to cancel the query manually so that we
		 * will not get a timeout.
		 */
		k_delayed_work_cancel(&ctx->queries[slot].timer);

		DBG("Calling cb %p with user data %p\n",
		    ctx->queries[slot].cb,
		    ctx->queries[slot].user_data);

		ctx->queries[slot].cb(DNS_EAI_INPROGRESS,
				      &addrinfo,
				      ctx->queries[slot].user_data);
		ctx->queries[slot].cb(DNS_EAI_ALLDONE,
				      NULL,
				      ctx->queries[slot].user_data);

		ctx->queries[slot].cb = NULL;
	}

out:
	net_pkt_unref(pkt);

	return 0;
}

struct net_if_test net_iface1_data;

static struct net_if_api net_iface_api = {
	.init = net_iface_init,
	.send = sender_iface,
};

#define _ETH_L2_LAYER DUMMY_L2
#define _ETH_L2_CTX_TYPE NET_L2_GET_CTX_TYPE(DUMMY_L2)

NET_DEVICE_INIT_INSTANCE(net_iface1_test,
			 "iface1",
			 iface1,
			 net_iface_dev_init,
			 &net_iface1_data,
			 NULL,
			 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
			 &net_iface_api,
			 _ETH_L2_LAYER,
			 _ETH_L2_CTX_TYPE,
			 127);

static void test_init(void)
{
	struct net_if_addr *ifaddr;

	/* The semaphore is there to wait the data to be received. */
	k_sem_init(&wait_data, 0, UINT_MAX);
	k_sem_init(&wait_data2, 0, UINT_MAX);

	iface1 = net_if_get_by_index(0);

	((struct net_if_test *)iface1->dev->driver_data)->idx = 0;

#if defined(CONFIG_NET_IPV6)
	ifaddr = net_if_ipv6_addr_add(iface1, &my_addr1,
				      NET_ADDR_MANUAL, 0);
	if (!ifaddr) {
		DBG("Cannot add IPv6 address %s\n",
		       net_sprint_ipv6_addr(&my_addr1));
		zassert_not_null(ifaddr, "addr1");

		return;
	}

	/* For testing purposes we need to set the adddresses preferred */
	ifaddr->addr_state = NET_ADDR_PREFERRED;

	ifaddr = net_if_ipv6_addr_add(iface1, &ll_addr,
				      NET_ADDR_MANUAL, 0);
	if (!ifaddr) {
		DBG("Cannot add IPv6 address %s\n",
		       net_sprint_ipv6_addr(&ll_addr));
		zassert_not_null(ifaddr, "ll_addr");

		return;
	}

	ifaddr->addr_state = NET_ADDR_PREFERRED;
#endif

#if defined(CONFIG_NET_IPV4)
	ifaddr = net_if_ipv4_addr_add(iface1, &my_addr2,
				      NET_ADDR_MANUAL, 0);
	if (!ifaddr) {
		DBG("Cannot add IPv4 address %s\n",
		       net_sprint_ipv4_addr(&my_addr2));
		zassert_not_null(ifaddr, "addr2");

		return;
	}

	ifaddr->addr_state = NET_ADDR_PREFERRED;
#endif

	net_if_up(iface1);

	/* The interface might receive data which might fail the checks
	 * in the iface sending function, so we need to reset the failure
	 * flag.
	 */
	test_failed = false;

	test_started = true;
}

void dns_result_cb_dummy(enum dns_resolve_status status,
			 struct dns_addrinfo *info,
			 void *user_data)
{
	return;
}

static void dns_query_invalid_timeout(void)
{
	int ret;

	ret = dns_get_addr_info(NAME6,
				DNS_QUERY_TYPE_AAAA,
				NULL,
				dns_result_cb_dummy,
				NULL,
				K_NO_WAIT);
	zassert_equal(ret, -EINVAL, "Wrong return code for timeout");
}

static void dns_query_invalid_context(void)
{
	int ret;

	ret = dns_resolve_name(NULL,
			       NAME6,
			       DNS_QUERY_TYPE_AAAA,
			       NULL,
			       dns_result_cb_dummy,
			       NULL,
			       DNS_TIMEOUT);
	zassert_equal(ret, -EINVAL, "Wrong return code for context");
}

static void dns_query_invalid_callback(void)
{
	int ret;

	ret = dns_get_addr_info(NAME6,
				DNS_QUERY_TYPE_AAAA,
				NULL,
				NULL,
				NULL,
				DNS_TIMEOUT);
	zassert_equal(ret, -EINVAL, "Wrong return code for callback");
}

static void dns_query_invalid_query(void)
{
	int ret;

	ret = dns_get_addr_info(NULL,
				DNS_QUERY_TYPE_AAAA,
				NULL,
				dns_result_cb_dummy,
				NULL,
				DNS_TIMEOUT);
	zassert_equal(ret, -EINVAL, "Wrong return code for query");
}

void dns_result_cb_timeout(enum dns_resolve_status status,
			   struct dns_addrinfo *info,
			   void *user_data)
{
	int expected_status = POINTER_TO_INT(user_data);

	if (expected_status != status) {
		DBG("Result status %d\n", status);
		DBG("Expected status %d\n", expected_status);

		zassert_equal(expected_status, status, "Invalid status");
	}

	k_sem_give(&wait_data);
}

static void dns_query_server_count(void)
{
	struct dns_resolve_context *ctx = dns_resolve_get_default();
	int i, count = 0;

	for (i = 0; i < CONFIG_DNS_RESOLVER_MAX_SERVERS; i++) {
		if (!ctx->is_used) {
			continue;
		}

		if (!ctx->servers[i].net_ctx) {
			continue;
		}

		count++;
	}

	zassert_equal(count, CONFIG_DNS_RESOLVER_MAX_SERVERS,
		     "Invalid number of servers");
}

static void dns_query_ipv4_server_count(void)
{
	struct dns_resolve_context *ctx = dns_resolve_get_default();
	int i, count = 0, port = 0;

	for (i = 0; i < CONFIG_DNS_RESOLVER_MAX_SERVERS; i++) {
		if (!ctx->is_used) {
			continue;
		}

		if (!ctx->servers[i].net_ctx) {
			continue;
		}

		if (ctx->servers[i].dns_server.sa_family == AF_INET6) {
			continue;
		}

		count++;

		if (net_sin(&ctx->servers[i].dns_server)->sin_port ==
		    ntohs(53)) {
			port++;
		}
	}

	zassert_equal(count, 2, "Invalid number of IPv4 servers");
	zassert_equal(port, 1, "Invalid number of IPv4 servers with port 53");
}

static void dns_query_ipv6_server_count(void)
{
	struct dns_resolve_context *ctx = dns_resolve_get_default();
	int i, count = 0, port = 0;

	for (i = 0; i < CONFIG_DNS_RESOLVER_MAX_SERVERS; i++) {
		if (!ctx->is_used) {
			continue;
		}

		if (!ctx->servers[i].net_ctx) {
			continue;
		}

		if (ctx->servers[i].dns_server.sa_family == AF_INET) {
			continue;
		}

		count++;

		if (net_sin6(&ctx->servers[i].dns_server)->sin6_port ==
		    ntohs(53)) {
			port++;
		}
	}

#if defined(CONFIG_NET_IPV6)
	zassert_equal(count, 2, "Invalid number of IPv6 servers");
	zassert_equal(port, 1, "Invalid number of IPv6 servers with port 53");
#else
	zassert_equal(count, 0, "Invalid number of IPv6 servers");
	zassert_equal(port, 0, "Invalid number of IPv6 servers with port 53");
#endif
}

static void dns_query_too_many(void)
{
	int expected_status = DNS_EAI_CANCELED;
	int ret;

	timeout_query = true;

	ret = dns_get_addr_info(NAME4,
				DNS_QUERY_TYPE_A,
				NULL,
				dns_result_cb_timeout,
				INT_TO_POINTER(expected_status),
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv4 query");

	ret = dns_get_addr_info(NAME4,
				DNS_QUERY_TYPE_A,
				NULL,
				dns_result_cb_dummy,
				INT_TO_POINTER(expected_status),
				DNS_TIMEOUT);
	zassert_equal(ret, -EAGAIN, "Should have run out of space");

	if (k_sem_take(&wait_data, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}

	timeout_query = false;
}

static void dns_query_ipv4_timeout(void)
{
	int expected_status = DNS_EAI_CANCELED;
	int ret;

	timeout_query = true;

	ret = dns_get_addr_info(NAME4,
				DNS_QUERY_TYPE_A,
				NULL,
				dns_result_cb_timeout,
				INT_TO_POINTER(expected_status),
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv4 query");

	if (k_sem_take(&wait_data, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}

	timeout_query = false;
}

static void dns_query_ipv6_timeout(void)
{
	int expected_status = DNS_EAI_CANCELED;
	int ret;

	timeout_query = true;

	ret = dns_get_addr_info(NAME6,
				DNS_QUERY_TYPE_AAAA,
				NULL,
				dns_result_cb_timeout,
				INT_TO_POINTER(expected_status),
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv6 query");

	if (k_sem_take(&wait_data, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}

	timeout_query = false;
}

static void verify_cancelled(void)
{
	struct dns_resolve_context *ctx = dns_resolve_get_default();
	int i, count = 0, timer_not_stopped = 0;

	for (i = 0; i < CONFIG_DNS_NUM_CONCUR_QUERIES; i++) {
		if (ctx->queries[i].cb) {
			count++;
		}

		if (k_delayed_work_remaining_get(&ctx->queries[i].timer) > 0) {
			timer_not_stopped++;
		}
	}

	zassert_equal(count, 0, "Not all pending queries vere cancelled");
	zassert_equal(timer_not_stopped, 0, "Not all timers vere cancelled");
}

static void dns_query_ipv4_cancel(void)
{
	int expected_status = DNS_EAI_CANCELED;
	u16_t dns_id;
	int ret;

	timeout_query = true;

	ret = dns_get_addr_info(NAME4,
				DNS_QUERY_TYPE_A,
				&dns_id,
				dns_result_cb_timeout,
				INT_TO_POINTER(expected_status),
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv4 query");

	ret = dns_cancel_addr_info(dns_id);
	zassert_equal(ret, 0, "Cannot cancel IPv4 query");

	if (k_sem_take(&wait_data, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}

	verify_cancelled();
}

static void dns_query_ipv6_cancel(void)
{
	int expected_status = DNS_EAI_CANCELED;
	u16_t dns_id;
	int ret;

	timeout_query = true;

	ret = dns_get_addr_info(NAME6,
				DNS_QUERY_TYPE_AAAA,
				&dns_id,
				dns_result_cb_timeout,
				INT_TO_POINTER(expected_status),
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv6 query");

	ret = dns_cancel_addr_info(dns_id);
	zassert_equal(ret, 0, "Cannot cancel IPv6 query");

	if (k_sem_take(&wait_data, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}

	verify_cancelled();
}

struct expected_status {
	int status1;
	int status2;
	const char *caller;
};

void dns_result_cb(enum dns_resolve_status status,
		   struct dns_addrinfo *info,
		   void *user_data)
{
	struct expected_status *expected = user_data;

	if (status != expected->status1 && status != expected->status2) {
		DBG("Result status %d\n", status);
		DBG("Expected status1 %d\n", expected->status1);
		DBG("Expected status2 %d\n", expected->status2);
		DBG("Caller %s\n", expected->caller);

		zassert_true(false, "Invalid status");
	}

	k_sem_give(&wait_data2);
}

static void dns_query_ipv4(void)
{
	struct expected_status status = {
		.status1 = DNS_EAI_INPROGRESS,
		.status2 = DNS_EAI_ALLDONE,
		.caller = __func__,
	};
	int ret;

	timeout_query = false;

	ret = dns_get_addr_info(NAME4,
				DNS_QUERY_TYPE_A,
				&current_dns_id,
				dns_result_cb,
				&status,
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv4 query");

	DBG("Query id %u\n", current_dns_id);

	k_yield(); /* mandatory so that net_if send func gets to run */

	if (k_sem_take(&wait_data2, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}
}

static void dns_query_ipv6(void)
{
	struct expected_status status = {
		.status1 = DNS_EAI_INPROGRESS,
		.status2 = DNS_EAI_ALLDONE,
		.caller = __func__,
	};
	int ret;

	timeout_query = false;

	ret = dns_get_addr_info(NAME6,
				DNS_QUERY_TYPE_AAAA,
				&current_dns_id,
				dns_result_cb,
				&status,
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv6 query");

	DBG("Query id %u\n", current_dns_id);

	k_yield(); /* mandatory so that net_if send func gets to run */

	if (k_sem_take(&wait_data2, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}
}

struct expected_addr_status {
	struct sockaddr addr;
	int status1;
	int status2;
	const char *caller;
};

void dns_result_numeric_cb(enum dns_resolve_status status,
			   struct dns_addrinfo *info,
			   void *user_data)
{
	struct expected_addr_status *expected = user_data;

	if (status != expected->status1 && status != expected->status2) {
		DBG("Result status %d\n", status);
		DBG("Expected status1 %d\n", expected->status1);
		DBG("Expected status2 %d\n", expected->status2);
		DBG("Caller %s\n", expected->caller);

		zassert_true(false, "Invalid status");
	}

	if (info && info->ai_family == AF_INET) {
		if (net_ipv4_addr_cmp(&net_sin(&info->ai_addr)->sin_addr,
				      &my_addr2) != true) {
			zassert_true(false, "IPv4 address does not match");
		}
	}

	if (info && info->ai_family == AF_INET6) {
#if defined(CONFIG_NET_IPV6)
		if (net_ipv6_addr_cmp(&net_sin6(&info->ai_addr)->sin6_addr,
				      &my_addr3) != true) {
			zassert_true(false, "IPv6 address does not match");
		}
#endif
	}

	k_sem_give(&wait_data2);
}

static void dns_query_ipv4_numeric(void)
{
	struct expected_addr_status status = {
		.status1 = DNS_EAI_INPROGRESS,
		.status2 = DNS_EAI_ALLDONE,
		.caller = __func__,
	};
	int ret;

	timeout_query = false;

	ret = dns_get_addr_info(NAME_IPV4,
				DNS_QUERY_TYPE_A,
				&current_dns_id,
				dns_result_numeric_cb,
				&status,
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv4 numeric query");

	DBG("Query id %u\n", current_dns_id);

	k_yield(); /* mandatory so that net_if send func gets to run */

	if (k_sem_take(&wait_data2, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}
}

static void dns_query_ipv6_numeric(void)
{
	struct expected_addr_status status = {
		.status1 = DNS_EAI_INPROGRESS,
		.status2 = DNS_EAI_ALLDONE,
		.caller = __func__,
	};
	int ret;

	timeout_query = false;

	ret = dns_get_addr_info(NAME_IPV6,
				DNS_QUERY_TYPE_AAAA,
				&current_dns_id,
				dns_result_numeric_cb,
				&status,
				DNS_TIMEOUT);
	zassert_equal(ret, 0, "Cannot create IPv6 query");

	DBG("Query id %u\n", current_dns_id);

	k_yield(); /* mandatory so that net_if send func gets to run */

	if (k_sem_take(&wait_data2, WAIT_TIME)) {
		zassert_true(false, "Timeout while waiting data");
	}
}

void test_main(void)
{
	ztest_test_suite(dns_tests,
			 ztest_unit_test(test_init),
			 ztest_unit_test(dns_query_invalid_timeout),
			 ztest_unit_test(dns_query_invalid_context),
			 ztest_unit_test(dns_query_invalid_callback),
			 ztest_unit_test(dns_query_invalid_query),
			 ztest_unit_test(dns_query_too_many),
			 ztest_unit_test(dns_query_server_count),
			 ztest_unit_test(dns_query_ipv4_server_count),
			 ztest_unit_test(dns_query_ipv6_server_count),
			 ztest_unit_test(dns_query_ipv4_timeout),
			 ztest_unit_test(dns_query_ipv6_timeout),
			 ztest_unit_test(dns_query_ipv4_cancel),
			 ztest_unit_test(dns_query_ipv6_cancel),
			 ztest_unit_test(dns_query_ipv4),
			 ztest_unit_test(dns_query_ipv6),
			 ztest_unit_test(dns_query_ipv4_numeric),
			 ztest_unit_test(dns_query_ipv6_numeric));

	ztest_run_test_suite(dns_tests);
}