From bf5980880684a6ea3a9c1c275053879b3b985a8a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 11 Apr 2019 10:08:11 +0200 Subject: [PATCH] Add checksums for udp_6, udp_v4, tcp_v6, tcp_v4 --- doc/plan.org | 5 ++- p4src/bug1-bool.p4 | 6 +-- p4src/checksums.p4 | 97 +++++++++++++++++++++++++++++++++++++++++ p4src/headers.p4 | 6 ++- p4src/parsers.p4 | 8 +++- p4src/static-mapping.p4 | 3 ++ 6 files changed, 118 insertions(+), 7 deletions(-) diff --git a/doc/plan.org b/doc/plan.org index dc256c3..43c35d8 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -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 | | diff --git a/p4src/bug1-bool.p4 b/p4src/bug1-bool.p4 index 4a2a4a7..e54e588 100644 --- a/p4src/bug1-bool.p4 +++ b/p4src/bug1-bool.p4 @@ -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; diff --git a/p4src/checksums.p4 b/p4src/checksums.p4 index 5b52f06..189cdc5 100644 --- a/p4src/checksums.p4 +++ b/p4src/checksums.p4 @@ -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); + } } diff --git a/p4src/headers.p4 b/p4src/headers.p4 index 8c48927..24dea27 100644 --- a/p4src/headers.p4 +++ b/p4src/headers.p4 @@ -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; } diff --git a/p4src/parsers.p4 b/p4src/parsers.p4 index 2d4ec34..c55bb47 100644 --- a/p4src/parsers.p4 +++ b/p4src/parsers.p4 @@ -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; diff --git a/p4src/static-mapping.p4 b/p4src/static-mapping.p4 index 4116dfc..d79d75d 100644 --- a/p4src/static-mapping.p4 +++ b/p4src/static-mapping.p4 @@ -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 */