tun_freebsd: reuse existing TUN interface on SIOCIFCREATE EEXIST
This commit is contained in:
1 parent
952504d8eb
commit
af382403ec
1 file changed
+7
-3
+7
-3
@@ -77,9 +77,13 @@ static int create_tun_device(char *ifname, size_t ifname_len) {
|
||||
strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
|
||||
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
|
||||
if (ioctl(sock, SIOCIFCREATE, &ifr) < 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "SIOCIFCREATE failed for %s: %s", ifname, strerror(errno));
|
||||
close(sock);
|
||||
return -1;
|
||||
if (errno == EEXIST) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_TUN, "TUN interface %s already exists, reusing it", ifname);
|
||||
} else {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "SIOCIFCREATE failed for %s: %s", ifname, strerror(errno));
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
close(sock);
|
||||
|
||||
|
||||
Reference in new issue
Block a user