f-25: dhcp: fill db with dhcp data
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
371ec75468
commit
b4092fbe02
5 changed files with 41 additions and 13 deletions
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func GenerateConfig(c Config) (string, error) {
|
||||
func GenerateConfig(c Config) (string, map[string]string, error) {
|
||||
mask := fmt.Sprintf("%d.%d.%d.%d", c.Network.Mask[0], c.Network.Mask[1], c.Network.Mask[2], c.Network.Mask[3])
|
||||
|
||||
var sb strings.Builder
|
||||
|
|
@ -17,18 +17,20 @@ func GenerateConfig(c Config) (string, error) {
|
|||
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")
|
||||
|
||||
entries := make(map[string]string)
|
||||
i := 0
|
||||
for ip := cloneIP(c.Network.IP); c.Network.Contains(ip); incrementIP(ip) {
|
||||
fmt.Fprintf(&sb, "dhcp-host=00:22:33:%02X:%02X:%02X,%s\n",
|
||||
(i>>16)&0xFF, (i>>8)&0xFF, i&0xFF, ip)
|
||||
mac := fmt.Sprintf("00:22:33:%02X:%02X:%02X", (i>>16)&0xFF, (i>>8)&0xFF, i&0xFF)
|
||||
fmt.Fprintf(&sb, "dhcp-host=%s,%s\n", mac, ip)
|
||||
entries[ip.String()] = mac
|
||||
i++
|
||||
}
|
||||
|
||||
outPath := filepath.Join(c.ConfDir, c.Name+".conf")
|
||||
if err := os.MkdirAll(c.ConfDir, 0755); err != nil {
|
||||
return "", err
|
||||
return "", nil, err
|
||||
}
|
||||
return outPath, os.WriteFile(outPath, []byte(sb.String()), 0644)
|
||||
return outPath, entries, os.WriteFile(outPath, []byte(sb.String()), 0644)
|
||||
}
|
||||
|
||||
func incrementIP(ip net.IP) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue