#!/bin/sh

# icd2 start ipv6 configuration after ipv4 is done
# so icd2 not working on ipv6 only networks
# this script will tell to icd2 that ipv4 configuraiton
# was successfull if kernel received ipv6 route via RA

# check if we have link
if test "$(cat /sys/class/net/$interface/carrier 2>/dev/null)" != "1"; then
	exit 0
fi

rtsol.real -q -d $interface
ret=$?

if test $ret -ge 0 -a $ret -le 3; then
	# we recived RA packet with ipv6 route
	if test "$1" = "deconfig"; then
		# ignore deconfig when disconnecting (icd state: 3)
		if ! /usr/bin/dbus-send --system --type=method_call --print-reply --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.get_state | sed -n 's/^   uint32 //p' | grep -q '^3$'; then
			/usr/bin/dbus-send --system --dest=com.nokia.icd /com/nokia/icd/autoconf com.nokia.icd.autoconf.autoconf_changed string:$interface string:DHCP string:CONNECTED
		fi
	fi
else
	# there is no ipv6 route
	# call commented parts from 50_ipv4_network_setup script
	if test "$1" = "zeroconf"; then
		/usr/bin/dbus-send --system --dest=com.nokia.icd /com/nokia/icd/autoconf com.nokia.icd.autoconf.autoconf_changed string:$interface string:LINKLOCAL string:CONNECTED
	elif test "$1" = "zeroconf.deconfig"; then
		/usr/bin/dbus-send --system --dest=com.nokia.icd /com/nokia/icd/autoconf com.nokia.icd.autoconf.autoconf_changed string:$interface string:LINKLOCAL string:DISCONNECTED
	fi
fi

exit 0
