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

transparent proxy: use IP_BINDANY where available #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
19 changes: 16 additions & 3 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,16 +630,29 @@ initiate_server_connect(struct Connection *con, struct ev_loop *loop) {

if (con->listener->transparent_proxy &&
con->client.addr.ss_family == con->server.addr.ss_family) {
#ifdef IP_TRANSPARENT
#if defined(IP_TRANSPARENT)
int on = 1;
int result = setsockopt(sockfd, SOL_IP, IP_TRANSPARENT, &on, sizeof(on));
#elif defined(IP_BINDANY) && defined(IPV6_BINDANY)
int on = 1;
int result = -EINVAL;
switch(con->server.addr.ss_family) {
case AF_INET:
result = setsockopt(sockfd, IPPROTO_IP, IP_BINDANY, &on, sizeof(on));
break;
case AF_INET6:
result = setsockopt(sockfd, IPPROTO_IPV6, IPV6_BINDANY, &on, sizeof(on));
break;
default:
err("unsupported address family %d does not support transparent mode", con->server.addr.ss_family);
}
#else
int result = -EPERM;
int result = -EINVAL;
/* XXX error: not implemented would be better, but this shouldn't be
* reached since it is prohibited in the configuration parser. */
#endif
if (result < 0) {
err("setsockopt IP_TRANSPARENT failed: %s", strerror(errno));
err("setsockopt IP_TRANSPARENT/BINDANY failed: %s", strerror(errno));
close(sockfd);
abort_connection(con);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ accept_listener_source_address(struct Listener *listener, const char *source) {
}

if (strcasecmp("client", source) == 0) {
#ifdef IP_TRANSPARENT
#if defined(IP_TRANSPARENT) || defined(IP_BINDANY) && defined(IPV6_BINDANY)
listener->transparent_proxy = 1;
return 1;
#else
Expand Down