]> git.proxmox.com Git - mirror_frr.git/blame - lib/frrlua.h
Merge pull request #12708 from donaldsharp/no_notification
[mirror_frr.git] / lib / frrlua.h
CommitLineData
634949ae 1/*
60219659
QY
2 * Copyright (C) 2016-2019 Cumulus Networks, Inc.
3 * Donald Sharp, Quentin Young
634949ae 4 *
60219659
QY
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.
634949ae 9 *
60219659
QY
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.
634949ae
DS
14 *
15 * You should have received a copy of the GNU General Public License along
60219659
QY
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
634949ae 18 */
60219659
QY
19#ifndef __FRRLUA_H__
20#define __FRRLUA_H__
634949ae 21
fa22080d
QY
22#include <zebra.h>
23
24#ifdef HAVE_SCRIPTING
634949ae 25
9e47ee98
QY
26#include <lua.h>
27#include <lualib.h>
28#include <lauxlib.h>
634949ae 29
60219659 30#include "prefix.h"
5f98c815 31#include "frrscript.h"
60219659 32
5e244469
RW
33#ifdef __cplusplus
34extern "C" {
35#endif
36
78f1ac25
DL
37DECLARE_MTYPE(SCRIPT_RES);
38
ea6caa1f
DS
39/*
40 * gcc-10 is complaining about the wrapper function
41 * not being compatible with lua_pushstring returning
42 * a char *. Let's wrapper it here to make our life
43 * easier
44 */
45static inline void lua_pushstring_wrapper(lua_State *L, const char *str)
46{
47 (void)lua_pushstring(L, str);
48}
49
60219659 50/*
f869ab17 51 * Converts a prefix to a Lua value and pushes it on the stack.
634949ae 52 */
47dd8736 53void lua_pushprefix(lua_State *L, const struct prefix *prefix);
634949ae 54
3a3cfe47
DL
55void lua_decode_prefix(lua_State *L, int idx, struct prefix *prefix);
56
cd6ca660 57/*
f869ab17
QY
58 * Converts the Lua value at idx to a prefix.
59 *
60 * Returns:
61 * struct prefix allocated with MTYPE_TMP
62 */
63void *lua_toprefix(lua_State *L, int idx);
64
65/*
66 * Converts an interface to a Lua value and pushes it on the stack.
cd6ca660 67 */
47dd8736 68void lua_pushinterface(lua_State *L, const struct interface *ifp);
cd6ca660 69
3a3cfe47
DL
70void lua_decode_interface(lua_State *L, int idx, struct interface *ifp);
71
60219659 72/*
f869ab17
QY
73 * Converts the Lua value at idx to an interface.
74 *
75 * Returns:
76 * struct interface allocated with MTYPE_TMP. This interface is not hooked
77 * to anything, nor is it inserted in the global interface tree.
78 */
79void *lua_tointerface(lua_State *L, int idx);
80
81/*
82 * Converts an in_addr to a Lua value and pushes it on the stack.
42ae55b5 83 */
47dd8736 84void lua_pushinaddr(lua_State *L, const struct in_addr *addr);
42ae55b5 85
3a3cfe47
DL
86void lua_decode_inaddr(lua_State *L, int idx, struct in_addr *addr);
87
42ae55b5 88/*
f869ab17
QY
89 * Converts the Lua value at idx to an in_addr.
90 *
91 * Returns:
92 * struct in_addr allocated with MTYPE_TMP.
93 */
94void *lua_toinaddr(lua_State *L, int idx);
95
96/*
97 * Converts an in6_addr to a Lua value and pushes it on the stack.
42ae55b5 98 */
47dd8736 99void lua_pushin6addr(lua_State *L, const struct in6_addr *addr);
42ae55b5 100
3a3cfe47
DL
101void lua_decode_in6addr(lua_State *L, int idx, struct in6_addr *addr);
102
e6f42b94
DL
103void lua_pushipaddr(lua_State *L, const struct ipaddr *addr);
104
105void lua_pushethaddr(lua_State *L, const struct ethaddr *addr);
106
42ae55b5 107/*
f869ab17
QY
108 * Converts the Lua value at idx to an in6_addr.
109 *
110 * Returns:
111 * struct in6_addr allocated with MTYPE_TMP.
112 */
113void *lua_toin6addr(lua_State *L, int idx);
114
115/*
116 * Converts a time_t to a Lua value and pushes it on the stack.
42ae55b5 117 */
47dd8736 118void lua_pushtimet(lua_State *L, const time_t *time);
42ae55b5 119
3a3cfe47
DL
120void lua_decode_timet(lua_State *L, int idx, time_t *time);
121
42ae55b5 122/*
f869ab17
QY
123 * Converts the Lua value at idx to a time_t.
124 *
125 * Returns:
126 * time_t allocated with MTYPE_TMP.
127 */
128void *lua_totimet(lua_State *L, int idx);
129
130/*
131 * Converts a sockunion to a Lua value and pushes it on the stack.
60219659 132 */
47dd8736 133void lua_pushsockunion(lua_State *L, const union sockunion *su);
634949ae 134
3a3cfe47
DL
135void lua_decode_sockunion(lua_State *L, int idx, union sockunion *su);
136
eeb61724 137/*
f869ab17
QY
138 * Converts the Lua value at idx to a sockunion.
139 *
140 * Returns:
141 * sockunion allocated with MTYPE_TMP.
142 */
143void *lua_tosockunion(lua_State *L, int idx);
144
9b851b74
DL
145void lua_pushnexthop_group(lua_State *L, const struct nexthop_group *ng);
146
147void lua_pushnexthop(lua_State *L, const struct nexthop *nexthop);
148
f869ab17
QY
149/*
150 * Converts an int to a Lua value and pushes it on the stack.
151 */
152void lua_pushintegerp(lua_State *L, const long long *num);
153
3a3cfe47
DL
154void lua_decode_integerp(lua_State *L, int idx, long long *num);
155
f869ab17
QY
156/*
157 * Converts the Lua value at idx to an int.
158 *
159 * Returns:
160 * int allocated with MTYPE_TMP.
161 */
162void *lua_tointegerp(lua_State *L, int idx);
163
3a3cfe47
DL
164void lua_decode_stringp(lua_State *L, int idx, char *str);
165
f869ab17
QY
166/*
167 * Pop string.
168 *
169 * Sets *string to a copy of the string at the top of the stack. The copy is
170 * allocated with MTYPE_TMP and the caller is responsible for freeing it.
eeb61724 171 */
f869ab17 172void *lua_tostringp(lua_State *L, int idx);
eeb61724 173
7e058da5 174/*
6d28552d 175 * No-op decoders
7e058da5
DL
176 */
177void lua_decode_noop(lua_State *L, int idx, const void *ptr);
178
36cf58c7 179void lua_decode_integer_noop(lua_State *L, int idx, int i);
2b67227e 180
634949ae 181/*
60219659
QY
182 * Retrieve an integer from table on the top of the stack.
183 *
184 * key
185 * Key of string value in table
634949ae 186 */
60219659 187int frrlua_table_get_integer(lua_State *L, const char *key);
5e244469 188
d473bdc7
QY
189/*
190 * Exports a new table containing bindings to FRR zlog functions into the
191 * global namespace.
192 *
193 * From Lua, these functions may be accessed as:
194 *
195 * - log.debug()
196 * - log.info()
197 * - log.warn()
198 * - log.error()
199 *
200 * They take a single string argument.
201 */
202void frrlua_export_logging(lua_State *L);
203
e93f19fb
QY
204/*
205 * Dump Lua stack to a string.
206 *
207 * Return value must be freed with XFREE(MTYPE_TMP, ...);
208 */
209char *frrlua_stackdump(lua_State *L);
210
5e244469
RW
211#ifdef __cplusplus
212}
213#endif
214
fa22080d
QY
215#endif /* HAVE_SCRIPTING */
216
60219659 217#endif /* __FRRLUA_H__ */