blob: 16e8269d02768b4c67b3d3aea5fce5f903a1ba33 [file] [log] [blame]
Ian Wienand2bbc9bb2019-02-11 12:25:38 +11001#!/bin/bash
2#
3# lib/tcpdump
4# Functions to start and stop a tcpdump
5
6# Dependencies:
7#
8# - ``functions`` file
9
10# ``stack.sh`` calls the entry points in this order:
11#
12# - start_tcpdump
13# - stop_tcpdump
14
15# Save trace setting
16_XTRACE_TCPDUMP=$(set +o | grep xtrace)
17set +o xtrace
18
19TCPDUMP_OUTPUT=${TCPDUMP_OUTPUT:-$LOGDIR/tcpdump.pcap}
20
21# e.g. for iscsi
22# "-i any tcp port 3260"
23TCPDUMP_ARGS=${TCPDUMP_ARGS:-""}
24
25# start_tcpdump() - Start running processes
26function start_tcpdump {
27 # Run a tcpdump with given arguments and save the packet capture
28 if is_service_enabled tcpdump; then
29 if [[ -z "${TCPDUMP_ARGS}" ]]; then
30 die $LINENO "The tcpdump service requires TCPDUMP_ARGS to be set"
31 fi
32 touch ${TCPDUMP_OUTPUT}
33 run_process tcpdump "/usr/sbin/tcpdump -w $TCPDUMP_OUTPUT $TCPDUMP_ARGS" root root
34 fi
35}
36
37# stop_tcpdump() stop tcpdump process
38function stop_tcpdump {
39 stop_process tcpdump
40}
41
42# Restore xtrace
43$_XTRACE_TCPDUMP