check_is_pppoe ()
{
	if  [ -z $1 ]; then
		return 1;
	fi

	/bin/grep pppoe /proc/$1/cmdline  > /dev/null 2>&1
	if [ 0 -eq $? ]; then
		return 0;
	fi

	return 1;
}

check_is_usbmodem ()
{
	local IPPARAM="$1"
	local PEERWVDIAL_PATH='/etc/ppp/peers/wvdial'

	# if this ppp called wvdial, it will pass addition parameter
	if [ -z $IPPARAM ]; then
		return 0
	fi

	# if file is not readable
	if [ ! -r $PEERWVDIAL_PATH ]; then
		return 0
	fi

	# the parameter should same as ipparam in wvdial
	local WVDIAL_IPPARAM=`grep ipparam $PEERWVDIAL_PATH | cut -d' ' -f2`
	if [ "x$WVDIAL_IPPARAM" != "x$IPPARAM" ]; then
		return 0
	fi

	return 1
}

check_usbmodem_is_defaultroute ()
{
	local WVDIAL_NODEFAULTROUTE=`grep nodefaultroute /etc/ppp/peers/wvdial`

	# check if default route set
	if [ ! -z $WVDIAL_NODEFAULTROUTE ]; then
		return 0
	fi

	return 1
}

restore_backup_default_gateway ()
{
	# check that is the default gateway exists
	/sbin/ip route | /bin/grep default > /dev/null 2>&1
	[ $? -eq 0 ] && return 0

	local pppoe_gw="/tmp/pppoe_gw_backup"
	local default_gw=`/bin/cat /etc/ppp/usbmodem_backup_gw | /usr/bin/head -n1`

	if [ -e ${pppoe_gw} ]; then
		default_gw=`/bin/cat ${pppoe_gw} | /usr/bin/head -n1`
	fi
	/sbin/route add default gw ${default_gw}
	if [ 0 -ne $? ]; then
		logger -p user.err "routing table is losing default gateway (${default_gw})."
	fi
}
