Expand LAN to 10.0.0.0/22 with static/reserved/dynamic/spare zones
Splits the LAN into four /24 zones: 10.0.0.0/24 static (no DHCP, DNS only), 10.0.1.0/24 fixed DHCP reservations by MAC, 10.0.2.0/24 dynamic DHCP pool, 10.0.3.0/24 spare/unused. ipadm now derives the required subnet from whether a host has a MAC, auto-assigns free IPs, and auto-migrates a host's IP when its MAC is added/removed. Migrated the existing archerc80 reservation from 10.0.0.2 to 10.0.1.2. Also fixes a latent bug found while doing this: dnsmasq's SIGHUP (`systemctl reload`) only re-reads /etc/hosts, not the conf-dir files ipadm writes to, so config changes were silently not applied on reload. ipadm now restarts dnsmasq instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@@ -82,3 +83,27 @@ func findByMAC(hosts []Host, mac string, exceptIdx int) int {
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// classifyHostArgs sorts the optional trailing arguments of `ipadm -a` (ip
|
||||
// address and/or mac address, in any order, either of which may be omitted)
|
||||
// into their fields. Returns an error on unrecognized or duplicate tokens.
|
||||
func classifyHostArgs(args []string) (ip, mac string, err error) {
|
||||
for _, a := range args {
|
||||
if _, macErr := net.ParseMAC(a); macErr == nil {
|
||||
if mac != "" {
|
||||
return "", "", fmt.Errorf("MAC address given more than once: %q", a)
|
||||
}
|
||||
mac = a
|
||||
continue
|
||||
}
|
||||
if parsed := net.ParseIP(a); parsed != nil && parsed.To4() != nil {
|
||||
if ip != "" {
|
||||
return "", "", fmt.Errorf("IP address given more than once: %q", a)
|
||||
}
|
||||
ip = a
|
||||
continue
|
||||
}
|
||||
return "", "", fmt.Errorf("unrecognized argument %q (expected IP address or MAC address)", a)
|
||||
}
|
||||
return ip, mac, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user