tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: proposed /etc/rc.d/staticroute change to allow variables
On Mon, Oct 17, 2011 at 5:09 PM, David Brownlee <abs%netbsd.org@localhost>
wrote:
> On 17 October 2011 22:19, Tracy Di Marco White
> <netbsd-t%menelos.com@localhost> wrote:
>> 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?
>>
>
> Since ! has a well defined meaning in ifconfig.if, maybe use a '$' or
> similar prefix to mean eval?
I was using someone else's suggestion for it, my preference is to not
have a separate indicator, but offering an option to have one. Do you
feel it should be separate?
-Tracy
Home |
Main Index |
Thread Index |
Old Index