Skip to content

Commit

Permalink
Thread dhcpv6 server update
Browse files Browse the repository at this point in the history
Created own function for dhcpv6 server init which register server
callback functions and timeout.

Change-Id: I56b4183874777ea294f96883f85ea155f47a9ce4
  • Loading branch information
Juha Heiskanen committed Oct 22, 2018
1 parent fe9ba3b commit 5e45c40
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 16 deletions.
7 changes: 4 additions & 3 deletions source/6LoWPAN/Thread/thread_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@
#include "thread_border_router_api.h"
#include "thread_bbr_api.h"
#include "net_ipv6_api.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "Common_Protocols/ipv6_constants.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"
#include "6LoWPAN/Thread/thread_dhcpv6_server.h"
#include "thread_management_if.h"
#include "6LoWPAN/Thread/thread_config.h"
#include "6LoWPAN/Thread/thread_constants.h"
#include "6LoWPAN/Thread/thread_common.h"
#include "6LoWPAN/Thread/thread_bootstrap.h"
#include "6LoWPAN/Thread/thread_joiner_application.h"
#include "6LoWPAN/Thread/thread_extension.h"
#include "6LoWPAN/Thread/thread_extension_bbr.h"
Expand Down Expand Up @@ -588,16 +591,14 @@ static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8],
// delete old prefix
memset(this->bbr_prefix,0,8);
// create new prefix
if (DHCPv6_server_service_init(this->interface_id, prefix, eui64, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
if (thread_dhcp6_server_init(this->interface_id, prefix, eui64, THREAD_MIN_PREFIX_LIFETIME) != 0) {
tr_warn("DHCP server alloc fail");
// set 20 seconds delay before next process
this->br_delay_timer = 20;
return;
}
memcpy(this->bbr_prefix,prefix,8);

DHCPv6_server_service_set_address_validlifetime(this->interface_id, this->bbr_prefix, THREAD_MIN_PREFIX_LIFETIME);

br_info.P_default_route = true;
br_info.P_dhcp = true;
br_info.P_on_mesh = true;
Expand Down
1 change: 0 additions & 1 deletion source/6LoWPAN/Thread/thread_bbr_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t tics);
*/
int thread_bbr_commissioner_proxy_service_update(int8_t interface_id);


#else
#define thread_bbr_init(interface_id, external_commisssioner_port)
#define thread_bbr_delete(interface_id)
Expand Down
1 change: 0 additions & 1 deletion source/6LoWPAN/Thread/thread_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ int thread_bootstrap_announce_send(protocol_interface_info_entry_t *cur, uint8_t
void thread_bootstrap_announcement_start(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint8_t count, uint16_t period);
void thread_bootstrap_temporary_attach(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint16_t panid, uint64_t timestamp);


#else
#define thread_interface_up(cur) ((void) 0)
#define thread_bootstrap_state_machine(cur) ((void)0)
Expand Down
100 changes: 100 additions & 0 deletions source/6LoWPAN/Thread/thread_dhcpv6_server.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2018, 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"
#if defined(HAVE_THREAD) && defined(HAVE_DHCPV6_SERVER)
#include <string.h>
#include <ns_types.h>
#include "eventOS_event.h"
#include "eventOS_event_timer.h"
#include "common_functions.h"
#include "ns_trace.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "ipv6_stack/protocol_ipv6.h"
#include "Common_Protocols/ipv6_constants.h"
#include "Common_Protocols/ipv6.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"

#define TRACE_GROUP "thds"

static void thread_service_remove_GUA_from_neighcache(protocol_interface_info_entry_t *cur, uint8_t *targetAddress)
{
ipv6_neighbour_t *neighbour_entry;

neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, targetAddress);
if (neighbour_entry) {
tr_debug("Remove from neigh Cache: %s", tr_ipv6(targetAddress));
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
}
}

static void thread_dhcp_address_prefer_remove_cb(int8_t interfaceId, uint8_t *targetAddress, void *prefix_info)
{
protocol_interface_info_entry_t *curPtr = protocol_stack_interface_info_get_by_id(interfaceId);
if (!curPtr) {
return;
}
if (!targetAddress) {
//Clear All targets routes
ipv6_route_table_remove_info(interfaceId, ROUTE_THREAD_PROXIED_HOST,prefix_info);
} else {
ipv6_route_delete(targetAddress, 128, interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST);
thread_service_remove_GUA_from_neighcache(curPtr, targetAddress);

}

}

static bool thread_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_update_t *address_info, void *route_src)
{
protocol_interface_info_entry_t *curPtr = protocol_stack_interface_info_get_by_id(interfaceId);
if (!curPtr) {
return false;
}

// If this is solicit from existing address, flush ND cache.
if (address_info->allocatedNewAddress) {
// coverity[returned_null] for ignoring protocol_stack_interface_info_get_by_id NULL return
thread_service_remove_GUA_from_neighcache(curPtr, address_info->allocatedAddress);
}

if (thread_bbr_nd_entry_add(interfaceId,address_info->allocatedAddress, address_info->validLifeTime, route_src) == -1) {
// No nanostack BBR present we will put entry for application implemented BBR
ipv6_route_t *route = ipv6_route_add_with_info(address_info->allocatedAddress, 128, interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST,route_src,0, address_info->validLifeTime, 0);
if (!route) {
return false;
}

}
return true;
}

