- fix attributes
[pingofdeath.git] / pl-podcntl
1 #/bin/sh -
2 #
3 # Enable ICMP ping-of-death.  Runs on the target node and sets the
4 # passed parameters into the kernel.
5 # Invocation: pl-podcntl HOSTIP HOSTMASK HASH
6
7 # -----------------------------------------------------------------
8 # $Header: /shareddata/CVS/planetlab/admin/ipod/pl-podcntl,v 1.2 2003/01/18 01:43:48 radams Exp $
9 #
10 # Copyright (c) 2003 Intel Corporation
11 # All rights reserved.
12 # This file is distributed under the terms in the attached INTEL_LICENSE
13 # file.  If you do not find this file, a copy can be obtained by
14 # writing to Intel Research Berkeley; Attention: Intel License Inquiry;
15 # 2150 Shattuck Avenue; Berkeley, CA 94704
16 # -----------------------------------------------------------------
17
18 # Modified from origional EMULAB script.  Origional copyright:
19 # EMULAB-COPYRIGHT
20 # Copyright (c) 2000-2002 University of Utah and the Flux Group.
21 # All rights reserved.
22 #
23 # Enable ICMP ping-of-death
24 # Support both the old style (host only) and the new style (host+mask+key)
25 #
26
27 IPODHOSTP=$1
28 IPODMASKP=$2
29 IPODHASHP=$3
30
31 SYSCTL="/sbin/sysctl"
32
33 # Grotesque sed/awk converts IP addrs into an integer for sysctl
34 if [ x"$IPODHOSTP" != x ]; then
35         IPODHOST=`echo $IPODHOSTP | \
36                 sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \
37                 awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'`
38         IPODMASK=`echo $IPODMASKP | \
39                 sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \
40                 awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'`
41         IPODKEY=`echo $IPODHASHP | \
42                 sed -e 's/\(.*\)/\1/'`
43
44         echo "IPODHOST = $IPODHOST"
45         echo "IPODMASK = $IPODMASK"
46         echo "IPODKEY = $IPODKEY"
47
48         # figure out the version
49         version=`$SYSCTL net.ipv4.icmp_ipod_version 2>/dev/null`
50         if [ "$version"x = x ]; then
51                 $SYSCTL net.ipv4.icmp_ipod_enabled >/dev/null 2>&1
52                 case $? in
53                 0)
54                         version=1
55                         ;;
56                 *)
57                         version=0
58                         ;;
59                 esac
60         fi
61
62         echo "Version = $version"
63         # enable if possible
64         case $version in
65         0)
66                 echo "*** WARNING: no IPOD sysctls, not enabled"
67                 exit 1
68                 ;;
69         1)
70                 $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null
71                 $SYSCTL -w net.ipv4.icmp_ipod_enabled=1 >/dev/null
72                 str="Old-style"
73                 ;;
74         *)
75                 $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null
76                 Success=$?
77                 $SYSCTL -w net.ipv4.icmp_ipod_mask=$IPODMASK >/dev/null
78                 $SYSCTL -w net.ipv4.icmp_ipod_key=$IPODKEY >/dev/null
79                 $SYSCTL -w net.ipv4.icmp_ipod_enabled=1 >/dev/null
80                 str="Authenticated"
81                 ;;
82         esac
83         echo Success = $Success
84         if [[ $Success -eq 0 ]] ; then
85                 IPODHOST=`echo $IPODINFO | \
86             sed -e 's/.*HOST=\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/'`
87                 IPODMASK=`echo $IPODINFO | \
88             sed -e 's/.*MASK=\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/'`
89         echo "$str IPOD enabled from $IPODHOST/$IPODMASK"
90     else
91         echo "*** WARNING: could not set IPOD info, not enabled"
92     fi
93 else
94         echo "*** WARNING: no IPOD info, not enabled"
95 fi
96