Re: net80211: stub SIOCS80211SCAN, make ifconfig scan instant

2018-04-26 Thread Klemens Nanni
On Wed, Apr 25, 2018 at 08:02:01PM +0200, Stefan Sperling wrote:
> On Wed, Apr 25, 2018 at 08:55:26PM +0300, Paul Irofti wrote:
> > Currently tested on iwm(4), urtwn(4), run(4) and athn(4). We are
> > interested in wider testing, specially on iwn(4) and athn(4) in client
> > mode.
> 
> To clarify, we tested athn(4) on USB. We are still looking for
> a test with athn(4) on PCI.
Works fine on my X230 with

athn0 at pci2 dev 0 function 0 "Atheros AR9281" rev 0x01: apic 2 int 17

I can see the list changing on successive `ifconfig wlan scan' runs
which do not block anymore, thanks!



Re: net80211: stub SIOCS80211SCAN, make ifconfig scan instant

2018-04-26 Thread Landry Breuil
On Wed, Apr 25, 2018 at 09:14:42PM +0300, Paul Irofti wrote:
> On Wed, Apr 25, 2018 at 08:55:26PM +0300, Paul Irofti wrote:
> > Hi,
> > 
> > The following diff removes the functionality of the SIOCS80211SCAN ioctl.
> > After long discussions with stps@, mpi@, and deraadt@ we decided that
> > this was the correct way of fixing ifconfig scan from blocking the
> > network stack.
> > 
> > The kernel will continue scanning in the background and filling the
> > nodes array, but ifconfig scan commands will now basically do just a
> > SIOCG80211ALLNODES and pretty print the array. So the output stays the
> > same but is instant.
> > 
> > In fact, when the interface is freshly brought up, if you type fast
> > enough, you can see the array being filled by running multiple ifconfig
> > scans in sequence.
> > 
> > Another change that this introduces is the fact that ifconfig scan no
> > longer plays with UP and DOWN. If the interface is down it complains and
> > exits. This is needed in order to maintain the nodes list.
> > 
> > Currently tested on iwm(4), urtwn(4), run(4) and athn(4). We are
> > interested in wider testing, specially on iwn(4) and athn(4) in client
> > mode.
> > 
> > Thoughts? OKs?
> > 
> > Paul
> 
> Updated diff that fixes scan on hostap mode. This removes the hostap
> check from SIOCG80211ALLNODES that I added by mistake.

Works as advertised on x200s w/
iwn0 at pci2 dev 0 function 0 "Intel WiFi Link 5100" rev 0x00: msi, MIMO 1T2R, 
MoW



Re: net80211: stub SIOCS80211SCAN, make ifconfig scan instant

2018-04-25 Thread Florian Obser
On Wed, Apr 25, 2018 at 09:14:42PM +0300, Paul Irofti wrote:
> On Wed, Apr 25, 2018 at 08:55:26PM +0300, Paul Irofti wrote:
> > Hi,
> > 
> > The following diff removes the functionality of the SIOCS80211SCAN ioctl.
> > After long discussions with stps@, mpi@, and deraadt@ we decided that
> > this was the correct way of fixing ifconfig scan from blocking the
> > network stack.
> > 
> > The kernel will continue scanning in the background and filling the
> > nodes array, but ifconfig scan commands will now basically do just a
> > SIOCG80211ALLNODES and pretty print the array. So the output stays the
> > same but is instant.
> > 
> > In fact, when the interface is freshly brought up, if you type fast
> > enough, you can see the array being filled by running multiple ifconfig
> > scans in sequence.
> > 
> > Another change that this introduces is the fact that ifconfig scan no
> > longer plays with UP and DOWN. If the interface is down it complains and
> > exits. This is needed in order to maintain the nodes list.
> > 
> > Currently tested on iwm(4), urtwn(4), run(4) and athn(4). We are
> > interested in wider testing, specially on iwn(4) and athn(4) in client
> > mode.
> > 
> > Thoughts? OKs?
> > 
> > Paul
> 
> Updated diff that fixes scan on hostap mode. This removes the hostap
> check from SIOCG80211ALLNODES that I added by mistake.

neat!

works very nicely on my X201 with

iwn0 at pci3 dev 0 function 0 "Intel Centrino Ultimate-N 6300" rev 0x35: msi, 
MIMO 3T3R, MoW, address 00:24:d7:86:d7:e8


OpenBSD 6.3-current (GENERIC.MP) #2: Wed Apr 25 20:17:06 CEST 2018

flor...@openbsd-build.home.narrans.de:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8357658624 (7970MB)
avail mem = 8096481280 (7721MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.6 @ 0xe0010 (78 entries)
bios0: vendor LENOVO version "6QET61WW (1.31 )" date 10/26/2010
bios0: LENOVO 3680K84
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SSDT ECDT APIC MCFG HPET ASF! SLIC BOOT SSDT TCPA DMAR 
SSDT SSDT SSDT
acpi0: wakeup devices LID_(S3) SLPB(S3) IGBE(S4) EXP1(S4) EXP2(S4) EXP3(S4) 
EXP4(S4) EXP5(S4) EHC1(S3) EHC2(S3) HDEF(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpiec0 at acpi0
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz, 1197.24 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,AES,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
cpu0: apic clock running at 133MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz, 1197.00 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,AES,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 4 (application processor)
cpu2: Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz, 1197.00 MHz
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,AES,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT,MELTDOWN
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 2, package 0
cpu3 at mainbus0: apid 5 (application processor)
cpu3: Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz, 1197.00 MHz
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,AES,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,SENSOR,ARAT,MELTDOWN
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 2, package 0
ioapic0 at mainbus0: apid 1 pa 0xfec0, version 20, 24 pins
, remapped to apid 1
acpimcfg0 at acpi0 addr 0xe000, bus 0-255
acpihpet0 at acpi0: 14318179 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PEG_)
acpiprt2 at acpi0: bus 13 (EXP1)
acpiprt3 at acpi0: bus -1 (EXP2)
acpiprt4 at acpi0: bus -1 (EXP3)
acpiprt5 at acpi0: bus 5 (EXP4)
acpiprt6 at acpi0: bus 2 (EXP5)
acpicpu0 at acpi0: C3(350@245 mwait.3@0x20), C2(500@205 mwait.3@0x10), 
C1(1000@3 mwait.1), PSS
acpicpu1 at acpi0: C3(350@245 mwait.3@0x20), C2(500@205 mwait.3@0x10), 
C1(1000@3 mwait.1), PSS
acpicpu2 at acpi0: C3(350@245 mwait.3@0x20), C2(500@205 mwait.3@0x10), 
C1(1000@3 mwait.1), PSS
acpicpu3 at acpi0: C3(350@245 mwait.3@0x20), 

Re: net80211: stub SIOCS80211SCAN, make ifconfig scan instant

2018-04-25 Thread Paul Irofti
On Wed, Apr 25, 2018 at 08:55:26PM +0300, Paul Irofti wrote:
> Hi,
> 
> The following diff removes the functionality of the SIOCS80211SCAN ioctl.
> After long discussions with stps@, mpi@, and deraadt@ we decided that
> this was the correct way of fixing ifconfig scan from blocking the
> network stack.
> 
> The kernel will continue scanning in the background and filling the
> nodes array, but ifconfig scan commands will now basically do just a
> SIOCG80211ALLNODES and pretty print the array. So the output stays the
> same but is instant.
> 
> In fact, when the interface is freshly brought up, if you type fast
> enough, you can see the array being filled by running multiple ifconfig
> scans in sequence.
> 
> Another change that this introduces is the fact that ifconfig scan no
> longer plays with UP and DOWN. If the interface is down it complains and
> exits. This is needed in order to maintain the nodes list.
> 
> Currently tested on iwm(4), urtwn(4), run(4) and athn(4). We are
> interested in wider testing, specially on iwn(4) and athn(4) in client
> mode.
> 
> Thoughts? OKs?
> 
> Paul

Updated diff that fixes scan on hostap mode. This removes the hostap
check from SIOCG80211ALLNODES that I added by mistake.


diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index 993a1ed32c8..5643c1f0219 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -2255,11 +2255,11 @@ ieee80211_listnodes(void)
struct ieee80211_nodereq_all na;
struct ieee80211_nodereq nr[512];
struct ifreq ifr;
-   int i, down = 0;
+   int i;
 
if ((flags & IFF_UP) == 0) {
-   down = 1;
-   setifflags("up", IFF_UP);
+   printf("\t\tcan not scan, interface is down\n");
+   return;
}
 
bzero(, sizeof(ifr));
@@ -2268,7 +2268,7 @@ ieee80211_listnodes(void)
if (ioctl(s, SIOCS80211SCAN, (caddr_t)) != 0) {
if (errno == EPERM)
printf("\t\tno permission to scan\n");
-   goto done;
+   return;
}
 
bzero(, sizeof(na));
@@ -2279,7 +2279,7 @@ ieee80211_listnodes(void)
 
if (ioctl(s, SIOCG80211ALLNODES, ) != 0) {
warn("SIOCG80211ALLNODES");
-   goto done;
+   return;
}
 
if (!na.na_nodes)
@@ -2292,10 +2292,6 @@ ieee80211_listnodes(void)
ieee80211_printnode([i]);
putchar('\n');
}
-
- done:
-   if (down)
-   setifflags("restore", -IFF_UP);
 }
 
 void
diff --git sys/dev/ic/athn.c sys/dev/ic/athn.c
index 54f1e668f7d..0830049a401 100644
--- sys/dev/ic/athn.c
+++ sys/dev/ic/athn.c
@@ -2917,8 +2917,6 @@ athn_stop(struct ifnet *ifp, int disable)
ifq_clr_oactive(>if_snd);
 
timeout_del(>scan_to);
-   /* In case we were scanning, release the scan "lock". */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
 
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 
diff --git sys/dev/ic/bwfm.c sys/dev/ic/bwfm.c
index 8a2f1beaddd..b05427cc0b9 100644
--- sys/dev/ic/bwfm.c
+++ sys/dev/ic/bwfm.c
@@ -463,9 +463,6 @@ bwfm_stop(struct ifnet *ifp)
ifp->if_flags &= ~IFF_RUNNING;
ifq_clr_oactive(>if_snd);
 
-   /* In case we were scanning, release the scan "lock". */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
-
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 
bwfm_fwvar_cmd_set_int(sc, BWFM_C_DOWN, 1);
diff --git sys/dev/pci/if_ipw.c sys/dev/pci/if_ipw.c
index 57532466efd..a519af322ec 100644
--- sys/dev/pci/if_ipw.c
+++ sys/dev/pci/if_ipw.c
@@ -2024,9 +2024,6 @@ ipw_stop(struct ifnet *ifp, int disable)
for (i = 0; i < IPW_NTBD; i++)
ipw_release_sbd(sc, >stbd_list[i]);
 
-   /* in case we were scanning, release the scan "lock" */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
-
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 }
 
diff --git sys/dev/pci/if_iwi.c sys/dev/pci/if_iwi.c
index f60f911..c3801f008df 100644
--- sys/dev/pci/if_iwi.c
+++ sys/dev/pci/if_iwi.c
@@ -2291,9 +2291,6 @@ iwi_stop(struct ifnet *ifp, int disable)
ifp->if_flags &= ~IFF_RUNNING;
ifq_clr_oactive(>if_snd);
 
-   /* in case we were scanning, release the scan "lock" */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
-
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 
iwi_stop_master(sc);
diff --git sys/dev/pci/if_iwm.c sys/dev/pci/if_iwm.c
index fa3c1c82cc8..5a526802010 100644
--- sys/dev/pci/if_iwm.c
+++ sys/dev/pci/if_iwm.c
@@ -6708,9 +6708,6 @@ iwm_stop(struct ifnet *ifp)
sc->sc_cmd_resp_pkt[i] = NULL;
sc->sc_cmd_resp_len[i] = 0;
}
-   if (ic->ic_scan_lock & IEEE80211_SCAN_REQUEST)
-   wakeup(>ic_scan_lock);
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
ifp->if_flags &= ~IFF_RUNNING;
ifq_clr_oactive(>if_snd);
 
diff --git sys/dev/pci/if_iwn.c 

Re: net80211: stub SIOCS80211SCAN, make ifconfig scan instant

2018-04-25 Thread Stefan Sperling
On Wed, Apr 25, 2018 at 08:55:26PM +0300, Paul Irofti wrote:
> Currently tested on iwm(4), urtwn(4), run(4) and athn(4). We are
> interested in wider testing, specially on iwn(4) and athn(4) in client
> mode.

To clarify, we tested athn(4) on USB. We are still looking for
a test with athn(4) on PCI.



net80211: stub SIOCS80211SCAN, make ifconfig scan instant

2018-04-25 Thread Paul Irofti
Hi,

The following diff removes the functionality of the SIOCS80211SCAN ioctl.
After long discussions with stps@, mpi@, and deraadt@ we decided that
this was the correct way of fixing ifconfig scan from blocking the
network stack.

The kernel will continue scanning in the background and filling the
nodes array, but ifconfig scan commands will now basically do just a
SIOCG80211ALLNODES and pretty print the array. So the output stays the
same but is instant.

In fact, when the interface is freshly brought up, if you type fast
enough, you can see the array being filled by running multiple ifconfig
scans in sequence.

Another change that this introduces is the fact that ifconfig scan no
longer plays with UP and DOWN. If the interface is down it complains and
exits. This is needed in order to maintain the nodes list.

Currently tested on iwm(4), urtwn(4), run(4) and athn(4). We are
interested in wider testing, specially on iwn(4) and athn(4) in client
mode.

Thoughts? OKs?

Paul


diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index 993a1ed32c8..5643c1f0219 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -2255,11 +2255,11 @@ ieee80211_listnodes(void)
struct ieee80211_nodereq_all na;
struct ieee80211_nodereq nr[512];
struct ifreq ifr;
-   int i, down = 0;
+   int i;
 
if ((flags & IFF_UP) == 0) {
-   down = 1;
-   setifflags("up", IFF_UP);
+   printf("\t\tcan not scan, interface is down\n");
+   return;
}
 
bzero(, sizeof(ifr));
@@ -2268,7 +2268,7 @@ ieee80211_listnodes(void)
if (ioctl(s, SIOCS80211SCAN, (caddr_t)) != 0) {
if (errno == EPERM)
printf("\t\tno permission to scan\n");
-   goto done;
+   return;
}
 
bzero(, sizeof(na));
@@ -2279,7 +2279,7 @@ ieee80211_listnodes(void)
 
if (ioctl(s, SIOCG80211ALLNODES, ) != 0) {
warn("SIOCG80211ALLNODES");
-   goto done;
+   return;
}
 
if (!na.na_nodes)
@@ -2292,10 +2292,6 @@ ieee80211_listnodes(void)
ieee80211_printnode([i]);
putchar('\n');
}
-
- done:
-   if (down)
-   setifflags("restore", -IFF_UP);
 }
 
 void
diff --git sys/dev/ic/athn.c sys/dev/ic/athn.c
index 54f1e668f7d..0830049a401 100644
--- sys/dev/ic/athn.c
+++ sys/dev/ic/athn.c
@@ -2917,8 +2917,6 @@ athn_stop(struct ifnet *ifp, int disable)
ifq_clr_oactive(>if_snd);
 
timeout_del(>scan_to);
-   /* In case we were scanning, release the scan "lock". */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
 
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 
diff --git sys/dev/ic/bwfm.c sys/dev/ic/bwfm.c
index 8a2f1beaddd..b05427cc0b9 100644
--- sys/dev/ic/bwfm.c
+++ sys/dev/ic/bwfm.c
@@ -463,9 +463,6 @@ bwfm_stop(struct ifnet *ifp)
ifp->if_flags &= ~IFF_RUNNING;
ifq_clr_oactive(>if_snd);
 
-   /* In case we were scanning, release the scan "lock". */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
-
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 
bwfm_fwvar_cmd_set_int(sc, BWFM_C_DOWN, 1);
diff --git sys/dev/pci/if_ipw.c sys/dev/pci/if_ipw.c
index 57532466efd..a519af322ec 100644
--- sys/dev/pci/if_ipw.c
+++ sys/dev/pci/if_ipw.c
@@ -2024,9 +2024,6 @@ ipw_stop(struct ifnet *ifp, int disable)
for (i = 0; i < IPW_NTBD; i++)
ipw_release_sbd(sc, >stbd_list[i]);
 
-   /* in case we were scanning, release the scan "lock" */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
-
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 }
 
diff --git sys/dev/pci/if_iwi.c sys/dev/pci/if_iwi.c
index f60f911..c3801f008df 100644
--- sys/dev/pci/if_iwi.c
+++ sys/dev/pci/if_iwi.c
@@ -2291,9 +2291,6 @@ iwi_stop(struct ifnet *ifp, int disable)
ifp->if_flags &= ~IFF_RUNNING;
ifq_clr_oactive(>if_snd);
 
-   /* in case we were scanning, release the scan "lock" */
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
-
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
 
iwi_stop_master(sc);
diff --git sys/dev/pci/if_iwm.c sys/dev/pci/if_iwm.c
index fa3c1c82cc8..5a526802010 100644
--- sys/dev/pci/if_iwm.c
+++ sys/dev/pci/if_iwm.c
@@ -6708,9 +6708,6 @@ iwm_stop(struct ifnet *ifp)
sc->sc_cmd_resp_pkt[i] = NULL;
sc->sc_cmd_resp_len[i] = 0;
}
-   if (ic->ic_scan_lock & IEEE80211_SCAN_REQUEST)
-   wakeup(>ic_scan_lock);
-   ic->ic_scan_lock = IEEE80211_SCAN_UNLOCKED;
ifp->if_flags &= ~IFF_RUNNING;
ifq_clr_oactive(>if_snd);
 
diff --git sys/dev/pci/if_iwn.c sys/dev/pci/if_iwn.c
index d26fb6a5e64..a839000a2ae 100644
--- sys/dev/pci/if_iwn.c
+++ sys/dev/pci/if_iwn.c
@@ -6633,11 +6633,6 @@ iwn_stop(struct ifnet *ifp, int disable)
ifp->if_flags &= ~IFF_RUNNING;
ifq_clr_oactive(>if_snd);