]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: frontend: switch to conn_get_{src,dst}() for logging and debugging
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Jul 2019 09:25:46 +0000 (11:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 19 Jul 2019 11:50:09 +0000 (13:50 +0200)
The frontend accept code uses conn_get_{from,to}_addr for logging and
debugging, without really checking if the operation succeeds. In
preparation of future changes, let's switch to conn_get_{src,dst}() and
integrate status check for possible failures.

src/frontend.c

index 47a9b1dee221356226e7ce8b8f048b39de30da8b..92c8323ee4308fa907bd046169bafd5b2b337353 100644 (file)
@@ -65,19 +65,27 @@ int frontend_accept(struct stream *s)
                                if (!(s->logs.logwait &= ~(LW_CLIP|LW_INIT)))
                                        s->do_log(s);
                }
+               else if (conn && !conn_get_src(conn)) {
+                       send_log(fe, LOG_INFO, "Connect from unknown source to listener %d (%s/%s)\n",
+                                l->luid, fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
+               }
                else if (conn) {
                        char pn[INET6_ADDRSTRLEN], sn[INET6_ADDRSTRLEN];
-
-                       conn_get_from_addr(conn);
-                       conn_get_to_addr(conn);
+                       int port;
 
                        switch (addr_to_str(&conn->addr.from, pn, sizeof(pn))) {
                        case AF_INET:
                        case AF_INET6:
-                               addr_to_str(&conn->addr.to, sn, sizeof(sn));
+                               if (conn_get_dst(conn)) {
+                                       addr_to_str(&conn->addr.to, sn, sizeof(sn));
+                                       port = get_host_port(&conn->addr.to);
+                               } else {
+                                       strcpy(sn, "undetermined address");
+                                       port = 0;
+                               }
                                send_log(fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
                                         pn, get_host_port(&conn->addr.from),
-                                        sn, get_host_port(&conn->addr.to),
+                                        sn, port,
                                         fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
                                break;
                        case AF_UNIX:
@@ -97,11 +105,8 @@ int frontend_accept(struct stream *s)
                const char *alpn_str = NULL;
                int alpn_len;
 
-               conn_get_from_addr(conn);
-
                /* try to report the ALPN value when available (also works for NPN) */
-
-               if (conn && conn == cs_conn(objt_cs(s->si[0].end))) {
+               if (conn == cs_conn(objt_cs(s->si[0].end))) {
                        if (conn_get_alpn(conn, &alpn_str, &alpn_len) && alpn_str) {
                                int len = MIN(alpn_len, sizeof(alpn) - 1);
                                memcpy(alpn, alpn_str, len);
@@ -109,7 +114,12 @@ int frontend_accept(struct stream *s)
                        }
                }
 
-               switch (addr_to_str(&conn->addr.from, pn, sizeof(pn))) {
+               if (!conn_get_src(conn)) {
+                       chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n",
+                                    s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
+                                    l->luid, alpn);
+               }
+               else switch (addr_to_str(&conn->addr.from, pn, sizeof(pn))) {
                case AF_INET:
                case AF_INET6:
                        chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n",