blob: d2aaa4a3c69de399fecc920dda9fb5ad6785298c [file] [log] [blame]
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +01001#ifndef _TYPES_HLUA_H
2#define _TYPES_HLUA_H
3
Thierry FOURNIERa718b292015-03-04 16:48:34 +01004#ifdef USE_LUA
5
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +01006#include <lua.h>
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +01007#include <lauxlib.h>
8
9#include <types/proxy.h>
10#include <types/server.h>
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +010011
Thierry FOURNIER0efc94c2015-09-16 21:22:28 +020012#define CLASS_CORE "Core"
13#define CLASS_TXN "TXN"
14#define CLASS_FETCHES "Fetches"
15#define CLASS_CONVERTERS "Converters"
16#define CLASS_SOCKET "Socket"
17#define CLASS_CHANNEL "Channel"
18#define CLASS_HTTP "HTTP"
19#define CLASS_MAP "Map"
Thierry FOURNIERf0a64b62015-09-19 12:36:17 +020020#define CLASS_APPLET_TCP "AppletTCP"
Thierry FOURNIERa30b5db2015-09-18 09:04:27 +020021#define CLASS_APPLET_HTTP "AppletHTTP"
Thierry Fournierf61aa632016-02-19 20:56:00 +010022#define CLASS_PROXY "Proxy"
Thierry Fournierf2fdc9d2016-02-22 08:21:39 +010023#define CLASS_SERVER "Server"
Thierry Fournierff480422016-02-25 08:36:46 +010024#define CLASS_LISTENER "Listener"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010025
Willy Tarreau87b09662015-04-03 00:22:06 +020026struct stream;
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010027
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010028#define HLUA_RUN 0x00000001
Thierry FOURNIER4abd3ae2015-03-03 17:29:06 +010029#define HLUA_CTRLYIELD 0x00000002
Thierry FOURNIERef6a2112015-03-05 17:45:34 +010030#define HLUA_WAKERESWR 0x00000004
Thierry FOURNIER53e08ec2015-03-06 00:35:53 +010031#define HLUA_WAKEREQWR 0x00000008
Thierry FOURNIER0a99b892015-08-26 00:14:17 +020032#define HLUA_EXIT 0x00000010
Thierry FOURNIER7c39ab42015-09-27 22:53:33 +020033#define HLUA_MUST_GC 0x00000020
Thierry FOURNIER9bd52d42016-07-14 11:45:33 +020034#define HLUA_STOP 0x00000040
Thierry FOURNIER380d0932015-01-23 14:27:52 +010035
Thierry FOURNIER7fa05492015-12-20 18:42:25 +010036#define HLUA_F_AS_STRING 0x01
Thierry FOURNIERca988662015-12-20 18:43:03 +010037#define HLUA_F_MAY_USE_HTTP 0x02
Thierry FOURNIER7fa05492015-12-20 18:42:25 +010038
Thierry FOURNIERab00df62016-07-14 11:42:37 +020039#define HLUA_TXN_NOTERM 0x00000001
40
Thierry Fournier49d48422016-02-19 12:09:29 +010041#define HLUA_CONCAT_BLOCSZ 2048
42
Thierry FOURNIER380d0932015-01-23 14:27:52 +010043enum hlua_exec {
44 HLUA_E_OK = 0,
45 HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when
46 the associatedtask is waked. */
47 HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message
48 in the top of stack. */
49 HLUA_E_ERR, /* LUA stack execution failed without error message. */
50};
51
52struct hlua {
53 lua_State *T; /* The LUA stack. */
54 int Tref; /* The reference of the stack in coroutine case.
55 -1 for the main lua stack. */
56 int Mref; /* The reference of the memory context in coroutine case.
57 -1 if the memory context is not used. */
58 int nargs; /* The number of arguments in the stack at the start of execution. */
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010059 unsigned int flags; /* The current execution flags. */
Thierry FOURNIERc42c1ae2015-03-03 17:17:55 +010060 int wake_time; /* The lua wants to be waked at this time, or before. */
Thierry FOURNIER10770fa2015-09-29 01:59:42 +020061 unsigned int max_time; /* The max amount of execution time for an Lua process, in ms. */
62 unsigned int start_time; /* The ms time when the Lua starts the last execution. */
63 unsigned int run_time; /* Lua total execution time in ms. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010064 struct task *task; /* The task associated with the lua stack execution.
65 We must wake this task to continue the task execution */
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010066 struct list com; /* The list head of the signals attached to this task. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010067 struct ebpt_node node;
68};
69
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010070struct hlua_com {
71 struct list purge_me; /* Part of the list of signals to be purged in the
72 case of the LUA execution stack crash. */
73 struct list wake_me; /* Part of list of signals to be targeted if an
74 event occurs. */
75 struct task *task; /* The task to be wake if an event occurs. */
76};
77
Thierry FOURNIERa4a0f3d2015-01-23 12:08:30 +010078/* This is a part of the list containing references to functions
79 * called at the initialisation time.
80 */
81struct hlua_init_function {
82 struct list l;
83 int function_ref;
84};
85
Thierry FOURNIERfa0e5dd2015-02-16 20:19:18 +010086/* This struct contains the lua data used to bind
87 * Lua function on HAProxy hook like sample-fetches
88 * or actions.
89 */
90struct hlua_function {
91 char *name;
92 int function_ref;
93};
94
Thierry FOURNIER258d8aa2015-02-16 20:23:40 +010095/* This struct is used with the structs:
96 * - http_req_rule
97 * - http_res_rule
98 * - tcp_rule
99 * It contains the lua execution configuration.
100 */
101struct hlua_rule {
102 struct hlua_function fcn;
103 char **args;
104};
105
Thierry FOURNIER65f34c62015-02-16 20:11:43 +0100106/* This struct contains the pointer provided on the most
107 * of internal HAProxy calls during the processing of
108 * rules, converters and sample-fetches. This struct is
109 * associated with the lua object called "TXN".
110 */
111struct hlua_txn {
Willy Tarreau87b09662015-04-03 00:22:06 +0200112 struct stream *s;
Thierry FOURNIER65f34c62015-02-16 20:11:43 +0100113 struct proxy *p;
Thierry FOURNIERc4eebc82015-11-02 10:01:59 +0100114 int dir; /* SMP_OPT_DIR_{REQ,RES} */
Thierry FOURNIERab00df62016-07-14 11:42:37 +0200115 int flags;
Thierry FOURNIER65f34c62015-02-16 20:11:43 +0100116};
117
Thierry FOURNIERf0a64b62015-09-19 12:36:17 +0200118/* This struct contains the applet context. */
119struct hlua_appctx {
120 struct appctx *appctx;
121 luaL_Buffer b; /* buffer used to prepare strings. */
122 struct hlua_txn htxn;
123};
124
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100125/* This struc is used with sample fetches and sample converters. */
126struct hlua_smp {
Willy Tarreau87b09662015-04-03 00:22:06 +0200127 struct stream *s;
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100128 struct proxy *p;
Thierry FOURNIER7fa05492015-12-20 18:42:25 +0100129 unsigned int flags; /* LUA_F_OPT_* */
Thierry FOURNIERc4eebc82015-11-02 10:01:59 +0100130 int dir; /* SMP_OPT_DIR_{REQ,RES} */
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100131};
132
Thierry FOURNIER5b8608f2015-02-16 19:43:25 +0100133/* This struct contains data used with sleep functions. */
134struct hlua_sleep {
135 struct task *task; /* task associated with sleep. */
136 struct list com; /* list of signal to wake at the end of sleep. */
137 unsigned int wakeup_ms; /* hour to wakeup. */
138};
139
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100140/* This struct is used to create coprocess doing TCP or
Willy Tarreau87b09662015-04-03 00:22:06 +0200141 * SSL I/O. It uses a fake stream.
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100142 */
143struct hlua_socket {
Willy Tarreau87b09662015-04-03 00:22:06 +0200144 struct stream *s; /* Stream used for socket I/O. */
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100145 luaL_Buffer b; /* buffer used to prepare strings. */
146};
147
Thierry Fournier49d48422016-02-19 12:09:29 +0100148struct hlua_concat {
149 int size;
150 int len;
151};
152
Thierry FOURNIER / OZON.IO62fec752016-11-10 20:38:11 +0100153struct hlua_addr {
154 union {
155 struct {
156 struct in_addr ip;
157 struct in_addr mask;
158 } v4;
159 struct {
160 struct in6_addr ip;
161 struct in6_addr mask;
162 } v6;
163 } addr;
164 int type;
165};
166
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100167#else /* USE_LUA */
168
169/* Empty struct for compilation compatibility */
170struct hlua { };
171struct hlua_socket { };
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200172struct hlua_rule { };
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100173
174#endif /* USE_LUA */
175
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100176#endif /* _TYPES_HLUA_H */