From f8971980184acdac6243e806e635b420ccef1d3f Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 21 Sep 2022 21:41:31 -0400 Subject: [PATCH] djbdns/*.py: don't clobber id() and type() built-ins. --- djbdns/common.py | 2 +- djbdns/dnscache.py | 6 +++--- djbdns/tinydns.py | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/djbdns/common.py b/djbdns/common.py index 1381011..06124bf 100644 --- a/djbdns/common.py +++ b/djbdns/common.py @@ -12,7 +12,7 @@ timestamp_pat = r'[\d-]+ [\d:\.]+' # # Note that mapping here is non-exhaustive, and that tinydns will # log responses for record types that it does not know about. -query_type = { +query_type_name = { 1: "a", 2: "ns", 5: "cname", diff --git a/djbdns/dnscache.py b/djbdns/dnscache.py index 0d9de08..7fed987 100644 --- a/djbdns/dnscache.py +++ b/djbdns/dnscache.py @@ -59,8 +59,8 @@ def decode_client(words : list, i : int): if len(chunks) == 3: # For a "query" entry's clientip:clientport:id field. - id = int(chunks[2], 16) - words[i] += f" (id {id})" + packet_id = int(chunks[2], 16) + words[i] += f" (id {packet_id})" def decode_ip(words : list, i : int): r""" @@ -207,7 +207,7 @@ def decode_type(words : list, i : int): """ qt = words[i] - words[i] = query_type.get(int(qt), qt) + words[i] = query_type_name.get(int(qt), qt) def handle_dnscache_log(line : str) -> Optional[str]: r""" diff --git a/djbdns/tinydns.py b/djbdns/tinydns.py index 34cedef..d647156 100644 --- a/djbdns/tinydns.py +++ b/djbdns/tinydns.py @@ -65,33 +65,34 @@ def handle_tinydns_log(line : str) -> Optional[str]: if not match: return None - (timestamp, ip, port, id, code, type, name) = match.groups() + (timestamp, ip, port, request_id, code, query_type, name) = match.groups() ip = convert_ip(ip) port = int(port, 16) - id = int(id, 16) + request_id = int(request_id, 16) # Convert the "type" field to a human-readable record type name # using the query_type dictionary. If the right name isn't present # in the dictionary, we use the (decimal) type id instead. - type = int(type, 16) # "001c" -> 28 - type = query_type.get(type, type) # 28 -> "aaaa" + query_type = int(query_type, 16) # "001c" -> 28 + query_type = query_type_name.get(query_type, type) # 28 -> "aaaa" line_tpl = "{timestamp} " reason = query_drop_reason[code] if code == "+": - line_tpl += "sent response to {ip}:{port} (id {id}): {type} {name}" + line_tpl += "sent response to {ip}:{port} (id {request_id}): " + line_tpl += "{query_type} {name}" else: line_tpl += "dropped query ({reason}) from {ip}:{port}" if code != "/": # If the query can actually be parsed, the log line is a # bit more informative than it would have been otherwise. - line_tpl += " (id {id}): {type} {name}" + line_tpl += " (id {request_id}): {query_type} {name}" return line_tpl.format(timestamp=timestamp, reason=reason, ip=ip, port=port, - id=id, - type=type, + request_id=request_id, + query_type=query_type, name=name) -- 2.44.2