From: Daniel Lenski Date: Fri, 23 Apr 2021 01:58:03 +0000 (-0700) Subject: Split ESP checksum functions into csum_partial and csum_finish X-Git-Tag: v8.20~249 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4b3c6c1130ed8ff97090ac896dd1a1adb88ac40d;p=users%2Fdwmw2%2Fopenconnect.git 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 --- diff --git a/gpst.c b/gpst.c index c3d0b5ed..d5c42890 100644 --- a/gpst.c +++ b/gpst.c @@ -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)