diff options
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/if_tun.c | 376 |
1 files changed, 188 insertions, 188 deletions
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index a79bc270e22..929e5a163b5 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tun.c,v 1.193 2019/11/21 07:30:28 dlg Exp $ */ +/* $OpenBSD: if_tun.c,v 1.194 2019/11/26 04:03:48 dlg Exp $ */ /* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */ /* @@ -195,28 +195,28 @@ tap_clone_create(struct if_clone *ifc, int unit) struct tun_softc * tun_list_lookup(struct tun_list *tl, int unit) { - struct tun_softc *tp; + struct tun_softc *sc; KERNEL_ASSERT_LOCKED(); - LIST_FOREACH(tp, tl, sc_entry) { - if (tp->sc_unit == unit) - return (tp); + LIST_FOREACH(sc, tl, sc_entry) { + if (sc->sc_unit == unit) + return (sc); } return (NULL); } int -tun_list_insert(struct tun_list *tl, struct tun_softc *tp) +tun_list_insert(struct tun_list *tl, struct tun_softc *sc) { KERNEL_ASSERT_LOCKED(); /* check for a race */ - if (tun_list_lookup(tl, tp->sc_unit) != NULL) + if (tun_list_lookup(tl, sc->sc_unit) != NULL) return (EEXIST); - LIST_INSERT_HEAD(tl, tp, sc_entry); + LIST_INSERT_HEAD(tl, sc, sc_entry); return (0); } @@ -224,20 +224,20 @@ tun_list_insert(struct tun_list *tl, struct tun_softc *tp) int tun_create(struct if_clone *ifc, int unit, int flags) { - struct tun_softc *tp; + struct tun_softc *sc; struct ifnet *ifp; if (unit > minor(~0U)) return (ENXIO); - tp = malloc(sizeof(*tp), M_DEVBUF, M_WAITOK|M_ZERO); - tp->sc_unit = unit; - tp->sc_flags = TUN_INITED|TUN_STAYUP; + sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); + sc->sc_unit = unit; + sc->sc_flags = TUN_INITED|TUN_STAYUP; - ifp = &tp->sc_if; + ifp = &sc->sc_if; snprintf(ifp->if_xname, sizeof(ifp->if_xname), "%s%d", ifc->ifc_name, unit); - ifp->if_softc = tp; + ifp->if_softc = sc; ifp->if_ioctl = tun_ioctl; ifp->if_output = tun_output; @@ -247,10 +247,10 @@ tun_create(struct if_clone *ifc, int unit, int flags) IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); if ((flags & TUN_LAYER2) == 0) { - if (tun_list_insert(&tun_softc_list, tp) != 0) + if (tun_list_insert(&tun_softc_list, sc) != 0) goto exists; - tp->sc_flags &= ~TUN_LAYER2; + sc->sc_flags &= ~TUN_LAYER2; ifp->if_mtu = ETHERMTU; ifp->if_flags = (IFF_POINTOPOINT|IFF_MULTICAST); ifp->if_type = IFT_TUNNEL; @@ -263,10 +263,10 @@ tun_create(struct if_clone *ifc, int unit, int flags) bpfattach(&ifp->if_bpf, ifp, DLT_LOOP, sizeof(u_int32_t)); #endif } else { - if (tun_list_insert(&tap_softc_list, tp) != 0) + if (tun_list_insert(&tap_softc_list, sc) != 0) goto exists; - tp->sc_flags |= TUN_LAYER2; + sc->sc_flags |= TUN_LAYER2; ether_fakeaddr(ifp); ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST); @@ -277,40 +277,40 @@ tun_create(struct if_clone *ifc, int unit, int flags) } #ifdef PIPEX - if ((tp->sc_flags & TUN_LAYER2) == 0) - pipex_iface_init(&tp->sc_pipex_iface, ifp); + if ((sc->sc_flags & TUN_LAYER2) == 0) + pipex_iface_init(&sc->sc_pipex_iface, ifp); #endif return (0); exists: - free(tp, M_DEVBUF, sizeof(*tp)); + free(sc, M_DEVBUF, sizeof(*sc)); return (EEXIST); } int tun_clone_destroy(struct ifnet *ifp) { - struct tun_softc *tp = ifp->if_softc; + struct tun_softc *sc = ifp->if_softc; int s; #ifdef PIPEX - if ((tp->sc_flags & TUN_LAYER2) == 0) - pipex_iface_fini(&tp->sc_pipex_iface); + if ((sc->sc_flags & TUN_LAYER2) == 0) + pipex_iface_fini(&sc->sc_pipex_iface); #endif - tun_wakeup(tp); + tun_wakeup(sc); s = splhigh(); - klist_invalidate(&tp->sc_rsel.si_note); - klist_invalidate(&tp->sc_wsel.si_note); + klist_invalidate(&sc->sc_rsel.si_note); + klist_invalidate(&sc->sc_wsel.si_note); splx(s); - if (tp->sc_flags & TUN_LAYER2) + if (sc->sc_flags & TUN_LAYER2) ether_ifdetach(ifp); if_detach(ifp); - LIST_REMOVE(tp, sc_entry); - free(tp, M_DEVBUF, sizeof *tp); + LIST_REMOVE(sc, sc_entry); + free(sc, M_DEVBUF, sizeof *sc); return (0); } @@ -333,10 +333,10 @@ tap_lookup(int unit) int tunopen(dev_t dev, int flag, int mode, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; unsigned int rdomain = rtable_l2(p->p_p->ps_rtableid); - if ((tp = tun_lookup(minor(dev))) == NULL) { /* create on demand */ + if ((sc = tun_lookup(minor(dev))) == NULL) { /* create on demand */ char xname[IFNAMSIZ]; int error; @@ -347,25 +347,25 @@ tunopen(dev_t dev, int flag, int mode, struct proc *p) /* we lost a race to create */ /* FALLTHROUGH */ case 0: - if ((tp = tun_lookup(minor(dev))) == NULL) + if ((sc = tun_lookup(minor(dev))) == NULL) return (ENXIO); - tp->sc_flags &= ~TUN_STAYUP; + sc->sc_flags &= ~TUN_STAYUP; break; default: return (error); } } - return (tun_dev_open(tp, flag, mode, p)); + return (tun_dev_open(sc, flag, mode, p)); } int tapopen(dev_t dev, int flag, int mode, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; unsigned int rdomain = rtable_l2(p->p_p->ps_rtableid); - if ((tp = tap_lookup(minor(dev))) == NULL) { /* create on demand */ + if ((sc = tap_lookup(minor(dev))) == NULL) { /* create on demand */ char xname[IFNAMSIZ]; int error; @@ -376,34 +376,34 @@ tapopen(dev_t dev, int flag, int mode, struct proc *p) /* we lost a race to create */ /* FALLTHROUGH */ case 0: - if ((tp = tap_lookup(minor(dev))) == NULL) + if ((sc = tap_lookup(minor(dev))) == NULL) return (ENXIO); - tp->sc_flags &= ~TUN_STAYUP; + sc->sc_flags &= ~TUN_STAYUP; break; default: return (error); } } - return (tun_dev_open(tp, flag, mode, p)); + return (tun_dev_open(sc, flag, mode, p)); } int -tun_dev_open(struct tun_softc *tp, int flag, int mode, struct proc *p) +tun_dev_open(struct tun_softc *sc, int flag, int mode, struct proc *p) { struct ifnet *ifp; - if (tp->sc_flags & TUN_OPEN) + if (sc->sc_flags & TUN_OPEN) return (EBUSY); - ifp = &tp->sc_if; - tp->sc_flags |= TUN_OPEN; + ifp = &sc->sc_if; + sc->sc_flags |= TUN_OPEN; if (flag & FNONBLOCK) - tp->sc_flags |= TUN_NBIO; + sc->sc_flags |= TUN_NBIO; /* automatically mark the interface running on open */ ifp->if_flags |= IFF_RUNNING; - tun_link_state(tp); + tun_link_state(sc); TUNDEBUG(("%s: open\n", ifp->if_xname)); return (0); @@ -416,83 +416,83 @@ tun_dev_open(struct tun_softc *tp, int flag, int mode, struct proc *p) int tunclose(dev_t dev, int flag, int mode, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tun_lookup(minor(dev))) == NULL) + if ((sc = tun_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_close(tp, flag, mode, p)); + return (tun_dev_close(sc, flag, mode, p)); } int tapclose(dev_t dev, int flag, int mode, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tap_lookup(minor(dev))) == NULL) + if ((sc = tap_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_close(tp, flag, mode, p)); + return (tun_dev_close(sc, flag, mode, p)); } int -tun_dev_close(struct tun_softc *tp, int flag, int mode, struct proc *p) +tun_dev_close(struct tun_softc *sc, int flag, int mode, struct proc *p) { int error = 0; struct ifnet *ifp; - ifp = &tp->sc_if; - tp->sc_flags &= ~(TUN_OPEN|TUN_NBIO|TUN_ASYNC); + ifp = &sc->sc_if; + sc->sc_flags &= ~(TUN_OPEN|TUN_NBIO|TUN_ASYNC); /* * junk all pending output */ ifp->if_flags &= ~IFF_RUNNING; - tun_link_state(tp); + tun_link_state(sc); IFQ_PURGE(&ifp->if_snd); TUNDEBUG(("%s: closed\n", ifp->if_xname)); - if (!(tp->sc_flags & TUN_STAYUP)) + if (!(sc->sc_flags & TUN_STAYUP)) error = if_clone_destroy(ifp->if_xname); else { - tp->sc_pgid = 0; - selwakeup(&tp->sc_rsel); + sc->sc_pgid = 0; + selwakeup(&sc->sc_rsel); } return (error); } int -tun_init(struct tun_softc *tp) +tun_init(struct tun_softc *sc) { - struct ifnet *ifp = &tp->sc_if; + struct ifnet *ifp = &sc->sc_if; struct ifaddr *ifa; TUNDEBUG(("%s: tun_init\n", ifp->if_xname)); ifp->if_flags |= IFF_UP | IFF_RUNNING; - tp->sc_flags &= ~(TUN_IASET|TUN_DSTADDR|TUN_BRDADDR); + sc->sc_flags &= ~(TUN_IASET|TUN_DSTADDR|TUN_BRDADDR); TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family == AF_INET) { struct sockaddr_in *sin; sin = satosin(ifa->ifa_addr); if (sin && sin->sin_addr.s_addr) - tp->sc_flags |= TUN_IASET; + sc->sc_flags |= TUN_IASET; if (ifp->if_flags & IFF_POINTOPOINT) { sin = satosin(ifa->ifa_dstaddr); if (sin && sin->sin_addr.s_addr) - tp->sc_flags |= TUN_DSTADDR; + sc->sc_flags |= TUN_DSTADDR; } else - tp->sc_flags &= ~TUN_DSTADDR; + sc->sc_flags &= ~TUN_DSTADDR; if (ifp->if_flags & IFF_BROADCAST) { sin = satosin(ifa->ifa_broadaddr); if (sin && sin->sin_addr.s_addr) - tp->sc_flags |= TUN_BRDADDR; + sc->sc_flags |= TUN_BRDADDR; } else - tp->sc_flags &= ~TUN_BRDADDR; + sc->sc_flags &= ~TUN_BRDADDR; } #ifdef INET6 if (ifa->ifa_addr->sa_family == AF_INET6) { @@ -500,15 +500,15 @@ tun_init(struct tun_softc *tp) sin6 = satosin6(ifa->ifa_addr); if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) - tp->sc_flags |= TUN_IASET; + sc->sc_flags |= TUN_IASET; if (ifp->if_flags & IFF_POINTOPOINT) { sin6 = satosin6(ifa->ifa_dstaddr); if (sin6 && !IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) - tp->sc_flags |= TUN_DSTADDR; + sc->sc_flags |= TUN_DSTADDR; } else - tp->sc_flags &= ~TUN_DSTADDR; + sc->sc_flags &= ~TUN_DSTADDR; } #endif /* INET6 */ } @@ -522,16 +522,16 @@ tun_init(struct tun_softc *tp) int tun_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { - struct tun_softc *tp = (struct tun_softc *)(ifp->if_softc); + struct tun_softc *sc = (struct tun_softc *)(ifp->if_softc); struct ifreq *ifr = (struct ifreq *)data; int error = 0; switch (cmd) { case SIOCSIFADDR: - tun_init(tp); + tun_init(sc); break; case SIOCSIFDSTADDR: - tun_init(tp); + tun_init(sc); TUNDEBUG(("%s: destination address set\n", ifp->if_xname)); break; case SIOCSIFMTU: @@ -546,8 +546,8 @@ tun_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) case SIOCSIFFLAGS: break; default: - if (tp->sc_flags & TUN_LAYER2) - error = ether_ioctl(ifp, &tp->sc_arpcom, cmd, data); + if (sc->sc_flags & TUN_LAYER2) + error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data); else error = ENOTTY; } @@ -562,7 +562,7 @@ int tun_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, struct rtentry *rt) { - struct tun_softc *tp = ifp->if_softc; + struct tun_softc *sc = ifp->if_softc; int error; u_int32_t *af; @@ -573,14 +573,14 @@ tun_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, TUNDEBUG(("%s: tun_output\n", ifp->if_xname)); - if ((tp->sc_flags & TUN_READY) != TUN_READY) { + if ((sc->sc_flags & TUN_READY) != TUN_READY) { TUNDEBUG(("%s: not ready %#x\n", ifp->if_xname, - tp->sc_flags)); + sc->sc_flags)); m_freem(m0); return (EHOSTDOWN); } - if (tp->sc_flags & TUN_LAYER2) + if (sc->sc_flags & TUN_LAYER2) return (ether_output(ifp, m0, dst, rt)); M_PREPEND(m0, sizeof(*af), M_DONTWAIT); @@ -595,7 +595,7 @@ tun_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, #endif #ifdef PIPEX if (pipex_enable && (m0 = pipex_output(m0, dst->sa_family, - sizeof(u_int32_t), &tp->sc_pipex_iface)) == NULL) { + sizeof(u_int32_t), &sc->sc_pipex_iface)) == NULL) { return (0); } #endif @@ -607,22 +607,22 @@ tun_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, return (error); } - tun_wakeup(tp); + tun_wakeup(sc); return (0); } void -tun_wakeup(struct tun_softc *tp) +tun_wakeup(struct tun_softc *sc) { KERNEL_LOCK(); - if (tp->sc_flags & TUN_RWAIT) { - tp->sc_flags &= ~TUN_RWAIT; - wakeup((caddr_t)tp); + if (sc->sc_flags & TUN_RWAIT) { + sc->sc_flags &= ~TUN_RWAIT; + wakeup((caddr_t)sc); } - if (tp->sc_flags & TUN_ASYNC && tp->sc_pgid) - csignal(tp->sc_pgid, SIGIO, - tp->sc_siguid, tp->sc_sigeuid); - selwakeup(&tp->sc_rsel); + if (sc->sc_flags & TUN_ASYNC && sc->sc_pgid) + csignal(sc->sc_pgid, SIGIO, + sc->sc_siguid, sc->sc_sigeuid); + selwakeup(&sc->sc_rsel); KERNEL_UNLOCK(); } @@ -632,25 +632,25 @@ tun_wakeup(struct tun_softc *tp) int tunioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tun_lookup(minor(dev))) == NULL) + if ((sc = tun_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_ioctl(tp, cmd, data, flag, p)); + return (tun_dev_ioctl(sc, cmd, data, flag, p)); } int tapioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tap_lookup(minor(dev))) == NULL) + if ((sc = tap_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_ioctl(tp, cmd, data, flag, p)); + return (tun_dev_ioctl(sc, cmd, data, flag, p)); } int -tun_dev_ioctl(struct tun_softc *tp, u_long cmd, caddr_t data, int flag, +tun_dev_ioctl(struct tun_softc *sc, u_long cmd, caddr_t data, int flag, struct proc *p) { struct tuninfo *tunp; @@ -660,20 +660,20 @@ tun_dev_ioctl(struct tun_softc *tp, u_long cmd, caddr_t data, int flag, tunp = (struct tuninfo *)data; if (tunp->mtu < ETHERMIN || tunp->mtu > TUNMRU) return (EINVAL); - if (tunp->type != tp->sc_if.if_type) + if (tunp->type != sc->sc_if.if_type) return (EINVAL); - tp->sc_if.if_mtu = tunp->mtu; - tp->sc_if.if_flags = + sc->sc_if.if_mtu = tunp->mtu; + sc->sc_if.if_flags = (tunp->flags & TUN_IFF_FLAGS) | - (tp->sc_if.if_flags & ~TUN_IFF_FLAGS); - tp->sc_if.if_baudrate = tunp->baudrate; + (sc->sc_if.if_flags & ~TUN_IFF_FLAGS); + sc->sc_if.if_baudrate = tunp->baudrate; break; case TUNGIFINFO: tunp = (struct tuninfo *)data; - tunp->mtu = tp->sc_if.if_mtu; - tunp->type = tp->sc_if.if_type; - tunp->flags = tp->sc_if.if_flags; - tunp->baudrate = tp->sc_if.if_baudrate; + tunp->mtu = sc->sc_if.if_mtu; + tunp->type = sc->sc_if.if_type; + tunp->flags = sc->sc_if.if_flags; + tunp->baudrate = sc->sc_if.if_baudrate; break; #ifdef TUN_DEBUG case TUNSDEBUG: @@ -687,8 +687,8 @@ tun_dev_ioctl(struct tun_softc *tp, u_long cmd, caddr_t data, int flag, switch (*(int *)data & (IFF_POINTOPOINT|IFF_BROADCAST)) { case IFF_POINTOPOINT: case IFF_BROADCAST: - tp->sc_if.if_flags &= ~TUN_IFF_FLAGS; - tp->sc_if.if_flags |= *(int *)data & TUN_IFF_FLAGS; + sc->sc_if.if_flags &= ~TUN_IFF_FLAGS; + sc->sc_if.if_flags |= *(int *)data & TUN_IFF_FLAGS; break; default: return (EINVAL); @@ -697,45 +697,45 @@ tun_dev_ioctl(struct tun_softc *tp, u_long cmd, caddr_t data, int flag, case FIONBIO: if (*(int *)data) - tp->sc_flags |= TUN_NBIO; + sc->sc_flags |= TUN_NBIO; else - tp->sc_flags &= ~TUN_NBIO; + sc->sc_flags &= ~TUN_NBIO; break; case FIOASYNC: if (*(int *)data) - tp->sc_flags |= TUN_ASYNC; + sc->sc_flags |= TUN_ASYNC; else - tp->sc_flags &= ~TUN_ASYNC; + sc->sc_flags &= ~TUN_ASYNC; break; case FIONREAD: - *(int *)data = ifq_hdatalen(&tp->sc_if.if_snd); + *(int *)data = ifq_hdatalen(&sc->sc_if.if_snd); break; case TIOCSPGRP: - tp->sc_pgid = *(int *)data; - tp->sc_siguid = p->p_ucred->cr_ruid; - tp->sc_sigeuid = p->p_ucred->cr_uid; + sc->sc_pgid = *(int *)data; + sc->sc_siguid = p->p_ucred->cr_ruid; + sc->sc_sigeuid = p->p_ucred->cr_uid; break; case TIOCGPGRP: - *(int *)data = tp->sc_pgid; + *(int *)data = sc->sc_pgid; break; case SIOCGIFADDR: - if (!(tp->sc_flags & TUN_LAYER2)) + if (!(sc->sc_flags & TUN_LAYER2)) return (EINVAL); - bcopy(tp->sc_arpcom.ac_enaddr, data, - sizeof(tp->sc_arpcom.ac_enaddr)); + bcopy(sc->sc_arpcom.ac_enaddr, data, + sizeof(sc->sc_arpcom.ac_enaddr)); break; case SIOCSIFADDR: - if (!(tp->sc_flags & TUN_LAYER2)) + if (!(sc->sc_flags & TUN_LAYER2)) return (EINVAL); - bcopy(data, tp->sc_arpcom.ac_enaddr, - sizeof(tp->sc_arpcom.ac_enaddr)); + bcopy(data, sc->sc_arpcom.ac_enaddr, + sizeof(sc->sc_arpcom.ac_enaddr)); break; default: #ifdef PIPEX - if (!(tp->sc_flags & TUN_LAYER2)) { + if (!(sc->sc_flags & TUN_LAYER2)) { int ret; - ret = pipex_ioctl(&tp->sc_pipex_iface, cmd, data); + ret = pipex_ioctl(&sc->sc_pipex_iface, cmd, data); return (ret); } #endif @@ -751,44 +751,44 @@ tun_dev_ioctl(struct tun_softc *tp, u_long cmd, caddr_t data, int flag, int tunread(dev_t dev, struct uio *uio, int ioflag) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tun_lookup(minor(dev))) == NULL) + if ((sc = tun_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_read(tp, uio, ioflag)); + return (tun_dev_read(sc, uio, ioflag)); } int tapread(dev_t dev, struct uio *uio, int ioflag) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tap_lookup(minor(dev))) == NULL) + if ((sc = tap_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_read(tp, uio, ioflag)); + return (tun_dev_read(sc, uio, ioflag)); } int -tun_dev_read(struct tun_softc *tp, struct uio *uio, int ioflag) +tun_dev_read(struct tun_softc *sc, struct uio *uio, int ioflag) { - struct ifnet *ifp = &tp->sc_if; + struct ifnet *ifp = &sc->sc_if; struct mbuf *m, *m0; unsigned int ifidx; int error = 0; size_t len; - if ((tp->sc_flags & TUN_READY) != TUN_READY) + if ((sc->sc_flags & TUN_READY) != TUN_READY) return (EHOSTDOWN); ifidx = ifp->if_index; - tp->sc_flags &= ~TUN_RWAIT; + sc->sc_flags &= ~TUN_RWAIT; do { struct ifnet *ifp1; int destroyed; - while ((tp->sc_flags & TUN_READY) != TUN_READY) { - if ((error = tsleep_nsec(tp, + while ((sc->sc_flags & TUN_READY) != TUN_READY) { + if ((error = tsleep_nsec(sc, (PZERO + 1)|PCATCH, "tunread", INFSLP)) != 0) return (error); /* Make sure the interface still exists. */ @@ -800,10 +800,10 @@ tun_dev_read(struct tun_softc *tp, struct uio *uio, int ioflag) } IFQ_DEQUEUE(&ifp->if_snd, m0); if (m0 == NULL) { - if (tp->sc_flags & TUN_NBIO && ioflag & IO_NDELAY) + if (sc->sc_flags & TUN_NBIO && ioflag & IO_NDELAY) return (EWOULDBLOCK); - tp->sc_flags |= TUN_RWAIT; - if ((error = tsleep_nsec(tp, + sc->sc_flags |= TUN_RWAIT; + if ((error = tsleep_nsec(sc, (PZERO + 1)|PCATCH, "tunread", INFSLP)) != 0) return (error); /* Make sure the interface still exists. */ @@ -815,7 +815,7 @@ tun_dev_read(struct tun_softc *tp, struct uio *uio, int ioflag) } } while (m0 == NULL); - if (tp->sc_flags & TUN_LAYER2) { + if (sc->sc_flags & TUN_LAYER2) { #if NBPFILTER > 0 if (ifp->if_bpf) bpf_mtap(ifp->if_bpf, m0, BPF_DIRECTION_OUT); @@ -846,25 +846,25 @@ tun_dev_read(struct tun_softc *tp, struct uio *uio, int ioflag) int tunwrite(dev_t dev, struct uio *uio, int ioflag) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tun_lookup(minor(dev))) == NULL) + if ((sc = tun_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_write(tp, uio, ioflag)); + return (tun_dev_write(sc, uio, ioflag)); } int tapwrite(dev_t dev, struct uio *uio, int ioflag) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tap_lookup(minor(dev))) == NULL) + if ((sc = tap_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_write(tp, uio, ioflag)); + return (tun_dev_write(sc, uio, ioflag)); } int -tun_dev_write(struct tun_softc *tp, struct uio *uio, int ioflag) +tun_dev_write(struct tun_softc *sc, struct uio *uio, int ioflag) { struct ifnet *ifp; u_int32_t *th; @@ -872,7 +872,7 @@ tun_dev_write(struct tun_softc *tp, struct uio *uio, int ioflag) int error = 0, tlen; size_t mlen; - ifp = &tp->sc_if; + ifp = &sc->sc_if; TUNDEBUG(("%s: tunwrite\n", ifp->if_xname)); if (uio->uio_resid < ifp->if_hdrlen || @@ -898,7 +898,7 @@ tun_dev_write(struct tun_softc *tp, struct uio *uio, int ioflag) top = NULL; mp = ⊤ - if (tp->sc_flags & TUN_LAYER2) { + if (sc->sc_flags & TUN_LAYER2) { /* * Pad so that IP header is correctly aligned * this is necessary for all strict aligned architectures. @@ -937,7 +937,7 @@ tun_dev_write(struct tun_softc *tp, struct uio *uio, int ioflag) top->m_pkthdr.len = tlen; - if (tp->sc_flags & TUN_LAYER2) { + if (sc->sc_flags & TUN_LAYER2) { struct mbuf_list ml = MBUF_LIST_INITIALIZER(); ml_enqueue(&ml, top); @@ -997,31 +997,31 @@ tun_dev_write(struct tun_softc *tp, struct uio *uio, int ioflag) int tunpoll(dev_t dev, int events, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tun_lookup(minor(dev))) == NULL) + if ((sc = tun_lookup(minor(dev))) == NULL) return (POLLERR); - return (tun_dev_poll(tp, events, p)); + return (tun_dev_poll(sc, events, p)); } int tappoll(dev_t dev, int events, struct proc *p) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tap_lookup(minor(dev))) == NULL) + if ((sc = tap_lookup(minor(dev))) == NULL) return (POLLERR); - return (tun_dev_poll(tp, events, p)); + return (tun_dev_poll(sc, events, p)); } int -tun_dev_poll(struct tun_softc *tp, int events, struct proc *p) +tun_dev_poll(struct tun_softc *sc, int events, struct proc *p) { int revents; struct ifnet *ifp; unsigned int len; - ifp = &tp->sc_if; + ifp = &sc->sc_if; revents = 0; TUNDEBUG(("%s: tunpoll\n", ifp->if_xname)); @@ -1032,7 +1032,7 @@ tun_dev_poll(struct tun_softc *tp, int events, struct proc *p) revents |= events & (POLLIN | POLLRDNORM); } else { TUNDEBUG(("%s: tunpoll waiting\n", ifp->if_xname)); - selrecord(p, &tp->sc_rsel); + selrecord(p, &sc->sc_rsel); } } if (events & (POLLOUT | POLLWRNORM)) @@ -1049,47 +1049,47 @@ tun_dev_poll(struct tun_softc *tp, int events, struct proc *p) int tunkqfilter(dev_t dev, struct knote *kn) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tun_lookup(minor(dev))) == NULL) + if ((sc = tun_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_kqfilter(tp, kn)); + return (tun_dev_kqfilter(sc, kn)); } int tapkqfilter(dev_t dev, struct knote *kn) { - struct tun_softc *tp; + struct tun_softc *sc; - if ((tp = tap_lookup(minor(dev))) == NULL) + if ((sc = tap_lookup(minor(dev))) == NULL) return (ENXIO); - return (tun_dev_kqfilter(tp, kn)); + return (tun_dev_kqfilter(sc, kn)); } int -tun_dev_kqfilter(struct tun_softc *tp, struct knote *kn) +tun_dev_kqfilter(struct tun_softc *sc, struct knote *kn) { int s; struct klist *klist; struct ifnet *ifp; - ifp = &tp->sc_if; + ifp = &sc->sc_if; TUNDEBUG(("%s: tunkqfilter\n", ifp->if_xname)); switch (kn->kn_filter) { case EVFILT_READ: - klist = &tp->sc_rsel.si_note; + klist = &sc->sc_rsel.si_note; kn->kn_fop = &tunread_filtops; break; case EVFILT_WRITE: - klist = &tp->sc_wsel.si_note; + klist = &sc->sc_wsel.si_note; kn->kn_fop = &tunwrite_filtops; break; default: return (EINVAL); } - kn->kn_hook = (caddr_t)tp; + kn->kn_hook = (caddr_t)sc; s = splhigh(); SLIST_INSERT_HEAD(klist, kn, kn_selnext); @@ -1102,19 +1102,19 @@ void filt_tunrdetach(struct knote *kn) { int s; - struct tun_softc *tp; + struct tun_softc *sc; - tp = (struct tun_softc *)kn->kn_hook; + sc = (struct tun_softc *)kn->kn_hook; s = splhigh(); if (!(kn->kn_status & KN_DETACHED)) - SLIST_REMOVE(&tp->sc_rsel.si_note, kn, knote, kn_selnext); + SLIST_REMOVE(&sc->sc_rsel.si_note, kn, knote, kn_selnext); splx(s); } int filt_tunread(struct knote *kn, long hint) { - struct tun_softc *tp; + struct tun_softc *sc; struct ifnet *ifp; if (kn->kn_status & KN_DETACHED) { @@ -1122,8 +1122,8 @@ filt_tunread(struct knote *kn, long hint) return (1); } - tp = (struct tun_softc *)kn->kn_hook; - ifp = &tp->sc_if; + sc = (struct tun_softc *)kn->kn_hook; + ifp = &sc->sc_if; kn->kn_data = ifq_hdatalen(&ifp->if_snd); @@ -1134,19 +1134,19 @@ void filt_tunwdetach(struct knote *kn) { int s; - struct tun_softc *tp; + struct tun_softc *sc; - tp = (struct tun_softc *)kn->kn_hook; + sc = (struct tun_softc *)kn->kn_hook; s = splhigh(); if (!(kn->kn_status & KN_DETACHED)) - SLIST_REMOVE(&tp->sc_wsel.si_note, kn, knote, kn_selnext); + SLIST_REMOVE(&sc->sc_wsel.si_note, kn, knote, kn_selnext); splx(s); } int filt_tunwrite(struct knote *kn, long hint) { - struct tun_softc *tp; + struct tun_softc *sc; struct ifnet *ifp; if (kn->kn_status & KN_DETACHED) { @@ -1154,8 +1154,8 @@ filt_tunwrite(struct knote *kn, long hint) return (1); } - tp = (struct tun_softc *)kn->kn_hook; - ifp = &tp->sc_if; + sc = (struct tun_softc *)kn->kn_hook; + ifp = &sc->sc_if; kn->kn_data = ifp->if_hdrlen + ifp->if_hardmtu; @@ -1165,22 +1165,22 @@ filt_tunwrite(struct knote *kn, long hint) void tun_start(struct ifnet *ifp) { - struct tun_softc *tp = ifp->if_softc; + struct tun_softc *sc = ifp->if_softc; splassert(IPL_NET); if (IFQ_LEN(&ifp->if_snd)) - tun_wakeup(tp); + tun_wakeup(sc); } void -tun_link_state(struct tun_softc *tp) +tun_link_state(struct tun_softc *sc) { - struct ifnet *ifp = &tp->sc_if; + struct ifnet *ifp = &sc->sc_if; int link_state = LINK_STATE_DOWN; - if (tp->sc_flags & TUN_OPEN) { - if (tp->sc_flags & TUN_LAYER2) + if (sc->sc_flags & TUN_OPEN) { + if (sc->sc_flags & TUN_LAYER2) link_state = LINK_STATE_FULL_DUPLEX; else link_state = LINK_STATE_UP; |