Add encoded path-hash width selectors to forwarding rules
This commit is contained in:
1 parent
946354760b
commit
d084f5b837
12 files changed
+343
-29
No files matched your search
@@ -210,6 +210,7 @@
|
||||
hops: "all",
|
||||
channel: "#rgdata",
|
||||
incoming: "none",
|
||||
hashBytes: 0,
|
||||
pathKind: "none",
|
||||
pathPrefix: "",
|
||||
sender: "",
|
||||
@@ -255,6 +256,8 @@
|
||||
hops: normalizeHops(input.hops),
|
||||
channel: normalizeChannel(input.channel, true),
|
||||
incoming: normalizeIncoming(input.incoming),
|
||||
hashBytes: ["", "0", "any", "*"].includes(clean(input.hashBytes).toLowerCase())
|
||||
? 0 : requiredInteger(input.hashBytes, 1, 3, "Path hash bytes"),
|
||||
pathKind: enumValue(input.pathKind, PATH_KINDS, "Path matcher", "none"),
|
||||
pathPrefix: "",
|
||||
sender: clean(input.sender),
|
||||
@@ -276,6 +279,10 @@
|
||||
|
||||
if (rule.pathKind === "prefix") rule.pathPrefix = normalizePathPrefix(input.pathPrefix, 3);
|
||||
if (rule.pathKind === "prefix" && !rule.pathPrefix) throw new FilterToolError("Prefix path matcher requires at least one pbyte ID.");
|
||||
if (rule.pathKind === "prefix" && rule.hashBytes
|
||||
&& rule.pathPrefix.split(",")[0].length / 2 !== rule.hashBytes) {
|
||||
throw new FilterToolError("Path hash bytes conflicts with prefix width.");
|
||||
}
|
||||
if (rule.sender) {
|
||||
rule.sender = requiredText(rule.sender, "Sender", 31);
|
||||
if (rule.sender.includes(":")) throw new FilterToolError("Sender matcher cannot contain a colon.");
|
||||
@@ -356,6 +363,7 @@
|
||||
];
|
||||
if (rule.channel) matches.push(`channel=${quoteDsl(rule.channel)}`);
|
||||
if (rule.incoming !== "any") matches.push(`rx.scope=${quoteDsl(rule.incoming)}`);
|
||||
if (rule.hashBytes) matches.push(`hashbytes=${rule.hashBytes}`);
|
||||
if (rule.pathKind === "prefix") matches.push(`path=prefix:${rule.pathPrefix}`);
|
||||
else if (rule.pathKind !== "none") matches.push(`path=${rule.pathKind}`);
|
||||
if (rule.sender) matches.push(`sender=${quoteDsl(rule.sender)}`);
|
||||
@@ -462,6 +470,7 @@
|
||||
else if (name === "hops") rule.hops = value;
|
||||
else if (name === "channel") rule.channel = value;
|
||||
else if (name === "rx.scope") rule.incoming = value;
|
||||
else if (name === "hashbytes") rule.hashBytes = value;
|
||||
else if (name === "path") {
|
||||
if (value.toLowerCase().startsWith("prefix:")) {
|
||||
rule.pathKind = "prefix";
|
||||
@@ -568,6 +577,7 @@
|
||||
else if (rule.pathKind === "blacklist") conditions.push("a path matching the passive blacklist");
|
||||
else if (rule.pathKind.startsWith("bucket:")) conditions.push(`a path matching ${rule.pathKind}`);
|
||||
else if (rule.pathKind.startsWith("loop:")) conditions.push(`the ${rule.pathKind.slice(5)} own-ID loop threshold`);
|
||||
if (rule.hashBytes) conditions.push(`${rule.hashBytes}-byte encoded path hashes, including zero hops`);
|
||||
if (rule.sender) conditions.push(`decrypted sender "${rule.sender}"`);
|
||||
conditions.push(`traffic path ${rule.via}`);
|
||||
if (rule.tempRadio !== "any") conditions.push(`temporary radio ${rule.tempRadio}`);
|
||||
@@ -596,7 +606,9 @@
|
||||
if (rule.verdict === "drop" && rule.route === "flood" && rule.type === "any"
|
||||
&& rule.hops === "all" && !rule.channel && rule.incoming === "any"
|
||||
&& rule.pathKind === "none" && rule.tempRadio === "any") {
|
||||
warnings.push("This is a global drop rule across both flood route types.");
|
||||
warnings.push(rule.hashBytes
|
||||
? `This drops all ${rule.hashBytes}-byte path-hash packets across both flood route types.`
|
||||
: "This is a global drop rule across both flood route types.");
|
||||
}
|
||||
if (limitsRemoteManagement(rule)) {
|
||||
const zeroHop = minimumHops === 0 && rule.pathKind === "none";
|
||||
@@ -622,6 +634,7 @@
|
||||
bytes += 3 + 3 + 3;
|
||||
if (rule.channel) bytes += 3 + (rule.channel.startsWith("hash:") ? 1 : rule.channel.length === 32 || rule.channel.length === 64 ? rule.channel.length / 2 : rule.channel.length);
|
||||
if (rule.incoming !== "any") bytes += 3 + rule.incoming.length;
|
||||
if (rule.hashBytes) bytes += 3;
|
||||
if (rule.pathKind === "prefix") bytes += 4 + rule.pathPrefix.replace(/,/g, "").length / 2;
|
||||
else if (rule.pathKind !== "none") bytes += 3;
|
||||
if (rule.sender) bytes += 3 + rule.sender.length;
|
||||
@@ -965,12 +978,20 @@
|
||||
const buckets = clean(input.buckets)
|
||||
? clean(input.buckets).split(",").map((value) => requiredInteger(value, 1, 6, "Path bucket"))
|
||||
: [];
|
||||
const path = normalizePacketPath(input.path);
|
||||
const inferredWidth = path ? path.split(",")[0].length / 2 : 1;
|
||||
const hashBytes = ["", "auto"].includes(clean(input.hashBytes).toLowerCase())
|
||||
? inferredWidth : requiredInteger(input.hashBytes, 1, 3, "Packet path hash bytes");
|
||||
if (path && hashBytes !== inferredWidth) {
|
||||
throw new FilterToolError("Packet path hash bytes conflicts with received path width.");
|
||||
}
|
||||
return {
|
||||
route: enumValue(input.route, ["unscoped_flood", "scoped_flood"], "Packet route", "unscoped_flood"),
|
||||
type,
|
||||
hops: requiredInteger(input.hops, 0, 63, "Packet hops"),
|
||||
channel,
|
||||
path: normalizePacketPath(input.path),
|
||||
path,
|
||||
hashBytes,
|
||||
scopeStatus,
|
||||
scopeName: clean(input.scopeName).replace(/^#/, ""),
|
||||
regionName: clean(input.regionName),
|
||||
@@ -1017,6 +1038,7 @@
|
||||
if (packet.hops < minimum || packet.hops > maximum) misses.push(`hop ${packet.hops} is outside ${rule.hops}`);
|
||||
if (rule.channel && rule.channel !== packet.channel) misses.push("channel differs or is unavailable");
|
||||
if (!incomingMatches(rule.incoming, packet)) misses.push(`original scope does not satisfy ${rule.incoming}`);
|
||||
if (rule.hashBytes && rule.hashBytes !== packet.hashBytes) misses.push(`path hash width is ${packet.hashBytes} bytes`);
|
||||
if (rule.pathKind === "prefix") {
|
||||
const wanted = rule.pathPrefix.split(",");
|
||||
const actual = packet.path ? packet.path.split(",") : [];
|
||||
@@ -1139,6 +1161,9 @@
|
||||
}
|
||||
|
||||
const EXAMPLES = Object.freeze({
|
||||
hash_width: Object.freeze([
|
||||
{ ...documentedDropRule("drop-one-byte-paths", "any", "all"), hashBytes: 1 },
|
||||
]),
|
||||
channel_scope: Object.freeze([
|
||||
{
|
||||
...defaultRule("rgdata-scope"),
|
||||
@@ -1312,6 +1337,7 @@
|
||||
hops: field("hops").value,
|
||||
channel: field("channel").value,
|
||||
incoming: field("incoming").value,
|
||||
hashBytes: field("hash-bytes").value,
|
||||
pathKind: field("path-kind").value,
|
||||
pathPrefix: field("path-prefix").value,
|
||||
sender: field("sender").value,
|
||||
@@ -1346,6 +1372,7 @@
|
||||
hops: rule.hops,
|
||||
channel: rule.channel,
|
||||
incoming: rule.incoming,
|
||||
"hash-bytes": rule.hashBytes,
|
||||
"path-kind": rule.pathKind,
|
||||
"path-prefix": rule.pathPrefix,
|
||||
sender: rule.sender,
|
||||
@@ -1575,6 +1602,7 @@
|
||||
hops: packetField("hops").value,
|
||||
channel: packetField("channel").value,
|
||||
path: packetField("path").value,
|
||||
hashBytes: packetField("hash-bytes").value,
|
||||
scopeStatus: packetField("scope-status").value,
|
||||
scopeName: packetField("scope-name").value,
|
||||
regionName: packetField("region-name").value,
|
||||
@@ -1593,6 +1621,7 @@
|
||||
packetField("type").value = decoded.type;
|
||||
packetField("hops").value = String(decoded.hops);
|
||||
packetField("path").value = decoded.pathIds.join(",");
|
||||
packetField("hash-bytes").value = String(decoded.pathHashBytes);
|
||||
packetField("channel").value = decoded.channelHash;
|
||||
packetField("scope-status").value = decoded.routeCode === 0 ? "unknown" : "none";
|
||||
packetField("scope-name").value = "";
|
||||
|
||||
@@ -2910,9 +2910,9 @@ worked moderation examples, see [Flood Filtering and Moderation](flood_filtering
|
||||
- `get flood.rule`
|
||||
- `get flood.rule.<n>`
|
||||
- `get fr[.<n>]` (numbered form returns a complete short setter for copying)
|
||||
- `set fr[.<n>] <type> [h=<range>] [m=r|b|c|bc] [c=<channel>] <d|s=<scope>|r=<region>|q=<N>|r|s> [...]`
|
||||
- `set fr[.<n>] <type> [h=<range>] [m=r|b|c|bc] [c=<channel>] [pb=any|1|2|3] <d|s=<scope>|r=<region>|q=<N>|r|s> [...]`
|
||||
- `del fr.<n>` or `del fr all`
|
||||
- `set flood.rule[.<n>] type=<type> [mode=radio|bridge|cross|bridge,cross] [hops=<range>] [channel=<channel>] [prefix=<path-prefix>] [in=<input-scope>] <drop|scope=<name>|region=<name>|rate=<N>/min|retry|stop> [priority=<0-255>] [tx=slow] [suspend=tempradio]`
|
||||
- `set flood.rule[.<n>] type=<type> [mode=radio|bridge|cross|bridge,cross] [hops=<range>] [channel=<channel>] [hashbytes=any|1|2|3] [prefix=<path-prefix>] [in=<input-scope>] <drop|scope=<name>|region=<name>|rate=<N>/min|retry|stop> [priority=<0-255>] [tx=slow] [suspend=tempradio]`
|
||||
- `del flood.rule.<n>`
|
||||
- `del flood.rule all`
|
||||
- `get flood.filter`
|
||||
@@ -2968,6 +2968,12 @@ compile this table.
|
||||
MAC/decrypt check with the Public channel key. That distinguishes an ordinary
|
||||
`0x11` collision, but it is channel authentication rather than sender
|
||||
authentication: the group MAC is two bytes and the Public key is shared.
|
||||
- `hashbytes=any|1|2|3`: Optional encoded path-hash width, independent of hop
|
||||
count and hash value. Omitted, `any`, or `*` matches every supported width.
|
||||
Width-specific rules also match zero-hop packets. Four-byte hashes are
|
||||
reserved and unsupported. A simultaneous `prefix=` must use the same width.
|
||||
Example: `set fr any pb=1 d` drops all 1-byte floods from forwarding, including
|
||||
relayed login/admin traffic, but not direct packets or local delivery.
|
||||
- `prefix=<ID[,ID...]>`: Optional ordered source-path prefix of one to three
|
||||
pbyte IDs. IDs must all be 2, 4, or 6 hex characters, matching a packet's
|
||||
1-, 2-, or 3-byte pbyte width. `path=<prefix>` is an alias.
|
||||
@@ -3217,6 +3223,7 @@ have the same behavior as their long forms.
|
||||
| `hops=...` | Positional range or `h=...`; `*` means `all` |
|
||||
| `mode=radio/bridge/cross/bridge,cross` | `m=r/b/c/bc` (choose one value) |
|
||||
| `channel=...`, `prefix=...` | `c=...`, `p=...` |
|
||||
| `hashbytes=any/1/2/3` | `pb=*/1/2/3` (choose one value) |
|
||||
| `path=blacklist` | `p=bl` (repeater only) |
|
||||
| `in=any/none/scoped/allowed/unknown` | `i=*/n/s/a/u` (choose one value) |
|
||||
| `in=scope:name`, `in=region:name` | `i=s:name`, `i=r:name` |
|
||||
|
||||
@@ -24,6 +24,15 @@ Start with an example or build a rule, then test the draft against packet facts
|
||||
in the simulator below. The examples draw from
|
||||
[Flood Filtering and Moderation](flood_filtering.md).
|
||||
|
||||
To match every 1-byte path, select **Path hash width → 1 byte**, **type → ANY**,
|
||||
all hops, no channel/input-scope restriction, and no prefix condition (or use
|
||||
the 1-byte example below). This also matches zero-hop packets. The firmware command is
|
||||
`set fr any pb=1 d` (or `set flood.rule type=any hashbytes=1 drop`); it adds a
|
||||
forwarding-drop rule, including for relayed login/admin floods. Direct routes
|
||||
and local delivery remain unaffected. Width-only rules require updated
|
||||
firmware. The simulator's policy definitions remain design-preview text, not
|
||||
installable commands.
|
||||
|
||||
<div class="filter-tool" data-filter-tool>
|
||||
<div class="filter-management-safety" role="note">
|
||||
<strong>Remote login and direct routes</strong>
|
||||
@@ -68,6 +77,7 @@ in the simulator below. The examples draw from
|
||||
<tr><td><code>channel=</code></td><td><code>*</code> means no channel condition; a name or key authenticates one group channel; <code>hash:XX</code> is an unauthenticated one-byte fallback</td></tr>
|
||||
<tr><td><code>rx.scope=</code></td><td>Original incoming transport scope</td></tr>
|
||||
<tr><td><code>path=</code></td><td>Path prefix, blacklist, bucket, or loop match</td></tr>
|
||||
<tr><td><code>hashbytes=</code></td><td>Encoded path-hash width: 1, 2, or 3 bytes, including zero-hop packets</td></tr>
|
||||
<tr><td><code>tempradio=</code></td><td>Temporary-radio state</td></tr>
|
||||
<tr><td><code>do drop</code></td><td>Do not retransmit</td></tr>
|
||||
<tr><td><code>do scope=</code></td><td>Set the outgoing transport scope</td></tr>
|
||||
@@ -82,6 +92,10 @@ in the simulator below. The examples draw from
|
||||
</p>
|
||||
</div>
|
||||
<div class="filter-example-grid">
|
||||
<button type="button" data-example="hash_width">
|
||||
<span>Drop all floods with 1-byte path hashes (including zero hops)</span>
|
||||
<code>when type=any hops=all hashbytes=1 do drop</code>
|
||||
</button>
|
||||
<button type="button" data-example="channel_scope">
|
||||
<span>Set #BlackHole86 scope on all #rgdata group traffic</span>
|
||||
<code>when type=class:group hops=all channel=#rgdata do scope=#BlackHole86 timing=fast</code>
|
||||
@@ -185,6 +199,15 @@ in the simulator below. The examples draw from
|
||||
<option value="region:west"></option>
|
||||
</datalist>
|
||||
</label>
|
||||
<label>
|
||||
Path hash width
|
||||
<select data-field="hash-bytes">
|
||||
<option value="0">Any width</option>
|
||||
<option value="1">1 byte</option>
|
||||
<option value="2">2 bytes</option>
|
||||
<option value="3">3 bytes</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Path matcher
|
||||
<select data-field="path-kind">
|
||||
@@ -497,6 +520,15 @@ in the simulator below. The examples draw from
|
||||
Channel
|
||||
<input data-packet="channel" value="#rgdata" placeholder="#name, public, hash:A7, key, or blank">
|
||||
</label>
|
||||
<label>
|
||||
Encoded path hash width
|
||||
<select data-packet="hash-bytes">
|
||||
<option value="auto">Infer from path (empty defaults to 1 byte)</option>
|
||||
<option value="1">1 byte</option>
|
||||
<option value="2">2 bytes</option>
|
||||
<option value="3">3 bytes</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Received pbyte path
|
||||
<input data-packet="path" value="860C,12A4" placeholder="same-width IDs">
|
||||
|
||||
+26
-1
@@ -445,7 +445,7 @@ The extended form is:
|
||||
|
||||
```text
|
||||
set flood.rule[.<slot>] type=<type> [mode=radio|bridge|cross|bridge,cross]
|
||||
[hops=<range>] [channel=<channel>]
|
||||
[hops=<range>] [channel=<channel>] [hashbytes=any|1|2|3]
|
||||
[prefix=<ID[,ID...]>] [in=<input-scope>] <action> [rate=<N>/min]
|
||||
[priority=<0-255>] [stop] [tx=fast|slow] [suspend=tempradio]
|
||||
get flood.rule
|
||||
@@ -495,6 +495,12 @@ Match fields:
|
||||
collision, while `public` verifies and decrypts with the Public key. This is
|
||||
channel authentication, not sender authentication: the group MAC is two
|
||||
bytes and the Public key is shared.
|
||||
- `hashbytes=any|1|2|3` matches the encoded width of each path hash, independent
|
||||
of its value or the hop count. Omitted or `any` means any width; `*` is an
|
||||
alias for `any`. It includes zero-hop packets carrying the selected width.
|
||||
Four-byte path hashes are reserved and unsupported. Combine this with other
|
||||
match fields as needed; a `prefix=` must have the same width when both are
|
||||
specified. The compact alias is `pb=`.
|
||||
- `prefix=` is a source-path prefix containing one to three comma-separated
|
||||
pbyte IDs. Every ID must use the packet's pbyte width: 2, 4, or 6 hex
|
||||
characters for 1-, 2-, or 3-byte paths. Order matters and matching begins at
|
||||
@@ -684,6 +690,7 @@ set fr.3 any c=#wardriving m=bc d
|
||||
| `mode=radio`, `bridge`, `cross`, `bridge,cross` | `m=r`, `m=b`, `m=c`, `m=bc` | Select the admission path. Omitted means radio; `cb`, `b,c`, and `c,b` also mean both transport paths. |
|
||||
| `channel=...` | `c=...` | Same authenticated name/key or explicit `hash:XX` matcher. |
|
||||
| `prefix=...` | `p=...` | Ordered path prefix. |
|
||||
| `hashbytes=any`, `1`, `2`, or `3` | `pb=*`, `1`, `2`, or `3` | Encoded path-hash width, even with zero hops. |
|
||||
| `path=blacklist` | `p=bl` | Shared unordered blacklist; repeater only. |
|
||||
| `in=any`, `none`, `scoped`, `allowed`, `unknown` | `i=*`, `i=n`, `i=s`, `i=a`, `i=u` | Incoming scope condition. |
|
||||
| `in=scope:name`, `in=region:name` | `i=s:name`, `i=r:name` | Match a specific incoming scope or region. |
|
||||
@@ -698,6 +705,24 @@ The `=` distinguishes `s=name` (scope) from `s` (stop), and `r=name`
|
||||
(region) from `r` (retry). Short forms keep the same action restrictions;
|
||||
for example, `m=bc r` is rejected because transport rules cannot enable retries.
|
||||
|
||||
### Filter every 1-byte flood path
|
||||
|
||||
```text
|
||||
set flood.rule type=any hashbytes=1 drop
|
||||
```
|
||||
|
||||
The equivalent short command is `set fr any pb=1 d`. This adds a rule in a free
|
||||
slot without replacing the default rules. It stops this node forwarding all
|
||||
1-byte flood packets, including advertisements and relayed login/admin traffic;
|
||||
direct routes and local delivery are unchanged. Use a narrower `type=` or
|
||||
`channel=` if those floods must remain reachable. Use `hashbytes=2` or `3` for
|
||||
the other supported widths, and `get fr.<slot>` to copy the saved command.
|
||||
|
||||
Width-only rules require updated firmware. Existing rules remain unchanged and
|
||||
the table uses no additional RAM or storage. Before downgrading to firmware
|
||||
without this selector, remove width-only rules: its older reader considers them
|
||||
invalid and can reset the rule table to defaults.
|
||||
|
||||
```text
|
||||
get fr.3
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user