Skip to content

Commit 61d3db8

Browse files
author
Mika
committed
Create APIs for DNS cache results
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
1 parent 587add5 commit 61d3db8

File tree

12 files changed

+602
-12
lines changed

12 files changed

+602
-12
lines changed

nanostack/net_interface.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,74 @@ extern int8_t arm_net_address_add_to_interface(int8_t interface_id, const uint8_
868868
*/
869869
extern int8_t arm_net_address_delete_from_interface(int8_t interface_id, const uint8_t address[16]);
870870

871+
/**
872+
* \brief A function to Get DNS server address learned by the interface setup
873+
*
874+
* If interface has learned DNS server address during the setup it can be used by
875+
* the DNS client in that interface. This may return more than one address with DNS search list
876+
*
877+
* DNS server address can be learned from multiple routes
878+
* * Router advertisements from Ethernet or LTE interfaces
879+
* * DHCPv6 address generation
880+
*
881+
* If this address is not working DNS client should retry queries to other DNS servers
882+
*
883+
* Address is written to the buffer of the caller.
884+
*
885+
* DNS search list is given as pointer to stack memory where the data is present.
886+
*
887+
* This function should be called in loop with increasing index value starting
888+
* from 0 until error is returned.
889+
*
890+
* \param interface_id Network interface ID. If set to -1 all interfaces are used
891+
* \param address The address of the DNS server.
892+
* \param dns_search_list_ptr pointer of pointer where dns search list data is pointing.
893+
* \param dns_search_list_len pointer where.length of search list data
894+
* \param index DNS address index that is read by the client. if that index is not available < -1 returned
895+
*
896+
* \return 0 on success, -1 on errors.
897+
*/
898+
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);
899+
900+
/**
901+
* \brief A function to store cached DNS Query results
902+
*
903+
* Possibility to store or clear DNS query results to the stack.
904+
*
905+
* These are static query results that can be entered to specific interface.
906+
* These are bound to single interface to allow making the actual query through other interface
907+
*
908+
* Lifetime should be set in value where new DNS entry is refreshed by application.
909+
* This would be useful in case where servers are having DNS based load balancing.
910+
*
911+
* \param interface_id Network interface ID.
912+
* \param address The IPv6 address of the domain. NULL to delete
913+
* \param domain_name_ptr Domain name of the host.
914+
* \param lifetime Lifetime of the entry 0 to delete.
915+
*
916+
* \return 0 on success, < 0 on errors.
917+
*/
918+
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);
919+
920+
/**
921+
* \brief A function to Get cached DNS Query results
922+
*
923+
* If interface has learned DNS query results during the setup or operation.
924+
*
925+
* These are static query results that should be checked if the DNS did not find own
926+
* cache entry.
927+
*
928+
* These will be updated during the lifetime and can be unavailable some time during
929+
* the operation. This function should be called always to see if there is more recent data available.
930+
*
931+
* \param interface_id Network interface ID. If set to -1 all interfaces are used
932+
* \param address Return the IPv6 address of the domain.
933+
* \param domain_name_ptr Domain name where address query is made.
934+
*
935+
* \return 0 on success, -1 on errors.
936+
*/
937+
extern int8_t arm_net_dns_query_result_get(int8_t interface_id, uint8_t address[16], char *domain_name_ptr);
938+
871939
/**
872940
* \brief A function to add a route to the routing table.
873941
* \param prefix Destination prefix for the route to be added.

nanostack/ws_bbr_api.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,28 @@ int ws_bbr_radius_shared_secret_set(int8_t interface_id, const uint16_t shared_s
421421
*/
422422
int ws_bbr_radius_shared_secret_get(int8_t interface_id, uint16_t *shared_secret_len, uint8_t *shared_secret);
423423

