bneradt commented on code in PR #14065:
URL: https://github.com/apache/trafficserver/pull/14065#discussion_r4568411846


##########
src/proxy/ProtocolProbeSessionAccept.cc:
##########
@@ -157,7 +157,11 @@ struct ProtocolProbeTrampoline : public Continuation, 
public ProtocolProbeSessio
 
     acceptor = probeParent->endpoint[static_cast<int>(key)];
     if (acceptor == nullptr) {
-      Warning("Unregistered protocol type %d", static_cast<int>(key));
+      char client_ip[INET6_ADDRSTRLEN];
+      ats_ip_ntop(netvc->get_remote_addr(), client_ip, sizeof(client_ip));
+      Warning("Closing connection from client_ip=%s on local port %d: the 
client spoke %s, but this port is not configured for it. "
+              "Check the protocols for this port in 
proxy.config.http.server_ports (proto=...).",
+              client_ip, netvc->get_local_port(), key == ProtoGroupKey::HTTP2 
? "HTTP/2 with prior knowledge (h2c)" : "HTTP/1.x");

Review Comment:
   Agreed, fixed in 59a3a80a6d. The warning now says what the probe detected 
rather than what the client spoke:
   
   - HTTP2 key: "sent an HTTP/2 connection preface (h2c prior knowledge), but 
this port does not enable HTTP/2", with the `proto=` hint.
   - HTTP key, h2 preface on TLS (the RFC 9113 ยง3.3 branch): "sent an HTTP/2 
connection preface over TLS without negotiating h2 via ALPN, which RFC 9113 
forbids, so it was handled as HTTP/1.x, which this port does not enable". Its 
advice is "The client must negotiate h2 via ALPN." instead of the `proto=` 
hint, since enabling HTTP/1.x would not fix it.
   - HTTP key otherwise (TLS ClientHello on a plaintext port, scanner bytes, 
short reads): "did not send an HTTP/2 connection preface, so it was handled as 
HTTP/1.x, which this port does not enable", with the `proto=` hint.
   
   Added urtests for the plain `HTTP` branch (an HTTP/1.1 request to a 
`proto=http2` port) and for the h2-preface-over-TLS-without-ALPN case on an 
`ssl:proto=http2` port.



##########
src/proxy/ProtocolProbeSessionAccept.cc:
##########
@@ -157,7 +157,11 @@ struct ProtocolProbeTrampoline : public Continuation, 
public ProtocolProbeSessio
 
     acceptor = probeParent->endpoint[static_cast<int>(key)];
     if (acceptor == nullptr) {
-      Warning("Unregistered protocol type %d", static_cast<int>(key));
+      char client_ip[INET6_ADDRSTRLEN];
+      ats_ip_ntop(netvc->get_remote_addr(), client_ip, sizeof(client_ip));

Review Comment:
   Good catch, fixed in 59a3a80a6d. Addresses now go through a helper that 
calls `ats_ip_ntop` only when `ats_is_ip()` is true. For `AF_UNIX` it bounds 
the path with `strnlen(sun_path, TS_UNIX_SIZE)` into a `std::string`, so 
nothing relies on a NUL terminator, and an unbound client socket is reported as 
`unix:(unnamed)`. The listener is likewise named "local port N" only for IP 
sockets and "listener unix:<path>" otherwise, so it no longer says "local port 
0".
   
   Added a urtest that binds a client socket to a path over 46 bytes, connects 
to a default UDS port, sends the h2 preface, and checks that the full client 
path and the listener path are logged.



##########
src/proxy/ProtocolProbeSessionAccept.cc:
##########
@@ -157,7 +157,11 @@ struct ProtocolProbeTrampoline : public Continuation, 
public ProtocolProbeSessio
 
     acceptor = probeParent->endpoint[static_cast<int>(key)];
     if (acceptor == nullptr) {
-      Warning("Unregistered protocol type %d", static_cast<int>(key));
+      char client_ip[INET6_ADDRSTRLEN];
+      ats_ip_ntop(netvc->get_remote_addr(), client_ip, sizeof(client_ip));

Review Comment:
   Done in 59a3a80a6d. When a PROXY header was parsed and has a source address, 
the warning logs `client_ip=<pp-src> (peer <tcp-peer>)`; otherwise just the TCP 
peer. Added a urtest that sends a v1 PROXY header followed by the h2 preface to 
a `:pp` HTTP-only port and checks for `client_ip=192.0.2.10 (peer 127.0.0.1)`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to