summaryrefslogtreecommitdiff
path: root/src/conf_mode/vpp_nat_source.py
diff options
context:
space:
mode:
authorNataliia Solomko <natalirs1985@gmail.com>2025-04-23 15:11:16 +0300
committerNataliia Solomko <natalirs1985@gmail.com>2025-04-25 13:44:45 +0300
commitfa293316e679645e6397697428cee96e32e346fc (patch)
tree046587e39d00c2959cd159583b6b4059de16de99 /src/conf_mode/vpp_nat_source.py
parent4d32bcddda72c1df944470f06b75908b2dc31667 (diff)
downloadvyos-1x-fa293316e679645e6397697428cee96e32e346fc.tar.gz
vyos-1x-fa293316e679645e6397697428cee96e32e346fc.zip
T7181: VPP Static and dynamic NAT
New CLI for static and dynamic NAT: ``` set vpp nat44 interface outside <interface> # multi set vpp nat44 interface inside <interface> # multi set vpp nat44 address-pool translation interface <interface> # multi set vpp nat44 address-pool translation address <address> # multi set vpp nat44 address-pool twice-nat interface <interface> # multi set vpp nat44 address-pool twice-nat address <address> # multi set vpp nat44 static rule <rule> external address <address> set vpp nat44 static rule <rule> external port <port> set vpp nat44 static rule <rule> local address <address> set vpp nat44 static rule <rule> local port <port> set vpp nat44 static rule <rule> protocol <protocol> set vpp nat44 static rule <rule> options twice-nat set vpp nat44 static rule <rule> options self-twice-nat set vpp nat44 static rule <rule> options out-to-in-only set vpp nat44 static rule <rule> options twice-nat-address <address> set vpp nat44 exclude rule <rule> protocol <protocol> set vpp nat44 exclude rule <rule> local-port <port> set vpp nat44 exclude rule <rule> local-address <address> set vpp nat44 exclude rule <rule> external-interface <interface> ``` Settings: ``` set vpp settings nat44 session-limit <limit> # default 64512 set vpp settings nat44 timeout udp <sec> # default 300 set vpp settings nat44 timeout tcp-established <sec> # default 7440 set vpp settings nat44 timeout tcp-transitory <sec> # default 240 set vpp settings nat44 timeout icmp <sec> # default 60 set vpp settings nat44 workers <list> set vpp settings nat44 no-forwarding ```
Diffstat (limited to 'src/conf_mode/vpp_nat_source.py')
-rw-r--r--src/conf_mode/vpp_nat_source.py119
1 files changed, 0 insertions, 119 deletions
diff --git a/src/conf_mode/vpp_nat_source.py b/src/conf_mode/vpp_nat_source.py
deleted file mode 100644
index 40b16a3c8..000000000
--- a/src/conf_mode/vpp_nat_source.py
+++ /dev/null
@@ -1,119 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2025 VyOS Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-from vyos.config import Config
-from vyos import ConfigError
-from vyos.vpp.nat.nat44 import Nat44
-
-
-def get_config(config=None) -> dict:
- if config:
- conf = config
- else:
- conf = Config()
-
- base = ['vpp', 'nat44', 'source']
-
- # Get config_dict with default values
- config = conf.get_config_dict(
- base,
- key_mangling=('-', '_'),
- get_first_key=True,
- no_tag_node_value_mangle=True,
- with_defaults=True,
- with_recursive_defaults=True,
- )
-
- # Get effective config as we need full dicitonary per interface delete
- effective_config = conf.get_config_dict(
- base,
- key_mangling=('-', '_'),
- effective=True,
- get_first_key=True,
- no_tag_node_value_mangle=True,
- )
-
- if not config:
- config['remove'] = True
-
- if effective_config:
- config.update({'effective': effective_config})
-
- return config
-
-
-def verify(config):
- if 'remove' in config:
- return None
-
- required_keys = {'inside_interface', 'outside_interface'}
- if not all(key in config for key in required_keys):
- missing_keys = required_keys - set(config.keys())
- raise ConfigError(
- f"Required options are missing: {', '.join(missing_keys).replace('_', '-')}"
- )
-
- if not config.get('translation', {}).get('address'):
- raise ConfigError('Translation requires address')
-
- if config.get('translation', {}).get('address') == 'masquerade':
- raise ConfigError('Masquerade is not implemented')
-
-
-def generate(config):
- pass
-
-
-def apply(config):
- # Delete NAT source
- if 'effective' in config:
- remove_config = config.get('effective')
- interface_in = remove_config.get('inside_interface')
- interface_out = remove_config.get('outside_interface')
- translation_address = remove_config.get('translation', {}).get('address')
-
- n = Nat44(interface_in, interface_out, translation_address)
- n.delete_nat44_out_interface()
- n.delete_nat44_interface_inside()
- n.delete_nat44_address_range()
-
- if 'remove' in config:
- return None
-
- # Add NAT44
- interface_in = config.get('inside_interface')
- interface_out = config.get('outside_interface')
- translation_address = config.get('translation', {}).get('address')
-
- n = Nat44(interface_in, interface_out, translation_address)
- n.enable_nat44_ed()
- n.enable_nat44_forwarding()
- n.add_nat44_out_interface()
- # n.add_nat44_interface_inside()
- n.add_nat44_address_range()
-
-
-if __name__ == '__main__':
- try:
- c = get_config()
- verify(c)
- generate(c)
- apply(c)
- except ConfigError as e:
- print(e)
- exit(1)