424+
/**
425+
* \brief A function to set DNS query results to border router
426+
*
427+
* Border router distributes these query results in DHCP Solicit responses to
428+
* all the devices joining to the Wi-SUN mesh network.
429+
*
430+
* Border router keeps these forever, but if application does not update these in regular interval
431+
* The address might stop working. So periodic keep alive is required.
432+
*
433+
* These cached query results will become available in the Wi-SUN interface.
434+
*
435+
* This function can be called multiple times.
436+
* if domain name matches a existing entry address is updated.
437+
* If address and domain name is set to NULL entire list is cleared
438+
*
439+
* \param interface_id Network interface ID.
440+
* \param address The address of the DNS query result.
441+
* \param domain_name_ptr Domain name matching the address
442+
*
443+
* \return < 0 failure
444+
* \return >= 0 success
445+
*/
446+
int ws_bbr_dns_query_result_set(int8_t interface_id, const uint8_t address[16], char *domain_name_ptr);
447+
424448
#endif /* WS_BBR_API_H_ */

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "6LoWPAN/ws/ws_pae_controller.h"
4242
#include "DHCPv6_Server/DHCPv6_server_service.h"
4343
#include "DHCPv6_client/dhcpv6_client_api.h"
44+
#include "libNET/src/net_dns_internal.h"
45+
4446

4547
#include "ws_bbr_api.h"
4648

@@ -73,6 +75,9 @@ static uint8_t current_global_prefix[16] = {0}; // DHCP requires 16 bytes prefix
7375
static uint32_t bbr_delay_timer = BBR_CHECK_INTERVAL; // initial delay.
7476
static uint32_t global_prefix_unavailable_timer = 0; // initial delay.
7577

78+
static uint8_t *dhcp_vendor_data_ptr = NULL;
79+
static uint8_t dhcp_vendor_data_len = 0;
80+
7681
static rpl_dodag_conf_t rpl_conf = {
7782
// Lifetime values
7883
.default_lifetime = 120,
@@ -363,6 +368,23 @@ static bool wisun_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_upd
363368
wisun_bbr_na_send(backbone_interface_id, address_info->allocatedAddress);
364369
return true;
365370
}
371+
static void ws_bbr_dhcp_server_dns_info_update(protocol_interface_info_entry_t *cur)
372+
{
373+
//add DNS server information to DHCP server that is learned from the backbone interface.
374+
uint8_t dns_server_address[16];
375+
uint8_t *dns_search_list_ptr = NULL;
376+
uint8_t dns_search_list_len = 0;
377+
(void)cur;
378+
if (net_dns_server_get(backbone_interface_id, dns_server_address, &dns_search_list_ptr, &dns_search_list_len, 0) == 0) {
379+
/*Only supporting one DNS server address*/
380+
//DHCPv6_server_service_set_dns_server(cur->id, dns_server_address, dns_search_list_ptr, dns_search_list_len);
381+
}
382+
383+
//TODO Generate vendor data in Wi-SUN network include the cached DNS query results in some sort of TLV format
384+
(void)dhcp_vendor_data_ptr;
385+
(void)dhcp_vendor_data_len;
386+
//DHCPv6_server_service_set_vendor_data(cur->id, dhcp_vendor_data_ptr, dhcp_vendor_data_len);
387+
}
366388

367389
static void ws_bbr_dhcp_server_start(protocol_interface_info_entry_t *cur, uint8_t *global_id, uint32_t dhcp_address_lifetime)
368390
{
@@ -384,6 +406,8 @@ static void ws_bbr_dhcp_server_start(protocol_interface_info_entry_t *cur, uint8
384406
//SEt max value for not limiting address allocation
385407
DHCPv6_server_service_set_max_clients_accepts_count(cur->id, global_id, MAX_SUPPORTED_ADDRESS_LIST_SIZE);
386408

409+
ws_bbr_dhcp_server_dns_info_update(cur);
410+
387411
ws_dhcp_client_address_request(cur, global_id, ll);
388412
}
389413
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)
570594
// Add also global prefix and route to RPL
571595
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, current_global_prefix, 64, 0, WS_ROUTE_LIFETIME, false);
572596
}
597+
ws_bbr_dhcp_server_dns_info_update(cur);
573598
}
574599
}
575600
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
11371162
return -1;
11381163
#endif
11391164
}
1165+
int ws_bbr_dns_query_result_set(int8_t interface_id, const uint8_t address[16], char *domain_name_ptr)
1166+
{
1167+
#ifdef HAVE_WS_BORDER_ROUTER
1168+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
1169+
if (!cur || !address || !domain_name_ptr) {
1170+
return -1;
1171+
}
1172+
1173+
/* This information is only stored to the DHCPv6 server where it is distributed to the network
1174+
*
1175+
* Border router stores a list of these entries and includes a function to parse and generate the vendor data output
1176+
*
1177+
* This is included in the vendor extension where the format is decided by the vendor
1178+
*/
1179+
// TODO search if entry exists replace if address is NULL delete the entry
1180+
// TODO This information should expire if not updated by client
1181+
1182+
ws_bbr_dhcp_server_dns_info_update(cur);
1183+
return 0;
1184+
#else
1185+
(void) interface_id;
1186+
(void) address;
1187+
(void) domain_name_ptr;
1188+
return -1;
1189+
#endif
1190+
}
1191+
1192+

