Skip to content

Commit 1540d04

Browse files
committed
vpp: T7972: Make nat44 no-forwarding feature automatically configurable
If any dynamic rule is configured forwarding should be disabled because each packet must be processed through the NAT session table to apply proper translations
1 parent 81eb751 commit 1540d04

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,6 @@
10331033
<multi/>
10341034
</properties>
10351035
</leafNode>
1036-
<leafNode name="no-forwarding">
1037-
<properties>
1038-
<help>Do not forward packets which do not match existing NAT translations (static or dynamic)</help>
1039-
<valueless/>
1040-
</properties>
1041-
</leafNode>
10421036
</children>
10431037
</node>
10441038
<node name="physmem">

smoketest/scripts/cli/test_vpp.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,13 @@ def test_16_vpp_nat(self):
13661366
self.cli_set(
13671367
base_nat + ['address-pool', 'translation', 'address', translation_pool]
13681368
)
1369+
self.cli_commit()
1370+
1371+
# Forwarding is disabled when only dynamic NAT is configured
1372+
vpp = VPPControl()
1373+
out = vpp.api.nat44_show_running_config().forwarding_enabled
1374+
self.assertFalse(out)
1375+
13691376
self.cli_set(
13701377
base_nat + ['exclude', 'rule', '100', 'local-address', exclude_local_addr]
13711378
)
@@ -1386,7 +1393,6 @@ def test_16_vpp_nat(self):
13861393
base_nat + ['static', 'rule', '100', 'local', 'address', static_local_addr]
13871394
)
13881395

1389-
self.cli_set(base_nat_settings + ['no-forwarding'])
13901396
self.cli_set(base_nat_settings + ['session-limit', sess_limit])
13911397
self.cli_set(base_nat_settings + ['timeout', 'icmp', timeout_icmp])
13921398
self.cli_set(
@@ -1426,6 +1432,20 @@ def test_16_vpp_nat(self):
14261432
_, out = rc_cmd('sudo vppctl show nat44 summary')
14271433
self.assertIn(f'max translations per thread: {sess_limit} fib 0', out)
14281434

1435+
# Forwarding should be disabled with statyc+dynamic NAT
1436+
vpp = VPPControl()
1437+
out = vpp.api.nat44_show_running_config().forwarding_enabled
1438+
self.assertFalse(out)
1439+
1440+
# Delete dynamic NAT and check forwarding
1441+
self.cli_delete(base_nat + ['address-pool'])
1442+
self.cli_commit()
1443+
1444+
# Forwarding should be enabled if only statyc NAT is configured
1445+
vpp = VPPControl()
1446+
out = vpp.api.nat44_show_running_config().forwarding_enabled
1447+
self.assertTrue(out)
1448+
14291449
def test_17_vpp_sflow(self):
14301450
base_sflow = ['system', 'sflow']
14311451
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 = not bool(config.get('address_pool', {}).get('translation'))
446444
n.enable_disable_nat44_forwarding(enable_forwarding)
447445

448446
# Add inside interfaces

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright VyOS maintainers and contributors <[email protected]>
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+
# Delete 'vpp settings nat44 no-forwarding'
17+
# because it will be set automatically (T7972)
18+
19+
20+
from vyos.configtree import ConfigTree
21+
22+
base = ['vpp', 'settings', 'nat44']
23+
24+
def migrate(config: ConfigTree) -> None:
25+
26+
if config.exists(base + ['no-forwarding']):
27+
# Delete no-forwarding option from NAT44 settings
28+
config.delete(base + ['no-forwarding'])
29+
if config.exists(base) and len(config.list_nodes(base)) == 0:
30+
config.delete(base)

0 commit comments

Comments
 (0)