From 81738bd8afe1e72d2119d121e4d0560f02d266b9 Mon Sep 17 00:00:00 2001 From: pvanhorn Date: Tue, 18 Oct 2016 13:56:50 -0700 Subject: [PATCH] Remove Netif name and rely on enumerated Interface Id's for netif. (#833) * Remove Netif name and rely on enumerated Interface Id's for netif. --- include/openthread-types.h | 8 ++++++++ src/cli/cli.cpp | 2 +- src/core/meshcop/joiner.cpp | 2 +- src/core/net/ip6.cpp | 26 ++------------------------ src/core/net/ip6.hpp | 11 ----------- src/core/net/netif.cpp | 4 ++-- src/core/net/netif.hpp | 13 +++---------- src/core/thread/thread_netif.cpp | 9 +-------- src/core/thread/thread_netif.hpp | 8 -------- 9 files changed, 18 insertions(+), 65 deletions(-) diff --git a/include/openthread-types.h b/include/openthread-types.h index 853039d8c..09950697b 100644 --- a/include/openthread-types.h +++ b/include/openthread-types.h @@ -843,6 +843,14 @@ typedef struct otNetifAddress struct otNetifAddress *mNext; ///< A pointer to the next network interface address. } otNetifAddress; +/** + * This enumeration represents the list of allowable values for an InterfaceId. + */ +typedef enum otNetifInterfaceId +{ + OT_NETIF_INTERFACE_ID_THREAD = 1, ///< The Thread Network interface ID. +} otNetifInterfaceId; + /** * This structure represents data used by Semantically Opaque IID Generator. * diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index aad3f9e05..2a84a207e 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1107,7 +1107,7 @@ void Interpreter::ProcessPing(int argc, char *argv[]) memset(&sMessageInfo, 0, sizeof(sMessageInfo)); SuccessOrExit(error = sMessageInfo.GetPeerAddr().FromString(argv[0])); - sMessageInfo.mInterfaceId = 1; + sMessageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD; sLength = 8; sCount = 1; diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index ca14590da..32986c15f 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -227,7 +227,7 @@ void Joiner::HandleUdpTransmit(void) messageInfo.GetPeerAddr().mFields.m16[0] = HostSwap16(0xfe80); messageInfo.GetPeerAddr().SetIid(mJoinerRouter); messageInfo.mPeerPort = mJoinerUdpPort; - messageInfo.mInterfaceId = 1; + messageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD; SuccessOrExit(error = mSocket.SendTo(*mTransmitMessage, messageInfo)); diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 2162b1a02..60d72998a 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -58,8 +58,7 @@ Ip6::Ip6(void): mReceiveIp6DatagramCallback(NULL), mReceiveIp6DatagramCallbackContext(NULL), mIsReceiveIp6FilterEnabled(false), - mNetifListHead(NULL), - mNextInterfaceId(1) + mNetifListHead(NULL) { } @@ -609,7 +608,7 @@ ThreadError Ip6::AddNetif(Netif &aNetif) do { - if (netif == &aNetif) + if (netif == &aNetif || netif->mInterfaceId == aNetif.mInterfaceId) { ExitNow(error = kThreadError_Already); } @@ -621,11 +620,6 @@ ThreadError Ip6::AddNetif(Netif &aNetif) aNetif.mNext = NULL; - if (aNetif.mInterfaceId < 0) - { - aNetif.mInterfaceId = mNextInterfaceId++; - } - exit: return error; } @@ -682,22 +676,6 @@ exit: return netif; } -Netif *Ip6::GetNetifByName(char *aName) -{ - Netif *netif; - - for (netif = mNetifListHead; netif; netif = netif->mNext) - { - if (strcmp(netif->GetName(), aName) == 0) - { - ExitNow(); - } - } - -exit: - return netif; -} - bool Ip6::IsUnicastAddress(const Address &aAddress) { bool rval = false; diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 521736431..d89cc3e79 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -282,16 +282,6 @@ public: */ Netif *GetNetifById(int8_t aInterfaceId); - /** - * This method returns the network interface identified by @p aName. - * - * @param[in] aName A pointer to a NULL-terminated string. - * - * @returns A pointer to the network interface or NULL if none is found. - * - */ - Netif *GetNetifByName(char *aName); - /** * This method indicates whether or not @p aAddress is assigned to a network interface. * @@ -363,7 +353,6 @@ private: bool mIsReceiveIp6FilterEnabled; Netif *mNetifListHead; - int8_t mNextInterfaceId; }; static inline Ip6 *Ip6FromTaskletScheduler(TaskletScheduler *aTaskletScheduler) diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index bca76470a..85831c86b 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -40,14 +40,14 @@ namespace Thread { namespace Ip6 { -Netif::Netif(Ip6 &aIp6): +Netif::Netif(Ip6 &aIp6, int8_t aInterfaceId): mIp6(aIp6), mStateChangedTask(aIp6.mTaskletScheduler, &Netif::HandleStateChangedTask, this) { mCallbacks = NULL; mUnicastAddresses = NULL; mMulticastAddresses = NULL; - mInterfaceId = -1; + mInterfaceId = aInterfaceId; mAllRoutersSubscribed = false; mNext = NULL; mMaskExtUnicastAddresses = 0; diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index 826161f00..e42d55a9a 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -233,10 +233,11 @@ public: /** * This constructor initializes the network interface. * - * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aIp6 A reference to the IPv6 network object. + * @param[in] aInterfaceId The interface ID for this object. * */ - Netif(Ip6 &aIp6); + Netif(Ip6 &aIp6, int8_t aInterfaceId); /** * This method returns a reference to the IPv6 network object. @@ -418,14 +419,6 @@ public: */ virtual ThreadError SendMessage(Message &aMessage) = 0; - /** - * This virtual method returns a NULL-terminated string that names the network interface. - * - * @returns A NULL-terminated string that names the network interface. - * - */ - virtual const char *GetName(void) const = 0; - /** * This virtual method fills out @p aAddress with the link address. * diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index bc9e7b99b..e8df010e7 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -53,10 +53,8 @@ static const uint8_t kThreadMasterKey[] = 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, }; -static const char name[] = "thread"; - ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6): - Netif(aIp6), + Netif(aIp6, OT_NETIF_INTERFACE_ID_THREAD), mCoapServer(aIp6.mUdp, kCoapUdpPort), mCoapClient(*this), mAddressResolver(*this), @@ -88,11 +86,6 @@ ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6): mKeyManager.SetMasterKey(kThreadMasterKey, sizeof(kThreadMasterKey)); } -const char *ThreadNetif::GetName(void) const -{ - return name; -} - ThreadError ThreadNetif::Up(void) { if (!mIsUp) diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 5c7d168ba..974d027cd 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -116,14 +116,6 @@ public: */ bool IsUp(void) const; - /** - * This method returns a pointer to a NULL-terminated string that names the interface. - * - * @returns A pointer to a NULL-terminated string that names the interface. - * - */ - const char *GetName(void) const; - /** * This method retrieves the link address. *