[Midnightbsd-cvs] src [11680] trunk/etc/rc.d/routing: update routing script

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jul 8 16:19:42 EDT 2018


Revision: 11680
          http://svnweb.midnightbsd.org/src/?rev=11680
Author:   laffer1
Date:     2018-07-08 16:19:42 -0400 (Sun, 08 Jul 2018)
Log Message:
-----------
update routing script

Modified Paths:
--------------
    trunk/etc/rc.d/routing

Modified: trunk/etc/rc.d/routing
===================================================================
--- trunk/etc/rc.d/routing	2018-07-08 20:18:31 UTC (rev 11679)
+++ trunk/etc/rc.d/routing	2018-07-08 20:19:42 UTC (rev 11680)
@@ -3,7 +3,6 @@
 # Configure routing and miscellaneous network tunables
 #
 # $MidnightBSD$
-#
 
 # PROVIDE: routing
 # REQUIRE: faith netif ppp stf
@@ -19,78 +18,98 @@
 static_cmd="routing_start static"
 options_cmd="routing_start options"
 
-afcheck()
-{
-	case $_af in
-	""|inet|inet6|ipx|atm)
-		;;
-	*)
-		err 1 "Unsupported address family: $_af."
-		;;
-	esac
-}
+ROUTE_CMD="/sbin/route"
 
 routing_start()
 {
-	local _cmd _af _a
+	local _cmd _af _if _a _ret
 	_cmd=$1
 	_af=$2
+	_if=$3
+	_ret=0
 
-	afcheck
+	case $_if in
+	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])	_if="" ;;
+	esac
 
 	case $_af in
-	inet|inet6|ipx|atm)
-		setroutes $_cmd $_af
-		;;
-	"")
-		for _a in inet inet6 ipx atm; do
-			afexists $_a && setroutes $_cmd $_a
+	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])
+		for _a in inet inet6 atm; do
+			afexists $_a || continue
+			setroutes $_cmd $_a $_if || _ret=1
 		done
-		;;
+	;;
+	*)
+		if afexists $_af; then
+			setroutes $_cmd $_af $_if || _ret=1
+		else
+			err 1 "Unsupported address family: $_af."
+		fi
+	;;
 	esac
+
+	return $_ret
 }
 
 routing_stop()
 {
-	local _af _a
+	local _af _if _a
 	_af=$1
+	_if=$2
 
-	afcheck
+	case $_if in
+	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])	_if="" ;;
+	esac
 
 	case $_af in
-	inet|inet6|ipx|atm)
-		eval static_${_af} delete
-		eval routing_stop_${_af}
-		;;
-	"")
+	""|[Aa][Ll][Ll]|[Aa][Nn][Yy])
 		for _a in inet inet6 ipx atm; do
 			afexists $_a || continue
-			eval static_${_a} delete
-			eval routing_stop_${_a}
+			eval static_${_a} delete $_if
+			# When $_if is specified, do not flush routes.
+			if ! [ -n "$_if" ]; then
+				eval routing_stop_${_a}
+			fi
 		done
-		;;
+	;;
+	*)
+		if afexists $_af; then
+			eval static_${_af} delete $_if 
+			# When $_if is specified, do not flush routes.
+			if ! [ -n "$_if" ]; then
+				eval routing_stop_${_af}
+			fi
+		else
+			err 1 "Unsupported address family: $_af."
+		fi
+	;;
 	esac
 }
 
 setroutes()
 {
+	local _ret
+	_ret=0
 	case $1 in
 	static)
-		static_$2 add
+		static_$2 add $3
+		_ret=$?
 		;;
 	options)
 		options_$2
 		;;
 	doall)
-		static_$2 add
+		static_$2 add $3
+		_ret=$?
 		options_$2
 		;;
 	esac
+	return $_ret
 }
 
 routing_stop_inet()
 {
-	route -n flush -inet
+	${ROUTE_CMD} -n flush -inet
 }
 
 routing_stop_inet6()
@@ -97,9 +116,11 @@
 {
 	local i
 
-	route -n flush -inet6
-	for i in ${ipv6_network_interfaces}; do
-		ifconfig $i inet6 -defaultif
+	${ROUTE_CMD} -n flush -inet6
+	for i in `list_net_interfaces`; do
+		if ipv6if $i; then
+			ifconfig $i inet6 -defaultif
+		fi
 	done
 }
 
