f-76: vm: filtrage nftables par tap, champ dhcp_server, watchdog #76

Chaque NIC a sa chaîne pre-tap<id>, posée avant le tap et retirée après :
MAC, ARP et IPv4 source limités à ceux de la NIC (0.0.0.0 pour le client
DHCP et la sonde ARP), réponses DHCP refusées sauf si dhcp_server, seuls
IPv4, ARP et IPv6 émis. Le watchdog vérifie la chaîne de chaque NIC.

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-25 22:59:45 +01:00
commit 74bfda7004
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
16 changed files with 295 additions and 15 deletions

View file

@ -36,10 +36,16 @@ func mustParse(t *testing.T, data string) table {
func TestRuleTexts(t *testing.T) {
for got, want := range map[string]string{
DropSourceMAC("02:01:00:00:0b:5f"): "ether saddr 02:01:00:00:0b:5f drop",
DropARPRequestTo("10.33.0.1"): "arp operation request arp daddr ip 10.33.0.1 drop",
DropARPFrom("10.33.0.1"): "arp saddr ip 10.33.0.1 drop",
DropDHCPFrom("10.33.0.1"): "ip saddr 10.33.0.1 udp sport 67-68 udp dport 67-68 drop",
DropSourceMAC("02:01:00:00:0b:5f"): "ether saddr 02:01:00:00:0b:5f drop",
DropARPRequestTo("10.33.0.1"): "arp operation request arp daddr ip 10.33.0.1 drop",
DropARPFrom("10.33.0.1"): "arp saddr ip 10.33.0.1 drop",
DropDHCPFrom("10.33.0.1"): "ip saddr 10.33.0.1 udp sport 67-68 udp dport 67-68 drop",
DropSourceMACOtherThan("52:54:00:00:0a:05"): "ether saddr != 52:54:00:00:0a:05 drop",
DropEtherTypesOtherThanIPAndARP(): "ether type != { ip, arp, ip6 } drop",
DropARPSenderMACOtherThan("52:54:00:00:0a:05"): "arp saddr ether != 52:54:00:00:0a:05 drop",
DropARPSenderIPOtherThan("10.0.0.5"): "arp saddr ip != { 0.0.0.0, 10.0.0.5 } drop",
DropDHCPServer(): "udp sport 67 drop",
DropIPSourceOtherThan("10.0.0.5"): "ip saddr != { 0.0.0.0, 10.0.0.5 } drop",
} {
if got != want {
t.Errorf("%q, %q attendu", got, want)
@ -47,6 +53,13 @@ func TestRuleTexts(t *testing.T) {
}
}
func TestDropUnspecifiedSourceOutsideDHCP(t *testing.T) {
want := "ip saddr 0.0.0.0 ip protocol != udp drop|ip saddr 0.0.0.0 udp dport != 67 drop"
if got := strings.Join(DropUnspecifiedSourceOutsideDHCP(), "|"); got != want {
t.Errorf("%q, %q attendu", got, want)
}
}
func TestSetScriptOnAnEmptyNetns(t *testing.T) {
want := `add table bridge two
add map bridge two pre_ports { type ifname : verdict; }