From 73cc341cf20e98e50bcf2d268aff4bb54fb3f453 Mon Sep 17 00:00:00 2001 From: Aaron Klingaman Date: Fri, 5 Aug 2005 23:05:12 +0000 Subject: [PATCH] - simplify build procses by combining start/enable/status functions into pod script - update to get pod hash from /etc/planetlab/session --- Makefile | 8 +- disable_pod.sh | 28 ------- enable_pod.sh | 76 ----------------- ipod.spec | 11 ++- pod | 216 +++++++++++++++++++++++++++++++++++++++++++++++++ pod.src | 122 ---------------------------- shell_include | 129 ----------------------------- status_pod.sh | 27 ------- 8 files changed, 225 insertions(+), 392 deletions(-) delete mode 100755 disable_pod.sh delete mode 100755 enable_pod.sh create mode 100755 pod delete mode 100755 pod.src delete mode 100755 shell_include delete mode 100755 status_pod.sh diff --git a/Makefile b/Makefile index dbe3395..fc4cf8d 100644 --- a/Makefile +++ b/Makefile @@ -7,16 +7,12 @@ # test: runs the tests on the current machine # -ALLBUILD=pl-poddoit pod +ALLBUILD=pl-poddoit all: $(ALLBUILD) -pod: pod.src disable_pod.sh enable_pod.sh status_pod.sh - ./shell_include --source pod.src --destination pod - pl-poddoit: pl-poddoit.c gcc pl-poddoit.c -o pl-poddoit clean: - rm -f pod pl-poddoit - + rm -f pl-poddoit diff --git a/disable_pod.sh b/disable_pod.sh deleted file mode 100755 index bba89f8..0000000 --- a/disable_pod.sh +++ /dev/null @@ -1,28 +0,0 @@ -#! /bin/bash -#include INTEL_LICENSE.txt -# -######################################################################## -# -# Disable Ping Of Death -# -######################################################################## -# -# DESCRIPTION -# -# The disable_pod function turns off the pod syscntl -# -# HISTORY -# -# May 17, 2003 - Paul Brett -# Initial version based on the work of -# Robert Adams and EMULAB -# - -function disable_pod() -{ - local SYSCTL=/sbin/sysctl - $SYSCTL -w net.ipv4.icmp_ipod_enabled=0 >/dev/null - return 0 -} - - diff --git a/enable_pod.sh b/enable_pod.sh deleted file mode 100755 index e48c91b..0000000 --- a/enable_pod.sh +++ /dev/null @@ -1,76 +0,0 @@ -#! /bin/bash -#include INTEL_LICENSE.txt -# -######################################################################## -# -# Enable Ping Of Death -# -######################################################################## -# -# DESCRIPTION -# -# The Enable_POD function is passed the IP_SUBNET, IP_MASK and HASH and -# does all the dirty muching about with syscontrols -# -# HISTORY -# -# May 17, 2003 - Paul Brett -# Initial version based on the work of -# Robert Adams and EMULAB -# - -function enable_pod() -{ - local SYSCTL=/sbin/sysctl - - local IP_SUBNET=$1 - local IP_MASK=$2 - local IP_HASH=$3 - - # Grotesque sed/awk converts IP addrs into an integer for sysctl - local IPODHOST=`echo $IP_SUBNET | \ - sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \ - awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'` - local IPODMASK=`echo $IP_MASK | \ - sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \ - awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'` - local IPODKEY=`echo $HASH | \ - sed -e 's/\(.*\)/\1/'` - - # figure out the version - local version=`$SYSCTL net.ipv4.icmp_ipod_version 2>/dev/null` - if [[ "$version" == "" ]] - then - $SYSCTL net.ipv4.icmp_ipod_enabled >/dev/null 2>&1 - case $? in - 0) - version=1 - ;; - *) - version=0 - ;; - esac - fi - - # enable if possible - case $version in - 0) - return 1 - ;; - 1) - $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null - $SYSCTL -w net.ipv4.icmp_ipod_enabled=1 >/dev/null - Success=0 - ;; - *) - $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null - Success=$? - $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 - ;; - esac - return $Success -} - - diff --git a/ipod.spec b/ipod.spec index 77cef16..9609456 100644 --- a/ipod.spec +++ b/ipod.spec @@ -1,6 +1,6 @@ %define name ipod -%define version 2.0 -%define release 6.planetlab%{?date:.%{date}} +%define version 2.1 +%define release 1.planetlab%{?date:.%{date}} Vendor: PlanetLab Packager: PlanetLab Central @@ -47,8 +47,6 @@ cp pod $RPM_BUILD_ROOT/etc/init.d/ %pre %post -RUNLEVEL=`/sbin/runlevel` - if [ "$1" = 1 ]; then chkconfig --add pod chkconfig pod on @@ -68,6 +66,11 @@ fi %changelog +* Fri Aug 5 2005 Aaron Klingaman +- updated to use new source of POD Hash (/etc/planetlab/session) +- minor build changes to simply build process +- remove unnecessary call to runlevel in post section + * Mon Apr 12 2004 Aaron Klingaman - moved to new build process - added change log diff --git a/pod b/pod new file mode 100755 index 0000000..a2ee0ee --- /dev/null +++ b/pod @@ -0,0 +1,216 @@ +#! /bin/bash +#include INTEL_LICENSE.txt +# +######################################################################## +# +# PlanetLab Ping Of Death +# +######################################################################## +# +# DESCRIPTION +# +# This shell script takes care of starting and stopping Planetlab +# Ping-Of-Death. +# +# The Planetlab POD is a Linux kernel patch that creates the feature +# of resetting and rebooting a computer when a particularily +# formatted ICMP "ping" commmand is received. +# +# A PlanetLab node's kernel gets a host, mask and hash value through +# sysctl's that are performed on the node. The node then looks +# for an ICMP packet from a host matching the host/mask and, if the +# packet payload is the hash value, the node forces an immediate +# reboot. +# +# HISTORY +# +# May 17, 2003 - Paul Brett +# Initial version based on the work of +# Robert Adams and EMULAB +# +# chkconfig: - 11 99 +# description: enable Ping of Death + +# Source function library. +. /etc/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +function enable_pod() +{ + local SYSCTL=/sbin/sysctl + + local IP_SUBNET=$1 + local IP_MASK=$2 + local HASH=$3 + + # Grotesque sed/awk converts IP addrs into an integer for sysctl + local IPODHOST=`echo $IP_SUBNET | \ + sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \ + awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'` + local IPODMASK=`echo $IP_MASK | \ + sed -e 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/' | \ + awk '{ printf "%d\n", $1*16777216+$2*65536+$3*256+$4 }'` + + # figure out the version + local version=`$SYSCTL net.ipv4.icmp_ipod_version 2>/dev/null` + if [[ "$version" == "" ]] + then + $SYSCTL net.ipv4.icmp_ipod_enabled >/dev/null 2>&1 + case $? in + 0) + version=1 + ;; + *) + version=0 + ;; + esac + fi + + # enable if possible + case $version in + 0) + return 1 + ;; + 1) + $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null + $SYSCTL -w net.ipv4.icmp_ipod_enabled=1 >/dev/null + Success=0 + ;; + *) + $SYSCTL -w net.ipv4.icmp_ipod_host=$IPODHOST >/dev/null + Success=$? + $SYSCTL -w net.ipv4.icmp_ipod_mask=$IPODMASK >/dev/null + $SYSCTL -w net.ipv4.icmp_ipod_key=$HASH >/dev/null + $SYSCTL -w net.ipv4.icmp_ipod_enabled=1 >/dev/null + ;; + esac + return $Success +} + +function disable_pod() +{ + local SYSCTL=/sbin/sysctl + $SYSCTL -w net.ipv4.icmp_ipod_enabled=0 >/dev/null + return 0 +} + +function status_pod() +{ + + local SYSCTL="/sbin/sysctl" + + # Check that IPOD is built into this kernel + local version + version=`$SYSCTL -n net.ipv4.icmp_ipod_version 2> /dev/null` + if [[ $? -ne 0 ]] + then + echo "Not installed" + return 255 + fi + + # Check if it has been enabled + local enabled=`$SYSCTL -n net.ipv4.icmp_ipod_enabled` + echo -n "version $version " + if [[ $enabled -eq 1 ]] + then + echo "Enabled" + else + echo "Disabled" + fi + return $enabled +} + +echo -n "PlanetLab Ping Of Death " + +CONF=/etc/ipod.conf + +if [[ -r $CONF ]] +then + # load the POD configuration file + . $CONF +else + # no POD configuration file - failed + echo + action $"Missing configuration file $CONF" /bin/false + exit 1 +fi + +SESSION=/etc/planetlab/session + +if [[ -r $SESSION ]] +then + # load the session value file + HASH=`cat $SESSION` +else + # no session value (ie, no hash) + echo + action $"Missing node session file $SESSION" /bin/false + exit 1 +fi + +# Check that networking is up. +if [[ ${NETWORKING} = "no" ]] +then + action $"" /bin/false + exit 1 +fi + +# Check the POD parameters +if [[ "$HASH" == "" ]] +then + echo + action $"Missing HASH (from $SESSION)" /bin/false + exit 1 +fi + +if [[ "$IP_SUBNET" == "" ]] +then + echo + action $"Missing IP_SUBNET in $CONF" /bin/false + exit 1 +fi + +if [[ "$IP_MASK" == "" ]] +then + echo + action $"Missing IP_MASK in $CONF" /bin/false + exit 1 +fi + +# See how we were called. +case "$1" in + start) + enable_pod $IP_SUBNET $IP_MASK $HASH + RETVAL=$? + if [[ $RETVAL -eq 0 ]] + then + action $"" /bin/true + else + action $"" /bin/false + fi + ;; + stop) + disable_pod + RETVAL=$? + if [[ $RETVAL -eq 0 ]] + then + action $"" /bin/true + else + action $"" /bin/false + fi + ;; + status) + status_pod + RETVAL=$? + ;; + restart|reload) + disable_pod + enable_pod + RETVAL=$? + ;; + *) + echo $"Usage: $0 {start|stop|restart|status}" + exit 1 +esac diff --git a/pod.src b/pod.src deleted file mode 100755 index 057e8b1..0000000 --- a/pod.src +++ /dev/null @@ -1,122 +0,0 @@ -#! /bin/bash -#include INTEL_LICENSE.txt -# -######################################################################## -# -# PlanetLab Ping Of Death -# -######################################################################## -# -# DESCRIPTION -# -# This shell script takes care of starting and stopping Planetlab -# Ping-Of-Death. -# -# The Planetlab POD is a Linux kernel patch that creates the feature -# of resetting and rebooting a computer when a particularily -# formatted ICMP "ping" commmand is received. -# -# A PlanetLab node's kernel gets a host, mask and hash value through -# sysctl's that are performed on the node. The node then looks -# for an ICMP packet from a host matching the host/mask and, if the -# packet payload is the hash value, the node forces an immediate -# reboot. -# -# HISTORY -# -# May 17, 2003 - Paul Brett -# Initial version based on the work of -# Robert Adams and EMULAB -# -# chkconfig: - 11 99 -# description: enable Ping of Death - -# Source function library. -. /etc/init.d/functions - -# Source networking configuration. -. /etc/sysconfig/network - -#include enable_pod.sh -#include disable_pod.sh -#include status_pod.sh - -echo -n "PlanetLab Ping Of Death " - -CONF=/etc/ipod.conf - -if [[ -r $CONF ]] -then - # load the POD configuration file - . $CONF -else - # no POD configuration file - failed - echo - action $"Missing configuration file $CONF" /bin/false - exit 1 -fi - -# Check that networking is up. -if [[ ${NETWORKING} = "no" ]] -then - action $"" /bin/false - exit 1 -fi - -# Check the POD parameters -if [[ "$HASH" == "" ]] -then - echo - action $"Missing HASH in $CONF" /bin/false - exit 1 -fi - -if [[ "$IP_SUBNET" == "" ]] -then - echo - action $"Missing IP_SUBNET in $CONF" /bin/false - exit 1 -fi - -if [[ "$IP_MASK" == "" ]] -then - echo - action $"Missing IP_MASK in $CONF" /bin/false - exit 1 -fi - -# See how we were called. -case "$1" in - start) - enable_pod $IP_SUBNET $IP_MASK $IP_HASH - RETVAL=$? - if [[ $RETVAL -eq 0 ]] - then - action $"" /bin/true - else - action $"" /bin/false - fi - ;; - stop) - disable_pod - RETVAL=$? - if [[ $RETVAL -eq 0 ]] - then - action $"" /bin/true - else - action $"" /bin/false - fi - ;; - status) - status_pod - RETVAL=$? - ;; - restart|reload) - disable_pod - enable_pod - RETVAL=$? - ;; - *) - echo $"Usage: $0 {start|stop|restart|status}" - exit 1 -esac diff --git a/shell_include b/shell_include deleted file mode 100755 index b404f85..0000000 --- a/shell_include +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/perl - -use strict; -use Getopt::Long; - -my $source = ""; -my $destination = ""; -my $make; -my $help; - -my @lines; -my %included; - -######################################################################## -# -# usage -# - -sub usage() -{ - print "Usage: shell_include --source --destination [--make] [--help]\n"; - print "\n"; - print "--make will output makefile dependencies to stdout and exit\n"; - print "--help will output this text and exit\n"; - print "\n"; -} -######################################################################## -# -# check_options -# - -sub check_options() -{ - if ( !GetOptions( - 's|source=s' => \$source, - 'd|destination=s' => \$destination, - 'm|make' => \$make, - 'h|help' => \$help ) ) - { - &usage; - exit 1; - } - - if ( $help ) { - &usage; - exit 0; - }; - - die( "Missing input file - use --source " ) if ( $source eq "" ); - die( "Missing output file - use --destination ") if ( $destination eq "" ); -} - -######################################################################## -# -# read_input : Read in the initial input file into @lines -# - -sub read_input() -{ - open( SOURCE, $source ) || die ( "Cannot open input file : $source" ); - while ( ) { - @lines = ( @lines, $_ ); - }; - close( SOURCE ); -} - -######################################################################## -# -# Process #include directives -# -sub process_includes() -{ - my $changed = 0; - my @newlines; - - foreach my $line ( @lines ) { - - if ( $line =~ /^(\s*)\#include(\s+)(\S+)/ ) { - $changed = 1; - my $filename = $3; - if ( ! defined $included{ $filename } ) { - open( INC, $filename ) || die ( "Cannot open include file : $filename" ); - @newlines = ( @newlines, "########################################################################\n" ); - @newlines = ( @newlines, "#\n" ); - @newlines = ( @newlines, "# Included file : $filename\n" ); - @newlines = ( @newlines, "#\n" ); - while( ) { - @newlines = ( @newlines, $_ ); - } - close( INC ); - @newlines = ( @newlines, "#\n" ); - @newlines = ( @newlines, "# End of included file : $filename\n" ); - @newlines = ( @newlines, "#\n" ); - @newlines = ( @newlines, "########################################################################\n" ); - $included{ $filename } = ""; - } - } else { - @newlines = ( @newlines, $line ); - } - } - @lines = @newlines; - return $changed; -} - -######################################################################## -# -# write_output : write the final set of lines to the output file -# -sub write_output() -{ - open( DEST, ">$destination" ) || die( "Cannot open output file : $destination" ); - foreach my $line ( @lines ) { - print DEST $line; - } - close( DEST ); -} - -&check_options; -&read_input; -while ( &process_includes ) { }; -if ( $make ) { - print "$destination: $source "; - foreach my $inc ( sort( keys( %included ) ) ) { - print "$inc "; - }; - print "\n"; -} else { - &write_output; -} diff --git a/status_pod.sh b/status_pod.sh deleted file mode 100755 index 2431244..0000000 --- a/status_pod.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -function status_pod() -{ - - local SYSCTL="/sbin/sysctl" - - # Check that IPOD is built into this kernel - local version - version=`$SYSCTL -n net.ipv4.icmp_ipod_version 2> /dev/null` - if [[ $? -ne 0 ]] - then - echo "Not installed" - return 255 - fi - - # Check if it has been enabled - local enabled=`$SYSCTL -n net.ipv4.icmp_ipod_enabled` - echo -n "version $version " - if [[ $enabled -eq 1 ]] - then - echo "Enabled" - else - echo "Disabled" - fi - return $enabled -} -- 2.43.0