Browse Source

Fix: Add ifindex field for Linux

- Move ifindex field outside WIN32 conditional block
- Initialize ifindex in Linux tun_platform_init()
nodeinfo-routing-update
jeka 1 month ago
parent
commit
06f58f5e2e
  1. 3
      src/tun_if.h
  2. 5
      src/tun_linux.c

3
src/tun_if.h

@ -50,13 +50,14 @@ struct tun_if {
uint32_t packets_written;
uint32_t read_errors;
uint32_t write_errors;
uint32_t ifindex; // интерфейсный индекс
#ifdef _WIN32
CRITICAL_SECTION output_queue_lock; // защита output_queue (TUN → routing)
HANDLE read_thread;
HANDLE stop_event;
volatile int running; // 1 = поток работает
DWORD ifindex; // Windows: интерфейсный индекс
#endif
};

5
src/tun_linux.c

@ -195,6 +195,11 @@ int tun_platform_init(struct tun_if* tun, const char* ifname, const char* ip_str
tun->fd = -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
int flags = fcntl(tun->fd, F_GETFL, 0);

Loading…
Cancel
Save