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:
parent
6c35ebdff4
commit
12d69798fb
9 changed files with 116 additions and 4 deletions
|
|
@ -316,3 +316,27 @@ func TestGenerateConfig_MissingInterfaceIPIsAnError(t *testing.T) {
|
|||
t.Error("sans interface_ip aucune route metadata n'est possible : il faut échouer, pas écrire une conf muette")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateConfig_ListensOnTheAnycastGateway(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29")
|
||||
conf.Listen = "gw-s9r1"
|
||||
conf.Except = "br-s9r1"
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
for _, line := range []string{"\ninterface=gw-s9r1\n", "\nexcept-interface=br-s9r1\n"} {
|
||||
if !strings.Contains(string(content), line) {
|
||||
t.Errorf("%q absente du fichier généré :\n%s", strings.TrimSpace(line), content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateConfig_NoInterfaceLinesByDefault(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29")
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
if strings.Contains(string(content), "interface=") {
|
||||
t.Errorf("aucune directive d'interface attendue sans Listen :\n%s", content)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ func GenerateConfig(c Config) (string, map[string]string, error) {
|
|||
|
||||
var sb strings.Builder
|
||||
fmt.Fprintf(&sb, "no-resolv\n")
|
||||
if c.Listen != "" {
|
||||
fmt.Fprintf(&sb, "interface=%s\n", c.Listen)
|
||||
}
|
||||
if c.Except != "" {
|
||||
fmt.Fprintf(&sb, "except-interface=%s\n", c.Except)
|
||||
}
|
||||
fmt.Fprintf(&sb, "dhcp-range=%s,static,%s,12h\n", c.Network.IP.String(), mask)
|
||||
fmt.Fprintf(&sb, "dhcp-option=121,%s\n", strings.Join(classlessRoutes(c), ","))
|
||||
if c.DefaultGateway != nil {
|
||||
|
|
|
|||
|
|
@ -13,4 +13,6 @@ type Config struct {
|
|||
DefaultGateway net.IP // if non-nil, default route via option 3 and 0.0.0.0/0 in option 121
|
||||
Name string
|
||||
ConfDir string
|
||||
Listen string
|
||||
Except string
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue