* tundtor - tear down the device - mark i/f down & delete * routing info */
| 1107 | * routing info |
| 1108 | */ |
| 1109 | static void |
| 1110 | tundtor(void *data) |
| 1111 | { |
| 1112 | struct proc *p; |
| 1113 | struct tuntap_softc *tp; |
| 1114 | struct ifnet *ifp; |
| 1115 | bool l2tun; |
| 1116 | |
| 1117 | tp = data; |
| 1118 | p = curproc; |
| 1119 | ifp = TUN2IFP(tp); |
| 1120 | |
| 1121 | TUN_LOCK(tp); |
| 1122 | |
| 1123 | /* |
| 1124 | * Realistically, we can't be obstinate here. This only means that the |
| 1125 | * tuntap device was closed out of order, and the last closer wasn't the |
| 1126 | * controller. These are still good to know about, though, as software |
| 1127 | * should avoid multiple processes with a tuntap device open and |
| 1128 | * ill-defined transfer of control (e.g., handoff, TUNSIFPID, close in |
| 1129 | * parent). |
| 1130 | */ |
| 1131 | if (p->p_pid != tp->tun_pid) { |
| 1132 | log(LOG_INFO, |
| 1133 | "pid %d (%s), %s: tun/tap protocol violation, non-controlling process closed last.\n", |
| 1134 | p->p_pid, p->p_comm, tp->tun_dev->si_name); |
| 1135 | } |
| 1136 | |
| 1137 | /* |
| 1138 | * junk all pending output |
| 1139 | */ |
| 1140 | CURVNET_SET(ifp->if_vnet); |
| 1141 | |
| 1142 | l2tun = false; |
| 1143 | if ((tp->tun_flags & TUN_L2) != 0) { |
| 1144 | l2tun = true; |
| 1145 | IF_DRAIN(&ifp->if_snd); |
| 1146 | } else { |
| 1147 | IFQ_PURGE(&ifp->if_snd); |
| 1148 | } |
| 1149 | |
| 1150 | /* For vmnet, we won't do most of the address/route bits */ |
| 1151 | if ((tp->tun_flags & TUN_VMNET) != 0 || |
| 1152 | (l2tun && (ifp->if_flags & IFF_LINK0) != 0)) |
| 1153 | goto out; |
| 1154 | |
| 1155 | if (ifp->if_flags & IFF_UP) { |
| 1156 | TUN_UNLOCK(tp); |
| 1157 | if_down(ifp); |
| 1158 | TUN_LOCK(tp); |
| 1159 | } |
| 1160 | |
| 1161 | /* Delete all addresses and routes which reference this interface. */ |
| 1162 | if (ifp->if_drv_flags & IFF_DRV_RUNNING) { |
| 1163 | ifp->if_drv_flags &= ~IFF_DRV_RUNNING; |
| 1164 | TUN_UNLOCK(tp); |
| 1165 | if_purgeaddrs(ifp); |
| 1166 | TUN_LOCK(tp); |
nothing calls this directly
no test coverage detected