]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/frrlua.c
Merge pull request #12584 from pguibert6WIND/bgp_imported_distance
[mirror_frr.git] / lib / frrlua.c
index 00491568f63efef42d36acd5c67b7c45fab5e561..535649eff2c35ff7656427697b4a4256fee99055 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];
@@ -297,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);