diff options
author | Nicolas Vollmar <nvo@scaling.ch> | 2024-08-27 12:55:35 +0200 |
---|---|---|
committer | Nicolas Vollmar <nvo@scaling.ch> | 2024-09-02 13:41:15 +0200 |
commit | f96733dd1e8d840012d98740006d7999a9fa6776 (patch) | |
tree | 1763953ed7b56620d0223093a4c4a24d9ff28417 /src | |
parent | c78c5bd7e65b19e0e50ef6944dc74fb33660ff71 (diff) | |
download | vyos-1x-f96733dd1e8d840012d98740006d7999a9fa6776.tar.gz vyos-1x-f96733dd1e8d840012d98740006d7999a9fa6776.zip |
T6679: add destination groups
Diffstat (limited to 'src')
-rwxr-xr-x | src/conf_mode/nat66.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/conf_mode/nat66.py b/src/conf_mode/nat66.py index c44320f36..95dfae3a5 100755 --- a/src/conf_mode/nat66.py +++ b/src/conf_mode/nat66.py @@ -26,6 +26,7 @@ from vyos.utils.dict import dict_search from vyos.utils.kernel import check_kmod from vyos.utils.network import interface_exists from vyos.utils.process import cmd +from vyos.utils.process import run from vyos.template import is_ipv6 from vyos import ConfigError from vyos import airbag @@ -48,6 +49,14 @@ def get_config(config=None): if not conf.exists(base): nat['deleted'] = '' + return nat + + nat['firewall_group'] = conf.get_config_dict(['firewall', 'group'], key_mangling=('-', '_'), get_first_key=True, + no_tag_node_value_mangle=True) + + # Remove dynamic firewall groups if present: + if 'dynamic_group' in nat['firewall_group']: + del nat['firewall_group']['dynamic_group'] return nat @@ -99,22 +108,33 @@ def verify(nat): if not interface_exists(interface_name): Warning(f'Interface "{interface_name}" for destination NAT66 rule "{rule}" does not exist!') + if 'destination' in config and 'group' in config['destination']: + if len({'address_group', 'network_group', 'domain_group'} & set(config['destination']['group'])) > 1: + raise ConfigError('Only one address-group, network-group or domain-group can be specified') + return None def generate(nat): if not os.path.exists(nftables_nat66_config): nat['first_install'] = True - render(nftables_nat66_config, 'firewall/nftables-nat66.j2', nat, permission=0o755) + render(nftables_nat66_config, 'firewall/nftables-nat66.j2', nat) + + # dry-run newly generated configuration + tmp = run(f'nft --check --file {nftables_nat66_config}') + if tmp > 0: + raise ConfigError('Configuration file errors encountered!') + return None def apply(nat): - if not nat: - return None - check_kmod(k_mod) cmd(f'nft --file {nftables_nat66_config}') + + if not nat or 'deleted' in nat: + os.unlink(nftables_nat66_config) + call_dependents() return None |