]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: txn: add function set_(loglevel|tos|mark)
authorThierry FOURNIER <tfournier@haproxy.com>
Mon, 16 Mar 2015 11:04:16 +0000 (12:04 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 18 Mar 2015 10:34:06 +0000 (11:34 +0100)
This patch adds the "loglevel", "tos" and "mark" manipulation related to
one transaction.

doc/lua-api/index.rst
src/hlua.c

index 3c76e50bbe9c290d8e2a628f54b46279f7be1378..545ee375074aad87b43786a73a95e8b0442a0307 100644 (file)
@@ -553,6 +553,31 @@ TXN class
 
   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
 ============
 
index 7e416f20c1dd90fc947d0962e9fbff9401c52ad7..65939eebbd2b61e5486ca6bb340f070618f4c4a1 100644 (file)
@@ -2983,6 +2983,55 @@ static int hlua_txn_new(lua_State *L, struct session *s, struct proxy *p, void *
        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 @@ void hlua_init(void)
        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);