Skip to content

Instantly share code, notes, and snippets.

@jlongman
Last active August 29, 2015 14:20
Show Gist options
  • Save jlongman/44a1e92498e7c8974893 to your computer and use it in GitHub Desktop.
Save jlongman/44a1e92498e7c8974893 to your computer and use it in GitHub Desktop.
A Linux gulp box
DEV1=eth4
DEV2=eth5
###########################################################################
# install gulp
###########################################################################
apt-get install libpcap-dev
wget http://staff.washington.edu/corey/gulp/gulp.tgz
mkdir -p gulp
cd gulp && tar xvfz ../gulp.tgz
make
###########################################################################
# install bridging
###########################################################################
sudo apt-get install bridge-utils
cat << EOF >> /etc/network/interfaces
# Bridge between $DEV1 and $DEV2
auto br0
iface br0 inet dhcp
# For static configuration delete or comment out the above line and uncomment the following:
# iface br0 inet static
# address 192.168.1.10
# netmask 255.255.255.0
# network 192.168.1.0
# gateway 192.168.1.1
# dns-nameservers 192.168.1.5
# dns-search example.com
pre-up ip link set $DEV1 down
pre-up ip link set $DEV2 down
pre-up brctl addbr br0
pre-up brctl addif br0 $DEV1 $DEV2
pre-up ip addr flush dev $DEV1
pre-up ip addr flush dev $DEV2
post-down ip link set $DEV1 down
post-down ip link set $DEV2 down
post-down ip link set br0 down
post-down brctl delif br0 $DEV1 $DEV2
post-down brctl delbr bra
EOF
# reboot. Test by putting traffic between eth4 eth5 and tcpdump'ing br0.
###########################################################################
# start gulp on restart
###########################################################################
cat << EOF > /etc/init/gulp.conf
##############################################################################
# XipLink Gulp Appliance
##############################################################################
description "Xiplink Gulp Appliance"
# -i br0 = capture interface
# -V xxxxxxxxxx = ps status line
# -W 55 = wrap at 55 files
# -o /home/test = output dir to write cap files to
# double check gulp dir and record dir
exec /home/xiplink/gulp/gulp -i br0 -V xxxxxxxxxx -W 55 -o /home/test
respawn
respawn limit 3 12
start on runlevel [345]
start on runlevel [012]
pre-start script
# prepare environment - ensure matches -o from gulp exec line
mkdir -p /home/test
end script
EOF
# reboot - takes a bit to start up, may need some refinement with respect to "start on" conditions.
###########################################################################
# monitor script
###########################################################################
cat << EOF > monitor.sh
#!/usr/bin/env python
import subprocess
# ifstat rates are in kB/s
thresholdRate = 100.0
refreshInterval = 1
if "stop" in subprocess.check_output(["/sbin/status", "gulp"]):
print "failed to find gulp"
exit(-12)
process = subprocess.Popen(["/usr/bin/ifstat","-n", "-i","br0", refreshInterval], bufsize = 1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#(stdout, stderr) = process.communicate()
stdout = process.stdout.readline()
if not 'br0' in stdout:
print "Interface br0 not found in ifstat - " + stdout
exit(-2)
if not "KB/s in" in process.stdout.readline():
print "Unexpected format from ifstat"
exit(-2)
baselineFound = False
while not baselineFound:
inrate = process.stdout.readline().split()[0]
print str(inrate) + " checking low"
baselineFound = float(inrate) > thresholdRate
baselineLost = False
while not baselineLost:
try:
inrate = process.stdout.readline().split()[0]
print str(inrate) + " checking high"
baselineLost = float(inrate) < thresholdRate
except:
print "error in input - %s - stopping gulp" % inrate
baselineLost = True
print("br0 rate dropped below %d, killing gulp." % thresholdRate)
process.terminate()
if subprocess.call(["/sbin/stop", "gulp"]) != 0:
print "failed to kill gulp"
EOF
###########################################################################
# misc
###########################################################################
# added ifstat to watch traffic levels go through, used in monitor.sh above
# disabled avahi, cups, lightdm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment