REORG: connection: centralize the conn_set_{tos,mark,quickack} functions
There were a number of ugly setsockopt() calls spread all over
proto_http.c, proto_htx.c and hlua.c just to manipulate the front
connection's TOS, mark or TCP quick-ack. These ones entirely relied
on the connection, its existence, its control layer's presence, and
its addresses. Worse, inet_set_tos() was placed in proto_http.c,
exported and used from the two other ones, surrounded in #ifdefs.
This patch moves this code to connection.h and makes the other ones
rely on it without ifdefs.
diff --git a/src/proto_htx.c b/src/proto_htx.c
index c22908a..9088ecb 100644
--- a/src/proto_htx.c
+++ b/src/proto_htx.c
@@ -225,16 +225,16 @@
channel_dont_connect(req);
req->flags |= CF_READ_DONTWAIT; /* try to get back here ASAP */
s->res.flags &= ~CF_EXPECT_MORE; /* speed up sending a previous response */
-#ifdef TCP_QUICKACK
+
if (sess->listener->options & LI_O_NOQUICKACK && htx_is_not_empty(htx) &&
objt_conn(sess->origin) && conn_ctrl_ready(__objt_conn(sess->origin))) {
/* We need more data, we have to re-enable quick-ack in case we
* previously disabled it, otherwise we might cause the client
* to delay next data.
*/
- setsockopt(__objt_conn(sess->origin)->handle.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
+ conn_set_quickack(objt_conn(sess->origin), 1);
}
-#endif
+
if ((req->flags & CF_READ_PARTIAL) && (txn->flags & TX_WAIT_NEXT_RQ)) {
/* If the client starts to talk, let's fall back to
* request timeout processing.
@@ -951,17 +951,15 @@
req->analysers &= ~AN_REQ_FLT_XFER_DATA;
req->analysers |= AN_REQ_HTTP_XFER_BODY;
-#ifdef TCP_QUICKACK
+
/* We expect some data from the client. Unless we know for sure
* we already have a full request, we have to re-enable quick-ack
* in case we previously disabled it, otherwise we might cause
* the client to delay further data.
*/
if ((sess->listener->options & LI_O_NOQUICKACK) &&
- cli_conn && conn_ctrl_ready(cli_conn) &&
(htx_get_tail_type(htx) != HTX_BLK_EOM))
- setsockopt(cli_conn->handle.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
-#endif
+ conn_set_quickack(cli_conn, 1);
/*************************************************************
* OK, that's finished for the headers. We have done what we *
@@ -2754,7 +2752,6 @@
struct session *sess = strm_sess(s);
struct http_txn *txn = s->txn;
struct htx *htx;
- struct connection *cli_conn;
struct act_rule *rule;
struct http_hdr_ctx ctx;
const char *auth_realm;
@@ -2850,15 +2847,11 @@
break;
case ACT_HTTP_SET_TOS:
- if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
- inet_set_tos(cli_conn->handle.fd, &cli_conn->addr.from, rule->arg.tos);
+ conn_set_tos(objt_conn(sess->origin), rule->arg.tos);
break;
case ACT_HTTP_SET_MARK:
-#ifdef SO_MARK
- if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
- setsockopt(cli_conn->handle.fd, SOL_SOCKET, SO_MARK, &rule->arg.mark, sizeof(rule->arg.mark));
-#endif
+ conn_set_mark(objt_conn(sess->origin), rule->arg.mark);
break;
case ACT_HTTP_SET_LOGL:
@@ -3144,7 +3137,6 @@
struct session *sess = strm_sess(s);
struct http_txn *txn = s->txn;
struct htx *htx;
- struct connection *cli_conn;
struct act_rule *rule;
struct http_hdr_ctx ctx;
enum rule_result rule_ret = HTTP_RULE_RES_CONT;
@@ -3197,15 +3189,11 @@
break;
case ACT_HTTP_SET_TOS:
- if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
- inet_set_tos(cli_conn->handle.fd, &cli_conn->addr.from, rule->arg.tos);
+ conn_set_tos(objt_conn(sess->origin), rule->arg.tos);
break;
case ACT_HTTP_SET_MARK:
-#ifdef SO_MARK
- if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
- setsockopt(cli_conn->handle.fd, SOL_SOCKET, SO_MARK, &rule->arg.mark, sizeof(rule->arg.mark));
-#endif
+ conn_set_mark(objt_conn(sess->origin), rule->arg.mark);
break;
case ACT_HTTP_SET_LOGL: