Skip to content

Commit

Permalink
Avoid circular lwip pcb list (#53)
Browse files Browse the repository at this point in the history
* don't close tcp_pcb in CLOSED state

* null pcbs when closing
  • Loading branch information
scareything authored Oct 26, 2020
1 parent 5f6cdcc commit 976c359
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/tunnel_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ int tunneler_tcp_close(struct tcp_pcb *pcb) {
return 0;
}
ZITI_LOG(INFO, "closing %p, state=%d", pcb, pcb->state);
if (pcb->state == CLOSED) {
return 0;
}
tcp_arg(pcb, NULL);
tcp_recv(pcb, NULL);
err_t err = tcp_close(pcb);
Expand Down
4 changes: 3 additions & 1 deletion lib/ziti_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ int ziti_tunneler_close(tunneler_io_context *tnlr_io_ctx) {
switch ((*tnlr_io_ctx)->proto) {
case tun_tcp:
tunneler_tcp_close((*tnlr_io_ctx)->tcp);
(*tnlr_io_ctx)->tcp = NULL;
break;
case tun_udp:
tunneler_udp_close((*tnlr_io_ctx)->udp.pcb);
(*tnlr_io_ctx)->udp.pcb = NULL;
break;
default:
ZITI_LOG(ERROR, "unknown proto %d", (*tnlr_io_ctx)->proto);
Expand Down Expand Up @@ -272,7 +274,7 @@ static void run_packet_loop(uv_loop_t *loop, tunneler_context tnlr_ctx) {
}

uv_timer_init(loop, &tnlr_ctx->lwip_timer_req);
uv_timer_start(&tnlr_ctx->lwip_timer_req, check_lwip_timeouts, 0, 100);
uv_timer_start(&tnlr_ctx->lwip_timer_req, check_lwip_timeouts, 0, 10);
}

#define _str(x) #x
Expand Down
3 changes: 3 additions & 0 deletions programs/ziti-edge-tunnel/dnsmasq_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ static int apply_address(dns_manager *dns, const char *hostname, const char *ip)
char entry[512];
int c = snprintf(entry, sizeof(entry), "%s\t%s", ip, hostname);
FILE *rec = fopen(fname, "wb");
if (rec == NULL) {
return 1;
}
fwrite(entry, 1, c, rec);
fflush(rec);
fclose(rec);
Expand Down

0 comments on commit 976c359

Please sign in to comment.