Skip to content

Commit b1342f1

Browse files
c-pomergify[bot]
authored andcommitted
nat66: T6365: remove warnings for negated interface selections by name
(cherry picked from commit 59781ff)
1 parent 7279f74 commit b1342f1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/conf_mode/nat66.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
import os
1818

1919
from sys import exit
20-
from netifaces import interfaces
2120

2221
from vyos.base import Warning
2322
from vyos.config import Config
2423
from vyos.configdep import set_dependents, call_dependents
2524
from vyos.template import render
26-
from vyos.utils.process import cmd
27-
from vyos.utils.kernel import check_kmod
2825
from vyos.utils.dict import dict_search
26+
from vyos.utils.kernel import check_kmod
27+
from vyos.utils.network import interface_exists
28+
from vyos.utils.process import cmd
2929
from vyos.template import is_ipv6
3030
from vyos import ConfigError
3131
from vyos import airbag
@@ -64,8 +64,12 @@ def verify(nat):
6464
if 'name' in config['outbound_interface'] and 'group' in config['outbound_interface']:
6565
raise ConfigError(f'{err_msg} cannot specify both interface group and interface name for nat source rule "{rule}"')
6666
elif 'name' in config['outbound_interface']:
67-
if config['outbound_interface']['name'] not in 'any' and config['outbound_interface']['name'] not in interfaces():
68-
Warning(f'NAT66 interface "{config["outbound_interface"]["name"]}" for source NAT66 rule "{rule}" does not exist!')
67+
interface_name = config['outbound_interface']['name']
68+
if interface_name not in 'any':
69+
if interface_name.startswith('!'):
70+
interface_name = interface_name[1:]
71+
if not interface_exists(interface_name):
72+
Warning(f'Interface "{interface_name}" for source NAT66 rule "{rule}" does not exist!')
6973

7074
addr = dict_search('translation.address', config)
7175
if addr != None:
@@ -88,8 +92,12 @@ def verify(nat):
8892
if 'name' in config['inbound_interface'] and 'group' in config['inbound_interface']:
8993
raise ConfigError(f'{err_msg} cannot specify both interface group and interface name for destination nat rule "{rule}"')
9094
elif 'name' in config['inbound_interface']:
91-
if config['inbound_interface']['name'] not in 'any' and config['inbound_interface']['name'] not in interfaces():
92-
Warning(f'NAT66 interface "{config["inbound_interface"]["name"]}" for destination NAT66 rule "{rule}" does not exist!')
95+
interface_name = config['inbound_interface']['name']
96+
if interface_name not in 'any':
97+
if interface_name.startswith('!'):
98+
interface_name = interface_name[1:]
99+
if not interface_exists(interface_name):
100+
Warning(f'Interface "{interface_name}" for destination NAT66 rule "{rule}" does not exist!')
93101

94102
return None
95103

0 commit comments

Comments
 (0)