Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - Don't expose random data conversion functions, but exp...



details:   https://anonhg.NetBSD.org/src/rev/db851ec99ee9
branches:  trunk
changeset: 448288:db851ec99ee9
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jan 28 21:13:58 2019 +0000

description:
- 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.

diffstat:

 sys/compat/common/ieee80211_20.c |  33 +++++++++++++++++++++++++++------
 sys/kern/compat_stub.c           |   4 ++--
 sys/net80211/ieee80211_ioctl.c   |  21 +++++----------------
 sys/sys/compat_stub.h            |   9 ++++-----
 4 files changed, 38 insertions(+), 29 deletions(-)

diffs (160 lines):

diff -r 58e96a948719 -r db851ec99ee9 sys/compat/common/ieee80211_20.c
--- a/sys/compat/common/ieee80211_20.c  Mon Jan 28 18:53:52 2019 +0000
+++ b/sys/compat/common/ieee80211_20.c  Mon Jan 28 21:13:58 2019 +0000
@@ -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 @@
 
 #include <compat/sys/sockio.h>
 
-static int
+static void
 ieee80211_get_ostats(struct ieee80211_ostats *ostats,
     struct ieee80211_stats *stats)
 {
@@ -90,20 +90,41 @@
        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);
 }
diff -r 58e96a948719 -r db851ec99ee9 sys/kern/compat_stub.c
--- a/sys/kern/compat_stub.c    Mon Jan 28 18:53:52 2019 +0000
+++ b/sys/kern/compat_stub.c    Mon Jan 28 21:13:58 2019 +0000
@@ -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 @@
 /*
  * ieee80211 ioctl compatability
  */
-struct ieee80211_ostats_hook_t ieee80211_ostats_hook;
+struct ieee80211_20_ioctl_hook_t ieee80211_20_ioctl_hook;
 
 /*
  * if_43 compatability
diff -r 58e96a948719 -r db851ec99ee9 sys/net80211/ieee80211_ioctl.c
--- a/sys/net80211/ieee80211_ioctl.c    Mon Jan 28 18:53:52 2019 +0000
+++ b/sys/net80211/ieee80211_ioctl.c    Mon Jan 28 21:13:58 2019 +0000
@@ -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 @@
 #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 @@
                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;
diff -r 58e96a948719 -r db851ec99ee9 sys/sys/compat_stub.h
--- a/sys/sys/compat_stub.h     Mon Jan 28 18:53:52 2019 +0000
+++ b/sys/sys/compat_stub.h     Mon Jan 28 21:13:58 2019 +0000
@@ -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 @@
 /*
  * 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



Home | Main Index | Thread Index | Old Index