Compare commits

...

3 commits

Author SHA1 Message Date
63fc305736
Merge branch 'feature-43' 2026-08-24 21:37:29 +02:00
ea9559c784
f-43: test: fix default route create for nothing #43
All checks were successful
Release Pipeline / set-release-target (push) Successful in 1s
Release Pipeline / upload-assets (agent.service, systemd/agent.service) (push) Successful in 3s
Release Pipeline / upload-assets (dnsmasq@.service, systemd/dnsmasq@.service) (push) Successful in 3s
Release Pipeline / upload-assets (metadata@.service, systemd/metadata@.service) (push) Successful in 3s
Release Pipeline / upload-assets (run-dnsmasq-in-netns.sh, scripts/run-dnsmasq-in-netns.sh) (push) Successful in 3s
Release Pipeline / build (agent, amd64, linux) (push) Successful in 0s
Release Pipeline / build (metadata, amd64, linux) (push) Successful in 0s
Release Pipeline / checksums (push) Successful in 4s
Release Pipeline / release (push) Successful in 11s
Release Pipeline / publish (push) Successful in 0s
Release Pipeline / build (push) Successful in 1m29s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-08-24 21:19:50 +02:00
52d214404d
f-43: dhcp: fix default route create for nothing #43
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-08-24 21:19:39 +02:00
3 changed files with 29 additions and 1 deletions

View file

@ -109,6 +109,32 @@ func TestGenerateConfig_NoDefaultGateway(t *testing.T) {
} }
} }
func TestGenerateConfig_NoDefaultGatewaySuppressesRouterOption(t *testing.T) {
conf := newConf(t, "192.168.1.0/29")
conf.DefaultGateway = nil
path, _, _ := GenerateConfig(conf)
content, _ := os.ReadFile(path)
if !strings.Contains(string(content), "\ndhcp-option=3\n") {
t.Errorf("dhcp-option=3 nue absente : sans elle dnsmasq annonce sa propre adresse comme routeur\n%s", content)
}
}
func TestGenerateConfig_VxlanEmitsNoRouterOption(t *testing.T) {
conf := newConf(t, "192.168.1.0/29")
conf.DefaultGateway = nil
path, _, _ := GenerateConfig(conf)
content, _ := os.ReadFile(path)
if !strings.Contains(string(content), "dhcp-option=121,") {
t.Fatalf("dhcp-option=121 attendue pour un subnet vxlan :\n%s", content)
}
if strings.Contains(string(content), "dhcp-option=3,") {
t.Errorf("un subnet vxlan est privé : aucune route par défaut ne doit être émise\n%s", content)
}
}
func TestGenerateConfig_ContainsVPCRoute(t *testing.T) { func TestGenerateConfig_ContainsVPCRoute(t *testing.T) {
conf := newConf(t, "192.168.1.0/29") conf := newConf(t, "192.168.1.0/29")
path, _, _ := GenerateConfig(conf) path, _, _ := GenerateConfig(conf)

View file

@ -19,6 +19,8 @@ func GenerateConfig(c Config) (string, map[string]string, error) {
} }
if c.DefaultGateway != nil { if c.DefaultGateway != nil {
fmt.Fprintf(&sb, "dhcp-option=3,%s\n", c.DefaultGateway.String()) fmt.Fprintf(&sb, "dhcp-option=3,%s\n", c.DefaultGateway.String())
} else {
fmt.Fprintf(&sb, "dhcp-option=3\n")
} }
fmt.Fprintf(&sb, "dhcp-option=6,1.1.1.1,8.8.8.8\n\n") fmt.Fprintf(&sb, "dhcp-option=6,1.1.1.1,8.8.8.8\n\n")

View file

@ -10,7 +10,7 @@ type Config struct {
Network *net.IPNet Network *net.IPNet
VPCGateway net.IP // next-hop for VPCRoute (option 121) VPCGateway net.IP // next-hop for VPCRoute (option 121)
VPCRoute *net.IPNet // if non-nil, emit dhcp-option=121,VPCRoute,VPCGateway VPCRoute *net.IPNet // if non-nil, emit dhcp-option=121,VPCRoute,VPCGateway
DefaultGateway net.IP // if non-nil, emit dhcp-option=3,DefaultGateway DefaultGateway net.IP // if non-nil, emit dhcp-option=3,DefaultGateway; if nil, emit a bare dhcp-option=3 to suppress the dnsmasq default
Name string Name string
ConfDir string ConfDir string
} }