Module Name: src Committed By: pgoyette Date: Mon Mar 25 09:07:24 UTC 2019
Modified Files: src/sys/net: if_tun.c Log Message: Resequence the stuff in tundetach() to ensure that no new device units can be created by either 'ifconfig create' or 'open("/dev/tun0")' paths. Note: previous efforts at fixing 'modunload if_tun' are abandoned, since there is no bug. Just need to ensure that the cloned interface is both close(1)d _and_ 'ifconfig tunx destroy' before trying to unload. To generate a diff of this commit: cvs rdiff -u -r1.153 -r1.154 src/sys/net/if_tun.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_tun.c diff -u src/sys/net/if_tun.c:1.153 src/sys/net/if_tun.c:1.154 --- src/sys/net/if_tun.c:1.153 Mon Mar 25 04:06:36 2019 +++ src/sys/net/if_tun.c Mon Mar 25 09:07:24 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tun.c,v 1.153 2019/03/25 04:06:36 msaitoh Exp $ */ +/* $NetBSD: if_tun.c,v 1.154 2019/03/25 09:07:24 pgoyette Exp $ */ /* * Copyright (c) 1988, Julian Onions <j...@cs.nott.ac.uk> @@ -19,7 +19,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.153 2019/03/25 04:06:36 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.154 2019/03/25 09:07:24 pgoyette Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -144,19 +144,26 @@ tundetach(void) { int error = 0; - if (!LIST_EMPTY(&tun_softc_list) || !LIST_EMPTY(&tunz_softc_list)) - error = EBUSY; + if_clone_detach(&tun_cloner); +#ifdef _MODULE + error = devsw_detach(NULL, &tun_cdevsw); + if (error != 0) { + if_clone_attach(&tun_cloner); + return error; + } +#endif + if (!LIST_EMPTY(&tun_softc_list) || !LIST_EMPTY(&tunz_softc_list)) { #ifdef _MODULE - if (error == 0) - error = devsw_detach(NULL, &tun_cdevsw); + devsw_attach("tun", NULL, &tun_bmajor, &tun_cdevsw, &tun_cmajor); #endif - if (error == 0) { - if_clone_detach(&tun_cloner); - mutex_destroy(&tun_softc_lock); - } + if_clone_attach(&tun_cloner); + return EBUSY; +} - return error; + mutex_destroy(&tun_softc_lock); + + return 0; } /*