summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-08-18 20:22:21 +0800
committerDonald Lee <dlqs@gmx.com>2021-10-20 00:56:00 +0800
commite6f42b94c6168b35ef9382d6aa68137b5c6c92ed (patch)
treed26addad0b036467ef73ba2dd2ef66ab45829ec8
parentd759866d5b9026f8761bf89dfc9c4107cc1df764 (diff)
lib: Add encoders/decoders for ipaddr/ethaddr
Signed-off-by: Donald Lee <dlqs@gmx.com>
-rw-r--r--lib/frrlua.c15
-rw-r--r--lib/frrlua.h4
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/frrlua.c b/lib/frrlua.c
index 00491568f6..d407388bb9 100644
--- a/lib/frrlua.c
+++ b/lib/frrlua.c
@@ -223,6 +223,21 @@ void *lua_toin6addr(lua_State *L, int idx)
return in6addr;
}
+void lua_pushipaddr(lua_State *L, const struct ipaddr *addr)
+{
+ if (IS_IPADDR_V4(addr))
+ lua_pushinaddr(L, &addr->ipaddr_v4);
+ else
+ lua_pushin6addr(L, &addr->ipaddr_v6);
+}
+
+void lua_pushethaddr(lua_State *L, const struct ethaddr *addr)
+{
+ lua_newtable(L);
+ lua_pushinteger(L, *(addr->octet));
+ lua_setfield(L, -2, "octet");
+}
+
void lua_pushsockunion(lua_State *L, const union sockunion *su)
{
char buf[SU_ADDRSTRLEN];
diff --git a/lib/frrlua.h b/lib/frrlua.h
index 3e16c82e22..ed1d5f8b4a 100644
--- a/lib/frrlua.h
+++ b/lib/frrlua.h
@@ -100,6 +100,10 @@ void lua_pushin6addr(lua_State *L, const struct in6_addr *addr);
void lua_decode_in6addr(lua_State *L, int idx, struct in6_addr *addr);
+void lua_pushipaddr(lua_State *L, const struct ipaddr *addr);
+
+void lua_pushethaddr(lua_State *L, const struct ethaddr *addr);
+
/*
* Converts the Lua value at idx to an in6_addr.
*