Skip to content

Commit 976c359

Browse files
authored
Avoid circular lwip pcb list (#53)
* don't close tcp_pcb in CLOSED state * null pcbs when closing
1 parent 5f6cdcc commit 976c359

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/tunnel_tcp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ int tunneler_tcp_close(struct tcp_pcb *pcb) {
170170
return 0;
171171
}
172172
ZITI_LOG(INFO, "closing %p, state=%d", pcb, pcb->state);
173+
if (pcb->state == CLOSED) {
174+
return 0;
175+
}
173176
tcp_arg(pcb, NULL);
174177
tcp_recv(pcb, NULL);
175178
err_t err = tcp_close(pcb);

lib/ziti_tunnel.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,11 @@ int ziti_tunneler_close(tunneler_io_context *tnlr_io_ctx) {
177177
switch ((*tnlr_io_ctx)->proto) {
178178
case tun_tcp:
179179
tunneler_tcp_close((*tnlr_io_ctx)->tcp);
180+
(*tnlr_io_ctx)->tcp = NULL;
180181
break;
181182
case tun_udp:
182183
tunneler_udp_close((*tnlr_io_ctx)->udp.pcb);
184+
(*tnlr_io_ctx)->udp.pcb = NULL;
183185
break;
184186
default:
185187
ZITI_LOG(ERROR, "unknown proto %d", (*tnlr_io_ctx)->proto);
@@ -272,7 +274,7 @@ static void run_packet_loop(uv_loop_t *loop, tunneler_context tnlr_ctx) {
272274
}
273275

274276
uv_timer_init(loop, &tnlr_ctx->lwip_timer_req);
275-
uv_timer_start(&tnlr_ctx->lwip_timer_req, check_lwip_timeouts, 0, 100);
277+
uv_timer_start(&tnlr_ctx->lwip_timer_req, check_lwip_timeouts, 0, 10);
276278
}
277279

278280
#define _str(x) #x

programs/ziti-edge-tunnel/dnsmasq_manager.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ static int apply_address(dns_manager *dns, const char *hostname, const char *ip)
3737
char entry[512];
3838
int c = snprintf(entry, sizeof(entry), "%s\t%s", ip, hostname);
3939
FILE *rec = fopen(fname, "wb");
40+
if (rec == NULL) {
41+
return 1;
42+
}
4043
fwrite(entry, 1, c, rec);
4144
fflush(rec);
4245
fclose(rec);

0 commit comments

Comments
 (0)