source/Common_Protocols/icmpv6.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
4747
#include "6LoWPAN/ws/ws_common_defines.h"
4848
#include "6LoWPAN/ws/ws_common.h"
49+
#include "libNET/src/net_dns_internal.h"
4950

5051
#define TRACE_GROUP "icmp"
5152

@@ -869,12 +870,9 @@ static buffer_t *icmpv6_ra_handler(buffer_t *buf)
869870
uint8_t *dns_search_list = dptr + 6;
870871
uint8_t dns_search_list_len = length - 8; // Length includes type and length
871872

872-
tr_info("DNS Search List: %s Lifetime: %lu", trace_array(dns_search_list, dns_search_list_len), (unsigned long) dns_lifetime);
873-
// TODO Add DNS server to DNS information storage.
874-
// dns_search_list_storage(cur, buf->src_sa.address, dns_search_list, dns_search_list_len, dns_lifetime);
875-
(void)dns_search_list;
876-
(void)dns_search_list_len;
877-
(void)dns_lifetime;
873+
//tr_info("DNS Search List: %s Lifetime: %lu", trace_array(dns_search_list, dns_search_list_len), (unsigned long) dns_lifetime);
874+
// Add DNS server to DNS information storage.
875+
net_dns_server_search_list_set(cur->id, buf->src_sa.address, dns_search_list, dns_search_list_len, dns_lifetime);
878876

879877
} else if (type == ICMPV6_OPT_RECURSIVE_DNS_SERVER) {
880878
uint8_t dns_length = length / 8;
@@ -887,11 +885,9 @@ static buffer_t *icmpv6_ra_handler(buffer_t *buf)
887885
uint32_t dns_lifetime = common_read_32_bit(dptr + 2); // 2 x reserved
888886
for (int n = 0; n < dns_count; n++) {
889887
uint8_t *dns_srv_addr = dptr + 6 + n * 16;
890-
tr_info("DNS Server: %s Lifetime: %lu", trace_ipv6(dns_srv_addr), (unsigned long) dns_lifetime);
891-
// TODO Add DNS server to DNS information storage.
892-
// dns_server_storage(cur, buf->src_sa.address, dns_srv_addr, dns_lifetime);
893-
(void)dns_srv_addr;
894-
(void)dns_lifetime;
888+
//tr_info("DNS Server: %s Lifetime: %lu", trace_ipv6(dns_srv_addr), (unsigned long) dns_lifetime);
889+
// Add DNS server to DNS information storage.
890+
net_dns_server_address_set(cur->id, buf->src_sa.address, dns_srv_addr, dns_lifetime);
895891
}
896892
} else if (type == ICMPV6_OPT_6LOWPAN_CONTEXT) {
897893
nd_ra_process_lowpan_context_option(cur, dptr - 2);

source/NWK_INTERFACE/protocol_core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "Service_Libs/load_balance/load_balance_api.h"
8484
#include "Service_Libs/pan_blacklist/pan_blacklist_api.h"
8585
#include "Service_Libs/etx/etx.h"
86+
#include "libNET/src/net_dns_internal.h"
8687

8788
#include "mac_api.h"
8889
#include "ethernet_mac_api.h"
@@ -304,6 +305,8 @@ void core_timer_event_handle(uint16_t ticksUpdate)
304305
ipv6_destination_cache_timer(seconds);
305306
ipv6_frag_timer(seconds);
306307
cipv6_frag_timer(seconds);
308+
net_dns_timer_seconds(seconds);
309+
307310
#ifdef HAVE_WS
308311
ws_pae_controller_slow_timer(seconds);
309312
#endif

0 commit comments

Comments
 (0)