summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Harbott <j.harbott@x-ion.de>2017-11-23 16:44:02 +0000
committerJens Harbott <j.harbott@x-ion.de>2018-11-28 12:08:18 +0000
commit16297a3014266f1da2c0a87a19027c7eeec577ea (patch)
tree7148b40394caaac79bafad47666c1c55c844f467
parent7c2a3be3e42cc72b6b03c9b6cb67393d423e5e21 (diff)
Fix servicing IPv6 based TCP connectionsstable/pike
When a connection is received via IPv6, the address is a 4-tuple instead of a 2-tuple for IPv4, so handle this accordingly. Also handle the end of the TCP connection gracefully instead of emitting an "Invalid packet" warning every time. [1] https://docs.python.org/2/library/socket.html Change-Id: I935bbea1d58af8a5b41b5d29f12de4dcb7cf6301 Closes-Bug: 1734101 (cherry picked from commit 5e45b15419e80539e35d08380351445553bf92b0)
Notes
Notes (review): Code-Review+2: Erik Olof Gunnar Andersson <eandersson@blizzard.com> Code-Review+2: Graham Hayes <gr@ham.ie> Workflow+1: Graham Hayes <gr@ham.ie> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 04 Dec 2018 17:41:17 +0000 Reviewed-on: https://review.openstack.org/620583 Project: openstack/designate Branch: refs/heads/stable/pike
-rw-r--r--designate/service.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/designate/service.py b/designate/service.py
index 6e20a3c..8f63095 100644
--- a/designate/service.py
+++ b/designate/service.py
@@ -321,6 +321,9 @@ class DNSService(object):
321 321
322 LOG.debug("Handling TCP Request from: %(host)s:%(port)d" % 322 LOG.debug("Handling TCP Request from: %(host)s:%(port)d" %
323 {'host': addr[0], 'port': addr[1]}) 323 {'host': addr[0], 'port': addr[1]})
324 if len(addr) == 4:
325 LOG.debug("Flow info: %(host)s scope: %(port)d" %
326 {'host': addr[2], 'port': addr[3]})
324 327
325 # Dispatch a thread to handle the connection 328 # Dispatch a thread to handle the connection
326 self.tg.add_thread(self._dns_handle_tcp_conn, addr, client) 329 self.tg.add_thread(self._dns_handle_tcp_conn, addr, client)
@@ -349,25 +352,28 @@ class DNSService(object):
349 def _dns_handle_tcp_conn(self, addr, client): 352 def _dns_handle_tcp_conn(self, addr, client):
350 """ 353 """
351 Handle a DNS Query over TCP. Multiple queries can be pipelined 354 Handle a DNS Query over TCP. Multiple queries can be pipelined
352 though the same TCP connection but they will be processed 355 through the same TCP connection but they will be processed
353 sequentially. 356 sequentially.
354 See https://tools.ietf.org/html/draft-ietf-dnsop-5966bis-03 357 See https://tools.ietf.org/html/draft-ietf-dnsop-5966bis-03
355 Raises no exception: it's to be run in an eventlet green thread 358 Raises no exception: it's to be run in an eventlet green thread
356 359
357 :param addr: Tuple of the client's (IP addr, Port) 360 :param addr: Tuple of the client's (IPv4 addr, Port) or
361 (IPv6 addr, Port, Flow info, Scope ID)
358 :type addr: tuple 362 :type addr: tuple
359 :param client: Client socket 363 :param client: Client socket
360 :type client: socket 364 :type client: socket
361 :raises: None 365 :raises: None
362 """ 366 """
363 host, port = addr 367 host, port = addr[:2]
364 try: 368 try:
365 # The whole loop lives in a try/except block. On exceptions, the 369 # The whole loop lives in a try/except block. On exceptions, the
366 # connection is closed: there would be little chance to save save 370 # connection is closed: there would be little chance to save
367 # the connection after a struct error, a socket error. 371 # the connection after a struct error, a socket error.
368 while True: 372 while True:
369 # Decode the first 2 bytes containing the query length 373 # Decode the first 2 bytes containing the query length
370 expected_length_raw = client.recv(2) 374 expected_length_raw = client.recv(2)
375 if len(expected_length_raw) == 0:
376 break
371 (expected_length, ) = struct.unpack('!H', expected_length_raw) 377 (expected_length, ) = struct.unpack('!H', expected_length_raw)
372 378
373 # Keep receiving data until we've got all the data we expect 379 # Keep receiving data until we've got all the data we expect