summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Lee <dlqs@gmx.com>2021-08-18 20:25:40 +0800
committerDonald Lee <dlqs@gmx.com>2021-10-20 00:56:00 +0800
commit9b851b74b0310a50530d505f20792ee7a108eb2e (patch)
tree3388837fc0ba93d67431fcb6a110007ae53ac567
parente6f42b94c6168b35ef9382d6aa68137b5c6c92ed (diff)
lib: Add encoder/decoder for nexthop/nexthop group
Signed-off-by: Donald Lee <dlqs@gmx.com>
-rw-r--r--lib/frrlua.c52
-rw-r--r--lib/frrlua.h4
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/frrlua.c b/lib/frrlua.c
index d407388bb9..535649eff2 100644
--- a/lib/frrlua.c
+++ b/lib/frrlua.c
@@ -312,6 +312,58 @@ void *lua_tointegerp(lua_State *L, int idx)
return num;
}
+void lua_pushnexthop(lua_State *L, const struct nexthop *nexthop)
+{
+ lua_newtable(L);
+ lua_pushinteger(L, nexthop->vrf_id);
+ lua_setfield(L, -2, "vrf_id");
+ lua_pushinteger(L, nexthop->ifindex);
+ lua_setfield(L, -2, "ifindex");
+ lua_pushinteger(L, nexthop->type);
+ lua_setfield(L, -2, "type");
+ lua_pushinteger(L, nexthop->flags);
+ lua_setfield(L, -2, "flags");
+ if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE) {
+ lua_pushinteger(L, nexthop->bh_type);
+ lua_setfield(L, -2, "bh_type");
+ } else if (nexthop->type == NEXTHOP_TYPE_IPV4) {
+ lua_pushinaddr(L, &nexthop->gate.ipv4);
+ lua_setfield(L, -2, "gate");
+ } else if (nexthop->type == NEXTHOP_TYPE_IPV6) {
+ lua_pushin6addr(L, &nexthop->gate.ipv6);
+ lua_setfield(L, -2, "gate");
+ }
+ lua_pushinteger(L, nexthop->nh_label_type);
+ lua_setfield(L, -2, "nh_label_type");
+ lua_pushinteger(L, nexthop->weight);
+ lua_setfield(L, -2, "weight");
+ lua_pushinteger(L, nexthop->backup_num);
+ lua_setfield(L, -2, "backup_num");
+ lua_pushinteger(L, *(nexthop->backup_idx));
+ lua_setfield(L, -2, "backup_idx");
+ if (nexthop->nh_encap_type == NET_VXLAN) {
+ lua_pushinteger(L, nexthop->nh_encap.vni);
+ lua_setfield(L, -2, "vni");
+ }
+ lua_pushinteger(L, nexthop->nh_encap_type);
+ lua_setfield(L, -2, "nh_encap_type");
+ lua_pushinteger(L, nexthop->srte_color);
+ lua_setfield(L, -2, "srte_color");
+}
+
+void lua_pushnexthop_group(lua_State *L, const struct nexthop_group *ng)
+{
+ lua_newtable(L);
+ struct nexthop *nexthop;
+ int i = 0;
+
+ for (ALL_NEXTHOPS_PTR(ng, nexthop)) {
+ lua_pushnexthop(L, nexthop);
+ lua_seti(L, -2, i);
+ i++;
+ }
+}
+
void lua_decode_stringp(lua_State *L, int idx, char *str)
{
strlcpy(str, lua_tostring(L, idx), strlen(str) + 1);
diff --git a/lib/frrlua.h b/lib/frrlua.h
index ed1d5f8b4a..a82009a779 100644
--- a/lib/frrlua.h
+++ b/lib/frrlua.h
@@ -142,6 +142,10 @@ void lua_decode_sockunion(lua_State *L, int idx, union sockunion *su);
*/
void *lua_tosockunion(lua_State *L, int idx);
+void lua_pushnexthop_group(lua_State *L, const struct nexthop_group *ng);
+
+void lua_pushnexthop(lua_State *L, const struct nexthop *nexthop);
+
/*
* Converts an int to a Lua value and pushes it on the stack.
*/