Add checksums for udp_6, udp_v4, tcp_v6, tcp_v4

This commit is contained in:
Nico Schottelius 2019-04-11 10:08:11 +02:00
parent 84b1d613ff
commit bf59808806
6 changed files with 118 additions and 7 deletions

View File

@ -188,13 +188,16 @@
| | Need to setup hardware addresses -> in theor resolution -> hardcoded atm | |
| | | |
| | | |
| 2019-04-04 | PLAN: NAT64 1:1 table ICMP, ICMPv6 working | x |
| 2019-04-04 | NAT64 1:1 table ICMP, ICMPv6 working | x |
| | Will need some switch local ip addresses | x |
| | | |
| 2019-04-11 | PLAN: NAT64 1:1 table UDP working | |
| | checksums in both directions | |
| | | |
| 2019-04-18 | PLAN: NAT64 1:1 table TCP/UDP working | |
| | | |
| | | |
| | | |
| 2019-05-02 | Jool SIIT / range / offset support https://www.jool.mx/en/run-vanilla.html | |
| | Jool EAMT support https://www.jool.mx/en/run-eam.html | |
| | Bidirectional support | |

View File

@ -131,7 +131,7 @@ struct headers {
}
struct metadata {
bit<16> tcp_length;
bit<16> length_without_ip_header;
bool do_cksum;
}
@ -151,7 +151,7 @@ parser MyParser(packet_in packet,
state ipv4 {
packet.extract(hdr.ipv4);
meta.tcp_length = hdr.ipv4.totalLen - 16w20;
meta.length_without_ip_header = hdr.ipv4.totalLen - 16w20;
transition select(hdr.ipv4.protocol){
PROTO_TCP: tcp;
@ -164,7 +164,7 @@ parser MyParser(packet_in packet,
state ipv6 {
packet.extract(hdr.ipv6);
meta.tcp_length = hdr.ipv6.payload_length;
meta.length_without_ip_header = hdr.ipv6.payload_length;
transition select(hdr.ipv6.next_header){
PROTO_TCP: tcp;

View File

@ -87,6 +87,103 @@ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
},
hdr.ipv4.hdrChecksum,
HashAlgorithm.csum16);
update_checksum_with_payload(meta.chk_udp_v4 == 1,
{
hdr.ipv4.src_addr,
hdr.ipv4.dst_addr,
8w0,
hdr.ipv4.protocol,
meta.length_without_ip_header,
// UDP header
hdr.udp.src_port,
hdr.udp.dst_port,
hdr.udp.payload_length,
},
hdr.udp.checksum,
HashAlgorithm.csum16
);
update_checksum_with_payload(meta.chk_udp_v6 == 1,
{
hdr.ipv6.src_addr, /* 128 */
hdr.ipv6.dst_addr, /* 128 */
meta.length_without_ip_header, /* 32 */
24w0, /* 24 */
hdr.ipv6.next_header, /* 8 */
/* total: 324 */
// UDP header
hdr.udp.src_port, /* 16 */
hdr.udp.dst_port, /* 16 */
hdr.udp.payload_length, /* 16 */
/* all: 372 */
},
hdr.udp.checksum,
HashAlgorithm.csum16
);
update_checksum_with_payload(meta.chk_tcp_v4 == 1,
{
hdr.ipv4.src_addr,
hdr.ipv4.dst_addr,
8w0,
hdr.ipv4.protocol,
meta.length_without_ip_header,
// TCP header
hdr.tcp.src_port,
hdr.tcp.dst_port,
hdr.tcp.seqNo,
hdr.tcp.ackNo,
hdr.tcp.data_offset,
hdr.tcp.res,
hdr.tcp.cwr,
hdr.tcp.ece,
hdr.tcp.urg,
hdr.tcp.ack,
hdr.tcp.psh,
hdr.tcp.rst,
hdr.tcp.syn,
hdr.tcp.fin,
hdr.tcp.window,
hdr.tcp.urgentPtr
},
hdr.tcp.checksum,
HashAlgorithm.csum16
);
update_checksum_with_payload(meta.chk_tcp_v6 == 1,
{
hdr.ipv6.src_addr,
hdr.ipv6.dst_addr,
meta.length_without_ip_header,
24w0,
hdr.ipv6.next_header,
// TCP header
hdr.tcp.src_port,
hdr.tcp.dst_port,
hdr.tcp.seqNo,
hdr.tcp.ackNo,
hdr.tcp.data_offset,
hdr.tcp.res,
hdr.tcp.cwr,
hdr.tcp.ece,
hdr.tcp.urg,
hdr.tcp.ack,
hdr.tcp.psh,
hdr.tcp.rst,
hdr.tcp.syn,
hdr.tcp.fin,
hdr.tcp.window,
hdr.tcp.urgentPtr
},
hdr.tcp.checksum,
HashAlgorithm.csum16);
}
}

View File

@ -212,8 +212,12 @@ struct metadata {
bit<1> chk_icmp6;
bit<1> chk_icmp;
bit<1> chk_ipv4;
bit<1> chk_udp_v4;
bit<1> chk_udp_v6;
bit<1> chk_tcp_v4;
bit<1> chk_tcp_v6;
bit<16> tcp_length;
bit<16> length_without_ip_header;
bit<32> cast_length;
table_t table_id;
}

View File

@ -17,6 +17,10 @@ parser MyParser(packet_in packet,
meta.chk_icmp = 0;
meta.chk_icmp6 = 0;
meta.chk_icmp6_na_ns = 0;
meta.chk_ipv4 = 0;
meta.chk_udp_v4 = 0;
meta.chk_udp_v6 = 0;
meta.chk_tcp = 0;
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.ethertype){
@ -30,7 +34,7 @@ parser MyParser(packet_in packet,
state ipv4 {
packet.extract(hdr.ipv4);
meta.tcp_length = hdr.ipv4.totalLen - 16w20;
meta.length_without_ip_header = hdr.ipv4.totalLen - 16w20;
transition select(hdr.ipv4.protocol){
PROTO_TCP: tcp;
@ -43,7 +47,7 @@ parser MyParser(packet_in packet,
state ipv6 {
packet.extract(hdr.ipv6);
meta.tcp_length = hdr.ipv6.payload_length;
meta.length_without_ip_header = hdr.ipv6.payload_length;
transition select(hdr.ipv6.next_header){
PROTO_TCP: tcp;

View File

@ -446,6 +446,9 @@ Echo or Echo Reply Message
hdr.icmp.code = 0;
}
}
if(hdr.udp.isValid()) {
meta.chk_udp = 1;
}
v4_networks.apply(); /* apply egress for IPv4 */
exit; /* no further v6 processing */