diff options
Diffstat (limited to 'sys/net/if_pppx.c')
-rw-r--r-- | sys/net/if_pppx.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/sys/net/if_pppx.c b/sys/net/if_pppx.c index dacbc678740..3d552ad52e0 100644 --- a/sys/net/if_pppx.c +++ b/sys/net/if_pppx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pppx.c,v 1.58 2017/05/04 15:00:24 bluhm Exp $ */ +/* $OpenBSD: if_pppx.c,v 1.59 2017/05/28 12:51:34 yasuoka Exp $ */ /* * Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org> @@ -287,10 +287,11 @@ pppxread(dev_t dev, struct uio *uio, int ioflag) if (ISSET(ioflag, IO_NDELAY)) return (EWOULDBLOCK); - s = splnet(); + NET_LOCK(s); pxd->pxd_waiting = 1; - error = tsleep(pxd, (PZERO + 1)|PCATCH, "pppxread", 0); - splx(s); + error = rwsleep(pxd, &netlock, + (PZERO + 1)|PCATCH, "pppxread", 0); + NET_UNLOCK(s); if (error != 0) { return (error); } @@ -321,9 +322,6 @@ pppxwrite(dev_t dev, struct uio *uio, int ioflag) int tlen; int error = 0; size_t mlen; -#if NBPFILTER > 0 - int s; -#endif if (uio->uio_resid < sizeof(*th) + sizeof(uint32_t) || uio->uio_resid > MCLBYTES) @@ -389,11 +387,8 @@ pppxwrite(dev_t dev, struct uio *uio, int ioflag) top->m_pkthdr.ph_ifidx = pxi->pxi_if.if_index; #if NBPFILTER > 0 - if (pxi->pxi_if.if_bpf) { - s = splnet(); + if (pxi->pxi_if.if_bpf) bpf_mtap(pxi->pxi_if.if_bpf, top, BPF_DIRECTION_IN); - splx(s); - } #endif /* strip the tunnel header */ proto = ntohl(*(uint32_t *)(th + 1)); @@ -423,8 +418,9 @@ int pppxioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) { struct pppx_dev *pxd = pppx_dev2pxd(dev); - int error = 0; + int s, error = 0; + NET_LOCK(s); switch (cmd) { case PIPEXSMODE: /* @@ -468,12 +464,13 @@ pppxioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) case FIONBIO: case FIOASYNC: case FIONREAD: - return (0); + break; default: error = ENOTTY; break; } + NET_UNLOCK(s); return (error); } @@ -660,7 +657,7 @@ pppx_add_session(struct pppx_dev *pxd, struct pipex_session_req *req) struct pipex_session *session; struct pipex_hash_head *chain; struct ifnet *ifp; - int unit, s, error = 0; + int unit, error = 0; struct in_ifaddr *ia; struct sockaddr_in ifaddr; #ifdef PIPEX_PPPOE @@ -845,8 +842,6 @@ pppx_add_session(struct pppx_dev *pxd, struct pipex_session_req *req) ifp->if_softc = pxi; /* ifp->if_rdomain = req->pr_rdomain; */ - s = splnet(); - /* hook up pipex context */ chain = PIPEX_ID_HASHTABLE(session->session_id); LIST_INSERT_HEAD(chain, session, id_chain); @@ -864,7 +859,11 @@ pppx_add_session(struct pppx_dev *pxd, struct pipex_session_req *req) if (LIST_NEXT(session, session_list) == NULL) pipex_timer_start(); + /* XXXSMP breaks atomicity */ + rw_exit_write(&netlock); if_attach(ifp); + rw_enter_write(&netlock); + if_addgroup(ifp, "pppx"); if_alloc_sadl(ifp); @@ -913,7 +912,6 @@ pppx_add_session(struct pppx_dev *pxd, struct pipex_session_req *req) } else { dohooks(ifp->if_addrhooks, 0); } - splx(s); out: rw_exit_write(&pppx_ifs_lk); @@ -957,12 +955,11 @@ pppx_if_destroy(struct pppx_dev *pxd, struct pppx_if *pxi) { struct ifnet *ifp; struct pipex_session *session; - int s; + NET_ASSERT_LOCKED(); session = &pxi->pxi_session; ifp = &pxi->pxi_if; - s = splnet(); LIST_REMOVE(session, id_chain); LIST_REMOVE(session, session_list); switch (session->protocol) { @@ -976,9 +973,11 @@ pppx_if_destroy(struct pppx_dev *pxd, struct pppx_if *pxi) /* if final session is destroyed, stop timer */ if (LIST_EMPTY(&pipex_session_list)) pipex_timer_stop(); - splx(s); + /* XXXSMP breaks atomicity */ + rw_exit_write(&netlock); if_detach(ifp); + rw_enter_write(&netlock); rw_enter_write(&pppx_ifs_lk); if (RBT_REMOVE(pppx_ifs, &pppx_ifs, pxi) == NULL) @@ -1023,9 +1022,8 @@ pppx_if_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct pppx_hdr *th; int error = 0; int proto; -#if NBPFILTER > 0 - int s; -#endif + + NET_ASSERT_LOCKED(); if (!ISSET(ifp->if_flags, IFF_UP)) { m_freem(m); @@ -1034,11 +1032,8 @@ pppx_if_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, } #if NBPFILTER > 0 - if (ifp->if_bpf) { - s = splnet(); + if (ifp->if_bpf) bpf_mtap_af(ifp->if_bpf, dst->sa_family, m, BPF_DIRECTION_OUT); - splx(s); - } #endif if (pipex_enable) { switch (dst->sa_family) { @@ -1074,12 +1069,10 @@ pppx_if_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, rw_enter_read(&pppx_devs_lk); error = mq_enqueue(&pxi->pxi_dev->pxd_svcq, m); if (error == 0) { - s = splnet(); if (pxi->pxi_dev->pxd_waiting) { wakeup((caddr_t)pxi->pxi_dev); pxi->pxi_dev->pxd_waiting = 0; } - splx(s); selwakeup(&pxi->pxi_dev->pxd_rsel); } rw_exit_read(&pppx_devs_lk); |