Module Name: src Committed By: christos Date: Mon Jan 28 21:13:58 UTC 2019
Modified Files: src/sys/compat/common: ieee80211_20.c src/sys/kern: compat_stub.c src/sys/net80211: ieee80211_ioctl.c src/sys/sys: compat_stub.h Log Message: - Don't expose random data conversion functions, but expose the high level entry point (such as ioctl) instead. - Attempt to autoload the module before using it. Naming: Should the names of the hooks be: <category>_<version>_<function>_hook_t or: <category>_<function>_<version>_hook_t We should make those consistent. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/compat/common/ieee80211_20.c cvs rdiff -u -r1.3 -r1.4 src/sys/kern/compat_stub.c cvs rdiff -u -r1.61 -r1.62 src/sys/net80211/ieee80211_ioctl.c cvs rdiff -u -r1.3 -r1.4 src/sys/sys/compat_stub.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/common/ieee80211_20.c diff -u src/sys/compat/common/ieee80211_20.c:1.2 src/sys/compat/common/ieee80211_20.c:1.3 --- src/sys/compat/common/ieee80211_20.c:1.2 Sat Jan 26 21:08:39 2019 +++ src/sys/compat/common/ieee80211_20.c Mon Jan 28 16:13:58 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ieee80211_20.c,v 1.2 2019/01/27 02:08:39 pgoyette Exp $ */ +/* $NetBSD: ieee80211_20.c,v 1.3 2019/01/28 21:13:58 christos Exp $ */ /*- * Copyright (c) 2001 Atsushi Onoe * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting @@ -36,7 +36,7 @@ __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.35 2005/08/30 14:27:47 avatar Exp $"); #endif #ifdef __NetBSD__ -__KERNEL_RCSID(0, "$NetBSD: ieee80211_20.c,v 1.2 2019/01/27 02:08:39 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ieee80211_20.c,v 1.3 2019/01/28 21:13:58 christos Exp $"); #endif /* @@ -72,7 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_20 #include <compat/sys/sockio.h> -static int +static void ieee80211_get_ostats(struct ieee80211_ostats *ostats, struct ieee80211_stats *stats) { @@ -90,20 +90,41 @@ ieee80211_get_ostats(struct ieee80211_os COPYSTATS(ostats, stats, is_rx_deauth, is_rx_unauth); COPYSTATS1(ostats, stats, is_tx_nombuf, is_tx_nobuf, is_tx_badcipher); COPYSTATS(ostats, stats, is_scan_active, is_crypto_tkip); +} - return 0; +static int +ieee80211_20_ioctl(struct ieee80211com *ic, u_long cmd, void *data) +{ + struct ieee80211_ostats ostats; + struct ifreq *ifr; + int s, error; + + switch (cmd) { + case OSIOCG80211STATS: + case OSIOCG80211ZSTATS: + s = splnet(); + ifr = (struct ifreq *)data; + ieee80211_get_ostats(&ostats, &ic->ic_stats); + error = copyout(&ostats, ifr->ifr_data, sizeof(ostats)); + if (error == 0 && cmd == OSIOCG80211ZSTATS) + (void)memset(&ic->ic_stats, 0, sizeof(ic->ic_stats)); + splx(s); + return error; + default: + return EPASSTHROUGH; + } } void ieee80211_20_init(void) { - MODULE_SET_HOOK(ieee80211_ostats_hook, "ieee20", ieee80211_get_ostats); + MODULE_SET_HOOK(ieee80211_20_ioctl_hook, "ieee20", ieee80211_20_ioctl); } void ieee80211_20_fini(void) { - MODULE_UNSET_HOOK(ieee80211_ostats_hook); + MODULE_UNSET_HOOK(ieee80211_20_ioctl_hook); } Index: src/sys/kern/compat_stub.c diff -u src/sys/kern/compat_stub.c:1.3 src/sys/kern/compat_stub.c:1.4 --- src/sys/kern/compat_stub.c:1.3 Mon Jan 28 10:46:49 2019 +++ src/sys/kern/compat_stub.c Mon Jan 28 16:13:58 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: compat_stub.c,v 1.3 2019/01/28 15:46:49 christos Exp $ */ +/* $NetBSD: compat_stub.c,v 1.4 2019/01/28 21:13:58 christos Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -153,7 +153,7 @@ struct compat_vndioctl_50_hook_t compat_ /* * ieee80211 ioctl compatability */ -struct ieee80211_ostats_hook_t ieee80211_ostats_hook; +struct ieee80211_20_ioctl_hook_t ieee80211_20_ioctl_hook; /* * if_43 compatability Index: src/sys/net80211/ieee80211_ioctl.c diff -u src/sys/net80211/ieee80211_ioctl.c:1.61 src/sys/net80211/ieee80211_ioctl.c:1.62 --- src/sys/net80211/ieee80211_ioctl.c:1.61 Sat Jan 26 21:08:48 2019 +++ src/sys/net80211/ieee80211_ioctl.c Mon Jan 28 16:13:58 2019 @@ -36,7 +36,7 @@ __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.35 2005/08/30 14:27:47 avatar Exp $"); #endif #ifdef __NetBSD__ -__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.61 2019/01/27 02:08:48 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.62 2019/01/28 21:13:58 christos Exp $"); #endif /* @@ -56,6 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_io #include <sys/systm.h> #include <sys/proc.h> #include <sys/kauth.h> +#include <sys/module.h> #include <sys/compat_stub.h> #include <net/if.h> @@ -2851,22 +2852,10 @@ ieee80211_ioctl(struct ieee80211com *ic, break; case OSIOCG80211STATS: case OSIOCG80211ZSTATS: - { - struct ieee80211_ostats ostats; - - ifr = (struct ifreq *)data; - s = splnet(); - MODULE_CALL_HOOK(ieee80211_ostats_hook, - (&ostats, &ic->ic_stats), enosys(), error); - if (error == ENOSYS) - error = EINVAL; - if (error == 0) - error = copyout(&ostats, ifr->ifr_data, sizeof(ostats)); - if (error == 0 && cmd == OSIOCG80211ZSTATS) - (void)memset(&ic->ic_stats, 0, sizeof(ic->ic_stats)); - splx(s); + (void)module_autoload("compat_20", MODULE_CLASS_EXEC); + MODULE_CALL_HOOK(ieee80211_20_ioctl_hook, (ic, cmd, data), + enosys(), error); break; - } case SIOCG80211ZSTATS: case SIOCG80211STATS: ifr = (struct ifreq *)data; Index: src/sys/sys/compat_stub.h diff -u src/sys/sys/compat_stub.h:1.3 src/sys/sys/compat_stub.h:1.4 --- src/sys/sys/compat_stub.h:1.3 Mon Jan 28 10:46:49 2019 +++ src/sys/sys/compat_stub.h Mon Jan 28 16:13:58 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: compat_stub.h,v 1.3 2019/01/28 15:46:49 christos Exp $ */ +/* $NetBSD: compat_stub.h,v 1.4 2019/01/28 21:13:58 christos Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -181,11 +181,10 @@ MODULE_HOOK(compat_vndioctl_50_hook, int /* * ieee80211 ioctl compatability */ -struct ieee80211_ostats; -struct ieee80211_stats; +struct ieee80211com; -MODULE_HOOK(ieee80211_ostats_hook, int, - (struct ieee80211_ostats *, struct ieee80211_stats *)); +MODULE_HOOK(ieee80211_20_ioctl_hook, int, + (struct ieee80211com *ic, u_long cmd, void *data)); /* * if_43 compatability