forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
11 changed files
with
271 additions
and
16 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
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
131 changes: 131 additions & 0 deletions
131
test/nanostack/unittest/stub/dhcpv6_server_service_stub.c
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,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 |
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