File tree Expand file tree Collapse file tree 2 files changed +22
-14
lines changed
Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 3636
3737/* FLB_CONNECTION_MAX_LABEL_LENGTH is the maximum length of
3838 * any of the following variants plus an optional colon if
39- * the spec includes a port number :
39+ * the spec includes a port number, as well as enclosing
40+ * square brackets for IPv6 addresses :
4041 *
41- * udp://
42- * tcp://
43- * unix://
42+ * udp:// (6 for prefix + 1 for colon + 2 for brackets = 9 total)
43+ * tcp:// (6 for prefix + 1 for colon + 2 for brackets = 9 total)
44+ * unix:// (7 for prefix)
4445 */
45- #define FLB_CONNECTION_MAX_LABEL_LENGTH 7
46+ #define FLB_CONNECTION_MAX_LABEL_LENGTH 9
4647
4748#define FLB_CONNECTION_MAX_IPV4_ADDRESS_LENGTH 15
4849#define FLB_CONNECTION_MAX_IPV6_ADDRESS_LENGTH 39
Original file line number Diff line number Diff line change 11#include <assert.h>
2+ #include <string.h>
23
34#include <fluent-bit/flb_connection.h>
45#include <fluent-bit/flb_upstream.h>
@@ -89,17 +90,23 @@ static void compose_user_friendly_remote_host(struct flb_connection *connection)
8990
9091 connection_type = connection -> stream -> transport ;
9192
92- if (connection_type == FLB_TRANSPORT_TCP ) {
93- snprintf (connection -> user_friendly_remote_host ,
94- sizeof (connection -> user_friendly_remote_host ),
95- "tcp://%s:%u" ,
96- connection -> remote_host ,
97- connection -> remote_port );
98- }
99- else if (connection_type == FLB_TRANSPORT_UDP ) {
93+ if (connection_type == FLB_TRANSPORT_TCP ||
94+ connection_type == FLB_TRANSPORT_UDP ) {
95+ const char * fmt ;
96+
97+ /* If the address is an IPv6 literal, we need to
98+ * enclose the address in square brackets.
99+ */
100+ if (strchr (connection -> remote_host , ':' ) != NULL ) {
101+ fmt = "%s://[%s]:%u" ;
102+ }
103+ else {
104+ fmt = "%s://%s:%u" ;
105+ }
100106 snprintf (connection -> user_friendly_remote_host ,
101107 sizeof (connection -> user_friendly_remote_host ),
102- "udp://%s:%u" ,
108+ fmt ,
109+ connection_type == FLB_TRANSPORT_TCP ? "tcp" : "udp" ,
103110 connection -> remote_host ,
104111 connection -> remote_port );
105112 }
You can’t perform that action at this time.
0 commit comments