From 162ef20072d4283cd1afc2106f051fa95f5001db Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 23 Mar 2019 14:39:56 +0100 Subject: [PATCH] Checksum the newly parsed fields --- doc/plan.org | 1 + p4src/checksums.p4 | 28 +++++++++++++++++++++++++++- p4src/headers.p4 | 4 +++- p4src/static-mapping.p4 | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/doc/plan.org b/doc/plan.org index 9da3f65..0623ccf 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -121,6 +121,7 @@ | | | | | 2019-03-23 | Parsing down to link layer option | | | | Parsing on wrong field detected by unset fields in wireshark | | +| | Correcting parser->leads to incorrect checksum | | | | | | | | | | | 2019-03-28 | Meet Laurent #4 | | diff --git a/p4src/checksums.p4 b/p4src/checksums.p4 index 183380d..9e05953 100644 --- a/p4src/checksums.p4 +++ b/p4src/checksums.p4 @@ -21,7 +21,7 @@ control MyVerifyChecksum(inout headers hdr, inout metadata meta) { control MyComputeChecksum(inout headers hdr, inout metadata meta) { apply { - update_checksum_with_payload(meta.do_cksum == 1, + update_checksum_with_payload(meta.task == TASK_CHECKSUM_ICMP6, { hdr.ipv6.src_addr, /* 128 */ hdr.ipv6.dst_addr, /* 128 */ @@ -34,6 +34,32 @@ control MyComputeChecksum(inout headers hdr, inout metadata meta) { hdr.icmp6.checksum, HashAlgorithm.csum16 ); + + /* checksumming for icmp6_na_ns_option */ + update_checksum_with_payload(meta.task == TASK_CHECKSUM_ICMP6_NA, + { + hdr.ipv6.src_addr, /* 128 */ + hdr.ipv6.dst_addr, /* 128 */ + meta.cast_length, /* 32 */ + 24w0, /* 24 0's */ + PROTO_ICMP6, /* 8 */ + hdr.icmp6.type, /* 8 */ + hdr.icmp6.code, /* 8 */ + + hdr.icmp6_na_ns.router, + hdr.icmp6_na_ns.solicitated, + hdr.icmp6_na_ns.override, + hdr.icmp6_na_ns.reserved, + hdr.icmp6_na_ns.target_addr, + + hdr.icmp6_option_link_layer_addr.type, + hdr.icmp6_option_link_layer_addr.ll_length, + hdr.icmp6_option_link_layer_addr.mac_addr + }, + hdr.icmp6.checksum, + HashAlgorithm.csum16 + ); + } } diff --git a/p4src/headers.p4 b/p4src/headers.p4 index 3c06323..a60ceb0 100644 --- a/p4src/headers.p4 +++ b/p4src/headers.p4 @@ -43,6 +43,9 @@ const task_t TASK_ICMP6_NS = 1; const task_t TASK_ICMP6_GENERAL = 2; const task_t TASK_DEBUG = 3; const task_t TASK_ICMP6_REPLY = 4; +const task_t TASK_CHECKSUM_ICMP6 = 5; /* data plane */ +const task_t TASK_CHECKSUM_ICMP6_NA = 6; /* data plane */ + /* 48+48+16 = 112 */ header ethernet_t { @@ -165,7 +168,6 @@ struct metadata { task_t task; bit<16> tcp_length; bit<32> cast_length; - bit<1> do_cksum; } #endif \ No newline at end of file diff --git a/p4src/static-mapping.p4 b/p4src/static-mapping.p4 index 1205745..993353f 100644 --- a/p4src/static-mapping.p4 +++ b/p4src/static-mapping.p4 @@ -67,6 +67,7 @@ control MyIngress(inout headers hdr, hdr.icmp6_option_link_layer_addr.ll_length = 1; /* 1* 64 bit */ hdr.icmp6_option_link_layer_addr.mac_addr = mac_addr; + /* version1: rebuilding packet */ /* truncate((bit<32>)(112 + 320 + 32)/8);