File:  [Local Repository] / badi / public_scripts / switchgate / dhclient-exit-hooks.d / switchgate-helper
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Sat Apr 4 21:29:07 2020 UTC (4 years, 7 months ago) by adi
Branches: MAIN
CVS tags: HEAD
get ipv6 ready


# dhclient-exit-hook: switchgate-helper

RUN="yes"
SWITCHGATE="/usr/local/sbin/switchgate"

if [ "$RUN" = "yes" ]; then 

	# ipv4 or ipv6?
	if [ -z "$(echo "$reason" | sed -e "s/^.*6$//")" ]; then
		IF_FILENAME="dhcp6.${interface}"
		IPV="IPv6"
	else
		IF_FILENAME="dhcp.${interface}"
		IPV="IPv4"
	fi

	# get writeable tmp dir from switchgate
	SWITCHGATE_TMPDIR="$("$SWITCHGATE" -C)"
	if [ $? -ne 0 ]; then
		echo -e "Error: Failed to query switchgate:\n\n$SWITCHGATE_TMPDIR"
		exit 1
	elif [ -z "$SWITCHGATE_TMPDIR" ]; then
		echo "Error: No writeable dir from switchgate received. Please check."
		exit 1
	fi

	
	case "$reason" in 

	    BOUND|RENEW|REBIND|REBOOT|BOUND6|RENEW6|REBIND6|REBOOT6)

		# check there is a gateway given
		if [ -z "$new_routers" ]; then
			echo "No $IPV gateway supplied from DHCP server."
			# remove the gw file
			if [ -f "$SWITCHGATE_TMPDIR/$IF_FILENAME" ]; then
				rm "$SWITCHGATE_TMPDIR/$IF_FILENAME"
			fi
			exit 0
		fi
		
		# create writeable dir if not already existing
		if [ ! -d "$SWITCHGATE_TMPDIR" ]; then
			mkdir "$SWITCHGATE_TMPDIR"
		fi

		echo "Adding DHCP supplied gateways to the list of gateways for switchgate: $new_routers"

		# Register switchgate routers
		echo "$new_routers" | sed -e "s/ /\n/g" > "$SWITCHGATE_TMPDIR/$IF_FILENAME"
		;;

	    *)
		# remove the gw file
		if [ -f "$SWITCHGATE_TMPDIR/$IF_FILENAME" ]; then
			rm "$SWITCHGATE_TMPDIR/$IF_FILENAME"
		fi
		exit 0
		;;

	esac
fi

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>