f-42: vpc: br-public du netns fermé, br_netfilter coupé dans le netns #42

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-30 00:23:40 +01:00
commit 1df0d2dad6
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
8 changed files with 128 additions and 0 deletions

28
internal/nft/guard.go Normal file
View file

@ -0,0 +1,28 @@
package nft
import (
"fmt"
"strings"
)
var guardChains = []natChain{
{"in-", "filter", "input", "filter"},
{"fwd-", "filter", "forward", "filter"},
}
func guardScript(bridge string) string {
var b strings.Builder
fmt.Fprintf(&b, "add table ip %s\n", Table)
for _, c := range guardChains {
name := c.declare(&b, bridge)
fmt.Fprintf(&b, "add rule ip %s %s iifname %q drop\n", Table, name, bridge)
}
return b.String()
}
func SetBridgeGuard(bridge string) error {
if err := apply(guardScript(bridge)); err != nil {
return fmt.Errorf("guard %s: %w", bridge, err)
}
return nil
}

View file

@ -0,0 +1,17 @@
package nft
import "testing"
func TestGuardScript(t *testing.T) {
want := `add table ip two
add chain ip two in-br-public { type filter hook input priority filter; policy accept; }
flush chain ip two in-br-public
add rule ip two in-br-public iifname "br-public" drop
add chain ip two fwd-br-public { type filter hook forward priority filter; policy accept; }
flush chain ip two fwd-br-public
add rule ip two fwd-br-public iifname "br-public" drop
`
if got := guardScript("br-public"); got != want {
t.Errorf("script :\n%s\nattendu :\n%s", got, want)
}
}