Skip to content

Commit

Permalink
Eliminate memcpy() for incoming packets from DTLS
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 12, 2011
1 parent 337cf1a commit b0f4d00
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions dtls.c
Expand Up @@ -430,14 +430,29 @@ int setup_dtls(struct openconnect_info *vpninfo)
return 0;
}

static struct pkt *dtls_pkt;

int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout)
{
unsigned char buf[2000];
int len;
int work_done = 0;
char magic_pkt;

while ( (len = SSL_read(vpninfo->dtls_ssl, buf, sizeof(buf))) > 0 ) {
while (1) {
int len = vpninfo->mtu;
unsigned char *buf;

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

buf = dtls_pkt->data - 1;
len = SSL_read(vpninfo->dtls_ssl, buf, len + 1);
if (len <= 0)
break;

vpn_progress(vpninfo, PRG_TRACE,
_("Received DTLS packet 0x%02x of %d bytes\n"),
Expand Down

0 comments on commit b0f4d00

Please sign in to comment.