Skip to content

Commit

Permalink
Merge pull request ARMmbed#1869 from ARMmbed/dhcpv6_server_update
Browse files Browse the repository at this point in the history
DHCPv6 server update
  • Loading branch information
Juha Heiskanen authored Oct 23, 2018
2 parents ab1260a + 5e45c40 commit fc11a7a
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 175 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
21 changes: 15 additions & 6 deletions source/6LoWPAN/ws/ws_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "net_rpl.h"
#include "Service_Libs/nd_proxy/nd_proxy.h"
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"

#define TRACE_GROUP "wsbs"

Expand Down Expand Up @@ -237,22 +238,30 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
if (memcmp(global_dodag_id, ADDR_UNSPECIFIED,16) != 0) {
// TODO remove old global prefix
tr_info("RPL GUA deactivate %s", trace_ipv6(global_dodag_id));
addr_delete_matching(cur, global_dodag_id, 64, ADDR_SOURCE_SLAAC);

rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, 0, false);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, false);
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 7200, 0);
}
// TODO add global prefix
if (memcmp(global_id, ADDR_UNSPECIFIED,16) != 0) {
// TODO Add new prefix
tr_info("RPL GUA activate %s", trace_ipv6(global_id));
if_address_entry_t *add_entry = icmpv6_slaac_address_add(cur, global_id, 64, 0xffffffff, 0xffffffff, true, SLAAC_IID_OPAQUE);
if (!add_entry) {
//DHCPv6 Server set here
//Interface LL64 address
uint8_t ll[16];
memcpy(ll, ADDR_LINK_LOCAL_PREFIX, 8);
memcpy(&ll[8], cur->mac, 8);
ll[8] ^= 2;

if (DHCPv6_server_service_init(cur->id, global_id, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
tr_error("DHCPv6 Server create fail");
return;
}

rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, PIO_A, 0xffffffff, 0xffffffff, false);
DHCPv6_server_service_set_address_autonous_flag(cur->id, global_id, false);
tr_info("RPL GUA activate %s", trace_ipv6(global_id));
ws_dhcp_client_address_request(cur, global_id, ll);

rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 0xffffffff, 0xffffffff, false);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 0xffffffff, false);
ipv6_route_add_with_info(global_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 0xffffffff, 0);
}
Expand Down
Loading

0 comments on commit fc11a7a

Please sign in to comment.