diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2017-10-11 07:57:28 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2017-10-11 07:57:28 +0000 |
commit | a8b9a59b6861914d150e5c88c10c1c0539481947 (patch) | |
tree | 770dab7838c10a2763be4b0ef849091c70e68267 | |
parent | 93f56b0c7129d7a6d83f90928a3c36b1b163342e (diff) |
ifioctl() cleanups.
Only one semantic chance for SIOCSIFXFLAGS, rtm_ifchg() is now only called
when the flags changed, not always.
ok bluhm@, visa@
-rw-r--r-- | sys/net/if.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index 60020606df5..784a0fc71d1 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.513 2017/10/09 08:35:38 mpi Exp $ */ +/* $OpenBSD: if.c,v 1.514 2017/10/11 07:57:27 mpi Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -1816,10 +1816,9 @@ int ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) { struct ifnet *ifp; - struct ifreq *ifr; - struct sockaddr_dl *sdl; + struct ifreq *ifr = (struct ifreq *)data; struct ifgroupreq *ifgr; - struct if_afreq *ifar; + struct if_afreq *ifar = (struct if_afreq *)data; char ifdescrbuf[IFDESCRSIZE]; char ifrtlabelbuf[RTLABEL_LEN]; int s, error = 0, oif_xflags; @@ -1828,13 +1827,8 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) const char *label; switch (cmd) { - case SIOCGIFCONF: return (ifconf(cmd, data)); - } - ifr = (struct ifreq *)data; - - switch (cmd) { case SIOCIFCREATE: case SIOCIFDESTROY: if ((error = suser(p, 0)) != 0) @@ -1852,15 +1846,19 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) if ((error = suser(p, 0)) != 0) return (error); return (if_setgroupattribs(data)); + } + + ifp = ifunit(ifr->ifr_name); + if (ifp == NULL) + return (ENXIO); + oif_flags = ifp->if_flags; + oif_xflags = ifp->if_xflags; + + switch (cmd) { case SIOCIFAFATTACH: case SIOCIFAFDETACH: if ((error = suser(p, 0)) != 0) return (error); - ifar = (struct if_afreq *)data; - if ((ifp = ifunit(ifar->ifar_name)) == NULL) - return (ENXIO); - oif_flags = ifp->if_flags; - oif_xflags = ifp->if_xflags; switch (ifar->ifar_af) { case AF_INET: /* attach is a noop for AF_INET */ @@ -1878,16 +1876,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) default: return (EAFNOSUPPORT); } - if (oif_flags != ifp->if_flags || oif_xflags != ifp->if_xflags) - rtm_ifchg(ifp); - return (error); - } - - ifp = ifunit(ifr->ifr_name); - if (ifp == 0) - return (ENXIO); - oif_flags = ifp->if_flags; - switch (cmd) { + break; case SIOCGIFFLAGS: ifr->ifr_flags = ifp->if_flags; @@ -2002,7 +1991,6 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) ifp->if_xflags = (ifp->if_xflags & IFXF_CANTCHANGE) | (ifr->ifr_flags & ~IFXF_CANTCHANGE); - rtm_ifchg(ifp); break; case SIOCSIFMETRIC: @@ -2140,8 +2128,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) case SIOCSIFLLADDR: if ((error = suser(p, 0))) return (error); - sdl = ifp->if_sadl; - if (sdl == NULL) + if (ifp->if_sadl == NULL) return (EINVAL); if (ifr->ifr_addr.sa_len != ETHER_ADDR_LEN) return (EINVAL); @@ -2183,6 +2170,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) break; } + if (oif_flags != ifp->if_flags || oif_xflags != ifp->if_xflags) + rtm_ifchg(ifp); + if (((oif_flags ^ ifp->if_flags) & IFF_UP) != 0) getmicrotime(&ifp->if_lastchange); |