Skip to content
Snippets Groups Projects
Commit bd543db8 authored by Christof Schulze's avatar Christof Schulze Committed by Matthias Schiffer
Browse files

gluon-core: enhance mac_to_ip() beyond RFC 4291 (#1798)

mac_to_ip() calculates an ipv6 address from a mac address according to
RFC 4291. For wireguard we have to use specially crafted addresses that
must be unique. This allows calculating such unique mac-based addresses
by allowing to optionally specifying the bytes to be inserted into the
address.
parent 087f14be
Branches
Tags
No related merge requests found
......@@ -74,10 +74,10 @@ function M.IPv6(address)
end
end
function M.mac_to_ip(prefix, mac)
function M.mac_to_ip(prefix, mac, firstbyte, secondbyte)
local m1, m2, m3, m6, m7, m8 = string.match(mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)')
local m4 = 0xff
local m5 = 0xfe
local m4 = firstbyte or 0xff
local m5 = secondbyte or 0xfe
m1 = bit.bxor(tonumber(m1, 16), 0x02)
local h1 = 0x100 * m1 + tonumber(m2, 16)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment