From bd543db86b59dfec20975d4932c0889b9c2211cf Mon Sep 17 00:00:00 2001
From: Christof Schulze <christof.schulze@gmx.net>
Date: Fri, 23 Aug 2019 20:42:23 +0200
Subject: [PATCH] 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.
---
 package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua
index c0fe93cec..266ede38f 100644
--- a/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua
+++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua
@@ -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)
-- 
GitLab