This file is indexed.

/usr/share/cluster/ip.sh is in resource-agents 1:4.1.0~rc1-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
#!/bin/bash

#
# IPv4/IPv6 address management using iproute2 (formerly: ifcfg, ifconfig).
#
#
# Copyright (C) 1997-2003 Sistina Software, Inc.  All rights reserved.
# Copyright (C) 2004-2012 Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

LC_ALL=C
LANG=C
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export LC_ALL LANG PATH

SENDUA=/usr/libexec/heartbeat/send_ua

# Grab nfs lock tricks if available
export NFS_TRICKS=1
if [ -f "$(dirname $0)/svclib_nfslock" ]; then
	. $(dirname $0)/svclib_nfslock
	NFS_TRICKS=0
fi

. $(dirname $0)/ocf-shellfuncs


meta_data()
{
    cat <<EOT
<?xml version="1.0" ?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1-modified.dtd">
<resource-agent version="rgmanager 2.0" name="ip">
    <version>1.0</version>

    <longdesc lang="en">
        This is an IP address.  Both IPv4 and IPv6 addresses are supported,
        as well as NIC link monitoring for each IP address.
    </longdesc>
    <shortdesc lang="en">
        This is an IP address.
    </shortdesc>

    <parameters>
        <parameter name="address" unique="1" primary="1">
            <longdesc lang="en">
                IPv4 or IPv6 address to use as a virtual IP
                resource.  It may be followed by a slash and a decimal
                number that encodes the network prefix length.
            </longdesc>

            <shortdesc lang="en">
                IP Address
            </shortdesc>

	    <content type="string"/>
        </parameter>

        <parameter name="family">
            <longdesc lang="en">
                IPv4 or IPv6 address protocol family.
            </longdesc>

            <shortdesc lang="en">
                Family
            </shortdesc>

            <!--
            <val>auto</val>
            <val>inet</val>
            <val>inet6</val>
            -->
            <content type="string"/>
        </parameter>

        <parameter name="monitor_link">
            <longdesc lang="en">
                Enabling this causes the status check to fail if
                the link on the NIC to which this IP address is
                bound is not present.
            </longdesc>
            <shortdesc lang="en">
                Monitor NIC Link
            </shortdesc>
            <content type="boolean" default="1"/>
        </parameter>

	<parameter name="nfslock" inherit="service%nfslock">
	    <longdesc lang="en">
	        If set and unmounting the file system fails, the node will
		try to kill lockd and issue reclaims across all remaining
		network interface cards.
	    </longdesc>
	    <shortdesc lang="en">
	        Enable NFS lock workarounds
	    </shortdesc>
	    <content type="boolean"/>
	</parameter>

	<parameter name="sleeptime">
	    <longdesc lang="en">
		Amount of time to sleep after removing an IP address.
		Value is specified in seconds. Default value is 10.
	    </longdesc>
	    <shortdesc lang="en">
		Amount of time (seconds) to sleep.
	    </shortdesc>
	    <content type="string"/>
	</parameter>

	<parameter name="disable_rdisc">
	    <longdesc lang="en">
	        Disable updating of routing using RDISC protocol and
	        preserve static routes.
	    </longdesc>
	    <shortdesc lang="en">
	        Disable updating of routing using RDISC protocol
	    </shortdesc>
	    <content type="boolean"/>
	</parameter>

	<parameter name="prefer_interface">
	    <longdesc lang="en">
	        The network interface to which the IP address should be added. The interface must already be configured and active. This parameter should be used only when at least two active interfaces have IP addresses on the same subnet and it is desired to have the IP address added to a particular interface.
	    </longdesc>
	    <shortdesc lang="en">
	        Network interface
	    </shortdesc>
	    <content type="string"/>
	</parameter>
    </parameters>

    <actions>
        <action name="start" timeout="20"/>
        <action name="stop" timeout="20"/>
	<!-- No recover action.  If the IP address is not useable, then
	     resources may or may not depend on it.  If it's been 
	     deconfigured, resources using it are in a bad state. -->

	<!-- Checks to see if the IP is up and (optionally) the link is
	     working -->
        <action name="status" interval="20" timeout="10"/>
        <action name="monitor" interval="20" timeout="10"/>

	<!-- Checks to see if we can ping the IP address locally -->
        <action name="status" depth="10" interval="60" timeout="20"/>
        <action name="monitor" depth="10" interval="60" timeout="20"/>

        <action name="meta-data" timeout="20"/>
        <action name="validate-all" timeout="20"/>
    </actions>

    <special tag="rgmanager">
	<attributes maxinstances="1"/>
	<child type="nfsclient" forbid="1"/>
	<child type="nfsexport" forbid="1"/>
    </special>
</resource-agent>
EOT
}


