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