#!/bin/ksh # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2018,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/usr/sbin/cluster/utilities/cl_hb_alias.sh 1.10 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2002,2011 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#) 7d4c34b 43haes/usr/sbin/cluster/utilities/cl_hb_alias.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM ############################################################################### # # COMPONENT_NAME: EVENTUTILS # ############################################################################### ############################################################################### # # Name: cl_hb_alias # # This script is used to manage alias addresses for heartbeat. It is called # from the cl_hats_adapter utility. # # The parameters are: # interface name - e.g. en0. Because this is a local action only, there # are no other arguments required - interface name is # unique on a node and can be used to look up the # network, alias address, netmask, etc. # # action - there are 4 basic actions: # -e - (enable) add the alias address to the specified adapter and # enable it (to hats) # -d - delete the alias (and only the alias) from the adapter # and disable it (to hats) # -f - same as -d but dont check the results # -g - begin an rsct grace period request for this adapter # # Other actions may be passed from cl_hats_adapter - if the # interface is not one using heartbeat via alias, simply return # 1 so the caller can do the appropriate calls. # # grace period - optional - only passed on -g requests # # Note that this routine does NOT check the attribute of the network itself - # it assumes the caller has determined this network is using hb via aliasing. # # Returns: 1 - adapter is not configured for heartbeat via aliasing # 0 - adapter sucesfully configured with alias hb address # -1 - failure - ifconfig failure, bad number of arguments, etc # # Environment: VERBOSE_LOGGING,PATH # ############################################################################### ############################################################################### # Name: flush_arp # # Flushes entire arp cache # # Returns: None. ############################################################################### flush_arp () { typeset PS4_FUNC="flush_arp" [[ "$VERBOSE_LOGGING" = "high" ]] && set -x set -u arp -an | grep "\?" | tr -d '()' | (while read host addr other ; do arp -d $addr done) return 0 } ############################################################################### # Name: check_alias_status # # This modification to check_ifconfig_status, added for IP aliasing support # because ifconfig displays aliased addresses on additional lines. # # Arguments: # Interface to check # IP address in dotted-decimal format # Netmask in dotted-decimal format # # Returns: # 0 Interface has a proper entry # -1 Interface does not have a proper entry # ############################################################################### check_alias_status () { typeset PS4_FUNC="check_alias_status" set -u CH_INTERFACE=$1 CH_ADDRESS=$2 CH_ACQ_OR_RLSE=$3 ADDR=`ifconfig $CH_INTERFACE | grep -w $CH_ADDRESS | awk '{print $2}'` # # If any IPv6 address is aliased, then it is seen as below # 2001::4/64 # [[ "$ADDR_FAMILY" == "AF_INET6" ]] && { ADDR=`echo $ADDR | cut -d '/' -f 1` } if [ "$CH_ACQ_OR_RLSE" = "-e" ] then # if acquiring, make sure the alias IS on the interface [[ "$ADDR" != "$CH_ADDRESS" ]] && { cl_log 7324 "$PROGNAME: Failed to ifconfig alias $CH_ADDRESS on interface $CH_INTERFACE" $PROGNAME $CH_ADDRESS $CH_INTERFACE return -1 } else # if releasing, make sure the alias IS NOT on the interface [[ "$ADDR" = "$CH_ADDRESS" ]] && { cl_log 7325 "$PROGNAME: Failed ifconfig delete alias $CH_ADDRESS from interface $CH_INTERFACE." $PROGNAME $CH_ADDRESS $CH_INTERFACE return -1 } fi return 0 } ############################################################################### # Name: check_ATM_interface # # This routine is used to determine if a given interface is a classical # ATM interface or an ATM LAN emulation interface. # # Arguments: # $1 Interface name # # Stdout: # "atm" ATM Classical IP interface # "atmle_ent" ATM Ethernet Emulation interface # "atmle_tok" ATM Token-ring Emulation interface # "" Other interfaces # # Returns: N/A ############################################################################### check_ATM_interface () { typeset PS4_FUNC="check_ATM_interface" [[ "$VERBOSE_LOGGING" = "high" ]] && set -x set -u if_name=$1 case $if_name in at*) echo "atm" ;; en*|et*) LC_ALL=C entstat -d $if_name 2>&1 | awk \ '/Device Type: ATM LAN Emulation/ {print "atmle_ent";exit}' ;; tr*) LC_ALL=C tokstat -d $if_name 2>&1 | awk \ '/Device Type: ATM LAN Emulation/ {print "atmle_tok";exit}' ;; esac } ############################################################################### # Name: disable_pmtu_gated # # Disable PMTU discovery and the gated daemon temporarily. # Global variables DISABLE_TCP_PMTU, DISABLE_UDP_PMTU and DISABLE_GATED # are set to retain current values. # # Arguments: 0 # # Returns: N/A ############################################################################### disable_pmtu_gated() { typeset PS4_FUNC="disable_pmtu_gated" DISABLE_TCP_PMTU=0 DISABLE_UDP_PMTU=0 DISABLE_TCP_PMTU=$(no -o tcp_pmtu_discover | cut -f3,3 -d" ") DISABLE_UDP_PMTU=$(no -o udp_pmtu_discover | cut -f3,3 -d" ") no -o tcp_pmtu_discover=0 no -o udp_pmtu_discover=0 # Note that running gated is not presently supported by HACMP. # The user may experience side effects if gated is not implemented # properly. HACMP does at least attempt to stop gated: ps -eo "pid,comm" | grep -w gated 2> /dev/null DISABLE_GATED=$? if [ $DISABLE_GATED -eq 0 ] then # This loop waits for gated to exit before continuing on. # The counter is set to 10 which means we will loop for # a maximum of 10 seconds before continuing on. This # counter can be increased however if it is increased # it might be wise to also increase the nim grace period # to prevent false fail_adapter events from occuring. GATED_COUNT=10; /usr/bin/stopsrc -s gated 2> /dev/null while [[ $GATED_COUNT -gt 0 ]] do ps -eo "pid,comm" | grep -w gated 2> /dev/null if [ $? -eq 1 ] then break; fi GATED_COUNT=`expr $GATED_COUNT - 1` sleep 1 done fi return 0 } ############################################################################### # Name: enable_pmtu_gated # # Reenable PMTU discovery and restart gated daemon. # Global variables DISABLE_TCP_PMTU, DISABLE_UDP_PMTU and DISABLE_GATED # hold values previously set in the disable_pmtu_gated subroutine. # # Arguments: 0 # # Returns: N/A ############################################################################### enable_pmtu_gated() { typeset PS4_FUNC="enable_pmtu_gated" # if PMTU discovery was disabled, then reenable it. no -o tcp_pmtu_discover=$DISABLE_TCP_PMTU no -o udp_pmtu_discover=$DISABLE_UDP_PMTU # if gated was on when we entered this script, start it back [[ $DISABLE_GATED -eq 0 ]] && { startsrc -s gated; sleep 5; } return 0 } restore_ipignoreredirects() { typeset PS4_FUNC="restore_ipignoreredirects" /usr/sbin/no -o ipignoreredirects=$PRIOR_IPIGNORE_REDIRECTS_VALUE } set_ipignoreredirects() { typeset PS4_FUNC="set_ipignoreredirects" PRIOR_IPIGNORE_REDIRECTS_VALUE=`no -a | grep ipignoreredirects | awk '{ print $3 }'` /usr/sbin/no -o ipignoreredirects=1 } ############################################################################### # # Main entry point # ############################################################################### PROGNAME=$(basename ${0}) export PATH="$($(dirname ${0})/cl_get_path all)" [[ "$VERBOSE_LOGGING" = "high" ]] && set -x [[ "$VERBOSE_LOGGING" = "high" ]] && version='1.10 $Source: 61haes_r711 43haes/usr/sbin/cluster/utilities/cl_hb_alias.sh 1$' HA_DIR="$(cl_get_path)" OP_SEP="$(cl_get_path -S)" ATM_IF_TYPE="" STATUS=0 ADDR="" # address to be acquired or released NETWORK="" # on this network NETMASK="" # of the interface (IPv4) NET_TYPE="" # type of the network ADDR_FAMILY="" # address family (AF_INET/AF_INET6) PREFIX_LEN="" # prefix lenght (IPv6) OUTPUT="" IF=$1 # this is the interface (adapter) ACTION=$2 # this is the action if [[ $# -gt 2 ]]; then GRACE_PERIOD=$3 fi # check the inputs if [[ $# -gt 3 ]]; then # bad arg count cl_echo 9106 "Usage: $PROGNAME [grace_period]\n" $PROGNAME exit -1 fi if [[ $# -gt 2 && $ACTION != "-g" ]]; then # bad arg count cl_echo 9106 "Usage: $PROGNAME [grace_period]\n" $PROGNAME exit -1 fi # number of args is ok, proceed set -u date # # setup for rsct hats adapter call # export HA_DOMAIN_NAME=`/usr/sbin/cluster/utilities/cldomain` export HB_SERVER_SOCKET=/var/ha/soc/topsvcs/server_socket BINDIR=/usr/sbin/rsct/bin # get some information about this interface LOCALNODENAME=$(get_local_nodename) MTUSIZE=$(netstat -in | \ awk '$1 == "'$IF'" && $3 !~ "[Ll]ink" {print $2}'|uniq) # output of cllsif is: # 3 - network # 4 - network type # 11 - netmask # 12 - hb_alias # 14 - prefix length # 15 - address family (AF_INET/AF_INET6) OUTPUT=$(cllsif -J "$OP_SEP" -Si $LOCALNODENAME | grep "$OP_SEP$IF$OP_SEP") ADDR_FAMILY=$(echo $OUTPUT | cut -d"$OP_SEP" -f 15); if [[ "$ADDR_FAMILY" == "AF_INET" ]] then NETMASK=$(echo $OUTPUT | cut -d"$OP_SEP" -f 11) fi if [[ "$ADDR_FAMILY" == "AF_INET6" ]] then PREFIX_LEN=$(echo $OUTPUT | cut -d"$OP_SEP" -f 14) fi echo $OUTPUT | cut -d"$OP_SEP" -f3,4,12 | tr "$OP_SEP" " " | read NETWORK NET_TYPE ADDR if [ -z "$ADDR" ]; then cl_echo 9132 "$PROGNAME: Could not determine alias address for heartbeat for adapter $IF on node $LOCALNODENAME\n" $PROGNAME $IF $LOCALNODENAME exit 1 fi # do the specified action case $ACTION in -e ) cl_echo 7310 "$PROGNAME: Configuring network interface $IF with aliased IP address $ADDR\n" $PROGNAME $IF $ADDR # alias add the specified address to the specified interface case "$ADDR_FAMILY" in AF_INET) ifconfig $IF alias $ADDR netmask $NETMASK 2>/dev/null ;; AF_INET6) ifconfig $IF inet6 "$ADDR" alias prefixlen "$PREFIX_LEN" 2> /dev/null ;; *) dspmsg scripts.cat 9503 "\n$PROGNAME: ERROR: Invalid address \ family for IP address \"$ADDR\".\n" $PROGNAME $ADDR exit 1 ;; esac # tell hats to start monitoring this alias $BINDIR/hats_adapter -e $ADDR sleep 2 check_alias_status $IF $ADDR -e STATUS=$? ;; -d ) cl_echo 7320 "$PROGNAME: Removing aliased IP address $ADDR from adapter $IF\n" $PROGNAME $ADDR $IF # tell hats not to monitor this alias $BINDIR/hats_adapter -d $ADDR # delete the alias for the specified address case "$ADDR_FAMILY" in AF_INET) ifconfig $IF delete $ADDR 2>/dev/null ;; AF_INET6) ifconfig $IF inet6 "$ADDR" delete 2> /dev/null ;; *) dspmsg scripts.cat 9503 "\n$PROGNAME: ERROR: Invalid address \ family for IP address \"$ADDR\".\n" $PROGNAME $ADDR exit 1 ;; esac sleep 2 check_alias_status $IF $ADDR -d STATUS=$? ;; -f ) cl_echo 7320 "$PROGNAME: Removing aliased IP address $ADDR from adapter $IF\n" $PROGNAME $ADDR $IF # tell hats not to monitor this alias $BINDIR/hats_adapter -d $ADDR # delete the alias for the specified address case "$ADDR_FAMILY" in AF_INET) ifconfig $IF delete $ADDR 2>/dev/null ;; AF_INET6) ifconfig $IF inet6 "$ADDR" delete 2> /dev/null ;; *) dspmsg scripts.cat 9503 "\n$PROGNAME: ERROR: Invalid address \ family for IP address \"$ADDR\".\n" $PROGNAME $ADDR exit 1 ;; esac ;; -g ) # tell hats to start a grace period $BINDIR/hats_adapter -g $GRACE_PERIOD $ADDR STATUS=$? ;; * ) # not one of the actions we need to process STATUS=1 ;; esac date exit $STATUS