verify_address()
{
	# XXX TBD
	return 0
}


verify_all()
{
	# XXX TBD
	return 0
}


#
# Expand an IPv6 address.
#
ipv6_expand()
{
	typeset addr=$1
	typeset maskbits
	typeset -i x
	typeset tempaddr
	
	maskbits=${addr/*\//}
	if [ "$maskbits" = "$addr" ]; then
		maskbits=""
	else
		# chop off mask bits
		addr=${addr/\/*/}
	fi

	# grab each hex quad and expand it to 4 digits if it isn't already
	# leave doublecolon in place for expansion out to the proper number of zeros later
	tempaddr=""
	for count in `seq 1 8`; do
		quad=`echo $addr|awk -v count=$count -F : '{print $count}'`
		quadlen=${#quad}
		if [ $quadlen -eq 0 ]; then
			quad=::
		elif [ $quadlen -eq 1 ]; then
			quad=000$quad
		elif [ $quadlen -eq 2 ]; then
			quad=00$quad
		elif [ $quadlen -eq 3 ]; then
			quad=0$quad
		fi
		tempaddr=$tempaddr$quad
	done
	addr=$tempaddr

	# use space as placeholder
	addr=${addr/::/\ }

	# get rid of colons
	addr=${addr//:/}

	# add in zeroes where the doublecolon was
	len=$((${#addr}-1))
	zeroes=
	while [ $len -lt 32 ]; do
		zeroes="0$zeroes"
		((len++))
	done
	addr=${addr/\ /$zeroes}

	# probably a better way to do this
	for (( x=0; x < ${#addr} ; x++)); do
		naddr=$naddr${addr:x:1}

		if (( x < (${#addr} - 1) && x%4 == 3)); then
			naddr=$naddr:
		fi
	done

	if [ -n "$maskbits" ]; then
		echo "$naddr/$maskbits"
		return 0
	fi

	echo "$naddr"
	return 0
}


#
# see if two ipv6 addrs are in the same subnet
#
ipv6_same_subnet()
{
	declare addrl=$1
	declare addrr=$2
	declare m=$3 
	declare r x llsb rlsb

	if [ $# -lt 2 ]; then
		ocf_log err "usage: ipv6_same_subnet addr1 addr2 [mask]"
		return 255
	fi

	if [ -z "$m" ]; then
		m=${addrl/*\//}

		[ -n "$m" ] || return 1

	fi

	if [ "${addrr}" != "${addrr/*\//}" ] &&
	   [ "$m" != "${addrr/*\//}" ]; then
		return 1
	fi

	addrl=${addrl/\/*/}
	if [ ${#addrl} -lt 39 ]; then
		addrl=$(ipv6_expand $addrl)
	fi

	addrr=${addrr/\/*/}
	if [ ${#addrr} -lt 39 ]; then
		addrr=$(ipv6_expand $addrr)
	fi

	# Calculate the amount to compare directly
	x=$(($m/4+$m/16-(($m%4)==0)))

	# and the remaining number of bits
	r=$(($m%4))

	if [ $r -ne 0 ]; then
		# If we have any remaining bits, we will need to compare
		# them later.  Get them now.
		llsb=`printf "%d" 0x${addrl:$x:1}`
		rlsb=`printf "%d" 0x${addrr:$x:1}`

		# One less byte to compare directly, please
		((--x))
	fi
	
	# direct (string comparison) to see if they are equal
	if [ "${addrl:0:$x}" != "${addrr:0:$x}" ]; then
		return 1
	fi

	case $r in
	0)
		return 0
		;;
	1)	
		[ $(($llsb & 8)) -eq $(($rlsb & 8)) ]
		return $?
		;;
	2)
		[ $(($llsb & 12)) -eq $(($rlsb & 12)) ]
		return $?
		;;
	3)
		[ $(($llsb & 14)) -eq $(($rlsb & 14)) ]
		return $?
		;;
	esac

	return 1
}


ipv4_same_subnet()
{
	declare addrl=$1
	declare addrr=$2
	declare m=$3 
	declare r x llsb rlsb

	if [ $# -lt 2 ]; then
		ocf_log err "usage: ipv4_same_subnet current_addr new_addr [maskbits]"
		return 255
	fi


	#
	# Chop the netmask off of the ipaddr:
	# e.g. 1.2.3.4/22 -> 22
	#
	if [ -z "$m" ]; then
		m=${addrl/*\//}
		[ -n "$m" ] || return 1
	fi

	#
	# Check to see if there was a subnet mask provided on the
	# new IP address.  If there was one and it does not match
	# our expected subnet mask, we are done.
	#
	if [ "${addrr}" != "${addrr/\/*/}" ] &&
	   [ "$m" != "${addrr/*\//}" ]; then
		return 1
	fi

	#
	# Chop off subnet bits for good.
	#
	addrl=${addrl/\/*/}
	addrr=${addrr/\/*/}

	#
	# Remove '.' characters from dotted decimal notation and save
	# in arrays. i.e.
	#
	#	192.168.1.163 -> array[0] = 192
	#	                 array[1] = 168
	#	                 array[2] = 1
	#	                 array[3] = 163
	#

	let x=0
	for quad in ${addrl//./\ }; do
		ip1[((x++))]=$quad
	done

	x=0
	for quad in ${addrr//./\ }; do
		ip2[((x++))]=$quad
	done

	x=0

	while [ $m -ge 8 ]; do
		((m-=8))
		if [ ${ip1[x]} -ne ${ip2[x]} ]; then
			return 1
		fi
		((x++))
	done

	case $m in
	0)
		return 0
		;;
	1)	
		[ $((${ip1[x]} & 128)) -eq $((${ip2[x]} & 128)) ]
		return $?
		;;
	2)
		[ $((${ip1[x]} & 192)) -eq $((${ip2[x]} & 192)) ]
		return $?
		;;
	3)
		[ $((${ip1[x]} & 224)) -eq $((${ip2[x]} & 224)) ]
		return $?
		;;
	4)
		[ $((${ip1[x]} & 240)) -eq $((${ip2[x]} & 240)) ]
		return $?
		;;
	5)
		[ $((${ip1[x]} & 248)) -eq $((${ip2[x]} & 248)) ]
		return $?
		;;
	6)
		[ $((${ip1[x]} & 252)) -eq $((${ip2[x]} & 252)) ]
		return $?
		;;
	7)
		[ $((${ip1[x]} & 254)) -eq $((${ip2[x]} & 254)) ]
		return $?
		;;
	esac

	return 1
}


ipv6_list_interfaces()
{
	declare idx dev ifaddr
	declare ifaddr_exp
	
	while read idx dev ifaddr; do
	    
		isSlave $dev
		if [ $? -ne 2 ]; then
			continue
		fi
		
		idx=${idx/:/}
		
		ifaddr_exp=$(ipv6_expand $ifaddr)
		
		echo $dev ${ifaddr_exp/\/*/} ${ifaddr_exp/*\//}
		
	done < <(/sbin/ip -o -f inet6 addr | awk '{print $1,$2,$4}')

	return 0
}


isSlave()
{
	declare intf=$1
	declare line

	if [ -z "$intf" ]; then
		ocf_log err "usage: isSlave <I/F>"
		return $OCF_ERR_ARGS
	fi

	line=$(/sbin/ip link list dev $intf)
	if [ $? -ne 0 ]; then
		ocf_log err "$intf not found"
		return $OCF_ERR_GENERIC
	fi

	if [ "$line" = "${line/<*SLAVE*>/}" ]; then
		return 2
	fi

	# Yes, it is a slave device.  Ignore.
	return 0
}


# 
# Check if interface is in UP state
#
interface_up()
{
       declare intf=$1
       
       if [ -z "$intf" ]; then
		ocf_log err "usage: interface_up <I/F>"
		return 1
       fi
       
       line=$(/sbin/ip -o link show up dev $intf 2> /dev/null)
       [ -z "$line" ] && return 2
       
       return 0
}


ethernet_link_up()
{
	declare linkstate=$(ethtool $1 | grep "Link detected:" |\
			    awk '{print $3}')
	
	[ -n "$linkstate" ] || return 0

	case $linkstate in
	yes)
		return 0
		;;
	*)
		return 1
		;;
	esac
	
	return 1
}


#
# Checks the physical link status of an ethernet or bonded interface.
#
network_link_up()
{
	declare slaves
	declare intf_arg=$1
	declare link_up=1		# Assume link down
	declare intf_test

	if [ -z "$intf_arg" ]; then
		ocf_log err "usage: network_link_up <intf>"
		return 1
	fi
	
	ethernet_link_up $intf_arg
	link_up=$?

	if [ $link_up -eq 0 ]; then
		ocf_log debug "Link for $intf_arg: Detected"
	else
		ocf_log warn "Link for $intf_arg: Not detected"
	fi

	return $link_up
}


ipv4_list_interfaces()
{
	declare idx dev ifaddr

	while read idx dev ifaddr; do
	        
		isSlave $dev
		if [ $? -ne 2 ]; then
			continue
		fi
		
		idx=${idx/:/}
		
		echo $dev ${ifaddr/\/*/} ${ifaddr/*\//}
		
	done < <(/sbin/ip -o -f inet addr | awk '{print $1,$2,$4}')
	
	return 0
}


#
# Add an IP address to our interface or remove it.
#
ipv6()
{
	declare dev maskbits
	declare addr=$2
	declare addr_exp=$(ipv6_expand $addr)
	
	while read dev ifaddr_exp maskbits; do 
	        if [ -z "$dev" ]; then
		        continue
		fi
		
		if [ "$1" = "add" ]; then
			if [ -n "$OCF_RESKEY_prefer_interface" ] && \
			   [ "$OCF_RESKEY_prefer_interface" != $dev ]; then
				continue
			fi
			ipv6_same_subnet $ifaddr_exp/$maskbits $addr_exp
			if [ $? -ne 0 ]; then
                                continue
                        fi
                        interface_up $dev
                        if [ $? -ne 0 ]; then
                                continue
                        fi
			if [ "$OCF_RESKEY_monitor_link" = "yes" ]; then
                        	network_link_up $dev
                        	if [ $? -ne 0 ]; then
                                	continue
                        	fi
			fi

			if [ "${addr/\/*/}" = "${addr}" ]; then
				addr="$addr/$maskbits"
			fi
			ocf_log info "Adding IPv6 address $addr to $dev"
		fi
		if [ "$1" = "del" ]; then
		        if [ "${addr_exp/\/*/}" != "$ifaddr_exp" ]; then
			        continue
			fi
			addr=`/sbin/ip addr list | grep "$addr" | head -n 1 | awk '{print $2}'`
			ocf_log info "Removing IPv6 address $addr from $dev"
                fi
		
		/sbin/ip -f inet6 addr $1 dev $dev $addr
		[ $? -ne 0 ] && return 1

		# Duplicate Address Detection [DAD]
		# Kernel will flag the IP as 'tentative' until it ensured that
		# there is no duplicates.
		# if there is, it will flag it as 'dadfailed'
		if [ "$1" = "add" ]; then
			for i in {1..10}; do
				ipstatus=$(/sbin/ip -o -f inet6 addr show dev $dev to $addr)
				if [[ $ipstatus == *dadfailed* ]]; then
					ocf_log err "IPv6 address collision ${addr%%/*} [DAD]"
					ip -f inet6 addr del dev $dev $addr
					if [[ $? -ne 0 ]]; then
						ocf_log err "Could not delete IPv6 address"
					fi
					return 1
				elif [[ $ipstatus != *tentative* ]]; then
					break
				elif [[ $i -eq 10 ]]; then
					ofc_log warn "IPv6 address : DAD is still in tentative"
				fi
				sleep 0.5
			done
			# Now the address should be useable
			# Try to send Unsolicited Neighbor Advertisements if send_ua is available
 			if [ -x $SENDUA ]; then
				ARGS="-i 200 -c 5 ${addr%%/*} $maskbits $dev"
				ocf_log info "$SENDUA $ARGS"
				$SENDUA $ARGS || ocf_log err "Could not send ICMPv6 Unsolicited Neighbor Advertisements."
 			fi
		fi
		
		#
		# NDP should take of figuring out our new address.  Plus,
		# we do not have something (like arping) to do this for ipv6
		# anyway.
		# 
		# RFC 2461, section 7.2.6 states thusly:
		#
	   	# Note that because unsolicited Neighbor Advertisements do not
		# reliably update caches in all nodes (the advertisements might
		# not be received by all nodes), they should only be viewed as
		# a performance optimization to quickly update the caches in
		#  most neighbors. 
		#
		
		# Not sure if this is necessary for ipv6 either.
		file=$(which rdisc 2>/dev/null)
		if [ -f "$file" ]; then
			if [ "$OCF_RESKEY_disable_rdisc" != "yes" ] && \
			   [ "$OCF_RESKEY_disable_rdisc" != "1" ]; then
		        	killall -HUP rdisc || rdisc -fs
			fi
		fi
		
		return 0
	done < <(ipv6_list_interfaces)
	
	return 1
}


#
# Add an IP address to our interface or remove it.
#
ipv4()
{
	declare dev ifaddr maskbits
	declare addr=$2
	
	while read dev ifaddr maskbits; do
	        if [ -z "$dev" ]; then
		        continue
		fi

		if [ "$1" = "add" ]; then
			if [ -n "$OCF_RESKEY_prefer_interface" ] && \
			   [ "$OCF_RESKEY_prefer_interface" != $dev ]; then
				continue
			fi
		        ipv4_same_subnet $ifaddr/$maskbits $addr
			if [ $? -ne 0 ]; then
			        continue
			fi
		        interface_up $dev
			if [ $? -ne 0 ]; then
			        continue
			fi
			if [ "$OCF_RESKEY_monitor_link" = "yes" ]; then
				network_link_up $dev
				if [ $? -ne 0 ]; then
					continue
				fi
			fi

			if [ "${addr/\/*/}" = "${addr}" ]; then
				addr="$addr/$maskbits"
			fi
			ocf_log info "Adding IPv4 address $addr to $dev"
		fi
		if [ "$1" = "del" ]; then
			if [ "${addr/\/*/}" != "$ifaddr" ]; then
			        continue
			fi
			addr=`/sbin/ip addr list | grep "$ifaddr/" | head -n 1 | awk '{print $2}'`
			ocf_log info "Removing IPv4 address $addr from $dev"
		fi
		
		if [ "$1" = "add" ]; then
			ocf_log debug "Pinging addr ${addr%%/*} from dev $dev"
			if ping_check inet ${addr%%/*} $dev; then
				ocf_log err "IPv4 address collision ${addr%%/*}"
				return 1
			fi
		fi
		/sbin/ip -f inet addr $1 dev $dev $addr
		[ $? -ne 0 ] && return 1
		
        	#
		# XXX: Following needed? ifconfig:YES, ifcfg:NO, iproute2:???
        	#
		if [ "$1" = "add" ]; then
        		# do that freak arp thing
		    
 		        hwaddr=$(/sbin/ip -o link show $dev)
			hwaddr=${hwaddr/*link\/ether\ /}
			hwaddr=${hwaddr/\ \*/}
			
			addr=${addr/\/*/}
			ocf_log debug "Sending gratuitous ARP: $addr $hwaddr"
			arping -q -c 2 -U -I $dev $addr
		fi
		
		file=$(which rdisc 2>/dev/null)
		if [ -f "$file" ]; then
			if [ "$OCF_RESKEY_disable_rdisc" != "yes" ] && \
			   [ "$OCF_RESKEY_disable_rdisc" != "1" ]; then
			        killall -HUP rdisc || rdisc -fs
			fi
		fi
		
		return 0
	done  < <(ipv4_list_interfaces)
	
	return 1
}


#
# Usage:
# ping_check <family> <address> [interface]
#
ping_check()
{
	declare ops="-c 1 -w 2"
	declare pingcmd=""

	if [ "$1" = "inet6" ]; then
		pingcmd="ping6"
	else
		pingcmd="ping"
	fi

	if [ -n "$3" ]; then 
		ops="$ops -I $3"
	fi

	return $($pingcmd $ops $2 &> /dev/null)
}


# 
# Usage:
# check_interface_up <family> <address>
#
check_interface_up()
{
	declare dev
	declare addr=${2/\/*/}
	declare currentAddr caExpanded

	if [ "$1" == "inet6" ]; then
		addrExpanded=$(ipv6_expand $addr)
		for currentAddr in `/sbin/ip -f $1 -o addr|awk '{print $4}'`; do
			caExpanded=$(ipv6_expand $currentAddr)
			caExpanded=${caExpanded/\/*/}
			if [ "$addrExpanded" == "$caExpanded" ]; then
				dev=$(/sbin/ip -f $1 -o addr | grep " ${currentAddr/\/*/}" | awk '{print $2}')
				break
			fi
		done
	else
		dev=$(/sbin/ip -f $1 -o addr | grep " $addr/" | awk '{print $2}')
	fi

	if [ -z "$dev" ]; then
		return 1
	fi
	
	interface_up $dev
	return $?
}


# 
# Usage:
# address_configured <family> <address>
#
address_configured()
{
	declare line
	declare addr
	declare currentAddr caExpanded

	# Chop off mask bits
	addr=${2/\/*/}

	if [ "$1" == "inet6" ]; then
		addrExpanded=$(ipv6_expand $addr)
		for currentAddr in `/sbin/ip -f $1 -o addr|awk '{print $4}'`; do
			caExpanded=$(ipv6_expand $currentAddr)
			caExpanded=${caExpanded/\/*/}
			if [ "$addrExpanded" == "$caExpanded" ]; then
				line=$(/sbin/ip -f $1 -o addr | grep " ${currentAddr/\/*/}");
				break
			fi
		done
	else
		line=$(/sbin/ip -f $1 -o addr | grep " $addr/")
	fi

	if [ -z "$line" ]; then
		return 1
	fi
	return 0
}


#
# Usage:
# ip_op <family> <operation> <address> [quiet]
#
ip_op()
{
	declare dev
	declare rtr
	declare addr=${3/\/*/}
	declare caExpanded currentAddr

	if [ "$2" = "status" ]; then

		ocf_log debug "Checking $3, Level $OCF_CHECK_LEVEL"
	
		if [ "$1" == "inet6" ]; then
			addrExpanded=$(ipv6_expand $addr)
			for currentAddr in `/sbin/ip -f $1 -o addr|awk '{print $4}'`; do
				caExpanded=$(ipv6_expand $currentAddr)
				caExpanded=${caExpanded/\/*/}
				if [ "$addrExpanded" == "$caExpanded" ]; then
					dev=$(/sbin/ip -f $1 -o addr | grep " ${currentAddr/\/*/}" | awk '{print $2}')
					break
				fi
			done
		else
			dev=$(/sbin/ip -f $1 -o addr | grep " $addr/" | awk '{print $2}')
		fi

		if [ -z "$dev" ]; then
			ocf_log warn "$3 is not configured"
			return 1
		fi
		ocf_log debug "$3 present on $dev"
		
		if [ "$OCF_RESKEY_monitor_link" = "yes" ]; then
			if ! network_link_up $dev; then
		        	ocf_log warn "No link on $dev..."
				return 1
			fi
			ocf_log debug "Link detected on $dev"
		fi
		
		[ $OCF_CHECK_LEVEL -lt 10 ] && return 0
		if ! ping_check $1 $addr $dev; then
			ocf_log warn "Failed to ping $addr"
			return 1
		fi
		ocf_log debug "Local ping to $addr succeeded"
		
		return 0
	fi

	case $1 in
	inet)
		ipv4 $2 $3
		return $?
		;;
	inet6)
		if [ "$2" = "del" ]; then
			addrExpanded=$(ipv6_expand $addr)
			for currentAddr in `/sbin/ip -f $1 -o addr|awk '{print $4}'`; do
				caExpanded=$(ipv6_expand $currentAddr)
				caExpanded=${caExpanded/\/*/}
				if [ "$addrExpanded" == "$caExpanded" ]; then
					addr6=$(/sbin/ip -f $1 -o addr | grep " ${currentAddr/\/*/}" | awk '{print $4}')
					ipv6 $2 $addr6
					return $?
				fi
			done
		fi

		ipv6 $2 $3
		return $?
		;;
	esac
	return 1
}


case ${OCF_RESKEY_family} in
inet)
	;;
inet6)
	;;
*)
	if [ "${OCF_RESKEY_address//:/}" != "${OCF_RESKEY_address}" ]; then
		export OCF_RESKEY_family=inet6
	else
		export OCF_RESKEY_family=inet
	fi
	;;
esac

# Force ipv6 addresses to lower case
if [ "$OCF_RESKEY_family" = "inet6" ]; then
	OCF_RESKEY_address=$(echo $OCF_RESKEY_address | tr '[:upper:]' '[:lower:]')
fi

if [ -z "$OCF_CHECK_LEVEL" ]; then
	OCF_CHECK_LEVEL=0
fi

if [ "${OCF_RESKEY_monitor_link}" = "no" ] ||
   [ "${OCF_RESKEY_monitor_link}" = "0" ]; then
        OCF_RESKEY_monitor_link="no"
else
        OCF_RESKEY_monitor_link="yes"
fi

case $1 in
start)
	if address_configured ${OCF_RESKEY_family} ${OCF_RESKEY_address}; then
		ocf_log debug "${OCF_RESKEY_address} already configured"
		exit 0
	fi
	ip_op ${OCF_RESKEY_family} add ${OCF_RESKEY_address}
	if [ $? -ne 0 ]; then
		exit $OCF_ERR_GENERIC
	fi

	if [ $NFS_TRICKS -eq 0 ]; then
		if [ "$OCF_RESKEY_nfslock" = "yes" ] || \
	   	   [ "$OCF_RESKEY_nfslock" = "1" ]; then
			notify_list_broadcast /var/lib/nfs/statd
		fi
	fi

	exit $?
	;;
stop)
	if address_configured ${OCF_RESKEY_family} ${OCF_RESKEY_address}; then
		
		ip_op ${OCF_RESKEY_family} del ${OCF_RESKEY_address}

		# Make sure it's down
		if address_configured ${OCF_RESKEY_family} ${OCF_RESKEY_address}; then
			ocf_log err "Failed to remove ${OCF_RESKEY_address}"
			exit 1
		fi

		# XXX Let nfsd/lockd clear their queues; we hope to have a
		# way to enforce this in the future
		if [ -z "$OCF_RESKEY_sleeptime" ]; then
		    sleep 10
		else
		    if [ "$OCF_RESKEY_sleeptime" -gt "0" ]; then
			sleep $OCF_RESKEY_sleeptime
		    fi
		fi
	else
		ocf_log debug "${OCF_RESKEY_address} is not configured"
	fi
	exit 0
	;;
status|monitor)
	ip_op ${OCF_RESKEY_family} status ${OCF_RESKEY_address}
	[ $? -ne 0 ] && exit $OCF_NOT_RUNNING
	
	check_interface_up ${OCF_RESKEY_family} ${OCF_RESKEY_address}
	exit $?
	;;
restart)
	$0 stop || exit $OCF_ERR_GENERIC
	$0 start || exit $OCF_ERR_GENERIC
	exit 0
	;;
meta-data)
	meta_data
	exit 0
	;;
validate-all|verify_all)
	verify_all
	exit $?
	;;
*)
	echo "usage: $0 {start|stop|status|monitor|restart|meta-data|validate-all}"
	exit $OCF_ERR_UNIMPLEMENTED
	;;
esac