1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/net/dns/cache.h

112 lines
2.7 KiB
C
Raw Normal View History

2022-02-19 14:20:40 +01:00
/*
* 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.
*/
/**
* @defgroup net_dns_cache DNS cache
* @ingroup net_dns
2022-02-19 14:20:40 +01:00
*
* @brief DNS cache
*
* @{
*
* @file
* @brief DNS cache definitions
*
* This implements a simple DNS cache for A and AAAA entries.
*
* The cache eviction strategy is based on the remaining time to live
* of the cache entries, so the first entry to expire will be evicted.
*
* This is fine if there are only few cache entries and cache eviction
* is unlikely.
* If there is communication to many different hosts, the addition of a
* least-recently used counter could likely improve the behavior.
*
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
*/
#ifndef NET_DNS_CACHE_H
#define NET_DNS_CACHE_H
2022-02-19 14:20:40 +01:00
#include <stdint.h>
#include "kernel_defines.h"
2022-02-19 14:20:40 +01:00
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Maximum number of DNS cache entries
2022-02-19 14:20:40 +01:00
*/
#ifndef CONFIG_DNS_CACHE_SIZE
#define CONFIG_DNS_CACHE_SIZE 4
#endif
/**
* @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
2022-02-19 14:20:40 +01:00
/**
* @brief Get IP address for a DNS name from the DNS cache
*
* @param[in] domain_name DNS name to resolve into address
* @param[out] addr_out buffer to write result into
* @param[in] family Either AF_INET, AF_INET6 or AF_UNSPEC
*
* @return the size of the resolved address on success
* @return <= 0 otherwise
2022-02-19 14:20:40 +01:00
*/
int dns_cache_query(const char *domain_name, void *addr_out, int family);
2022-02-19 14:20:40 +01:00
/**
* @brief Add an IP address for a DNS name to the DNS cache
*
* @param[in] domain_name DNS name to resolve into address
* @param[in] addr buffer containing the address
2022-02-19 14:20:40 +01:00
* @param[in] addr_len length of the address in bytes
* @param[in] ttl lifetime of the entry in seconds
*/
void dns_cache_add(const char *domain_name, const void *addr, int addr_len, uint32_t ttl);
2022-02-19 14:20:40 +01:00
#else
static inline int dns_cache_query(const char *domain_name, void *addr_out, int family)
2022-02-19 14:20:40 +01:00
{
(void)domain_name;
(void)addr_out;
(void)family;
return 0;
}
static inline void dns_cache_add(const char *domain_name, const void *addr,
int addr_len, uint32_t ttl)
2022-02-19 14:20:40 +01:00
{
(void)domain_name;
(void)addr;
2022-02-19 14:20:40 +01:00
(void)addr_len;
(void)ttl;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* NET_DNS_CACHE_H */
2022-02-19 14:20:40 +01:00
/** @} */