diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-08-05 14:10:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-05 14:10:53 +0200 |
| commit | 636f74e180a6481892fd87f7957b9b3758bb17e8 (patch) | |
| tree | 5080ff64af8c4cd183ee374c6057a88b1c98cb6f /python | |
| parent | 02ab78102df4f58c149d375de8a88494ee9e02df (diff) | |
| parent | 1373026ff54e6496ae182ede56ada5eca120fb83 (diff) | |
| download | vyos-1x-636f74e180a6481892fd87f7957b9b3758bb17e8.tar.gz vyos-1x-636f74e180a6481892fd87f7957b9b3758bb17e8.zip | |
Merge pull request #5352 from c-po/container-veth
container: T7736: give container veths a deterministic host_interface_name
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/container.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/python/vyos/container.py b/python/vyos/container.py index 475d796f2..b2dd306c4 100644 --- a/python/vyos/container.py +++ b/python/vyos/container.py @@ -12,11 +12,27 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from hashlib import sha256 + from vyos.config import Config from vyos.ifconfig import Interface from vyos.utils.dict import dict_search from vyos.utils.network import interface_exists +def get_container_host_ifname(name: str) -> str: + """ + Deterministic host-side veth interface name for a container's network + attachment (verify() only allows one network per container). Kept within + IFNAMSIZ and - thanks to the leading "veth-" (a hyphen can never appear in + a VyOS "vethN" interface name) - guaranteed to never collide with the + "virtual-ethernet" naming scheme.. + """ + prefix = f'veth-{name}' + if len(prefix) <= 15: + return prefix + digest = sha256(name.encode()).hexdigest()[:4] + return f'veth-{name[:5]}-{digest}' + def restart_network(config: Config) -> None: """ Start network and assign it to given VRF if requested. |
