Skip to content

Commit 5f920df

Browse files
committed
vpp: T7972: Improve nat44 no-forwarding feature name and description in CLI
1 parent 81eb751 commit 5f920df

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!-- include start from include/version/vpp-version.xml.i -->
2-
<syntaxVersion component='vpp' version='3'></syntaxVersion>
2+
<syntaxVersion component='vpp' version='4'></syntaxVersion>
33
<!-- include end -->

interface-definitions/vpp.xml.in

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,25 @@
10331033
<multi/>
10341034
</properties>
10351035
</leafNode>
1036-
<leafNode name="no-forwarding">
1036+
<leafNode name="processing-mode">
10371037
<properties>
1038-
<help>Do not forward packets which do not match existing NAT translations (static or dynamic)</help>
1039-
<valueless/>
1038+
<help>Processing mode for NAT</help>
1039+
<completionHelp>
1040+
<list>static-dynamic static-bypass</list>
1041+
</completionHelp>
1042+
<valueHelp>
1043+
<format>static-dynamic</format>
1044+
<description>Process traffic by both static rules and dynamic NAT</description>
1045+
</valueHelp>
1046+
<valueHelp>
1047+
<format>static-bypass</format>
1048+
<description>Process traffic by static NAT rules only, pass without NAT if not matched</description>
1049+
</valueHelp>
1050+
<constraint>
1051+
<regex>(static-dynamic|static-bypass)</regex>
1052+
</constraint>
10401053
</properties>
1054+
<defaultValue>static-dynamic</defaultValue>
10411055
</leafNode>
10421056
</children>
10431057
</node>

smoketest/scripts/cli/test_vpp.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,6 @@ def test_16_vpp_nat(self):
13861386
base_nat + ['static', 'rule', '100', 'local', 'address', static_local_addr]
13871387
)
13881388

1389-
self.cli_set(base_nat_settings + ['no-forwarding'])
13901389
self.cli_set(base_nat_settings + ['session-limit', sess_limit])
13911390
self.cli_set(base_nat_settings + ['timeout', 'icmp', timeout_icmp])
13921391
self.cli_set(
@@ -1426,6 +1425,19 @@ def test_16_vpp_nat(self):
14261425
_, out = rc_cmd('sudo vppctl show nat44 summary')
14271426
self.assertIn(f'max translations per thread: {sess_limit} fib 0', out)
14281427

1428+
# Forwarding
1429+
# By default forwarding is disabled ('vpp settings nat44 processing-mode static-dynamic')
1430+
vpp = VPPControl()
1431+
out = vpp.api.nat44_show_running_config().forwarding_enabled
1432+
self.assertFalse(out)
1433+
1434+
# Enable forwarding
1435+
self.cli_set(base_nat_settings + ['processing-mode', 'static-bypass'])
1436+
self.cli_commit()
1437+
vpp = VPPControl()
1438+
out = vpp.api.nat44_show_running_config().forwarding_enabled
1439+
self.assertTrue(out)
1440+
14291441
def test_17_vpp_sflow(self):
14301442
base_sflow = ['system', 'sflow']
14311443
sampling_rate = '1500'

src/conf_mode/vpp_nat.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,7 @@ def apply(config):
440440
n.enable_nat44_ed()
441441

442442
# Enable/disable forwarding
443-
enable_forwarding = True
444-
if 'no_forwarding' in config:
445-
enable_forwarding = False
443+
enable_forwarding = config['processing_mode'] == 'static-bypass'
446444
n.enable_disable_nat44_forwarding(enable_forwarding)
447445

448446
# Add inside interfaces

src/migration-scripts/vpp/3-to-4

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright VyOS maintainers and contributors <maintainers@vyos.io>
2+
#
3+
# This library is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU Lesser General Public
5+
# License as published by the Free Software Foundation; either
6+
# version 2.1 of the License, or (at your option) any later version.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public License
14+
# along with this library. If not, see <http://www.gnu.org/licenses/>.
15+
16+
# Migrate "vpp settings nat44 no-forwarding"
17+
# to "vpp settings nat44 processing-mode <static+dynamic|static+bypass>"
18+
19+
from vyos.configtree import ConfigTree
20+
21+
base = ['vpp', 'settings', 'nat44']
22+
23+
def migrate(config: ConfigTree) -> None:
24+
if not config.exists(['vpp']):
25+
# Nothing to do
26+
return
27+
28+
if config.exists(base + ['no-forwarding']):
29+
# Delete no-forwarding option from NAT44 settings
30+
config.delete(base + ['no-forwarding'])
31+
config.set(base + ['processing-mode'], value='static-dynamic')
32+
else:
33+
config.set(base + ['processing-mode'], value='static-bypass')

0 commit comments

Comments
 (0)