Lines Matching refs:tp

270 tun_destroy(struct tun_softc *tp)  in tun_destroy()  argument
274 mtx_lock(&tp->tun_mtx); in tun_destroy()
275 tp->tun_flags |= TUN_DYING; in tun_destroy()
276 if ((tp->tun_flags & TUN_OPEN) != 0) in tun_destroy()
277 cv_wait_unlock(&tp->tun_cv, &tp->tun_mtx); in tun_destroy()
279 mtx_unlock(&tp->tun_mtx); in tun_destroy()
281 CURVNET_SET(TUN2IFP(tp)->if_vnet); in tun_destroy()
283 dev = tp->tun_dev; in tun_destroy()
284 bpfdetach(TUN2IFP(tp)); in tun_destroy()
285 if_detach(TUN2IFP(tp)); in tun_destroy()
288 TUN2IFP(tp)->if_softc = NULL; in tun_destroy()
291 free_unr(tun_unrhdr, TUN2IFP(tp)->if_dunit); in tun_destroy()
292 if_free(TUN2IFP(tp)); in tun_destroy()
294 seldrain(&tp->tun_rsel); in tun_destroy()
295 knlist_clear(&tp->tun_rsel.si_note, 0); in tun_destroy()
296 knlist_destroy(&tp->tun_rsel.si_note); in tun_destroy()
297 mtx_destroy(&tp->tun_mtx); in tun_destroy()
298 cv_destroy(&tp->tun_cv); in tun_destroy()
299 free(tp, M_TUN); in tun_destroy()
306 struct tun_softc *tp = ifp->if_softc; in tun_clone_destroy() local
309 TAILQ_REMOVE(&tunhead, tp, tun_list); in tun_clone_destroy()
311 tun_destroy(tp); in tun_clone_destroy()
336 struct tun_softc *tp; in tun_uninit() local
342 while ((tp = TAILQ_FIRST(&tunhead)) != NULL) { in tun_uninit()
343 TAILQ_REMOVE(&tunhead, tp, tun_list); in tun_uninit()
345 tun_destroy(tp); in tun_uninit()
389 struct tun_softc *tp = ifp->if_softc; in tunstart() local
403 mtx_lock(&tp->tun_mtx); in tunstart()
404 if (tp->tun_flags & TUN_RWAIT) { in tunstart()
405 tp->tun_flags &= ~TUN_RWAIT; in tunstart()
406 wakeup(tp); in tunstart()
408 selwakeuppri(&tp->tun_rsel, PZERO + 1); in tunstart()
409 KNOTE_LOCKED(&tp->tun_rsel.si_note, 0); in tunstart()
410 if (tp->tun_flags & TUN_ASYNC && tp->tun_sigio) { in tunstart()
411 mtx_unlock(&tp->tun_mtx); in tunstart()
412 pgsigio(&tp->tun_sigio, SIGIO, 0); in tunstart()
414 mtx_unlock(&tp->tun_mtx); in tunstart()
462 struct tun_softc *tp; in tunopen() local
468 tp = dev->si_drv1; in tunopen()
469 if (!tp) { in tunopen()
471 tp = dev->si_drv1; in tunopen()
474 mtx_lock(&tp->tun_mtx); in tunopen()
475 if ((tp->tun_flags & (TUN_OPEN | TUN_DYING)) != 0) { in tunopen()
476 mtx_unlock(&tp->tun_mtx); in tunopen()
480 tp->tun_pid = td->td_proc->p_pid; in tunopen()
481 tp->tun_flags |= TUN_OPEN; in tunopen()
482 ifp = TUN2IFP(tp); in tunopen()
485 mtx_unlock(&tp->tun_mtx); in tunopen()
498 struct tun_softc *tp; in tunclose() local
502 tp = dev->si_drv1; in tunclose()
503 ifp = TUN2IFP(tp); in tunclose()
505 mtx_lock(&tp->tun_mtx); in tunclose()
515 if (p->p_pid != tp->tun_pid) { in tunclose()
528 mtx_unlock(&tp->tun_mtx); in tunclose()
530 mtx_lock(&tp->tun_mtx); in tunclose()
538 mtx_unlock(&tp->tun_mtx); in tunclose()
543 tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0); in tunclose()
549 mtx_lock(&tp->tun_mtx); in tunclose()
554 funsetown(&tp->tun_sigio); in tunclose()
555 selwakeuppri(&tp->tun_rsel, PZERO + 1); in tunclose()
556 KNOTE_LOCKED(&tp->tun_rsel.si_note, 0); in tunclose()
558 tp->tun_flags &= ~TUN_OPEN; in tunclose()
559 tp->tun_pid = 0; in tunclose()
561 cv_broadcast(&tp->tun_cv); in tunclose()
562 mtx_unlock(&tp->tun_mtx); in tunclose()
569 struct tun_softc *tp = ifp->if_softc; in tuninit() local
576 mtx_lock(&tp->tun_mtx); in tuninit()
589 tp->tun_flags |= TUN_IASET; in tuninit()
593 tp->tun_flags |= TUN_DSTADDR; in tuninit()
598 mtx_unlock(&tp->tun_mtx); in tuninit()
608 struct tun_softc *tp; in tunifioctl() local
613 tp = ifp->if_softc; in tunifioctl()
614 if (tp == NULL) { in tunifioctl()
621 mtx_lock(&tp->tun_mtx); in tunifioctl()
622 if (tp->tun_pid) in tunifioctl()
624 "\tOpened by PID %d\n", tp->tun_pid); in tunifioctl()
627 mtx_unlock(&tp->tun_mtx); in tunifioctl()
656 struct tun_softc *tp = ifp->if_softc; in tunoutput() local
672 mtx_lock(&tp->tun_mtx); in tunoutput()
673 cached_tun_flags = tp->tun_flags; in tunoutput()
674 mtx_unlock(&tp->tun_mtx); in tunoutput()
676 TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags); in tunoutput()
746 struct tun_softc *tp = dev->si_drv1; in tunioctl() local
753 strlcpy(ifrp->ifr_name, TUN2IFP(tp)->if_xname, IFNAMSIZ); in tunioctl()
757 if (TUN2IFP(tp)->if_type != tunp->type) in tunioctl()
759 mtx_lock(&tp->tun_mtx); in tunioctl()
760 if (TUN2IFP(tp)->if_mtu != tunp->mtu) { in tunioctl()
761 strlcpy(ifr.ifr_name, if_name(TUN2IFP(tp)), IFNAMSIZ); in tunioctl()
763 CURVNET_SET(TUN2IFP(tp)->if_vnet); in tunioctl()
764 error = ifhwioctl(SIOCSIFMTU, TUN2IFP(tp), in tunioctl()
768 mtx_unlock(&tp->tun_mtx); in tunioctl()
772 TUN2IFP(tp)->if_baudrate = tunp->baudrate; in tunioctl()
773 mtx_unlock(&tp->tun_mtx); in tunioctl()
777 mtx_lock(&tp->tun_mtx); in tunioctl()
778 tunp->mtu = TUN2IFP(tp)->if_mtu; in tunioctl()
779 tunp->type = TUN2IFP(tp)->if_type; in tunioctl()
780 tunp->baudrate = TUN2IFP(tp)->if_baudrate; in tunioctl()
781 mtx_unlock(&tp->tun_mtx); in tunioctl()
790 mtx_lock(&tp->tun_mtx); in tunioctl()
792 tp->tun_flags |= TUN_LMODE; in tunioctl()
793 tp->tun_flags &= ~TUN_IFHEAD; in tunioctl()
795 tp->tun_flags &= ~TUN_LMODE; in tunioctl()
796 mtx_unlock(&tp->tun_mtx); in tunioctl()
799 mtx_lock(&tp->tun_mtx); in tunioctl()
801 tp->tun_flags |= TUN_IFHEAD; in tunioctl()
802 tp->tun_flags &= ~TUN_LMODE; in tunioctl()
804 tp->tun_flags &= ~TUN_IFHEAD; in tunioctl()
805 mtx_unlock(&tp->tun_mtx); in tunioctl()
808 mtx_lock(&tp->tun_mtx); in tunioctl()
809 *(int *)data = (tp->tun_flags & TUN_IFHEAD) ? 1 : 0; in tunioctl()
810 mtx_unlock(&tp->tun_mtx); in tunioctl()
814 if (TUN2IFP(tp)->if_flags & IFF_UP) in tunioctl()
820 mtx_lock(&tp->tun_mtx); in tunioctl()
821 TUN2IFP(tp)->if_flags &= in tunioctl()
823 TUN2IFP(tp)->if_flags |= *(int *)data; in tunioctl()
824 mtx_unlock(&tp->tun_mtx); in tunioctl()
831 mtx_lock(&tp->tun_mtx); in tunioctl()
832 tp->tun_pid = curthread->td_proc->p_pid; in tunioctl()
833 mtx_unlock(&tp->tun_mtx); in tunioctl()
838 mtx_lock(&tp->tun_mtx); in tunioctl()
840 tp->tun_flags |= TUN_ASYNC; in tunioctl()
842 tp->tun_flags &= ~TUN_ASYNC; in tunioctl()
843 mtx_unlock(&tp->tun_mtx); in tunioctl()
846 if (!IFQ_IS_EMPTY(&TUN2IFP(tp)->if_snd)) { in tunioctl()
848 IFQ_LOCK(&TUN2IFP(tp)->if_snd); in tunioctl()
849 IFQ_POLL_NOLOCK(&TUN2IFP(tp)->if_snd, mb); in tunioctl()
852 IFQ_UNLOCK(&TUN2IFP(tp)->if_snd); in tunioctl()
857 return (fsetown(*(int *)data, &tp->tun_sigio)); in tunioctl()
860 *(int *)data = fgetown(&tp->tun_sigio); in tunioctl()
865 return (fsetown(-(*(int *)data), &tp->tun_sigio)); in tunioctl()
869 *(int *)data = -fgetown(&tp->tun_sigio); in tunioctl()
885 struct tun_softc *tp = dev->si_drv1; in tunread() local
886 struct ifnet *ifp = TUN2IFP(tp); in tunread()
891 mtx_lock(&tp->tun_mtx); in tunread()
892 if ((tp->tun_flags & TUN_READY) != TUN_READY) { in tunread()
893 mtx_unlock(&tp->tun_mtx); in tunread()
894 TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags); in tunread()
898 tp->tun_flags &= ~TUN_RWAIT; in tunread()
904 mtx_unlock(&tp->tun_mtx); in tunread()
907 tp->tun_flags |= TUN_RWAIT; in tunread()
908 error = mtx_sleep(tp, &tp->tun_mtx, PCATCH | (PZERO + 1), in tunread()
911 mtx_unlock(&tp->tun_mtx); in tunread()
916 mtx_unlock(&tp->tun_mtx); in tunread()
938 struct tun_softc *tp = dev->si_drv1; in tunwrite() local
939 struct ifnet *ifp = TUN2IFP(tp); in tunwrite()
954 if (tp->tun_flags & TUN_IFHEAD) in tunwrite()
972 mtx_lock(&tp->tun_mtx); in tunwrite()
973 if (tp->tun_flags & TUN_IFHEAD) { in tunwrite()
974 mtx_unlock(&tp->tun_mtx); in tunwrite()
981 mtx_unlock(&tp->tun_mtx); in tunwrite()
1020 struct tun_softc *tp = dev->si_drv1; in tunpoll() local
1021 struct ifnet *ifp = TUN2IFP(tp); in tunpoll()
1035 selrecord(td, &tp->tun_rsel); in tunpoll()
1051 struct tun_softc *tp = dev->si_drv1; in tunkqfilter() local
1052 struct ifnet *ifp = TUN2IFP(tp); in tunkqfilter()
1073 kn->kn_hook = tp; in tunkqfilter()
1074 knlist_add(&tp->tun_rsel.si_note, kn, 0); in tunkqfilter()
1086 struct tun_softc *tp = kn->kn_hook; in tunkqread() local
1087 struct cdev *dev = tp->tun_dev; in tunkqread()
1088 struct ifnet *ifp = TUN2IFP(tp); in tunkqread()
1111 struct tun_softc *tp = kn->kn_hook; in tunkqwrite() local
1112 struct ifnet *ifp = TUN2IFP(tp); in tunkqwrite()
1122 struct tun_softc *tp = kn->kn_hook; in tunkqdetach() local
1124 knlist_remove(&tp->tun_rsel.si_note, kn, 0); in tunkqdetach()