#! /bin/bash

# The VMXNET3 driver says it provides TCP segmentation offload on behalf of the
# virtual machine, but it lies - probably when a machine gets migrated from here
# to there. 

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin

[ -f /usr/sbin/tcpdump ] || yum -y install tcpdump

ip link | grep -o '\<eth.\>' | while read IFACE ; do

  if [ $( ( tcpdump -i $IFACE greater 2000 -pn 2>/dev/null & TCPDUMP=$! ; sleep 5 ; kill $TCPDUMP ; ) | wc -l ) -lt 5 ] ; then
    continue
  fi
  # TOE_OPTIONS="rx tx sg tso ufo gso gro lro rxvlan txvlan rxhash"
  TOE_OPTIONS="tso"
  echo "# Oversized packet on interface $IFACE, turning off $TOE_OPTIONS"
  for TOE_OPTION in $TOE_OPTIONS; do
    echo /sbin/ethtool --offload "$IFACE" "$TOE_OPTION" off 
    /sbin/ethtool --offload "$IFACE" "$TOE_OPTION" off 
  done
done

true
