Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mxtools/mxsnoop/mxsnoop.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
117 lines (84 sloc)
2.79 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# +--------------+ (!) +----------------------+ +---**** | |
# | | | br01 | | | |
# | THE SUSPECT O]===X===[O SCHNUEFFELSTUECK O]======[O WIS-NET | |
# | | |INLET OUTLET| | | |
# +--------------+ +----------------------+ +---**** | |
# (MX_NETDEV) | |
# Basics: https://wiki.archlinux.org/title/Network_bridge | |
# GATEWAY=10.0.3.1 | |
# BROADCAST=10.0.3.255 | |
# NETMASK=255.255.255.0 | |
# NIDL=24 | |
GATEWAY=141.14.16.128 | |
BROADCAST=141.14.31.255 | |
NETMASK=255.255.240.0 | |
NIDL=20 | |
INLET=${INLET:-} | |
OUTLET=${OUTLET:-} | |
BRIDGE=br01 | |
TRANSPARENT=${TRANSPARENT:-} | |
STP=${STP:-} | |
function die() { echo "$1"; exit 1; } | |
type ip > /dev/null || \ | |
die 'Error: Tools not available, check for ip command.' | |
MXHOSTCONF=${MXHOSTCONF:-/etc/local/mxhost.conf} | |
source $MXHOSTCONF || die "# Error: No 'mxhost.conf' ?" | |
test -n "$MX_IPADDR" || die '# Error: MX_IPADDR missing.' | |
if [ -z "$OUTLET" ]; then | |
test -n "$MX_NETDEV" || die '# Error: MX_NETDEV missing?' | |
test -e /sys/class/net/$MX_NETDEV || die "# Error: $MX_NETDEV missing." | |
OUTLET=$MX_NETDEV | |
fi | |
# inlet was present at boot time -> netXY, or plugged later -> Search for ethX | |
if [ -z "$INLET" ]; then # find the (sole) inlet | |
for D in net{00..09} eth{0..9}; do | |
test -e /sys/class/net/$D || continue | |
test $D = $OUTLET && continue | |
test -n "$INLET" && \ | |
die 'Error: Too many network devices (netXY) present, use INLET=dev (OUTLET=dev ?).' | |
INLET=$D | |
done | |
fi | |
test -z "$INLET" && die '# Error: no second network device found.' | |
echo "# Note: about to setup/destroy $BRIDGE between $INLET (INLET) and $OUTLET (OUTLET), IP: $MX_IPADDR" | |
cmd="$1" | |
case "$cmd" in | |
start) | |
if [ -z "$STP" ]; then | |
ip link add dev $BRIDGE type bridge | |
else | |
ip link add dev $BRIDGE type bridge stp_state 1 | |
fi | |
ip address flush dev $INLET | |
ip address flush dev $OUTLET | |
ip link set $INLET master $BRIDGE | |
ip link set $OUTLET master $BRIDGE | |
if [ -z "$TRANSPARENT" ] ; then | |
ip addr add $MX_IPADDR/$NIDL broadcast $BROADCAST dev $BRIDGE | |
ip link set up dev $BRIDGE | |
ip route add default via $GATEWAY dev $BRIDGE | |
fi | |
ip link set dev $INLET up | |
ip link set dev $OUTLET up | |
;; | |
stop) | |
ip link set $INLET nomaster | |
ip link set $OUTLET nomaster | |
ip link delete $BRIDGE type bridge | |
ip addr add $MX_IPADDR/$NIDL broadcast $BROADCAST dev $OUTLET | |
ip link set dev $OUTLET up | |
ip route add default via $GATEWAY | |
;; | |
restart) | |
$0 stop | |
sleep 1 | |
$0 start | |
;; | |
*) | |
echo "# usage: [INLET=dev] [OUTLET=dev] $0 [start|stop|restart]" | |
echo "# options: TRANSPARENT=1 doesn't bind IP on the bridge" | |
echo "# STP=1 enables Spanning Tree" | |
;; | |
esac | |