diff options
author | brooks <brooks@FreeBSD.org> | 2005-06-07 04:49:12 +0000 |
---|---|---|
committer | brooks <brooks@FreeBSD.org> | 2005-06-07 04:49:12 +0000 |
commit | 5a3d620fb15161572eed8cb406ccb6672fd2f93c (patch) | |
tree | 5b737af62b38f4124fab3c80ff903dbb7a8a0a1d /etc/network.subr | |
parent | 9a851b1b815c8f75342aef3c3bdd9d7943045a0d (diff) | |
download | FreeBSD-src-5a3d620fb15161572eed8cb406ccb6672fd2f93c.zip FreeBSD-src-5a3d620fb15161572eed8cb406ccb6672fd2f93c.tar.gz |
Support code for the OpenBSD dhclient. This significantly changes the
way interfaces are configured. Some key points:
- At startup, all interfaces are configured through /etc/rc.d/netif.
- ifconfig_<if> variables my now mix real ifconfig commands the with
DHCP and WPA directives. For example, this allows media
configuration prior to running dhclient.
- /etc/rc.d/dhclient is not run at startup except by netif to start
dhclient on specific interfaces.
- /etc/pccard_ether calls "/etc/rc.d/netif start <if>" to do most of
it's work.
- /etc/pccard_ether no longer takes additional arguments to pass to
ifconfig. Instead, ifconfig_<if> variables are now honored in favor
of pccard_ifconfig when available.
- /etc/pccard_ether will only run on interfaces specified in
removable_interfaces, even if pccard_ifconfig is set.
Diffstat (limited to 'etc/network.subr')
-rw-r--r-- | etc/network.subr | 111 |
1 files changed, 107 insertions, 4 deletions
diff --git a/etc/network.subr b/etc/network.subr index dfd2feb..a3059dd 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -34,16 +34,30 @@ # Evaluate ifconfig(8) arguments for interface $if and # run ifconfig(8) with those arguments. It returns 0 if # arguments were found and executed or 1 if the interface -# had no arguments. +# had no arguments. Pseudo arguments DHCP and WPA are handled +# here. # ifconfig_up() { - eval ifconfig_args=\$ifconfig_$1 + _cfg=1 + + ifconfig_args=`ifconfig_getargs $1` if [ -n "${ifconfig_args}" ]; then ifconfig $1 ${ifconfig_args} - return 0 + _cfg=0 fi - return 1 + + if wpaif $1; then + #/etc/rc.d/wpa_supplicant start $1 + _cfg=0 # XXX: not sure this should count + fi + + if dhcpif $1; then + /etc/rc.d/dhclient start $1 + _cfg=0 + fi + + return ${cfg} } # ifconfig_down if @@ -74,9 +88,98 @@ ifconfig_down() done IFS="$oldifs" + if wpaif $1; then + #/etc/rc.d/wpa_supplicant stop $1 + fi + + if dhcpif $1; then + /etc/rc.d/dhclient stop $1 + _cfg=0 + fi + return $_ret } +# _ifconfig_getargs if +# Echos the arguments for the supplied interface to stdout. +# returns 1 if empty. In general, ifconfig_getargs should be used +# outside this file. +_ifconfig_getargs() +{ + _ifn=$1 + if [ -z "$_ifn" ]; then + return 1 + fi + + eval _args=\$ifconfig_$1 + if [ -z "$_args" -a -n "${pccard_ifconfig}" ]; then + for _if in ${removable_interfaces} ; do + if [ "$_if" = "$_ifn" ] ; then + _args=${pccard_ifconfig} + break + fi + done + fi + + echo $_args +} + +# ifconfig_getargs if +# Takes the result from _ifconfig_getargs and removes pseudo +# args such as DHCP and WPA. +ifconfig_getargs() +{ + _tmpargs=`_ifconfig_getargs $1` + if [ $? -eq 1 ]; then + return 1 + fi + _args= + + for _arg in $_tmpargs; do + case $_arg in + [Dd][Hh][Cc][Pp]) + ;; + [Ww][Pp][Aa]) + ;; + *) + _args="$_args $_arg" + ;; + esac + done + + echo $_args +} + +# dhcpif if +# Returns 0 if the interface is a DHCP interface and 1 otherwise. +dhcpif() +{ + _tmpargs=`_ifconfig_getargs $1` + for _arg in $_tmpargs; do + case $_arg in + [Dd][Hh][Cc][Pp]) + return 0 + ;; + esac + done + return 1 +} + +# wpaif if +# Returns 0 if the interface is a WPA interface and 1 otherwise. +wpaif() +{ + _tmpargs=`_ifconfig_getargs $1` + for _arg in $_tmpargs; do + case $_arg in + [Ww][Pp][Aa]) + return 0 + ;; + esac + done + return 1 +} + # ifalias_up if # Configure aliases for network interface $if. # It returns 0 if at least one alias was configured or |