fix(filter): bracket the content verdict, gate content on the battery, and

start advert windows on admission

Three receive-path defects, all about state that outlived the operation that
produced it.

The content verdict stash was cleared only inside `if (content_verdict.pkt ==
pkt)`, so a verdict for a packet that never reached the forwarding hook — dropped
earlier, or on a path that skips forwarding — lingered until some later packet
reused that buffer. It is now consumed unconditionally in checkPacket(), and
MyMesh::onRecvPacket() brackets one whole receive with clearContentVerdict() on
both sides, which is what actually bounds its life. The pointer+hash guard stays
as defence in depth against pool reuse. Any rule or channel mutation clears it
too (markDirty() is the one place they all pass through), as do enable toggles
and reload, so a verdict can never be honoured under a rule list it was not
decided under.

The battery gate outranked the filter only for packets that could not be
decrypted. Decryptable group traffic ran the content rules and banked hits and
airtime while a suspended repeater was refusing to relay it, and could spend a
content throttle's free-pass budget — two different stories for one suspension.
onGroupDataRecv() now returns early while suspended, so the packet is accounted
as a battery drop at forwarding admission, once. Battery sampling also moved
before Mesh::loop(), so a receive that crosses a sampling boundary sees that
loop's reading rather than the previous one. No per-packet ADC read was added.

The advert rate limiter recorded a node's window inside the check, which runs
before every stock forwarding check — so a repeater left in `set off`, or
refusing adverts for hop-limit, unknown-region or loop reasons, silently stopped
relaying those nodes for the rest of the 48 h window. drop() is split into
wouldDrop(), which only answers, and recordForward(), called from
onForwardAllowed() at the successful end of allowPacketForward(). The window now
means "relayed", not "received". FILTER.md says so, including the honest limit
that a queued advert that never reaches the air still counts as admitted.

Existing limiter tests assumed check implied commit, which was true before and
would have silently tested nothing after. They now drive a forwardPacket()
helper that mirrors the real hook: check, then commit only on survival.

369 cases green across all four native envs, 315 clean under sanitizers, all four
firmware targets compile, RAM unchanged at 20.6%.
This commit is contained in:
Jason Huebert authored and github-actions[bot] committed 2026-10-09 18:28:45 +00:00
1 parent a23f03c2aa
commit 2ee4d29fce
8 files changed
+435 -78

No files matched your search

