Try to prevent underrun / possible off by one

Checking for bigger value
This commit is contained in:
Nico Schottelius 2019-07-13 18:05:50 +02:00
parent 86885760b2
commit 7599ebb89d
3 changed files with 18 additions and 13 deletions

View file

@ -37,30 +37,33 @@ action v6sum() {
meta.v6sum = meta.v6sum + (bit<16>) hdr.ipv6.next_header; // 8 bit
}
action delta_udp_from_v4_to_v6()
action delta_prepare()
{
v4sum();
v6sum();
bit<16> diff = meta.v6sum - meta.v4sum;
hdr.udp.checksum = hdr.udp.checksum + ~diff +1;
if(meta.v6sum > meta.v4sum) {
meta.headerdiff = meta.v6sum - meta.v4sum;
} else {
meta.headerdiff = meta.v4sum - meta.v6sum;
}
}
action delta_udp_from_v4_to_v6()
{
delta_prepare();
hdr.udp.checksum = hdr.udp.checksum + ~meta.headerdiff;
}
action delta_tcp_from_v4_to_v6()
{
v4sum();
v6sum();
bit<16> diff = meta.v6sum - meta.v4sum;
hdr.tcp.checksum = hdr.tcp.checksum + ~diff +1;
delta_prepare();
hdr.tcp.checksum = hdr.tcp.checksum + ~meta.headerdiff;
}
action delta_ipv4_from_v6_to_v4()
{
v4sum();
v6sum();
bit<16> diff = meta.v4sum - meta.v6sum ;
hdr.tcp.checksum = hdr.tcp.checksum + ~diff +1;
delta_prepare();
hdr.tcp.checksum = hdr.tcp.checksum + ~meta.headerdiff;
}
#endif

View file

@ -234,6 +234,7 @@ struct metadata {
/* for delta checksums */
bit<16> v4sum;
bit<16> v6sum;
bit<16> headerdiff;
table_t table_id;
}

View file

@ -15,6 +15,7 @@
meta.chk_tcp_v4 = 0;
meta.v4sum = 0;
meta.v6sum = 0;
meta.headerdiff = 0;
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.ethertype){