bump release number
[pingofdeath.git] / enable_pod.sh
1 #! /bin/bash
2 #include INTEL_LICENSE.txt
3 #
4 ########################################################################
5 #
6 # Enable Ping Of Death
7 #
8 ########################################################################
9 #
10 # DESCRIPTION
11 #
12 # The Enable_POD function is passed the IP_SUBNET, IP_MASK and HASH and
13 # does all the dirty muching about with syscontrols
14 #
15 # HISTORY
16 #
17 # May 17, 2003    -   Paul Brett <paul.brett@intel.com>
18 #                     Initial version based on the work of 
19 #                     Robert Adams <robert.adams@intel.com> and EMULAB
20 #
21
22 function enable_pod()
23 {
24     local SYSCTL=/sbin/sysctl
25
26     local IP_SUBNET=$1
27     local IP_MASK=$2
28     local IP_HASH=$3
29
30     # Grotesque sed/awk converts IP addrs into an integer for sysctl
31     local IPODHOST=`echo $IP_SUBNET | \
32               sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \
33               awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'`
34     local IPODMASK=`echo $IP_MASK | \
35               sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \
36               awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'`
37     local IPODKEY=`echo $HASH | \
38               sed -e 's/\(.*\)/\1/'`
39
40     # figure out the version
41     local version=`$SYSCTL net.ipv4.icmp_ipod_version 2>/dev/null`
42     if [[ "$version" == "" ]]
43     then
44         $SYSCTL net.ipv4.icmp_ipod_enabled >/dev/null 2>&1
45         case $? in
46             0)
47                 version=1
48                 ;;
49             *)
50                 version=0
51                 ;;
52         esac
53     fi
54
55     # enable if possible
56     case $version in
57         0)
58             return 1
59             ;;
60         1)
61             $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null
62             $SYSCTL -w net.ipv4.icmp_ipod_enabled=1 >/dev/null
63             Success=0
64             ;;
65         *)
66             $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null
67             Success=$?
68             $SYSCTL -w net.ipv4.icmp_ipod_mask=$IPODMASK >/dev/null
69             $SYSCTL -w net.ipv4.icmp_ipod_key=$IPODKEY >/dev/null
70             $SYSCTL -w net.ipv4.icmp_ipod_enabled=1 >/dev/null
71         ;;
72     esac
73     return $Success
74 }
75
76