diff --git a/interface-definitions/protocols_static_proxy.xml.in b/interface-definitions/protocols_static_proxy.xml.in new file mode 100644 index 00000000000..1914551df74 --- /dev/null +++ b/interface-definitions/protocols_static_proxy.xml.in @@ -0,0 +1,71 @@ + + + + + + + + + IP address for selective ARP proxy + + ipv4 + IPv4 destination address allowed for proxy-arp + + + + + + + + + Interface + + + + + txt + Interface name + + + #include + + + + + + + + + IPv6 address for selective NDP proxy + + ipv6 + IPv6 destination address + + + + + + + + + Interface + + + + + txt + Interface name + + + #include + + + + + + + + + + + diff --git a/src/conf_mode/protocols_static_proxy.py b/src/conf_mode/protocols_static_proxy.py new file mode 100755 index 00000000000..c5f7f02bfaa --- /dev/null +++ b/src/conf_mode/protocols_static_proxy.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os + +from sys import exit + +from vyos.config import Config +from vyos.configdict import node_changed +from vyos.utils.process import call +from vyos import ConfigError +from vyos import airbag + +airbag.enable() + + +def get_config(config=None): + if config: + conf = config + else: + conf = Config() + + base = ['protocols', 'static'] + config = conf.get_config_dict(base, get_first_key=True) + + # Get required keys + keys_to_keep = ['proxy-arp', 'proxy-ndp'] + config = {key: config[key] for key in keys_to_keep if key in config} + + return config + + +def verify(config): + + if 'proxy-arp' in config: + for neighbor, neighbor_conf in config['proxy-arp'].items(): + if 'interface' not in neighbor_conf: + raise ConfigError(f'proxy-arp {neighbor} interface required but not set.') + + if 'proxy-ndp' in config: + for neighbor, neighbor_conf in config['proxy-ndp'].items(): + if 'interface' not in neighbor_conf: + raise ConfigError(f'proxy-ndp {neighbor} interface required but not set.') + + +def generate(config): + pass + + +def apply(config): + if not config: + # Cleanup proxy + call('ip neighbor flush proxy') + call('ip -6 neighbor flush proxy') + return None + + # Add proxy ARP + if 'proxy-arp' in config: + # Cleanup entries before config + call('ip neighbor flush proxy') + for neighbor, neighbor_conf in config['proxy-arp'].items(): + for interface in neighbor_conf.get('interface'): + call(f'ip neighbor add proxy {neighbor} dev {interface}') + + # Add proxy NDP + if 'proxy-ndp' in config: + # Cleanup entries before config + call('ip -6 neighbor flush proxy') + for neighbor, neighbor_conf in config['proxy-ndp'].items(): + for interface in neighbor_conf['interface']: + call(f'ip -6 neighbor add proxy {neighbor} dev {interface}') + + +if __name__ == '__main__': + try: + c = get_config() + verify(c) + generate(c) + apply(c) + except ConfigError as e: + print(e) + exit(1)