Skip to content

Commit a9f8b75

Browse files
author
Mika
committed
Addeed support for DHCP vendor data
Process ARM vendor data at Wi-SUN bootstrap Fixed DHCP client vendor data processing Added new ARM Vendor data to transfer DNS cache results Removed Extra traces
1 parent d8f0003 commit a9f8b75

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "platform/topo_trace.h"
6666
#include "dhcp_service_api.h"
6767
#include "libDHCPv6/libDHCPv6.h"
68+
#include "libDHCPv6/libDHCPv6_vendordata.h"
6869
#include "DHCPv6_client/dhcpv6_client_api.h"
6970
#include "ws_management_api.h"
7071
#include "net_rpl.h"
@@ -898,7 +899,36 @@ static void ws_bootstrap_dhcp_info_notify_cb(int8_t interface, dhcp_option_notif
898899

899900
switch (options->option_type) {
900901
case DHCPV6_OPTION_VENDOR_SPECIFIC_INFO:
902+
if (options->option.vendor_spesific.enterprise_number != ARM_ENTERPRISE_NUMBER) {
903+
break;
904+
}
905+
while (options->option.vendor_spesific.data_length) {
906+
uint16_t option_type;
907+
char *domain;
908+
uint8_t *address;
909+
uint16_t option_len;
910+
option_len = net_dns_option_vendor_option_data_get_next(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &option_type);
911+
tr_debug("DHCP vendor specific data type:%u length %d", option_type, option_len);
912+
//tr_debug("DHCP vendor specific data %s", trace_array(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length));
913+
914+
if (option_len == 0) {
915+
// Option fields were corrupted
916+
break;
917+
}
918+
if (option_type == ARM_DHCP_VENDOR_DATA_DNS_QUERY_RESULT) {
919+
// Process ARM DNS query result
920+
domain = NULL;
921+
address = NULL;
922+
if (net_dns_option_vendor_option_data_dns_query_read(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &address, &domain) > 0 ||
923+
domain || address) {
924+
// Valid ARM DNS query entry
925+
net_dns_query_result_set(interface, address, domain, server_info->life_time);
926+
}
927+
}
901928

929+
options->option.vendor_spesific.data_length -= option_len;
930+
options->option.vendor_spesific.data += option_len;
931+
}
902932
break;
903933

904934
case DHCPV6_OPTION_DNS_SERVERS:

source/DHCPv6_client/dhcpv6_client_service.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ static void dhcp_vendor_information_notify(uint8_t *ptr, uint16_t data_len, dhcp
244244

245245
dhcp_server_notify_info_t server_info;
246246
server_info.life_time = srv_data_ptr->iaNontemporalAddress.validLifetime;
247-
server_info.duid = srv_data_ptr->serverDUID.duid;
247+
server_info.duid = srv_data_ptr->serverDUID.duid + 2; // Skip the type
248248
server_info.duid_type = srv_data_ptr->serverDUID.type;
249-
server_info.duid_length = srv_data_ptr->serverDUID.duid_length;
249+
server_info.duid_length = srv_data_ptr->serverDUID.duid_length - 2;// remove the type
250250

251251
while (data_len >= 4) {
252252
type = common_read_16_bit(ptr);
@@ -265,18 +265,19 @@ static void dhcp_vendor_information_notify(uint8_t *ptr, uint16_t data_len, dhcp
265265
dhcp_option.option.vendor_spesific.enterprise_number = common_read_32_bit(ptr);
266266
ptr += 4;
267267
data_len -= 4;
268+
length -= 4;
268269
dhcp_option.option.vendor_spesific.data = ptr;
269-
dhcp_option.option.vendor_spesific.data_length = data_len;
270+
dhcp_option.option.vendor_spesific.data_length = length;
270271

271272

272-
} else if (type == DHCPV6_OPTION_DNS_SERVERS && (data_len >= 16 && ((data_len % 16) == 0))) {
273+
} else if (type == DHCPV6_OPTION_DNS_SERVERS && (length >= 16 && ((length % 16) == 0))) {
273274
valid_optional_options = true;
274275
dhcp_option.option.generic.data = ptr;
275-
dhcp_option.option.generic.data_length = data_len;
276+
dhcp_option.option.generic.data_length = length;
276277
} else if (type == DHCPV6_OPTION_DOMAIN_LIST) {
277278
valid_optional_options = true;
278279
dhcp_option.option.generic.data = ptr;
279-
dhcp_option.option.generic.data_length = data_len;
280+
dhcp_option.option.generic.data_length = length;
280281
}
281282
if (valid_optional_options) {
282283
dhcp_option.option_type = type;

source/libDHCPv6/libDHCPv6_vendordata.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "libDHCPv6.h"
2424
#include "libDHCPv6_vendordata.h"
2525

26+
#define TRACE_GROUP "vend"
2627

2728

2829
/* DHCPv6 vendor options to distribute ARM vendor data*/
@@ -45,3 +46,55 @@ uint8_t *net_dns_option_vendor_option_data_dns_query_write(uint8_t *ptr, uint8_t
4546
ptr += domain_len + 1;
4647
return ptr;
4748
}
49+
50+
uint16_t net_dns_option_vendor_option_data_get_next(uint8_t *ptr, uint16_t length, uint16_t *type)
51+
{
52+
uint16_t option_len;
53+
54+
if (length < 4) {
55+
// Corrupted
56+
return 0;
57+
}
58+
if (type) {
59+
*type = common_read_16_bit(ptr);
60+
}
61+
62+
option_len = common_read_16_bit(ptr + 2);
63+
if (option_len + 4 > length) {
64+
// Corrupted
65+
return 0;
66+
}
67+
68+
return option_len + 4;
69+
}
70+
71+
uint16_t net_dns_option_vendor_option_data_dns_query_read(uint8_t *ptr, uint16_t length, uint8_t **address, char **domain)
72+
{
73+
uint16_t option_len;
74+
option_len = common_read_16_bit(ptr + 2);
75+
76+
if (length < 4 + 16 + 1) {
77+
// Corrupted as there is no room for all fields
78+
return 0;
79+
}
80+
if (option_len < 17) {
81+
// Corrupted as not enough room in field
82+
return 0;
83+
}
84+
if (*(ptr + 4 + option_len - 1) != 0) {
85+
// Not nul terminated string for domain
86+
return 0;
87+
}
88+
89+
if (common_read_16_bit(ptr) != ARM_DHCP_VENDOR_DATA_DNS_QUERY_RESULT) {
90+
return 0;
91+
}
92+
93+
if (address) {
94+
*address = ptr + 4;
95+
}
96+
if (domain) {
97+
*domain = (char *)(ptr + 4 + 16);
98+
}
99+
return option_len;
100+
}

source/libDHCPv6/libDHCPv6_vendordata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
uint16_t net_dns_option_vendor_option_data_dns_query_length(char *domain);
3838
uint8_t *net_dns_option_vendor_option_data_dns_query_write(uint8_t *ptr, uint8_t *address, char *domain);
3939

40+
uint16_t net_dns_option_vendor_option_data_get_next(uint8_t *ptr, uint16_t length, uint16_t *type);
41+
uint16_t net_dns_option_vendor_option_data_dns_query_read(uint8_t *ptr, uint16_t length, uint8_t **address, char **domain);
4042

4143

4244
#endif /* LIBDHCPV6_VENDOR_DATA_H_ */

source/libNET/src/net_dns.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int8_t net_dns_server_address_set(int8_t interface_id, const uint8_t address[16]
115115
}
116116
info_ptr->lifetime = lifetime;
117117
memcpy(info_ptr->dns_server_address, dns_server_address, 16);
118-
tr_info("DNS Server: %s Lifetime: %lu", trace_ipv6(info_ptr->dns_server_address), (unsigned long) info_ptr->lifetime);
118+
tr_info("DNS Server: %s from: %s Lifetime: %lu", trace_ipv6(info_ptr->dns_server_address), trace_ipv6(info_ptr->address), (unsigned long) info_ptr->lifetime);
119119
return 0;
120120
}
121121

@@ -234,7 +234,7 @@ static dns_query_t *dns_query_result_create(int8_t interface_id, const char *dom
234234
}
235235
this->interface_id = interface_id;
236236
strcpy(this->domain_str, domain_str);
237-
tr_debug("Create DNS query entry for %s", this->domain_str);
237+
//tr_debug("Create DNS query entry for %s", this->domain_str);
238238
ns_list_add_to_start(&dns_query_list, this);
239239
return this;
240240
}

0 commit comments

Comments
 (0)