svn commit: r197719 - head/etc/rc.d

Hiroki Sato hrs at FreeBSD.org
Fri Oct 2 20:19:53 UTC 2009


Author: hrs
Date: Fri Oct  2 20:19:53 2009
New Revision: 197719
URL: http://svn.freebsd.org/changeset/base/197719

Log:
  - Enable an afexists() check only when no AF argument is specified.
  - Simplify helper functions.
  
  Discussed with:	ume

Modified:
  head/etc/rc.d/routing

Modified: head/etc/rc.d/routing
==============================================================================
--- head/etc/rc.d/routing	Fri Oct  2 20:15:47 2009	(r197718)
+++ head/etc/rc.d/routing	Fri Oct  2 20:19:53 2009	(r197719)
@@ -13,26 +13,80 @@
 . /etc/network.subr
 
 name="routing"
-start_cmd="routing_start"
+start_cmd="routing_start doall"
 stop_cmd="routing_stop"
 extra_commands="options static"
-static_cmd="static_start"
-options_cmd="options_start"
+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
+}
 
 routing_start()
 {
-	static_start "$@"
-	options_start "$@"
+	local _cmd _af _a
+	_cmd=$1
+	_af=$2
+
+	afcheck
+
+	case $_af in
+	inet|inet6|ipx|atm)
+		setroutes $_cmd $_af
+		;;
+	"")
+		for _a in inet inet6 ipx atm; do
+			afexists $_a && setroutes $_cmd $_a
+		done
+		;;
+	esac
+	[ -n "${_ropts_initdone}" ] && echo '.'
 }
 
 routing_stop()
 {
-	local _af
+	local _af _a
+	_af=$1
 
-	static_stop "$@"
-	for _af in inet inet6; do
-		afexists ${_af} && eval routing_stop_${_af}
-	done
+	afcheck
+
+	case $_af in
+	inet|inet6|ipx|atm)
+		eval static_${_af} delete
+		eval routing_stop_${_af}
+		;;
+	"")
+		for _a in inet inet6 ipx atm; do
+			afexists $_a || continue
+			eval static_${_a} delete
+			eval routing_stop_${_a}
+		done
+		;;
+	esac
+}
+
+setroutes()
+{
+	case $1 in
+	static)
+		static_$2 add
+		;;
+	options)
+		options_$2
+		;;
+	doall)
+		static_$2 add
+		options_$2
+		;;
+	esac
 }
 
 routing_stop_inet()
@@ -50,45 +104,14 @@ routing_stop_inet6()
 	done
 }
 
-static_start()
-{
-	local _af
-	_af=$1
-
-	case ${_af} in
-	inet|inet6|atm)
-		do_static add ${_af}
-		;;
-	"")
-		do_static add inet inet6 atm
-		;;
-	esac
-}
-
-static_stop()
+routing_stop_atm()
 {
-	local _af
-	_af=$1
-
-	case ${_af} in
-	inet|inet6|atm)
-		do_static delete ${_af}
-		;;
-	"")
-		do_static delete inet inet6 atm
-		;;
-	esac
+	return 0
 }
 
-do_static()
+routing_stop_ipx()
 {
-	local _af _action
-	_action=$1
-
-	shift
-	for _af in "$@"; do
-		afexists ${_af} && eval static_${_af} ${_action}
-	done
+	return 0
 }
 
 static_inet()
@@ -233,6 +256,10 @@ static_atm()
 	fi
 }
 
+static_ipx()
+{
+}
+
 _ropts_initdone=
 ropts_init()
 {
@@ -242,16 +269,6 @@ ropts_init()
 	fi
 }
 
-options_start()
-{
-	local _af
-
-	for _af in inet inet6 ipx; do
-		afexists ${_af} && eval options_${_af}
-	done
-	 [ -n "${_ropts_initdone}" ] && echo '.'
-}
-
 options_inet()
 {
 	if checkyesno icmp_bmcastecho; then
@@ -322,6 +339,10 @@ options_inet6()
 	fi
 }
 
+options_atm()
+{
+}
+
 options_ipx()
 {
 	if checkyesno ipxgateway_enable; then


More information about the svn-src-all mailing list