Get rid of negative wrap around
This commit is contained in:
parent
e74a18c102
commit
bc90421426
2 changed files with 30 additions and 5 deletions
14
doc/plan.org
14
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:
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue