|
26 | 26 | from vyos.utils.network import get_interface_address |
27 | 27 |
|
28 | 28 | from vyos.vpp.utils import cli_ifaces_list |
| 29 | +from vyos.vpp.utils import vpp_iface_name_transform |
29 | 30 | from vyos.vpp.nat.nat44 import Nat44 |
| 31 | +from vyos.vpp.control_vpp import VPPControl |
30 | 32 |
|
31 | 33 |
|
32 | 34 | protocol_map = { |
@@ -155,16 +157,14 @@ def verify(config): |
155 | 157 | f'Both inside and outside interfaces must be configured. Please add: {", ".join(missing_keys)}' |
156 | 158 | ) |
157 | 159 |
|
158 | | - for interface in config['interface']['inside']: |
159 | | - if interface not in config['vpp_ifaces']: |
160 | | - raise ConfigError( |
161 | | - f'{interface} must be a VPP interface for inside NAT interface' |
162 | | - ) |
163 | | - for interface in config['interface']['outside']: |
164 | | - if interface not in config['vpp_ifaces']: |
165 | | - raise ConfigError( |
166 | | - f'{interface} must be a VPP interface for outside NAT interface' |
167 | | - ) |
| 160 | + vpp = VPPControl() |
| 161 | + for direction in ['inside', 'outside']: |
| 162 | + for interface in config['interface'][direction]: |
| 163 | + vpp_iface_name = vpp_iface_name_transform(interface) |
| 164 | + if vpp.get_sw_if_index(vpp_iface_name) is None: |
| 165 | + raise ConfigError( |
| 166 | + f'{interface} must be a VPP interface for {direction} NAT interface' |
| 167 | + ) |
168 | 168 |
|
169 | 169 | if not config.get('address_pool', {}).get('translation') and not config.get( |
170 | 170 | 'static', {} |
@@ -371,11 +371,13 @@ def apply(config): |
371 | 371 | # Delete inside interfaces |
372 | 372 | for interface in remove_config['interface']['inside']: |
373 | 373 | if interface not in config.get('interface', {}).get('inside', []): |
374 | | - n.delete_nat44_interface_inside(interface) |
| 374 | + vpp_iface_name = vpp_iface_name_transform(interface) |
| 375 | + n.delete_nat44_interface_inside(vpp_iface_name) |
375 | 376 | # Delete outside interfaces |
376 | 377 | for interface in remove_config['interface']['outside']: |
377 | 378 | if interface not in config.get('interface', {}).get('outside', []): |
378 | | - n.delete_nat44_interface_outside(interface) |
| 379 | + vpp_iface_name = vpp_iface_name_transform(interface) |
| 380 | + n.delete_nat44_interface_outside(vpp_iface_name) |
379 | 381 | # Delete address pool |
380 | 382 | address_pool = config.get('address_pool', {}) |
381 | 383 | for address in ( |
@@ -445,10 +447,12 @@ def apply(config): |
445 | 447 |
|
446 | 448 | # Add inside interfaces |
447 | 449 | for interface in config['interface']['inside']: |
448 | | - n.add_nat44_interface_inside(interface) |
| 450 | + vpp_iface_name = vpp_iface_name_transform(interface) |
| 451 | + n.add_nat44_interface_inside(vpp_iface_name) |
449 | 452 | # Add outside interfaces |
450 | 453 | for interface in config['interface']['outside']: |
451 | | - n.add_nat44_interface_outside(interface) |
| 454 | + vpp_iface_name = vpp_iface_name_transform(interface) |
| 455 | + n.add_nat44_interface_outside(vpp_iface_name) |
452 | 456 | # Add translation pool |
453 | 457 | for address in ( |
454 | 458 | config.get('address_pool', {}).get('translation', {}).get('address', []) |
|
0 commit comments