From bd8513b9046db4bf5216f6de0506e1342ed72172 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 30 Sep 2022 08:36:48 -0700 Subject: [PATCH] [ip6] define `Ip6::NetifIdentifier` mirroring `otNetifIdentifier` (#8219) --- src/core/api/udp_api.cpp | 2 +- src/core/backbone_router/backbone_tmf.cpp | 6 +++--- src/core/coap/coap.cpp | 2 +- src/core/coap/coap.hpp | 2 +- src/core/meshcop/dtls.cpp | 2 +- src/core/net/dns_client.cpp | 2 +- src/core/net/dnssd_server.cpp | 2 +- src/core/net/sntp_client.cpp | 2 +- src/core/net/srp_server.cpp | 2 +- src/core/net/udp6.cpp | 22 +++++++++++----------- src/core/net/udp6.hpp | 22 +++++++++++++++++----- src/core/thread/tmf.cpp | 2 +- 12 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/core/api/udp_api.cpp b/src/core/api/udp_api.cpp index 331e62b04..505458aa2 100644 --- a/src/core/api/udp_api.cpp +++ b/src/core/api/udp_api.cpp @@ -62,7 +62,7 @@ otError otUdpClose(otInstance *aInstance, otUdpSocket *aSocket) otError otUdpBind(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName, otNetifIdentifier aNetif) { - return AsCoreType(aInstance).Get().Bind(AsCoreType(aSocket), AsCoreType(aSockName), aNetif); + return AsCoreType(aInstance).Get().Bind(AsCoreType(aSocket), AsCoreType(aSockName), MapEnum(aNetif)); } otError otUdpConnect(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName) diff --git a/src/core/backbone_router/backbone_tmf.cpp b/src/core/backbone_router/backbone_tmf.cpp index 293793f04..4d2c9bf51 100644 --- a/src/core/backbone_router/backbone_tmf.cpp +++ b/src/core/backbone_router/backbone_tmf.cpp @@ -47,7 +47,7 @@ Error BackboneTmfAgent::Start(void) { Error error = kErrorNone; - SuccessOrExit(error = Coap::Start(kBackboneUdpPort, OT_NETIF_BACKBONE)); + SuccessOrExit(error = Coap::Start(kBackboneUdpPort, Ip6::kNetifBackbone)); SubscribeMulticast(Get().GetAllNetworkBackboneRoutersAddress()); exit: @@ -79,14 +79,14 @@ bool BackboneTmfAgent::IsBackboneTmfMessage(const Ip6::MessageInfo &aMessageInfo void BackboneTmfAgent::SubscribeMulticast(const Ip6::Address &aAddress) { - Error error = mSocket.JoinNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress); + Error error = mSocket.JoinNetifMulticastGroup(Ip6::kNetifBackbone, aAddress); LogError("Backbone TMF subscribes", aAddress, error); } void BackboneTmfAgent::UnsubscribeMulticast(const Ip6::Address &aAddress) { - Error error = mSocket.LeaveNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress); + Error error = mSocket.LeaveNetifMulticastGroup(Ip6::kNetifBackbone, aAddress); LogError("Backbone TMF unsubscribes", aAddress, error); } diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index f0b966daa..88f948236 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -1701,7 +1701,7 @@ Coap::Coap(Instance &aInstance) { } -Error Coap::Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier) +Error Coap::Start(uint16_t aPort, Ip6::NetifIdentifier aNetifIdentifier) { Error error = kErrorNone; bool socketOpened = false; diff --git a/src/core/coap/coap.hpp b/src/core/coap/coap.hpp index aea240eac..cfebb9d9b 100644 --- a/src/core/coap/coap.hpp +++ b/src/core/coap/coap.hpp @@ -906,7 +906,7 @@ public: * @retval kErrorFailed Failed to start CoAP agent. * */ - Error Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier = OT_NETIF_UNSPECIFIED); + Error Start(uint16_t aPort, Ip6::NetifIdentifier aNetifIdentifier = Ip6::kNetifUnspecified); /** * This method stops the CoAP service. diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index b1482ed31..f15beb9ea 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -226,7 +226,7 @@ Error Dtls::Bind(uint16_t aPort) VerifyOrExit(mState == kStateOpen, error = kErrorInvalidState); VerifyOrExit(mTransportCallback == nullptr, error = kErrorAlready); - SuccessOrExit(error = mSocket.Bind(aPort, OT_NETIF_UNSPECIFIED)); + SuccessOrExit(error = mSocket.Bind(aPort, Ip6::kNetifUnspecified)); exit: return error; diff --git a/src/core/net/dns_client.cpp b/src/core/net/dns_client.cpp index bb33d7072..2c687c622 100644 --- a/src/core/net/dns_client.cpp +++ b/src/core/net/dns_client.cpp @@ -554,7 +554,7 @@ Error Client::Start(void) Error error; SuccessOrExit(error = mSocket.Open(&Client::HandleUdpReceive, this)); - SuccessOrExit(error = mSocket.Bind(0, OT_NETIF_UNSPECIFIED)); + SuccessOrExit(error = mSocket.Bind(0, Ip6::kNetifUnspecified)); exit: return error; diff --git a/src/core/net/dnssd_server.cpp b/src/core/net/dnssd_server.cpp index 91550dcf2..5857ba67d 100644 --- a/src/core/net/dnssd_server.cpp +++ b/src/core/net/dnssd_server.cpp @@ -75,7 +75,7 @@ Error Server::Start(void) VerifyOrExit(!IsRunning()); SuccessOrExit(error = mSocket.Open(&Server::HandleUdpReceive, this)); - SuccessOrExit(error = mSocket.Bind(kPort, kBindUnspecifiedNetif ? OT_NETIF_UNSPECIFIED : OT_NETIF_THREAD)); + SuccessOrExit(error = mSocket.Bind(kPort, kBindUnspecifiedNetif ? Ip6::kNetifUnspecified : Ip6::kNetifThread)); #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE Get().HandleDnssdServerStateChange(); diff --git a/src/core/net/sntp_client.cpp b/src/core/net/sntp_client.cpp index b2e82f200..98f1fca73 100644 --- a/src/core/net/sntp_client.cpp +++ b/src/core/net/sntp_client.cpp @@ -105,7 +105,7 @@ Error Client::Start(void) Error error; SuccessOrExit(error = mSocket.Open(&Client::HandleUdpReceive, this)); - SuccessOrExit(error = mSocket.Bind(0, OT_NETIF_UNSPECIFIED)); + SuccessOrExit(error = mSocket.Bind(0, Ip6::kNetifUnspecified)); exit: return error; diff --git a/src/core/net/srp_server.cpp b/src/core/net/srp_server.cpp index 7c86fedbf..cd97a3078 100644 --- a/src/core/net/srp_server.cpp +++ b/src/core/net/srp_server.cpp @@ -598,7 +598,7 @@ void Server::PrepareSocket(void) VerifyOrExit(!mSocket.IsOpen()); SuccessOrExit(error = mSocket.Open(HandleUdpReceive, this)); - error = mSocket.Bind(mPort, OT_NETIF_THREAD); + error = mSocket.Bind(mPort, Ip6::kNetifThread); exit: if (error != kErrorNone) diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index 1dea10e05..988fa9b48 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -92,12 +92,12 @@ bool Udp::Socket::IsOpen(void) const return Get().IsOpen(*this); } -Error Udp::Socket::Bind(const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier) +Error Udp::Socket::Bind(const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier) { return Get().Bind(*this, aSockAddr, aNetifIdentifier); } -Error Udp::Socket::Bind(uint16_t aPort, otNetifIdentifier aNetifIdentifier) +Error Udp::Socket::Bind(uint16_t aPort, NetifIdentifier aNetifIdentifier) { return Bind(SockAddr(aPort), aNetifIdentifier); } @@ -123,7 +123,7 @@ Error Udp::Socket::SendTo(Message &aMessage, const MessageInfo &aMessageInfo) } #if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE -Error Udp::Socket::JoinNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress) +Error Udp::Socket::JoinNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress) { OT_UNUSED_VARIABLE(aNetifIdentifier); OT_UNUSED_VARIABLE(aAddress); @@ -133,14 +133,14 @@ Error Udp::Socket::JoinNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, c VerifyOrExit(aAddress.IsMulticast(), error = kErrorInvalidArgs); #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - error = otPlatUdpJoinMulticastGroup(this, aNetifIdentifier, &aAddress); + error = otPlatUdpJoinMulticastGroup(this, MapEnum(aNetifIdentifier), &aAddress); #endif exit: return error; } -Error Udp::Socket::LeaveNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress) +Error Udp::Socket::LeaveNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress) { OT_UNUSED_VARIABLE(aNetifIdentifier); OT_UNUSED_VARIABLE(aAddress); @@ -150,7 +150,7 @@ Error Udp::Socket::LeaveNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, VerifyOrExit(aAddress.IsMulticast(), error = kErrorInvalidArgs); #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - error = otPlatUdpLeaveMulticastGroup(this, aNetifIdentifier, &aAddress); + error = otPlatUdpLeaveMulticastGroup(this, MapEnum(aNetifIdentifier), &aAddress); #endif exit: @@ -209,18 +209,18 @@ exit: return error; } -Error Udp::Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier) +Error Udp::Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier) { OT_UNUSED_VARIABLE(aNetifIdentifier); Error error = kErrorNone; #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - SuccessOrExit(error = otPlatUdpBindToNetif(&aSocket, aNetifIdentifier)); + SuccessOrExit(error = otPlatUdpBindToNetif(&aSocket, MapEnum(aNetifIdentifier))); #endif #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE - if (aNetifIdentifier == OT_NETIF_BACKBONE) + if (aNetifIdentifier == kNetifBackbone) { SetBackboneSocket(aSocket); } @@ -297,7 +297,7 @@ Error Udp::Connect(SocketHandle &aSocket, const SockAddr &aSockAddr) if (!aSocket.IsBound()) { - SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), OT_NETIF_THREAD)); + SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), kNetifThread)); } #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE @@ -360,7 +360,7 @@ Error Udp::SendTo(SocketHandle &aSocket, Message &aMessage, const MessageInfo &a if (!aSocket.IsBound()) { - SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), OT_NETIF_THREAD)); + SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), kNetifThread)); } messageInfoLocal.SetSockPort(aSocket.GetSockName().mPort); diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index 6471c4bdf..0ddb60cc1 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -65,6 +65,17 @@ class Udp; #error "OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE and OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE must not both be set." #endif +/** + * This enumeration defines the network interface identifiers. + * + */ +enum NetifIdentifier : uint8_t +{ + kNetifUnspecified = OT_NETIF_UNSPECIFIED, ///< Unspecified network interface. + kNetifThread = OT_NETIF_THREAD, ///< The Thread interface. + kNetifBackbone = OT_NETIF_BACKBONE, ///< The Backbone interface. +}; + /** * This class implements core UDP message handling. * @@ -191,7 +202,7 @@ public: * @retval kErrorFailed Failed to bind UDP Socket. * */ - Error Bind(const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier = OT_NETIF_THREAD); + Error Bind(const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier = kNetifThread); /** * This method binds the UDP socket. @@ -203,7 +214,7 @@ public: * @retval kErrorFailed Failed to bind UDP Socket. * */ - Error Bind(uint16_t aPort, otNetifIdentifier aNetifIdentifier = OT_NETIF_THREAD); + Error Bind(uint16_t aPort, NetifIdentifier aNetifIdentifier = kNetifThread); /** * This method binds the UDP socket. @@ -278,7 +289,7 @@ public: * @retval kErrorFailed Failed to join the multicast group. * */ - Error JoinNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress); + Error JoinNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress); /** * This method configures the UDP socket to leave a multicast group on a Host network interface. @@ -290,7 +301,7 @@ public: * @retval kErrorFailed Failed to leave the multicast group. * */ - Error LeaveNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress); + Error LeaveNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress); #endif }; @@ -474,7 +485,7 @@ public: * @retval kErrorFailed Failed to bind UDP Socket. * */ - Error Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier); + Error Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier); /** * This method connects a UDP socket. @@ -655,6 +666,7 @@ private: DefineCoreType(otUdpSocket, Ip6::Udp::SocketHandle); DefineCoreType(otUdpReceiver, Ip6::Udp::Receiver); +DefineMapEnum(otNetifIdentifier, Ip6::NetifIdentifier); } // namespace ot diff --git a/src/core/thread/tmf.cpp b/src/core/thread/tmf.cpp index 24a4ae9a8..05e7f015d 100644 --- a/src/core/thread/tmf.cpp +++ b/src/core/thread/tmf.cpp @@ -82,7 +82,7 @@ void MessageInfo::SetSockAddrToRlocPeerAddrTo(const Ip6::Address &aPeerAddress) Error Agent::Start(void) { - return Coap::Start(kUdpPort, OT_NETIF_THREAD); + return Coap::Start(kUdpPort, Ip6::kNetifThread); } Error Agent::Filter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)