Source-Changes-HG archive

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

[.joined/src/trunk]: .joined/src/sys/net sys/net: New functions if_ioctl, if_...



details:   https://anonhg.NetBSD.org/.joined/src/rev/d8636251029c
branches:  trunk
changeset: 359340:d8636251029c
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Dec 31 14:24:26 2021 +0000

description:
sys/net: New functions if_ioctl, if_init, and if_stop.

These are wrappers, suitable for inserting appropriate kasserts
regarding the API's locking contract, for the corresponding functions
in struct ifnet.

Since these are intended to commit configuration changes to the
interface, which may involve resetting the device, the caller should
hold IFNET_LOCK.  However, I can't straightforwardly prove that all
callers do yet, so the assertion is disabled for now.

diffstat:

 sys/net/if.c |  65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 sys/net/if.h |   6 ++++-
 2 files changed, 65 insertions(+), 6 deletions(-)

diffs (127 lines):

diff -r 733a725a82a1 -r d8636251029c sys/net/if.c
--- a/sys/net/if.c      Fri Dec 31 14:24:16 2021 +0000
+++ b/sys/net/if.c      Fri Dec 31 14:24:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.496 2021/09/30 03:51:05 yamaguchi Exp $       */
+/*     $NetBSD: if.c,v 1.497 2021/12/31 14:24:26 riastradh Exp $       */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.496 2021/09/30 03:51:05 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.497 2021/12/31 14:24:26 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1622,7 +1622,7 @@
        struct ifnet *ifp;
        struct psref psref;
        int error;
-       int (*if_ioctl)(struct ifnet *, u_long, void *);
+       int (*if_ioctlfn)(struct ifnet *, u_long, void *);
 
        KASSERT(mutex_owned(&if_clone_mtx));
 
@@ -1639,7 +1639,7 @@
 
        /* We have to disable ioctls here */
        IFNET_LOCK(ifp);
-       if_ioctl = ifp->if_ioctl;
+       if_ioctlfn = ifp->if_ioctl;
        ifp->if_ioctl = if_nullioctl;
        IFNET_UNLOCK(ifp);
 
@@ -1654,7 +1654,7 @@
        if (error != 0) {
                /* We have to restore if_ioctl on error */
                IFNET_LOCK(ifp);
-               ifp->if_ioctl = if_ioctl;
+               ifp->if_ioctl = if_ioctlfn;
                IFNET_UNLOCK(ifp);
        }
 
@@ -2728,6 +2728,61 @@
 }
 
 /*
+ * if_ioctl(ifp, cmd, data)
+ *
+ *     Apply an ioctl command to the interface.  Returns 0 on success,
+ *     nonzero errno(3) number on failure.
+ *
+ *     May sleep.  Caller must hold ifp->if_ioctl_lock.
+ */
+int
+if_ioctl(struct ifnet *ifp, u_long cmd, void *data)
+{
+
+       KASSERT(1 || IFNET_LOCKED(ifp));        /* XXX not yet */
+
+       return (*ifp->if_ioctl)(ifp, cmd, data);
+}
+
+/*
+ * if_init(ifp)
+ *
+ *     Prepare the hardware underlying ifp to process packets
+ *     according to its current configuration.  Returns 0 on success,
+ *     nonzero errno(3) number on failure.
+ *
+ *     May sleep.  Caller must hold ifp->if_ioctl_lock, a.k.a
+ *     IFNET_LOCK.
+ */
+int
+if_init(struct ifnet *ifp)
+{
+
+       KASSERT(1 || IFNET_LOCKED(ifp));        /* XXX not yet */
+
+       return (*ifp->if_init)(ifp);
+}
+
+/*
+ * if_stop(ifp, disable)
+ *
+ *     Stop the hardware underlying ifp from processing packets.
+ *
+ *     If disable is true, ... XXX(?)
+ *
+ *     May sleep.  Caller must hold ifp->if_ioctl_lock, a.k.a
+ *     IFNET_LOCK.
+ */
+void
+if_stop(struct ifnet *ifp, int disable)
+{
+
+       KASSERT(1 || IFNET_LOCKED(ifp));        /* XXX not yet */
+
+       (*ifp->if_stop)(ifp, disable);
+}
+
+/*
  * Map interface name to
  * interface structure pointer.
  */
diff -r 733a725a82a1 -r d8636251029c sys/net/if.h
--- a/sys/net/if.h      Fri Dec 31 14:24:16 2021 +0000
+++ b/sys/net/if.h      Fri Dec 31 14:24:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.295 2021/09/30 03:51:05 yamaguchi Exp $       */
+/*     $NetBSD: if.h,v 1.296 2021/12/31 14:24:26 riastradh Exp $       */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1143,6 +1143,10 @@
 int    if_flags_set(struct ifnet *, const u_short);
 int    if_clone_list(int, char *, int *);
 
+int    if_ioctl(struct ifnet *, u_long, void *);
+int    if_init(struct ifnet *);
+void   if_stop(struct ifnet *, int);
+
 struct ifnet *ifunit(const char *);
 struct ifnet *if_get(const char *, struct psref *);
 ifnet_t *if_byindex(u_int);



Home | Main Index | Thread Index | Old Index