[trel] check simulated socket port in simulation trel platform (#13906)

In `examples/platforms/simulation/trel.c`, `sSockAddr` tracks the
simulated node's TREL IPv6 socket address and port, which can be
updated at runtime by `treltest changesockaddr` and `treltest
changesockport`. However, `processMessage()` checked incoming
`TREL_DATA_MESSAGE` destination ports against the initial
`sSocket.mPort` instead of `sSockAddr.mPort`.

After `treltest changesockport` changed a node's simulated TREL port
in `test-706-multi-radio-trel-peer-addr-port-change-discovery.py`:
- The node continued accepting TREL broadcast packets sent by peers
  to its old port and replied with TREL ACKs from its new port. On
  receiving the unauthenticated TREL ACK, the peer incremented
  `sNotifyAddressDiffCounter` without updating the peer's recorded
  socket address, and then incremented it a second time upon
  receiving the node's next MLE Advertisement, causing `verify()` at
  line 152 to fail (`3 != 2`).
- Once peers updated the node's TREL port to the new port, the node
  dropped all subsequent TREL packets sent to its new port.

This commit updates `processMessage()` and `otPlatTrelEnable()` in
simulation `trel.c` to use `sSockAddr.mPort`.
This commit is contained in:
Jonathan Hui
2026-11-10 08:05:40 -08:00
committed by GitHub
parent 28fbf384e7
commit d743255d1c
+2 -2
View File
@@ -187,7 +187,7 @@ static void processMessage(otInstance *aInstance, Message *aMessage, uint16_t aL
switch (aMessage->mType)
{
case TREL_DATA_MESSAGE:
otEXPECT(aMessage->mSockAddr.mPort == sSocket.mPort);
otEXPECT(aMessage->mSockAddr.mPort == sSockAddr.mPort);
otEXPECT(otIp6IsAddressEqual(&aMessage->mSockAddr.mAddress, &sSockAddr.mAddress));
otPlatTrelHandleReceived(aInstance, aMessage->mData, aMessage->mDataLength, &aMessage->mSourceAddr);
break;
@@ -218,7 +218,7 @@ void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort)
{
OT_UNUSED_VARIABLE(aInstance);
*aUdpPort = sSocket.mPort;
*aUdpPort = sSockAddr.mPort;
#if DEBUG_LOG
fprintf(stderr, "\r\n[trel-sim] otPlatTrelEnable() *aUdpPort=%u\r\n", *aUdpPort);