Fix: Add ifindex field for Linux

- Move ifindex field outside WIN32 conditional block
- Initialize ifindex in Linux tun_platform_init()
This commit is contained in:
jeka committed 2026-02-28 16:31:04 +03:00
1 parent f821ab9640
commit 06f58f5e2e
2 files changed
+7 -1

No files matched your search

+2 -1
View File
@@ -50,13 +50,14 @@ struct tun_if {
uint32_t packets_written; uint32_t packets_written;
uint32_t read_errors; uint32_t read_errors;
uint32_t write_errors; uint32_t write_errors;
uint32_t ifindex; // интерфейсный индекс
#ifdef _WIN32 #ifdef _WIN32
CRITICAL_SECTION output_queue_lock; // защита output_queue (TUN → routing) CRITICAL_SECTION output_queue_lock; // защита output_queue (TUN → routing)
HANDLE read_thread; HANDLE read_thread;
HANDLE stop_event; HANDLE stop_event;
volatile int running; // 1 = поток работает volatile int running; // 1 = поток работает
DWORD ifindex; // Windows: интерфейсный индекс
#endif #endif
}; };
+5
View File
@@ -195,6 +195,11 @@ int tun_platform_init(struct tun_if* tun, const char* ifname, const char* ip_str
tun->fd = -1; tun->fd = -1;
return -1; return -1;
} }
tun->ifindex = if_nametoindex(tun->ifname);
if (tun->ifindex == 0) {
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "Failed to get ifindex for %s", tun->ifname);
}
// Set non-blocking mode // Set non-blocking mode
int flags = fcntl(tun->fd, F_GETFL, 0); int flags = fcntl(tun->fd, F_GETFL, 0);