Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add the ability for staticroute to evaluate lines from /etc/...



details:   https://anonhg.NetBSD.org/src/rev/847863c4283c
branches:  trunk
changeset: 779102:847863c4283c
user:      gendalia <gendalia%NetBSD.org@localhost>
date:      Wed May 02 15:57:15 2012 +0000

description:
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.

diffstat:

 etc/rc.d/staticroute        |  15 +++++++++------
 share/man/man5/route.conf.5 |  22 ++++++++++++++++------
 2 files changed, 25 insertions(+), 12 deletions(-)

diffs (96 lines):

diff -r 591747dab2ac -r 847863c4283c etc/rc.d/staticroute
--- a/etc/rc.d/staticroute      Wed May 02 15:42:58 2012 +0000
+++ b/etc/rc.d/staticroute      Wed May 02 15:57:15 2012 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: staticroute,v 1.5 2009/10/07 08:06:11 tron Exp $
+# $NetBSD: staticroute,v 1.6 2012/05/02 15:57:15 gendalia Exp $
 #
 
 # PROVIDE: staticroute
@@ -20,26 +20,29 @@
 
        if [ -s /etc/route.conf ]; then
                echo "$1 static routes."
-               while read args; do
+               ( while read args; do
                        [ -z "$args" ] && continue
                        case "$args" in
                        "#"*)
                                ;;
                        "+"*)
                                if [ $2 = "add" ]; then
-                                       eval ${args#*+} || retval=1
+                                       eval "${args#*+}" || retval=1
                                fi
                                ;;
                        "-"*)
                                if [ $2 = "delete" ]; then
-                                       eval ${args#*-} || retval=1
+                                       eval "${args#*-}" || retval=1
                                fi
                                ;;
+                       "!"*)
+                               eval "${args#*!}" || retval=1
+                               ;;
                        *)
-                               route -q $2 -$args || retval=1
+                               eval "route -q $2 -$args" || retval=1
                                ;;
                        esac
-               done < /etc/route.conf
+               done < /etc/route.conf )
        fi
 
        return $retval
diff -r 591747dab2ac -r 847863c4283c share/man/man5/route.conf.5
--- a/share/man/man5/route.conf.5       Wed May 02 15:42:58 2012 +0000
+++ b/share/man/man5/route.conf.5       Wed May 02 15:57:15 2012 +0000
@@ -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.4 2012/05/02 15:57:15 gendalia 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 @@
 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 @@
 .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



Home | Main Index | Thread Index | Old Index