Skip to content

Commit

Permalink
After DPD, keep retrying to connect for longer.
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Dec 11, 2008
1 parent c7cb879 commit d4f2bdf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cstp.c
Expand Up @@ -291,8 +291,10 @@ static int start_cstp_connection(struct openconnect_info *vpninfo)

int make_cstp_connection(struct openconnect_info *vpninfo)
{
if (!vpninfo->https_ssl && openconnect_open_https(vpninfo))
exit(1);
int ret;

if (!vpninfo->https_ssl && (ret=openconnect_open_https(vpninfo)))
return ret;

if (vpninfo->deflate) {
vpninfo->deflate_adler32 = 1;
Expand All @@ -317,13 +319,24 @@ int make_cstp_connection(struct openconnect_info *vpninfo)
}
}

if (start_cstp_connection(vpninfo))
return -EINVAL;
return start_cstp_connection(vpninfo);
}

static int cstp_reconnect(struct openconnect_info *vpninfo)
{
int retries, nr_retries, ret;

nr_retries = vpninfo->reconnect_timeout / vpninfo->reconnect_interval;

while ((ret = make_cstp_connection(vpninfo))) {
retries++;
if (retries >= nr_retries)
return ret;
sleep(vpninfo->reconnect_interval);
}
return 0;
}


static int inflate_and_queue_packet(struct openconnect_info *vpninfo, int type, void *buf, int len)
{
struct pkt *new = malloc(sizeof(struct pkt) + vpninfo->mtu);
Expand Down Expand Up @@ -528,7 +541,7 @@ int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout)
if (vpninfo->current_ssl_pkt == vpninfo->deflate_pkt)
vpninfo->current_ssl_pkt = NULL;

if (make_cstp_connection(vpninfo)) {
if (cstp_reconnect(vpninfo)) {
vpninfo->progress(vpninfo, PRG_ERR, "Reconnect failed\n");
vpninfo->quit_reason = "SSL DPD detected dead peer; reconnect failed";
return 1;
Expand Down
2 changes: 2 additions & 0 deletions main.c
Expand Up @@ -155,6 +155,8 @@ int main(int argc, char **argv)
vpninfo->deflate = 1;
vpninfo->dtls_attempt_period = 60;
vpninfo->max_qlen = 10;
vpninfo->reconnect_interval = 20;
vpninfo->reconnect_timeout = 300;

if (RAND_bytes(vpninfo->dtls_secret, sizeof(vpninfo->dtls_secret)) != 1) {
fprintf(stderr, "Failed to initialise DTLS secret\n");
Expand Down
2 changes: 2 additions & 0 deletions openconnect.h
Expand Up @@ -106,6 +106,8 @@ struct openconnect_info {
z_stream deflate_strm;
uint32_t deflate_adler32;

int reconnect_timeout;
int reconnect_interval;
int dtls_attempt_period;
time_t new_dtls_started;
SSL_CTX *dtls_ctx;
Expand Down

0 comments on commit d4f2bdf

Please sign in to comment.