Skip to content

Commit

Permalink
fix(tcpdump): use interface-specific name for pcap files
Browse files Browse the repository at this point in the history
This adds interface-specific pcap output file names to the tcpdump
component to allow for multiple concurrent captures on the same VM but
different interfaces.

fixes sandialabs#35
  • Loading branch information
nblair2 authored and activeshadow committed Jul 2, 2024
1 parent 07eb5f5 commit 8056c29
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/python/phenix_apps/apps/scorch/tcpdump/tcpdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def start(self):

mm.cc_filter(f'name={hostname}')
mm.cc_exec(f'ip link set {iface} up')
mm.cc_background(f'tcpdump {options} -i {iface} -U -w /dump.pcap {filter}')
mm.cc_background(f'tcpdump {options} -i {iface} -U -w /dump-{iface}.pcap {filter}')

logger.log('INFO', f'Started user component: {self.name}')

Expand All @@ -65,20 +65,25 @@ def stop(self):

for vm in vms:
hostname = vm.get('hostname', None)
iface = vm.get('iface', None)

if not hostname:
self.eprint('no hostname provided for VM config')
sys.exit(1)

pcap_out = f'{self.base_dir}/{hostname}.pcap'
json_out = f'{self.base_dir}/{hostname}.pcap.jsonl'
if not iface:
self.eprint('no interface name provided for VM config')
sys.exit(1)

pcap_out = f'{self.base_dir}/{hostname}-{iface}.pcap'
json_out = f'{self.base_dir}/{hostname}-{iface}.pcap.jsonl'

utils.mm_exec_wait(mm, hostname, 'pkill tcpdump')

self.print(f'copying PCAP file from node {hostname}...')

utils.mm_recv(mm, hostname, '/dump.pcap', pcap_out)
mm.cc_exec('rm /dump.pcap')
utils.mm_recv(mm, hostname, f'/dump-{iface}.pcap', pcap_out)
mm.cc_exec(f'rm /dump-{iface}.pcap')

self.print(f'done copying PCAP file from node {hostname}')

Expand Down

0 comments on commit 8056c29

Please sign in to comment.