]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: tcp: condition TCP keepalive settings to platforms providing them
authorWilly Tarreau <w@1wt.eu>
Thu, 9 Jul 2020 03:58:51 +0000 (05:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 9 Jul 2020 03:58:51 +0000 (05:58 +0200)
Previous commit b24bc0d ("MINOR: tcp: Support TCP keepalive parameters
customization") broke non-Linux builds as TCP_KEEP{CNT,IDLE,INTVL} are
not necessarily defined elsewhere.

This patch adds the required #ifdefs to condition the visibility of the
keywords, and adds a mention in the doc about their dependency on Linux.

doc/configuration.txt
src/proto_tcp.c
src/proxy.c
src/session.c

index 28630ba3fe107c45fa620809f7b641f9bdc01576..d040af6ba744084ee6a3327a7a1b04b498e673b3 100644 (file)
@@ -3588,6 +3588,8 @@ clitcpka-cnt <count>
 
   This keyword corresponds to the socket option TCP_KEEPCNT. If this keyword
   is not specified, system-wide TCP parameter (tcp_keepalive_probes) is used.
+  The availability of this setting depends on the operating system. It is
+  known to work on Linux.
 
   See also : "option clitcpka", "clitcpka-idle", "clitcpka-intvl".
 
@@ -3606,6 +3608,8 @@ clitcpka-idle <timeout>
 
   This keyword corresponds to the socket option TCP_KEEPIDLE. If this keyword
   is not specified, system-wide TCP parameter (tcp_keepalive_time) is used.
+  The availability of this setting depends on the operating system. It is
+  known to work on Linux.
 
   See also : "option clitcpka", "clitcpka-cnt", "clitcpka-intvl".
 
@@ -3622,6 +3626,8 @@ clitcpka-intvl <timeout>
 
   This keyword corresponds to the socket option TCP_KEEPINTVL. If this keyword
   is not specified, system-wide TCP parameter (tcp_keepalive_intvl) is used.
+  The availability of this setting depends on the operating system. It is
+  known to work on Linux.
 
   See also : "option clitcpka", "clitcpka-cnt", "clitcpka-idle".
 
@@ -9471,6 +9477,8 @@ srvtcpka-cnt <count>
 
   This keyword corresponds to the socket option TCP_KEEPCNT. If this keyword
   is not specified, system-wide TCP parameter (tcp_keepalive_probes) is used.
+  The availability of this setting depends on the operating system. It is
+  known to work on Linux.
 
   See also : "option srvtcpka", "srvtcpka-idle", "srvtcpka-intvl".
 
@@ -9489,6 +9497,8 @@ srvtcpka-idle <timeout>
 
   This keyword corresponds to the socket option TCP_KEEPIDLE. If this keyword
   is not specified, system-wide TCP parameter (tcp_keepalive_time) is used.
+  The availability of this setting depends on the operating system. It is
+  known to work on Linux.
 
   See also : "option srvtcpka", "srvtcpka-cnt", "srvtcpka-intvl".
 
@@ -9505,6 +9515,8 @@ srvtcpka-intvl <timeout>
 
   This keyword corresponds to the socket option TCP_KEEPINTVL. If this keyword
   is not specified, system-wide TCP parameter (tcp_keepalive_intvl) is used.
+  The availability of this setting depends on the operating system. It is
+  known to work on Linux.
 
   See also : "option srvtcpka", "srvtcpka-cnt", "srvtcpka-idle".
 
index 0fdb9440af2ed9ae956149fe49cb04769de095b6..b772c88d9fce8dd84bf2ee415fe1c9fea36cab3f 100644 (file)
@@ -382,14 +382,20 @@ int tcp_connect_server(struct connection *conn, int flags)
        if (be->options & PR_O_TCP_SRV_KA) {
                setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one));
 
+#ifdef TCP_KEEPCNT
                if (be->srvtcpka_cnt)
                        setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &be->srvtcpka_cnt, sizeof(be->srvtcpka_cnt));
+#endif
 
+#ifdef TCP_KEEPIDLE
                if (be->srvtcpka_idle)
                        setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &be->srvtcpka_idle, sizeof(be->srvtcpka_idle));
+#endif
 
+#ifdef TCP_KEEPINTVL
                if (be->srvtcpka_intvl)
                        setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &be->srvtcpka_intvl, sizeof(be->srvtcpka_intvl));
