17
17
import os
18
18
19
19
from sys import exit
20
- from netifaces import interfaces
21
20
22
21
from vyos .base import Warning
23
22
from vyos .config import Config
24
23
from vyos .configdep import set_dependents , call_dependents
25
24
from vyos .template import render
26
- from vyos .utils .process import cmd
27
- from vyos .utils .kernel import check_kmod
28
25
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
29
29
from vyos .template import is_ipv6
30
30
from vyos import ConfigError
31
31
from vyos import airbag
@@ -64,8 +64,12 @@ def verify(nat):
64
64
if 'name' in config ['outbound_interface' ] and 'group' in config ['outbound_interface' ]:
65
65
raise ConfigError (f'{ err_msg } cannot specify both interface group and interface name for nat source rule "{ rule } "' )
66
66
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!' )
69
73
70
74
addr = dict_search ('translation.address' , config )
71
75
if addr != None :
@@ -88,8 +92,12 @@ def verify(nat):
88
92
if 'name' in config ['inbound_interface' ] and 'group' in config ['inbound_interface' ]:
89
93
raise ConfigError (f'{ err_msg } cannot specify both interface group and interface name for destination nat rule "{ rule } "' )
90
94
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!' )
93
101
94
102
return None
95
103
0 commit comments