@@ -115,22 +136,38 @@
 
 static_inet()
 {
-	local _action
+	local _action _if _skip
 	_action=$1
+	_if=$2
 
+	# Add default route.
 	case ${defaultrouter} in
 	[Nn][Oo] | '')
 		;;
 	*)
-		static_routes="default ${static_routes}"
-		route_default="default ${defaultrouter}"
+		static_routes="${static_routes} _default"
+		route__default="default ${defaultrouter}"
 		;;
 	esac
 
+	# Install configured routes.
 	if [ -n "${static_routes}" ]; then
 		for i in ${static_routes}; do
-			route_args=`get_if_var $i route_IF`
-			route ${_action} ${route_args}
+			_skip=0
+			if [ -n "$_if" ]; then
+				case $i in
+				*:$_if)	;;
+				*)	_skip=1 ;;
+				esac
+			fi
+			if [ $_skip = 0 ]; then
+				route_args=`get_if_var ${i%:*} route_IF`
+				if [ -n "$route_args" ]; then
+					${ROUTE_CMD} ${_action} ${route_args}
+				else
+					warn "route_${i%:*} not found."
+				fi
+			fi
 		done
 	fi
 }
@@ -137,78 +174,87 @@
 
 static_inet6()
 {
-	local _action i fibs
+	local _action _if _skip fibmod fibs allfibs
 	_action=$1
+	_if=$2
 
 	# get the number of FIBs supported.
-	fibs=`sysctl -n net.fibs`
-	: ${fibs:=1}
+	fibs=$((`${SYSCTL_N} net.fibs` - 1))
+	allfibs=`${SYSCTL_N} net.add_addr_allfibs`
+	if [ "$fibs" -gt 0 ] && [ "$allfibs" -ne 0 ]; then
+		fibmod="-fib 0-$fibs"
+	else
+		fibmod=
+	fi
 
+	# Add pre-defined static routes first.
+	ipv6_static_routes="_v4mapped _v4compat ${ipv6_static_routes}"
+	ipv6_static_routes="_lla _llma ${ipv6_static_routes}"
+
 	# disallow "internal" addresses to appear on the wire
-	route ${_action} -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
-	route ${_action} -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
-	i=1
-	if test ${i} -lt ${fibs}; then
-		printf "Also installing reject routes for FIBs"
-		while test ${i} -lt ${fibs}; do
-			setfib -F ${i} route -q ${_action} \
-			    -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
-			setfib -F ${i} route -q ${_action} \
-			    -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
-			printf " %d" ${i}
-			i=$((i + 1))
-		done
-		printf "\n"
-	fi
+	ipv6_route__v4mapped="::ffff:0.0.0.0 -prefixlen 96 ::1 -reject ${fibmod}"
+	ipv6_route__v4compat="::0.0.0.0 -prefixlen 96 ::1 -reject ${fibmod}"
 
+	# Disallow link-local unicast packets without outgoing scope
+	# identifiers.  However, if you set "ipv6_default_interface",
+	# for the host case, you will allow to omit the identifiers.
+	# Under this configuration, the packets will go to the default
+	# interface.
+	ipv6_route__lla="fe80:: -prefixlen 10 ::1 -reject ${fibmod}"
+	ipv6_route__llma="ff02:: -prefixlen 16 ::1 -reject ${fibmod}"
+
+	# Add default route.
 	case ${ipv6_defaultrouter} in
 	[Nn][Oo] | '')
 		;;
 	*)
-		ipv6_static_routes="default ${ipv6_static_routes}"
-		ipv6_route_default="default ${ipv6_defaultrouter}"
+		ipv6_static_routes="${ipv6_static_routes} _default"
+		ipv6_route__default="default ${ipv6_defaultrouter}"
 		;;
 	esac
 
+	# Install configured routes.
 	if [ -n "${ipv6_static_routes}" ]; then
 		for i in ${ipv6_static_routes}; do
