diff options
author | Christian Breunig <christian@breunig.cc> | 2024-04-02 18:50:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-02 18:50:42 +0200 |
commit | 92be9ee46943f38648daeb75da729a460daea9c9 (patch) | |
tree | b6ca67716ab8e6716f56d42557adc5b55a92cd80 /src/conf_mode/vrf.py | |
parent | 0cb21915164551b3d2eaab79ed6339184957c326 (diff) | |
parent | 33b031cc9005e51129719ff42d70bf50fb7f14e1 (diff) | |
download | vyos-1x-92be9ee46943f38648daeb75da729a460daea9c9.tar.gz vyos-1x-92be9ee46943f38648daeb75da729a460daea9c9.zip |
Merge pull request #3234 from vyos/mergify/bp/sagitta/pr-3230
firewall: nat: policy: vrf: nft call syntax and import cleanup (backport #3230)
Diffstat (limited to 'src/conf_mode/vrf.py')
-rwxr-xr-x | src/conf_mode/vrf.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/conf_mode/vrf.py b/src/conf_mode/vrf.py index 16908100f..1fc813189 100755 --- a/src/conf_mode/vrf.py +++ b/src/conf_mode/vrf.py @@ -14,8 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import os - from sys import exit from json import loads @@ -33,6 +31,7 @@ from vyos.utils.network import get_vrf_members from vyos.utils.network import interface_exists from vyos.utils.process import call from vyos.utils.process import cmd +from vyos.utils.process import popen from vyos.utils.system import sysctl_write from vyos import ConfigError from vyos import frr @@ -227,7 +226,11 @@ def apply(vrf): # Remove nftables conntrack zone map item nft_del_element = f'delete element inet vrf_zones ct_iface_map {{ "{tmp}" }}' - cmd(f'nft {nft_del_element}') + # Check if deleting is possible first to avoid raising errors + _, err = popen(f'nft --check {nft_del_element}') + if not err: + # Remove map element + cmd(f'nft {nft_del_element}') # Delete the VRF Kernel interface call(f'ip link delete dev {tmp}') @@ -307,7 +310,7 @@ def apply(vrf): if vrf['conntrack']: for chain, rule in nftables_rules.items(): cmd(f'nft add rule inet vrf_zones {chain} {rule}') - + if 'name' not in vrf or not vrf['conntrack']: for chain, rule in nftables_rules.items(): cmd(f'nft flush chain inet vrf_zones {chain}') |