misc/145440: Multiple fib support (setfib) in /etc/rc.d/routing

Mark Harrison mark at mivok.net
Tue Apr 6 20:30:07 UTC 2010


>Number:         145440
>Category:       misc
>Synopsis:       Multiple fib support (setfib) in /etc/rc.d/routing
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 06 20:30:06 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Mark Harrison
>Release:        8.0-RELEASE-p2
>Organization:
OmniTI
>Environment:
FreeBSD gatling.office.omniti.com 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Sat Apr  3 13:15:36 EDT 2010     root at gatling.office.omniti.com:/usr/obj/usr/src/sys/OMNIKERN  amd64
>Description:
It is not possible to set up static/default routes for alternate fib on startup via rc.conf. The current method is to use rc.local and manually run 'setfib <n> route add ...'
>How-To-Repeat:
Recompile the kernel with multiple fib support (sysctl net.fibs should be > 1). Try to set up static routes for a fib > 0.
>Fix:
This patch adds support for setting up static routes in alternate fibs in
rc.conf. For fibs other than 0, append _fib<n> to the relevant configuration
options normally dealt with by the routing rc script.

E.g.

static_routes_fib1="foo bar"
defaultrouter_fib1="10.0.0.1"

This requires that multiple fib support be compiled into the kernel.

In addition, the stop function flushes routes for all fibs on the system.

Patch attached with submission follows:

--- /jails/test/etc/rc.d/routing	2009-11-21 09:31:36.000000000 -0500
+++ /etc/rc.d/routing	2010-04-06 16:12:01.050390660 -0400
@@ -27,36 +27,60 @@
 
 routing_stop()
 {
-	route -n flush
+	fibcount=`sysctl -n net.fibs`
+	[ -z $fibcount ] && fibcount=1
+	i=0
+	while [ $i -lt $fibcount ]; do
+		setfib $i route -n flush
+		i=$((i + 1))
+	done
 }
 
 static_start()
 {
-	case ${defaultrouter} in
-	[Nn][Oo] | '')
-		;;
-	*)
-		static_routes="default ${static_routes}"
-		route_default="default ${defaultrouter}"
-		;;
-	esac
-
-	# Setup static routes. This should be done before router discovery.
-	#
-	if [ -n "${static_routes}" ]; then
-		for i in ${static_routes}; do
-			eval route_args=\$route_${i}
-			route add ${route_args}
-		done
-	fi
-	# Now ATM static routes
-	#
-	if [ -n "${natm_static_routes}" ]; then
-		for i in ${natm_static_routes}; do
-			eval route_args=\$route_${i}
-			atmconfig natm add ${route_args}
-		done
-	fi
+	fib=0
+	setfib=''
+	while : ; do
+		if [ $fib -gt 0 ]; then
+			eval defaultrouter=\$defaultrouter_fib${fib}
+			eval static_routes=\$static_routes_fib${fib}
+			eval natm_static_routes=\$natm_static_routes_fib${fib}
+			setfib="setfib $fib"
+			[ -z "${defaultrouter}" -a -z "${static_routes}" -a \
+			-z "${natm_static_routes}" ] && break
+		fi
+
+		case ${defaultrouter} in
+		[Nn][Oo] | '')
+			;;
+		*)
+			static_routes="default ${static_routes}"
+			route_default="default ${defaultrouter}"
+			;;
+		esac
+
+		# Setup static routes. This should be done before router
+		# discovery.
+		#
+		if [ -n "${static_routes}" ]; then
+			for i in ${static_routes}; do
+				eval route_args=\$route_${i}
+				${setfib} route add ${route_args}
+			done
+		fi
+		# Now ATM static routes
+		#
+		if [ -n "${natm_static_routes}" ]; then
+			for i in ${natm_static_routes}; do
+				eval route_args=\$route_${i}
+				${setfib} atmconfig natm add ${route_args}
+			done
+		fi
+
+		# Loop through all fib configs
+		#
+		fib=$((fib + 1))
+	done
 }
 
 _ropts_initdone=


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list