From ada90a5b2c4a609a9b698d98b0173b8ee03c34c4 Mon Sep 17 00:00:00 2001 From: stsp Date: Mon, 7 Mar 2022 08:13:13 +0000 Subject: [PATCH] rename net80211 ioctl struct ieee80211_channel to struct ieee80211_chaninfo ioctls should use dedicated names for their structs, but SIOCG80211ALLCHANS duplicated struct ieee80211_channel. We cannot make changes to the kernel's version of ieee80211_channel while an ioctl is squatting on the struct name. Helpful guidance from deraadt@ Tested in a ports bulk build by sthen@, and tested by Mikhail. ok sthen@ --- sbin/ifconfig/ifconfig.c | 14 +++++++++----- sys/net80211/ieee80211_ioctl.c | 23 +++++++++++++++++++---- sys/net80211/ieee80211_ioctl.h | 21 +++++++-------------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 8ee7b194d0b..0ef67c56edd 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.452 2022/02/22 09:55:54 dlg Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.453 2022/03/07 08:13:13 stsp Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -116,6 +116,10 @@ #include "ifconfig.h" +#ifndef nitems +#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) +#endif + #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) @@ -2670,7 +2674,7 @@ join_status(void) void ieee80211_listchans(void) { - static struct ieee80211_channel chans[256+1]; + static struct ieee80211_chaninfo chans[256]; struct ieee80211_chanreq_all ca; int i; @@ -2684,11 +2688,11 @@ ieee80211_listchans(void) return; } printf("\t\t%4s %-8s %s\n", "chan", "freq", "properties"); - for (i = 1; i <= 256; i++) { - if (chans[i].ic_flags == 0) + for (i = 1; i < nitems(chans); i++) { + if (chans[i].ic_freq == 0) continue; printf("\t\t%4d %4d MHz ", i, chans[i].ic_freq); - if (chans[i].ic_flags & IEEE80211_CHAN_PASSIVE) + if (chans[i].ic_flags & IEEE80211_CHANINFO_PASSIVE) printf("passive scan"); else putchar('-'); diff --git a/sys/net80211/ieee80211_ioctl.c b/sys/net80211/ieee80211_ioctl.c index e3da39394d2..85d795d745e 100644 --- a/sys/net80211/ieee80211_ioctl.c +++ b/sys/net80211/ieee80211_ioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_ioctl.c,v 1.80 2020/11/19 20:03:33 krw Exp $ */ +/* $OpenBSD: ieee80211_ioctl.c,v 1.81 2022/03/07 08:13:13 stsp Exp $ */ /* $NetBSD: ieee80211_ioctl.c,v 1.15 2004/05/06 02:58:16 dyoung Exp $ */ /*- @@ -469,6 +469,8 @@ ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) struct ieee80211_nodereq *nr, nrbuf; struct ieee80211_nodereq_all *na; struct ieee80211_node *ni; + struct ieee80211_chaninfo chaninfo; + struct ieee80211_chanreq_all *allchans; u_int32_t flags; switch (cmd) { @@ -791,9 +793,22 @@ ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) chanreq->i_channel = ieee80211_chan2ieee(ic, chan); break; case SIOCG80211ALLCHANS: - error = copyout(ic->ic_channels, - ((struct ieee80211_chanreq_all *)data)->i_chans, - sizeof(ic->ic_channels)); + allchans = (struct ieee80211_chanreq_all *)data; + for (i = 0; i <= IEEE80211_CHAN_MAX; i++) { + chan = &ic->ic_channels[i]; + chaninfo.ic_freq = chan->ic_freq; + chaninfo.ic_flags = 0; + if (chan->ic_flags & IEEE80211_CHAN_2GHZ) + chaninfo.ic_flags |= IEEE80211_CHANINFO_2GHZ; + if (chan->ic_flags & IEEE80211_CHAN_5GHZ) + chaninfo.ic_flags |= IEEE80211_CHANINFO_5GHZ; + if (chan->ic_flags & IEEE80211_CHAN_PASSIVE) + chaninfo.ic_flags |= IEEE80211_CHANINFO_PASSIVE; + error = copyout(&chaninfo, &allchans->i_chans[i], + sizeof(chaninfo)); + if (error) + break; + } break; #if 0 case SIOCG80211ZSTATS: diff --git a/sys/net80211/ieee80211_ioctl.h b/sys/net80211/ieee80211_ioctl.h index 20647ca5ee9..65e93c23da2 100644 --- a/sys/net80211/ieee80211_ioctl.h +++ b/sys/net80211/ieee80211_ioctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_ioctl.h,v 1.41 2020/10/06 07:23:15 gerhard Exp $ */ +/* $OpenBSD: ieee80211_ioctl.h,v 1.42 2022/03/07 08:13:13 stsp Exp $ */ /* $NetBSD: ieee80211_ioctl.h,v 1.7 2004/04/30 22:51:04 dyoung Exp $ */ /*- @@ -161,31 +161,24 @@ struct ieee80211chanreq { u_int16_t i_channel; }; -#ifndef _KERNEL /* * Channels are specified by frequency and attributes. */ -struct ieee80211_channel { +struct ieee80211_chaninfo { u_int16_t ic_freq; /* setting in MHz */ u_int16_t ic_flags; /* see below */ }; /* - * Channel attributes (XXX must keep in sync with radiotap flags). + * Channel attributes. */ -#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ -#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ -#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel */ -#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ -#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ -#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ -#define IEEE80211_CHAN_XR 0x1000 /* Extended range OFDM channel */ -#define IEEE80211_CHAN_HT 0x2000 /* 11n/HT channel */ -#endif /* !_KERNEL */ +#define IEEE80211_CHANINFO_2GHZ 0x0080 /* 2 GHz spectrum channel */ +#define IEEE80211_CHANINFO_5GHZ 0x0100 /* 5 GHz spectrum channel */ +#define IEEE80211_CHANINFO_PASSIVE 0x0200 /* Only passive scan allowed */ struct ieee80211_chanreq_all { char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ - struct ieee80211_channel *i_chans; + struct ieee80211_chaninfo *i_chans; /* array of 256 elements */ }; #ifndef IEEE80211_CHAN_ANY -- 2.20.1