Development

This commit is contained in:
Matthew Grotke 2026-06-03 02:57:59 -04:00
parent d6f1a74684
commit f518f0e86b
3 changed files with 25 additions and 20 deletions

View file

@ -38,6 +38,7 @@ CONFIG_FILE = SCRIPT_DIR / "config.json"
CACHE_SERVICE_FILE = SCRIPT_DIR / ".ddns-last-service"
LOG_FILE = SCRIPT_DIR / "ddns.log"
RADIUS_LOG_FILE = Path("/var/log/freeradius/radius.log")
ARP_CACHE_FILE = Path("/var/lib/misc/arp-cache.json")
# log is assigned in setup_logging() after config is loaded
log = None
@ -534,6 +535,25 @@ def rotate_radius_log(radius_cfg):
# Main
# ===================================================================
def refresh_arp_cache():
try:
result = subprocess.run(['ip', 'neigh'], capture_output=True, text=True, timeout=5)
entries = {}
for line in result.stdout.splitlines():
parts = line.split()
if 'lladdr' not in parts:
continue
state = parts[-1]
if state in ('FAILED', 'PERMANENT', 'NOARP', 'INCOMPLETE'):
continue
idx = parts.index('lladdr')
mac = parts[idx + 1].lower()
entries[mac] = {'ip': parts[0], 'state': state}
ARP_CACHE_FILE.write_text(json.dumps(entries))
except Exception as exc:
print(f"WARNING: Could not refresh ARP cache: {exc}")
def run_update(cfg, force=False, getip_only=False):
"""Perform a single DDNS update pass.
If force=True, bypasses the cached IP check and always updates.
@ -593,6 +613,7 @@ def main():
run_update(cfg, force=args.force)
rotate_radius_log(cfg.get("_radius", {}))
refresh_arp_cache()
if __name__ == "__main__":
main()