Split ipv4 header into 16 bit words

This commit is contained in:
Nico Schottelius 2019-07-21 10:45:43 +02:00
parent 054c1605eb
commit dda1aa9c3c
2 changed files with 43 additions and 8 deletions

View File

@ -5659,6 +5659,20 @@ Vivado%
Vivado%
#+END_CENTER
*** TODO 2019-07-21: whether or not to handle icmp(6) checksums
*** TODO 2019-07-21: implement v6->v4 delta based
#+BEGIN_CENTER
while true; do mx h3 "echo V4-OK | socat - TCP-LISTEN:2343"; sleep 2;
done
while true; do mx h1 "echo V6-OK | socat -
TCP6:[2001:db8:1::a00:1]:2343"; sleep 2; done
mx h1 "echo V6-OK | socat - TCP6:[2001:db8:1::a00:1]:2343"
#+END_CENTER
Result: no reply, but translated packets seen on h3; wrong IPv4
checksum; tcp checksum is ok
-> doing manual calculation to see where diff comes from
** The NetPFGA saga
Problems encountered:
- The logfile for a compile run is 10k+ lines

View File

@ -125,22 +125,43 @@ action delta_tcp_from_v6_to_v4()
action delta_ipv4_from_v6_to_v4()
{
bit<16> tmp = 0;
bit<16> shift_tmp = 0;
/* we don't have ANY checksum, but tcp or udp: we can
base on that ones for calculating the diff for IPv4
Does NOT contain payload! -> can be done manually */
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 */
shift_tmp = ((bit<16>) hdr.ipv4.version) << 12 +
((bit<16>) hdr.ipv4.ihl) << 8 +
((bit<16>) hdr.ipv4.diff_serv) << 2 +
((bit<16>) hdr.ipv4.ecn);
tmp = tmp + shift_tmp;
// 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 */
tmp = tmp + (bit<16>) hdr.ipv4.fragOffset; /* 13 bit */
tmp = tmp + (bit<16>) hdr.ipv4.ttl; /* 8 bit */
tmp = tmp + (bit<16>) hdr.ipv4.protocol; /* 8 bit */
shift_tmp = ((bit<16>) hdr.ipv4.flags) << 13 +
((bit<16>) hdr.ipv4.fragOffset);
tmp = tmp + shift_tmp;
// tmp = tmp + (bit<16>) hdr.ipv4.flags; /* 3 bit */
// tmp = tmp + (bit<16>) hdr.ipv4.fragOffset; /* 13 bit */
shift_tmp = ((bit<16>) hdr.ipv4.ttl) << 8 +
((bit<16>) hdr.ipv4.protocol);
tmp = tmp + shift_tmp;
// tmp = tmp + (bit<16>) hdr.ipv4.ttl; /* 8 bit */
// tmp = tmp + (bit<16>) hdr.ipv4.protocol; /* 8 bit */
tmp = tmp + (bit<16>) hdr.ipv4.src_addr[15:0]; /* 16 bit */
tmp = tmp + (bit<16>) hdr.ipv4.src_addr[31:16]; /* 16 bit */
tmp = tmp + (bit<16>) hdr.ipv4.dst_addr[15:0]; /* 16 bit */