diff --git a/shadowsocks/shell.py b/shadowsocks/shell.py index d53e461..69853d0 100644 --- a/shadowsocks/shell.py +++ b/shadowsocks/shell.py @@ -261,6 +261,12 @@ def get_config(is_local): except Exception as e: logging.error(e) sys.exit(2) + try: + config['ignore_bind'] = \ + IPNetwork(config.get('ignore_bind', '127.0.0.0/8,::1/128')) + except Exception as e: + logging.error(e) + sys.exit(2) config['server_port'] = config.get('server_port', 8388) logging.getLogger('').handlers = [] diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index 7fa4f35..1a080bb 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -140,6 +140,7 @@ class TCPRelayHandler(object): self._redir_list = config.get('redirect', ["0.0.0.0:0"]) self._bind = config.get('out_bind', '') self._bindv6 = config.get('out_bindv6', '') + self._ignore_bind_list = config.get('ignore_bind', []) self._fastopen_connected = False self._data_to_write_to_local = [] @@ -528,10 +529,13 @@ class TCPRelayHandler(object): bind_addr = self._local_sock.getsockname()[0] bind_addr = bind_addr.replace("::ffff:", "") - local_addrs = socket.getaddrinfo(bind_addr, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) - if local_addrs[0][0] == af: - logging.debug("bind %s" % (bind_addr,)) - remote_sock.bind((bind_addr, 0)) + if bind_addr in self._ignore_bind_list: + bind_addr = None + if bind_addr: + local_addrs = socket.getaddrinfo(bind_addr, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) + if local_addrs[0][0] == af: + logging.debug("bind %s" % (bind_addr,)) + remote_sock.bind((bind_addr, 0)) return remote_sock def _handle_dns_resolved(self, result, error):