+#endif
        }
 
        /* allow specific binding :
index a03cbd043e27e0342b60982e4b2157924bbd5190..3e42370d808d5acebae88484f4b30a6c4df99c5f 100644 (file)
@@ -570,6 +570,7 @@ proxy_parse_retry_on(char **args, int section, struct proxy *curpx,
        return 0;
 }
 
+#ifdef TCP_KEEPCNT
 /* This function parses "{cli|srv}tcpka-cnt" statements */
 static int proxy_parse_tcpka_cnt(char **args, int section, struct proxy *proxy,
                                     struct proxy *defpx, const char *file, int line,
@@ -614,7 +615,9 @@ static int proxy_parse_tcpka_cnt(char **args, int section, struct proxy *proxy,
 
        return retval;
 }
+#endif
 
+#ifdef TCP_KEEPIDLE
 /* This function parses "{cli|srv}tcpka-idle" statements */
 static int proxy_parse_tcpka_idle(char **args, int section, struct proxy *proxy,
                                   struct proxy *defpx, const char *file, int line,
@@ -668,7 +671,9 @@ static int proxy_parse_tcpka_idle(char **args, int section, struct proxy *proxy,
 
        return retval;
 }
+#endif
 
+#ifdef TCP_KEEPINTVL
 /* This function parses "{cli|srv}tcpka-intvl" statements */
 static int proxy_parse_tcpka_intvl(char **args, int section, struct proxy *proxy,
                                   struct proxy *defpx, const char *file, int line,
@@ -722,6 +727,7 @@ static int proxy_parse_tcpka_intvl(char **args, int section, struct proxy *proxy
 
        return retval;
 }
+#endif
 
 /* This function inserts proxy <px> into the tree of known proxies. The proxy's
  * name is used as the storing key so it must already have been initialized.
@@ -1828,12 +1834,18 @@ static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_LISTEN, "max-keep-alive-queue", proxy_parse_max_ka_queue },
        { CFG_LISTEN, "declare", proxy_parse_declare },
        { CFG_LISTEN, "retry-on", proxy_parse_retry_on },
+#ifdef TCP_KEEPCNT
        { CFG_LISTEN, "clitcpka-cnt", proxy_parse_tcpka_cnt },
-       { CFG_LISTEN, "clitcpka-idle", proxy_parse_tcpka_idle },
-       { CFG_LISTEN, "clitcpka-intvl", proxy_parse_tcpka_intvl },
        { CFG_LISTEN, "srvtcpka-cnt", proxy_parse_tcpka_cnt },
+#endif
+#ifdef TCP_KEEPIDLE
+       { CFG_LISTEN, "clitcpka-idle", proxy_parse_tcpka_idle },
        { CFG_LISTEN, "srvtcpka-idle", proxy_parse_tcpka_idle },
+#endif
+#ifdef TCP_KEEPINTVL
+       { CFG_LISTEN, "clitcpka-intvl", proxy_parse_tcpka_intvl },
        { CFG_LISTEN, "srvtcpka-intvl", proxy_parse_tcpka_intvl },
+#endif
        { 0, NULL, NULL },
 }};
 
index 51380d638ca88cf980fa56a04964b1f4f4ce034a..4fad934ceca44e0d12226f137a28260c7565623b 100644 (file)
@@ -227,14 +227,20 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
                if (p->options & PR_O_TCP_CLI_KA) {
                        setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one));
 
+#ifdef TCP_KEEPCNT
                        if (p->clitcpka_cnt)
                                setsockopt(cfd, IPPROTO_TCP, TCP_KEEPCNT, &p->clitcpka_cnt, sizeof(p->clitcpka_cnt));
+#endif
 
+#ifdef TCP_KEEPIDLE
                        if (p->clitcpka_idle)
                                setsockopt(cfd, IPPROTO_TCP, TCP_KEEPIDLE, &p->clitcpka_idle, sizeof(p->clitcpka_idle));
+#endif
 
+#ifdef TCP_KEEPINTVL
                        if (p->clitcpka_intvl)
                                setsockopt(cfd, IPPROTO_TCP, TCP_KEEPINTVL, &p->clitcpka_intvl, sizeof(p->clitcpka_intvl));
+#endif
                }
 
                if (p->options & PR_O_TCP_NOLING)