Browse Source

wintun bugfix

nodeinfo-routing-update
jeka 1 week ago
parent
commit
6f045a011c
  1. 2
      src/tun_if.c
  2. 16
      src/tun_windows.c

2
src/tun_if.c

@ -62,7 +62,7 @@ static void tun_read_callback(int fd, void* user_arg)
if (queue_data_put(tun->output_queue, pkt, 0) != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "Failed to add packet to output queue");
u_free(packet_data);
memory_pool_free(tun->pool, pkt);
queue_entry_free(pkt);
tun->read_errors++;
return;
}

16
src/tun_windows.c

@ -255,7 +255,7 @@ DWORD WINAPI tun_read_thread_proc(LPVOID arg)
BYTE* wintun_pkt = WintunReceivePacket(session, &size);
if (!wintun_pkt) {
if (GetLastError() == ERROR_NO_MORE_ITEMS)
break; /* нормально — пакетов больше нет */
break;
tun->read_errors++;
break;
}
@ -265,16 +265,16 @@ DWORD WINAPI tun_read_thread_proc(LPVOID arg)
continue;
}
/* === ОДНО копирование (+1 for prefix byte) === */
uint8_t* data = u_malloc(size + 1);
if (!data) {
WintunReleaseReceivePacket(session, wintun_pkt);
tun->read_errors++;
continue;
}
data[0] = 0; // Prefix byte
data[0] = 0;
memcpy(data + 1, wintun_pkt, size);
WintunReleaseReceivePacket(session, wintun_pkt); /* сразу отдаём кольцо */
WintunReleaseReceivePacket(session, wintun_pkt);
// struct ll_entry* pkt = queue_entry_new_from_pool(tun->pool);// from pool нельзя - нет thred safe (memory consistency)
struct ll_entry* pkt = queue_entry_new(0);
@ -283,20 +283,19 @@ DWORD WINAPI tun_read_thread_proc(LPVOID arg)
tun->read_errors++;
continue;
}
pkt->dgram = data;
pkt->len = size + 1;
struct tun_packet_data* pd = u_malloc(sizeof(*pd));
if (!pd) {
u_free(data);
memory_pool_free(tun->pool, pkt);
queue_entry_free(pkt);
tun->read_errors++;
continue;
}
pd->tun = tun;
pd->entry = (struct ll_entry*)pkt;
pd->entry = pkt;
tun->bytes_read += size + 1;
tun->packets_read ++;
@ -306,10 +305,9 @@ DWORD WINAPI tun_read_thread_proc(LPVOID arg)
}
uasync_post(tun->ua, tun_packet_handler, pd);
// DEBUG_DEBUG(DEBUG_CATEGORY_TUN, "POST done");
}
}
DEBUG_DEBUG(DEBUG_CATEGORY_TUN, "TUN exit");
DEBUG_DEBUG(DEBUG_CATEGORY_TUN, "TUN read thread exit");
return 0;
}

Loading…
Cancel
Save