Module Name:    src
Committed By:   riz
Date:           Sat May 19 16:48:36 UTC 2012

Modified Files:
        src/etc/rc.d [netbsd-5]: staticroute
        src/share/man/man5 [netbsd-5]: route.conf.5

Log Message:
Pull up following revision(s) (requested by gendalia in ticket #1757):
        share/man/man5/route.conf.5: revision 1.4
        etc/rc.d/staticroute: revision 1.4
        etc/rc.d/staticroute: revision 1.5
        etc/rc.d/staticroute: revision 1.6
Add a "return 0" to avoid incorrect error returns because we ran out of
lines to read from "/etc/route.conf".
Add proper error reporting via the return code:
Remember if any of the "route" commands failed and return an error in
that case.
Add the ability for staticroute to evaluate lines from /etc/route.conf
as shell script fragments, add example to the route.conf man page of
evaluating variables.
Remove route.conf man page statement that staticroute is enabled in
rc.conf since that's incorrect.
Wrap the staticroute while in parens, per <apb> & <christos>, and
quote all the arguments for the evals.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.12.1 src/etc/rc.d/staticroute
cvs rdiff -u -r1.3 -r1.3.2.1 src/share/man/man5/route.conf.5

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/etc/rc.d/staticroute
diff -u src/etc/rc.d/staticroute:1.3 src/etc/rc.d/staticroute:1.3.12.1
--- src/etc/rc.d/staticroute:1.3	Thu Jan 31 15:21:32 2008
+++ src/etc/rc.d/staticroute	Sat May 19 16:48:36 2012
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: staticroute,v 1.3 2008/01/31 15:21:32 reed Exp $
+# $NetBSD: staticroute,v 1.3.12.1 2012/05/19 16:48:36 riz Exp $
 #
 
 # PROVIDE: staticroute
@@ -16,25 +16,36 @@ start_cmd="staticroute_doit Adding add"
 stop_cmd="staticroute_doit Deleting delete"
 
 staticroute_doit() {
+	retval=0
+
 	if [ -s /etc/route.conf ]; then
 		echo "$1 static routes."
-		while read args; do
+		( while read args; do
 			[ -z "$args" ] && continue
 			case "$args" in
 			"#"*)
 				;;
 			"+"*)
-				[ $2 = "add" ] && eval ${args#*+}
+				if [ $2 = "add" ]; then
+					eval "${args#*+}" || retval=1
+				fi
 				;;
 			"-"*)
-				[ $2 = "delete" ] && eval ${args#*-}
+				if [ $2 = "delete" ]; then
+					eval "${args#*-}" || retval=1
+				fi
+				;;
+			"!"*)
+				eval "${args#*!}" || retval=1
 				;;
 			*)
-				route -q $2 -$args
+				eval "route -q $2 -$args" || retval=1
 				;;
 			esac
-		done < /etc/route.conf
+		done < /etc/route.conf )
 	fi
+
+	return $retval
 }
 
 load_rc_config $name

Index: src/share/man/man5/route.conf.5
diff -u src/share/man/man5/route.conf.5:1.3 src/share/man/man5/route.conf.5:1.3.2.1
--- src/share/man/man5/route.conf.5:1.3	Thu May  8 15:34:39 2008
+++ src/share/man/man5/route.conf.5	Sat May 19 16:48:36 2012
@@ -1,4 +1,4 @@
-.\"        $NetBSD: route.conf.5,v 1.3 2008/05/08 15:34:39 wiz Exp $
+.\"        $NetBSD: route.conf.5,v 1.3.2.1 2012/05/19 16:48:36 riz Exp $
 .\"
 .\" Copyright (c) 2004 Thomas Klausner
 .\" All rights reserved.
@@ -23,7 +23,7 @@
 .\" INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 24, 2004
+.Dd May 1, 2012
 .Dt ROUTE.CONF 5
 .Os
 .Sh NAME
@@ -46,6 +46,9 @@ are run during start-up,
 while lines starting with a minus sign
 .Pq Sq \-
 are run during system shutdown.
+If a line starts with a
+.Sq \&! ,
+the rest of the line will get evaluated as a shell script fragment.
 All other lines are passed to
 .Xr route 8 .
 During start-up, they are passed behind a
@@ -66,10 +69,17 @@ script that parses
 .Nm .
 .El
 .Sh EXAMPLES
-In this example, if the
-.Pa staticroute
-script is enabled in
-.Xr rc.conf 5 ,
+In this example, the interface for the desired routing changes is set,
+the IP address on that interface is determined, and a route is added
+during startup, or deleted during system shutdown.
+.Bd -literal -offset indent 
+# Set interface and determine current IP address for added route.
+!ifname=bnx0
+!ipaddr=$(/sbin/ifconfig ${ifname} | awk '$1 == "inet" {print $2}')
+net 10.10.1 -interface ${ipaddr}
+.Ed
+.Pp
+In this example,
 IP forwarding is turned on during
 start-up, and a static route added for 192.168.2.0.
 During system shutdown, the route is removed

Reply via email to