Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: fix IPV6 handling for accepting connections #9404

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 12 additions & 6 deletions src/flb_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1758,16 +1758,22 @@ int flb_net_bind_udp(flb_sockfd_t fd, const struct sockaddr *addr,
flb_sockfd_t flb_net_accept(flb_sockfd_t server_fd)
{
flb_sockfd_t remote_fd;
struct sockaddr sock_addr;
socklen_t socket_size = sizeof(struct sockaddr);

// return accept(server_fd, &sock_addr, &socket_size);
struct sockaddr_storage sock_addr = { 0 };
socklen_t socket_size = sizeof(sock_addr);

/*
* sock_addr used to be a sockaddr struct, but this was too
* small of a structure to handle IPV6 addresses (#9053).
* This would cause accept() to not accept the connection (with no error),
* and a loop would occur continually trying to accept the connection.
* The sockaddr_storage can handle both IPV4 and IPV6.
*/

#ifdef FLB_HAVE_ACCEPT4
remote_fd = accept4(server_fd, &sock_addr, &socket_size,
remote_fd = accept4(server_fd, (struct sockaddr*)&sock_addr, &socket_size,
SOCK_NONBLOCK | SOCK_CLOEXEC);
#else
remote_fd = accept(server_fd, &sock_addr, &socket_size);
remote_fd = accept(server_fd, (struct sockaddr*)&sock_addr, &socket_size);
flb_net_socket_nonblocking(remote_fd);
#endif

Expand Down