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

T6366: CGNAT add ability to get external and internal allocations #3490

Merged
merged 1 commit into from
May 21, 2024

Conversation

sever-sever
Copy link
Member

Change Summary

Add the ability to show port allocation per external or internal address. With huge entries of allocation, it is necessary to filter them by specific external/internal IP address

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): Extend op-mode for CGN

Related Task(s)

Related PR(s)

Component(s) name

cgnat

Proposed changes

How to test

set nat cgnat pool external ext-01 external-port-range '40000-60000'
set nat cgnat pool external ext-01 per-user-limit port '5000'
set nat cgnat pool external ext-01 range 192.0.2.1-192.0.2.2
set nat cgnat pool external ext-01 range 192.0.2.11/32
set nat cgnat pool external vyos-ext-02 external-port-range '2000-22000'
set nat cgnat pool external vyos-ext-02 per-user-limit port '2000'
set nat cgnat pool external vyos-ext-02 range 203.0.113.55/32
set nat cgnat pool internal int-01 range '100.64.0.0/29'
set nat cgnat pool internal vyos-int-02 range '100.64.222.10-100.64.222.12'
set nat cgnat rule 100 source pool 'int-01'
set nat cgnat rule 100 translation pool 'ext-01'
set nat cgnat rule 120 source pool 'vyos-int-02'
set nat cgnat rule 120 translation pool 'vyos-ext-02'

Op-mode, check external/internal options

vyos@r4:~$ show nat cgnat allocation 
Internal IP    External IP    Port range
-------------  -------------  ------------
100.64.0.0     192.0.2.1      40000-44999
100.64.0.1     192.0.2.1      45000-49999
100.64.0.2     192.0.2.1      50000-54999
100.64.0.3     192.0.2.1      55000-59999
100.64.0.4     192.0.2.2      40000-44999
100.64.0.5     192.0.2.2      45000-49999
100.64.0.6     192.0.2.2      50000-54999
100.64.0.7     192.0.2.2      55000-59999
100.64.222.10  203.0.113.55   2000-3999
100.64.222.11  203.0.113.55   4000-5999
100.64.222.12  203.0.113.55   6000-7999
vyos@r4:~$ 
vyos@r4:~$ 
vyos@r4:~$ show nat cgnat allocation external-address 203.0.113.55
Internal IP    External IP    Port range
-------------  -------------  ------------
100.64.222.10  203.0.113.55   2000-3999
100.64.222.11  203.0.113.55   4000-5999
100.64.222.12  203.0.113.55   6000-7999
vyos@r4:~$ 
vyos@r4:~$ 
vyos@r4:~$ show nat cgnat allocation internal-address 100.64.0.2
Internal IP    External IP    Port range
-------------  -------------  ------------
100.64.0.2     192.0.2.1      50000-54999
vyos@r4:~$ 

Check the raw options:

vyos@r4:~$ sudo /usr/libexec/vyos/op_mode/cgnat.py show_allocation --internal-address 100.64.222.11 --raw
[
    {
        "internal_address": "100.64.222.11",
        "external_address": "203.0.113.55",
        "port_range": "4000-5999"
    }
]
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 the ability to show port allocation per external or internal address
With huge entries, it is necessary to filter it by specific
external/internal IP address
@c-po c-po merged commit 108a42f into vyos:current May 21, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants