[ncp] fix clearing unsecure ports (#3022)

This commit is contained in:
Zhanglong Xia
2018-09-10 14:39:06 -10:00
committed by Jonathan Hui
parent 0d0c04ece2
commit c573dafe8e
5 changed files with 32 additions and 7 deletions
+12
View File
@@ -455,6 +455,10 @@ otError otIp6AddUnsecurePort(otInstance *aInstance, uint16_t aPort);
/** /**
* This function removes a port from the allowed unsecure port list. * This function removes a port from the allowed unsecure port list.
* *
* @note This function removes @p aPort by overwriting @p aPort with the element after @p aPort in the internal port
* list. Be careful when calling otIp6GetUnsecurePorts() followed by otIp6RemoveUnsecurePort() to remove unsecure
* ports.
*
* @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aPort The port value. * @param[in] aPort The port value.
* *
@@ -464,6 +468,14 @@ otError otIp6AddUnsecurePort(otInstance *aInstance, uint16_t aPort);
*/ */
otError otIp6RemoveUnsecurePort(otInstance *aInstance, uint16_t aPort); otError otIp6RemoveUnsecurePort(otInstance *aInstance, uint16_t aPort);
/**
* This function removes all ports from the allowed unsecure port list.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
*/
void otIp6RemoveAllUnsecurePorts(otInstance *aInstance);
/** /**
* This function returns a pointer to the unsecure port list. * This function returns a pointer to the unsecure port list.
* *
+7
View File
@@ -221,6 +221,13 @@ otError otIp6RemoveUnsecurePort(otInstance *aInstance, uint16_t aPort)
return instance.GetThreadNetif().GetIp6Filter().RemoveUnsecurePort(aPort); return instance.GetThreadNetif().GetIp6Filter().RemoveUnsecurePort(aPort);
} }
void otIp6RemoveAllUnsecurePorts(otInstance *aInstance)
{
Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetIp6Filter().RemoveAllUnsecurePorts();
}
const uint16_t *otIp6GetUnsecurePorts(otInstance *aInstance, uint8_t *aNumEntries) const uint16_t *otIp6GetUnsecurePorts(otInstance *aInstance, uint8_t *aNumEntries)
{ {
Instance &instance = *static_cast<Instance *>(aInstance); Instance &instance = *static_cast<Instance *>(aInstance);
+5
View File
@@ -166,6 +166,11 @@ exit:
return error; return error;
} }
void Filter::RemoveAllUnsecurePorts(void)
{
memset(mUnsecurePorts, 0, sizeof(mUnsecurePorts));
}
const uint16_t *Filter::GetUnsecurePorts(uint8_t &aNumEntries) const const uint16_t *Filter::GetUnsecurePorts(uint8_t &aNumEntries) const
{ {
// Count the number of unsecure ports. // Count the number of unsecure ports.
+6
View File
@@ -97,6 +97,12 @@ public:
*/ */
otError RemoveUnsecurePort(uint16_t aPort); otError RemoveUnsecurePort(uint16_t aPort);
/**
* This method removes all ports from the allowed unsecure port list.
*
*/
void RemoveAllUnsecurePorts(void);
/** /**
* This method returns a pointer to the unsecure port list. * This method returns a pointer to the unsecure port list.
* *
+2 -7
View File
@@ -656,15 +656,10 @@ exit:
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_ASSISTING_PORTS>(void) template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_ASSISTING_PORTS>(void)
{ {
uint8_t numEntries = 0; otError error = OT_ERROR_NONE;
const uint16_t *ports = otIp6GetUnsecurePorts(mInstance, &numEntries);
otError error = OT_ERROR_NONE;
// First, we need to remove all of the current assisting ports. // First, we need to remove all of the current assisting ports.
for (; numEntries != 0; ports++, numEntries--) otIp6RemoveAllUnsecurePorts(mInstance);
{
SuccessOrExit(error = otIp6RemoveUnsecurePort(mInstance, *ports));
}
while (mDecoder.GetRemainingLengthInStruct() >= sizeof(uint16_t)) while (mDecoder.GetRemainingLengthInStruct() >= sizeof(uint16_t))
{ {