int thread_dhcp6_server_init(int8_t interface_id, uint8_t prefix[8], uint8_t eui64[8], uint32_t validLifeTimne)
{
if (DHCPv6_server_service_init(interface_id, prefix, eui64, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
return -1;
}
//Register Callbacks
DHCPv6_server_service_callback_set(interface_id, prefix, thread_dhcp_address_prefer_remove_cb, thread_dhcp_address_add_cb);
//SET Timeout
DHCPv6_server_service_set_address_validlifetime(interface_id, prefix, validLifeTimne);

return 0;
}

#endif
27 changes: 27 additions & 0 deletions source/6LoWPAN/Thread/thread_dhcpv6_server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2018, 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 THREAD_DHCPV6_SERVER_H_
#define THREAD_DHCPV6_SERVER_H_
#if defined(HAVE_THREAD) && defined(HAVE_DHCPV6_SERVER)
int thread_dhcp6_server_init(int8_t interface_id, uint8_t prefix[8], uint8_t eui64[8], uint32_t validLifeTimne);
#else
#define thread_dhcp6_server_init(interface_id, prefix, eui64, validLifeTimne) (-1)
#endif


#endif /* THREAD_DHCPV6_SERVER_H_ */
11 changes: 3 additions & 8 deletions source/6LoWPAN/Thread/thread_management_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "6LoWPAN/Thread/thread_constants.h"
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
#include "6LoWPAN/Thread/thread_extension.h"
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
#include "RPL/rpl_control.h" // insanity - bootstraps shouldn't be doing each others' clean-up
#include "MLE/mle.h"
Expand All @@ -71,9 +72,8 @@
#include "thread_commissioning_if.h"
#include "shalib.h"
#include "Common_Protocols/icmpv6.h"
#include "libDHCPv6/libDHCPv6.h"
#include "libDHCPv6/libDHCPv6_server.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"
#include "6LoWPAN/Thread/thread_dhcpv6_server.h"
#include "Service_Libs/mle_service/mle_service_api.h"
#include "Service_Libs/blacklist/blacklist.h"
#include "6LoWPAN/MAC/mac_helper.h"
Expand Down Expand Up @@ -622,7 +622,7 @@ int thread_dhcpv6_server_add(int8_t interface_id, uint8_t *prefix_ptr, uint32_t
return -1;
}

if (DHCPv6_server_service_init(interface_id, prefix_ptr, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
if (thread_dhcp6_server_init(interface_id, prefix_ptr, cur->mac, THREAD_MIN_PREFIX_LIFETIME) != 0) {
tr_warn("SerVER alloc fail");
return -1;
}
Expand All @@ -637,14 +637,9 @@ int thread_dhcpv6_server_add(int8_t interface_id, uint8_t *prefix_ptr, uint32_t
service.P_on_mesh = true;
service.stableData = stableData;

//SET Timeout
DHCPv6_server_service_set_address_validlifetime(interface_id, prefix_ptr, THREAD_MIN_PREFIX_LIFETIME);

// SET maximum number of accepted clients
DHCPv6_server_service_set_max_clients_accepts_count(interface_id, prefix_ptr, max_client_cnt);

//Enable Mapping
//DHCPv6_server_service_set_gua_address_mapping(interface_id,prefix_ptr, true, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix);
tr_debug("GUA server Generate OK");
memcpy(ptr, prefix_ptr, 8);
memset(ptr + 8, 0, 8);
Expand Down
1 change: 0 additions & 1 deletion source/6LoWPAN/ws/ws_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "net_rpl.h"
#include "Service_Libs/nd_proxy/nd_proxy.h"
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
#include "libDHCPv6/libDHCPv6.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"

#define TRACE_GROUP "wsbs"
Expand Down
6 changes: 4 additions & 2 deletions source/DHCPv6_Server/DHCPv6_server_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#ifndef DHCPV6_SERVER_SERVICE_H_
#define DHCPV6_SERVER_SERVICE_H_

#ifdef HAVE_DHCPV6_SERVER
#include "libDHCPv6/libDHCPv6.h"
#include "libDHCPv6/libDHCPv6_server.h"

Expand Down Expand Up @@ -87,5 +87,7 @@ int DHCPv6_server_service_set_max_clients_accepts_count(int8_t interface, uint8_
* /param validLifeTimne in seconds
*/
int DHCPv6_server_service_set_address_validlifetime(int8_t interface, uint8_t guaPrefix[static 16], uint32_t validLifeTimne);

#else
#define DHCPv6_server_service_delete(interface, guaPrefix, delete_gua_addresses)
#endif
#endif /* DHCPV6_SERVER_SERVICE_H_ */
1 change: 1 addition & 0 deletions sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ SRCS += \
source/6LoWPAN/Thread/thread_management_client.c \
source/6LoWPAN/Thread/thread_network_synch.c \
source/6LoWPAN/Thread/thread_bootstrap.c \
source/6LoWPAN/Thread/thread_dhcpv6_server.c \
source/6LoWPAN/Thread/thread_host_bootstrap.c \
source/6LoWPAN/Thread/thread_router_bootstrap.c \
source/6LoWPAN/Thread/thread_discovery.c \
Expand Down
131 changes: 131 additions & 0 deletions test/nanostack/unittest/stub/dhcpv6_server_service_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2014-2018, 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.
*/

/*
* \file DHCPv6_Server_service.c
* \brief Add short description about this file!!!
*
*/
#include "nsconfig.h"
#ifdef HAVE_DHCPV6_SERVER
#include <string.h>
#include <ns_types.h>
#include <ns_trace.h>
#include "eventOS_event.h"
#include "eventOS_scheduler.h"
#include "eventOS_event_timer.h"
#include <nsdynmemLIB.h>
#include "libDHCPv6/libDHCPv6.h"
#include "libDHCPv6/libDHCPv6_server.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"
#include "common_functions.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "Common_Protocols/icmpv6.h"
#include "dhcp_service_api.h"

#define TRACE_GROUP "dhcp"

#define DHCPV6_GUA_IF "dhcp"
#define DHCPV6_SERVER_SERVICE_TASKLET_INIT 1
#define DHCPV6_SERVER_SERVICE_TIMER 2

#define DHCPV6_SERVER_SERVICE_TIMER_ID 1

#define DHCPV6_TIMER_UPDATE_PERIOD_IN_SECONDS 10

typedef struct dhcpv6_gua_response {
uint16_t responseLength;
uint8_t *responsePtr;
} dhcpv6_gua_response_t;



/* Initialize dhcp Global address server.
*
* This instance needs to bee initialized once for each thread network interface.
* if only one thread instance is supported this is needed to call only once.
*
* /param interface interface id of this thread instance.
* /param guaPrefix Global prefix /64
* /param serverDUID Server Device ID (64-bit MAC)
* /param serverDUIDType
*
*/
int DHCPv6_server_service_init(int8_t interface, uint8_t guaPrefix[static 16], uint8_t serverDUID[static 8], uint16_t serverDUIDType)
{
return 0;
}

void DHCPv6_server_service_timeout_cb(uint32_t timeUpdateInSeconds)
{

}

/* Delete dhcp thread dhcp router ID server.
*
* When this is called it close selected service and free all allocated memory.
*
* /param interface interface id of this thread instance.
* /param guaPrefix Prefix which will be removed
* /param delete_gua_addresses Whether or not assigned addresses with the prefix should be removed from the interface.
*/
void DHCPv6_server_service_delete(int8_t interface, uint8_t guaPrefix[static 16], bool delete_gua_addresses)
{

}

/* Control GUA address for client by DUI.Default value is true
*
*
* /param interface interface id of this thread instance.
* /param guaPrefix Prefix which will be removed
* /param mode true trig autonous mode, false define address by default suffics + client id
*/
int DHCPv6_server_service_set_address_autonous_flag(int8_t interface, uint8_t guaPrefix[static 16], bool mode)
{
return 0;
}

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)
{

}

/* SET max accepted clients to server, Default is 200
*
*
* /param interface interface id of this thread instance.
* /param guaPrefix Prefix which will be removed
* /param maxClientCount
*/
int DHCPv6_server_service_set_max_clients_accepts_count(int8_t interface, uint8_t guaPrefix[static 16], uint32_t maxClientCount)
{
return 0;
}

/** SET Address Valid Lifetime parameter for allocated address, Default is 7200 seconds
*
*
* /param interface interface id of this thread instance.
* /param guaPrefix Prefix which will be removed
* /param validLifeTimne in seconds
*/
int DHCPv6_server_service_set_address_validlifetime(int8_t interface, uint8_t guaPrefix[static 16], uint32_t validLifeTimne)
{
return 0;
}
#endif
1 change: 1 addition & 0 deletions test/nanostack/unittest/thread/thread_bootstrap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TEST_SRC_FILES = \
../../stub/thread_management_api_stub.c \
../../stub/event_stub.c \
../../stub/dhcpv6_client_stub.c \
../../stub/dhcpv6_server_service_stub.c \
../../stub/thread_border_router_api_stub.c \
../../stub/thread_border_router_api_internal_stub.c \
../../stub/thread_common_stub.c \
Expand Down

0 comments on commit 5e45c40

Please sign in to comment.