]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Split ESP checksum functions into csum_partial and csum_finish
authorDaniel Lenski <dlenski@gmail.com>
Fri, 23 Apr 2021 01:58:03 +0000 (18:58 -0700)
committerDavid Woodhouse <dwmw2@infradead.org>
Wed, 28 Apr 2021 10:07:27 +0000 (11:07 +0100)
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>
gpst.c

diff --git a/gpst.c b/gpst.c
index c3d0b5ede850a5c0178f33ff2906d259d7389b4b..d5c428907f47e01b6e741d71397b8ba4a0aa3284 100644 (file)
--- 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)