#!/bin/sh # # set_ttl # ------- # Script to modify the ttl values: # tcpDefaultTTL - time to live of an ip datagram; i.e., # of hops # (Most reboot for effect to take place.) # # Hewlett-Packard Corporation # This script is UNSUPPORTED. Use at own risk. # Written: 8/27/93 Bob Kelley # Modified: 20 Oct 94 Bob Kelley Dropped Max to 127 - real limit! # Modified: 9 Dec 94 Bob Kelley Fixed bug: used adb (d/w) instead of (D/W) # PATH=/bin:/usr/bin:/etc:. # # Range of accepted values # max_ttl=127 # At most 255 hops allowed per IP min_ttl=2 # At least past 1 hop # # Default Values # def_ttl=30 # 30 hops # # Temporary Dumping Ground # TMPFILE=/tmp/keep$$ # initialize variables # TTL=$def_ttl set_ttl=0 ttl_varies=0 # # Usage Subroutine # usage() { echo "usage: set_ttl { [-d] | [-p] | [-t ] | [-help] }" exit } # # Help Information Subroutine - called when -help option given # printhelp() { echo "set_icmp:" echo " Will set the kernel's IP datagram time-to-live field." echo "- The \"-t n\" option sets the time to n. " echo "- The \"-d\" option sets the time to its default (30)." echo "- The \"-p\" option prints out the current values." echo "- Must reboot for change to take effect." } # # Kernel value reading subroutine # read_values() { adb /hp-ux /dev/kmem << EOF > $TMPFILE tcpDefaultTTL?d tcpDefaultTTL/d EOF vals=`cat $TMPFILE | grep tcpDefault | awk '{if ($2 != "") printf "%s ", $2}'` once=0 for i in $vals do case $once in 0) TTL_file=`expr $i / 256` lo_byte_file=`expr $i % 256` once=`expr $once + 1`;; 1) TTL_image=`expr $i / 256` lo_byte_image=`expr $i % 256` once=`expr $once + 1`;; *) echo "internal error" esac done rm $TMPFILE } # Begin of Program # # check for options for i in $* do case $i in -t ) shift set_ttl=1 TTL=$1 if [ $TTL -le $max_ttl ] && [ $TTL -ge $min_ttl ] then shift else echo "TTL, $TTL, is out of range ( $min_ttl to $max_ttl)" exit fi;; -d ) TTL=$def_ttl set_ttl=1;; -p) ;; #default case -help ) printhelp exit ;; -* ) echo $1 is an unknown parameter usage;; esac done read_values if [ $TTL_file -ne $TTL_image ] then echo "Warning: the keep alive interval value differ in the kernel image and hp-ux file" ttl_varies=1 fi # # if we are not setting values, then print out the current ones # if [ $set_ttl -eq 0 ] then if [ $ttl_varies -eq 0 ] then echo "The TTL field is set to $TTL_file" else echo "The kernel file TTL field is set to $TTL_file" echo "The kernel image TTL field is set to $TTL_image" fi exit fi # # Set the new TTL # if [ $set_ttl -eq 1 ] then # first calculate the word, using the lo_bytes previously read TTLword_image=`expr 256 \* $TTL + $lo_byte_image` TTLword_file=`expr 256 \* $TTL + $lo_byte_file` # write interval to kernel and kernel image adb -w /hp-ux /dev/kmem << EOF > /dev/null tcpDefaultTTL?w 0d$TTLword_file tcpDefaultTTL/w 0d$TTLword_image EOF read_values if [ $TTL_image -ne $TTL ] then echo "Error in changing TTL kernel image to $TTL. Currently is $TTL_image." fi if [ $TTL_file -ne $TTL ] then echo "Error in changing TTL kernel file to $TTL. Currently is $TTL_file." exit fi if [ $TTL_image -eq $TTL ] && [ $TTL_file -eq $TTL ] then echo "TCP TTL changed to $TTL." echo "Reboot to have change take effect." fi fi