E6b: cut a derived rule's comment to nftables' 128 bytes with a count

nftables refuses a rule comment past 128 bytes, and with it the whole
table, so a port shared by enough modules took every opening down. The
comment is a label: past the bound its module list is cut with a count of
the rest; the whole list stands in the table's lines above the rule.

Builds: design 47 H2 §813 (4); H-A-357, H-A-384 (1)
This commit is contained in:
2026-11-22 00:11:18 +01:00
parent f5dcea2f10
commit fea6836f9e
2 changed files with 24 additions and 3 deletions
@@ -84,6 +84,9 @@ func TestALocalNetworkPortIsAdmittedFromItsNetworksAndTheMesh(t *testing.T) {
{Port: 1883, Protocol: "tcp", From: mcat.FromLocalNetwork, Because: []string{"mosquitto"}},
{Port: 5432, Protocol: "tcp", From: mcat.FromMesh, Because: []string{"postgres"}},
{Port: 443, Protocol: "tcp", From: mcat.FromEverywhere, Because: []string{"caddy", "forge"}},
// A shared port whose module list would pass nftables' 128 bytes: the label is cut with a count (H-A-384 (1)).
{Port: 8443, Protocol: "tcp", From: mcat.FromEverywhere, Because: []string{"mesh-delivery-pipeline", "mesh-delivery-builder",
"mesh-delivery-assigner", "mesh-delivery-indexer", "mesh-delivery-gate", "mesh-delivery-teller"}},
}
local := CountedLocalNetworks(judged(t))
out := AsNftablesWithLocal(rules, []string{"10.10.0.1", "10.10.0.4"}, false, nil,
@@ -102,11 +105,18 @@ func TestALocalNetworkPortIsAdmittedFromItsNetworksAndTheMesh(t *testing.T) {
`tcp dport 5432 accept comment "derived postgres tcp/5432 scope private-network"`,
"\t\ttcp dport 443 accept comment \"derived caddy,forge tcp/443 scope any\"\n",
"\t\tct original proto-dst 443 accept comment \"derived caddy,forge tcp/443 scope any\"\n",
`tcp dport 8443 accept comment "derived mesh-delivery-pipeline,mesh-delivery-builder,mesh-delivery-assigner,mesh-delivery-indexer,+2 tcp/8443 scope any"`,
"\t\t# mesh-delivery-teller\n",
} {
if !strings.Contains(out, want) {
t.Errorf("the rule set lacks %q:\n%s", want, out)
}
}
for _, line := range strings.Split(out, "\n") {
if _, comment, ok := strings.Cut(line, ` comment "`); ok && len(strings.TrimSuffix(comment, `"`)) > commentMost {
t.Errorf("a comment passes nftables' %d bytes: %s", commentMost, line)
}
}
if strings.Contains(out, "203.0.113") {
t.Errorf("the public subnet reached the rule set:\n%s", out)
}