diff options
| author | l0crian1 <ryan.claridge13@gmail.com> | 2025-08-28 22:05:54 -0400 |
|---|---|---|
| committer | l0crian1 <ryan.claridge13@gmail.com> | 2025-08-28 22:05:54 -0400 |
| commit | 048ff4fab605a1c6ebf5124fe2adedb81788066e (patch) | |
| tree | 006eb0d55ad5145a1a5da57d1ce73faf00d0fe96 /python | |
| parent | 86b3b035b8559ee5dd8da8d4a57a11c041b32882 (diff) | |
| download | vyos-1x-048ff4fab605a1c6ebf5124fe2adedb81788066e.tar.gz vyos-1x-048ff4fab605a1c6ebf5124fe2adedb81788066e.zip | |
container: T7186: Add macvlan network type for containers
- Moved gen_mac function outside of 'for network' loop
- Cached result of get_host_identity() to prevent multiple calls
- Other minor improvements per Copilot suggestions
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/utils/network.py | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py index 50f1771e2..e6b838cdc 100644 --- a/python/vyos/utils/network.py +++ b/python/vyos/utils/network.py @@ -68,7 +68,7 @@ def get_host_identity() -> str: host = cmd("hostname").strip().lower() return f"{uuid}:{host}" -def gen_mac(name: str, addr: str) -> str: +def gen_mac(name: str, addr: str, ident: str) -> str: """ Generate a deterministic locally-administered MAC address. @@ -88,7 +88,6 @@ def gen_mac(name: str, addr: str) -> str: Returns: str: Deterministic MAC address in standard "xx:xx:xx:xx:xx:xx" format. """ - ident = get_host_identity() h = hashlib.sha256(f"{ident}:{name}:{addr}".encode()).hexdigest() # 0x02 = locally-administered, unicast b = [0x02] + [int(h[i:i+2], 16) for i in range(0, 10, 2)] # 5 bytes = 40 bits |
