diff mbox series

[API-NEXT,v2,4/5] api: parse: set next layer offset

Message ID 1512993608-19038-5-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v2,1/5] api: packet: refine layer offset specification | expand

Commit Message

Github ODP bot Dec. 11, 2017, noon UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Explicitly require that implementation sets the next layer
offset after user defined last parse layer. Next layer offset
can be set without checking the layer itself. For example:

l4_offset = l3_offset + l3_hdr_len

Also renamed packet_parse_param 'layer' to 'last_layer' since
it's documenting the usage better:

parse.proto = ODP_PROTO_IPV4;
parse.last_layer = ODP_PROTO_LAYER_L4;

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 332 (psavol:next-l4-offset)
 ** https://github.com/Linaro/odp/pull/332
 ** Patch: https://github.com/Linaro/odp/pull/332.patch
 ** Base sha: 0980001e33b4190133d478a0aa2e718fd1e3c164
 ** Merge commit sha: 821e53e2ab0847f73ddb171a65e3e4fc5d28e64f
 **/
 include/odp/api/spec/ipsec.h        | 13 +++++++++----
 include/odp/api/spec/packet.h       | 32 +++++++++++++++++---------------
 include/odp/api/spec/packet_io.h    |  9 +++++++--
 platform/linux-generic/odp_packet.c |  2 +-
 test/validation/api/packet/packet.c | 10 +++++-----
 5 files changed, 39 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/include/odp/api/spec/ipsec.h b/include/odp/api/spec/ipsec.h
