From: Matt Corallo Date: Tue, 11 May 2021 23:36:00 +0000 (+0000) Subject: Fix checksum offset calculation X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=9779a53938e32d7d81f3c45346731cb06401ae94;p=flowspec-xdp Fix checksum offset calculation --- diff --git a/genrules.py b/genrules.py index db138a8..da42e01 100755 --- a/genrules.py +++ b/genrules.py @@ -439,7 +439,8 @@ with open("rules.h", "w") as out: write_rule("uint8_t orig_tos = ip->tos;") write_rule("ip->tos = (ip->tos & 3) | " + str(low_bytes << 2) + ";") write_rule("chk = (chk - orig_tos + ip->tos);") - write_rule("if (unlikely(chk < 0)) { chk += 65534; }") + write_rule("if (unlikely(chk > 0xffff)) { chk -= 65535; }") + write_rule("else if (unlikely(chk < 0)) { chk += 65535; }") write_rule("ip->check = ~BE16(chk);") else: write_rule("ip6->priority = " + str(low_bytes >> 2) + ";")