f-57: dhcp: écoute sur le macvlan de la gateway anycast, dnsmasq et serveur intégré #57

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-13 14:51:40 +02:00
commit 12d69798fb
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
9 changed files with 116 additions and 4 deletions

View file

@ -11,6 +11,7 @@ type Subnet struct {
Name string
VPC string
Bridge string
Listen string
Network *net.IPNet
InterfaceIP net.IP
VPCRoute *net.IPNet

View file

@ -28,7 +28,7 @@ func (Dnsmasq) Unit(s Subnet) string {
}
func (b Dnsmasq) config(s Subnet) dhcp.Config {
return dhcp.Config{
c := dhcp.Config{
Network: s.Network,
Name: s.Instance(),
ConfDir: b.confDir(),
@ -36,6 +36,11 @@ func (b Dnsmasq) config(s Subnet) dhcp.Config {
VPCRoute: s.VPCRoute,
DefaultGateway: s.DefaultGateway,
}
if s.Listen != "" && s.Listen != s.Bridge {
c.Listen = s.Listen
c.Except = s.Bridge
}
return c
}
func (b Dnsmasq) ConfigureSubnet(s Subnet) error {

View file

@ -111,3 +111,22 @@ func TestDnsmasqSetVM_RejectsAVMWithoutReservation(t *testing.T) {
t.Fatal("a vm with no reservation would get no address: that must be reported")
}
}
func TestDnsmasqConfig_ListenOnGatewayExcludesTheBridge(t *testing.T) {
c := Dnsmasq{}.config(Subnet{VPC: "vp-s9", Bridge: "br-s9r1", Listen: "gw-s9r1"})
if c.Listen != "gw-s9r1" || c.Except != "br-s9r1" {
t.Errorf("Listen %q, Except %q : gw-s9r1 et br-s9r1 attendus", c.Listen, c.Except)
}
if c.Name != "vp-s9_br-s9r1" {
t.Errorf("instance %q : le nom doit rester celui du bridge", c.Name)
}
}
func TestDnsmasqConfig_NoListenKeepsTheCommandLineInterface(t *testing.T) {
for _, listen := range []string{"", "br-s9r1"} {
c := Dnsmasq{}.config(Subnet{VPC: "vp-s9", Bridge: "br-s9r1", Listen: listen})
if c.Listen != "" || c.Except != "" {
t.Errorf("Listen=%q : Listen %q, Except %q, vides attendus", listen, c.Listen, c.Except)
}
}
}