summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2026-11-06 13:27:22 +0200
committerGitHub <noreply@github.com>2026-11-06 13:27:22 +0200
commitc67221dfa4eac5e2f78eea09028a078a9c63cde6 (patch)
tree3edd0a98e5b126b6e25cd7fabd2411662f0284ce /python
parent0059e631a896b9c46e13d83c6689479fa8d46377 (diff)
parent0949562e1761bd3885664132e9485347afcc50aa (diff)
downloadvyos-1x-c67221dfa4eac5e2f78eea09028a078a9c63cde6.tar.gz
vyos-1x-c67221dfa4eac5e2f78eea09028a078a9c63cde6.zip
Merge pull request #5631 from c-po/T9559
https: T9559: fix bogus port conflict with "vrf default"
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/network.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py
index 4a4414f56..c7304d15b 100644
--- a/python/vyos/utils/network.py
+++ b/python/vyos/utils/network.py
@@ -417,19 +417,23 @@ def check_port_availability(address: str = None, port: int = 0,
print(f'Invalid address: {address}')
return False
+ # the default VRF has no master device - an unbound socket already uses it
+ if vrf == 'default':
+ vrf = None
+
for family, socktype, proto, canonname, sockaddr in addr_info:
- try:
- with socket.socket(family, socktype, proto) as s:
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- # When a VRF is specified, bind the socket to the VRF master
- # device so the address is resolved in that VRF's L3 domain.
- if vrf:
- s.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE,
- (vrf + '\0').encode())
+ with socket.socket(family, socktype, proto) as s:
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ # When a VRF is specified, bind the socket to the VRF master
+ # device so the address is resolved in that VRF's L3 domain.
+ if vrf:
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE,
+ (vrf + '\0').encode())
+ try:
s.bind(sockaddr)
return True # port is free to use
- except OSError:
- return False # port is already in use
+ except OSError:
+ return False # port is already in use
# if we reach this point, no socket was tested and we assume the port is
# already in use - better safe then sorry