From e6f42b94c6168b35ef9382d6aa68137b5c6c92ed Mon Sep 17 00:00:00 2001 From: Donald Lee Date: Wed, 18 Aug 2021 20:22:21 +0800 Subject: [PATCH] lib: Add encoders/decoders for ipaddr/ethaddr Signed-off-by: Donald Lee --- lib/frrlua.c | 15 +++++++++++++++ lib/frrlua.h | 4 ++++ 2 files changed, 19 insertions(+) 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. * -- 2.39.5