Migrate scapy shift/filter code to P4
This commit is contained in:
parent
2caace5735
commit
52adbb1990
1 changed files with 9 additions and 7 deletions
|
@ -16,9 +16,10 @@ action v4sum() {
|
|||
carryover = tmp >> 16; /* maximum is 6*(2**16) >> 16 == 6 */
|
||||
tmp = (tmp & 0xffff) + carryover; /* Now tmp contains at maximum 65541 */
|
||||
carryover = tmp >> 16; /* Now carryover contains at maximum 1 */
|
||||
tmp = (tmp & 0xffff) + carryover; /* No overrun possible anymore */
|
||||
tmp = tmp + carryover; /* No overrun possible anymore */
|
||||
|
||||
meta.v4sum = (bit<16>) tmp;
|
||||
/* filtering code copied from scapy */
|
||||
meta.v4sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff) ;
|
||||
}
|
||||
|
||||
action v6sum() {
|
||||
|
@ -47,11 +48,12 @@ action v6sum() {
|
|||
tmp = tmp + (bit<32>) hdr.ipv6.next_header; // 8 bit
|
||||
|
||||
carryover = tmp >> 16; /* maximum is 18*(2**16) >> 16 == 18 */
|
||||
tmp = (tmp & 0xffff) + carryover; /* Now tmp contains at maximum 65554*/
|
||||
ffff) + carryover; /* Now tmp contains at maximum 65554*/
|
||||
carryover = tmp >> 16; /* Now carryover contains at maximum 1 */
|
||||
tmp = (tmp & 0xffff) + carryover; /* No overrun possible anymore */
|
||||
tmp = tmp + carryover; /* No overrun possible anymore */
|
||||
|
||||
meta.v6sum = (bit<16>) tmp;
|
||||
/* filtering code copied from scapy */
|
||||
meta.v6sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff) ;
|
||||
}
|
||||
|
||||
action delta_prepare()
|
||||
|
@ -68,13 +70,13 @@ action delta_prepare()
|
|||
action delta_udp_from_v4_to_v6()
|
||||
{
|
||||
delta_prepare();
|
||||
hdr.udp.checksum = hdr.udp.checksum + ~meta.headerdiff +1;
|
||||
hdr.udp.checksum = hdr.udp.checksum + ~meta.headerdiff;
|
||||
}
|
||||
|
||||
action delta_tcp_from_v4_to_v6()
|
||||
{
|
||||
delta_prepare();
|
||||
hdr.tcp.checksum = hdr.tcp.checksum + ~meta.headerdiff +1;
|
||||
hdr.tcp.checksum = hdr.tcp.checksum + ~meta.headerdiff;
|
||||
}
|
||||
|
||||
action delta_ipv4_from_v6_to_v4()
|
||||
|
|
Loading…
Reference in a new issue