]> git.bitcoin.ninja Git - flowspec-xdp/commitdiff
Fix checksum offset calculation
authorMatt Corallo <git@bluematt.me>
Tue, 11 May 2021 23:36:00 +0000 (23:36 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 11 May 2021 23:53:31 +0000 (23:53 +0000)
genrules.py

index db138a8724e7ec4169d66db37bc95cbfbe3eb63d..da42e01732795f85a6c30b3e53913d7ac9a304f9 100755 (executable)
@@ -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) + ";")