From: Sascha Wildner Date: Tue, 10 Jul 2007 22:36:01 +0000 (+0000) Subject: Add a wpa_supplicant rc script and bring in code to handle "WPA" in an X-Git-Tag: v2.0.1~2601 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/f26c267a65aecf9279492ce5aa7d711dd8b5680d Add a wpa_supplicant rc script and bring in code to handle "WPA" in an ifconfig_blah0="..." line in rc.conf. It should now be possible to bring up a wireless interface with a line similar to: ifconfig_iwi0="up WPA DHCP" This commit also removes the restriction that when "DHCP" was specified, the rest of the arguments were ignored. So the following should work now: ifconfig_rl0="DHCP media 10baseT/UTP" The commit also adds rc settings for interface renaming, e.g.: ifconfig_iwi0_name="net0" ifconfig_net0="up WPA DHCP" Obtained-from: FreeBSD --- diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index 18b94499e9..ed1303b0b6 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -14,7 +14,7 @@ # All arguments must be in double or single quotes. # # $FreeBSD: src/etc/defaults/rc.conf,v 1.180 2003/06/26 09:50:50 smkelly Exp $ -# $DragonFly: src/etc/defaults/rc.conf,v 1.39 2007/07/04 16:28:45 swildner Exp $ +# $DragonFly: src/etc/defaults/rc.conf,v 1.40 2007/07/10 22:36:01 swildner Exp $ ############################################################## ### Important initial Boot-time options #################### @@ -116,6 +116,7 @@ cloned_interfaces="" # List of cloned network interfaces to create. ifconfig_lo0="inet 127.0.0.1" # default loopback device configuration. #ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff" # Sample alias entry. #ifconfig_ed0_ipx="ipx 0x00010010" # Sample IPX address family entry. +#ifconfig_fxp0_name="net0" # Change interface name from fxp0 to net0. # # If you have any sppp(4) interfaces above, you might also want to set # the following parameters. Refer to spppcontrol(8) for their meaning. diff --git a/etc/mtree/BSD.var.dist b/etc/mtree/BSD.var.dist index 2cdd9c3cda..55f0da9fff 100644 --- a/etc/mtree/BSD.var.dist +++ b/etc/mtree/BSD.var.dist @@ -1,5 +1,5 @@ # $FreeBSD: src/etc/mtree/BSD.var.dist,v 1.43.2.9 2002/06/30 17:57:17 des Exp $ -# $DragonFly: src/etc/mtree/BSD.var.dist,v 1.5 2007/02/07 16:34:32 corecode Exp $ +# $DragonFly: src/etc/mtree/BSD.var.dist,v 1.6 2007/07/10 22:36:01 swildner Exp $ # # Please see the file src/etc/mtree/README before making changes to this file. # @@ -63,6 +63,8 @@ run ppp gname=network mode=0770 .. + wpa_supplicant + .. .. rwho gname=daemon mode=0775 .. diff --git a/etc/network.subr b/etc/network.subr index 3187254789..825b42d9ca 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -22,8 +22,8 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $FreeBSD: src/etc/network.subr,v 1.156 2004/08/28 07:58:02 yar Exp $ -# $DragonFly: src/etc/network.subr,v 1.4 2005/12/24 14:29:47 corecode Exp $ +# $FreeBSD: src/etc/network.subr,v 1.163 2005/06/30 04:52:47 brooks Exp $ +# $DragonFly: src/etc/network.subr,v 1.5 2007/07/10 22:36:01 swildner Exp $ # # @@ -35,16 +35,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 @@ -56,7 +70,7 @@ ifconfig_down() { [ -z "$1" ] && return 1 _ifs="^" - _ret=1 + _cfg=1 inetList="`ifconfig $1 | grep 'inet ' | tr "\n" "$_ifs"`" @@ -71,11 +85,100 @@ ifconfig_down() IFS="$oldifs" ifconfig $1 ${_inet} delete IFS="$_ifs" - _ret=0 + _cfg=0 done IFS="$oldifs" - return $_ret + 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 $_cfg +} + +# _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 @@ -251,6 +354,23 @@ ipx_down() return $_ret } +# ifnet_rename +# Rename all requested interfaces. +# +ifnet_rename() +{ + + _ifn_list="`ifconfig -l`" + [ -z "$_ifn_list" ] && return 0 + for _if in ${_ifn_list} ; do + eval _ifname=\$ifconfig_${_if}_name + if [ ! -z "$_ifname" ]; then + ifconfig $_if name $_ifname + fi + done + return 0 +} + # # list_net_interfaces type # List all network interfaces. The type of interface returned @@ -285,7 +405,7 @@ list_net_interfaces() return 0 fi - # Separate out dhcp and non-dhcp intefraces + # Separate out dhcp and non-dhcp interfaces # _aprefix= _bprefix= diff --git a/etc/rc.d/Makefile b/etc/rc.d/Makefile index 1701d4f89a..053780c1d4 100644 --- a/etc/rc.d/Makefile +++ b/etc/rc.d/Makefile @@ -1,6 +1,6 @@ # $NetBSD: Makefile,v 1.16 2001/01/14 15:37:22 minoura Exp $ # $FreeBSD: src/etc/rc.d/Makefile,v 1.20 2003/06/29 05:15:57 mtm Exp $ -# $DragonFly: src/etc/rc.d/Makefile,v 1.20 2007/07/04 16:28:45 swildner Exp $ +# $DragonFly: src/etc/rc.d/Makefile,v 1.21 2007/07/10 22:36:01 swildner Exp $ .include @@ -23,8 +23,8 @@ FILES= DAEMON LOGIN NETWORKING SERVERS abi accounting addswap adjkerntz \ quota random rarpd rcconf.sh resident rndcontrol root route6d routed \ routing rpcbind rtadvd rtsold rwho sysdb savecore securelevel sendmail \ serial sppp sshd swap1 syscons sysctl syslogd timed ttys usbd \ - vinum virecover watchdogd ypbind yppasswdd ypserv ypset ypupdated \ - ypxfrd varsym + varsym vinum virecover watchdogd wpa_supplicant \ + ypbind yppasswdd ypserv ypset ypupdated ypxfrd FILESDIR= /etc/rc.d FILESMODE= ${BINMODE} diff --git a/etc/rc.d/dhclient b/etc/rc.d/dhclient index 931465456a..967914e06c 100644 --- a/etc/rc.d/dhclient +++ b/etc/rc.d/dhclient @@ -1,107 +1,63 @@ #!/bin/sh # # $NetBSD: dhclient,v 1.8 2002/03/22 04:33:58 thorpej Exp $ -# $FreeBSD: src/etc/rc.d/dhclient,v 1.6 2003/06/29 05:34:41 mtm Exp $ -# $DragonFly: src/etc/rc.d/dhclient,v 1.9 2007/06/17 14:08:00 swildner Exp $ +# $FreeBSD: src/etc/rc.d/dhclient,v 1.20.2.4 2007/03/10 14:07:01 yar Exp $ +# $DragonFly: src/etc/rc.d/dhclient,v 1.10 2007/07/10 22:36:01 swildner Exp $ # # PROVIDE: dhclient -# REQUIRE: netif mountcritlocal -# BEFORE: NETWORKING -# -# Note that there no syslog logging of dhclient messages at boot because -# dhclient needs to start before services that syslog depends upon do. +# KEYWORD: nojail nostart # . /etc/rc.subr . /etc/network.subr name="dhclient" -pidfile="/var/run/${name}.pid" - rcvar= - start_precmd="dhclient_prestart" - start_postcmd="dhclient_poststart" - stop_cmd="dhclient_stop" - stop_precmd="dhclient_prestop" - stop_postcmd="dhclient_poststop" - +rcvar= +start_cmd="dhclient_start" +stop_cmd="dhclient_stop" -dhclient_common() +dhclient_start() { - dhcp_list="`list_net_interfaces dhcp`" - if [ -z "$dhcp_list" ]; then - return $RC_IRRELEVANT - fi - - # Determine the scope of the command - # - _cooked_list="$dhcp_list" - if [ -n "$_cmdifn" ]; then - eval _cooked_list=\"`expr "$dhcp_list" : ".*\($_cmdifn\).*"`\" - if [ -z "$_cooked_list" ]; then - err 1 "No such network interface: $_cmdifn" + # prevent unnecessary restarts + # XXX: dhclient had better create a pidfile + if [ -x /bin/pgrep ]; then + pids=`/bin/pgrep -f "dhclient: $ifn(\$| .*)"` + if [ -n "$pids" ]; then + exit 0 fi fi -} -dhclient_prestart() -{ - dhclient_common || return $? + # Override for $ifn specific flags (see rc.subr for $flags setting) + eval specific=\$dhclient_flags_$ifn + if [ -z "$flags" -a -n "$specific" ]; then + rc_flags=$specific + fi - for ifn in ${_cooked_list}; do - ifscript_up ${ifn} - done +# eval specific=\$background_dhclient_$ifn +# if [ -n "$specific" ]; then +# if checkyesno background_dhclient_$ifn; then +# rc_flags="${rc_flags} -b" +# fi +# elif checkyesno background_dhclient; then +# rc_flags="${rc_flags} -b" +# fi - rc_flags="${rc_flags} ${_cooked_list}" - return 0 -} - -dhclient_poststart() -{ - for ifn in ${_cooked_list}; do - ifalias_up ${ifn} - ipx_up ${ifn} - ifconfig ${ifn} - done + ${dhclient_program} ${rc_flags} $ifn } dhclient_stop() { - echo -n "Releasing DHCP leases:" - for ifn in $_cooked_list ; do - ${command} -r $ifn - if [ $? -eq 0 ]; then - echo -n " $ifn" - else - _fail="$_fail $ifn" - fi - done - echo '.' - debug "The following leases failed to release: $_fail" + ifconfig $ifn down # cause dhclient to die } -dhclient_prestop() -{ - dhclient_common || return $? +ifn="$2" - for ifn in ${_cooked_list}; do - ipx_down ${ifn} - ifalias_down ${ifn} - done - return 0 -} - -dhclient_poststop() -{ - for ifn in ${_cooked_list}; do - ifscript_down ${ifn} - done -} +load_rc_config $name +load_rc_config network -if [ -n "$2" ]; then - _cmdifn="$2" +if ! dhcpif $ifn; then + return 1 fi -load_rc_config $name - run_rc_command "$1" diff --git a/etc/rc.d/netif b/etc/rc.d/netif index 8fdff43e5f..a14ee1739e 100644 --- a/etc/rc.d/netif +++ b/etc/rc.d/netif @@ -23,7 +23,7 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # $FreeBSD: src/etc/rc.d/netif,v 1.2 2003/06/29 05:34:41 mtm Exp $ -# $DragonFly: src/etc/rc.d/netif,v 1.6 2007/06/17 14:08:00 swildner Exp $ +# $DragonFly: src/etc/rc.d/netif,v 1.7 2007/07/10 22:36:01 swildner Exp $ # # PROVIDE: netif @@ -42,6 +42,10 @@ _cmdifn= network_start() { + # Set the list of interfaces to work on. + # + _cmdifn=$* + if [ -z "$_cmdifn" ]; then # # We're operating as a general network start routine. @@ -52,6 +56,9 @@ network_start() # Create IPv6<-->IPv4 tunnels gif_up + + # Rename interfaces. + ifnet_rename fi # Configure the interface(s). @@ -68,6 +75,10 @@ network_start() network_stop() { + # Set the list of interfaces to work on. + # + _cmdifn=$* + echo -n "Stopping network:" # Deconfigure the interface(s) @@ -94,17 +105,22 @@ network_common() fi [ -n "$2" ] && _verbose=yes - # Get a list of network interfaces. Do not include dhcp interfaces. - _ifn_list="`list_net_interfaces nodhcp`" + # Get a list of network interfaces. + _ifn_list="`list_net_interfaces`" # Set the scope of the command (all interfaces or just one). # - _cooked_list="$_ifn_list" + _cooked_list= if [ -n "$_cmdifn" ]; then - eval _cooked_list=\"`expr "$_ifn_list" : ".*\($_cmdifn\).*"`\" - if [ -z "$_cooked_list" ]; then - err 1 "No such network interface: $_cmdifn" - fi + for i in $_cmdifn ; do + eval _if=\"`expr "$_ifn_list" : ".*\(${i}\).*"`\" + if [ -z "$_if" ]; then + err 1 "No such network interface: $i" + fi + _cooked_list="$_cooked_list $_if" + done + else + _cooked_list="$_ifn_list" fi for ifn in ${_cooked_list}; do @@ -162,9 +178,5 @@ ifn_stop() return $cfg } -if [ -n "$2" ]; then - _cmdifn="$2" -fi - load_rc_config $name -run_rc_command "$1" +run_rc_command $* diff --git a/etc/rc.d/wpa_supplicant b/etc/rc.d/wpa_supplicant new file mode 100644 index 0000000000..f670213ad3 --- /dev/null +++ b/etc/rc.d/wpa_supplicant @@ -0,0 +1,39 @@ +#!/bin/sh +# +# $FreeBSD: src/etc/rc.d/wpa_supplicant,v 1.2 2005/10/19 22:26:47 jkim Exp $ +# $DragonFly: src/etc/rc.d/wpa_supplicant,v 1.1 2007/07/10 22:36:01 swildner Exp $ +# + +# PROVIDE: wpa_supplicant +# REQUIRE: mountcritremote +# KEYWORD: nojail nostart + +. /etc/rc.subr +. /etc/network.subr + +name="wpa_supplicant" +rcvar= +command="/usr/sbin/${name}" +conf_file="/etc/wpa_supplicant.conf" + +ifn="$2" +if [ -z "$ifn" ]; then + return 1 +fi + +case ${ifn} in +ndis*) + driver="ndis" + ;; +*) + driver="bsd" + ;; +esac + +load_rc_config $name + +pid_file="/var/run/${name}/${ifn}.pid" +command_args="-B -q -i $ifn -c $conf_file -D $driver -P $pid_file" +required_files=$conf_file + +run_rc_command "$1" diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index 12585f7bff..64906428e3 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -23,8 +23,8 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD: src/share/man/man5/rc.conf.5,v 1.197 2003/07/28 13:56:00 mbr Exp $ -.\" $DragonFly: src/share/man/man5/rc.conf.5,v 1.41 2007/07/04 16:28:45 swildner Exp $ -.Dd July 4, 2007 +.\" $DragonFly: src/share/man/man5/rc.conf.5,v 1.42 2007/07/10 22:36:01 swildner Exp $ +.Dd July 10, 2007 .Dt RC.CONF 5 .Os .Sh NAME @@ -200,13 +200,13 @@ Additional flags to pass to the DHCP client program. For the ISC DHCP client, see the .Xr dhclient 8 manpage for a description of the command line options available. -.It Va background_dhclient -.Pq Vt bool -Set to -.Dq Li YES -to start the DHCP client in background. -This can cause trouble with applications depending on -a working network, but it will provide a faster startup in many cases. +.\".It Va background_dhclient +.\".Pq Vt bool +.\"Set to +.\".Dq Li YES +.\"to start the DHCP client in background. +.\"This can cause trouble with applications depending on +.\"a working network, but it will provide a faster startup in many cases. .It Va dhcpd_enable .Pq Vt bool Set to @@ -813,16 +813,42 @@ and .Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n variables. .Pp -It is possible to bring up an interface with DHCP by setting the +It is possible to bring up an interface with DHCP by adding +.Dq Li DHCP +to the .Va ifconfig_ Ns Aq Ar interface -variable to -.Dq Li DHCP . +variable. For instance, to initialize the .Li ed0 device via DHCP, it is possible to use something like: .Bd -literal ifconfig_ed0="DHCP" .Ed +.Pp +Also, if your interface needs WPA authentication, it is possible to add +.Dq Li WPA +to the +.Va ifconfig_ Ns Aq Ar interface +variable. +.Pp +Finally, you can add +.Xr ifconfig 8 +options in this variable, in addition to the +.Pa /etc/start_if. Ns Aq Ar interface +file. +For instance, to initialize the +.Li wi0 +device via DHCP, using WPA authentication and 802.11b mode, it is +possible to use something like: +.Bd -literal +ifconfig_wi0="up DHCP WPA mode 11b" +.Ed +.Pp +It is also possible to rename interface by doing: +.Bd -literal +ifconfig_ed0_name="net0" +ifconfig_net0="inet 10.0.0.1 netmask 0xffff0000" +.Ed .It Va ipv6_network_interfaces .Pq Vt str This is the IPv6 equivalent of