Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Kill static dtls_pkt
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 6, 2015
1 parent 3c516fa commit 50b0850
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions cstp.c
Expand Up @@ -623,6 +623,11 @@ static int cstp_reconnect(struct openconnect_info *vpninfo)
timeout = vpninfo->reconnect_timeout;
interval = vpninfo->reconnect_interval;

free(vpninfo->dtls_pkt);
vpninfo->dtls_pkt = NULL;
free(vpninfo->tun_pkt);
vpninfo->tun_pkt = NULL;

while ((ret = openconnect_make_cstp_connection(vpninfo))) {
if (timeout <= 0)
return ret;
Expand Down
18 changes: 7 additions & 11 deletions dtls.c
Expand Up @@ -677,9 +677,6 @@ int openconnect_setup_dtls(struct openconnect_info *vpninfo, int dtls_attempt_pe
return 0;
}

static struct pkt *dtls_pkt;
static int dtls_pkt_max;

int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout)
{
int work_done = 0;
Expand Down Expand Up @@ -712,16 +709,15 @@ int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout)
int len = vpninfo->ip_info.mtu;
unsigned char *buf;

if (!dtls_pkt || len > dtls_pkt_max) {
realloc_inplace(dtls_pkt, sizeof(struct pkt) + len);
if (!dtls_pkt) {
if (!vpninfo->dtls_pkt) {
vpninfo->dtls_pkt = malloc(sizeof(struct pkt) + len);
if (!vpninfo->dtls_pkt) {
vpn_progress(vpninfo, PRG_ERR, "Allocation failed\n");
break;
}
dtls_pkt_max = len;
}

buf = dtls_pkt->data - 1;
buf = vpninfo->dtls_pkt->data - 1;
len = DTLS_RECV(vpninfo->dtls_ssl, buf, len + 1);
if (len <= 0)
break;
Expand All @@ -734,9 +730,9 @@ int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout)

switch (buf[0]) {
case AC_PKT_DATA:
dtls_pkt->len = len - 1;
queue_packet(&vpninfo->incoming_queue, dtls_pkt);
dtls_pkt = NULL;
vpninfo->dtls_pkt->len = len - 1;
queue_packet(&vpninfo->incoming_queue, vpninfo->dtls_pkt);
vpninfo->dtls_pkt = NULL;
work_done = 1;
break;

Expand Down
1 change: 1 addition & 0 deletions library.c
Expand Up @@ -294,6 +294,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)

free(vpninfo->deflate_pkt);
free(vpninfo->tun_pkt);
free(vpninfo->dtls_pkt);
free(vpninfo);
}

Expand Down
11 changes: 7 additions & 4 deletions openconnect-internal.h
Expand Up @@ -352,11 +352,14 @@ struct openconnect_info {
struct pin_cache *pin_cache;
struct keepalive_info ssl_times;
int owe_ssl_dpd_response;
int deflate_pkt_size;
struct pkt *deflate_pkt;
struct pkt *current_ssl_pkt;
struct pkt *pending_deflated_pkt;

int deflate_pkt_size; /* It may need to be larger than MTU */
struct pkt *deflate_pkt; /* For compressing outbound packets into */
struct pkt *pending_deflated_pkt; /* The original packet associated with above */
struct pkt *current_ssl_pkt; /* Partially sent SSL packet */

/* Packet buffers for receiving into */
struct pkt *dtls_pkt;
struct pkt *tun_pkt;

z_stream inflate_strm;
Expand Down

0 comments on commit 50b0850

Please sign in to comment.