undo 1's complement of the checksum, add / subtract and then redo
This commit is contained in:
parent
b4882159f1
commit
4286ad0832
1 changed files with 8 additions and 18 deletions
|
@ -12,7 +12,6 @@ action v4sum() {
|
|||
tmp = tmp + (bit<16>) hdr.ipv4.totalLen -20; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv4.protocol; // 8 bit
|
||||
|
||||
tmp = ~tmp;
|
||||
meta.v4sum = tmp;
|
||||
}
|
||||
|
||||
|
@ -40,7 +39,6 @@ action v6sum() {
|
|||
tmp = tmp + (bit<16>) hdr.ipv6.payload_length; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.next_header; // 8 bit
|
||||
|
||||
tmp = ~tmp;
|
||||
meta.v6sum = tmp;
|
||||
}
|
||||
|
||||
|
@ -53,29 +51,21 @@ action delta_prepare()
|
|||
action delta_udp_from_v4_to_v6()
|
||||
{
|
||||
delta_prepare();
|
||||
hdr.udp.checksum = hdr.udp.checksum + meta.v6sum;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
bit<16> tmp = ~hdr.udp.checksum;
|
||||
tmp = tmp + meta.v6sum;
|
||||
tmp = tmp - meta.v4sum;
|
||||
hdr.udp.checksum = ~tmp;
|
||||
}
|
||||
|
||||
action delta_tcp_from_v4_to_v6()
|
||||
{
|
||||
delta_prepare();
|
||||
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;
|
||||
}
|
||||
bit<16> tmp = ~hdr.tcp.checksum;
|
||||
tmp = tmp + meta.v6sum;
|
||||
tmp = tmp - meta.v4sum;
|
||||
hdr.tcp.checksum = ~tmp;
|
||||
}
|
||||
|
||||
action delta_ipv4_from_v6_to_v4()
|
||||
|
|
Loading…
Reference in a new issue