Commit 915b357d authored by Petr Špaček's avatar Petr Špaček

tcpcomp2pickle: fix evaluation methodology

Some of TCP errors were errorneously clasified as "compatible" but they
in fact cause resolution breakage.

WARNING!
Results obtained by previous version of tcpscanner are invalid and have
to be re-evaluated by executing tcpcomp2pickle and ednsevalzone again.
parent 76de92a8
......@@ -6,7 +6,7 @@ import logging
import pickle
import re
import sys
from typing import Counter, Dict, List, Tuple
from typing import Counter, Dict, FrozenSet, List, Tuple
from ednsevalzone import EDNSResult, AnIPAddress
......@@ -15,7 +15,7 @@ from ednsevalzone import EDNSResult, AnIPAddress
# nic.cz. @193.29.206.1 (d.ns.nic.cz.): tcp=ok do=ok signed=ok,yes ednstcp=ok
# test. @127.0.0.10 (test.): tcp=nosoa,noaa do=nosoa,noaa signed=nosoa,noaa ednstcp=timeout
def parse_nsip_line(line: str) -> Tuple[AnIPAddress, Dict[str, List[str]]]:
def parse_nsip_line(line: str) -> Tuple[AnIPAddress, Dict[str, FrozenSet[str]]]:
"""parse one line from genreport log"""
matches = re.match('^[^ ]*\\. @(?P<ip>[^ ]+) \\([^)]+\\): (?P<results>tcp=.*)$', line)
if not matches:
......@@ -24,7 +24,7 @@ def parse_nsip_line(line: str) -> Tuple[AnIPAddress, Dict[str, List[str]]]:
tests_list = matches.group('results').split()
try:
tests_results = {test.split('=')[0]:
test.split('=')[1].split(',')
frozenset(test.split('=')[1].split(','))
for test in tests_list}
except IndexError:
raise ValueError('skipping nonsense test results "{}"'.format(line))
......@@ -48,16 +48,18 @@ def eval_tcp_permissive(tcp_results: Dict[str, List[str]]) -> EDNSResult:
else:
return EDNSResult.dead
def eval_tcp(tests_results: Dict[str, List[str]], timeout_evaluator) -> EDNSResult:
hard_breakage_types = frozenset(['timeout', 'failed', 'reset', 'connection-refused', 'eof',
'malformed', 'mismatch', 'rcode15', 'servfail', 'refused', 'nxdomain'])
def eval_tcp(tests_results: Dict[str, FrozenSet[str]], timeout_evaluator) -> EDNSResult:
"""
Combine individual tests into overall result for a single IP address.
"""
if all('ok' in results for results in tests_results.values()):
return EDNSResult.ok
# it is not 100% compliant but answers -> it is kind of "compatible" but does not get highest grade
if (all('timeout' not in results for results in tests_results.values())
and all('failed' not in results for results in tests_results.values())
and all('connection-refused' not in results for results in tests_results.values())):
# it is not 100% compliant but answers in a reasonable way
# -> it is kind of "compatible" but does not get highest grade
if (all(hard_breakage_types.intersection(results) == 0
for results in tests_results.values())):
return EDNSResult.compatible
else: # impact of not working TCP is different before and after the flag day
return timeout_evaluator(tests_results)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment