Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsdist: Handle response dnstap messages arriving before the query ones #15156

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions regression-tests.dnsdist/test_Dnstap.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,23 @@ def startResponders(cls):
cls._remoteLoggerListener.daemon = True
cls._remoteLoggerListener.start()

def getFirstDnstap(self):
def getFirstDnstap(self, messageType=None):
self.assertFalse(self._remoteLoggerQueue.empty())
data = self._remoteLoggerQueue.get(False)
self.assertTrue(data)
dnstap = dnstap_pb2.Dnstap()
dnstap.ParseFromString(data)
unused = []
dnstap = None
while not self._remoteLoggerQueue.empty():
data = self._remoteLoggerQueue.get(False)
self.assertTrue(data)
dnstap = dnstap_pb2.Dnstap()
dnstap.ParseFromString(data)
if not messageType or dnstap.message.type == messageType:
break
unused.append(data)

# put back non-matching messages for later
for msg in reversed(unused):
self._remoteLoggerQueue.put(msg)

return dnstap

def testDnstap(self):
Expand Down Expand Up @@ -423,13 +434,13 @@ def testDnstap(self):
time.sleep(1)

# check the dnstap message corresponding to the UDP query
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_QUERY)

checkDnstapQuery(self, dnstap, dnstap_pb2.UDP, query)
checkDnstapNoExtra(self, dnstap)

# check the dnstap message corresponding to the UDP response
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_RESPONSE)
checkDnstapResponse(self, dnstap, dnstap_pb2.UDP, response)
checkDnstapNoExtra(self, dnstap)

Expand All @@ -444,13 +455,13 @@ def testDnstap(self):
time.sleep(1)

# check the dnstap message corresponding to the TCP query
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_QUERY)

checkDnstapQuery(self, dnstap, dnstap_pb2.TCP, query)
checkDnstapNoExtra(self, dnstap)

# check the dnstap message corresponding to the TCP response
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_RESPONSE)
checkDnstapResponse(self, dnstap, dnstap_pb2.TCP, response)
checkDnstapNoExtra(self, dnstap)

Expand Down Expand Up @@ -489,12 +500,12 @@ def testDnstapExtra(self):
time.sleep(1)

# check the dnstap message corresponding to the UDP query
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_QUERY)
checkDnstapQuery(self, dnstap, dnstap_pb2.UDP, query)
checkDnstapExtra(self, dnstap, b"Type,Query")

# check the dnstap message corresponding to the UDP response
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_RESPONSE)
checkDnstapResponse(self, dnstap, dnstap_pb2.UDP, response)
checkDnstapExtra(self, dnstap, b"Type,Response")

Expand All @@ -509,12 +520,12 @@ def testDnstapExtra(self):
time.sleep(1)

# check the dnstap message corresponding to the TCP query
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_QUERY)
checkDnstapQuery(self, dnstap, dnstap_pb2.TCP, query)
checkDnstapExtra(self, dnstap, b"Type,Query")

# check the dnstap message corresponding to the TCP response
dnstap = self.getFirstDnstap()
dnstap = self.getFirstDnstap(dnstap_pb2.Message.CLIENT_RESPONSE)
checkDnstapResponse(self, dnstap, dnstap_pb2.TCP, response)
checkDnstapExtra(self, dnstap, b"Type,Response")

Expand Down