[posix-app] fix crash on os ifconfig down (#4171)

This commit fixes a crash issue triggered by system command ifconfig
down.  This is because OpenThread's tries removing addresses when the
platform network interface is already down.
This commit is contained in:
Yakun Xu
2019-09-17 04:05:02 -07:00
committed by Jonathan Hui
parent 9a0ef5304a
commit 69f173ebae
+16 -4
View File
@@ -98,12 +98,24 @@ static void UpdateUnicast(otInstance *aInstance, const otIp6Address &aAddress, u
ifr6.ifr6_ifindex = static_cast<int>(sTunIndex);
ifr6.ifr6_prefixlen = aPrefixLength;
VerifyOrExit(ioctl(sIpFd, (aIsAdded ? SIOCSIFADDR : SIOCDIFADDR), &ifr6) == 0, perror("ioctl");
error = OT_ERROR_FAILED);
if (aIsAdded)
{
VerifyOrDie(ioctl(sIpFd, SIOCSIFADDR, &ifr6) == 0, OT_EXIT_ERROR_ERRNO);
}
else
{
VerifyOrExit(ioctl(sIpFd, SIOCDIFADDR, &ifr6) == 0, perror("ioctl"); error = OT_ERROR_FAILED);
}
exit:
SuccessOrDie(error);
otLogInfoPlat("%s: %s", __func__, otThreadErrorToString(error));
if (error != OT_ERROR_NONE)
{
otLogWarnPlat("%s: %s", __func__, otThreadErrorToString(error));
}
else
{
otLogInfoPlat("%s: %s", __func__, otThreadErrorToString(error));
}
}
static void UpdateMulticast(otInstance *aInstance, const otIp6Address &aAddress, bool aIsAdded)