Development

This commit is contained in:
Matthew Grotke 2026-06-03 03:23:19 -04:00
parent 5d7ca3770f
commit 386054dc1b

View file

@ -23,6 +23,7 @@ Usage:
python3 maintenance.py --getip Print current public IP and exit python3 maintenance.py --getip Print current public IP and exit
""" """
import ipaddress
import json import json
import os import os
import subprocess import subprocess
@ -538,7 +539,17 @@ def rotate_radius_log(radius_cfg):
ARP_MAX_AGE_SECS = 4 * 3600 ARP_MAX_AGE_SECS = 4 * 3600
def refresh_arp_cache(): def refresh_arp_cache(cfg):
vlan_networks = []
for v in cfg.get('vlans', []):
subnet = v.get('subnet')
mask = v.get('subnet_mask')
if subnet and mask:
try:
vlan_networks.append(ipaddress.IPv4Network(f'{subnet}/{mask}', strict=False))
except ValueError:
pass
try: try:
result = subprocess.run(['ip', '-stats', 'neigh'], capture_output=True, text=True, timeout=5) result = subprocess.run(['ip', '-stats', 'neigh'], capture_output=True, text=True, timeout=5)
best = {} # mac -> (used_secs, entry_dict) best = {} # mac -> (used_secs, entry_dict)
@ -548,6 +559,12 @@ def refresh_arp_cache():
continue continue
if ':' in parts[0]: # skip IPv6 if ':' in parts[0]: # skip IPv6
continue continue
try:
addr = ipaddress.IPv4Address(parts[0])
if vlan_networks and not any(addr in n for n in vlan_networks):
continue
except ValueError:
continue
iface = parts[2] if len(parts) > 2 else '' iface = parts[2] if len(parts) > 2 else ''
if iface.startswith('br-') or iface == 'docker0': if iface.startswith('br-') or iface == 'docker0':
continue continue
@ -626,7 +643,7 @@ def main():
run_update(cfg, force=args.force) run_update(cfg, force=args.force)
rotate_radius_log(cfg.get("_radius", {})) rotate_radius_log(cfg.get("_radius", {}))
refresh_arp_cache() refresh_arp_cache(cfg)
if __name__ == "__main__": if __name__ == "__main__":
main() main()