Skip to content

Commit

Permalink
Fix: broken redudp
Browse files Browse the repository at this point in the history
  • Loading branch information
semigodking committed Mar 1, 2020
1 parent fd8aad1 commit 6a793f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions libc-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
# define IP_TRANSPARENT 19
#endif

#ifndef IPV6_TRANSPARENT
# warning Using hardcoded value for IPV6_TRANSPARENT as libc headers do not define it.
# define IPV6_TRANSPARENT 75
#endif

#ifndef SOL_IP
# warning Using hardcoded value for SOL_IP as libc headers do not define it.
# define SOL_IP IPPROTO_IP
Expand Down
3 changes: 1 addition & 2 deletions redudp.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ static void bound_udp4_action(const void *nodep, const VISIT which, const int de

static int do_tproxy(redudp_instance* instance)
{
// When listner is bound to IPv6 address, TPORXY must be used.
return instance->config.bindaddr.ss_family == AF_INET6 || instance->config.dest == NULL;
return instance->config.dest == NULL;
}

struct sockaddr_storage* get_destaddr(redudp_client *client)
Expand Down
13 changes: 10 additions & 3 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ int red_recv_udp_pkt(
if (
((cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_ORIGDSTADDR)
#ifdef SOL_IPV6
|| (cmsg->cmsg_level == SOL_IPV6 && cmsg->cmsg_type == IPV6_ORIGDSTADDR)
|| (cmsg->cmsg_level == SOL_IPV6 && cmsg->cmsg_type == IPV6_ORIGDSTADDR)
#endif
) &&
) &&
(cmsg->cmsg_len == CMSG_LEN(sizeof(struct sockaddr_in))
|| cmsg->cmsg_len == CMSG_LEN(sizeof(struct sockaddr_in6))) &&
cmsg->cmsg_len <= CMSG_LEN(sizeof(*toaddr))
Expand Down Expand Up @@ -497,7 +497,14 @@ size_t get_write_hwm(struct bufferevent *bufev)
int make_socket_transparent(int fd)
{
int on = 1;
int error = setsockopt(fd, SOL_IP, IP_TRANSPARENT, &on, sizeof(on));
int error = 0;
#ifdef SOL_IPV6
// Try IPv6 first
error = setsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT, &on, sizeof(on));
if (!error)
return error;
#endif
error = setsockopt(fd, SOL_IP, IP_TRANSPARENT, &on, sizeof(on));
if (error)
log_errno(LOG_ERR, "setsockopt(..., SOL_IP, IP_TRANSPARENT)");
return error;
Expand Down

0 comments on commit 6a793f5

Please sign in to comment.