[posix] disable trel platform when empty/no trel interface name is given (#5971)

This commit changes the trel platform implementation under posix such
that if the interface name used for trel is empty, the platform layer
would disable trel. This is done by having all `otPlatTrel` functions
returning immediately without performing any action. This commit also
changes the `OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME` to be
empty string. This is the posix config option specifying the interface
name to be used by the trel platform layer. Note that the trel
interface name can be given using this build-time config, or through
the `-trel-interface` (or `-t`) input arg option. When the input arg
is not used, the interface name is determined from the build-time
config `POSIX_APP_TREL_INTERFACE_NAME`. This commit therefore makes
the default behavior when `-t` is not used to disable trel platform.
This commit is contained in:
Abtin Keshavarzian
2020-12-20 16:18:58 -08:00
committed by GitHub
parent 3b832ef470
commit 8ff8526061
4 changed files with 36 additions and 14 deletions
+2 -2
View File
@@ -50,11 +50,11 @@
/**
* @def OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME
*
* Defines the default interface name used for TREL UDP6 platform.
* Defines the default interface name used for TREL UDP6 platform. Empty string disables TREL platform.
*
*/
#ifndef OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME
#define OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME "trel"
#define OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME ""
#endif
/**
+26 -4
View File
@@ -71,6 +71,7 @@ static TxPacket sTxPacketPool[TREL_PACKET_POOL_SIZE];
static TxPacket * sFreeTxPacketHead; // A singly linked list of free/available `TxPacket` from pool.
static TxPacket * sTxPacketQueueTail; // A circular linked list for queued tx packets.
static char sInterfaceName[IFNAMSIZ + 1];
static bool sEnabled = false;
static int sInterfaceIndex = -1;
static int sMulticastSocket = -1;
static int sSocket = -1;
@@ -413,9 +414,13 @@ exit:
void otPlatTrelUdp6Init(otInstance *aInstance, const otIp6Address *aUnicastAddress, uint16_t aUdpPort)
{
OT_UNUSED_VARIABLE(aInstance);
int val;
struct sockaddr_in6 sockAddr;
VerifyOrExit(sEnabled);
otLogDebgPlat("[trel] otPlatTrelUdp6Init(%s, port:%d)", Ip6AddrToString(aUnicastAddress), aUdpPort);
sUdpPort = aUdpPort;
@@ -453,11 +458,16 @@ void otPlatTrelUdp6Init(otInstance *aInstance, const otIp6Address *aUnicastAddre
PrepareSocket();
OT_UNUSED_VARIABLE(aInstance);
exit:
return;
}
void otPlatTrelUdp6UpdateAddress(otInstance *aInstance, const otIp6Address *aUnicastAddress)
{
OT_UNUSED_VARIABLE(aInstance);
VerifyOrExit(sEnabled);
assert(sSocket >= 0);
otLogDebgPlat("[trel] otPlatTrelUdp6UpdateAddress(%s)", Ip6AddrToString(aUnicastAddress));
@@ -473,14 +483,16 @@ void otPlatTrelUdp6UpdateAddress(otInstance *aInstance, const otIp6Address *aUni
PrepareSocket();
exit:
OT_UNUSED_VARIABLE(aInstance);
return;
}
void otPlatTrelUdp6SubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aMulticastAddress)
{
OT_UNUSED_VARIABLE(aInstance);
struct ipv6_mreq mr;
OT_UNUSED_VARIABLE(aInstance);
VerifyOrExit(sEnabled);
assert(sMulticastSocket != -1);
@@ -489,6 +501,9 @@ void otPlatTrelUdp6SubscribeMulticastAddress(otInstance *aInstance, const otIp6A
VerifyOrDie(setsockopt(sMulticastSocket, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mr, sizeof(mr)) == 0, OT_EXIT_ERROR_ERRNO);
otLogDebgPlat("[trel] otPlatTrelUdp6SubscribeMulticastAddress(%s)", Ip6AddrToString(aMulticastAddress));
exit:
return;
}
otError otPlatTrelUdp6SendTo(otInstance * aInstance,
@@ -500,6 +515,8 @@ otError otPlatTrelUdp6SendTo(otInstance * aInstance,
otError error = OT_ERROR_NONE;
VerifyOrExit(sEnabled);
assert(aLength <= TREL_MAX_PACKET_SIZE);
otLogDebgPlat("[trel] otPlatTrelUdp6SendTo(%s) %s", Ip6AddrToString(aDestAddress),
@@ -524,6 +541,7 @@ otError otPlatTrelUdp6SendTo(otInstance * aInstance,
}
}
exit:
return error;
}
@@ -545,6 +563,9 @@ void platformTrelInit(const char *aInterfaceName)
otLogDebgPlat("[trel] platformTrelInit(InterfaceName:\"%s\")", sInterfaceName);
InitPacketQueue();
// Disable trel platform when interface name is empty.
sEnabled = (sInterfaceName[0] != '\0');
}
void platformTrelDeinit(void)
@@ -564,6 +585,8 @@ void platformTrelDeinit(void)
void platformTrelUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd, struct timeval *aTimeout)
{
OT_UNUSED_VARIABLE(aTimeout);
assert((aReadFdSet != NULL) && (aWriteFdSet != NULL) && (aMaxFd != NULL) && (aTimeout != NULL));
VerifyOrExit((sSocket >= 0) && (sMulticastSocket >= 0));
@@ -586,7 +609,6 @@ void platformTrelUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxF
}
exit:
OT_UNUSED_VARIABLE(aTimeout);
return;
}
@@ -53,6 +53,14 @@
*/
#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 1
/**
* @def OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME
*
* Defines the default interface name used for TREL UDP6 platform. Empty string disables TREL platform.
*
*/
#define OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME "trel"
/**
* @def OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
*
@@ -470,14 +470,6 @@
*/
#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 1
/**
* @def OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME
*
* Defines the default interface name used for TREL UDP6 platform.
*
*/
#define OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME "trel"
#if OPENTHREAD_RADIO
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE