Commit 5d06b04d authored by Petr Špaček's avatar Petr Špaček

Deckard: use SOCKET_WRAPPER_PCAP_FILE facilities

Custom implementation of packet logging was replaced by
SOCKET_WRAPPER_PCAP_FILE facilities. The main advantage is that it logs
all the traffic including malformed packets, ICMP messages and so on.

As side-effect, this commit removes depedency on Python package dpkt.
parent 5539d415
Pipeline #2008 failed with stage
in 46 seconds
......@@ -142,6 +142,8 @@ When cwrap environment is absent, default values will be used :
fails, the work directory can contain useful information for post-mortem analysis. You can explicitly
set ``SOCKET_WRAPPER_DIR`` to a custom path for more convenient analysis.
If ``SOCKET_WRAPPER_PCAP_FILE`` contains a path to a writeable file, all the network traffic will be appended to specified file.
Acknowledgments
---------------
......
......@@ -102,6 +102,9 @@ def setup_env(scenario, child_env, config, config_name_list, j2template_list):
# Set up child process env()
child_env["SOCKET_WRAPPER_DEFAULT_IFACE"] = "%i" % CHILD_IFACE
child_env["SOCKET_WRAPPER_DIR"] = TMPDIR
# do not pass SOCKET_WRAPPER_PCAP_FILE into child to avoid duplicate packets in pcap
if "SOCKET_WRAPPER_PCAP_FILE" in child_env:
del child_env["SOCKET_WRAPPER_PCAP_FILE"]
no_minimize = os.environ.get("NO_MINIMIZE", "true")
trust_anchor_list = []
stub_addr = ""
......
......@@ -11,27 +11,6 @@ from datetime import datetime
from dprint import dprint
from testserver import recvfrom_msg, sendto_msg
# If PCAP is pointed to a file, queries/responses from the test are captured
g_pcap = None
if 'PCAP' in os.environ:
import dpkt
g_pcap = dpkt.pcap.Writer(open(os.environ['PCAP'], 'wb'))
def log_packet(sock, buf, query = True):
""" Fake underlying layers and store packet in a pcap. """
if not g_pcap:
return
src, dst = (sock.getpeername()[0], 53), sock.getsockname()
if query:
src, dst = sock.getsockname(), (sock.getpeername()[0], 53)
# Synthesise IP/UDP/Eth layers
transport = dpkt.udp.UDP(data = buf, dport = dst[1], sport = src[1])
transport.ulen = len(transport)
ip = dpkt.ip.IP(src = socket.inet_pton(sock.family, src[0]),
dst = socket.inet_pton(sock.family, dst[0]), p = dpkt.ip.IP_PROTO_UDP)
ip.data = transport
ip.len = len(ip)
eth = dpkt.ethernet.Ethernet(data = ip)
g_pcap.writepkt(eth.pack())
# Global statistics
g_rtt = 0.0
......@@ -579,7 +558,6 @@ class Step:
sock.connect(destination)
# Send query to client and wait for response
tstart = datetime.now()
log_packet(sock, data_to_wire, query = True)
while True:
try:
sendto_msg(sock, data_to_wire)
......@@ -608,7 +586,6 @@ class Step:
ctx.last_raw_answer = answer
if self.raw_answer is not None:
self.answer = dns.message.from_wire(self.raw_answer, one_rr_per_rrset=True)
log_packet(sock, answer, query=False)
else:
self.answer = None
ctx.last_answer = self.answer
......
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