diff options
author | 2017-01-04 03:56:15 +0000 | |
---|---|---|
committer | 2017-01-04 03:56:15 +0000 | |
commit | 570e3de512335d388dadb20d27839c4c266a5651 (patch) | |
tree | 0253cdcde18fe94372f213055f2c42fb2e893edc | |
parent | shuffle the last change slightly. (diff) | |
download | wireguard-openbsd-570e3de512335d388dadb20d27839c4c266a5651.tar.xz wireguard-openbsd-570e3de512335d388dadb20d27839c4c266a5651.zip |
dont assume setting IFF_UP will succeed.
run a drivers ioctl handler and check if it worked before calling
if_up or if_down to report the change. propagate that error up to
userland so ifconfig can report what happened.
ok mpi@
-rw-r--r-- | sys/net/if.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index 4381f2abd5c..7b0614b6f4f 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.472 2017/01/04 03:42:33 dlg Exp $ */ +/* $OpenBSD: if.c,v 1.473 2017/01/04 03:56:15 dlg Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -1802,20 +1802,26 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) case SIOCSIFFLAGS: if ((error = suser(p, 0)) != 0) return (error); - if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) { - s = splnet(); - if_down(ifp); - splx(s); + + ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) | + (ifr->ifr_flags & ~IFF_CANTCHANGE); + + if (ifp->if_ioctl != NULL) { + error = (*ifp->if_ioctl)(ifp, cmd, data); + if (error != 0) { + ifp->if_flags = oif_flags; + break; + } } - if (ifr->ifr_flags & IFF_UP && (ifp->if_flags & IFF_UP) == 0) { + + if (ISSET(oif_flags ^ ifp->if_flags, IFF_UP)) { s = splnet(); - if_up(ifp); + if (ISSET(ifp->if_flags, IFF_UP)) + if_up(ifp); + else + if_down(ifp); splx(s); } - ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) | - (ifr->ifr_flags & ~IFF_CANTCHANGE); - if (ifp->if_ioctl) - (void) (*ifp->if_ioctl)(ifp, cmd, data); break; case SIOCSIFXFLAGS: |