[API-NEXT,v1,1/4] linux-gen: packet: implement packet l3/l4 proto types

Message ID 1518051607-20804-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • Packet L3/L4 type implementation
Related show

Commit Message

Github ODP bot Feb. 8, 2018, 1 a.m.
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 459 (lumag:packet-types-2)
 ** https://github.com/Linaro/odp/pull/459
 ** Patch: https://github.com/Linaro/odp/pull/459.patch
 ** Base sha: af7be638ef9ac98bdb1f2e4917f152889eb1850f
 ** Merge commit sha: 714954eb283fbb69b44b8dc12b02f5cfbcf17577
 **/
 .../include/odp/api/plat/packet_inline_types.h        |  3 +++
 platform/linux-generic/odp_packet.c                   | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

Patch

diff --git a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h
index e8ebdabb1..a190b45af 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h
@@ -98,6 +98,9 @@  typedef union {
 		uint64_t l3_chksum_done:1; /* L3 checksum validation done */
 		uint64_t l4_chksum_done:1; /* L4 checksum validation done */
 		uint64_t ipsec_udp:1; /* UDP-encapsulated IPsec packet */
+
+		uint64_t l3_type : 8; /* L3 packet type */
+		uint64_t l4_type : 8; /* L4 packet type */
 	};
 
 } _odp_packet_input_flags_t;
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index dc16e9be4..f5151d293 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -2197,12 +2197,14 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 	switch (ethtype) {
 	case _ODP_ETHTYPE_IPV4:
 		prs->input_flags.ipv4 = 1;
+		prs->input_flags.l3_type = ODP_PROTO_L3_TYPE_IPV4;
 		ip_proto = parse_ipv4(prs, &parseptr, &offset, frame_len);
 		prs->l4_offset = offset;
 		break;
 
 	case _ODP_ETHTYPE_IPV6:
 		prs->input_flags.ipv6 = 1;
+		prs->input_flags.l3_type = ODP_PROTO_L3_TYPE_IPV6;
 		ip_proto = parse_ipv6(prs, &parseptr, &offset, frame_len,
 				      seg_len);
 		prs->l4_offset = offset;
@@ -2210,6 +2212,7 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 
 	case _ODP_ETHTYPE_ARP:
 		prs->input_flags.arp = 1;
+		prs->input_flags.l3_type = ODP_PROTO_L3_TYPE_ARP;
 		ip_proto = 255;  /* Reserved invalid by IANA */
 		break;
 
@@ -2223,6 +2226,7 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 
 	/* Set l4 flag only for known ip_proto */
 	prs->input_flags.l4 = 1;
+	prs->input_flags.l4_type = ip_proto;
 
 	/* Parse Layer 4 headers */
 	switch (ip_proto) {
@@ -2267,6 +2271,7 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 
 	default:
 		prs->input_flags.l4 = 0;
+		prs->input_flags.l4_type = ODP_PROTO_L4_TYPE_NONE;
 		break;
 	}
 
@@ -2544,3 +2549,17 @@  int odp_packet_has_ref(odp_packet_t pkt)
 
 	return 0;
 }
+
+odp_proto_l3_type_t odp_packet_l3_type(odp_packet_t pkt)
+{
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	return pkt_hdr->p.input_flags.l3_type;
+}
+
+odp_proto_l4_type_t odp_packet_l4_type(odp_packet_t pkt)
+{
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	return pkt_hdr->p.input_flags.l4_type;
+}