From 1791196c87f7dae5a9d84e0c648c83c1c366cb90 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sun, 26 Apr 2026 15:04:24 +0200 Subject: [PATCH] f-21: lib: add ebatable wrapper Signed-off-by: GnomeZworc --- internal/ebtables/ebtables.go | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 internal/ebtables/ebtables.go diff --git a/internal/ebtables/ebtables.go b/internal/ebtables/ebtables.go new file mode 100644 index 0000000..31e276b --- /dev/null +++ b/internal/ebtables/ebtables.go @@ -0,0 +1,58 @@ +package ebtables + +import ( + "fmt" + "os/exec" +) + +func addRule(args ...string) error { + return exec.Command("ebtables", append([]string{"-A"}, args...)...).Run() +} + +func deleteRule(args ...string) error { + return exec.Command("ebtables", append([]string{"-D"}, args...)...).Run() +} + +func DropARPToGateway(bridge, gatewayIP string) error { + if err := addRule("FORWARD", + "--out-interface", bridge, + "-p", "arp", + "--arp-op", "Request", + "--arp-ip-dst", gatewayIP, + "-j", "DROP"); err != nil { + return fmt.Errorf("ebtables arp rule: %w", err) + } + return nil +} + +func DropDHCP(bridge string) error { + if err := addRule("FORWARD", + "--out-interface", bridge, + "-p", "IPv4", + "--ip-protocol", "udp", + "--ip-source-port", "67:68", + "--ip-destination-port", "67:68", + "-j", "DROP"); err != nil { + return fmt.Errorf("ebtables dhcp rule: %w", err) + } + return nil +} + +func DeleteARPToGateway(bridge, gatewayIP string) error { + return deleteRule("FORWARD", + "--out-interface", bridge, + "-p", "arp", + "--arp-op", "Request", + "--arp-ip-dst", gatewayIP, + "-j", "DROP") +} + +func DeleteDHCP(bridge string) error { + return deleteRule("FORWARD", + "--out-interface", bridge, + "-p", "IPv4", + "--ip-protocol", "udp", + "--ip-source-port", "67:68", + "--ip-destination-port", "67:68", + "-j", "DROP") +}