-			ipv6_route_args=`get_if_var $i ipv6_route_IF`
-			route ${_action} -inet6 ${ipv6_route_args}
+			_skip=0
+			if [ -n "$_if" ]; then
+				case $i in
+				*:$_if)	;;
+				*)	_skip=1 ;;
+				esac
+			fi
+			if [ $_skip = 0 ]; then
+				ipv6_route_args=`get_if_var ${i%:*} ipv6_route_IF`
+				if [ -n "$ipv6_route_args" ]; then
+					${ROUTE_CMD} ${_action} \
+						-inet6 ${ipv6_route_args}
+				else
+					warn "route_${i%:*} not found"
+				fi
+			fi
 		done
 	fi
 
-	# Fixup $ipv6_network_interfaces
-	case ${ipv6_network_interfaces} in
-	[Nn][Oo][Nn][Ee])
-		ipv6_network_interfaces=''
-		;;
-	esac
+	# Install the "default interface" to kernel, which will be used
+	# as the default route when there's no router.
 
+	# Disable installing the default interface when we act
+	# as router to avoid conflict between the default
+	# router list and the manual configured default route.
 	if checkyesno ipv6_gateway_enable; then
-		for i in ${ipv6_network_interfaces}; do
-
-			laddr=`network6_getladdr $i exclude_tentative`
-			case ${laddr} in
-			'')
-				;;
-			*)
-				ipv6_working_interfaces="$i \
-				    ${ipv6_working_interfaces}"
-				;;
-			esac
-		done
-		ipv6_network_interfaces=${ipv6_working_interfaces}
+		return
 	fi
 
-	# Install the "default interface" to kernel, which will be used
-	# as the default route when there's no router.
 	case "${ipv6_default_interface}" in
 	[Nn][Oo] | [Nn][Oo][Nn][Ee])
-		ipv6_default_interface=""
+		return
 		;;
 	[Aa][Uu][Tt][Oo] | "")
 		for i in ${ipv6_network_interfaces}; do
 			case $i in
+			[Nn][Oo][Nn][Ee])
+				return
+				;;
 			lo0|faith[0-9]*)
 				continue
 				;;
@@ -226,40 +272,8 @@
 		;;
 	esac
 
-	# Disallow link-local unicast packets without outgoing scope
-	# identifiers.  However, if you set "ipv6_default_interface",
-	# for the host case, you will allow to omit the identifiers.
-	# Under this configuration, the packets will go to the default
-	# interface.
-	route ${_action} -inet6 fe80:: -prefixlen 10 ::1 -reject
-	route ${_action} -inet6 ff02:: -prefixlen 16 ::1 -reject
-	i=1
-	if test ${i} -lt ${fibs}; then
-		printf "Also installing reject routes for FIBs"
-		while test ${i} -lt ${fibs}; do
-			setfib -F ${i} route -q ${_action} \
-			    -inet6 fe80:: -prefixlen 10 ::1 -reject
-			setfib -F ${i} route -q ${_action} \
-			    -inet6 ff02:: -prefixlen 16 ::1 -reject
-			printf " %d" ${i}
-			i=$((i + 1))
-		done
-		printf "\n"
-	fi
-
-	case ${ipv6_default_interface} in
-	'')
-		;;
-	*)
-		# Disable installing the default interface when we act
-		# as router to avoid conflict between the default
-		# router list and the manual configured default route.
-		if ! checkyesno ipv6_gateway_enable; then
-			ifconfig ${ipv6_default_interface} inet6 defaultif
-			sysctl net.inet6.ip6.use_defaultzone=1
-		fi
-		;;
-	esac
+	ifconfig ${ipv6_default_interface} inet6 defaultif
+	sysctl net.inet6.ip6.use_defaultzone=1
 }
 
 static_atm()
@@ -270,7 +284,11 @@
 	if [ -n "${natm_static_routes}" ]; then
 		for i in ${natm_static_routes}; do
 			route_args=`get_if_var $i route_IF`
-			atmconfig natm ${_action} ${route_args}
+			if [ -n "$route_args" ]; then
+				atmconfig natm ${_action} ${route_args}
+			else
+				warn "route_${i} not found."
+			fi
 		done
 	fi
 }
@@ -277,6 +295,7 @@
 
 static_ipx()
 {
+	:
 }
 
 ropts_init()



More information about the Midnightbsd-cvs mailing list