Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6351: CGNAT add verification if the pool exists #3464

Merged
merged 1 commit into from
May 17, 2024

Conversation

sever-sever
Copy link
Member

Change Summary

Add verification if the external/internal pools are exists before we can use them in the source and translation rules

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Component(s) name

cgnat

Proposed changes

How to test

Use not exists pool name in the rules (in this example fake-pool):

set nat cgnat pool external ext1 external-port-range '1024-65535'
set nat cgnat pool external ext1 per-user-limit port '2000'
set nat cgnat pool external ext1 range 192.168.122.222/32
set nat cgnat pool internal int1 range '100.64.0.0/28'

set nat cgnat rule 10 source pool 'fake-pool'
set nat cgnat rule 10 translation pool 'ext1'

Before the fix:

vyos@r4# commit
[ nat cgnat ]
VyOS had an issue completing a command.

Report time:      2024-05-16 15:23:29
Image version:    VyOS 1.5-rolling-202405140019
Release train:    current

Built by:         autobuild@vyos.net
Built on:         Tue 14 May 2024 02:55 UTC
Build UUID:       c30a637d-f3c1-473e-8af6-03c9bfaf0729
Build commit ID:  3463386246a9ac

Architecture:     x86_64
Boot via:         installed image
System type:      KVM guest

Hardware vendor:  QEMU
Hardware model:   Standard PC (Q35 + ICH9, 2009)
Hardware S/N:     
Hardware UUID:    166cfd25-7d3a-4eca-9ef6-0b655c9acf0f

Traceback (most recent call last):
  File "/usr/libexec/vyos/conf_mode/nat_cgnat.py", line 284, in <module>
    generate(c)
  File "/usr/libexec/vyos/conf_mode/nat_cgnat.py", line 240, in generate
    i_count = IPOperations(int_range).get_ips_count()
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/libexec/vyos/conf_mode/nat_cgnat.py", line 39, in __init__
    self.ip_network = ipaddress.ip_network(ip_prefix) if '/' in ip_prefix else None
                                                         ^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable



[[nat cgnat]] failed
Commit failed
[edit]
vyos@r4#

After the fix:

vyos@r4# commit
[ nat cgnat ]
Internal pool "fake-pool" does not exist!

[[nat cgnat]] failed
Commit failed
[edit]
vyos@r4# 

Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

Add verification if the external/internal pools are exists before we
can use them in the source and translation rules
@sever-sever sever-sever requested review from a team, dmbaturin, sarthurdev, zdc, jestabro and c-po and removed request for a team May 16, 2024 16:36
@c-po
Copy link
Member

c-po commented May 16, 2024

@Mergifyio backport sagitta

Copy link

mergify bot commented May 16, 2024

backport sagitta

✅ Backports have been created

@dmbaturin dmbaturin merged commit f438fc3 into vyos:current May 17, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 participants