update checksum code
This commit is contained in:
parent
4286ad0832
commit
512fca1349
2 changed files with 47 additions and 15 deletions
13
doc/plan.org
13
doc/plan.org
|
@ -4596,7 +4596,6 @@ Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Windo
|
||||||
#+END_CENTER
|
#+END_CENTER
|
||||||
|
|
||||||
Reason was a hidden window.
|
Reason was a hidden window.
|
||||||
***
|
|
||||||
*** 2019-06-13: try using external card for packets
|
*** 2019-06-13: try using external card for packets
|
||||||
*** 2019-06-14: test adding table entry with ubuntu 16.04, kernel 4.15.0-51-generic
|
*** 2019-06-14: test adding table entry with ubuntu 16.04, kernel 4.15.0-51-generic
|
||||||
#+BEGIN_CENTER
|
#+BEGIN_CENTER
|
||||||
|
@ -5301,6 +5300,8 @@ p4@ubuntu:~/master-thesis/bin$ mx h3 "echo V4-OK | socat - UDP:10.1.1.1:2342"
|
||||||
|
|
||||||
My code is +1 too high
|
My code is +1 too high
|
||||||
|
|
||||||
|
*** 2019-07-17: continuing on wrap around issue
|
||||||
|
|
||||||
*** DONE 2019-07-16: understood scapy code
|
*** DONE 2019-07-16: understood scapy code
|
||||||
CLOSED: [2019-07-16 Tue 11:25]
|
CLOSED: [2019-07-16 Tue 11:25]
|
||||||
meta.v6sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff) ;
|
meta.v6sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff) ;
|
||||||
|
@ -5335,7 +5336,8 @@ 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
|
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 from P4: v6sum, v4sum and co.
|
*** DONE 2019-07-16: get values from P4: v6sum, v4sum and co.
|
||||||
|
CLOSED: [2019-07-16 Tue 13:15]
|
||||||
- v6sum = 0x9a6b
|
- v6sum = 0x9a6b
|
||||||
- v4sum = 0xeadd
|
- v4sum = 0xeadd
|
||||||
|
|
||||||
|
@ -5348,7 +5350,12 @@ Gives off-by-one in udp, sometimes!
|
||||||
hdr.udp.checksum = 0x4a8a + 0x9a6b - 0xeadd;
|
hdr.udp.checksum = 0x4a8a + 0x9a6b - 0xeadd;
|
||||||
Result: 0xfa18!
|
Result: 0xfa18!
|
||||||
|
|
||||||
|
*** TODO 2019-07-16: debug v3.3: even positive wrap around fails!!
|
||||||
|
- hdr.udp.checksum = 0x91ef + 0x9a6b;
|
||||||
|
../p4src/actions_delta_checksum.p4(66): warning: 76890: value does not fit in 16 bits
|
||||||
|
hdr.udp.checksum = 0x91ef + 0x9a6b;
|
||||||
|
11:52:13.177826 IP6 (hlim 64, next-header UDP (17) payload length: 14)
|
||||||
|
2001:db8:1::a00:1.50705 > 2001:db8::1.2342: [bad udp cksum 0x2c5a -> 0xfc97!] UDP, length 6
|
||||||
|
|
||||||
** The NetPFGA saga
|
** The NetPFGA saga
|
||||||
Problems encountered:
|
Problems encountered:
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
#ifndef NICO_DELTA_CHECKSUM
|
#ifndef NICO_DELTA_CHECKSUM
|
||||||
#define NICO_DELTA_CHECKSUM
|
#define NICO_DELTA_CHECKSUM
|
||||||
|
|
||||||
|
/* copied from
|
||||||
|
https://p4.org/p4-spec/docs/PSA-v1.1.0.html#appendix-internetchecksum-implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
bit<16> ones_complement_sum(in bit<16> x, in bit<16> y) {
|
||||||
|
bit<17> ret = (bit<17>) x + (bit<17>) y;
|
||||||
|
if (ret[16:16] == 1) {
|
||||||
|
ret = ret + 1;
|
||||||
|
}
|
||||||
|
return ret[15:0];
|
||||||
|
}
|
||||||
|
|
||||||
action v4sum() {
|
action v4sum() {
|
||||||
bit<16> tmp = 0;
|
bit<16> tmp = 0;
|
||||||
|
|
||||||
|
@ -12,7 +24,7 @@ action v4sum() {
|
||||||
tmp = tmp + (bit<16>) hdr.ipv4.totalLen -20; // 16 bit
|
tmp = tmp + (bit<16>) hdr.ipv4.totalLen -20; // 16 bit
|
||||||
tmp = tmp + (bit<16>) hdr.ipv4.protocol; // 8 bit
|
tmp = tmp + (bit<16>) hdr.ipv4.protocol; // 8 bit
|
||||||
|
|
||||||
meta.v4sum = tmp;
|
meta.v4sum = ~tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
action v6sum() {
|
action v6sum() {
|
||||||
|
@ -39,7 +51,7 @@ action v6sum() {
|
||||||
tmp = tmp + (bit<16>) hdr.ipv6.payload_length; // 16 bit
|
tmp = tmp + (bit<16>) hdr.ipv6.payload_length; // 16 bit
|
||||||
tmp = tmp + (bit<16>) hdr.ipv6.next_header; // 8 bit
|
tmp = tmp + (bit<16>) hdr.ipv6.next_header; // 8 bit
|
||||||
|
|
||||||
meta.v6sum = tmp;
|
meta.v6sum = ~tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
action delta_prepare()
|
action delta_prepare()
|
||||||
|
@ -52,28 +64,41 @@ action delta_udp_from_v4_to_v6()
|
||||||
{
|
{
|
||||||
delta_prepare();
|
delta_prepare();
|
||||||
|
|
||||||
bit<16> tmp = ~hdr.udp.checksum;
|
bit<16> tmp = 0;
|
||||||
tmp = tmp + meta.v6sum;
|
tmp = ones_complement_sum(hdr.udp.checksum, meta.v6sum);
|
||||||
tmp = tmp - meta.v4sum;
|
hdr.udp.checksum = ones_complement_sum(tmp, 0xffff - meta.v6sum);
|
||||||
hdr.udp.checksum = ~tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
action delta_tcp_from_v4_to_v6()
|
action delta_tcp_from_v4_to_v6()
|
||||||
{
|
{
|
||||||
delta_prepare();
|
delta_prepare();
|
||||||
|
bit<16> tmp = 0;
|
||||||
bit<16> tmp = ~hdr.tcp.checksum;
|
tmp = ones_complement_sum(hdr.tcp.checksum, meta.v6sum);
|
||||||
tmp = tmp + meta.v6sum;
|
hdr.tcp.checksum = ones_complement_sum(tmp, 0xffff - meta.v6sum);
|
||||||
tmp = tmp - meta.v4sum;
|
|
||||||
hdr.tcp.checksum = ~tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
action delta_ipv4_from_v6_to_v4()
|
action delta_ipv4_from_v6_to_v4()
|
||||||
{
|
{
|
||||||
delta_prepare();
|
bit<16> tmp = 0;
|
||||||
|
|
||||||
|
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.version; /* 4 bit */
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.ihl; /* 4 bit */
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.diff_serv; /* 6 bit */
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.ecn; /* 2 bit */
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.totalLen; /* 16 bit */
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.identification; /* 16 bit */
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.flags; /* 3 bit */
|
||||||
/* we don't have ANY checksum, but tcp or udp: we can
|
/* we don't have ANY checksum, but tcp or udp: we can
|
||||||
base on that ones for calculating the diff for IPv4
|
base on that ones for calculating the diff for IPv4
|
||||||
|
|
||||||
|
Does NOT contain payload! -> can be done manually
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.fragOffset;
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.ttl,
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.protocol,
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.src_addr,
|
||||||
|
tmp = tmp + (bit<16>) hdr.ipv4.dst_addr
|
||||||
|
|
||||||
*/
|
*/
|
||||||
hdr.ipv4.checksum = 0; /* TO BE DONE! */
|
hdr.ipv4.checksum = 0; /* TO BE DONE! */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue