Skip to content

Commit

Permalink
Create APIs for DNS cache results
Browse files Browse the repository at this point in the history
Added Border router API to insert cached DNS queries

Added network interface API to get DNS configuration and queries

Added new module to store and read DNS queries
  • Loading branch information
Mika committed Aug 28, 2020
1 parent 587add5 commit 61d3db8
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 12 deletions.
68 changes: 68 additions & 0 deletions nanostack/net_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions nanostack/ws_bbr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
53 changes: 53 additions & 0 deletions source/6LoWPAN/ws/ws_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}


18 changes: 7 additions & 11 deletions source/Common_Protocols/icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions source/NWK_INTERFACE/protocol_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 61d3db8

Please sign in to comment.