tun_freebsd: reuse existing TUN interface on SIOCIFCREATE EEXIST

This commit is contained in:
evgeny committed 2026-09-14 23:17:59 +03:00
1 parent 952504d8eb
commit af382403ec
1 file changed
+7 -3
+7 -3
View File
@@ -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);