forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ARMmbed#1869 from ARMmbed/dhcpv6_server_update
DHCPv6 server update
- Loading branch information
Showing
15 changed files
with
345 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.