Skip to content

Commit

Permalink
rename to "dns_ipv6"
Browse files Browse the repository at this point in the history
log wrong UDP header package
  • Loading branch information
breakwa11 committed Oct 29, 2015
1 parent c0d1d66 commit d9dc3ae
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"method": "aes-256-cfb",
"obfs": "http_simple_compatible",
"obfs_param": "",
"ipv6": false,
"dns_ipv6": false,
"fast_open": false,
"workers": 1
}
2 changes: 1 addition & 1 deletion shadowsocks/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 26 additions & 6 deletions shadowsocks/udprelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ def _handle_dns_resolved(self, result, error):
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,
Expand Down Expand Up @@ -830,7 +832,10 @@ def destroy(self):
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():
Expand All @@ -845,7 +850,11 @@ def destroy_local(self):
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):
Expand Down Expand Up @@ -964,9 +973,14 @@ def _pack_rsp_data(self, cmd, request_id, data):
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:
Expand Down Expand Up @@ -1057,8 +1071,14 @@ def _handle_server(self):
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

Expand Down

0 comments on commit d9dc3ae

Please sign in to comment.