Browse Source

Fix #493

pull/498/head
Max Lv 8 years ago
parent
commit
e921f40aa8
7 changed files with 37 additions and 0 deletions
  1. 4
      src/local.c
  2. 10
      src/netutils.c
  3. 6
      src/netutils.h
  4. 4
      src/redir.c
  5. 5
      src/server.c
  6. 4
      src/tunnel.c
  7. 4
      src/udprelay.c

4
src/local.c

@ -170,6 +170,10 @@ int create_and_bind(const char *addr, const char *port)
#ifdef SO_NOSIGPIPE
setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
#endif
int err = set_reuseport(listen_sock);
if (err == 0) {
LOGI("tcp port reuse enabled");
}
s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen);
if (s == 0) {

10
src/netutils.c

@ -42,6 +42,16 @@
#include "netutils.h"
#include "utils.h"
#ifndef SO_REUSEPORT
#define SO_REUSEPORT 15
#endif
int set_reuseport(int socket)
{
int opt = 1;
return setsockopt(socket, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt));
}
size_t get_sockaddr_len(struct sockaddr *addr)
{
if (addr->sa_family == AF_INET) {

6
src/netutils.h

@ -20,5 +20,11 @@
* <http://www.gnu.org/licenses/>.
*/
#ifndef _NETUTILS_H
#define _NETUTILS_H
size_t get_sockaddr_len(struct sockaddr *addr);
size_t get_sockaddr(char *host, char *port, struct sockaddr_storage *storage, int block);
int set_reuseport(int socket);
#endif

4
src/redir.c

@ -139,6 +139,10 @@ int create_and_bind(const char *addr, const char *port)
#ifdef SO_NOSIGPIPE
setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
#endif
int err = set_reuseport(listen_sock);
if (err == 0) {
LOGI("tcp port reuse enabled");
}
s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen);
if (s == 0) {

5
src/server.c

@ -356,6 +356,11 @@ int create_and_bind(const char *host, const char *port)
#ifdef SO_NOSIGPIPE
setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
#endif
int err = set_reuseport(listen_sock);
if (err == 0) {
LOGI("port reuse enabled");
}
s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen);
if (s == 0) {
/* We managed to bind successfully! */

4
src/tunnel.c

@ -148,6 +148,10 @@ int create_and_bind(const char *addr, const char *port)
#ifdef SO_NOSIGPIPE
setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
#endif
int err = set_reuseport(listen_sock);
if (err == 0) {
LOGI("tcp port reuse enabled");
}
s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen);
if (s == 0) {

4
src/udprelay.c

@ -438,6 +438,10 @@ int create_server_socket(const char *host, const char *port)
#ifdef SO_NOSIGPIPE
set_nosigpipe(server_sock);
#endif
int err = set_reuseport(server_sock);
if (err == 0) {
LOGI("udp port reuse enabled");
}
#ifdef MODULE_REDIR
if (setsockopt(server_sock, SOL_IP, IP_TRANSPARENT, &opt, sizeof(opt))) {

Loading…
Cancel
Save