Skip to content

Commit 5b153f4

Browse files
author
Juha Heiskanen
committed
DHCPv6 Client and Server update
Added support for configure DUID to server dynamically after deafult setup which IS DUID-LL Client support now dynamically Any server DUID mode. DHCPv6 client support multi instance now and every intance generate default DUID-LL based on user intafce. Change-Id: I61beed73ab1a96ad83ad9af04471843255a72324
1 parent ab849c6 commit 5b153f4

File tree

16 files changed

+562
-289
lines changed

16 files changed

+562
-289
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ void thread_interface_init(protocol_interface_info_entry_t *cur)
899899
{
900900
thread_discovery_reset(cur->id);
901901
thread_routing_set_mesh_callbacks(cur);
902-
dhcp_client_init(cur->id);
902+
dhcp_client_init(cur->id, DHCPV6_DUID_HARDWARE_EUI64_TYPE);
903903
dhcp_client_configure(cur->id, false, false, false);
904904
thread_management_client_init(cur->id);
905905
thread_bootstrap_address_registration_init();
@@ -2886,7 +2886,7 @@ void thread_bootstrap_network_prefixes_process(protocol_interface_info_entry_t *
28862886
thread_addr_write_mesh_local_16(addr, curBorderRouter->routerID, cur->thread_info);
28872887
/* Do not allow multiple DHCP solicits from one prefix => delete previous */
28882888
dhcp_client_global_address_delete(cur->id, NULL, curPrefix->servicesPrefix);
2889-
if (dhcp_client_get_global_address(cur->id, addr, curPrefix->servicesPrefix, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE, thread_dhcp_client_gua_error_cb) == 0) {
2889+
if (dhcp_client_get_global_address(cur->id, addr, curPrefix->servicesPrefix, thread_dhcp_client_gua_error_cb) == 0) {
28902890
tr_debug("GP Address Requested");
28912891
}
28922892
}

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
761761
/*Replace NS handler to disable multicast address queries */
762762
cur->if_ns_transmit = ws_bootstrap_nd_ns_transmit;
763763

764-
dhcp_client_init(cur->id);
764+
dhcp_client_init(cur->id, DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE);
765765
dhcp_client_configure(cur->id, true, true, true); //RENEW uses SOLICIT, Interface will use 1 instance for address get, IAID address hint is not used.
766766
dhcp_client_solicit_timeout_set(cur->id, WS_DHCP_SOLICIT_TIMEOUT, WS_DHCP_SOLICIT_MAX_RT, WS_DHCP_SOLICIT_MAX_RC);
767767

@@ -2076,7 +2076,7 @@ static void ws_dhcp_client_global_adress_cb(int8_t interface, uint8_t dhcp_addr[
20762076

20772077
void ws_dhcp_client_address_request(protocol_interface_info_entry_t *cur, uint8_t *prefix, uint8_t *parent_link_local)
20782078
{
2079-
if (dhcp_client_get_global_address(cur->id, parent_link_local, prefix, cur->mac, DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE, ws_dhcp_client_global_adress_cb) != 0) {
2079+
if (dhcp_client_get_global_address(cur->id, parent_link_local, prefix, ws_dhcp_client_global_adress_cb) != 0) {
20802080
tr_error("DHCPp client request fail");
20812081
}
20822082
}

source/DHCPv6_Server/DHCPv6_Server_service.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ int DHCPv6_server_respond_client(dhcpv6_gua_server_entry_s *serverBase, dhcpv6_r
9090
dhcpv6_alloacted_address_entry_t *dhcp_allocated_address;
9191
dhcpv6_ia_non_temporal_address_s nonTemporalAddress;
9292
bool address_allocated = false;
93-
dhcp_allocated_address = libdhcpv6_address_allocated_list_scan(serverBase, replyPacket->clientDUID.linkID, replyPacket->clientDUID.linkType, dhcp_ia_non_temporal_params->iaId, dhcp_ia_non_temporal_params->T0, dhcp_ia_non_temporal_params->T1, allocateNew);
93+
//Validate Client DUID
94+
dhcp_link_options_params_t clientDUID;
95+
if (libdhcpv6_get_link_address_from_duid(replyPacket->clientDUID.duid, replyPacket->clientDUID.duid_length, replyPacket->clientDUID.type, &clientDUID) == 0) {
96+
dhcp_allocated_address = libdhcpv6_address_allocated_list_scan(serverBase, clientDUID.link_id, clientDUID.link_type, dhcp_ia_non_temporal_params->iaId, dhcp_ia_non_temporal_params->T0, dhcp_ia_non_temporal_params->T1, allocateNew);
97+
}
9498
if (dhcp_allocated_address) {
9599
address_allocated = true;
96100
nonTemporalAddress.requestedAddress = dhcp_allocated_address->nonTemporalAddress;
@@ -110,7 +114,7 @@ int DHCPv6_server_respond_client(dhcpv6_gua_server_entry_s *serverBase, dhcpv6_r
110114
}
111115
}
112116

113-
response->responseLength = libdhcpv6_address_reply_message_len(replyPacket->clientDUID.linkType, replyPacket->serverDUID.linkType, 0, replyPacket->rapidCommit, address_allocated);
117+
response->responseLength = libdhcpv6_address_reply_message_len(replyPacket->clientDUID.duid_length, replyPacket->serverDUID.duid_length, 0, replyPacket->rapidCommit, address_allocated);
114118
response->responsePtr = ns_dyn_mem_temporary_alloc(response->responseLength);
115119
if (response->responsePtr) {
116120
if (address_allocated) {
@@ -141,16 +145,13 @@ int DHCPV6_server_service_request_handler(uint16_t instance_id, uint32_t msg_tr_
141145
if (serverBase) {
142146
//Here Allocate address
143147
replyPacket.rapidCommit = libdhcpv6_rapid_commit_option_at_packet(msg_ptr, msg_len);
144-
replyPacket.serverDUID.linkID = serverBase->serverDUID;
145-
replyPacket.serverDUID.linkType = serverBase->serverLinkType;
148+
replyPacket.serverDUID = serverBase->serverDUID;
146149
replyPacket.T0 = dhcp_ia_non_temporal_params.T0;
147150
replyPacket.T1 = dhcp_ia_non_temporal_params.T1;
148151
replyPacket.iaId = dhcp_ia_non_temporal_params.iaId;
149152
replyPacket.transaction_ID = msg_tr_id;
150153

151-
uint16_t duid_length = libdhcpv6_duid_option_size(replyPacket.clientDUID.linkType);
152-
duid_length -= 8;
153-
tr_debug("Response dhcp sol %s clientDUID", trace_array(replyPacket.clientDUID.linkID, duid_length));
154+
tr_debug("Response dhcp sol %s clientDUID", trace_array(replyPacket.clientDUID.duid, replyPacket.clientDUID.duid_length));
154155

155156
//Check First Current list
156157
if (DHCPv6_server_respond_client(serverBase, &replyPacket, &dhcp_ia_non_temporal_params, &responseBuf, true) == 0) {
@@ -173,10 +174,7 @@ int DHCPV6_server_service_request_handler(uint16_t instance_id, uint32_t msg_tr_
173174
// Discover SERVER
174175
serverBase = libdhcpv6_server_data_get_by_prefix_and_socketinstance(instance_id, dhcp_ia_non_temporal_params.nonTemporalAddress);
175176
if (serverBase) {
176-
dhcp_link_options_params_t serverInfoDui;
177-
serverInfoDui.linkID = serverBase->serverDUID;
178-
serverInfoDui.linkType = serverBase->serverLinkType;
179-
if (libdhcpv6_compare_DUID(&serverInfoDui, &replyPacket.serverDUID) == 0) {
177+
if (libdhcpv6_compare_DUID(&serverBase->serverDUID, &replyPacket.serverDUID) == 0) {
180178
replyPacket.rapidCommit = libdhcpv6_rapid_commit_option_at_packet(msg_ptr, msg_len);
181179
replyPacket.T0 = dhcp_ia_non_temporal_params.T0;
182180
replyPacket.T1 = dhcp_ia_non_temporal_params.T1;
@@ -339,6 +337,25 @@ void DHCPv6_server_service_callback_set(int8_t interface, uint8_t guaPrefix[stat
339337
serverInfo->removeCb = remove_cb;
340338
}
341339

340+
341+
int DHCPv6_server_service_duid_update(int8_t interface, uint8_t guaPrefix[static 16], uint8_t *duid_ptr, uint16_t duid_type, uint8_t duid_length)
342+
{
343+
344+
//Validate length and type
345+
if (!libdhcpv6_duid_length_validate(duid_type, duid_length)) {
346+
return -1;
347+
}
348+
349+
350+
dhcpv6_gua_server_entry_s *serverInfo = libdhcpv6_server_data_get_by_prefix_and_interfaceid(interface, guaPrefix);
351+
if (!serverInfo) {
352+
return -1;
353+
}
354+
355+
return libdhcpv6_server_duid_set(serverInfo, duid_ptr, duid_type, duid_length);
356+
}
357+
358+
342359
/* SET max accepted clients to server, Default is 200
343360
*
344361
*

source/DHCPv6_Server/DHCPv6_server_service.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int DHCPv6_server_service_init(int8_t interface, uint8_t guaPrefix[static 16], u
4545

4646
void DHCPv6_server_service_callback_set(int8_t interface, uint8_t guaPrefix[static 16], dhcp_address_prefer_remove_cb *remove_cb, dhcp_address_add_notify_cb *add_cb);
4747

48+
int DHCPv6_server_service_duid_update(int8_t interface, uint8_t guaPrefix[static 16], uint8_t *duid_ptr, uint16_t duid_type, uint8_t duid_length);
4849

4950
/* Delete dhcp thread dhcp router ID server.
5051
*

source/DHCPv6_client/dhcpv6_client_api.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
* if only one thread instance is supported this is needed to call only once.
3333
*
3434
* /param interface interface id of this instance.
35+
* /param link_type DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE, DHCPV6_DUID_HARDWARE_EUI64_TYPE or DHCPV6_DUID_HARDWARE_EUI48_TYPE
3536
*
3637
*/
37-
void dhcp_client_init(int8_t interface);
38+
void dhcp_client_init(int8_t interface, uint16_t link_type);
3839

3940
/* Set configurations for DHCP client
4041
*
@@ -72,15 +73,13 @@ void dhcp_client_delete(int8_t interface);
7273
* /param interface interface where address is got
7374
* /param dhcp_addr dhcp server ML16 address where address is registered.
7475
* /param prefix dhcp server ML16 address where address is registered.
75-
* /param mac64 64 bit mac address for identifieng client.
76-
* /param link_type Link hardware type.
7776
* /param error_cb error callback that is called if address cannot be created or becomes invalid.
7877
* /param register_status true if address registered.
7978
*
8079
*/
8180
typedef void (dhcp_client_global_adress_cb)(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16], bool register_status);
8281

83-
int dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16], uint8_t mac64[static 8], uint16_t link_type, dhcp_client_global_adress_cb *error_cb);
82+
int dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16], dhcp_client_global_adress_cb *error_cb);
8483

8584
/* Renew all leased adddresses might be used when short address changes
8685
*

0 commit comments

Comments
 (0)