Skip to content

Commit 5e45c40

Browse files
author
Juha Heiskanen
committed
Thread dhcpv6 server update
Created own function for dhcpv6 server init which register server callback functions and timeout. Change-Id: I56b4183874777ea294f96883f85ea155f47a9ce4
1 parent fe9ba3b commit 5e45c40

File tree

11 files changed

+271
-16
lines changed

11 files changed

+271
-16
lines changed

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@
4141
#include "thread_border_router_api.h"
4242
#include "thread_bbr_api.h"
4343
#include "net_ipv6_api.h"
44+
#include "NWK_INTERFACE/Include/protocol.h"
4445
#include "Common_Protocols/ipv6_constants.h"
4546
#include "DHCPv6_Server/DHCPv6_server_service.h"
47+
#include "6LoWPAN/Thread/thread_dhcpv6_server.h"
4648
#include "thread_management_if.h"
4749
#include "6LoWPAN/Thread/thread_config.h"
4850
#include "6LoWPAN/Thread/thread_constants.h"
4951
#include "6LoWPAN/Thread/thread_common.h"
52+
#include "6LoWPAN/Thread/thread_bootstrap.h"
5053
#include "6LoWPAN/Thread/thread_joiner_application.h"
5154
#include "6LoWPAN/Thread/thread_extension.h"
5255
#include "6LoWPAN/Thread/thread_extension_bbr.h"
@@ -588,16 +591,14 @@ static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8],
588591
// delete old prefix
589592
memset(this->bbr_prefix,0,8);
590593
// create new prefix
591-
if (DHCPv6_server_service_init(this->interface_id, prefix, eui64, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
594+
if (thread_dhcp6_server_init(this->interface_id, prefix, eui64, THREAD_MIN_PREFIX_LIFETIME) != 0) {
592595
tr_warn("DHCP server alloc fail");
593596
// set 20 seconds delay before next process
594597
this->br_delay_timer = 20;
595598
return;
596599
}
597600
memcpy(this->bbr_prefix,prefix,8);
598601

599-
DHCPv6_server_service_set_address_validlifetime(this->interface_id, this->bbr_prefix, THREAD_MIN_PREFIX_LIFETIME);
600-
601602
br_info.P_default_route = true;
602603
br_info.P_dhcp = true;
603604
br_info.P_on_mesh = true;

source/6LoWPAN/Thread/thread_bbr_api_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t tics);
6767
*/
6868
int thread_bbr_commissioner_proxy_service_update(int8_t interface_id);
6969

70-
7170
#else
7271
#define thread_bbr_init(interface_id, external_commisssioner_port)
7372
#define thread_bbr_delete(interface_id)

source/6LoWPAN/Thread/thread_bootstrap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ int thread_bootstrap_announce_send(protocol_interface_info_entry_t *cur, uint8_t
194194
void thread_bootstrap_announcement_start(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint8_t count, uint16_t period);
195195
void thread_bootstrap_temporary_attach(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint16_t panid, uint64_t timestamp);
196196

197-
198197
#else
199198
#define thread_interface_up(cur) ((void) 0)
200199
#define thread_bootstrap_state_machine(cur) ((void)0)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "nsconfig.h"
19+
#if defined(HAVE_THREAD) && defined(HAVE_DHCPV6_SERVER)
20+
#include <string.h>
21+
#include <ns_types.h>
22+
#include "eventOS_event.h"
23+
#include "eventOS_event_timer.h"
24+
#include "common_functions.h"
25+
#include "ns_trace.h"
26+
#include "NWK_INTERFACE/Include/protocol.h"
27+
#include "ipv6_stack/protocol_ipv6.h"
28+
#include "Common_Protocols/ipv6_constants.h"
29+
#include "Common_Protocols/ipv6.h"
30+
#include "DHCPv6_Server/DHCPv6_server_service.h"
31+
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
32+
33+
#define TRACE_GROUP "thds"
34+
35+
static void thread_service_remove_GUA_from_neighcache(protocol_interface_info_entry_t *cur, uint8_t *targetAddress)
36+
{
37+
ipv6_neighbour_t *neighbour_entry;
38+
39+
neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, targetAddress);
40+
if (neighbour_entry) {
41+
tr_debug("Remove from neigh Cache: %s", tr_ipv6(targetAddress));
42+
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
43+
}
44+
}
45+
46+
static void thread_dhcp_address_prefer_remove_cb(int8_t interfaceId, uint8_t *targetAddress, void *prefix_info)
47+
{
48+
protocol_interface_info_entry_t *curPtr = protocol_stack_interface_info_get_by_id(interfaceId);
49+
if (!curPtr) {
50+
return;
51+
}
52+
if (!targetAddress) {
53+
//Clear All targets routes
54+
ipv6_route_table_remove_info(interfaceId, ROUTE_THREAD_PROXIED_HOST,prefix_info);
55+
} else {
56+
ipv6_route_delete(targetAddress, 128, interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST);
57+
thread_service_remove_GUA_from_neighcache(curPtr, targetAddress);
58+
59+
}
60+
61+
}
62+
63+
static bool thread_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_update_t *address_info, void *route_src)
64+
{
65+
protocol_interface_info_entry_t *curPtr = protocol_stack_interface_info_get_by_id(interfaceId);
66+
if (!curPtr) {
67+
return false;
68+
}
69+
70+
// If this is solicit from existing address, flush ND cache.
71+
if (address_info->allocatedNewAddress) {
72+
// coverity[returned_null] for ignoring protocol_stack_interface_info_get_by_id NULL return
73+
thread_service_remove_GUA_from_neighcache(curPtr, address_info->allocatedAddress);
74+
}
75+
76+
if (thread_bbr_nd_entry_add(interfaceId,address_info->allocatedAddress, address_info->validLifeTime, route_src) == -1) {
77+
// No nanostack BBR present we will put entry for application implemented BBR
78+
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);
79+
if (!route) {
80+
return false;
81+
}
82+
83+
}
84+
return true;
85+
}
86+
87+
int thread_dhcp6_server_init(int8_t interface_id, uint8_t prefix[8], uint8_t eui64[8], uint32_t validLifeTimne)
88+
{
89+
if (DHCPv6_server_service_init(interface_id, prefix, eui64, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
90+
return -1;
91+
}
92+
//Register Callbacks
93+
DHCPv6_server_service_callback_set(interface_id, prefix, thread_dhcp_address_prefer_remove_cb, thread_dhcp_address_add_cb);
94+
//SET Timeout
95+
DHCPv6_server_service_set_address_validlifetime(interface_id, prefix, validLifeTimne);
96+
97+
return 0;
98+
}
99+
100+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef THREAD_DHCPV6_SERVER_H_
19+
#define THREAD_DHCPV6_SERVER_H_
20+
#if defined(HAVE_THREAD) && defined(HAVE_DHCPV6_SERVER)
21+
int thread_dhcp6_server_init(int8_t interface_id, uint8_t prefix[8], uint8_t eui64[8], uint32_t validLifeTimne);
22+
#else
23+
#define thread_dhcp6_server_init(interface_id, prefix, eui64, validLifeTimne) (-1)
24+
#endif
25+
26+
27+
#endif /* THREAD_DHCPV6_SERVER_H_ */

source/6LoWPAN/Thread/thread_management_if.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "6LoWPAN/Thread/thread_constants.h"
6464
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
6565
#include "6LoWPAN/Thread/thread_extension.h"
66+
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
6667
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
6768
#include "RPL/rpl_control.h" // insanity - bootstraps shouldn't be doing each others' clean-up
6869
#include "MLE/mle.h"
@@ -71,9 +72,8 @@
7172
#include "thread_commissioning_if.h"
7273
#include "shalib.h"
7374
#include "Common_Protocols/icmpv6.h"
74-
#include "libDHCPv6/libDHCPv6.h"
75-
#include "libDHCPv6/libDHCPv6_server.h"
7675
#include "DHCPv6_Server/DHCPv6_server_service.h"
76+
#include "6LoWPAN/Thread/thread_dhcpv6_server.h"
7777
#include "Service_Libs/mle_service/mle_service_api.h"
7878
#include "Service_Libs/blacklist/blacklist.h"
7979
#include "6LoWPAN/MAC/mac_helper.h"
@@ -622,7 +622,7 @@ int thread_dhcpv6_server_add(int8_t interface_id, uint8_t *prefix_ptr, uint32_t
622622
return -1;
623623
}
624624

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

640-
//SET Timeout
641-
DHCPv6_server_service_set_address_validlifetime(interface_id, prefix_ptr, THREAD_MIN_PREFIX_LIFETIME);
642-
643640
// SET maximum number of accepted clients
644641
DHCPv6_server_service_set_max_clients_accepts_count(interface_id, prefix_ptr, max_client_cnt);
645642

646-
//Enable Mapping
647-
//DHCPv6_server_service_set_gua_address_mapping(interface_id,prefix_ptr, true, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix);
648643
tr_debug("GUA server Generate OK");
649644
memcpy(ptr, prefix_ptr, 8);
650645
memset(ptr + 8, 0, 8);

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "net_rpl.h"
3535
#include "Service_Libs/nd_proxy/nd_proxy.h"
3636
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
37-
#include "libDHCPv6/libDHCPv6.h"
3837
#include "DHCPv6_Server/DHCPv6_server_service.h"
3938

4039
#define TRACE_GROUP "wsbs"

source/DHCPv6_Server/DHCPv6_server_service.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#ifndef DHCPV6_SERVER_SERVICE_H_
2525
#define DHCPV6_SERVER_SERVICE_H_
26-
26+
#ifdef HAVE_DHCPV6_SERVER
2727
#include "libDHCPv6/libDHCPv6.h"
2828
#include "libDHCPv6/libDHCPv6_server.h"
2929

@@ -87,5 +87,7 @@ int DHCPv6_server_service_set_max_clients_accepts_count(int8_t interface, uint8_
8787
* /param validLifeTimne in seconds
8888
*/
8989
int DHCPv6_server_service_set_address_validlifetime(int8_t interface, uint8_t guaPrefix[static 16], uint32_t validLifeTimne);
90-
90+
#else
91+
#define DHCPv6_server_service_delete(interface, guaPrefix, delete_gua_addresses)
92+
#endif
9193
#endif /* DHCPV6_SERVER_SERVICE_H_ */

sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ SRCS += \
137137
source/6LoWPAN/Thread/thread_management_client.c \
138138
source/6LoWPAN/Thread/thread_network_synch.c \
139139
source/6LoWPAN/Thread/thread_bootstrap.c \
140+
source/6LoWPAN/Thread/thread_dhcpv6_server.c \
140141
source/6LoWPAN/Thread/thread_host_bootstrap.c \
141142
source/6LoWPAN/Thread/thread_router_bootstrap.c \
142143
source/6LoWPAN/Thread/thread_discovery.c \
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2014-2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* \file DHCPv6_Server_service.c
20+
* \brief Add short description about this file!!!
21+
*
22+
*/
23+
#include "nsconfig.h"
24+
#ifdef HAVE_DHCPV6_SERVER
25+
#include <string.h>
26+
#include <ns_types.h>
27+
#include <ns_trace.h>
28+
#include "eventOS_event.h"
29+
#include "eventOS_scheduler.h"
30+
#include "eventOS_event_timer.h"
31+
#include <nsdynmemLIB.h>
32+
#include "libDHCPv6/libDHCPv6.h"
33+
#include "libDHCPv6/libDHCPv6_server.h"
34+
#include "DHCPv6_Server/DHCPv6_server_service.h"
35+
#include "common_functions.h"
36+
#include "NWK_INTERFACE/Include/protocol.h"
37+
#include "Common_Protocols/icmpv6.h"
38+
#include "dhcp_service_api.h"
39+
40+
#define TRACE_GROUP "dhcp"
41+
42+
#define DHCPV6_GUA_IF "dhcp"
43+
#define DHCPV6_SERVER_SERVICE_TASKLET_INIT 1
44+
#define DHCPV6_SERVER_SERVICE_TIMER 2
45+
46+
#define DHCPV6_SERVER_SERVICE_TIMER_ID 1
47+
48+
#define DHCPV6_TIMER_UPDATE_PERIOD_IN_SECONDS 10
49+
50+
typedef struct dhcpv6_gua_response {
51+
uint16_t responseLength;
52+
uint8_t *responsePtr;
53+
} dhcpv6_gua_response_t;
54+
55+
56+
57+
/* Initialize dhcp Global address server.
58+
*
59+
* This instance needs to bee initialized once for each thread network interface.
60+
* if only one thread instance is supported this is needed to call only once.
61+
*
62+
* /param interface interface id of this thread instance.
63+
* /param guaPrefix Global prefix /64
64+
* /param serverDUID Server Device ID (64-bit MAC)
65+
* /param serverDUIDType
66+
*
67+
*/
68+
int DHCPv6_server_service_init(int8_t interface, uint8_t guaPrefix[static 16], uint8_t serverDUID[static 8], uint16_t serverDUIDType)
69+
{
70+
return 0;
71+
}
72+
73+
void DHCPv6_server_service_timeout_cb(uint32_t timeUpdateInSeconds)
74+
{
75+
76+
}
77+
78+
/* Delete dhcp thread dhcp router ID server.
79+
*
80+
* When this is called it close selected service and free all allocated memory.
81+
*
82+
* /param interface interface id of this thread instance.
83+
* /param guaPrefix Prefix which will be removed
84+
* /param delete_gua_addresses Whether or not assigned addresses with the prefix should be removed from the interface.
85+
*/
86+
void DHCPv6_server_service_delete(int8_t interface, uint8_t guaPrefix[static 16], bool delete_gua_addresses)
87+
{
88+
89+
}
90+
91+
/* Control GUA address for client by DUI.Default value is true
92+
*
93+
*
94+
* /param interface interface id of this thread instance.
95+
* /param guaPrefix Prefix which will be removed
96+
* /param mode true trig autonous mode, false define address by default suffics + client id
97+
*/
98+
int DHCPv6_server_service_set_address_autonous_flag(int8_t interface, uint8_t guaPrefix[static 16], bool mode)
99+
{
100+
return 0;
101+
}
102+
103+
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)
104+
{
105+
106+
}
107+
108+
/* SET max accepted clients to server, Default is 200
109+
*
110+
*
111+
* /param interface interface id of this thread instance.
112+
* /param guaPrefix Prefix which will be removed
113+
* /param maxClientCount
114+
*/
115+
int DHCPv6_server_service_set_max_clients_accepts_count(int8_t interface, uint8_t guaPrefix[static 16], uint32_t maxClientCount)
116+
{
117+
return 0;
118+
}
119+
120+
/** SET Address Valid Lifetime parameter for allocated address, Default is 7200 seconds
121+
*
122+
*
123+
* /param interface interface id of this thread instance.
124+
* /param guaPrefix Prefix which will be removed
125+
* /param validLifeTimne in seconds
126+
*/
127+
int DHCPv6_server_service_set_address_validlifetime(int8_t interface, uint8_t guaPrefix[static 16], uint32_t validLifeTimne)
128+
{
129+
return 0;
130+
}
131+
#endif

test/nanostack/unittest/thread/thread_bootstrap/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ TEST_SRC_FILES = \
3030
../../stub/thread_management_api_stub.c \
3131
../../stub/event_stub.c \
3232
../../stub/dhcpv6_client_stub.c \
33+
../../stub/dhcpv6_server_service_stub.c \
3334
../../stub/thread_border_router_api_stub.c \
3435
../../stub/thread_border_router_api_internal_stub.c \
3536
../../stub/thread_common_stub.c \

0 commit comments

Comments
 (0)