]> git.proxmox.com Git - mirror_frr.git/blob - lib/frrlua.h
Merge pull request #7460 from pguibert6WIND/remove_bgp_constraint
[mirror_frr.git] / lib / frrlua.h
1 /*
2 * Copyright (C) 2016-2019 Cumulus Networks, Inc.
3 * Donald Sharp, Quentin Young
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #ifndef __FRRLUA_H__
20 #define __FRRLUA_H__
21
22 #include <zebra.h>
23
24 #ifdef HAVE_SCRIPTING
25
26 #include <lua.h>
27 #include <lualib.h>
28 #include <lauxlib.h>
29
30 #include "prefix.h"
31 #include "frrscript.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*
38 * gcc-10 is complaining about the wrapper function
39 * not being compatible with lua_pushstring returning
40 * a char *. Let's wrapper it here to make our life
41 * easier
42 */
43 static inline void lua_pushstring_wrapper(lua_State *L, const char *str)
44 {
45 (void)lua_pushstring(L, str);
46 }
47
48 /*
49 * Converts a prefix to a Lua value and pushes it on the stack.
50 */
51 void lua_pushprefix(lua_State *L, const struct prefix *prefix);
52
53 /*
54 * Converts the Lua value at idx to a prefix.
55 *
56 * Returns:
57 * struct prefix allocated with MTYPE_TMP
58 */
59 void *lua_toprefix(lua_State *L, int idx);
60
61 /*
62 * Converts an interface to a Lua value and pushes it on the stack.
63 */
64 void lua_pushinterface(lua_State *L, const struct interface *ifp);
65
66 /*
67 * Converts the Lua value at idx to an interface.
68 *
69 * Returns:
70 * struct interface allocated with MTYPE_TMP. This interface is not hooked
71 * to anything, nor is it inserted in the global interface tree.
72 */
73 void *lua_tointerface(lua_State *L, int idx);
74
75 /*
76 * Converts an in_addr to a Lua value and pushes it on the stack.
77 */
78 void lua_pushinaddr(lua_State *L, const struct in_addr *addr);
79
80 /*
81 * Converts the Lua value at idx to an in_addr.
82 *
83 * Returns:
84 * struct in_addr allocated with MTYPE_TMP.
85 */
86 void *lua_toinaddr(lua_State *L, int idx);
87
88 /*
89 * Converts an in6_addr to a Lua value and pushes it on the stack.
90 */
91 void lua_pushin6addr(lua_State *L, const struct in6_addr *addr);
92
93 /*
94 * Converts the Lua value at idx to an in6_addr.
95 *
96 * Returns:
97 * struct in6_addr allocated with MTYPE_TMP.
98 */
99 void *lua_toin6addr(lua_State *L, int idx);
100
101 /*
102 * Converts a time_t to a Lua value and pushes it on the stack.
103 */
104 void lua_pushtimet(lua_State *L, const time_t *time);
105
106 /*
107 * Converts the Lua value at idx to a time_t.
108 *
109 * Returns:
110 * time_t allocated with MTYPE_TMP.
111 */
112 void *lua_totimet(lua_State *L, int idx);
113
114 /*
115 * Converts a sockunion to a Lua value and pushes it on the stack.
116 */
117 void lua_pushsockunion(lua_State *L, const union sockunion *su);
118
119 /*
120 * Converts the Lua value at idx to a sockunion.
121 *
122 * Returns:
123 * sockunion allocated with MTYPE_TMP.
124 */
125 void *lua_tosockunion(lua_State *L, int idx);
126
127 /*
128 * Converts an int to a Lua value and pushes it on the stack.
129 */
130 void lua_pushintegerp(lua_State *L, const long long *num);
131
132 /*
133 * Converts the Lua value at idx to an int.
134 *
135 * Returns:
136 * int allocated with MTYPE_TMP.
137 */
138 void *lua_tointegerp(lua_State *L, int idx);
139
140 /*
141 * Pop string.
142 *
143 * Sets *string to a copy of the string at the top of the stack. The copy is
144 * allocated with MTYPE_TMP and the caller is responsible for freeing it.
145 */
146 void *lua_tostringp(lua_State *L, int idx);
147
148 /*
149 * Retrieve an integer from table on the top of the stack.
150 *
151 * key
152 * Key of string value in table
153 */
154 int frrlua_table_get_integer(lua_State *L, const char *key);
155
156 /*
157 * Exports a new table containing bindings to FRR zlog functions into the
158 * global namespace.
159 *
160 * From Lua, these functions may be accessed as:
161 *
162 * - log.debug()
163 * - log.info()
164 * - log.warn()
165 * - log.error()
166 *
167 * They take a single string argument.
168 */
169 void frrlua_export_logging(lua_State *L);
170
171 /*
172 * Dump Lua stack to a string.
173 *
174 * Return value must be freed with XFREE(MTYPE_TMP, ...);
175 */
176 char *frrlua_stackdump(lua_State *L);
177
178 #ifdef __cplusplus
179 }
180 #endif
181
182 #endif /* HAVE_SCRIPTING */
183
184 #endif /* __FRRLUA_H__ */