rc.ipod 2.58 KB
Newer Older
1
2
3
#/bin/sh -
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# All rights reserved.
#

#
# 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.
#

if [ -r /etc/emulab/paths.sh ]; then
	. /etc/emulab/paths.sh
else
Mike Hibler's avatar
Mike Hibler committed
19
	BINDIR=/etc/testbed
20
21
fi

22
#
23
# Grotesque sed/awk converts IP addrs into an integer for sysctl
24
25
26
27
# XXX update: only semi-grotesque now, we convert to hex strings since
# BSD sysctl takes hex numbers (and one-true-awk botches integers close
# to MAXINT)!
#
28
29
30
31
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/' | \
32
		awk '{ printf "0x%02x%02x%02x%02x\n", $1, $2, $3, $4 }'`
33
34
	IPODMASK=`echo $IPODINFO | \
		sed -e 's/.*MASK=\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \
35
		awk '{ printf "0x%02x%02x%02x%02x\n", $1, $2, $3, $4 }'`
36
	IPODKEY=`echo $IPODINFO | \
37
38
		sed -e 's/.*HASH=\(.*\)/\1/'`

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	# figure out the version
	version=`sysctl net.inet.icmp.ipod.version 2>/dev/null`
	if [ "$version"x = x ]; then
		sysctl net.inet.icmp.ipod.enabled >/dev/null 2>&1
		case $? in
		0)
			# XXX ick we sorta had a version 1.5 in BSD
			sysctl net.inet.icmp.ipod.hash >/dev/null 2>&1
			case $? in
			0)
				version=1.5
				;;
			*)
				version=1
				;;
			esac
			;;
		*)
			version=0
			;;
		esac
	fi

	# enable if possible
	case $version in
64
	0)
65
		echo "*** WARNING: no IPOD sysctls, not enabled"
66
		str=""
67
68
69
70
71
72
73
		;;
	1)
		sysctl -w net.inet.icmp.ipod_host=$IPODHOST >/dev/null
		sysctl -w net.inet.icmp.ipod_enabled=1 >/dev/null
		str="Old-style"
		;;
	1.5)
74
75
		sysctl -w net.inet.icmp.ipod.host=$IPODHOST >/dev/null
		sysctl -w net.inet.icmp.ipod.mask=$IPODMASK >/dev/null
76
		sysctl -w net.inet.icmp.ipod.hash=$IPODKEY >/dev/null
77
78
79
80
		sysctl -w net.inet.icmp.ipod.enabled=1 >/dev/null
		str="Authenticated"
		;;
	*)
81
82
83
84
85
86
		sysctl -w net.inet.icmp.ipod.host=$IPODHOST >/dev/null
		sysctl -w net.inet.icmp.ipod.mask=$IPODMASK >/dev/null
		sysctl -w net.inet.icmp.ipod.key=$IPODKEY >/dev/null
		sysctl -w net.inet.icmp.ipod.enabled=1 >/dev/null
		str="Authenticated"
		;;
87
	esac
88
89
90
91
92
93
94
	if [ "$str"x != x ]; then
		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"
	fi
95
96
97
98
else
	echo "*** WARNING: no IPOD info, not enabled"
fi