diff mbox series

[API-NEXT,v5,4/6] linux-gen: packet: add parse API

Message ID 1510228814-21692-5-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v5,1/6] api: packet: add parse functions | expand

Commit Message

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


Implemented new API functions for packet parsing.

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

---
/** Email created from pull request 273 (psavol:next-packet-parse)
 ** https://github.com/Linaro/odp/pull/273
 ** Patch: https://github.com/Linaro/odp/pull/273.patch
 ** Base sha: d22c949cc466bf28de559855a1cb525740578137
 ** Merge commit sha: 5ed52232b041f855c0e109143480b16ea467c7da
 **/
 .../linux-generic/include/odp_packet_internal.h    |  3 +-
 platform/linux-generic/odp_packet.c                | 62 ++++++++++++++++++++--
 2 files changed, 60 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index fed562aa3..97efcec4b 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -322,8 +322,7 @@  static inline void packet_set_ts(odp_packet_hdr_t *pkt_hdr, odp_time_t *ts)
 }
 
 int packet_parse_common(packet_parser_t *pkt_hdr, const uint8_t *ptr,
-			uint32_t pkt_len, uint32_t seg_len,
-			odp_pktio_parser_layer_t layer);
+			uint32_t pkt_len, uint32_t seg_len, int layer);
 
 int _odp_cls_parse(odp_packet_hdr_t *pkt_hdr, const uint8_t *parseptr);
 
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 3b2fac212..0bba30986 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -2098,8 +2098,7 @@  static inline
 int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 			      uint32_t offset,
 			      uint32_t frame_len, uint32_t seg_len,
-			      odp_pktio_parser_layer_t layer,
-			      uint16_t ethtype)
+			      int layer, uint16_t ethtype)
 {
 	uint8_t  ip_proto;
 
@@ -2199,7 +2198,7 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
  */
 int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr,
 			uint32_t frame_len, uint32_t seg_len,
-			odp_pktio_parser_layer_t layer)
+			int layer)
 {
 	uint32_t offset;
 	uint16_t ethtype;
@@ -2252,6 +2251,63 @@  int packet_parse_l3_l4(odp_packet_hdr_t *pkt_hdr,
 					 layer, ethtype);
 }
 
+int odp_packet_parse(odp_packet_t pkt, uint32_t offset,
+		     const odp_packet_parse_param_t *param)
+{
+	odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
+	void *data;
+	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;
+	int ret;
+	uint16_t ethtype;
+
+	if (proto == ODP_PROTO_NONE || layer == ODP_PROTO_LAYER_NONE)
+		return -1;
+
+	data = packet_map(pkt_hdr, offset, &seg_len, NULL);
+
+	if (data == NULL)
+		return -1;
+
+	packet_parse_reset(pkt_hdr);
+
+	if (proto == ODP_PROTO_ETH) {
+		ret = packet_parse_common(&pkt_hdr->p, data, packet_len,
+					  seg_len, layer);
+
+		if (ret)
+			return -1;
+	} else {
+		if (proto == ODP_PROTO_IPV4)
+			ethtype = _ODP_ETHTYPE_IPV4;
+		else
+			ethtype = _ODP_ETHTYPE_IPV6;
+
+		ret = packet_parse_common_l3_l4(&pkt_hdr->p, data, offset,
+						packet_len, seg_len,
+						layer, ethtype);
+
+		if (ret)
+			return -1;
+	}
+
+	return 0;
+}
+
+int odp_packet_parse_multi(const odp_packet_t pkt[], const uint32_t offset[],
+			   int num, const odp_packet_parse_param_t *param)
+{
+	int i;
+
+	for (i = 0; i < num; i++)
+		if (odp_packet_parse(pkt[i], offset[i], param))
+			return i;
+
+	return num;
+}
+
 uint64_t odp_packet_to_u64(odp_packet_t hdl)
 {
 	return _odp_pri(hdl);