From c25120edc06110ac9948d246f38905f44acd3367 Mon Sep 17 00:00:00 2001 From: Marius Preda Date: Tue, 28 Jan 2025 06:02:57 +0200 Subject: [PATCH] [cli] update default bind interface (#11187) This commit updates the default CLI bind interface to be consistent with the description. The default behavior should apply to all Thread nodes, not just devices that define UDP platform layer. For Thread nodes that only use the Open Thread Stack, netif type OT_NETIF_THREAD_HOST has no meaning. Support for OT_NETIF_THREAD_HOST has been kept using the -h option. Updated the CLI bind command readme to make it clear when the netif options are valid and what is the default behavior. Signed-off-by: Marius Preda --- src/cli/README_UDP.md | 7 ++++++- src/cli/cli_udp.cpp | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/cli/README_UDP.md b/src/cli/README_UDP.md index 7c365ee96..2d3c2ed09 100644 --- a/src/cli/README_UDP.md +++ b/src/cli/README_UDP.md @@ -68,12 +68,15 @@ Done Assigns a name (i.e. IPv6 address and port) to the example socket. - netif: the network interface to bind to. - - not specified: Thread network interface. + - not specified: Thread stack network interface. - `-u`: unspecified network interface. - `-b`: Backbone network interface. + - `-h`: Host Thread network interface. - ip: the unicast IPv6 address or the unspecified IPv6 address (`::`). - port: the UDP port +> Note: the netif parameter values (-u, -b, -h) are only valid if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE is set. + ```bash > udp bind :: 1234 Done @@ -81,6 +84,8 @@ Done Done > udp bind -b :: 1234 Done +> udp bind -h :: 1234 +Done ``` > Note: to receive datagrams sent to a multicast IPv6 address, the unspecified IPv6 address must be used. Using a multicast address for the \ argument is not supported. Also, the node must subscribe to the multicast group using `ipmaddr add` before it can receive UDP multicast. diff --git a/src/cli/cli_udp.cpp b/src/cli/cli_udp.cpp index aba4b2db6..4ae5b4133 100644 --- a/src/cli/cli_udp.cpp +++ b/src/cli/cli_udp.cpp @@ -64,12 +64,17 @@ UdpExample::UdpExample(otInstance *aInstance, OutputImplementer &aOutputImplemen * udp bind -b :: 1234 * Done * @endcode + * @code + * udp bind -h :: 1234 + * Done + * @endcode * @cparam udp bind [@ca{netif}] @ca{ip} @ca{port} * - `netif`: The binding network interface, which is determined as follows: - * - No value (leaving out this parameter from the command): Thread network interface is used. - * - `-u`: Unspecified network interface, which means that the UDP/IPv6 stack determines which - * network interface to bind the socket to. - * - `-b`: Backbone network interface is used. + * - No value (leaving out this parameter from the command): Thread stack network interface is used. + * - `-u`: Unspecified network interface, which means that the Host UDP/IPv6 stack determines which + * network interface to bind the socket to. Valid if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE is set. + * - `-b`: Backbone network interface is used. Valid if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE is set. + * - `-h`: Host Thread network interface is used. Valid if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE is set. * - `ip`: Unicast IPv6 address to bind to. If you wish to have the UDP/IPv6 stack assign the binding * IPv6 address, or if you wish to bind to multicast IPv6 addresses, then you can use the following * value to use the unspecified IPv6 address: `::`. Each example uses the unspecified IPv6 address. @@ -83,7 +88,7 @@ template <> otError UdpExample::Process(Arg aArgs[]) { otError error; otSockAddr sockaddr; - otNetifIdentifier netif = OT_NETIF_THREAD_HOST; + otNetifIdentifier netif = OT_NETIF_THREAD_INTERNAL; if (aArgs[0] == "-u") { @@ -95,6 +100,11 @@ template <> otError UdpExample::Process(Arg aArgs[]) netif = OT_NETIF_BACKBONE; aArgs++; } + else if (aArgs[0] == "-h") + { + netif = OT_NETIF_THREAD_HOST; + aArgs++; + } SuccessOrExit(error = aArgs[0].ParseAsIp6Address(sockaddr.mAddress)); SuccessOrExit(error = aArgs[1].ParseAsUint16(sockaddr.mPort));