]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Add encoders/decoders for ipaddr/ethaddr
authorDonald Lee <dlqs@gmx.com>
Wed, 18 Aug 2021 12:22:21 +0000 (20:22 +0800)
committerDonald Lee <dlqs@gmx.com>
Tue, 19 Oct 2021 16:56:00 +0000 (00:56 +0800)
Signed-off-by: Donald Lee <dlqs@gmx.com>
lib/frrlua.c
lib/frrlua.h

index 00491568f63efef42d36acd5c67b7c45fab5e561..d407388bb957c95952ba6d4a69b4d29b82d1e3c9 100644 (file)
@@ -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];
index 3e16c82e2255eba59ac0a4eb2d147cda505fc2d0..ed1d5f8b4a15b51b2bbfc6dbd524798fd83f5a21 100644 (file)
@@ -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.
  *