f-86: agent: dummy, DNAT et open par VPC, DHCP 6 et 42, watchdog #86

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-25 20:45:24 +01:00
commit 2e24a5da0a
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
16 changed files with 565 additions and 13 deletions

View file

@ -0,0 +1,48 @@
package iptables
import (
"reflect"
"strings"
"testing"
)
func TestHostSvcJump_OnlyLocalDestinations(t *testing.T) {
want := []string{"PREROUTING", "-m", "addrtype", "--dst-type", "LOCAL", "-j", "TWO-HOSTSVC"}
if got := hostSvcJump(); !reflect.DeepEqual(got, want) {
t.Errorf("jump = %v, want %v: traffic to an outside resolver must not be hijacked", got, want)
}
}
func TestHostSvcRules_ExclusionsComeFirst(t *testing.T) {
rules := hostSvcRules("169.254.169.253")
if len(rules) != 5 {
t.Fatalf("%d rules, want 2 exclusions and 3 redirections: %v", len(rules), rules)
}
for i, iface := range []string{"br-public", "l3-+"} {
want := []string{"TWO-HOSTSVC", "-i", iface, "-j", "RETURN"}
if !reflect.DeepEqual(rules[i], want) {
t.Errorf("rule %d = %v, want %v: the public segment and the vrf link must never reach the relay", i, rules[i], want)
}
}
}
func TestHostSvcRules_RedirectDNSAndNTPOnly(t *testing.T) {
var got []string
for _, rule := range hostSvcRules("169.254.169.253") {
if rule[len(rule)-3] != "DNAT" {
continue
}
if rule[len(rule)-1] != "169.254.169.253" {
t.Errorf("rule %v does not target 169.254.169.253", rule)
}
got = append(got, strings.Join(rule[1:7], " "))
}
want := []string{
"-p udp -m udp --dport 53",
"-p tcp -m tcp --dport 53",
"-p udp -m udp --dport 123",
}
if !reflect.DeepEqual(got, want) {
t.Errorf("redirections = %v, want %v", got, want)
}
}