Close NAT channels after cancelling producers and quiet transient TUN backpressure
This commit is contained in:
1 parent
cfc0051088
commit
41a68b86bc
3 files changed
+15
-1
No files matched your search
@@ -315,6 +315,16 @@ void nat_transport_destroy(struct UTUN_INSTANCE* inst) {
|
||||
struct ll_entry* peer;
|
||||
while ((peer = queue_data_get(tr->peers))) nat_peer_free((struct nat_peer*)peer);
|
||||
queue_free(tr->peers);
|
||||
// После отмены producers закрыть только каналы NAT; остальные сервисы ядра продолжают работать.
|
||||
while (inst->router_conns) {
|
||||
struct ETCP_ROUTER_CONN* route = NULL;
|
||||
for (struct ll_entry* e = inst->router_conns->head; e; e = e->next) {
|
||||
struct ETCP_ROUTER_CONN* candidate = (struct ETCP_ROUTER_CONN*)e;
|
||||
if (candidate->svc_id == ETCP_RT_ID_NAT) { route = candidate; break; }
|
||||
}
|
||||
if (!route) break;
|
||||
etcp_router_conn_close(route);
|
||||
}
|
||||
nat_packet_free(tr->tun_pending);
|
||||
tun_close(tr->nat_tun);
|
||||
eim_nat_destroy_ctx(&inst->nat);
|
||||
|
||||
+3
-1
@@ -255,7 +255,9 @@ ssize_t tun_write(struct tun_if* tun, const uint8_t* buf, size_t len) {
|
||||
} while (n < 0 && errno == EINTR);
|
||||
if (n != (ssize_t)len) {
|
||||
int error = n < 0 ? errno : EIO;
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_TUN, "TUN %s write failed: requested=%zu written=%zd error=%s", tun->ifname, len, n, strerror(error));
|
||||
if (error == EAGAIN || error == EWOULDBLOCK)
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_TUN, "TUN %s write backpressure: requested=%zu", tun->ifname, len);
|
||||
else DEBUG_ERROR(DEBUG_CATEGORY_TUN, "TUN %s write failed: requested=%zu written=%zd error=%s", tun->ifname, len, n, strerror(error));
|
||||
tun->write_errors++;
|
||||
errno = error;
|
||||
return -1;
|
||||
|
||||
@@ -1163,6 +1163,8 @@ static void test_hash_lifecycle(void) {
|
||||
ASSERT_EQ(eim_nat_egress(&ctx, packet, 42, 100000 + i, NULL), EIM_NAT_OK, "reuse freed port");
|
||||
uint16_t external; memcpy(&external, packet + 20, 2);
|
||||
ASSERT_EQ(be16toh(external), removed[i], "free ports reused in FIFO order");
|
||||
}
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
memcpy(packet, original, 42);
|
||||
ASSERT_EQ(eim_nat_egress(&ctx, packet, 42, removed[i], NULL), EIM_NAT_ERROR, "removed key does not alias reused slot");
|
||||
ASSERT(memcmp(packet, original, 42) == 0, "full-pool error preserves packet");
|
||||
|
||||
Reference in new issue
Block a user