Source-Changes-HG archive

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

[src/trunk]: src/sys/net Restore if_ioctl on error of ifc_destroy



details:   https://anonhg.NetBSD.org/src/rev/36d8dcaac2cf
branches:  trunk
changeset: 1002774:36d8dcaac2cf
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Aug 15 04:20:59 2019 +0000

description:
Restore if_ioctl on error of ifc_destroy

Otherwise subsequence ioctls won't work.

Patch from Harold Gutch on PR kern/54434 (tweaked a bit by me)

diffstat:

 sys/net/if.c |  18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diffs (53 lines):

diff -r c544faa0e208 -r 36d8dcaac2cf sys/net/if.c
--- a/sys/net/if.c      Thu Aug 15 03:10:42 2019 +0000
+++ b/sys/net/if.c      Thu Aug 15 04:20:59 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.457 2019/07/25 07:45:57 knakahara Exp $       */
+/*     $NetBSD: if.c,v 1.458 2019/08/15 04:20:59 ozaki-r 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.457 2019/07/25 07:45:57 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.458 2019/08/15 04:20:59 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1611,6 +1611,8 @@
        struct if_clone *ifc;
        struct ifnet *ifp;
        struct psref psref;
+       int error;
+       int (*if_ioctl)(struct ifnet *, u_long, void *);
 
        KASSERT(mutex_owned(&if_clone_mtx));
 
@@ -1627,6 +1629,7 @@
 
        /* We have to disable ioctls here */
        IFNET_LOCK(ifp);
+       if_ioctl = ifp->if_ioctl;
        ifp->if_ioctl = if_nullioctl;
        IFNET_UNLOCK(ifp);
 
@@ -1636,7 +1639,16 @@
         */
        if_put(ifp, &psref);
 
-       return (*ifc->ifc_destroy)(ifp);
+       error = (*ifc->ifc_destroy)(ifp);
+
+       if (error != 0) {
+               /* We have to restore if_ioctl on error */
+               IFNET_LOCK(ifp);
+               ifp->if_ioctl = if_ioctl;
+               IFNET_UNLOCK(ifp);
+       }
+
+       return error;
 }
 
 static bool



Home | Main Index | Thread Index | Old Index