From d9dc3ae0b5ccbfb874f56c9f32cbc1780c8cc215 Mon Sep 17 00:00:00 2001 From: BreakWa11 Date: Thu, 29 Oct 2015 23:38:23 +0800 Subject: [PATCH] rename to "dns_ipv6" log wrong UDP header package --- config.json | 2 +- shadowsocks/local.py | 2 +- shadowsocks/server.py | 2 +- shadowsocks/udprelay.py | 32 ++++++++++++++++++++++++++------ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/config.json b/config.json index 7ca77c3..2fbf33e 100644 --- a/config.json +++ b/config.json @@ -9,7 +9,7 @@ "method": "aes-256-cfb", "obfs": "http_simple_compatible", "obfs_param": "", - "ipv6": false, + "dns_ipv6": false, "fast_open": false, "workers": 1 } diff --git a/shadowsocks/local.py b/shadowsocks/local.py index 819e442..096283c 100755 --- a/shadowsocks/local.py +++ b/shadowsocks/local.py @@ -43,7 +43,7 @@ def main(): config = shell.get_config(True) - if not config.get('ipv6', False): + if not config.get('dns_ipv6', False): asyncdns.IPV6_CONNECTION_SUPPORT = False daemon.daemon_exec(config) diff --git a/shadowsocks/server.py b/shadowsocks/server.py index 40615d3..235a3f2 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -54,7 +54,7 @@ def main(): else: config['port_password'][str(server_port)] = config['password'] - if not config.get('ipv6', False): + if not config.get('dns_ipv6', False): asyncdns.IPV6_CONNECTION_SUPPORT = False if config.get('manager_address', 0): diff --git a/shadowsocks/udprelay.py b/shadowsocks/udprelay.py index 12676f7..5519466 100644 --- a/shadowsocks/udprelay.py +++ b/shadowsocks/udprelay.py @@ -465,9 +465,11 @@ class TCPRelayHandler(object): try: remote_sock.connect((remote_addr, remote_port)) except (OSError, IOError) as e: - if eventloop.errno_from_exception(e) == \ - errno.EINPROGRESS: - pass + if eventloop.errno_from_exception(e) in (errno.EINPROGRESS, + errno.EWOULDBLOCK): + pass # always goto here + else: + raise e self._loop.add(remote_sock, eventloop.POLL_ERR | eventloop.POLL_OUT, @@ -830,7 +832,10 @@ class TCPRelayHandler(object): if self._remote_sock: logging.debug('destroying remote') self._loop.remove(self._remote_sock) - del self._fd_to_handlers[self._remote_sock.fileno()] + try: + del self._fd_to_handlers[self._remote_sock.fileno()] + except Exception as e: + pass self._remote_sock.close() self._remote_sock = None if self._sendingqueue.empty(): @@ -845,7 +850,11 @@ class TCPRelayHandler(object): addr = self.get_local_address() self._write_to_sock(rsp_data, self._local_sock, addr) self._local_sock = None - del self._reqid_to_handlers[self._request_id] + try: + del self._reqid_to_handlers[self._request_id] + except Exception as e: + pass + self._server.remove_handler(self) def client_key(source_addr, server_af): @@ -964,9 +973,14 @@ class UDPRelay(object): reqid_str = struct.pack(">H", request_id) return b''.join([CMD_VER_STR, common.chr(cmd), reqid_str, data, _rand_data[:random.randint(0, len(_rand_data))], reqid_str]) + def _handel_protocol_error(self, client_address, ogn_data): + #raise Exception('can not parse header') + logging.warn("Protocol ERROR, UDP ogn data %s from %s:%d" % (binascii.hexlify(ogn_data), client_address[0], client_address[1])) + def _handle_server(self): server = self._server_socket data, r_addr = server.recvfrom(BUF_SIZE) + ogn_data = data if not data: logging.debug('UDP handle_server: data is empty') if self._stat_callback: @@ -1057,8 +1071,14 @@ class UDPRelay(object): logging.error(trace) return - header_result = parse_header(data) + try: + header_result = parse_header(data) + except: + self._handel_protocol_error(r_addr, ogn_data) + return + if header_result is None: + self._handel_protocol_error(r_addr, ogn_data) return connecttype, dest_addr, dest_port, header_length = header_result