diff options
author | Mauro Sardara <msardara@cisco.com> | 2020-11-10 14:50:26 +0000 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2020-11-10 15:16:04 +0000 |
commit | 014ea2ed39986793d6b82e7a43533e91c6ec2e18 (patch) | |
tree | 6aec6df61debd6c40049e534b3a4377c851160fc /lib/src/protocol/tcp.c | |
parent | f87f19fa389a1edea861faaabc972d508a58985c (diff) |
[HICN-651] Offload checksum computation also for data packets.
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Change-Id: I3663ac73cdbaad3e53d4b1973a7bcbb333b3910c
Diffstat (limited to 'lib/src/protocol/tcp.c')
-rw-r--r-- | lib/src/protocol/tcp.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/src/protocol/tcp.c b/lib/src/protocol/tcp.c index 7b7c44ef7..c6099bf8f 100644 --- a/lib/src/protocol/tcp.c +++ b/lib/src/protocol/tcp.c @@ -45,6 +45,28 @@ DECLARE_get_length (tcp, UNEXPECTED); DECLARE_get_payload_length (tcp, UNEXPECTED); DECLARE_set_payload_length (tcp, UNEXPECTED); +always_inline int +check_tcp_checksum(u16 csum) +{ + /* As per RFC1624 + * In one's complement, there are two representations of zero: the all + * zero and the all one bit values, often referred to as +0 and -0. + * One's complement addition of non-zero inputs can produce -0 as a + * result, but never +0. Since there is guaranteed to be at least one + * non-zero field in the IP header, and the checksum field in the + * protocol header is the complement of the sum, the checksum field can + * never contain ~(+0), which is -0 (0xFFFF). It can, however, contain + * ~(-0), which is +0 (0x0000). + */ + if (csum == 0xffff) + { + /* Invalid checksum, no need to compute incremental update */ + return HICN_LIB_ERROR_REWRITE_CKSUM_REQUIRED; + } + + return HICN_LIB_ERROR_NONE; +} + int tcp_init_packet_header (hicn_type_t type, hicn_protocol_t * h) { @@ -257,21 +279,12 @@ tcp_rewrite_interest (hicn_type_t type, hicn_protocol_t * h, ip46_address_t * addr_old) { u16 *tcp_checksum = &(h->tcp.csum); + int ret = check_tcp_checksum(*tcp_checksum); - /* As per RFC1624 - * In one's complement, there are two representations of zero: the all - * zero and the all one bit values, often referred to as +0 and -0. - * One's complement addition of non-zero inputs can produce -0 as a - * result, but never +0. Since there is guaranteed to be at least one - * non-zero field in the IP header, and the checksum field in the - * protocol header is the complement of the sum, the checksum field can - * never contain ~(+0), which is -0 (0xFFFF). It can, however, contain - * ~(-0), which is +0 (0x0000). - */ - if (*tcp_checksum == 0xffff) { - /* Invalid checksum, no need to compute incremental update */ - return HICN_LIB_ERROR_REWRITE_CKSUM_REQUIRED; - } + if (ret) + { + return ret; + } /* * Padding fields are set to zero so we can apply checksum on the @@ -297,6 +310,12 @@ tcp_rewrite_data (hicn_type_t type, hicn_protocol_t * h, const hicn_faceid_t face_id) { u16 *tcp_checksum = &(h->tcp.csum); + int ret = check_tcp_checksum(*tcp_checksum); + + if (ret) + { + return ret; + } /* * Padding fields are set to zero so we can apply checksum on the |