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) { if (queue_data_put(tun->output_queue, pkt, 0) != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "Failed to add packet to output queue"); DEBUG_ERROR(DEBUG_CATEGORY_TUN, "Failed to add packet to output queue");
u_free(packet_data); u_free(packet_data);
memory_pool_free(tun->pool, pkt); queue_entry_free(pkt);
tun->read_errors++; tun->read_errors++;
return; return;
} }

16
src/tun_windows.c

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

Loading…
Cancel
Save