Date: Wed, 6 Nov 2013 11:59:14 -0500 From: John Baldwin <jhb@freebsd.org> To: freebsd-arch@freebsd.org Cc: clutton <clutton@zoho.com>, Bernhard Schmidt <bschmidt@techwires.net>, "freebsd-wireless@freebsd.org" <freebsd-wireless@freebsd.org> Subject: Re: service netif restart [iface] runs a wpa_supplicant twice Message-ID: <201311061159.14824.jhb@freebsd.org> In-Reply-To: <201311051717.30519.jhb@freebsd.org> References: <1382572583.1862.39.camel@eva02.mbsd> <CAAgh0_aFdJTYVvgczt=wvKdUFR90hLiVS%2BFRbXZyvrVVpWvbYA@mail.gmail.com> <201311051717.30519.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, November 05, 2013 5:17:30 pm John Baldwin wrote: > On Tuesday, November 05, 2013 2:33:50 pm Bernhard Schmidt wrote: > > On Tue, Nov 5, 2013 at 5:54 PM, John Baldwin <jhb@freebsd.org> wrote: > > > On Sunday, November 03, 2013 12:56:08 pm Adrian Chadd wrote: > > >> On 2 November 2013 12:13, clutton <clutton@zoho.com> wrote: > > >> > > >> [snip] > > >> > > >> > What was happened? netif tries to setup wlan0 (clone, wpa, dhcp, etc), > > >> > when wlan0 interface occurs, devd runs another copy of netif. > > >> > > >> Well, it sounds like we need to pick an architecture _and_ fix the > > >> behaviour here. > > >> > > >> Which is: > > >> > > >> > > >> * I think wpa-supplicant should always run if it's required in /etc/rc.conf; > > >> * netif should check if devd is configured and if so, just leave the > > >> configuration up to devd > > >> * if it isn't running, then devd should be responsible for > > >> dhclient/add-to-wpa-config > > >> > > >> What we first have to establish is whether add_interface and > > >> remove_interface (or whatever they're called) are correctly working, > > >> for ethernet and wifi driver types. Then, we need to ensure they can > > >> coexist (ie, one wpa_supplicant, but with both ethernet/wifi drivers > > >> loaded and active on their relevant interfaces.) _then_ we can break > > >> out the "stuff devd does" out of netif and have _either_ netif (x)or > > >> devd call this new script to setup/teardown the interface runtime > > >> state. > > >> > > >> How's that sound? > > > > > > Note that devd just runs netif (via /etc/pccard_ether), so it's already > > > just one script, and having netif bail if devd is running would make > > > netif not do anything in the common case. > > > > > > What normally happens during boot is that '/etc/rc.d/netif start' creates > > > wlan0 and runs wpa_supplicant via 'childif_create' making a nested call to > > > ifn_start for wlan0. That is, childif_create autoruns /etc/rc.d/netif > > > explicitly after it creates the device. Probably that is what should be > > > removed. That would let devd always start wpa_supplicant via > > > /etc/pccard_ether. I've just tested this by doing a stop/start on iwn0 > > > (parent of wlan0, so wlan0 gets destroyed and re-created) and it started > > > wpa_supplicant correctly. > > > > > > Index: head/etc/network.subr > > > =================================================================== > > > --- network.subr (revision 257705) > > > +++ network.subr (working copy) > > > @@ -1429,9 +1429,6 @@ childif_create() > > > fi > > > ${IFCONFIG_CMD} $i name $child && cfg=0 > > > fi > > > - if autoif $child; then > > > - ifn_start $child > > > - fi > > > done > > > > > > # Create vlan interfaces > > > > > > I also tested vlans created via vlans_<if> and they should use the same fix as > > > well. Note that this model is more consistent with how cloned_interfaces > > > works where ifn_start is not explicitly run when each interface is created. > > > Instead, we rely on devd kicking off pccard_ether for those as well. > > > > That looks sane too me. > > > > Just one question, I remember that devd is disabled during boot and > > activated later through a sysctl (to ignore events entirely), is this > > the case before or after netif is running? I guess it is activated > > after netif, otherwise we would have seen this issue on booting and > > not just during netif restart. > > Hmm, devd starts after netif, but it just worked fine for me when I booted up. > I also misspoke about cloned_interfaces. We manually add the cloned_interface > list to the list of interfaces /etc/rc.d/netif iterates over. What I am > puzzled by is that this just worked for me during a test boot. Hmm, it looks like > devctl is no longer disabled during boot and then explicitly enabled by devd. > devctl is now always enabled during boot, but capped at 1000 entries to avoid > leaking memory. In fact, it looks like devd tries to recreate a few interfaces > after netif finishes and is generally confused. I tried again with devd_flags > set to "-n" to flush the initial set of events on boot. This removed the > multiple calls to netif on boot on my laptop, but somehow wpa_supplicant is > still being started by devd (and I'm not sure how now). I've hacked devd some more and can now see what is going on. -n doesn't do what I thought it does. It does not throw away pending events on startup, it just makes devd not fork until it has walked the initial set of events. The kernel changed (a while ago) to queue the first 1000 events until devd starts up. This means that in practice devd gets arrival events for all devices in the system as soon as it starts up and triggers duplicate invocations of netif after netif finishes. However, /etc/pccard_ether ignores attempts to start a device that is already up, so this should be a no-op on bootup (if my change is reverted) as the interfaces should already be configured by the time devd starts. I suspect what happens in multiuser is that devd fires off pccard_ether and sees that the interface isn't up before the original netif has a chance to invoke the nested ifn_start. We could perhaps change it so we only invoke ifn_start if devd isn't running. One other thought: I restart my wireless interfaces by doing 'sh /etc/rc.d/netif restart wlan0', not 'iwn0'. This doesn't teardown/recreate the wlan0 device, so it doesn't suffer from the issue reported by the OP. Here is a change I've tested that seems to do the right thing both at boot time and doing a restart of either iwn0 or wlan0 at runtime. If devd is running it leaves the task of starting an interface up to devd, otherwise (such as during boot), it configures the new child interface synchronously. Note that pgrep is in /bin. Index: network.subr =================================================================== --- network.subr (revision 257747) +++ network.subr (working copy) @@ -1406,10 +1406,14 @@ clone_down() # childif_create() { - local cfg child child_vlans child_wlans create_args debug_flags ifn i + local cfg child child_vlans child_wlans create_args debug_flags devd \ + ifn i cfg=1 ifn=$1 + # Check if devd is running + devd=$(pgrep devd) + # Create wireless interfaces child_wlans=`get_if_var $ifn wlans_IF` @@ -1429,6 +1433,9 @@ childif_create() fi ${IFCONFIG_CMD} $i name $child && cfg=0 fi + if [ -z "$devd" ] && autoif $child; then + ifn_start $child + fi done # Create vlan interfaces @@ -1452,6 +1459,9 @@ childif_create() ${IFCONFIG_CMD} $i name $child && cfg=0 fi fi + if [ -z "$devd" ] && autoif $child; then + ifn_start $child + fi done return ${cfg} -- John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201311061159.14824.jhb>