Support 2+ path-hash width filters

This commit is contained in:
mikecarper committed 2026-10-02 10:21:17 -07:00
1 parent d084f5b837
commit 7324bf06ef
12 files changed
+202 -37

No files matched your search

+27 -2
View File
@@ -407,6 +407,25 @@ inline bool pathMatchesConfiguredIds(const mesh::Packet* packet,
// A nonzero width with no prefix hops is a width-only matcher. Reuse the
// existing FPF7 fields so runtime RAM and serialized row sizes stay fixed.
// The high-bit selector is a rule-storage value, never a packet hash width.
static constexpr uint8_t RULE_HASH_BYTES_TWO_PLUS = 0x82;
inline const char* pathHashBytesName(uint8_t width) {
switch (width) {
case 1: return "1";
case 2: return "2";
case 3: return "3";
case RULE_HASH_BYTES_TWO_PLUS: return "2+";
default: return "any";
}
}
inline bool pathHashBytesMatch(uint8_t selector, uint8_t actual_width) {
return actual_width >= 1 && actual_width <= 3
&& (selector == 0 || selector == actual_width
|| (selector == RULE_HASH_BYTES_TWO_PLUS && actual_width >= 2));
}
inline bool parsePathHashBytes(const char* text, uint8_t& width) {
if (text == NULL) return false;
if (strcmp(text, "*") == 0
@@ -414,6 +433,10 @@ inline bool parsePathHashBytes(const char* text, uint8_t& width) {
width = 0;
return true;
}
if (strcmp(text, "2+") == 0) {
width = RULE_HASH_BYTES_TWO_PLUS;
return true;
}
if (text[0] >= '1' && text[0] <= '3' && text[1] == 0) {
width = (uint8_t)(text[0] - '0');
return true;
@@ -424,6 +447,7 @@ inline bool parsePathHashBytes(const char* text, uint8_t& width) {
inline bool pathMatcherValid(uint8_t width, uint8_t prefix_hops,
bool blacklist) {
return (width == 0 && prefix_hops == 0)
|| (width == RULE_HASH_BYTES_TWO_PLUS && prefix_hops == 0)
|| (width >= 1 && width <= 3 && prefix_hops <= 3
&& (prefix_hops == 0 || !blacklist));
}
@@ -433,8 +457,9 @@ inline bool pathStartsWith(const mesh::Packet* packet,
uint8_t prefix_hops,
const uint8_t* prefix) {
if (hash_size == 0 && prefix_hops == 0) return true;
if (packet == NULL || hash_size < 1 || hash_size > 3
|| packet->getPathHashSize() != hash_size
if (packet == NULL
|| (prefix_hops != 0 && (hash_size < 1 || hash_size > 3))
|| !pathHashBytesMatch(hash_size, packet->getPathHashSize())
|| packet->getPathHashCount() < prefix_hops) {
return false;
}
+1 -1
View File
@@ -82,7 +82,7 @@ bool formatCompact(char* out, size_t capacity, unsigned slot, const Entry& entry
}
if (entry.channel_key_len != 0) text.append(" c=%s", entry.channel_name);
if (entry.path_hops == 0 && entry.path_hash_size != 0)
text.append(" pb=%u", (unsigned)entry.path_hash_size);
text.append(" pb=%s", pathHashBytesName(entry.path_hash_size));
if (entry.match_blacklisted_path) text.append(" p=bl");
else if (entry.path_hops) {
text.append(" p=");