-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also piggy-back some fixes to the unittests and submodule handling
- Loading branch information
Showing
14 changed files
with
138 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
*/ | ||
|
||
/** | ||
* @ingroup net_sock_dns | ||
* @defgroup net_dns_cache DNS cache | ||
* @ingroup net_dns | ||
* | ||
* @brief DNS cache | ||
* | ||
|
@@ -29,23 +30,39 @@ | |
* @author Benjamin Valentin <[email protected]> | ||
*/ | ||
|
||
#ifndef DNS_CACHE_H | ||
#define DNS_CACHE_H | ||
#ifndef NET_DNS_CACHE_H | ||
#define NET_DNS_CACHE_H | ||
|
||
#include <stdint.h> | ||
|
||
#include "kernel_defines.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Number of DNS cache entries | ||
* @brief Maximum number of DNS cache entries | ||
*/ | ||
#ifndef CONFIG_DNS_CACHE_SIZE | ||
#define CONFIG_DNS_CACHE_SIZE 4 | ||
#endif | ||
|
||
#if IS_USED(MODULE_SOCK_DNS_CACHE) || DOXYGEN | ||
/** | ||
* @brief Handle to cache A records | ||
*/ | ||
#ifndef CONFIG_DNS_CACHE_A | ||
#define CONFIG_DNS_CACHE_A IS_USED(MODULE_IPV4) | ||
#endif | ||
|
||
/** | ||
* @brief Handle to cache AAAA records | ||
*/ | ||
#ifndef CONFIG_DNS_CACHE_AAAA | ||
#define CONFIG_DNS_CACHE_AAAA IS_USED(MODULE_IPV6) | ||
#endif | ||
|
||
#if IS_USED(MODULE_DNS_CACHE) || DOXYGEN | ||
/** | ||
* @brief Get IP address for a DNS name from the DNS cache | ||
* | ||
|
@@ -56,7 +73,7 @@ extern "C" { | |
* @return the size of the resolved address on success | ||
* @return <= 0 otherwise | ||
*/ | ||
int sock_dns_cache_query(const char *domain_name, void *addr_out, int family); | ||
int dns_cache_query(const char *domain_name, void *addr_out, int family); | ||
|
||
/** | ||
* @brief Add an IP address for a DNS name to the DNS cache | ||
|
@@ -66,19 +83,18 @@ int sock_dns_cache_query(const char *domain_name, void *addr_out, int family); | |
* @param[in] addr_len length of the address in bytes | ||
* @param[in] ttl lifetime of the entry in seconds | ||
*/ | ||
void sock_dns_cache_add(const char *domain_name, const void *addr, int addr_len, uint32_t ttl); | ||
void dns_cache_add(const char *domain_name, const void *addr, int addr_len, uint32_t ttl); | ||
#else | ||
static inline int sock_dns_cache_query(const char *domain_name, | ||
void *addr_out, int family) | ||
static inline int dns_cache_query(const char *domain_name, void *addr_out, int family) | ||
{ | ||
(void)domain_name; | ||
(void)addr_out; | ||
(void)family; | ||
return 0; | ||
} | ||
|
||
static inline void sock_dns_cache_add(const char *domain_name, const void *addr, | ||
int addr_len, uint32_t ttl) | ||
static inline void dns_cache_add(const char *domain_name, const void *addr, | ||
int addr_len, uint32_t ttl) | ||
{ | ||
(void)domain_name; | ||
(void)addr; | ||
|
@@ -91,5 +107,5 @@ static inline void sock_dns_cache_add(const char *domain_name, const void *addr, | |
} | ||
#endif | ||
|
||
#endif /* DNS_CACHE_H */ | ||
#endif /* NET_DNS_CACHE_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
SRC := | ||
|
||
SUBMODULE := 1 | ||
SUBMODULES := 1 | ||
|
||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
SRC += dns.c | ||
|
||
ifneq (,$(filter sock_dns_cache, $(USEMODULE))) | ||
SRC += dns_cache.c | ||
endif | ||
|
||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
USEMODULE += dns_cache | ||
USEMODULE += ipv4 | ||
USEMODULE += ipv6 | ||
USEMODULE += ztimer_usec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2022 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <string.h> | ||
#include "net/af.h" | ||
#include "net/ipv6.h" | ||
#include "ztimer.h" | ||
|
||
#include "net/dns/cache.h" | ||
|
||
#include "tests-dns_cache.h" | ||
|
||
static void test_dns_cache_add(void) | ||
{ | ||
ipv6_addr_t addr_in = IPV6_ADDR_ALL_NODES_IF_LOCAL; | ||
ipv6_addr_t addr_out; | ||
|
||
TEST_ASSERT_EQUAL_INT(0, dns_cache_query("example.com", &addr_out, AF_INET6)); | ||
|
||
/* add DNS entry, set it to expire in 1s */ | ||
dns_cache_add("example.com", &addr_in, sizeof(addr_in), 1); | ||
TEST_ASSERT_EQUAL_INT(sizeof(addr_out), dns_cache_query("example.com", &addr_out, AF_INET6)); | ||
TEST_ASSERT_EQUAL_INT(0, memcmp(&addr_in, &addr_out, sizeof(addr_in))); | ||
|
||
TEST_ASSERT_EQUAL_INT(0, dns_cache_query("example.com", &addr_out, AF_INET)); | ||
TEST_ASSERT_EQUAL_INT(0, dns_cache_query("alt.example.com", &addr_out, AF_INET6)); | ||
TEST_ASSERT_EQUAL_INT(0, dns_cache_query("example.comm", &addr_out, AF_INET6)); | ||
TEST_ASSERT_EQUAL_INT(0, dns_cache_query("example.co", &addr_out, AF_INET6)); | ||
|
||
ztimer_sleep(ZTIMER_USEC, 2000000); | ||
TEST_ASSERT_EQUAL_INT(0, dns_cache_query("example.com", &addr_out, AF_INET6)); | ||
} | ||
|
||
Test *tests_dns_cache_tests(void) | ||
{ | ||
EMB_UNIT_TESTFIXTURES(fixtures) { | ||
new_TestFixture(test_dns_cache_add), | ||
}; | ||
|
||
EMB_UNIT_TESTCALLER(dns_cache_tests, NULL, NULL, fixtures); | ||
|
||
return (Test *)&dns_cache_tests; | ||
} | ||
|
||
void tests_dns_cache(void) | ||
{ | ||
TESTS_RUN(tests_dns_cache_tests()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,12 @@ | |
* @{ | ||
* | ||
* @file | ||
* @brief Unittests for the ``sock_dns_cache`` module | ||
* @brief Unittests for the ``dns_cache`` module | ||
* | ||
* @author Benjamin Valentin <[email protected]> | ||
*/ | ||
#ifndef TESTS_SOCK_DNS_CACHE_H | ||
#define TESTS_SOCK_DNS_CACHE_H | ||
#ifndef TESTS_DNS_CACHE_H | ||
#define TESTS_DNS_CACHE_H | ||
|
||
#include "embUnit.h" | ||
|
||
|
@@ -27,18 +27,18 @@ extern "C" { | |
/** | ||
* @brief The entry point of this test suite. | ||
*/ | ||
void tests_sock_dns_cache(void); | ||
void tests_dns_cache(void); | ||
|
||
/** | ||
* @brief Generates tests for sock_dns_cache | ||
* @brief Generates tests for dns_cache | ||
* | ||
* @return embUnit tests if successful, NULL if not. | ||
*/ | ||
Test *tests_sock_dns_cache_tests(void); | ||
Test *tests_dns_cache_tests(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* TESTS_SOCK_DNS_CACHE_H */ | ||
#endif /* TESTS_DNS_CACHE_H */ | ||
/** @} */ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.