From 706668a52433701541a677ac2d4054574355d3b1 Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Thu, 8 Jun 2023 10:18:37 -0600 Subject: [PATCH 1/3] Add MDNS test --- test_orc/modules/dns/conf/module_config.json | 4 ++++ test_orc/modules/dns/python/src/dns_module.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/test_orc/modules/dns/conf/module_config.json b/test_orc/modules/dns/conf/module_config.json index b8ff36c97..177537b69 100644 --- a/test_orc/modules/dns/conf/module_config.json +++ b/test_orc/modules/dns/conf/module_config.json @@ -21,6 +21,10 @@ "name": "dns.network.from_dhcp", "description": "Verify the device allows for a DNS server to be entered automatically", "expected_behavior": "The device sends DNS requests to the DNS server provided by the DHCP server" + }, + { + "name": "dns.mdns", + "description": "If the device has MDNS (or any kind of IP multicast), can it be disabled" } ] } diff --git a/test_orc/modules/dns/python/src/dns_module.py b/test_orc/modules/dns/python/src/dns_module.py index cd7261da0..ca50e294f 100644 --- a/test_orc/modules/dns/python/src/dns_module.py +++ b/test_orc/modules/dns/python/src/dns_module.py @@ -63,6 +63,18 @@ def _dns_network_from_device(self): LOGGER.info('DNS traffic detected from device: ' + str(result)) return result + def _dns_mdns(self): + LOGGER.info("Running dns.mdns") + + # Check if the device sends any MDNS traffic + tcpdump_filter = f'udp port 5353 and ether src {self._device_mac}' + + result = self._check_dns_traffic(tcpdump_filter=tcpdump_filter) + + LOGGER.info('MDNS traffic detected from device: ' + str(result)) + return not result + + def _exec_tcpdump(self, tcpdump_filter): """ Args From 88ab3ed17de94f9d5b360e7c9bf34acd599eb934 Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Thu, 8 Jun 2023 10:26:51 -0600 Subject: [PATCH 2/3] Update existing mdns logging to be more consistent with other tests --- test_orc/modules/dns/python/src/dns_module.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_orc/modules/dns/python/src/dns_module.py b/test_orc/modules/dns/python/src/dns_module.py index ca50e294f..73f3b64f2 100644 --- a/test_orc/modules/dns/python/src/dns_module.py +++ b/test_orc/modules/dns/python/src/dns_module.py @@ -39,6 +39,7 @@ def _check_dns_traffic(self, tcpdump_filter): return dns_traffic_detected def _dns_network_from_dhcp(self): + LOGGER.info("Running dns.network.from_dhcp") LOGGER.info('Checking DNS traffic for configured DHCP DNS server: ' + self._dns_server) @@ -53,6 +54,7 @@ def _dns_network_from_dhcp(self): return result def _dns_network_from_device(self): + LOGGER.info("Running dns.network.from_device") LOGGER.info('Checking DNS traffic from device: ' + self._device_mac) # Check if the device DNS traffic is to appropriate server From 305b4d9151dacb8e68538f1a5f2abc870c2fd48d Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Thu, 8 Jun 2023 11:23:05 -0600 Subject: [PATCH 3/3] Add startup and monitor captures --- test_orc/modules/dns/python/src/dns_module.py | 23 ++++++++++++++----- test_orc/python/src/test_orchestrator.py | 17 ++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/test_orc/modules/dns/python/src/dns_module.py b/test_orc/modules/dns/python/src/dns_module.py index 73f3b64f2..8d32d4dfb 100644 --- a/test_orc/modules/dns/python/src/dns_module.py +++ b/test_orc/modules/dns/python/src/dns_module.py @@ -17,7 +17,9 @@ from test_module import TestModule LOG_NAME = 'test_dns' -CAPTURE_FILE = '/runtime/network/dns.pcap' +DNS_SERVER_CAPTURE_FILE = '/runtime/network/dns.pcap' +STARTUP_CAPTURE_FILE = '/runtime/device/startup.pcap' +MONITOR_CAPTURE_FILE = '/runtime/device/monitor.pcap' LOGGER = None @@ -31,10 +33,19 @@ def __init__(self, module): LOGGER = self._get_logger() def _check_dns_traffic(self, tcpdump_filter): - to_dns = self._exec_tcpdump(tcpdump_filter) - num_query_dns = len(to_dns) + dns_server_queries = self._exec_tcpdump(tcpdump_filter,DNS_SERVER_CAPTURE_FILE) + LOGGER.info('DNS Server queries found: ' + str(len(dns_server_queries))) + + dns_startup_queries = self._exec_tcpdump(tcpdump_filter,STARTUP_CAPTURE_FILE) + LOGGER.info('Startup DNS queries found: ' + str(len(dns_startup_queries))) + + dns_monitor_queries = self._exec_tcpdump(tcpdump_filter,MONITOR_CAPTURE_FILE) + LOGGER.info('Monitor DNS queries found: ' + str(len(dns_monitor_queries))) + + num_query_dns = len(dns_server_queries) + len(dns_startup_queries) + len(dns_monitor_queries) + LOGGER.info('DNS queries found: ' + str(num_query_dns)) - dns_traffic_detected = len(to_dns) > 0 + dns_traffic_detected = num_query_dns > 0 LOGGER.info('DNS traffic detected: ' + str(dns_traffic_detected)) return dns_traffic_detected @@ -77,7 +88,7 @@ def _dns_mdns(self): return not result - def _exec_tcpdump(self, tcpdump_filter): + def _exec_tcpdump(self, tcpdump_filter, capture_file): """ Args tcpdump_filter: Filter to pass onto tcpdump file @@ -85,7 +96,7 @@ def _exec_tcpdump(self, tcpdump_filter): Returns List of packets matching the filter """ - command = f'tcpdump -tttt -n -r {CAPTURE_FILE} {tcpdump_filter}' + command = f'tcpdump -tttt -n -r {capture_file} {tcpdump_filter}' LOGGER.debug('tcpdump command: ' + command) diff --git a/test_orc/python/src/test_orchestrator.py b/test_orc/python/src/test_orchestrator.py index e122221f5..b8b7a3af2 100644 --- a/test_orc/python/src/test_orchestrator.py +++ b/test_orc/python/src/test_orchestrator.py @@ -133,6 +133,15 @@ def _run_test_module(self, module, device): network_runtime_dir = os.path.join(self._root_path, "runtime/network") os.makedirs(container_runtime_dir) + device_startup_capture = os.path.join( + self._root_path, "runtime/test/" + device.mac_addr.replace(":", "") + + "/startup.pcap") + + device_monitor_capture = os.path.join( + self._root_path, "runtime/test/" + device.mac_addr.replace(":", "") + + "/monitor.pcap") + + client = docker.from_env() module.container = client.containers.run( @@ -151,6 +160,14 @@ def _run_test_module(self, module, device): source=network_runtime_dir, type="bind", read_only=True), + Mount(target="/runtime/device/startup.pcap", + source=device_startup_capture, + type="bind", + read_only=True), + Mount(target="/runtime/device/monitor.pcap", + source=device_monitor_capture, + type="bind", + read_only=True), ], environment={ "HOST_USER": self._get_host_user(),