diff --git a/.travis/script.sh b/.travis/script.sh index 21beb6f1e..c531cffcf 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -63,13 +63,13 @@ python --version || die -DOPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE=1 \ -DOPENTHREAD_CONFIG_COAP_API_ENABLE=1 \ -DOPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE=1 \ - -DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1" + -DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1 \ + -DOPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE=1" scan-build ./configure \ --enable-builtin-mbedtls=no \ --enable-cert-log \ --enable-cli \ - --enable-dhcp6-client \ --enable-dhcp6-server \ --enable-diag \ --enable-dns-client \ @@ -98,7 +98,6 @@ python --version || die --enable-builtin-mbedtls=no \ --enable-cert-log \ --enable-cli \ - --enable-dhcp6-client \ --enable-dhcp6-server \ --enable-diag \ --enable-dns-client \ diff --git a/Android.mk b/Android.mk index f2b2ee1b1..6e3d72811 100644 --- a/Android.mk +++ b/Android.mk @@ -55,7 +55,7 @@ ifeq ($(TARGET_PRODUCT),generic) OPENTHREAD_COMMON_FLAGS += \ -DOPENTHREAD_CONFIG_COAP_API_ENABLE=1 \ -DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1 \ - -DOPENTHREAD_ENABLE_DHCP6_CLIENT=1 \ + -DOPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE=1 \ -DOPENTHREAD_ENABLE_DHCP6_SERVER=1 \ -DOPENTHREAD_ENABLE_DNS_CLIENT=1 \ -DOPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC=1 \ diff --git a/Makefile.am b/Makefile.am index b7ae8beed..701819953 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,6 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-address-sanitizer \ --enable-cert-log \ --enable-cli \ - --enable-dhcp6-client \ --enable-dhcp6-server \ --enable-diag \ --enable-dns-client \ diff --git a/configure.ac b/configure.ac index eab130ce9..81b4ad2b1 100644 --- a/configure.ac +++ b/configure.ac @@ -1143,36 +1143,6 @@ AC_SUBST(OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS) AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER],[${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}],[Define to 1 if using NCP Spinel Encrypter]) AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER], [test "${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}" = "1"]) -# -# DHCPv6 Client -# - -AC_ARG_ENABLE(dhcp6_client, - [AS_HELP_STRING([--enable-dhcp6-client],[Enable DHCPv6 client support @<:@default=no@:>@.])], - [ - case "${enableval}" in - - no|yes) - enable_dhcp6_client=${enableval} - ;; - - *) - AC_MSG_ERROR([Invalid value ${enable_dhcp6_client} for --enable-dhcp6-client]) - ;; - esac - ], - [enable_dhcp6_client=no]) - -if test "$enable_dhcp6_client" = "yes"; then - OPENTHREAD_ENABLE_DHCP6_CLIENT=1 -else - OPENTHREAD_ENABLE_DHCP6_CLIENT=0 -fi - -AC_SUBST(OPENTHREAD_ENABLE_DHCP6_CLIENT) -AM_CONDITIONAL([OPENTHREAD_ENABLE_DHCP6_CLIENT], [test "${enable_dhcp6_client}" = "yes"]) -AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_DHCP6_CLIENT],[${OPENTHREAD_ENABLE_DHCP6_CLIENT}],[Define to 1 if you want to enable DHCPv6 Client]) - # # DHCPv6 Server # @@ -1788,7 +1758,6 @@ AC_MSG_NOTICE([ OpenThread Factory Diagnostics support : ${enable_diag} OpenThread Legacy network support : ${enable_legacy} OpenThread DHCPv6 Server support : ${enable_dhcp6_server} - OpenThread DHCPv6 Client support : ${enable_dhcp6_client} OpenThread DNS Client support : ${enable_dns_client} OpenThread SNTP Client support : ${enable_sntp_client} OpenThread Raw Link-Layer support : ${enable_raw_link_api} diff --git a/examples/common-switches.mk b/examples/common-switches.mk index 1f47d72fb..24f61d7b0 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -107,7 +107,7 @@ configure_OPTIONS += --enable-debug --disable-optimization endif ifeq ($(DHCP6_CLIENT),1) -configure_OPTIONS += --enable-dhcp6-client +COMMONCFLAGS += -DOPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE=1 endif ifeq ($(DHCP6_SERVER),1) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 8b06a5918..f1f155cb7 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -325,6 +325,7 @@ HEADERS_COMMON = \ config/child_supervision.h \ config/coap.h \ config/commissioner.h \ + config/dhcp6_client.h \ config/openthread-core-config-check.h \ config/openthread-core-default-config.h \ crypto/aes_ccm.hpp \ diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index feb11ccda..6778c4951 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -598,7 +598,7 @@ template <> inline NetworkDiagnostic::NetworkDiagnostic &Instance::Get(void) } #endif -#if OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE template <> inline Dhcp6::Dhcp6Client &Instance::Get(void) { return mThreadNetif.mDhcp6Client; diff --git a/src/core/config/dhcp6_client.h b/src/core/config/dhcp6_client.h new file mode 100644 index 000000000..c80503422 --- /dev/null +++ b/src/core/config/dhcp6_client.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file includes compile-time configurations for DHCPv6 Client. + * + */ + +#ifndef CONFIG_DHCP6_CLIENT_H_ +#define CONFIG_DHCP6_CLIENT_H_ + +/** + * @def OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE + * + * Define to 1 to enable DHCPv6 Client support. + * + */ +#ifndef OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE +#define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_DHCP6_CLIENT_NUM_PREFIXES + * + * The number of dhcp prefixes. + * + */ +#ifndef OPENTHREAD_CONFIG_DHCP6_CLIENT_NUM_PREFIXES +#define OPENTHREAD_CONFIG_DHCP6_CLIENT_NUM_PREFIXES 4 +#endif + +#endif // CONFIG_DHCP6_CLIENT_H_ diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index 47f3e7749..151b5a8e6 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -43,7 +43,7 @@ #include "net/dhcp6.hpp" #include "thread/thread_netif.hpp" -#if OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE using ot::Encoding::BigEndian::HostSwap16; @@ -593,4 +593,4 @@ exit: } // namespace Dhcp6 } // namespace ot -#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT +#endif // OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE diff --git a/src/core/net/dhcp6_client.hpp b/src/core/net/dhcp6_client.hpp index c7fdfa951..7c7dca71f 100644 --- a/src/core/net/dhcp6_client.hpp +++ b/src/core/net/dhcp6_client.hpp @@ -157,7 +157,7 @@ private: uint8_t mTransactionId[kTransactionIdSize]; uint32_t mStartTime; - IdentityAssociation mIdentityAssociations[OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES]; + IdentityAssociation mIdentityAssociations[OPENTHREAD_CONFIG_DHCP6_CLIENT_NUM_PREFIXES]; IdentityAssociation *mIdentityAssociationCurrent; }; diff --git a/src/core/openthread-core-config.h b/src/core/openthread-core-config.h index 7d80c09ff..0fbf20653 100644 --- a/src/core/openthread-core-config.h +++ b/src/core/openthread-core-config.h @@ -51,6 +51,7 @@ #include "config/child_supervision.h" #include "config/coap.h" #include "config/commissioner.h" +#include "config/dhcp6_client.h" #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || \ OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || OPENTHREAD_ENABLE_JOINER diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 3682b5b58..f91f8be8d 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -396,7 +396,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header) SuccessOrExit(error = MeshCoP::GetBorderAgentRloc(Get(), mMeshDest)); } -#if OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE else if (aloc16 <= Mle::kAloc16DhcpAgentEnd) { uint16_t agentRloc16; @@ -419,7 +419,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header) } } -#endif // OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_ENABLE_DHCP6_CLIENT +#endif // OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE #if OPENTHREAD_ENABLE_SERVICE else if ((aloc16 >= Mle::kAloc16ServiceStart) && (aloc16 <= Mle::kAloc16ServiceEnd)) { diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 35e98f5ec..fc3b6cd1f 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1559,9 +1559,9 @@ void Mle::HandleStateChanged(otChangedFlags aFlags) Get().UpdateService(); #endif // OPENTHREAD_ENABLE_DHCP6_SERVER -#if OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE Get().UpdateAddresses(); -#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT +#endif // OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE } if (aFlags & (OT_CHANGED_THREAD_ROLE | OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER)) diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index b5fcd9bc0..fcf5dcade 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -163,7 +163,7 @@ exit: return error; } -#if OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE otError LeaderBase::GetRlocByContextId(uint8_t aContextId, uint16_t &aRloc16) { otError error = OT_ERROR_NOT_FOUND; @@ -188,7 +188,7 @@ otError LeaderBase::GetRlocByContextId(uint8_t aContextId, uint16_t &aRloc16) exit: return error; } -#endif // OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_ENABLE_DHCP6_CLIENT +#endif // OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE bool LeaderBase::IsOnMesh(const Ip6::Address &aAddress) { diff --git a/src/core/thread/network_data_leader.hpp b/src/core/thread/network_data_leader.hpp index 369e2b3e4..5eb3921d5 100644 --- a/src/core/thread/network_data_leader.hpp +++ b/src/core/thread/network_data_leader.hpp @@ -217,7 +217,7 @@ public: */ otError SetCommissioningData(const uint8_t *aValue, uint8_t aValueLength); -#if OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE /** * This method gets the Rloc of Dhcp Agent of specified contextId. * @@ -229,7 +229,7 @@ public: * */ otError GetRlocByContextId(uint8_t aContextId, uint16_t &aRloc16); -#endif // OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_ENABLE_DHCP6_CLIENT +#endif // OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE protected: uint8_t mStableVersion; diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index b2744c254..2ca6dd973 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -50,9 +50,9 @@ namespace ot { ThreadNetif::ThreadNetif(Instance &aInstance) : Netif(aInstance) , mCoap(aInstance) -#if OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE , mDhcp6Client(aInstance) -#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT +#endif // OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE #if OPENTHREAD_ENABLE_DHCP6_SERVER , mDhcp6Server(aInstance) #endif // OPENTHREAD_ENABLE_DHCP6_SERVER diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 5d94d0efc..8d3023cbc 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -164,9 +164,9 @@ private: static otError TmfFilter(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext); Coap::Coap mCoap; -#if OPENTHREAD_ENABLE_DHCP6_CLIENT +#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE Dhcp6::Dhcp6Client mDhcp6Client; -#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT +#endif // OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE #if OPENTHREAD_ENABLE_DHCP6_SERVER Dhcp6::Dhcp6Server mDhcp6Server; #endif // OPENTHREAD_ENABLE_DHCP6_SERVER