From b0aeb2a9c196ea7048545e38e6f3c5759ff4a5ac Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 27 Apr 2022 21:42:22 +0200 Subject: arp: T4397: change CLI syntax to support interface and VRF bound ARP entries * set protocols static arp interface eth0 address 192.0.2.1 mac 01:23:45:67:89:01 --- src/conf_mode/arp.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/conf_mode/arp.py') diff --git a/src/conf_mode/arp.py b/src/conf_mode/arp.py index 51a08bee5..1cd8f5451 100755 --- a/src/conf_mode/arp.py +++ b/src/conf_mode/arp.py @@ -30,9 +30,12 @@ def get_config(config=None): conf = Config() base = ['protocols', 'static', 'arp'] - arp = conf.get_config_dict(base) - tmp = node_changed(conf, base) - if tmp: arp.update({'removed' : node_changed(conf, base)}) + arp = conf.get_config_dict(base, get_first_key=True) + + if 'interface' in arp: + for interface in arp['interface']: + tmp = node_changed(conf, base + ['interface', interface, 'address'], recursive=True) + if tmp: arp['interface'][interface].update({'address_old' : tmp}) return arp @@ -46,14 +49,19 @@ def apply(arp): if not arp: return None - if 'removed' in arp: - for host in arp['removed']: - call(f'arp --delete {host}') + if 'interface' in arp: + for interface, interface_config in arp['interface'].items(): + # Delete old static ARP assignments first + if 'address_old' in interface_config: + for address in interface_config['address_old']: + call(f'ip neigh del {address} dev {interface}') - if 'arp' in arp: - for host, host_config in arp['arp'].items(): - mac = host_config['hwaddr'] - call(f'arp --set {host} {mac}') + # Add new static ARP entries to interface + if 'address' not in interface_config: + continue + for address, address_config in interface_config['address'].items(): + mac = address_config['mac'] + call(f'ip neigh add {address} lladdr {mac} dev {interface}') if __name__ == '__main__': try: -- cgit v1.2.3