tech-userlevel archive

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

proposed /etc/rc.d/staticroute change to allow variables



Currently I have done this for local systems:

% cat /etc/rc.conf.d/staticroute
ifname=$(ifconfig -lbs | awk '{print $1}')
ipaddr=$(ifconfig ${ifname} | awk '$1 == "inet" {print $2}')
staticroute_doit() {
        if [ -s /etc/route.conf ]; then
                echo "$1 static routes."
                while read args; do
                        [ -z "$args" ] && continue
                        case "$args" in
                        "#"*)
                                ;;
                        "+"*)
                                [ $2 = "add" ] && eval ${args#*+}
                                ;;
                        "-"*)
                                [ $2 = "delete" ] && eval ${args#*-}
                                ;;
                        *)
                                eval route -q $2 -$args
                                ;;
                        esac
                done < /etc/route.conf
        fi
}
% cat /etc/route.conf
#
net 10.10.1.0  -netmask 255.255.255.0 ${ipaddr} ; true work
net 10.10.6.0  -netmask 255.255.255.0 ${ipaddr} ; true work
net 10.10.142.0 -netmask 255.255.255.0 ${ipaddr} ; true work
%

The only difference between the system staticroute_doit() and mine is
the "eval" before the route. Without it, I can't have "; true work"
(which I can get rid of anyway), and I can't have ${ipaddr} to easily
deal with IP address and interface changes.

If adding 'eval' to *) seems too risky, alternatively an additional
option of ! would work as well, such that staticroute_doit() looks
like:

staticroute_doit() {
        if [ -s /etc/route.conf ]; then
                echo "$1 static routes."
                while read args; do
                        [ -z "$args" ] && continue
                        case "$args" in
                        "#"*)
                                ;;
                        "+"*)
                                [ $2 = "add" ] && eval ${args#*+}
                                ;;
                        "-"*)
                                [ $2 = "delete" ] && eval ${args#*-}
                                ;;
                        "!"*)
                                eval route -q $2 -${args#*!}
                                ;;
                        *)
                                route -q $2 -$args
                                ;;
                        esac
                done < /etc/route.conf
        fi
}

and /etc/route.conf looks like:

!net 10.10.1.0  -netmask 255.255.255.0 ${ipaddr} ; true durham95
!net 10.10.6.0  -netmask 255.255.255.0 ${ipaddr} ; true durham95
!net 10.10.142.0 -netmask 255.255.255.0 ${ipaddr} ; true durham95

Opinions? Objections?

-Tracy


Home | Main Index | Thread Index | Old Index