rc.ipod 1.91 KB
Newer Older
1 2 3 4 5 6 7
#/bin/sh -
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#

8 9
. /etc/emulab/paths.sh

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#
# Enable ICMP ping-of-death
# Support both the old style (host only) and the new style (host+mask+key)
#
# This is a shell script instead of a perl script since we want to use this
# in the frisbee MFS which does not include perl.
#

# Grotesque sed/awk converts IP addrs into an integer for sysctl
IPODINFO=`$BINDIR/tmcc ipodinfo`
if [ x"$IPODINFO" != x ]; then
	IPODHOST=`echo $IPODINFO | \
		sed -e 's/.*HOST=\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \
		awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'`
	IPODMASK=`echo $IPODINFO | \
		sed -e 's/.*MASK=\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \
		awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'`
27
	IPODKEY=`echo $IPODINFO | \
28 29
		sed -e 's/.*HASH=\(.*\)/\1/'`

30 31 32
	# figure out the version
	version=`sysctl net.ipv4.icmp_ipod_version 2>/dev/null`
	if [ "$version"x = x ]; then
33 34 35
		sysctl net.ipv4.icmp_ipod_enabled >/dev/null 2>&1
		case $? in
		0)
36
			version=1
37 38
			;;
		*)
39 40
			version=0
			;;
41
		esac
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
	fi

	# enable if possible
	case $version in
	0)
		echo "*** WARNING: no IPOD sysctls, not enabled"
		exit 1
		;;
	1)
		sysctl -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null
		sysctl -w net.ipv4.icmp_ipod_enabled=1 >/dev/null
		str="Old-style"
		;;
	*)
		sysctl -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null
		sysctl -w net.ipv4.icmp_ipod_mask=$IPODMASK >/dev/null
		sysctl -w net.ipv4.icmp_ipod_key=$IPODKEY >/dev/null
		sysctl -w net.ipv4.icmp_ipod_enabled=1 >/dev/null
		str="Authenticated"
		;;
62 63 64 65 66 67 68 69 70 71
	esac
	IPODHOST=`echo $IPODINFO | \
		sed -e 's/.*HOST=\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/'`
	IPODMASK=`echo $IPODINFO | \
		sed -e 's/.*MASK=\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/'`
	echo "$str IPOD enabled from $IPODHOST/$IPODMASK"
else
	echo "*** WARNING: no IPOD info, not enabled"
fi