Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Feb 26, 2023
1 parent 4f789a8 commit ea9255e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/inet/BasicPacketFilters.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DropIfTooManyQueuedPacketsFilter : public chip::Inet::EndpointQueueFilter
*
* @param maxAllowedQueuedPackets - max number of pending-in-queue not yet processed predicate-matching packets
*/
DropIfTooManyQueuedPacketsFilter(int maxAllowedQueuedPackets) : mMaxAllowedQueuedPackets(maxAllowedQueuedPackets) {}
DropIfTooManyQueuedPacketsFilter(size_t maxAllowedQueuedPackets) : mMaxAllowedQueuedPackets(maxAllowedQueuedPackets) {}

/**
* @brief Set the predicate to use for filtering
Expand All @@ -68,7 +68,7 @@ class DropIfTooManyQueuedPacketsFilter : public chip::Inet::EndpointQueueFilter
*
* @param maxAllowedQueuedPackets - number of packets currently pending allowed.
*/
void SetMaxQueuedPacketsLimit(int maxAllowedQueuedPackets) { mMaxAllowedQueuedPackets.store(maxAllowedQueuedPackets); }
void SetMaxQueuedPacketsLimit(size_t maxAllowedQueuedPackets) { mMaxAllowedQueuedPackets.store(maxAllowedQueuedPackets); }

/**
* @return the total number of packets dropped so far by the filter
Expand Down Expand Up @@ -158,8 +158,12 @@ class DropIfTooManyQueuedPacketsFilter : public chip::Inet::EndpointQueueFilter
return FilterOutcome::kAllowPacket;
}

// If we ever go negative, we have mismatch ingress/egress filter via predicate and
// device may eventually starve.
VerifyOrDie(mNumQueuedPackets != 0);

--mNumQueuedPackets;
int numQueuedPackets = mNumQueuedPackets.load();
size_t numQueuedPackets = mNumQueuedPackets.load();
if (numQueuedPackets == 0)
{
OnLastMatchDequeued(endpoint, pktInfo, pktPayload);
Expand All @@ -176,8 +180,8 @@ class DropIfTooManyQueuedPacketsFilter : public chip::Inet::EndpointQueueFilter
protected:
PacketMatchPredicateFunc mPredicate = nullptr;
void * mContext = nullptr;
std::atomic_int mNumQueuedPackets{ 0 };
std::atomic_int mMaxAllowedQueuedPackets{ 0 };
std::atomic_size_t mNumQueuedPackets{ 0 };
std::atomic_size_t mMaxAllowedQueuedPackets{ 0 };
std::atomic_size_t mNumDroppedPackets{ 0u };
};

Expand Down
2 changes: 1 addition & 1 deletion src/inet/tests/TestBasicPacketFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace chip::Inet;
class DropIfTooManyQueuedPacketsHarness : public DropIfTooManyQueuedPacketsFilter
{
public:
DropIfTooManyQueuedPacketsHarness(int maxAllowedQueuedPackets) : DropIfTooManyQueuedPacketsFilter(maxAllowedQueuedPackets) {}
DropIfTooManyQueuedPacketsHarness(size_t maxAllowedQueuedPackets) : DropIfTooManyQueuedPacketsFilter(maxAllowedQueuedPackets) {}

void OnDropped(const void * endpoint, const IPPacketInfo & pktInfo,
const chip::System::PacketBufferHandle & pktPayload) override
Expand Down

0 comments on commit ea9255e

Please sign in to comment.