index d57815ed2..8a52c9ff6 100644
--- a/include/odp/api/spec/ipsec.h
+++ b/include/odp/api/spec/ipsec.h
@@ -148,10 +148,15 @@  typedef struct odp_ipsec_inbound_config_t {
 	/** Parse packet headers after IPSEC transformation
 	 *
 	 *  Select header parsing level after inbound processing. Headers of the
-	 *  resulting packet must be parsed (at least) up to this level. Parsing
-	 *  starts from IP (layer 3). Each successfully transformed packet has
-	 *  a valid value for L3 offset regardless of the parse configuration.
-	 *  Default value is ODP_IPSEC_LAYER_NONE.
+	 *  resulting packet must be checked (at least) up to this level.
+	 *  Parsing starts from IP (layer 3). Packet metadata from IP to this
+	 *  layer is set. In addition, offset (and pointer) to the next layer
+	 *  is set. Other layer/protocol specific metadata have undefined
+	 *  values.
+	 *
+	 *  Each successfully transformed packet has a valid value for L3 offset
+	 *  regardless of the parse configuration. Default value is
+	 *  ODP_IPSEC_LAYER_NONE. ODP_IPSEC_LAYER_L2 is not a valid value.
 	 */
 	odp_ipsec_proto_layer_t parse;
 
diff --git a/include/odp/api/spec/packet.h b/include/odp/api/spec/packet.h
index d444c317a..ec8dca673 100644
--- a/include/odp/api/spec/packet.h
+++ b/include/odp/api/spec/packet.h
@@ -1188,7 +1188,7 @@  typedef struct odp_packet_parse_param_t {
 
 	/** Continue parsing until this layer. Must be the same or higher
 	 *  layer than the layer of 'proto'. */
-	odp_proto_layer_t layer;
+	odp_proto_layer_t last_layer;
 
 	/** Flags to control payload data checks up to the selected parse
 	 *  layer. Checksum checking status can be queried for each packet with
@@ -1220,19 +1220,21 @@  typedef struct odp_packet_parse_param_t {
 /**
  * Parse packet
  *
- * Parse protocol headers in packet data. Parsing starts at 'offset', which
- * is the first header byte of protocol 'param.proto'. Parameter 'param.layer'
- * defines the last layer application is interested about.
- * Use ODP_PROTO_LAYER_ALL for all layers. A successful operation sets or resets
- * packet metadata for all layers from the layer of 'param.proto' to the
- * application defined last layer. Metadata of other layers have undefined
- * values. When operation fails, metadata of all protocol layers have undefined
- * values.
+ * Parse protocol headers in packet data and update layer/protocol specific
+ * metadata (e.g. offsets, errors, protocols, checksum statuses, etc). Parsing
+ * starts at 'offset', which is the first header byte of protocol 'param.proto'.
+ * Parameter 'param.last_layer' defines the last layer application requests
+ * to check. Use ODP_PROTO_LAYER_ALL for all layers. A successful operation
+ * sets (or resets) packet metadata for all layers from the layer of
+ * 'param.proto' to the application defined last layer. In addition, offset
+ * (and pointer) to the next layer is set. Other layer/protocol specific
+ * metadata have undefined values. When operation fails, all layer/protocol
+ * specific metadata have undefined values.
  *
  * @param pkt     Packet handle
  * @param offset  Byte offset into the packet
- * @param param   Parse parameters. Proto and layer fields must be set. Clear
- *                all check bits that are not used.
+ * @param param   Parse parameters. Proto and last_layer fields must be set.
+ *                Clear all check bits that are not used.
  *
  * @retval 0 on success
  * @retval <0 on failure
@@ -1244,14 +1246,14 @@  int odp_packet_parse(odp_packet_t pkt, uint32_t offset,
  * Parse multiple packets
  *
  * Otherwise like odp_packet_parse(), but parses multiple packets. Packets may
- * have unique offsets, but must start with the same protocol. Also, packets are
- * parsed up to the same protocol layer.
+ * have unique offsets, but must start with the same protocol. The same
+ * parse parameters are applied to all packets.
  *
  * @param pkt     Packet handle array
  * @param offset  Byte offsets into the packets
  * @param num     Number of packets and offsets
- * @param param   Parse parameters. Proto and layer fields must be set. Clear
- *                all check bits that are not used.
+ * @param param   Parse parameters. Proto and last_layer fields must be set.
+ *                Clear all check bits that are not used.
  *
  * @return Number of packets parsed successfully (0 ... num)
  * @retval <0 on failure
diff --git a/include/odp/api/spec/packet_io.h b/include/odp/api/spec/packet_io.h
index 60d13043d..9f7305c2c 100644
--- a/include/odp/api/spec/packet_io.h
+++ b/include/odp/api/spec/packet_io.h
@@ -404,8 +404,13 @@  typedef enum odp_pktio_parser_layer_t {
 typedef struct odp_pktio_parser_config_t {
 	/** Protocol parsing level in packet input
 	  *
-	  * Parse protocol layers in minimum up to this level during packet
-	  * input. The default value is ODP_PKTIO_PARSER_LAYER_ALL. */
+	  * Application requires that protocol headers in a packet are checked
+	  * up to this layer during packet input. Use ODP_PROTO_LAYER_ALL for
+	  * all layers. Packet metadata for this and all preceding layers are
+	  * set. In addition, offset (and pointer) to the next layer is set.
+	  * Other layer/protocol specific metadata have undefined values.
+	  *
+	  * The default value is ODP_PKTIO_PARSER_LAYER_ALL. */
 	odp_pktio_parser_layer_t layer;
 
 } odp_pktio_parser_config_t;
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index bdcb482fa..55f59178b 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -2311,7 +2311,7 @@  int odp_packet_parse(odp_packet_t pkt, uint32_t offset,
 	uint32_t seg_len;
 	uint32_t packet_len = pkt_hdr->frame_len;
 	odp_proto_t proto = param->proto;
-	odp_proto_layer_t layer = param->layer;
+	odp_proto_layer_t layer = param->last_layer;
 	int ret;
 	uint16_t ethtype;
 
diff --git a/test/validation/api/packet/packet.c b/test/validation/api/packet/packet.c
index ce4d66c0b..210ce9059 100644
--- a/test/validation/api/packet/packet.c
+++ b/test/validation/api/packet/packet.c
@@ -2450,7 +2450,7 @@  void packet_test_parse(void)
 	}
 
 	parse.proto = ODP_PROTO_ETH;
-	parse.layer = ODP_PROTO_LAYER_ALL;
+	parse.last_layer = ODP_PROTO_LAYER_ALL;
 	parse.all_check = 0;
 
 	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
@@ -2481,7 +2481,7 @@  void packet_test_parse(void)
 	}
 
 	parse.proto = ODP_PROTO_IPV4;
-	parse.layer = ODP_PROTO_LAYER_L4;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
 	parse.all_check = 0;
 
 	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
@@ -2511,7 +2511,7 @@  void packet_test_parse(void)
 	}
 
 	parse.proto = ODP_PROTO_ETH;
-	parse.layer = ODP_PROTO_LAYER_L4;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
 	parse.all_check = 0;
 
 	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
@@ -2541,7 +2541,7 @@  void packet_test_parse(void)
 	}
 
 	parse.proto = ODP_PROTO_ETH;
-	parse.layer = ODP_PROTO_LAYER_L4;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
 	parse.all_check = 0;
 
 	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);
@@ -2572,7 +2572,7 @@  void packet_test_parse(void)
 	}
 
 	parse.proto = ODP_PROTO_ETH;
-	parse.layer = ODP_PROTO_LAYER_ALL;
+	parse.last_layer = ODP_PROTO_LAYER_ALL;
 	parse.all_check = 0;
 
 	CU_ASSERT(odp_packet_parse(pkt[0], offset[0], &parse) == 0);