mirror of
https://github.com/espressif/openthread.git
synced 2026-08-05 02:17:47 +00:00
[posix] improve the logging in netif (#10362)
This commit improves the logging of `posix/platform/netif.cpp` in
following ways:
- Fix the false warning log when OT stack adds a unicast address.
1. When OT adds an address, it will add an address on host netif.
2. Then it causes a netlink `RTM_NEWADDR` event.
3. It assumes the newly added address is added by the host, so tries
to add the unicast address to OT again by
`otIp6AddUnicastAddress`.
4. `otIp6AddUnicastAddress` returns 'invalid arguments' error so it
will log `Failed to process event...`.
- Improve the logging of `AddRoute` and `DeleteRoute`. Previously they
silently sent out the requests so we don't know what the allocated
netlink sequence numbers were used for.
This commit is contained in:
@@ -652,7 +652,8 @@ template <size_t N> otError AddRoute(const uint8_t (&aAddress)[N], uint8_t aPref
|
||||
char buf[kBufSize];
|
||||
} req{};
|
||||
unsigned int netifIdx = otSysGetThreadNetifIndex();
|
||||
otError error = OT_ERROR_NONE;
|
||||
char addrStrBuf[INET6_ADDRSTRLEN];
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
static_assert(N == sizeof(in6_addr) || N == sizeof(in_addr), "aAddress should be 4 octets or 16 octets");
|
||||
|
||||
@@ -680,11 +681,18 @@ template <size_t N> otError AddRoute(const uint8_t (&aAddress)[N], uint8_t aPref
|
||||
AddRtAttrUint32(&req.header, sizeof(req), RTA_PRIORITY, aPriority);
|
||||
AddRtAttrUint32(&req.header, sizeof(req), RTA_OIF, netifIdx);
|
||||
|
||||
inet_ntop(req.msg.rtm_family, aAddress, addrStrBuf, sizeof(addrStrBuf));
|
||||
|
||||
if (send(sNetlinkFd, &req, sizeof(req), 0) < 0)
|
||||
{
|
||||
LogInfo("Failed to send request#%u to add route %s/%u", sNetlinkSequence, addrStrBuf, aPrefixLen);
|
||||
VerifyOrExit(errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK, error = OT_ERROR_BUSY);
|
||||
DieNow(OT_EXIT_ERROR_ERRNO);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogInfo("Sent request#%u to add route %s/%u", sNetlinkSequence, addrStrBuf, aPrefixLen);
|
||||
}
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
@@ -699,7 +707,8 @@ template <size_t N> otError DeleteRoute(const uint8_t (&aAddress)[N], uint8_t aP
|
||||
char buf[kBufSize];
|
||||
} req{};
|
||||
unsigned int netifIdx = otSysGetThreadNetifIndex();
|
||||
otError error = OT_ERROR_NONE;
|
||||
char addrStrBuf[INET6_ADDRSTRLEN];
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
static_assert(N == sizeof(in6_addr) || N == sizeof(in_addr), "aAddress should be 4 octets or 16 octets");
|
||||
|
||||
@@ -726,11 +735,18 @@ template <size_t N> otError DeleteRoute(const uint8_t (&aAddress)[N], uint8_t aP
|
||||
AddRtAttr(reinterpret_cast<nlmsghdr *>(&req), sizeof(req), RTA_DST, &aAddress, sizeof(aAddress));
|
||||
AddRtAttrUint32(&req.header, sizeof(req), RTA_OIF, netifIdx);
|
||||
|
||||
inet_ntop(req.msg.rtm_family, aAddress, addrStrBuf, sizeof(addrStrBuf));
|
||||
|
||||
if (send(sNetlinkFd, &req, sizeof(req), 0) < 0)
|
||||
{
|
||||
LogInfo("Failed to send request#%u to delete route %s/%u", sNetlinkSequence, addrStrBuf, aPrefixLen);
|
||||
VerifyOrExit(errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK, error = OT_ERROR_BUSY);
|
||||
DieNow(OT_EXIT_ERROR_ERRNO);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogInfo("Sent request#%u to delete route %s/%u", sNetlinkSequence, addrStrBuf, aPrefixLen);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -1340,6 +1356,7 @@ static void processNetifAddrEvent(otInstance *aInstance, struct nlmsghdr *aNetli
|
||||
netAddr.mPrefixLength = ifaddr->ifa_prefixlen;
|
||||
|
||||
error = otIp6AddUnicastAddress(aInstance, &netAddr);
|
||||
error = (error == OT_ERROR_INVALID_ARGS) ? OT_ERROR_NONE : error;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user