Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions include/fluent-bit/flb_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@

/* FLB_CONNECTION_MAX_LABEL_LENGTH is the maximum length of
* any of the following variants plus an optional colon if
* the spec includes a port number :
* the spec includes a port number, as well as enclosing
* square brackets for IPv6 addresses :
*
* udp://
* tcp://
* unix://
* udp:// (6 for prefix + 1 for colon + 2 for brackets = 9 total)
* tcp:// (6 for prefix + 1 for colon + 2 for brackets = 9 total)
* unix:// (7 for prefix)
*/
#define FLB_CONNECTION_MAX_LABEL_LENGTH 7
#define FLB_CONNECTION_MAX_LABEL_LENGTH 9

#define FLB_CONNECTION_MAX_IPV4_ADDRESS_LENGTH 15
#define FLB_CONNECTION_MAX_IPV6_ADDRESS_LENGTH 39
Expand Down
4 changes: 2 additions & 2 deletions plugins/in_syslog/syslog_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ static int syslog_server_net_create(struct flb_syslog *ctx)
&ctx->ins->net_setup);

if (ctx->downstream != NULL) {
flb_info("[in_syslog] %s server binding %s:%s",
flb_info("[in_syslog] %s server binding %s port %s",
((ctx->mode == FLB_SYSLOG_TCP) ? "TCP" : "UDP"),
ctx->listen, ctx->port);
}
else {
flb_error("[in_syslog] could not bind address %s:%s. Aborting",
flb_error("[in_syslog] could not bind address %s port %s. Aborting",
ctx->listen, ctx->port);

return -1;
Expand Down
25 changes: 16 additions & 9 deletions src/flb_connection.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <string.h>

#include <fluent-bit/flb_connection.h>
#include <fluent-bit/flb_upstream.h>
Expand Down Expand Up @@ -89,17 +90,23 @@ static void compose_user_friendly_remote_host(struct flb_connection *connection)

connection_type = connection->stream->transport;

if (connection_type == FLB_TRANSPORT_TCP) {
snprintf(connection->user_friendly_remote_host,
sizeof(connection->user_friendly_remote_host),
"tcp://%s:%u",
connection->remote_host,
connection->remote_port);
}
else if (connection_type == FLB_TRANSPORT_UDP) {
if (connection_type == FLB_TRANSPORT_TCP ||
connection_type == FLB_TRANSPORT_UDP) {
const char *fmt;

/* If the address is an IPv6 literal, we need to
* enclose the address in square brackets.
*/
if (strchr(connection->remote_host, ':') != NULL) {
fmt = "%s://[%s]:%u";
}
else {
fmt = "%s://%s:%u";
}
snprintf(connection->user_friendly_remote_host,
sizeof(connection->user_friendly_remote_host),
"udp://%s:%u",
fmt,
connection_type == FLB_TRANSPORT_TCP ? "tcp" : "udp",
connection->remote_host,
connection->remote_port);
}
Expand Down
18 changes: 17 additions & 1 deletion src/flb_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,7 @@ static int net_address_ip_str(flb_sockfd_t fd,
size_t *output_data_size)
{
void *address_data;
int family;
int result;

errno = 0;
Expand Down Expand Up @@ -2184,7 +2185,22 @@ static int net_address_ip_str(flb_sockfd_t fd,
return -1;
}

if ((inet_ntop(address->ss_family,
family = address->ss_family;

/*
* For IPv4-mapped IPv6 addresses (e.g. ::ffff:127.0.0.1),
* emit a plain IPv4 literal instead.
*/
if (address->ss_family == AF_INET6) {
struct in6_addr *addr6 = (struct in6_addr *) address_data;

if (IN6_IS_ADDR_V4MAPPED(addr6)) {
family = AF_INET;
address_data = &addr6->s6_addr[12];
}
}

if ((inet_ntop(family,
address_data,
output_buffer,
output_buffer_size)) == NULL) {
Expand Down