Development
This commit is contained in:
parent
5d7ca3770f
commit
386054dc1b
1 changed files with 19 additions and 2 deletions
|
|
@ -23,6 +23,7 @@ Usage:
|
|||
python3 maintenance.py --getip Print current public IP and exit
|
||||
"""
|
||||
|
||||
import ipaddress
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
|
@ -538,7 +539,17 @@ def rotate_radius_log(radius_cfg):
|
|||
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:
|
||||
result = subprocess.run(['ip', '-stats', 'neigh'], capture_output=True, text=True, timeout=5)
|
||||
best = {} # mac -> (used_secs, entry_dict)
|
||||
|
|
@ -548,6 +559,12 @@ def refresh_arp_cache():
|
|||
continue
|
||||
if ':' in parts[0]: # skip IPv6
|
||||
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 ''
|
||||
if iface.startswith('br-') or iface == 'docker0':
|
||||
continue
|
||||
|
|
@ -626,7 +643,7 @@ def main():
|
|||
run_update(cfg, force=args.force)
|
||||
|
||||
rotate_radius_log(cfg.get("_radius", {}))
|
||||
refresh_arp_cache()
|
||||
refresh_arp_cache(cfg)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue