mirror of
https://github.com/espressif/openthread.git
synced 2026-08-21 18:09:52 +00:00
[udp] bind to Thread interface by default (#6318)
Bind to Thread network by default so that UDP sockets in CLI can send multicast packets through Thread network interface.
This commit is contained in:
@@ -1666,8 +1666,7 @@ Error Coap::Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
|
||||
SuccessOrExit(error = mSocket.Open(&Coap::HandleUdpReceive, this));
|
||||
socketOpened = true;
|
||||
|
||||
SuccessOrExit(error = mSocket.BindToNetif(aNetifIdentifier));
|
||||
SuccessOrExit(error = mSocket.Bind(aPort));
|
||||
SuccessOrExit(error = mSocket.Bind(aPort, aNetifIdentifier));
|
||||
|
||||
exit:
|
||||
if (error != kErrorNone && socketOpened)
|
||||
|
||||
@@ -215,7 +215,7 @@ Error Dtls::Bind(uint16_t aPort)
|
||||
VerifyOrExit(mState == kStateOpen, error = kErrorInvalidState);
|
||||
VerifyOrExit(mTransportCallback == nullptr, error = kErrorAlready);
|
||||
|
||||
SuccessOrExit(error = mSocket.Bind(aPort));
|
||||
SuccessOrExit(error = mSocket.Bind(aPort, OT_NETIF_UNSPECIFIED));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -66,7 +66,7 @@ Error Server::Start(void)
|
||||
VerifyOrExit(!IsRunning());
|
||||
|
||||
SuccessOrExit(error = mSocket.Open(&Server::HandleUdpReceive, this));
|
||||
SuccessOrExit(error = mSocket.Bind(kPort));
|
||||
SuccessOrExit(error = mSocket.Bind(kPort, OT_NETIF_UNSPECIFIED));
|
||||
|
||||
exit:
|
||||
otLogInfoDns("[server] started: %s", ErrorToString(error));
|
||||
|
||||
@@ -424,7 +424,7 @@ void Server::Start(void)
|
||||
VerifyOrExit(!IsRunning());
|
||||
|
||||
SuccessOrExit(error = mSocket.Open(HandleUdpReceive, this));
|
||||
SuccessOrExit(error = mSocket.Bind(0));
|
||||
SuccessOrExit(error = mSocket.Bind(0, OT_NETIF_UNSPECIFIED));
|
||||
|
||||
SuccessOrExit(error = PublishServerData());
|
||||
|
||||
|
||||
+12
-22
@@ -87,17 +87,7 @@ Error Udp::Socket::Open(otUdpReceive aHandler, void *aContext)
|
||||
return Get<Udp>().Open(*this, aHandler, aContext);
|
||||
}
|
||||
|
||||
Error Udp::Socket::Bind(const SockAddr &aSockAddr)
|
||||
{
|
||||
return Get<Udp>().Bind(*this, aSockAddr);
|
||||
}
|
||||
|
||||
Error Udp::Socket::Bind(uint16_t aPort)
|
||||
{
|
||||
return Bind(SockAddr(aPort));
|
||||
}
|
||||
|
||||
Error Udp::Socket::BindToNetif(otNetifIdentifier aNetifIdentifier)
|
||||
Error Udp::Socket::Bind(const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aNetifIdentifier);
|
||||
|
||||
@@ -108,15 +98,23 @@ Error Udp::Socket::BindToNetif(otNetifIdentifier aNetifIdentifier)
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
Get<Udp>().BindToNetif(*this, aNetifIdentifier);
|
||||
if (aNetifIdentifier == OT_NETIF_BACKBONE)
|
||||
{
|
||||
Get<Udp>().SetBackboneSocket(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
|
||||
SuccessOrExit(error = Get<Udp>().Bind(*this, aSockAddr));
|
||||
|
||||
exit:
|
||||
#endif
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Udp::Socket::Bind(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
return Bind(SockAddr(aPort), aNetifIdentifier);
|
||||
}
|
||||
|
||||
Error Udp::Socket::Connect(const SockAddr &aSockAddr)
|
||||
{
|
||||
return Get<Udp>().Connect(*this, aSockAddr);
|
||||
@@ -253,14 +251,6 @@ exit:
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
void Udp::BindToNetif(SocketHandle &aSocket, otNetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
if (aNetifIdentifier == OT_NETIF_BACKBONE)
|
||||
{
|
||||
SetBackboneSocket(aSocket);
|
||||
}
|
||||
}
|
||||
|
||||
void Udp::SetBackboneSocket(SocketHandle &aSocket)
|
||||
{
|
||||
RemoveSocket(aSocket);
|
||||
|
||||
+6
-24
@@ -174,36 +174,27 @@ public:
|
||||
/**
|
||||
* This method binds the UDP socket.
|
||||
*
|
||||
* @param[in] aSockAddr A reference to the socket address.
|
||||
* @param[in] aSockAddr A reference to the socket address.
|
||||
* @param[in] aNetifIdentifier The network interface identifier.
|
||||
*
|
||||
* @retval kErrorNone Successfully bound the socket.
|
||||
* @retval kErrorInvalidArgs Unable to bind to Thread network interface with the given address.
|
||||
* @retval kErrorFailed Failed to bind UDP Socket.
|
||||
*
|
||||
*/
|
||||
Error Bind(const SockAddr &aSockAddr);
|
||||
|
||||
/**
|
||||
* This method binds the UDP socket to a specified network interface.
|
||||
*
|
||||
* @param[in] aNetifIdentifier The network interface identifier.
|
||||
*
|
||||
* @retval kErrorNone Successfully bound to the network interface.
|
||||
* @retval kErrorFailed Failed to bind to the network interface.
|
||||
*
|
||||
*/
|
||||
Error BindToNetif(otNetifIdentifier aNetifIdentifier);
|
||||
Error Bind(const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier = OT_NETIF_THREAD);
|
||||
|
||||
/**
|
||||
* This method binds the UDP socket.
|
||||
*
|
||||
* @param[in] aPort A port number.
|
||||
* @param[in] aPort A port number.
|
||||
* @param[in] aNetifIdentifier The network interface identifier.
|
||||
*
|
||||
* @retval kErrorNone Successfully bound the socket.
|
||||
* @retval kErrorFailed Failed to bind UDP Socket.
|
||||
*
|
||||
*/
|
||||
Error Bind(uint16_t aPort);
|
||||
Error Bind(uint16_t aPort, otNetifIdentifier aNetifIdentifier = OT_NETIF_THREAD);
|
||||
|
||||
/**
|
||||
* This method binds the UDP socket.
|
||||
@@ -468,15 +459,6 @@ public:
|
||||
*/
|
||||
Error Bind(SocketHandle &aSocket, const SockAddr &aSockAddr);
|
||||
|
||||
/**
|
||||
* This method binds a UDP socket to the Network interface.
|
||||
*
|
||||
* @param[in] aSocket A reference to the socket.
|
||||
* @param[in] aNetifIdentifier The network interface identifier.
|
||||
*
|
||||
*/
|
||||
void BindToNetif(SocketHandle &aSocket, otNetifIdentifier aNetifIdentifier);
|
||||
|
||||
/**
|
||||
* This method connects a UDP socket.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user