Change order of complement & filtering
This commit is contained in:
parent
991b725c36
commit
26c27cefa8
3 changed files with 25 additions and 13 deletions
|
@ -13,16 +13,20 @@ def checksum_scapy(pkt):
|
|||
if len(pkt) % 2 == 1:
|
||||
pkt += b"\0"
|
||||
|
||||
# P4: ABOVE not needed (always even)
|
||||
|
||||
# array: create an array of 16 bit values from the input
|
||||
# and then sum it up -> this might be sligthly/much higher
|
||||
# than 16 bit (additions!)
|
||||
s = sum(array.array("H", pkt))
|
||||
# P4: summing manually into 32bit
|
||||
|
||||
# add the (right shift 16) and the 16 right bits
|
||||
# basically: assuming 32 bit (?): add the two 16 bit "words"
|
||||
# together
|
||||
# This might still exceed 16 bit!
|
||||
s = (s >> 16) + (s & 0xffff)
|
||||
# P4:
|
||||
|
||||
# right shift 16 -> zero least significant bits,
|
||||
# and add the upper bits to it
|
||||
|
|
10
doc/plan.org
10
doc/plan.org
|
@ -5245,6 +5245,16 @@ likely this is the cause for the main error:
|
|||
|
||||
**** go through all steps again and try to understand why it (silently) fails later
|
||||
*** 2019-07-13: fix overflow error
|
||||
*** 2019-07-15: fix off-by-one-sometimes
|
||||
- scapy shift code / return does not work
|
||||
**** scapy code results
|
||||
Using meta.v6sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff)
|
||||
;
|
||||
|
||||
we get on the wire:
|
||||
|
||||
sum 0x324a (incorrect -> 0x5429),
|
||||
|
||||
** The NetPFGA saga
|
||||
Problems encountered:
|
||||
- The logfile for a compile run is 10k+ lines
|
||||
|
|
|
@ -13,13 +13,12 @@ action v4sum() {
|
|||
tmp = tmp + (bit<32>) hdr.ipv4.totalLen -20; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv4.protocol; // 8 bit
|
||||
|
||||
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 + carryover; /* No overrun possible anymore */
|
||||
|
||||
/* filtering code copied from scapy */
|
||||
tmp = (tmp >> 16) + (tmp & 0xffff);
|
||||
tmp = tmp + (tmp >> 16);
|
||||
tmp = ~tmp;
|
||||
meta.v4sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff);
|
||||
|
||||
}
|
||||
|
||||
action v6sum() {
|
||||
|
@ -47,15 +46,14 @@ action v6sum() {
|
|||
tmp = tmp + (bit<32>) hdr.ipv6.payload_length; // 16 bit
|
||||
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*/
|
||||
carryover = tmp >> 16; /* Now carryover contains at maximum 1 */
|
||||
tmp = tmp + carryover; /* No overrun possible anymore */
|
||||
|
||||
/* filtering code copied from scapy */
|
||||
tmp = (tmp >> 16) + (tmp & 0xffff);
|
||||
tmp = tmp + (tmp >> 16);
|
||||
tmp = ~tmp;
|
||||
meta.v6sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff) ;
|
||||
}
|
||||
|
||||
|
||||
action delta_prepare()
|
||||
{
|
||||
v4sum();
|
||||
|
@ -70,13 +68,13 @@ action delta_prepare()
|
|||
action delta_udp_from_v4_to_v6()
|
||||
{
|
||||
delta_prepare();
|
||||
hdr.udp.checksum = hdr.udp.checksum + ~meta.headerdiff;
|
||||
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;
|
||||
hdr.tcp.checksum = hdr.tcp.checksum + meta.headerdiff;
|
||||
}
|
||||
|
||||
action delta_ipv4_from_v6_to_v4()
|
||||
|
|
Loading…
Reference in a new issue