f-28: fix: dhcp do not emit local default route

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-05-18 22:19:00 +02:00
commit 2504b435a3
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
4 changed files with 29 additions and 13 deletions

View file

@ -52,10 +52,11 @@ func newConf(t *testing.T, cidr string) Config {
t.Helper() t.Helper()
_, network, _ := net.ParseCIDR(cidr) _, network, _ := net.ParseCIDR(cidr)
return Config{ return Config{
Network: network, Network: network,
Gateway: net.ParseIP("192.168.1.1").To4(), Gateway: net.ParseIP("192.168.1.1").To4(),
Name: "test", DefaultRoute: true,
ConfDir: t.TempDir(), Name: "test",
ConfDir: t.TempDir(),
} }
} }
@ -94,6 +95,17 @@ func TestGenerateConfig_ContainsGateway(t *testing.T) {
} }
} }
func TestGenerateConfig_NoDefaultRoute(t *testing.T) {
conf := newConf(t, "192.168.1.0/29")
conf.DefaultRoute = false
path, _, _ := GenerateConfig(conf)
content, _ := os.ReadFile(path)
if strings.Contains(string(content), "dhcp-option=3,") {
t.Errorf("dhcp-option=3 présente alors que DefaultRoute=false :\n%s", content)
}
}
func TestGenerateConfig_ContainsDhcpRange(t *testing.T) { func TestGenerateConfig_ContainsDhcpRange(t *testing.T) {
_, network, _ := net.ParseCIDR("10.10.0.0/24") _, network, _ := net.ParseCIDR("10.10.0.0/24")
conf := Config{ conf := Config{

View file

@ -14,7 +14,9 @@ func GenerateConfig(c Config) (string, map[string]string, error) {
var sb strings.Builder var sb strings.Builder
fmt.Fprintf(&sb, "no-resolv\n") fmt.Fprintf(&sb, "no-resolv\n")
fmt.Fprintf(&sb, "dhcp-range=%s,static,%s,12h\n", c.Network.IP.String(), mask) fmt.Fprintf(&sb, "dhcp-range=%s,static,%s,12h\n", c.Network.IP.String(), mask)
fmt.Fprintf(&sb, "dhcp-option=3,%s\n", c.Gateway.String()) if c.DefaultRoute {
fmt.Fprintf(&sb, "dhcp-option=3,%s\n", c.Gateway.String())
}
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")
entries := make(map[string]string) entries := make(map[string]string)

View file

@ -5,8 +5,9 @@ import (
) )
type Config struct { type Config struct {
Network *net.IPNet Network *net.IPNet
Gateway net.IP Gateway net.IP
Name string DefaultRoute bool
ConfDir string Name string
ConfDir string
} }

View file

@ -136,10 +136,11 @@ func setupVxlanHost(d subnetData, vethE string) error {
func startDHCP(db *badger.DB, subnetName string, d subnetData) error { func startDHCP(db *badger.DB, subnetName string, d subnetData) error {
conf := dhcp.Config{ conf := dhcp.Config{
Network: d.cidr, Network: d.cidr,
Gateway: d.interfaceIP, Gateway: d.interfaceIP,
Name: d.vpc + "_" + d.bridge, DefaultRoute: d.mode == "vxlan",
ConfDir: "/etc/dnsmasq.d", Name: d.vpc + "_" + d.bridge,
ConfDir: "/etc/dnsmasq.d",
} }
_, entries, err := dhcp.GenerateConfig(conf) _, entries, err := dhcp.GenerateConfig(conf)
if err != nil { if err != nil {