Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Split ESP checksum functions into csum_partial and csum_finish
csum_partial() feeds more uint16_t words into the checksummer;
csum_finish() does the final condensation down to uint16_t, and
conversion to network order.

[dwmw2: Note this still doesn't cope with odd-sized packets but
        we don't care for now.]

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
  • Loading branch information
dlenski authored and dwmw2 committed Apr 28, 2021
1 parent eef5e65 commit 4b3c6c1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion gpst.c
Expand Up @@ -1306,16 +1306,26 @@ int gpst_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
}

#ifdef HAVE_ESP
static uint16_t csum(uint16_t *buf, int nwords)
static inline uint32_t csum_partial(uint16_t *buf, int nwords)
{
uint32_t sum = 0;
for(sum=0; nwords>0; nwords--)
sum += ntohs(*buf++);
return sum;
}

static inline uint16_t csum_finish(uint32_t sum)
{
sum = (sum >> 16) + (sum &0xffff);
sum += (sum >> 16);
return htons((uint16_t)(~sum));
}

static inline uint16_t csum(uint16_t *buf, int nwords)
{
return csum_finish(csum_partial(buf, nwords));
}

static char magic_ping_payload[16] = "monitor\x00\x00pan ha ";

int gpst_esp_send_probes(struct openconnect_info *vpninfo)
Expand Down

0 comments on commit 4b3c6c1

Please sign in to comment.