Browse Source

add ignore_bind list

dev
BreakWa11 9 years ago
parent
commit
be922ba7c2
  1. 6
      shadowsocks/shell.py
  2. 12
      shadowsocks/tcprelay.py

6
shadowsocks/shell.py

@ -261,6 +261,12 @@ def get_config(is_local):
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
sys.exit(2) 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) config['server_port'] = config.get('server_port', 8388)
logging.getLogger('').handlers = [] logging.getLogger('').handlers = []

12
shadowsocks/tcprelay.py

@ -140,6 +140,7 @@ class TCPRelayHandler(object):
self._redir_list = config.get('redirect', ["0.0.0.0:0"]) self._redir_list = config.get('redirect', ["0.0.0.0:0"])
self._bind = config.get('out_bind', '') self._bind = config.get('out_bind', '')
self._bindv6 = config.get('out_bindv6', '') self._bindv6 = config.get('out_bindv6', '')
self._ignore_bind_list = config.get('ignore_bind', [])
self._fastopen_connected = False self._fastopen_connected = False
self._data_to_write_to_local = [] self._data_to_write_to_local = []
@ -528,10 +529,13 @@ class TCPRelayHandler(object):
bind_addr = self._local_sock.getsockname()[0] bind_addr = self._local_sock.getsockname()[0]
bind_addr = bind_addr.replace("::ffff:", "") bind_addr = bind_addr.replace("::ffff:", "")
local_addrs = socket.getaddrinfo(bind_addr, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) if bind_addr in self._ignore_bind_list:
if local_addrs[0][0] == af: bind_addr = None
logging.debug("bind %s" % (bind_addr,)) if bind_addr:
remote_sock.bind((bind_addr, 0)) 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 return remote_sock
def _handle_dns_resolved(self, result, error): def _handle_dns_resolved(self, result, error):

Loading…
Cancel
Save