Skip to content

Commit

Permalink
two commits for fix bugs on macos 10.15 & openssl 1.1: (darkk#146)
Browse files Browse the repository at this point in the history
* fix Invalid bind address format bug on macos

* change version number

* add __APPLE__ macro when bind to be compatible with linux and openbsd sockets definition


This reverts commit 8ce821e.
  • Loading branch information
HaoH authored May 10, 2020
1 parent a11c058 commit d94c245
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SRCS := $(OBJS:.o=.c)
CONF := config.h
DEPS := .depend
OUT := redsocks2
VERSION := 0.67
VERSION := 0.68
OS := $(shell uname)

LIBS := -levent
Expand Down
10 changes: 7 additions & 3 deletions redsocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ static int redsocks_init_instance(redsocks_instance *instance)
* looks ugly.
*/
int error;
int bindaddr_len = 0;
evutil_socket_t fd = -1;

if (instance->relay_ss->instance_init
Expand Down Expand Up @@ -1000,9 +1001,12 @@ static int redsocks_init_instance(redsocks_instance *instance)
if (apply_reuseport(fd))
log_error(LOG_WARNING, "Continue without SO_REUSEPORT enabled");

error = bind(fd,
(struct sockaddr*)&instance->config.bindaddr,
sizeof(instance->config.bindaddr));
#ifdef __APPLE__
bindaddr_len = instance->config.bindaddr.ss_len > 0 ? instance->config.bindaddr.ss_len : sizeof(instance->config.bindaddr);
#else
bindaddr_len = sizeof(instance->config.bindaddr);
#endif
error = bind(fd, (struct sockaddr*)&instance->config.bindaddr, bindaddr_len);
if (error) {
log_errno(LOG_ERR, "bind");
goto fail;
Expand Down
8 changes: 7 additions & 1 deletion redudp.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ static int redudp_init_instance(redudp_instance *instance)
*/
int error;
int fd = -1;
int bindaddr_len = 0;
char buf1[RED_INET_ADDRSTRLEN], buf2[RED_INET_ADDRSTRLEN];

instance->shared_buff = &shared_buff[0];
Expand Down Expand Up @@ -616,7 +617,12 @@ static int redudp_init_instance(redudp_instance *instance)
if (apply_reuseport(fd))
log_error(LOG_WARNING, "Continue without SO_REUSEPORT enabled");

error = bind(fd, (struct sockaddr*)&instance->config.bindaddr, sizeof(instance->config.bindaddr));
#ifdef __APPLE__
bindaddr_len = instance->config.bindaddr.ss_len > 0 ? instance->config.bindaddr.ss_len : sizeof(instance->config.bindaddr);
#else
bindaddr_len = sizeof(instance->config.bindaddr);
#endif
error = bind(fd, (struct sockaddr*)&instance->config.bindaddr, bindaddr_len);
if (error) {
log_errno(LOG_ERR, "bind");
goto fail;
Expand Down
8 changes: 7 additions & 1 deletion tcpdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ static int tcpdns_init_instance(tcpdns_instance *instance)
*/
int error;
int fd = -1;
int bindaddr_len = 0;
char buf1[RED_INET_ADDRSTRLEN];

fd = socket(instance->config.bindaddr.ss_family, SOCK_DGRAM, IPPROTO_UDP);
Expand All @@ -462,7 +463,12 @@ static int tcpdns_init_instance(tcpdns_instance *instance)
if (apply_reuseport(fd))
log_error(LOG_WARNING, "Continue without SO_REUSEPORT enabled");

error = bind(fd, (struct sockaddr*)&instance->config.bindaddr, sizeof(instance->config.bindaddr));
#ifdef __APPLE__
bindaddr_len = instance->config.bindaddr.ss_len > 0 ? instance->config.bindaddr.ss_len : sizeof(instance->config.bindaddr);
#else
bindaddr_len = sizeof(instance->config.bindaddr);
#endif
error = bind(fd, (struct sockaddr*)&instance->config.bindaddr, bindaddr_len);
if (error) {
log_errno(LOG_ERR, "bind");
goto fail;
Expand Down
18 changes: 10 additions & 8 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,19 +500,21 @@ int make_socket_transparent(int fd)
int error = 0;
#ifdef SOL_IPV6
int error_6 = 0;
// Try IPv6 first
error_6 = setsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT, &on, sizeof(on));
if (error_6)
log_errno(LOG_DEBUG, "setsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT)");
#endif

error = setsockopt(fd, SOL_IP, IP_TRANSPARENT, &on, sizeof(on));
if (error)
log_errno(LOG_DEBUG, "setsockopt(fd, SOL_IP, IP_TRANSPARENT)");
if (error && error_6) {

#ifdef SOL_IPV6
error_6 = setsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT, &on, sizeof(on));
if (error_6)
log_errno(LOG_DEBUG, "setsockopt(fd, SOL_IPV6, IPV6_TRANSPARENT)");

if (error && error_6)
log_error(LOG_ERR, "Can not make socket transparent. See debug log for details.");
return error;
}
return 0;
#endif
return error;
}

int apply_tcp_fastopen(int fd)
Expand Down

0 comments on commit d94c245

Please sign in to comment.