From eb06d26fbb4ce0b752fd025f01725ca6572824b1 Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Tue, 5 Sep 2017 13:46:58 +0300 Subject: [PATCH 1/3] api: packet_io: refine packet format on output Define explicitly that (by default) packet output does not need any extra metadata to be set. Also (Ethernet) padding and CRC are added by default. Signed-off-by: Petri Savolainen --- include/odp/api/spec/packet_io.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/odp/api/spec/packet_io.h b/include/odp/api/spec/packet_io.h index d42cebf079..6040a83104 100644 --- a/include/odp/api/spec/packet_io.h +++ b/include/odp/api/spec/packet_io.h @@ -889,6 +889,11 @@ uint64_t odp_pktin_wait_time(uint64_t nsec); * is less than 'num', the remaining packets at the end of packets[] array * are not consumed, and the caller has to take care of them. * + * Entire packet data is sent out (odp_packet_len() bytes of data, starting from + * odp_packet_data()). All other packet metadata is ignored unless otherwise + * specified e.g. for protocol offload purposes. Link protocol specific frame + * checksum and padding are added to frames before transmission. + * * @param queue Packet output queue handle for sending packets * @param packets[] Array of packets to send * @param num Number of packets to send From a2cf94f31fe0e8ca6b99e8d6136976e280e42062 Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Tue, 5 Sep 2017 15:36:04 +0300 Subject: [PATCH 2/3] api: packet: add checksum status Added functions to request L3/L4 checksum check status for a packet. Even if checksum checking is enabled on an interface, all packets may not be checked - for example L4 checksum cannot be checked for fragments (before reassembly). Also it varies how e.g. IP options affect HW checksum capability. Signed-off-by: Petri Savolainen --- include/odp/api/spec/packet.h | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/odp/api/spec/packet.h b/include/odp/api/spec/packet.h index 95f5349b27..b3e1449ff1 100644 --- a/include/odp/api/spec/packet.h +++ b/include/odp/api/spec/packet.h @@ -83,6 +83,22 @@ typedef struct odp_packet_data_range { } odp_packet_data_range_t; +/** + * Checksum check status in packet + */ +typedef enum odp_packet_chksum_status_t { + /** Checksum was not checked. Checksum check was not attempted or + * the attempt failed. */ + ODP_PACKET_CHKSUM_UNKNOWN = 0, + + /** Checksum was checked and it was not correct */ + ODP_PACKET_CHKSUM_BAD, + + /** Checksum was checked and it was correct */ + ODP_PACKET_CHKSUM_OK + +} odp_packet_chksum_status_t; + /* * * Alloc and free @@ -1377,6 +1393,34 @@ uint32_t odp_packet_l4_offset(odp_packet_t pkt); */ int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset); +/** + * Layer 3 checksum check status + * + * Returns the result of the latest layer 3 checksum check done for the packet. + * The status tells if checksum check was attempted and the result of the + * attempt. It depends on packet input (or IPSEC) configuration, packet content + * and implementation capabilities if checksum check is attempted for a packet. + * + * @param pkt Packet handle + * + * @return L3 checksum check status + */ +odp_packet_chksum_status_t odp_packet_l3_chksum_status(odp_packet_t pkt); + +/** + * Layer 4 checksum check status + * + * Returns the result of the latest layer 4 checksum check done for the packet. + * The status tells if checksum check was attempted and the result of the + * attempt. It depends on packet input (or IPSEC) configuration, packet content + * and implementation capabilities if checksum check is attempted for a packet. + * + * @param pkt Packet handle + * + * @return L4 checksum check status + */ +odp_packet_chksum_status_t odp_packet_l4_chksum_status(odp_packet_t pkt); + /** * Layer 3 checksum insertion override * From 0638246fad0aa30e56c7a2f4c7216827dbc59c6a Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Tue, 5 Sep 2017 16:01:55 +0300 Subject: [PATCH 3/3] api: packet_io: refine rules for checksum calculation An implementation must be able to check checksum for normal IP packets. It's implementation defined if options or extension headers are supported. Parsing configuration must match the layers of checksum check configuration. Checksum insertion on packet output can expect well formed packet headers from the application. Checksum calculation ignores possible extra data in the packet. Signed-off-by: Petri Savolainen --- include/odp/api/spec/ipsec.h | 14 ++++++--- include/odp/api/spec/packet.h | 8 +++++ include/odp/api/spec/packet_io.h | 54 +++++++++++++++++++++++++------- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/include/odp/api/spec/ipsec.h b/include/odp/api/spec/ipsec.h index 7085bc0d29..0b36b864ed 100644 --- a/include/odp/api/spec/ipsec.h +++ b/include/odp/api/spec/ipsec.h @@ -156,7 +156,9 @@ typedef struct odp_ipsec_inbound_config_t { odp_ipsec_proto_layer_t parse; /** Flags to control IPSEC payload data checks up to the selected parse - * level. */ + * level. Checksum checking status can be queried for each packet with + * odp_packet_l3_chksum_status() and odp_packet_l4_chksum_status(). + */ union { /** Mapping for individual bits */ struct { @@ -191,10 +193,12 @@ typedef struct odp_ipsec_inbound_config_t { */ typedef struct odp_ipsec_outbound_config_t { /** Flags to control L3/L4 checksum insertion as part of outbound - * packet processing. Packet must have set with valid L3/L4 offsets. - * Checksum configuration is ignored for packets that checksum cannot - * be computed for (e.g. IPv4 fragments). Application may use a packet - * metadata flag to disable checksum insertion per packet bases. + * packet processing. These flags control checksum insertion (for the + * payload packet) in the same way as the checksum flags in + * odp_pktout_config_opt_t control checksum insertion when sending + * packets out through a pktio interface. Also packet checksum override + * functions (e.g. odp_packet_l4_chksum_insert()) can be used in + * the same way. */ union { /** Mapping for individual bits */ diff --git a/include/odp/api/spec/packet.h b/include/odp/api/spec/packet.h index b3e1449ff1..c498e2e233 100644 --- a/include/odp/api/spec/packet.h +++ b/include/odp/api/spec/packet.h @@ -1428,6 +1428,10 @@ odp_packet_chksum_status_t odp_packet_l4_chksum_status(odp_packet_t pkt); * overrides a higher level configuration for checksum insertion into a L3 * header during packet output processing. * + * Calling this function is always allowed but the checksum will not be + * inserted if the packet is output through a pktio that does not have + * the relevant pktout chksum bit set in the pktio capability. + * * @param pkt Packet handle * @param l3 0: do not insert L3 checksum * 1: insert L3 checksum @@ -1441,6 +1445,10 @@ void odp_packet_l3_chksum_insert(odp_packet_t pkt, int l3); * overrides a higher level configuration for checksum insertion into a L4 * header during packet output processing. * + * Calling this function is always allowed but the checksum will not be + * inserted if the packet is output through a pktio that does not have + * the relevant pktout chksum bit set in the pktio capability. + * * @param pkt Packet handle * @param l4 0: do not insert L4 checksum * 1: insert L4 checksum diff --git a/include/odp/api/spec/packet_io.h b/include/odp/api/spec/packet_io.h index 6040a83104..b56a5205df 100644 --- a/include/odp/api/spec/packet_io.h +++ b/include/odp/api/spec/packet_io.h @@ -256,11 +256,27 @@ typedef struct odp_pktio_param_t { * belong to time synchronization protocol (PTP). * * Packet input checksum checking may be enabled or disabled. When it is - * enabled, implementation will verify checksum correctness on incoming packets - * and depending on drop configuration either deliver erroneous packets with - * appropriate flags set (e.g. odp_packet_has_l3_error()) or drop those. - * When packet dropping is enabled, application will never receive a packet - * with the specified error and may avoid to check the error flag. + * enabled, implementation will attempt to verify checksum correctness on + * incoming packets and depending on drop configuration either deliver erroneous + * packets with appropriate flags set (e.g. odp_packet_has_l3_error(), + * odp_packet_l3_chksum_status()) or drop those. When packet dropping is + * enabled, application will never receive a packet with the specified error + * and may avoid to check the error flag. + * + * If checksum checking is enabled, IPv4 header checksum checking is always + * done for packets that do not have IP options and L4 checksum checking + * is done for unfragmented packets that do not have IPv4 options or IPv6 + * extension headers. In other cases checksum checking may or may not + * be done. For example, L4 checksum of fragmented packets is typically + * not checked. + * + * IPv4 checksum checking may be enabled only when parsing level is + * ODP_PKTIO_PARSER_LAYER_L3 or higher. Similarly, L4 level checksum checking + * may be enabled only with parsing level ODP_PKTIO_PARSER_LAYER_L4 or higher. + * + * Whether checksum checking was done and whether a checksum was correct + * can be queried for each received packet with odp_packet_l3_chksum_status() + * and odp_packet_l4_chksum_status(). */ typedef union odp_pktin_config_opt_t { /** Option flags */ @@ -314,13 +330,27 @@ typedef union odp_pktin_config_opt_t { * Packet output configuration options listed in a bit field structure. Packet * output checksum insertion may be enabled or disabled. When it is enabled, * implementation will calculate and insert checksum into every outgoing packet - * by default. Application may use a packet metadata flag to disable checksum - * insertion per packet bases. For correct operation, packet metadata must - * provide valid offsets for the appropriate protocols. For example, UDP - * checksum calculation needs both L3 and L4 offsets (to access IP and UDP - * headers). When application (e.g. a switch) does not modify L3/L4 data and - * thus checksum does not need to be updated, output checksum insertion should - * be disabled for optimal performance. + * by default. Application may disable checksum insertion (e.g. + * odp_packet_l4_chksum_insert()) on per packet basis. For correct operation, + * packet metadata must provide valid offsets for the appropriate protocols. + * For example, UDP checksum calculation needs both L3 and L4 offsets (to access + * IP and UDP headers). When application (e.g. a switch) does not modify L3/L4 + * data and thus checksum does not need to be updated, output checksum insertion + * should be disabled for optimal performance. + * + * Packet flags (odp_packet_has_*()) are ignored for the purpose of checksum + * insertion in packet output. + * + * UDP, TCP and SCTP checksum insertion must not be requested for IP fragments. + * Use checksum override function (odp_packet_l4_chksum_insert()) to disable + * checksumming when sending a fragment through a packet IO interface that has + * the relevant L4 checksum insertion enabled. + * + * Result of checksum insertion at packet output is undefined if the protocol + * headers required for checksum calculation are not well formed. Packet must + * contain at least as many data bytes after L3/L4 offsets as the headers + * indicate. Other data bytes of the packet are ignored for the checksum + * insertion. */ typedef union odp_pktout_config_opt_t { /** Option flags */