MINOR: lua: txn: add function set_(loglevel|tos|mark)
This patch adds the "loglevel", "tos" and "mark" manipulation related to
one transaction.
diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index 3c76e50..545ee37 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -553,6 +553,31 @@
Not yet avalaible.
+.. js:function:: txn.set_loglevel(txn, loglevel)
+
+ Is used to change the log level of the current request. The "loglevel" must
+ be an integer between 0 and 7.
+
+ :param class_txn txn: The class txn object containing the data.
+ :param integer loglevel: The required log level. This variable can be one of
+ :see: core.<loglevel>
+
+.. js:function:: txn.set_tos(txn, tos)
+
+ Is used to set the TOS or DSCP field value of packets sent to the client to
+ the value passed in "tos" on platforms which support this.
+
+ :param class_txn txn: The class txn object containing the data.
+ :param integer tos: The new TOS os DSCP.
+
+.. js:function:: txn.set_mark(txn, mark)
+
+ Is used to set the Netfilter MARK on all packets sent to the client to the
+ value passed in "mark" on platforms which support it.
+
+ :param class_txn txn: The class txn object containing the data.
+ :param integer mark: The mark value.
+
Socket class
============
diff --git a/src/hlua.c b/src/hlua.c
index 7e416f2..65939ee 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2983,6 +2983,55 @@
return 1;
}
+__LJMP static int hlua_txn_set_loglevel(lua_State *L)
+{
+ struct hlua_txn *htxn;
+ int ll;
+
+ MAY_LJMP(check_args(L, 2, "set_loglevel"));
+ htxn = MAY_LJMP(hlua_checktxn(L, 1));
+ ll = MAY_LJMP(luaL_checkinteger(L, 2));
+
+ if (ll < 0 || ll > 7)
+ WILL_LJMP(luaL_argerror(L, 2, "Bad log level. It must be between 0 and 7"));
+
+ htxn->s->logs.level = ll;
+ return 0;
+}
+
+__LJMP static int hlua_txn_set_tos(lua_State *L)
+{
+ struct hlua_txn *htxn;
+ struct connection *cli_conn;
+ int tos;
+
+ MAY_LJMP(check_args(L, 2, "set_tos"));
+ htxn = MAY_LJMP(hlua_checktxn(L, 1));
+ tos = MAY_LJMP(luaL_checkinteger(L, 2));
+
+ if ((cli_conn = objt_conn(htxn->s->si[0].end)) && conn_ctrl_ready(cli_conn))
+ inet_set_tos(cli_conn->t.sock.fd, cli_conn->addr.from, tos);
+
+ return 0;
+}
+
+__LJMP static int hlua_txn_set_mark(lua_State *L)
+{
+#ifdef SO_MARK
+ struct hlua_txn *htxn;
+ struct connection *cli_conn;
+ int mark;
+
+ MAY_LJMP(check_args(L, 2, "set_mark"));
+ htxn = MAY_LJMP(hlua_checktxn(L, 1));
+ mark = MAY_LJMP(luaL_checkinteger(L, 2));
+
+ if ((cli_conn = objt_conn(htxn->s->si[0].end)) && conn_ctrl_ready(cli_conn))
+ setsockopt(cli_conn->t.sock.fd, SOL_SOCKET, SO_MARK, &mark, sizeof(int));
+#endif
+ return 0;
+}
+
/* This function is an Lua binding that send pending data
* to the client, and close the stream interface.
*/
@@ -4222,6 +4271,9 @@
hlua_class_function(gL.T, "set_priv", hlua_set_priv);
hlua_class_function(gL.T, "get_priv", hlua_get_priv);
hlua_class_function(gL.T, "close", hlua_txn_close);
+ hlua_class_function(gL.T, "set_loglevel",hlua_txn_set_loglevel);
+ hlua_class_function(gL.T, "set_tos", hlua_txn_set_tos);
+ hlua_class_function(gL.T, "set_mark", hlua_txn_set_mark);
lua_settable(gL.T, -3);