summaryrefslogtreecommitdiff
path: root/python/vyos/utils/network.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-07-25 19:55:02 +0200
committerGitHub <noreply@github.com>2024-07-25 19:55:02 +0200
commit35a675e21a4bc92b70b6ff070017bf7dcef6f3a5 (patch)
tree6c1af7c26adeefaab8007305674e3e996394d30b /python/vyos/utils/network.py
parent160a24d61d9adb108de9a210311ccd10a93f819f (diff)
parent33f998926fbbd4cd60567d61ffe2cff21fd9a110 (diff)
downloadvyos-1x-35a675e21a4bc92b70b6ff070017bf7dcef6f3a5.tar.gz
vyos-1x-35a675e21a4bc92b70b6ff070017bf7dcef6f3a5.zip
Merge pull request #3872 from vyos/mergify/bp/sagitta/pr-3857
interface: T6592: remove interface from conntrack ct_iface_map on deletion (backport #3857)
Diffstat (limited to 'python/vyos/utils/network.py')
-rw-r--r--python/vyos/utils/network.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py
index 8befe370f..55798651f 100644
--- a/python/vyos/utils/network.py
+++ b/python/vyos/utils/network.py
@@ -530,3 +530,31 @@ def get_vxlan_vni_filter(interface: str) -> list:
os_configured_vnis.append(str(vniStart))
return os_configured_vnis
+
+def get_nft_vrf_zone_mapping() -> dict:
+ """
+ Retrieve current nftables conntrack mapping list from Kernel
+
+ returns: [{'interface': 'red', 'vrf_tableid': 1000},
+ {'interface': 'eth2', 'vrf_tableid': 1000},
+ {'interface': 'blue', 'vrf_tableid': 2000}]
+ """
+ from json import loads
+ from jmespath import search
+ from vyos.utils.process import cmd
+ output = []
+ tmp = loads(cmd('sudo nft -j list table inet vrf_zones'))
+ # {'nftables': [{'metainfo': {'json_schema_version': 1,
+ # 'release_name': 'Old Doc Yak #3',
+ # 'version': '1.0.9'}},
+ # {'table': {'family': 'inet', 'handle': 6, 'name': 'vrf_zones'}},
+ # {'map': {'elem': [['eth0', 666],
+ # ['dum0', 666],
+ # ['wg500', 666],
+ # ['bond10.666', 666]],
+ vrf_list = search('nftables[].map.elem | [0]', tmp)
+ if not vrf_list:
+ return output
+ for (vrf_name, vrf_id) in vrf_list:
+ output.append({'interface' : vrf_name, 'vrf_tableid' : vrf_id})
+ return output