From bc9042142666ca3cba4f12724a12401fba879e1c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 16 Jul 2019 13:05:13 +0200 Subject: [PATCH] Get rid of negative wrap around --- doc/plan.org | 14 +++++++++++++- p4src/actions_delta_checksum.p4 | 21 +++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/doc/plan.org b/doc/plan.org index dadded5..9f389e2 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -5335,8 +5335,20 @@ Gives off-by-one in udp, sometimes! 10:08:52.626713 IP6 (hlim 64, next-header UDP (17) payload length: 14) 2001:db8:1::a00:1.51345 > 2001:db8::1.2342: [bad udp cks -*** TODO 2019-07-16: get values: v6sum, v4sum +*** TODO 2019-07-16: get values from P4: v6sum, v4sum and co. - v6sum = 0x9a6b + - v4sum = 0xeadd + + - 0x4a8a + 0x9a6b = 0xe4f5 (same as python) + (code: hdr.udp.checksum = 0x4a8a + 0x9a6b) + + - hdr.udp.checksum = 0x4a8a + 0x9a6b - 0xeadd; + ../p4src/actions_delta_checksum.p4(58): warning: -1512: negative + value with unsigned type + hdr.udp.checksum = 0x4a8a + 0x9a6b - 0xeadd; + Result: 0xfa18! + + ** The NetPFGA saga Problems encountered: diff --git a/p4src/actions_delta_checksum.p4 b/p4src/actions_delta_checksum.p4 index aedb110..56dbf55 100644 --- a/p4src/actions_delta_checksum.p4 +++ b/p4src/actions_delta_checksum.p4 @@ -53,16 +53,29 @@ action delta_prepare() action delta_udp_from_v4_to_v6() { delta_prepare(); -// hdr.udp.checksum = meta.v6sum; -// hdr.udp.checksum = meta.v4sum; hdr.udp.checksum = hdr.udp.checksum + meta.v6sum; - hdr.udp.checksum = hdr.udp.checksum - meta.v4sum; + + /* prevent negative wrap around that loses 1 */ + if(meta.v4sum > hdr.udp.checksum) { + bit<16> tmp = 0xffff - meta.v4sum; + hdr.udp.checksum = hdr.udp.checksum + tmp; + } else { + hdr.udp.checksum = hdr.udp.checksum - meta.v4sum; + } } action delta_tcp_from_v4_to_v6() { delta_prepare(); - hdr.tcp.checksum = hdr.tcp.checksum + meta.v6sum - meta.v4sum; + hdr.tcp.checksum = hdr.tcp.checksum + meta.v6sum; + + /* prevent negative wrap around that loses 1 */ + if(meta.v4sum > hdr.tcp.checksum) { + bit<16> tmp = 0xffff - meta.v4sum; + hdr.tcp.checksum = hdr.tcp.checksum + tmp; + } else { + hdr.tcp.checksum = hdr.tcp.checksum - meta.v4sum; + } } action delta_ipv4_from_v6_to_v4()