1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2016-2019 Cumulus Networks, Inc.
* Donald Sharp, Quentin Young
*/
#ifndef __FRRLUA_H__
#define __FRRLUA_H__
#ifdef HAVE_SCRIPTING
#include <netinet/in.h>
#include <lua.h>
#include "lib/memory.h"
#ifdef __cplusplus
extern "C" {
#endif
struct interface;
struct prefix;
struct ipaddr;
struct ethaddr;
union sockunion;
struct nexthop_group;
struct nexthop;
struct buffer;
DECLARE_MTYPE(SCRIPT_RES);
/*
* gcc-10 is complaining about the wrapper function
* not being compatible with lua_pushstring returning
* a char *. Let's wrapper it here to make our life
* easier
*/
static inline void lua_pushstring_wrapper(lua_State *L, const char *str)
{
(void)lua_pushstring(L, str);
}
/*
* Converts a prefix to a Lua value and pushes it on the stack.
*/
void lua_pushprefix(lua_State *L, const struct prefix *prefix);
void lua_decode_prefix(lua_State *L, int idx, struct prefix *prefix);
/*
* Converts the Lua value at idx to a prefix.
*
* Returns:
* struct prefix allocated with MTYPE_TMP
*/
void *lua_toprefix(lua_State *L, int idx);
/*
* Converts an interface to a Lua value and pushes it on the stack.
*/
void lua_pushinterface(lua_State *L, const struct interface *ifp);
void lua_decode_interface(lua_State *L, int idx, struct interface *ifp);
/*
* Converts the Lua value at idx to an interface.
*
* Returns:
* struct interface allocated with MTYPE_TMP. This interface is not hooked
* to anything, nor is it inserted in the global interface tree.
*/
void *lua_tointerface(lua_State *L, int idx);
/*
* Converts an in_addr to a Lua value and pushes it on the stack.
*/
void lua_pushinaddr(lua_State *L, const struct in_addr *addr);
void lua_decode_inaddr(lua_State *L, int idx, struct in_addr *addr);
/*
* Converts the Lua value at idx to an in_addr.
*
* Returns:
* struct in_addr allocated with MTYPE_TMP.
*/
void *lua_toinaddr(lua_State *L, int idx);
/*
* Converts an in6_addr to a Lua value and pushes it on the stack.
*/
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.
*
* Returns:
* struct in6_addr allocated with MTYPE_TMP.
*/
void *lua_toin6addr(lua_State *L, int idx);
/*
* Converts a sockunion to a Lua value and pushes it on the stack.
*/
void lua_pushsockunion(lua_State *L, const union sockunion *su);
void lua_decode_sockunion(lua_State *L, int idx, union sockunion *su);
/*
* Converts the Lua value at idx to a sockunion.
*
* Returns:
* sockunion allocated with MTYPE_TMP.
*/
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.
*/
void lua_pushintegerp(lua_State *L, const int *num);
void lua_decode_integerp(lua_State *L, int idx, int *num);
/*
* Converts the Lua value at idx to an int.
*
* Returns:
* int allocated with MTYPE_TMP.
*/
void *lua_tointegerp(lua_State *L, int idx);
/*
* Converts a long long to a Lua value and pushes it on the stack.
*/
void lua_pushlonglongp(lua_State *L, const long long *num);
void lua_decode_longlongp(lua_State *L, int idx, long long *num);
/*
* Converts the Lua value at idx to a long long.
*
* Returns:
* long long allocated with MTYPE_TMP.
*/
void *lua_tolonglongp(lua_State *L, int idx);
void lua_decode_stringp(lua_State *L, int idx, char *str);
/*
* Pop string.
*
* Sets *string to a copy of the string at the top of the stack. The copy is
* allocated with MTYPE_TMP and the caller is responsible for freeing it.
*/
void *lua_tostringp(lua_State *L, int idx);
/*
* Retrieve an integer from table on the top of the stack.
*
* key
* Key of string value in table
*/
int frrlua_table_get_integer(lua_State *L, const char *key);
/*
* Exports a new table containing bindings to FRR zlog functions into the
* global namespace.
*
* From Lua, these functions may be accessed as:
*
* - log.debug()
* - log.info()
* - log.warn()
* - log.error()
*
* They take a single string argument.
*/
void frrlua_export_logging(lua_State *L);
/* A helper fuction that dumps the Lua stack */
void lua_table_dump(lua_State *L, int index, struct buffer *buf, int level);
/*
* Dump Lua stack to a string.
*
* Return value must be freed with XFREE(MTYPE_TMP, ...);
*/
char *frrlua_stackdump(lua_State *L);
#ifdef __cplusplus
}
#endif
#endif /* HAVE_SCRIPTING */
#endif /* __FRRLUA_H__ */
|