diff --git a/nanostack/net_interface.h b/nanostack/net_interface.h index 2062a76eb161..89905eeb1625 100644 --- a/nanostack/net_interface.h +++ b/nanostack/net_interface.h @@ -868,6 +868,74 @@ extern int8_t arm_net_address_add_to_interface(int8_t interface_id, const uint8_ */ extern int8_t arm_net_address_delete_from_interface(int8_t interface_id, const uint8_t address[16]); +/** + * \brief A function to Get DNS server address learned by the interface setup + * + * If interface has learned DNS server address during the setup it can be used by + * the DNS client in that interface. This may return more than one address with DNS search list + * + * DNS server address can be learned from multiple routes + * * Router advertisements from Ethernet or LTE interfaces + * * DHCPv6 address generation + * + * If this address is not working DNS client should retry queries to other DNS servers + * + * Address is written to the buffer of the caller. + * + * DNS search list is given as pointer to stack memory where the data is present. + * + * This function should be called in loop with increasing index value starting + * from 0 until error is returned. + * + * \param interface_id Network interface ID. If set to -1 all interfaces are used + * \param address The address of the DNS server. + * \param dns_search_list_ptr pointer of pointer where dns search list data is pointing. + * \param dns_search_list_len pointer where.length of search list data + * \param index DNS address index that is read by the client. if that index is not available < -1 returned + * + * \return 0 on success, -1 on errors. + */ +extern int8_t arm_net_dns_server_get(int8_t interface_id, uint8_t address[16], uint8_t **dns_search_list_ptr, uint8_t *dns_search_list_len, uint8_t index); + +/** + * \brief A function to store cached DNS Query results + * + * Possibility to store or clear DNS query results to the stack. + * + * These are static query results that can be entered to specific interface. + * These are bound to single interface to allow making the actual query through other interface + * + * Lifetime should be set in value where new DNS entry is refreshed by application. + * This would be useful in case where servers are having DNS based load balancing. + * + * \param interface_id Network interface ID. + * \param address The IPv6 address of the domain. NULL to delete + * \param domain_name_ptr Domain name of the host. + * \param lifetime Lifetime of the entry 0 to delete. + * + * \return 0 on success, < 0 on errors. + */ +extern int8_t arm_net_dns_query_result_set(int8_t interface_id, const uint8_t address[16], const char *domain_name_ptr, uint32_t lifetime); + +/** + * \brief A function to Get cached DNS Query results + * + * If interface has learned DNS query results during the setup or operation. + * + * These are static query results that should be checked if the DNS did not find own + * cache entry. + * + * These will be updated during the lifetime and can be unavailable some time during + * the operation. This function should be called always to see if there is more recent data available. + * + * \param interface_id Network interface ID. If set to -1 all interfaces are used + * \param address Return the IPv6 address of the domain. + * \param domain_name_ptr Domain name where address query is made. + * + * \return 0 on success, -1 on errors. + */ +extern int8_t arm_net_dns_query_result_get(int8_t interface_id, uint8_t address[16], char *domain_name_ptr); + /** * \brief A function to add a route to the routing table. * \param prefix Destination prefix for the route to be added. diff --git a/nanostack/ws_bbr_api.h b/nanostack/ws_bbr_api.h index 760a22801535..18e4d019f280 100644 --- a/nanostack/ws_bbr_api.h +++ b/nanostack/ws_bbr_api.h @@ -421,4 +421,28 @@ int ws_bbr_radius_shared_secret_set(int8_t interface_id, const uint16_t shared_s */ int ws_bbr_radius_shared_secret_get(int8_t interface_id, uint16_t *shared_secret_len, uint8_t *shared_secret); +/** + * \brief A function to set DNS query results to border router + * + * Border router distributes these query results in DHCP Solicit responses to + * all the devices joining to the Wi-SUN mesh network. + * + * Border router keeps these forever, but if application does not update these in regular interval + * The address might stop working. So periodic keep alive is required. + * + * These cached query results will become available in the Wi-SUN interface. + * + * This function can be called multiple times. + * if domain name matches a existing entry address is updated. + * If address and domain name is set to NULL entire list is cleared + * + * \param interface_id Network interface ID. + * \param address The address of the DNS query result. + * \param domain_name_ptr Domain name matching the address + * + * \return < 0 failure + * \return >= 0 success + */ +int ws_bbr_dns_query_result_set(int8_t interface_id, const uint8_t address[16], char *domain_name_ptr); + #endif /* WS_BBR_API_H_ */ diff --git a/source/6LoWPAN/ws/ws_bbr_api.c b/source/6LoWPAN/ws/ws_bbr_api.c index 878c431f512e..3f22ab8ee2b9 100644 --- a/source/6LoWPAN/ws/ws_bbr_api.c +++ b/source/6LoWPAN/ws/ws_bbr_api.c @@ -41,6 +41,8 @@ #include "6LoWPAN/ws/ws_pae_controller.h" #include "DHCPv6_Server/DHCPv6_server_service.h" #include "DHCPv6_client/dhcpv6_client_api.h" +#include "libNET/src/net_dns_internal.h" + #include "ws_bbr_api.h" @@ -73,6 +75,9 @@ static uint8_t current_global_prefix[16] = {0}; // DHCP requires 16 bytes prefix static uint32_t bbr_delay_timer = BBR_CHECK_INTERVAL; // initial delay. static uint32_t global_prefix_unavailable_timer = 0; // initial delay. +static uint8_t *dhcp_vendor_data_ptr = NULL; +static uint8_t dhcp_vendor_data_len = 0; + static rpl_dodag_conf_t rpl_conf = { // Lifetime values .default_lifetime = 120, @@ -363,6 +368,23 @@ static bool wisun_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_upd wisun_bbr_na_send(backbone_interface_id, address_info->allocatedAddress); return true; } +static void ws_bbr_dhcp_server_dns_info_update(protocol_interface_info_entry_t *cur) +{ + //add DNS server information to DHCP server that is learned from the backbone interface. + uint8_t dns_server_address[16]; + uint8_t *dns_search_list_ptr = NULL; + uint8_t dns_search_list_len = 0; + (void)cur; + if (net_dns_server_get(backbone_interface_id, dns_server_address, &dns_search_list_ptr, &dns_search_list_len, 0) == 0) { + /*Only supporting one DNS server address*/ + //DHCPv6_server_service_set_dns_server(cur->id, dns_server_address, dns_search_list_ptr, dns_search_list_len); + } + + //TODO Generate vendor data in Wi-SUN network include the cached DNS query results in some sort of TLV format + (void)dhcp_vendor_data_ptr; + (void)dhcp_vendor_data_len; + //DHCPv6_server_service_set_vendor_data(cur->id, dhcp_vendor_data_ptr, dhcp_vendor_data_len); +} static void ws_bbr_dhcp_server_start(protocol_interface_info_entry_t *cur, uint8_t *global_id, uint32_t dhcp_address_lifetime) { @@ -384,6 +406,8 @@ static void ws_bbr_dhcp_server_start(protocol_interface_info_entry_t *cur, uint8 //SEt max value for not limiting address allocation DHCPv6_server_service_set_max_clients_accepts_count(cur->id, global_id, MAX_SUPPORTED_ADDRESS_LIST_SIZE); + ws_bbr_dhcp_server_dns_info_update(cur); + ws_dhcp_client_address_request(cur, global_id, ll); } static void ws_bbr_dhcp_server_stop(protocol_interface_info_entry_t *cur, uint8_t *global_id) @@ -570,6 +594,7 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur) // Add also global prefix and route to RPL rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, current_global_prefix, 64, 0, WS_ROUTE_LIFETIME, false); } + ws_bbr_dhcp_server_dns_info_update(cur); } } void ws_bbr_pan_version_increase(protocol_interface_info_entry_t *cur) @@ -1137,3 +1162,31 @@ int ws_bbr_radius_shared_secret_get(int8_t interface_id, uint16_t *shared_secret return -1; #endif } +int ws_bbr_dns_query_result_set(int8_t interface_id, const uint8_t address[16], char *domain_name_ptr) +{ +#ifdef HAVE_WS_BORDER_ROUTER + protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id); + if (!cur || !address || !domain_name_ptr) { + return -1; + } + + /* This information is only stored to the DHCPv6 server where it is distributed to the network + * + * Border router stores a list of these entries and includes a function to parse and generate the vendor data output + * + * This is included in the vendor extension where the format is decided by the vendor + */ + // TODO search if entry exists replace if address is NULL delete the entry + // TODO This information should expire if not updated by client + + ws_bbr_dhcp_server_dns_info_update(cur); + return 0; +#else + (void) interface_id; + (void) address; + (void) domain_name_ptr; + return -1; +#endif +} + + diff --git a/source/Common_Protocols/icmpv6.c b/source/Common_Protocols/icmpv6.c index 7433f2640b6d..52b87542577c 100644 --- a/source/Common_Protocols/icmpv6.c +++ b/source/Common_Protocols/icmpv6.c @@ -46,6 +46,7 @@ #include "6LoWPAN/Bootstraps/protocol_6lowpan.h" #include "6LoWPAN/ws/ws_common_defines.h" #include "6LoWPAN/ws/ws_common.h" +#include "libNET/src/net_dns_internal.h" #define TRACE_GROUP "icmp" @@ -869,12 +870,9 @@ static buffer_t *icmpv6_ra_handler(buffer_t *buf) uint8_t *dns_search_list = dptr + 6; uint8_t dns_search_list_len = length - 8; // Length includes type and length - tr_info("DNS Search List: %s Lifetime: %lu", trace_array(dns_search_list, dns_search_list_len), (unsigned long) dns_lifetime); - // TODO Add DNS server to DNS information storage. - // dns_search_list_storage(cur, buf->src_sa.address, dns_search_list, dns_search_list_len, dns_lifetime); - (void)dns_search_list; - (void)dns_search_list_len; - (void)dns_lifetime; + //tr_info("DNS Search List: %s Lifetime: %lu", trace_array(dns_search_list, dns_search_list_len), (unsigned long) dns_lifetime); + // Add DNS server to DNS information storage. + net_dns_server_search_list_set(cur->id, buf->src_sa.address, dns_search_list, dns_search_list_len, dns_lifetime); } else if (type == ICMPV6_OPT_RECURSIVE_DNS_SERVER) { uint8_t dns_length = length / 8; @@ -887,11 +885,9 @@ static buffer_t *icmpv6_ra_handler(buffer_t *buf) uint32_t dns_lifetime = common_read_32_bit(dptr + 2); // 2 x reserved for (int n = 0; n < dns_count; n++) { uint8_t *dns_srv_addr = dptr + 6 + n * 16; - tr_info("DNS Server: %s Lifetime: %lu", trace_ipv6(dns_srv_addr), (unsigned long) dns_lifetime); - // TODO Add DNS server to DNS information storage. - // dns_server_storage(cur, buf->src_sa.address, dns_srv_addr, dns_lifetime); - (void)dns_srv_addr; - (void)dns_lifetime; + //tr_info("DNS Server: %s Lifetime: %lu", trace_ipv6(dns_srv_addr), (unsigned long) dns_lifetime); + // Add DNS server to DNS information storage. + net_dns_server_address_set(cur->id, buf->src_sa.address, dns_srv_addr, dns_lifetime); } } else if (type == ICMPV6_OPT_6LOWPAN_CONTEXT) { nd_ra_process_lowpan_context_option(cur, dptr - 2); diff --git a/source/NWK_INTERFACE/protocol_core.c b/source/NWK_INTERFACE/protocol_core.c index 279bc7f0df61..168293a4b786 100644 --- a/source/NWK_INTERFACE/protocol_core.c +++ b/source/NWK_INTERFACE/protocol_core.c @@ -83,6 +83,7 @@ #include "Service_Libs/load_balance/load_balance_api.h" #include "Service_Libs/pan_blacklist/pan_blacklist_api.h" #include "Service_Libs/etx/etx.h" +#include "libNET/src/net_dns_internal.h" #include "mac_api.h" #include "ethernet_mac_api.h" @@ -304,6 +305,8 @@ void core_timer_event_handle(uint16_t ticksUpdate) ipv6_destination_cache_timer(seconds); ipv6_frag_timer(seconds); cipv6_frag_timer(seconds); + net_dns_timer_seconds(seconds); + #ifdef HAVE_WS ws_pae_controller_slow_timer(seconds); #endif diff --git a/source/libNET/src/net_dns.c b/source/libNET/src/net_dns.c new file mode 100644 index 000000000000..ef71f382fe7b --- /dev/null +++ b/source/libNET/src/net_dns.c @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2020, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "nsconfig.h" +#include "ns_types.h" +#include "ns_trace.h" +#include +#include "net_dns_internal.h" +#include "net_interface.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "nsdynmemLIB.h" +#include "ns_list.h" +#include "libNET/src/net_dns_internal.h" +#define TRACE_GROUP "Ndns" + + +typedef struct dns_server_info { + uint8_t address[16]; + uint8_t dns_server_address[16]; + uint32_t lifetime; + uint8_t *dns_search_list_ptr; + uint16_t dns_search_list_len; + int8_t interface_id; + ns_list_link_t link; +} dns_server_info_t; + +static NS_LIST_DEFINE(dns_server_list, dns_server_info_t, link); + +typedef struct dns_query { + uint8_t address[16]; + char *domain_str; + uint32_t lifetime; + int8_t interface_id; + ns_list_link_t link; +} dns_query_t; + +static NS_LIST_DEFINE(dns_query_list, dns_query_t, link); + +static dns_server_info_t *dns_server_info_find(int8_t interface_id, const uint8_t address[16]) +{ + dns_server_info_t *this = NULL; + ns_list_foreach(dns_server_info_t, cur_ptr, &dns_server_list) { + if (interface_id != -1 && cur_ptr->interface_id != interface_id) { + continue; + } + if (address && memcmp(cur_ptr->address, address, 16) == 0) { + this = cur_ptr; + break; + } + } + return this; +} + +static dns_server_info_t *dns_server_info_create(int8_t interface_id, const uint8_t address[16]) +{ + dns_server_info_t *this = ns_dyn_mem_alloc(sizeof(dns_server_info_t)); + + if (!this) { + return NULL; + } + + memset(this, 0, sizeof(dns_server_info_t)); + this->interface_id = interface_id; + memcpy(this->address, address, 16); + ns_list_add_to_start(&dns_server_list, this); + tr_debug("Create DNS entry for %s", trace_ipv6(address)); + + return this; +} + +static void dns_server_info_delete(dns_server_info_t *this) +{ + if (!this) { + return; + } + + tr_debug("delete DNS entry for %s", trace_ipv6(this->address)); + ns_list_remove(&dns_server_list, this); + ns_dyn_mem_free(this->dns_search_list_ptr); + ns_dyn_mem_free(this); +} + + +int8_t net_dns_server_address_set(int8_t interface_id, const uint8_t address[16], const uint8_t dns_server_address[16], uint32_t lifetime) +{ + dns_server_info_t *info_ptr; + + if (!address || interface_id < 0) { + return -1; + } + info_ptr = dns_server_info_find(interface_id, address); + + if (!dns_server_address || lifetime == 0) { + // Delete the entry + dns_server_info_delete(info_ptr); + return 0; + } + + if (!info_ptr) { + info_ptr = dns_server_info_create(interface_id, address); + } + info_ptr->lifetime = lifetime; + memcpy(info_ptr->dns_server_address, dns_server_address, 16); + tr_info("DNS Server: %s Lifetime: %lu", trace_ipv6(info_ptr->dns_server_address), (unsigned long) info_ptr->lifetime); + return 0; +} + +int8_t net_dns_server_search_list_set(int8_t interface_id, const uint8_t address[16], uint8_t *dns_search_list_ptr, uint8_t dns_search_list_len, uint32_t lifetime) +{ + dns_server_info_t *info_ptr; + + if (!address || interface_id < 0) { + return -1; + } + info_ptr = dns_server_info_find(interface_id, address); + + if (info_ptr && (!dns_search_list_ptr || lifetime == 0)) { + // remove search list information + tr_debug("DNS Search List clear"); + ns_dyn_mem_free(info_ptr->dns_search_list_ptr); + info_ptr->dns_search_list_ptr = NULL; + info_ptr->dns_search_list_len = 0; + return 0; + } + + if (!info_ptr) { + info_ptr = dns_server_info_create(interface_id, address); + if (!info_ptr) { + return -1; + } + info_ptr->lifetime = lifetime; + } + + if (info_ptr->dns_search_list_ptr && info_ptr->dns_search_list_len != dns_search_list_len) { + ns_dyn_mem_free(info_ptr->dns_search_list_ptr); + info_ptr->dns_search_list_ptr = NULL; + } + + if (!info_ptr->dns_search_list_ptr) { + info_ptr->dns_search_list_ptr = ns_dyn_mem_alloc(dns_search_list_len); + } + + if (!info_ptr->dns_search_list_ptr) { + return -2; + } + + memcpy(info_ptr->dns_search_list_ptr, dns_search_list_ptr, dns_search_list_len); + info_ptr->dns_search_list_len = dns_search_list_len; + tr_info("DNS Search List: %s Lifetime: %lu", trace_array(info_ptr->dns_search_list_ptr, info_ptr->dns_search_list_len), (unsigned long) info_ptr->lifetime); + + return 0; +} + +int8_t net_dns_server_get(int8_t interface_id, uint8_t dns_server_address[16], uint8_t **dns_search_list_ptr, uint8_t *dns_search_list_len, uint8_t index) +{ + dns_server_info_t *info_ptr = NULL; + uint8_t n = 0; + ns_list_foreach(dns_server_info_t, cur_ptr, &dns_server_list) { + if (interface_id != -1 && cur_ptr->interface_id != interface_id) { + continue; + } + if (index == n) { + info_ptr = cur_ptr; + break; + } + n++; + } + + if (!info_ptr) { + return -1; + } + if (dns_server_address) { + memcpy(dns_server_address, info_ptr->dns_server_address, 16); + } + if (dns_search_list_ptr) { + *dns_search_list_ptr = info_ptr->dns_search_list_ptr; + } + if (dns_search_list_len) { + *dns_search_list_len = info_ptr->dns_search_list_len; + } + return 0; +} + +/** + * Storage for DNS query results + */ + +static dns_query_t *dns_query_result_find(int8_t interface_id, const char *domain_str) +{ + dns_query_t *this = NULL; + ns_list_foreach(dns_query_t, cur_ptr, &dns_query_list) { + if (interface_id != -1 && cur_ptr->interface_id != interface_id) { + continue; + } + if (strcasecmp(cur_ptr->domain_str, domain_str) == 0) { + this = cur_ptr; + break; + } + } + return this; +} + +static dns_query_t *dns_query_result_create(int8_t interface_id, const char *domain_str) +{ + dns_query_t *this = NULL; + + if (!domain_str) { + return NULL; + } + this = ns_dyn_mem_alloc(sizeof(dns_query_t)); + if (!this) { + return NULL; + } + memset(this, 0, sizeof(dns_query_t)); + + this->domain_str = ns_dyn_mem_alloc(strlen(domain_str) + 1); + if (!this->domain_str) { + ns_dyn_mem_free(this); + return NULL; + } + this->interface_id = interface_id; + strcpy(this->domain_str, domain_str); + tr_debug("Create DNS query entry for %s", this->domain_str); + ns_list_add_to_start(&dns_query_list, this); + return this; +} + +static void dns_query_result_delete(dns_query_t *this) +{ + if (!this) { + return; + } + + tr_debug("Delete DNS query entry for %s", this->domain_str); + ns_list_remove(&dns_query_list, this); + ns_dyn_mem_free(this->domain_str); + ns_dyn_mem_free(this); +} + +int8_t net_dns_query_result_set(int8_t interface_id, const uint8_t address[16], const char *domain_name_ptr, uint32_t lifetime) +{ + dns_query_t *this; + + if (!domain_name_ptr || interface_id < 0) { + return -1; + } + this = dns_query_result_find(interface_id, domain_name_ptr); + + if (!address || lifetime == 0) { + // Delete the entry + dns_query_result_delete(this); + return 0; + } + + if (!this) { + this = dns_query_result_create(interface_id, domain_name_ptr); + } + + if (!this) { + return -2; + } + // update address and lifetime also to old query results + memcpy(this->address, address, 16); + this->lifetime = lifetime; + tr_info("DNS query set: %s address %s Lifetime: %lu", this->domain_str, trace_ipv6(this->address), (unsigned long) this->lifetime); + + return 0; +} + +int8_t net_dns_query_result_get(int8_t interface_id, uint8_t address[16], const char *domain_name_ptr) +{ + dns_query_t *this; + + if (!domain_name_ptr) { + return -1; + } + this = dns_query_result_find(interface_id, domain_name_ptr); + + if (!this) { + return -1; + } + if (address) { + memcpy(address, this->address, 16); + } + + return 0; +} + +/** + * Generic timeout handler for all interfaces and entries. + */ +void net_dns_timer_seconds(uint32_t seconds) +{ + ns_list_foreach_safe(dns_query_t, cur_ptr, &dns_query_list) { + if (cur_ptr->lifetime == 0xffffffff) { + continue; + } + if (cur_ptr->lifetime <= seconds) { + dns_query_result_delete(cur_ptr); + continue; + } + cur_ptr->lifetime -= seconds; + } + + ns_list_foreach_safe(dns_server_info_t, cur_ptr, &dns_server_list) { + if (cur_ptr->lifetime == 0xffffffff) { + continue; + } + if (cur_ptr->lifetime <= seconds) { + dns_server_info_delete(cur_ptr); + continue; + } + cur_ptr->lifetime -= seconds; + } + return; +} diff --git a/source/libNET/src/net_dns_internal.h b/source/libNET/src/net_dns_internal.h new file mode 100644 index 000000000000..bd58dbb51b29 --- /dev/null +++ b/source/libNET/src/net_dns_internal.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NET_DNS_INTERNAL_H_ +#define NET_DNS_INTERNAL_H_ + +/** + * These functions are used to store DNS server related information + * IF DNS information is learned from IPv6 Router advertisements + * or from the DHCPv6 elements + * + * Address is the link local address of the default router or DHCPv6 server address + */ + +int8_t net_dns_server_address_set(int8_t interface_id, const uint8_t address[16], const uint8_t dns_server_address[16], uint32_t lifetime); +int8_t net_dns_server_search_list_set(int8_t interface_id, const uint8_t address[16], uint8_t *dns_search_list_ptr, uint8_t dns_search_list_len, uint32_t lifetime); + +int8_t net_dns_server_get(int8_t interface_id, uint8_t dns_server_address[16], uint8_t **dns_search_list_ptr, uint8_t *dns_search_list_len, uint8_t index); + +/** + * Storage for DNS query results + */ + +int8_t net_dns_query_result_set(int8_t interface_id, const uint8_t address[16], const char *domain_name_ptr, uint32_t lifetime); + +int8_t net_dns_query_result_get(int8_t interface_id, uint8_t address[16], const char *domain_name_ptr); + +/** + * Generic timeout handler for all interfaces and entries. + */ +void net_dns_timer_seconds(uint32_t seconds); + +#endif /* NET_DNS_INTERNAL_H_ */ diff --git a/source/libNET/src/ns_net.c b/source/libNET/src/ns_net.c index ed35581c5e79..b863aa299224 100644 --- a/source/libNET/src/ns_net.c +++ b/source/libNET/src/ns_net.c @@ -61,6 +61,7 @@ #include "Security/Common/sec_lib_definitions.h" #include "ipv6_stack/protocol_ipv6.h" #include "ipv6_stack/ipv6_routing_table.h" +#include "libNET/src/net_dns_internal.h" #include "net_thread_test.h" #include "6LoWPAN/Thread/thread_common.h" #include "6LoWPAN/Thread/thread_routing.h" @@ -656,6 +657,24 @@ int8_t arm_net_address_delete_from_interface(int8_t interface_id, const uint8_t return addr_delete(cur, address); } +/* DNS cache functions + */ +int8_t arm_net_dns_server_get(int8_t interface_id, uint8_t address[16], uint8_t **dns_search_list_ptr, uint8_t *dns_search_list_len, uint8_t index) +{ + return net_dns_server_get(interface_id, address, dns_search_list_ptr, dns_search_list_len, index); +} + +int8_t arm_net_dns_query_result_set(int8_t interface_id, const uint8_t address[16], const char *domain_name_ptr, uint32_t lifetime) +{ + return net_dns_query_result_set(interface_id, address, domain_name_ptr, lifetime); +} + +int8_t arm_net_dns_query_result_get(int8_t interface_id, uint8_t address[16], char *domain_name_ptr) +{ + return net_dns_query_result_get(interface_id, address, domain_name_ptr); +} + + int8_t arm_net_route_add(const uint8_t *prefix, uint8_t prefix_len, const uint8_t *next_hop, uint32_t lifetime, uint8_t metric, int8_t interface_id) { ipv6_route_t *entry; @@ -682,7 +701,6 @@ int8_t arm_net_route_delete(const uint8_t *prefix, uint8_t prefix_len, const uin return ipv6_route_delete(prefix, prefix_len, interface_id, next_hop, ROUTE_USER); } - int8_t arm_nwk_interface_ethernet_init(eth_mac_api_t *api, const char *interface_name_ptr) { #ifdef HAVE_ETHERNET diff --git a/sources.mk b/sources.mk index 97b4113c2078..8db71ba29484 100644 --- a/sources.mk +++ b/sources.mk @@ -67,6 +67,7 @@ SRCS += \ source/libNET/src/net_mle.c \ source/libNET/src/net_rpl.c \ source/libNET/src/net_load_balance.c \ + source/libNET/src/net_dns.c \ source/libNET/src/ns_net.c \ source/libNET/src/socket_api.c \ source/libNET/src/multicast_api.c \ diff --git a/test/nanostack/unittest/Common_Protocols/icmpv6/Makefile b/test/nanostack/unittest/Common_Protocols/icmpv6/Makefile index 3b312da1be61..6a6f1379f3b6 100644 --- a/test/nanostack/unittest/Common_Protocols/icmpv6/Makefile +++ b/test/nanostack/unittest/Common_Protocols/icmpv6/Makefile @@ -25,6 +25,7 @@ TEST_SRC_FILES = \ ../../stub/rpl_control_stub.c \ ../../stub/mpl_stub.c \ ../../stub/mld_stub.c \ + ../../stub/net_dns_stub.c \ ../../stub/nd_proxy_stub.c \ ../../stub/rpl_data_stub.c \ ../../stub/icmpv6_radv_stub.c \ diff --git a/test/nanostack/unittest/nwk_interface/protocol_core/Makefile b/test/nanostack/unittest/nwk_interface/protocol_core/Makefile index d2eb83d8b4ed..6a3388fc6a1e 100644 --- a/test/nanostack/unittest/nwk_interface/protocol_core/Makefile +++ b/test/nanostack/unittest/nwk_interface/protocol_core/Makefile @@ -40,6 +40,7 @@ TEST_SRC_FILES = \ ../../stub/ws_pae_controller_stub.c \ ../../stub/mld_stub.c \ ../../stub/mpl_stub.c \ + ../../stub/net_dns_stub.c \ ../../stub/rpl_control_stub.c \ ../../stub/platform_stub.c \ ../../stub/lowpan_context_stub.c \ diff --git a/test/nanostack/unittest/stub/net_dns_stub.c b/test/nanostack/unittest/stub/net_dns_stub.c new file mode 100644 index 000000000000..15e508ea5fce --- /dev/null +++ b/test/nanostack/unittest/stub/net_dns_stub.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "nsconfig.h" +#include "ns_types.h" + +int8_t net_dns_server_address_set(int8_t interface_id, const uint8_t address[16], const uint8_t dns_server_address[16], uint32_t lifetime) +{ + return 0; +} + +int8_t net_dns_server_search_list_set(int8_t interface_id, const uint8_t address[16], uint8_t *dns_search_list_ptr, uint8_t dns_search_list_len, uint32_t lifetime) +{ + return 0; +} + +int8_t net_dns_server_get(int8_t interface_id, uint8_t dns_server_address[16], uint8_t **dns_search_list_ptr, uint8_t *dns_search_list_len, uint8_t index) +{ + return 0; +} + +int8_t net_dns_query_result_set(int8_t interface_id, const uint8_t address[16], const char *domain_name_ptr, uint32_t lifetime) +{ + return 0; +} + +int8_t net_dns_query_result_get(int8_t interface_id, uint8_t address[16], const char *domain_name_ptr) +{ + return 0; +} + +void net_dns_timer_seconds(uint32_t seconds) +{ +}