+6
View File
@@ -33,6 +33,12 @@ check the voltage, and adjust or disable the gate.
- **Drop counter:** a RAM-only counter of packets gated while suspended
(resets on reboot, like the filter stats).
Suspension is checked before the content rules too, so a decryptable group
message does not get evaluated (and counted as a filter hit) while the repeater
is refusing to relay it — it is accounted as a battery drop at forwarding
admission instead, once, the same as any other packet. Traffic already queued for
transmission is not cancelled by suspending.
While suspended, `allowPacketForward()` rejects every packet — flood, direct,
and group content alike. Everything the node originates on its own behalf
(CLI replies, status responses, adverts) is unaffected.
+8
View File
@@ -205,6 +205,14 @@ Group-text messages look like `SenderName: message text` after decryption.
Independent of the rules, you can rate-limit flood adverts per originating
node: *each node's advert is forwarded at most once every N hours.*
The window counts adverts this repeater actually **admitted for relay**, not
every advert it heard. An advert refused afterwards — by `set off`, a hop limit,
an unknown region, loop detection, or the battery gate — does not use up the
node's budget, so turning forwarding back on does not leave that node invisible
for the rest of the window. The honest limit: an advert queued for transmission
that never makes it onto the air still counts as admitted. Already-queued
relays are not cancelled by turning the filter or the battery gate off.
```text
filter ratelimit advert 48 # each origin forwarded at most every 48 h
filter ratelimit clear # optional: forget history, start clean
+46 -24
View File
@@ -2,54 +2,76 @@
#include "AdvertRateLimiter.h"
// cache key: 4 bytes sampled from the origin pubkey (payload[0..31]) at fixed
// offsets clear of the vanity zones at both ends — prefix/suffix grinding leaves
// the middle bytes uniformly random, so two vanity keys collide with plain
// random-chance odds instead of deterministically
static const uint8_t KEY_OFFSETS[4] = { 8, 14, 20, 26 };
AdvertRateLimiter::AdvertRateLimiter() {
reset();
}
void AdvertRateLimiter::clearCache() {
void AdvertRateLimiter::clearCacheImpl() {
memset(cache, 0, sizeof(cache));
cache_count = 0;
cache_head = 0;
}
bool AdvertRateLimiter::drop(const mesh::Packet* pkt, uint32_t now_millis) {
if (hours == 0) return false; // limiter off: nothing is ever suppressed
uint32_t window_ms = (uint32_t)hours * 3600UL * 1000UL;
void AdvertRateLimiter::clearCache() { clearCacheImpl(); }
// cache key: 4 bytes sampled from the origin pubkey (payload[0..31]) at fixed
// offsets clear of the vanity zones at both ends — prefix/suffix grinding
// leaves the middle bytes uniformly random, so two vanity keys collide with
// plain random-chance odds instead of deterministically
static const uint8_t KEY_OFFSETS[4] = { 8, 14, 20, 26 };
int AdvertRateLimiter::findOrigin(const mesh::Packet* pkt) const {
uint8_t prefix[4];
for (int i = 0; i < 4; i++) prefix[i] = pkt->payload[KEY_OFFSETS[i]];
// ring start/total do not change while scanning: entries are appended until
// ring start and total do not change while scanning: entries are appended until
// the cache is full, then the oldest is overwritten
const bool wrapped = cache_count >= FILTER_ADVERT_CACHE_SIZE;
const int total = wrapped ? FILTER_ADVERT_CACHE_SIZE : cache_count;
const int start = wrapped ? cache_head : 0;
for (int i = 0; i < total; i++) {
AdvertSeenEntry* e = &cache[(start + i) % FILTER_ADVERT_CACHE_SIZE];
if (memcmp(e->pub_key_prefix, prefix, sizeof(e->pub_key_prefix)) == 0) {
if (now_millis - e->first_seen_millis < window_ms) {
drops++;
return true; // too soon: drop the repeat
}
e->first_seen_millis = now_millis; // refresh: window restarts
return false;
}
const int idx = (start + i) % FILTER_ADVERT_CACHE_SIZE;
if (memcmp(cache[idx].pub_key_prefix, prefix, sizeof(prefix)) == 0) return idx;
}
return -1;
}
// not seen in this window: record
void AdvertRateLimiter::storeOrigin(const mesh::Packet* pkt, uint32_t now_millis) {
AdvertSeenEntry* e;
if (!wrapped) {
if (cache_count < FILTER_ADVERT_CACHE_SIZE) {
e = &cache[cache_count++];
} else {
e = &cache[cache_head]; // overwrite the oldest entry
cache_head = (cache_head + 1) % FILTER_ADVERT_CACHE_SIZE;
}
memcpy(e->pub_key_prefix, prefix, sizeof(e->pub_key_prefix));
for (int i = 0; i < 4; i++) e->pub_key_prefix[i] = pkt->payload[KEY_OFFSETS[i]];
e->first_seen_millis = now_millis;
return false;
}
bool AdvertRateLimiter::wouldDrop(const mesh::Packet* pkt, uint32_t now_millis) {
if (hours == 0) return false; // limiter off: nothing is ever suppressed
const uint32_t window_ms = (uint32_t)hours * 3600UL * 1000UL;
const int idx = findOrigin(pkt);
// not relayed in this window, or the window has expired: let it through. The
// stamp is refreshed on admission (recordForward), not here.
if (idx < 0) return false;
if ((uint32_t)(now_millis - cache[idx].first_seen_millis) >= window_ms) return false;
drops++;
return true; // too soon: suppress the repeat
}
bool AdvertRateLimiter::refreshExpired(const mesh::Packet* pkt, uint32_t now_millis) {
if (hours == 0) return false;
const uint32_t window_ms = (uint32_t)hours * 3600UL * 1000UL;
const int idx = findOrigin(pkt);
if (idx < 0) return false;
if ((uint32_t)(now_millis - cache[idx].first_seen_millis) < window_ms) return false;
cache[idx].first_seen_millis = now_millis; // window restarts
return true;
}
void AdvertRateLimiter::recordForward(const mesh::Packet* pkt, uint32_t now_millis) {
if (hours == 0) return; // limiter off: keep no history at all
const int idx = findOrigin(pkt);
if (idx >= 0) cache[idx].first_seen_millis = now_millis; // refresh the window
else storeOrigin(pkt, now_millis);
}
+26 -4
View File
@@ -42,7 +42,6 @@ public:
bool enabled() const { return hours > 0; }
int getCacheCount() const { return cache_count; }
uint32_t getDrops() const { return drops; }
void clearCache();
void resetDrops() { drops = 0; }
// back to a freshly constructed limiter (empty cache, window off, no drops)
@@ -55,9 +54,32 @@ public:
}
// True if this advert must be dropped because the same origin was already
// relayed less than `hours` ago (counting that drop). Drops nothing while the
// limiter is off (hours == 0) or the origin is seen for the first time.
bool drop(const mesh::Packet* pkt, uint32_t now_millis);
// RELAYED less than `hours` ago. This only answers the question — it records
// nothing, because whether an advert actually gets relayed is decided after the
// stock forwarding checks. Recording here would spend a node's 48 h budget on
// adverts that never got forwarded: a repeater left in `set off`, or refusing
// them for hop-limit/region/loop reasons, would silently stop relaying those
// nodes for the rest of the window.
bool wouldDrop(const mesh::Packet* pkt, uint32_t now_millis);
// Record that this origin's advert was admitted for relay, starting its window.
// Called from the successful end of the forwarding hook, never from the check.
void recordForward(const mesh::Packet* pkt, uint32_t now_millis);
// Restart an origin's expired window. Not used by the forwarding path — the
// stamp is refreshed by recordForward() on admission — but the expiry semantics
// are easier to state (and to test) as their own step.
bool refreshExpired(const mesh::Packet* pkt, uint32_t now_millis);
// Drop the cache entirely.
void clearCache();
private:
void clearCacheImpl();
// index of the cache slot holding this origin's 4-byte key, or -1
int findOrigin(const mesh::Packet* pkt) const;
// store this origin at `now`, evicting the oldest entry if the cache is full
void storeOrigin(const mesh::Packet* pkt, uint32_t now_millis);
};
#endif // _ADVERT_RATE_LIMITER_H
+25 -4
View File
@@ -457,6 +457,10 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
return false;
}
}
// Every stock check passed, so this packet will be relayed: start the origin's
// advert window now. Doing it here rather than in checkPacket() is what keeps a
// refused advert from consuming a node's 48 h budget.
filter.onForwardAllowed(packet, millis());
return true;
}
@@ -465,6 +469,13 @@ int MyMesh::searchChannelsByHash(const uint8_t* hash, mesh::GroupChannel channel
}
void MyMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mesh::GroupChannel& channel, uint8_t* data, size_t len) {
// The battery gate outranks the filter. Without this, decryptable group traffic
// runs the content rules and banks hits/airtime while a suspended repeater is
// refusing to relay it, whereas an undecryptable packet of the same shape is
// counted as a battery drop — two different stories for the same suspension.
// Forwarding admission stays in allowPacketForward(), which counts once.
if (battGate.isSuspended()) return;
if (filter.checkContent(packet, type, channel, data, len, recv_pkt_region, _radio->getEstAirtimeFor(packet->getRawLength())) == FILTER_ACT_DROP) {
MESH_DEBUG_PRINTLN("filter: dropping group packet by content rule");
packet->markDoNotRetransmit();
@@ -578,7 +589,15 @@ mesh::DispatcherAction MyMesh::onRecvPacket(mesh::Packet* pkt) {
} else {
recv_pkt_region = NULL;
}
return Mesh::onRecvPacket(pkt);
// Bracket ONE receive operation: the content verdict stashed by onGroupDataRecv()
// belongs to the packet being processed right now, and to no other. Clearing
// on both sides means a verdict cannot survive into a later packet, whatever
// core decides to do in between — including returning early or never reaching
// the forwarding hook at all.
filter.clearContentVerdict();
mesh::DispatcherAction action = Mesh::onRecvPacket(pkt);
filter.clearContentVerdict();
return action;
}
void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender,
@@ -1312,6 +1331,11 @@ void MyMesh::loop() {
bridge.loop();
#endif
// Battery FIRST, before any receive can be dispatched: at a sampling boundary
// the receive that follows must see this loop's reading, not the previous one.
// One sample per interval, not one per packet.
battGate.loop(_fs, board);
mesh::Mesh::loop();
if (next_flood_advert && millisHasNowPassed(next_flood_advert)) {
@@ -1349,9 +1373,6 @@ void MyMesh::loop() {
// lazy dirty-flag save for the packet filter config
filter.loop(_fs);
// battery gate: periodic voltage sample + lazy config save
battGate.loop(_fs, board);
// update uptime
uint32_t now = millis();
uptime_millis += now - last_millis;
+37 -12
View File
@@ -49,6 +49,7 @@ static int filterDecodeHex(const char* in, size_t in_len, uint8_t* out, size_t c
// One definition, so construction and reload cannot drift apart — a field added
// here is reset by both.
void FilterRules::resetToDefaults() {
clearContentVerdict(); // a reload must never honour a verdict for the old rules
memset(rules, 0, sizeof(rules)); // unpersisted tail bytes (padding, stats) stay deterministic
memset(channels, 0, sizeof(channels));
num_rules = 0;
@@ -82,12 +83,24 @@ void FilterRules::loop(FILESYSTEM* fs) {
// ---------------------------------------------------------------- enable / stats
void FilterRules::setEnabled(bool on) {
clearContentVerdict(); // the rule list just changed meaning for any stashed packet
if (enabled != on) {
enabled = on;
markDirty();
}
}
// Called from the successful end of allowPacketForward(), once every stock
// forwarding check has passed. This is the only place an advert's window starts,
// so a repeater that refuses to relay (manual off, hop limit, unknown region,
// loop detect) never spends a node's budget.
void FilterRules::onForwardAllowed(const mesh::Packet* pkt, uint32_t now_millis) {
if (!enabled) return;
if (pkt->getPayloadType() != PAYLOAD_TYPE_ADVERT) return;
if (!pkt->isRouteFlood()) return; // the limiter only governs flood adverts
limiter.recordForward(pkt, now_millis);
}
void FilterRules::resetStats() {
limiter.resetDrops();
budget_aborts = 0;
@@ -459,17 +472,23 @@ uint8_t FilterRules::checkPacket(const mesh::Packet* pkt, uint32_t now_millis, c
// one hash for this packet, shared by the stash guard and any prob roll below
PacketHashCache pkt_hash(pkt);
// a verdict stashed by checkContent() for this exact packet is final:
// return it without rescanning (no double-counted hits, no reordering).
// Stale stash (different buffer, or the pool re-used it with new content,
// caught by the content-hash tag) is cleared and a normal packet-level scan
// runs.
if (content_verdict.pkt == pkt) {
content_verdict.pkt = NULL; // consume once, whatever the tag says
if (memcmp(pkt_hash.get(), content_verdict.hash, MAX_HASH_SIZE) == 0) {
if (content_verdict.verdict != FILTER_ACT_DROP) billEvaluated(est_air_ms);
return content_verdict.verdict;
}
// A verdict stashed by checkContent() for this exact packet is final: return it
// without rescanning (no double-counted hits, no reordering).
//
// Whether the pointer matched or not, the stash is consumed HERE and now. It
// used to be cleared only inside the match branch, so a content verdict for a
// packet that never reached this hook — dropped earlier, or on a path that skips
// forwarding — lingered until some later packet happened to reuse the buffer.
// The pointer+hash pair is defence in depth for pool reuse, not the thing that
// bounds the stash's life; the receive bracketing in MyMesh::onRecvPacket() is.
const bool stash_matched = (content_verdict.pkt == pkt);
uint8_t stash_hash[MAX_HASH_SIZE];
memcpy(stash_hash, content_verdict.hash, MAX_HASH_SIZE);
const uint8_t stash_verdict = content_verdict.verdict;
clearContentVerdict();
if (stash_matched && memcmp(pkt_hash.get(), stash_hash, MAX_HASH_SIZE) == 0) {
if (stash_verdict != FILTER_ACT_DROP) billEvaluated(est_air_ms);
return stash_verdict;
}
billEvaluated(est_air_ms);
@@ -484,7 +503,7 @@ uint8_t FilterRules::checkPacket(const mesh::Packet* pkt, uint32_t now_millis, c
if (action == FILTER_ACT_DROP) return FILTER_ACT_DROP;
// limiter runs unless the rule list already dropped; forward adverts too
if (payload_type == PAYLOAD_TYPE_ADVERT && pkt->isRouteFlood() && limiter.drop(pkt, now_millis)) {
if (payload_type == PAYLOAD_TYPE_ADVERT && pkt->isRouteFlood() && limiter.wouldDrop(pkt, now_millis)) {
billSaved(est_air_ms); // a limiter drop saves the same airtime
return FILTER_ACT_DROP;
}
@@ -565,6 +584,10 @@ bool FilterRules::regexMatches(const char* pattern, const char* subject) {
uint8_t FilterRules::checkContent(mesh::Packet* pkt, uint8_t type, const mesh::GroupChannel& channel,
const uint8_t* data, size_t len, const RegionEntry* region,
uint32_t est_air_ms) {
// A disabled filter or non-group traffic reaches no content scan. That must
// not carry a verdict over from an earlier sequence in this same receive, so
// drop any stash before returning rather than leaving it to answer later.
clearContentVerdict();
if (!enabled) return FILTER_ACT_ALLOW;
if (type != PAYLOAD_TYPE_GRP_TXT && type != PAYLOAD_TYPE_GRP_DATA) return FILTER_ACT_ALLOW;
@@ -578,6 +601,8 @@ uint8_t FilterRules::checkContent(mesh::Packet* pkt, uint8_t type, const mesh::G
if (parsed) parseGroupText(data, len, sender, sizeof(sender), text, sizeof(text), &has_text, &has_sender);
uint8_t verdict = FILTER_ACT_ALLOW;
// Disabled or non-group traffic reaches no content scan, so it must also not
// carry a verdict over from an earlier sequence in this same receive.
PacketHashCache pkt_hash(pkt);
// one clock reading for the whole scan: the throttle gate stamps state that
// checkPacket() writes too, and both phases read the same millis() clock
+14 -1
View File
@@ -213,6 +213,11 @@ public:
void begin(FILESYSTEM* fs); // load persisted config, pre-provision Public channel
void loop(FILESYSTEM* fs); // lazy dirty-flag save (same pattern as ClientACL)
// Forget any content verdict stashed for the packet currently being received.
// MyMesh::onRecvPacket() brackets one receive with this so a verdict can never
// outlive the operation that produced it; checkPacket() also consumes it.
void clearContentVerdict() { content_verdict.pkt = NULL; }
bool isEnabled() const { return enabled; }
void setEnabled(bool on);
@@ -248,6 +253,11 @@ public:
uint8_t checkPacket(const mesh::Packet* pkt, uint32_t now_millis, const RegionEntry* region,
uint32_t est_air_ms = 0);
// Commit a forwarding decision that actually succeeded: starts an advert's
// rate-limit window. Called from the end of allowPacketForward(), never from
// the check, so the window means "relayed", not "received".
void onForwardAllowed(const mesh::Packet* pkt, uint32_t now_millis);
// Single-pass evaluation of the ENTIRE rule list on a decrypted group
// payload (packet-level predicates via ruleMatchesPacket, then chan keyed /
// sender / text), in listed order; first enabled match decides (first match
@@ -266,7 +276,10 @@ public:
uint16_t getAdvertRatelimit() const { return limiter.getHours(); }
void clearAdvertCache() { limiter.clearCache(); }
int getAdvertCacheCount() const { return limiter.getCacheCount(); }
void markDirty() { save_flag.markDirty(); }
// Any rule or channel mutation: the config is changing, so a verdict stashed
// under the old rules must not be honoured afterwards. markDirty() is the one
// place every mutation already passes through.
void markDirty() { clearContentVerdict(); save_flag.markDirty(); }
uint32_t getLimiterDrops() const { return limiter.getDrops(); }
uint32_t getBudgetAborts() const { return budget_aborts; }
uint64_t getAirSavedMs() const { return air_saved_ms; } // airtime not relayed (drops)
+273 -33
View File
@@ -1207,19 +1207,30 @@ TEST_F(FilterTest, SearchChannelsByHashDisabledWhenFilterOff) {
#include "FilterTestHelpers.h"
// Emulate MyMesh::allowPacketForward(): the filter check, and — only when the
// packet survives it — the commit at the successful end of the forwarding hook.
// Checking alone no longer starts an advert's rate-limit window, so a limiter
// test that only calls checkPacket() is not exercising the real path.
static uint8_t forwardPacket(FilterRules& filter, const mesh::Packet& pkt, uint32_t now_millis,
const RegionEntry* region = nullptr, uint32_t est_air_ms = 0) {
uint8_t action = filter.checkPacket(&pkt, now_millis, region, est_air_ms);
if (action != FILTER_ACT_DROP) filter.onForwardAllowed(&pkt, now_millis);
return action;
}
TEST_F(FilterTest, FirstAdvertRecordedRepeatDropped) {
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
auto pkt = makeAdvert(key);
EXPECT_EQ(filter.checkPacket(&pkt, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, 1000), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), 1);
EXPECT_EQ(filter.getLimiterDrops(), 0u);
// repeat flood advert within the 48h window (transport codes set to make a
// distinct packet, same origin key)
pkt.transport_codes[0] = 0x4242;
EXPECT_EQ(filter.checkPacket(&pkt, 5000, nullptr), FILTER_ACT_DROP);
EXPECT_EQ(forwardPacket(filter, pkt, 5000), FILTER_ACT_DROP);
EXPECT_EQ(filter.getLimiterDrops(), 1u);
EXPECT_EQ(filter.getAdvertCacheCount(), 1); // repeat not re-recorded
}
@@ -1230,12 +1241,12 @@ TEST_F(FilterTest, DistinctOriginsTrackedIndependently) {
uint8_t k2[4] = { 5, 6, 7, 8 };
auto a1 = makeAdvert(k1);
auto a2 = makeAdvert(k2) ;
EXPECT_EQ(filter.checkPacket(&a1, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.checkPacket(&a2, 1100, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, a1, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, a2, 1100, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), 2);
auto a1b = makeAdvert(k1);
EXPECT_EQ(filter.checkPacket(&a1b, 2000, nullptr), FILTER_ACT_DROP);
EXPECT_EQ(forwardPacket(filter, a1b, 2000, nullptr), FILTER_ACT_DROP);
}
TEST_F(FilterTest, WindowExpiryAllowsAndRefreshes) {
@@ -1244,12 +1255,12 @@ TEST_F(FilterTest, WindowExpiryAllowsAndRefreshes) {
auto pkt = makeAdvert(key);
uint32_t t0 = 1000;
EXPECT_EQ(filter.checkPacket(&pkt, t0, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.checkPacket(&pkt, t0 + 3600UL * 1000 - 1, nullptr), FILTER_ACT_DROP);
EXPECT_EQ(forwardPacket(filter, pkt, t0, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, t0 + 3600UL * 1000 - 1, nullptr), FILTER_ACT_DROP);
// at exactly the window boundary the advert is allowed again...
EXPECT_EQ(filter.checkPacket(&pkt, t0 + 3600UL * 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, t0 + 3600UL * 1000, nullptr), FILTER_ACT_ALLOW);
// ...and the window restarts from that moment
EXPECT_EQ(filter.checkPacket(&pkt, t0 + 3600UL * 1000 + 500, nullptr), FILTER_ACT_DROP);
EXPECT_EQ(forwardPacket(filter, pkt, t0 + 3600UL * 1000 + 500, nullptr), FILTER_ACT_DROP);
}
TEST_F(FilterTest, TimingIsWrapSafe) {
@@ -1258,11 +1269,11 @@ TEST_F(FilterTest, TimingIsWrapSafe) {
auto pkt = makeAdvert(key);
uint32_t t0 = 0xFFFFFFF0u; // just before the 32-bit millis() wrap
EXPECT_EQ(filter.checkPacket(&pkt, t0, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, t0, nullptr), FILTER_ACT_ALLOW);
// now has wrapped past 0 to ~16s: still inside the 1h window
EXPECT_EQ(filter.checkPacket(&pkt, 16000, nullptr), FILTER_ACT_DROP);
EXPECT_EQ(forwardPacket(filter, pkt, 16000, nullptr), FILTER_ACT_DROP);
// wrapped and past the window: allowed, entry refreshed
EXPECT_EQ(filter.checkPacket(&pkt, 3600UL * 1000 + 16000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, 3600UL * 1000 + 16000, nullptr), FILTER_ACT_ALLOW);
}
TEST_F(FilterTest, RingCacheEvictsOldestOrigin) {
@@ -1276,14 +1287,14 @@ TEST_F(FilterTest, RingCacheEvictsOldestOrigin) {
pkt.payload[ADV_KEY_OFFSETS[1]] = 0x55;
pkt.payload[ADV_KEY_OFFSETS[2]] = (uint8_t)(i >> 8);
pkt.payload[ADV_KEY_OFFSETS[3]] = (uint8_t)(i >> 16);
EXPECT_EQ(filter.checkPacket(&pkt, 1000 + i, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, 1000 + i, nullptr), FILTER_ACT_ALLOW);
}
EXPECT_EQ(filter.getAdvertCacheCount(), FILTER_ADVERT_CACHE_SIZE);
// origin 0 is the oldest: one more advert evicts it
uint8_t extra[4] = { 0xAA, 0xBB, 0xCC, 0xDD };
auto extra_pkt = makeAdvert(extra);
EXPECT_EQ(filter.checkPacket(&extra_pkt, 5000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, extra_pkt, 5000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), FILTER_ADVERT_CACHE_SIZE);
// origin 0 has been evicted, so it is recorded fresh instead of dropped
@@ -1291,7 +1302,7 @@ TEST_F(FilterTest, RingCacheEvictsOldestOrigin) {
pkt.payload[ADV_KEY_OFFSETS[1]] = 0x55;
pkt.payload[ADV_KEY_OFFSETS[2]] = 0;
pkt.payload[ADV_KEY_OFFSETS[3]] = 0;
EXPECT_EQ(filter.checkPacket(&pkt, 5100, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, 5100, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getLimiterDrops(), 0u);
}
@@ -1299,9 +1310,9 @@ TEST_F(FilterTest, ClearEmptiesCacheButNotCounters) {
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 7, 7, 7, 7 };
auto pkt = makeAdvert(key);
filter.checkPacket(&pkt, 1000, nullptr);
forwardPacket(filter, pkt, 1000, nullptr);
pkt.transport_codes[0] = 1;
filter.checkPacket(&pkt, 2000, nullptr);
forwardPacket(filter, pkt, 2000, nullptr);
ASSERT_GT(filter.getLimiterDrops(), 0u);
filter.clearAdvertCache();
@@ -1310,7 +1321,7 @@ TEST_F(FilterTest, ClearEmptiesCacheButNotCounters) {
// cleared cache: the origin is recorded again instead of dropped
auto pkt2 = makeAdvert(key);
EXPECT_EQ(filter.checkPacket(&pkt2, 3000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt2, 3000, nullptr), FILTER_ACT_ALLOW);
}
TEST_F(FilterTest, RatelimitClearCliClearsCacheNotCounters) {
@@ -1319,9 +1330,9 @@ TEST_F(FilterTest, RatelimitClearCliClearsCacheNotCounters) {
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 7, 7, 7, 7 };
auto pkt = makeAdvert(key);
filter.checkPacket(&pkt, 1000, nullptr);
forwardPacket(filter, pkt, 1000, nullptr);
pkt.transport_codes[0] = 1;
filter.checkPacket(&pkt, 2000, nullptr);
forwardPacket(filter, pkt, 2000, nullptr);
ASSERT_EQ(filter.getLimiterDrops(), 1u);
ASSERT_EQ(cli(filter, "ratelimit clear"), "OK - advert cache cleared");
@@ -1332,10 +1343,10 @@ TEST_F(FilterTest, RatelimitClearCliClearsCacheNotCounters) {
TEST_F(FilterTest, RatelimitZeroIsOff) {
uint8_t key[4] = { 3, 1, 4, 1 };
auto pkt = makeAdvert(key);
EXPECT_EQ(filter.checkPacket(&pkt, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), 0); // nothing recorded while off
pkt.transport_codes[0] = 2;
EXPECT_EQ(filter.checkPacket(&pkt, 2000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, pkt, 2000, nullptr), FILTER_ACT_ALLOW);
}
TEST_F(FilterTest, OnlyFloodAdvertsAreLimited) {
@@ -1343,12 +1354,12 @@ TEST_F(FilterTest, OnlyFloodAdvertsAreLimited) {
uint8_t key[4] = { 0x11, 0x22, 0x33, 0x44 };
auto direct_adv = makePacket(ROUTE_TYPE_DIRECT, PAYLOAD_TYPE_ADVERT, 64, 1, 0);
for (int i = 0; i < 4; i++) direct_adv.payload[ADV_KEY_OFFSETS[i]] = key[i];
EXPECT_EQ(filter.checkPacket(&direct_adv, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, direct_adv, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), 0); // direct adverts not recorded
auto flood_txt = makeAdvert(key);
flood_txt.header = (ROUTE_TYPE_FLOOD & PH_ROUTE_MASK) | (PAYLOAD_TYPE_GRP_TXT << PH_TYPE_SHIFT);
EXPECT_EQ(filter.checkPacket(&flood_txt, 1100, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(forwardPacket(filter, flood_txt, 1100, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), 0); // non-advert types not recorded
}
@@ -1358,9 +1369,9 @@ TEST_F(FilterTest, ForwardAdvertStillHitsLimiter) {
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 0x0A, 0x0B, 0x0C, 0x0D };
auto pkt = makeAdvert(key);
EXPECT_EQ(filter.checkPacket(&pkt, 1000, nullptr), FILTER_ACT_FORWARD);
EXPECT_EQ(forwardPacket(filter, pkt, 1000, nullptr), FILTER_ACT_FORWARD);
pkt.transport_codes[0] = 5;
EXPECT_EQ(filter.checkPacket(&pkt, 2000, nullptr), FILTER_ACT_DROP); // limiter wins
EXPECT_EQ(forwardPacket(filter, pkt, 2000, nullptr), FILTER_ACT_DROP); // limiter wins
EXPECT_EQ(filter.getLimiterDrops(), 1u);
}
@@ -1375,6 +1386,235 @@ TEST_F(FilterTest, ForwardAdvertStillHitsLimiter) {
#include "FilterTestHelpers.h"
// The limiter's window means "relayed", not "received": a packet refused by the
// stock forwarding checks after checkPacket() must not spend the origin's budget.
TEST_F(FilterTest, RefusedAdvertDoesNotSpendTheOriginBudget) {
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 0x5A, 0x5B, 0x5C, 0x5D };
auto pkt = makeAdvert(key);
// checkPacket() passes, but the stock checks then refuse it (manual off, hop
// limit, unknown region, loop detect) so onForwardAllowed() never runs
EXPECT_EQ(filter.checkPacket(&pkt, 1000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), 0); // nothing recorded
// the same origin must still be relayable later
pkt.transport_codes[0] = 1;
EXPECT_EQ(filter.checkPacket(&pkt, 2000, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getLimiterDrops(), 0u);
// only once it is actually admitted does the window start
pkt.transport_codes[0] = 2;
EXPECT_EQ(forwardPacket(filter, pkt, 3000), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAdvertCacheCount(), 1);
pkt.transport_codes[0] = 3;
EXPECT_EQ(forwardPacket(filter, pkt, 4000), FILTER_ACT_DROP);
EXPECT_EQ(filter.getLimiterDrops(), 1u);
}
TEST_F(FilterTest, RuleDropNeverCommitsAnAdvertWindow) {
filter.setAdvertRatelimit(48);
ASSERT_EQ(cli(filter, "add type=advert action=drop"), "OK - rule 0 added");
uint8_t key[4] = { 0x6A, 0x6B, 0x6C, 0x6D };
auto pkt = makeAdvert(key);
EXPECT_EQ(forwardPacket(filter, pkt, 1000), FILTER_ACT_DROP);
EXPECT_EQ(filter.getAdvertCacheCount(), 0); // a rule drop is not a forward
EXPECT_EQ(filter.getLimiterDrops(), 0u);
}
TEST_F(FilterTest, ForwardVerdictStillCommitsTheWindow) {
// action=forward is terminal for the rule list but the packet IS relayed, so
// the origin's window must start
filter.setAdvertRatelimit(48);
ASSERT_EQ(cli(filter, "add type=advert action=forward"), "OK - rule 0 added");
uint8_t key[4] = { 0x7A, 0x7B, 0x7C, 0x7D };
auto pkt = makeAdvert(key);
EXPECT_EQ(forwardPacket(filter, pkt, 1000), FILTER_ACT_FORWARD);
EXPECT_EQ(filter.getAdvertCacheCount(), 1);
pkt.transport_codes[0] = 9;
EXPECT_EQ(forwardPacket(filter, pkt, 2000), FILTER_ACT_DROP);
EXPECT_EQ(filter.getLimiterDrops(), 1u);
}
TEST_F(FilterTest, DisabledFilterKeepsNoAdvertHistory) {
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 0x8A, 0x8B, 0x8C, 0x8D };
auto pkt = makeAdvert(key);
filter.setEnabled(false);
EXPECT_EQ(filter.checkPacket(&pkt, 1000, nullptr), FILTER_ACT_ALLOW);
filter.onForwardAllowed(&pkt, 1000);
EXPECT_EQ(filter.getAdvertCacheCount(), 0);
}
TEST_F(FilterTest, CheckAloneRepeatedlyNeverSpendsTheBudget) {
// the exact bug: without a commit, every check passed and nothing was ever
// suppressed, so the limiter looked like it did nothing
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 0x9A, 0x9B, 0x9C, 0x9D };
for (int i = 0; i < 5; i++) {
auto pkt = makeAdvert(key);
pkt.transport_codes[0] = (uint8_t)i;
EXPECT_EQ(filter.checkPacket(&pkt, 1000, nullptr), FILTER_ACT_ALLOW);
}
EXPECT_EQ(filter.getLimiterDrops(), 0u);
EXPECT_EQ(filter.getAdvertCacheCount(), 0);
}
// ===================================================================
// CONTENT VERDICT STASH LIFETIME
// ===================================================================
// checkContent() stashes a verdict for the packet being received, and
// checkPacket() consumes it. The stash must never outlive that one receive
// operation, or a verdict can be served to a completely unrelated packet that
// later reuses the same buffer.
TEST_F(FilterTest, PointerMismatchInvalidatesAStashedVerdict) {
ASSERT_EQ(cli(filter, "add sender=^Alice$"), "OK - rule 0 added");
auto body = makeGroupText("Alice", "hello");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto other = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto chan = channelFromStore(filter, 0);
ASSERT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body.data,
body.len, nullptr), FILTER_ACT_DROP);
const uint32_t after_content = filter.getRule(0)->hits;
// a DIFFERENT packet arrives and never gets a content scan of its own
EXPECT_EQ(forwardPacket(filter, other, 0, nullptr), FILTER_ACT_ALLOW);
// A must not be able to revive its stale stash: it is rescanned normally, and a
// content-only predicate has no content to match on this pass
EXPECT_EQ(forwardPacket(filter, pkt, 0, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getRule(0)->hits, after_content); // not counted a second time
}
TEST_F(FilterTest, UnconsumedVerdictIsClearedByTheNextPacketScan) {
ASSERT_EQ(cli(filter, "add sender=^Alice$"), "OK - rule 0 added");
auto body = makeGroupText("Alice", "hello");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto chan = channelFromStore(filter, 0);
ASSERT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body.data,
body.len, nullptr), FILTER_ACT_DROP);
// no checkPacket() for pkt at all — it was dropped before the forwarding hook
const uint32_t after_content = filter.getRule(0)->hits;
// a brand new receive starts; the stash must not answer for it
auto advert = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_ADVERT, 64, 1, 0);
EXPECT_EQ(forwardPacket(filter, advert, 0, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getRule(0)->hits, after_content); // not revived for an unrelated packet
}
TEST_F(FilterTest, BracketingClearsAVerdictThatNeverReachesTheHook) {
// this is what MyMesh::onRecvPacket() does around one receive
auto runReceive = [&](mesh::Packet& pkt) {
filter.clearContentVerdict();
forwardPacket(filter, pkt, 0, nullptr);
filter.clearContentVerdict();
};
ASSERT_EQ(cli(filter, "add sender=^Alice$"), "OK - rule 0 added");
auto body = makeGroupText("Alice", "hi");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto chan = channelFromStore(filter, 0);
// content drop, then the forwarding hook is never reached (battery/loop/off)
filter.clearContentVerdict();
ASSERT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body.data,
body.len, nullptr), FILTER_ACT_DROP);
filter.clearContentVerdict(); // receive ends
// the same buffer address coming back with different content is rescanned
runReceive(pkt);
EXPECT_EQ(filter.getRule(0)->hits, 1u);
}
TEST_F(FilterTest, EnableToggleInvalidatesAStashedVerdict) {
ASSERT_EQ(cli(filter, "add sender=^Alice$"), "OK - rule 0 added");
auto body = makeGroupText("Alice", "hi");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto chan = channelFromStore(filter, 0);
ASSERT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body.data,
body.len, nullptr), FILTER_ACT_DROP);
const uint32_t after_content = filter.getRule(0)->hits;
filter.setEnabled(false);
filter.setEnabled(true);
EXPECT_EQ(forwardPacket(filter, pkt, 0, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getRule(0)->hits, after_content);
}
TEST_F(FilterTest, RuleMutationInvalidatesAStashedVerdict) {
auto body = makeGroupText("Alice", "hi");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto chan = channelFromStore(filter, 0);
ASSERT_EQ(cli(filter, "add sender=^Alice$"), "OK - rule 0 added");
ASSERT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body.data,
body.len, nullptr), FILTER_ACT_DROP);
// remove the matching rule before the packet-level scan runs
ASSERT_EQ(cli(filter, "del 0"), "OK - rule 0 deleted");
EXPECT_EQ(forwardPacket(filter, pkt, 0, nullptr), FILTER_ACT_ALLOW);
}
TEST_F(FilterTest, ReloadInvalidatesAStashedVerdict) {
ASSERT_EQ(cli(filter, "add sender=^Alice$"), "OK - rule 0 added");
auto body = makeGroupText("Alice", "hi");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto chan = channelFromStore(filter, 0);
ASSERT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body.data,
body.len, nullptr), FILTER_ACT_DROP);
filter.load(&fs); // a reload supersedes the rule list
EXPECT_EQ(forwardPacket(filter, pkt, 0, nullptr), FILTER_ACT_ALLOW);
}
TEST_F(FilterTest, PairedContentAndPacketStillCountsExactlyOnce) {
// the whole point of the stash: within ONE receive, a content drop must be
// counted once, not twice, and must not be re-ordered
ASSERT_EQ(cli(filter, "add sender=^Alice$"), "OK - rule 0 added");
auto body = makeGroupText("Alice", "hi");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, body.len);
auto chan = channelFromStore(filter, 0);
filter.clearContentVerdict();
EXPECT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body.data,
body.len, nullptr, 10), FILTER_ACT_DROP);
EXPECT_EQ(forwardPacket(filter, pkt, 0, nullptr, 10), FILTER_ACT_DROP);
filter.clearContentVerdict();
EXPECT_EQ(filter.getRule(0)->hits, 1u); // counted once
EXPECT_EQ(filter.getAirSavedMs(), 10u); // billed once
EXPECT_EQ(filter.getAirEvaluatedMs(), 10u); // evaluated once
}
TEST_F(FilterTest, SamePointerNewPathAfterACompletedReceiveIsRescanned) {
// the packet hash excludes route/path, so only the receive bracketing and the
// pointer+hash guard stop a completed receive's verdict being reused
ASSERT_EQ(cli(filter, "add path=^10$"), "OK - rule 0 added");
auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, 10, 1, 1); // one hop
auto chan = channelFromStore(filter, 0);
uint8_t body[] = { 0, 0, 0, 0, TXT_TYPE_PLAIN, 'h', 'i' };
filter.clearContentVerdict();
filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, body, sizeof(body), nullptr);
EXPECT_EQ(forwardPacket(filter, pkt, 0, nullptr), FILTER_ACT_DROP);
filter.clearContentVerdict();
const uint32_t after_first = filter.getRule(0)->hits;
// same buffer, same payload, but the path changed: the verdict for the first
// receive must not apply to the second
pkt.setPathHashSizeAndCount(1, 1);
pkt.path[0] = 0x20;
filter.clearContentVerdict();
EXPECT_EQ(forwardPacket(filter, pkt, 0, nullptr), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getRule(0)->hits, after_first);
}
// ===================================================================
// STAGED SAVE / CRASH RECOVERY
// ===================================================================
@@ -2609,17 +2849,17 @@ TEST_F(FilterTest, ThrottleOnPacketRulesViaCheckPacket) {
uint8_t key[4] = { 0x31, 0x32, 0x33, 0x34 };
auto a1 = makeAdvert(key);
EXPECT_EQ(filter.checkPacket(&a1, 0, nullptr), FILTER_ACT_ALLOW); // free pass + first sighting
EXPECT_EQ(forwardPacket(filter, a1, 0), FILTER_ACT_ALLOW); // free pass + first sighting
EXPECT_EQ(filter.getAdvertCacheCount(), 1);
auto a2 = makeAdvert(key);
a2.payload[0] = 0x99;
EXPECT_EQ(filter.checkPacket(&a2, 5000, nullptr), FILTER_ACT_DROP); // over rate: rule decides, limiter not reached
EXPECT_EQ(forwardPacket(filter, a2, 5000), FILTER_ACT_DROP); // over rate: rule decides, limiter not reached
EXPECT_EQ(filter.getRule(0)->hits, 1u);
EXPECT_EQ(filter.getLimiterDrops(), 0u);
auto a3 = makeAdvert(key);
EXPECT_EQ(filter.checkPacket(&a3, 10000, nullptr), FILTER_ACT_DROP); // in budget: slips past, limiter drops the repeat
EXPECT_EQ(forwardPacket(filter, a3, 10000), FILTER_ACT_DROP); // in budget: slips past, limiter drops the repeat
EXPECT_EQ(filter.getRule(0)->hits, 1u);
EXPECT_EQ(filter.getLimiterDrops(), 1u);
}
@@ -2690,10 +2930,10 @@ TEST_F(FilterTest, AirSavedNotBilledForForwardAllowLimiterPass) {
// window is dropped and billed (no rule attribution)
expectOk(filter, "ratelimit advert 1");
mesh::Packet first = makeAdvert(AIR_KEY);
ASSERT_EQ(filter.checkPacket(&first, 0, nullptr, EST_AIR), FILTER_ACT_ALLOW);
ASSERT_EQ(forwardPacket(filter, first, 0, nullptr, EST_AIR), FILTER_ACT_ALLOW);
EXPECT_EQ(filter.getAirSavedMs(), 0u);
mesh::Packet again = makeAdvert(AIR_KEY);
ASSERT_EQ(filter.checkPacket(&again, 0, nullptr, EST_AIR), FILTER_ACT_DROP);
ASSERT_EQ(forwardPacket(filter, again, 0, nullptr, EST_AIR), FILTER_ACT_DROP);
EXPECT_EQ(filter.getAirSavedMs(), EST_AIR);
EXPECT_EQ(filter.getAirEvaluatedMs(), 4 * EST_AIR);
EXPECT_EQ(filter.getAirSavedPercent(), 25u);
@@ -3777,10 +4017,10 @@ TEST_F(FilterTest, LimiterStillAppliesAfterForward) {
filter.setAdvertRatelimit(48);
uint8_t key[4] = { 0x21, 0x22, 0x23, 0x24 };
auto pkt = makeAdvert(key);
EXPECT_EQ(filter.checkPacket(&pkt, 1000, nullptr), FILTER_ACT_FORWARD);
EXPECT_EQ(forwardPacket(filter, pkt, 1000), FILTER_ACT_FORWARD);
EXPECT_EQ(filter.getRule(0)->hits, 1u);
pkt.transport_codes[0] = 7;
EXPECT_EQ(filter.checkPacket(&pkt, 2000, nullptr), FILTER_ACT_DROP); // limiter wins
EXPECT_EQ(forwardPacket(filter, pkt, 2000), FILTER_ACT_DROP); // limiter wins
EXPECT_EQ(filter.getLimiterDrops(), 1u);
EXPECT_EQ(filter.getRule(0)->hits, 2u); // one scan per received advert (single pass)
}