Skip to content

Commit

Permalink
Use DAD to check for IPv6 address collision
Browse files Browse the repository at this point in the history
  • Loading branch information
Oyvind Albrigtsen committed Oct 23, 2015
1 parent 7b5a98d commit cea6726
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions rgmanager/src/resources/ip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ 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
Expand Down Expand Up @@ -627,15 +629,38 @@ ipv6()
ocf_log info "Removing IPv6 address $addr from $dev"
fi

if [ "$1" = "add" ]; then
ocf_log debug "Pinging addr ${addr%%/*} from dev $dev"
if ping_check inet6 ${addr%%/*} $dev; then
ocf_log err "IPv6 address collision ${addr%%/*}"
return 1
fi
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,
Expand Down

0 comments on commit cea6726

Please sign in to comment.