]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] use tproxy address as source of health checks
authorWilly Tarreau <w@1wt.eu>
Tue, 14 Nov 2006 15:18:41 +0000 (16:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 14 Nov 2006 15:18:41 +0000 (16:18 +0100)
If a tproxy address is defined, then use it for health checks too.

src/checks.c

index 9643a2b0d6f9eab8757b1187ad48540376628641..99b843555b51300d465551f82d56bb81ec180bac 100644 (file)
 #include <proto/server.h>
 #include <proto/task.h>
 
+#ifdef CONFIG_HAP_CTTPROXY
+#include <import/ip_tproxy.h>
+#endif
+
 
 /* Sets server <s> down, notifies by all available means, recounts the
  * remaining servers on the proxy and transfers queued sessions whenever
@@ -260,6 +264,27 @@ int process_chk(struct task *t)
                                                      s->proxy->id, s->id);
                                                s->result = -1;
                                        }
+#ifdef CONFIG_HAP_CTTPROXY
+                                       if ((s->state & SRV_TPROXY_MASK) == SRV_TPROXY_ADDR) {
+                                               struct in_tproxy itp1, itp2;
+                                               memset(&itp1, 0, sizeof(itp1));
+                                               
+                                               itp1.op = TPROXY_ASSIGN;
+                                               itp1.v.addr.faddr = s->tproxy_addr.sin_addr;
+                                               itp1.v.addr.fport = s->tproxy_addr.sin_port;
+
+                                               /* set connect flag on socket */
+                                               itp2.op = TPROXY_FLAGS;
+                                               itp2.v.flags = ITP_CONNECT | ITP_ONCE;
+
+                                               if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) == -1 ||
+                                                   setsockopt(fd, SOL_IP, IP_TPROXY, &itp2, sizeof(itp2)) == -1) {
+                                                       Alert("Cannot bind to tproxy source address before connect() for server %s/%s. Aborting.\n",
+                                                             s->proxy->id, s->id);
+                                                       s->result = -1;
+                                               }
+                                       }
+#endif
                                }
                                else if (s->proxy->options & PR_O_BIND_SRC) {
                                        setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one));
@@ -268,6 +293,27 @@ int process_chk(struct task *t)
                                                      s->proxy->id);
                                                s->result = -1;
                                        }
+#ifdef CONFIG_HAP_CTTPROXY
+                                       if ((s->proxy->options & PR_O_TPXY_MASK) == PR_O_TPXY_ADDR) {
+                                               struct in_tproxy itp1, itp2;
+                                               memset(&itp1, 0, sizeof(itp1));
+                                               
+                                               itp1.op = TPROXY_ASSIGN;
+                                               itp1.v.addr.faddr = s->tproxy_addr.sin_addr;
+                                               itp1.v.addr.fport = s->tproxy_addr.sin_port;
+                                               
+                                               /* set connect flag on socket */
+                                               itp2.op = TPROXY_FLAGS;
+                                               itp2.v.flags = ITP_CONNECT | ITP_ONCE;
+                                               
+                                               if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) == -1 ||
+                                                   setsockopt(fd, SOL_IP, IP_TPROXY, &itp2, sizeof(itp2)) == -1) {
+                                                       Alert("Cannot bind to tproxy source address before connect() for proxy %s. Aborting.\n",
+                                                             s->proxy->id);
+                                                       s->result = -1;
+                                               }
+                                       }
+#endif
                                }
 
                                if (!s->result) {