Skip to content

Commit fc11a7a

Browse files
author
Juha Heiskanen
authored
Merge pull request ARMmbed#1869 from ARMmbed/dhcpv6_server_update
DHCPv6 server update
2 parents ab1260a + 5e45c40 commit fc11a7a

15 files changed

+345
-175
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: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
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 "DHCPv6_Server/DHCPv6_server_service.h"
3738

3839
#define TRACE_GROUP "wsbs"
3940

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

242242
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, 0, false);
243243
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, false);
244244
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 7200, 0);
245245
}
246246
// TODO add global prefix
247247
if (memcmp(global_id, ADDR_UNSPECIFIED,16) != 0) {
248-
// TODO Add new prefix
249-
tr_info("RPL GUA activate %s", trace_ipv6(global_id));
250-
if_address_entry_t *add_entry = icmpv6_slaac_address_add(cur, global_id, 64, 0xffffffff, 0xffffffff, true, SLAAC_IID_OPAQUE);
251-
if (!add_entry) {
248+
//DHCPv6 Server set here
249+
//Interface LL64 address
250+
uint8_t ll[16];
251+
memcpy(ll, ADDR_LINK_LOCAL_PREFIX, 8);
252+
memcpy(&ll[8], cur->mac, 8);
253+
ll[8] ^= 2;
254+
255+
if (DHCPv6_server_service_init(cur->id, global_id, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
256+
tr_error("DHCPv6 Server create fail");
252257
return;
253258
}
254259

255-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, PIO_A, 0xffffffff, 0xffffffff, false);
260+
DHCPv6_server_service_set_address_autonous_flag(cur->id, global_id, false);
261+
tr_info("RPL GUA activate %s", trace_ipv6(global_id));
262+
ws_dhcp_client_address_request(cur, global_id, ll);
263+
264+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 0xffffffff, 0xffffffff, false);
256265
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 0xffffffff, false);
257266
ipv6_route_add_with_info(global_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 0xffffffff, 0);
258267
}

0 commit comments

Comments
 (0)