From 9779a53938e32d7d81f3c45346731cb06401ae94 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 11 May 2021 23:36:00 +0000 Subject: [PATCH] Fix checksum offset calculation --- genrules.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) + ";") -- 2.30.2