diff mbox series

[API-NEXT,v3,8/14] linux-gen: use packet l3 type rather than ipv4/ipv6/arp input flags

Message ID 1518008409-31750-9-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v3,1/14] linux-gen: packet: implement packet l3/l4 proto types | expand

Commit Message

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


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

---
/** Email created from pull request 457 (lumag:packet-types)
 ** https://github.com/Linaro/odp/pull/457
 ** Patch: https://github.com/Linaro/odp/pull/457.patch
 ** Base sha: e1175d5a69c65bb465022c9f1381c40fdb5c4069
 ** Merge commit sha: 86fcf3650d33f5dd82712dda131fb8ca66a3bdf8
 **/
 .../include/odp/api/plat/packet_inline_types.h     |  3 --
 .../include/odp_classification_inlines.h           |  9 ++++--
 .../linux-generic/include/odp_packet_internal.h    |  7 ++++-
 platform/linux-generic/odp_classification.c        |  8 +++---
 platform/linux-generic/odp_packet.c                |  6 ----
 platform/linux-generic/odp_packet_flags.c          | 33 ++++++++++++++++++----
 6 files changed, 43 insertions(+), 23 deletions(-)
diff mbox series

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 a190b45af..fb54e6402 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
@@ -72,10 +72,7 @@  typedef union {
 		uint64_t vlan_qinq:1; /* Stacked VLAN found, QinQ */
 
 		uint64_t snap:1;      /* SNAP */
-		uint64_t arp:1;       /* ARP */
 
-		uint64_t ipv4:1;      /* IPv4 */
-		uint64_t ipv6:1;      /* IPv6 */
 		uint64_t ip_bcast:1;  /* IP broadcast */
 		uint64_t ip_mcast:1;  /* IP multicast */
 		uint64_t ipfrag:1;    /* IP fragment */
diff --git a/platform/linux-generic/include/odp_classification_inlines.h b/platform/linux-generic/include/odp_classification_inlines.h
index 3f1d9ce6a..f9462e976 100644
--- a/platform/linux-generic/include/odp_classification_inlines.h
+++ b/platform/linux-generic/include/odp_classification_inlines.h
@@ -51,7 +51,8 @@  static inline int verify_pmr_ip_proto(const uint8_t *pkt_addr,
 {
 	const _odp_ipv4hdr_t *ip;
 	uint8_t proto;
-	if (!pkt_hdr->p.input_flags.ipv4)
+
+	if (!packet_hdr_has_ipv4(pkt_hdr))
 		return 0;
 	ip = (const _odp_ipv4hdr_t *)(pkt_addr + pkt_hdr->p.l3_offset);
 	proto = ip->proto;
@@ -67,7 +68,8 @@  static inline int verify_pmr_ipv4_saddr(const uint8_t *pkt_addr,
 {
 	const _odp_ipv4hdr_t *ip;
 	uint32_t ipaddr;
-	if (!pkt_hdr->p.input_flags.ipv4)
+
+	if (!packet_hdr_has_ipv4(pkt_hdr))
 		return 0;
 	ip = (const _odp_ipv4hdr_t *)(pkt_addr + pkt_hdr->p.l3_offset);
 	ipaddr = _odp_be_to_cpu_32(ip->src_addr);
@@ -83,7 +85,8 @@  static inline int verify_pmr_ipv4_daddr(const uint8_t *pkt_addr,
 {
 	const _odp_ipv4hdr_t *ip;
 	uint32_t ipaddr;
-	if (!pkt_hdr->p.input_flags.ipv4)
+
+	if (!packet_hdr_has_ipv4(pkt_hdr))
 		return 0;
 	ip = (const _odp_ipv4hdr_t *)(pkt_addr + pkt_hdr->p.l3_offset);
 	ipaddr = _odp_be_to_cpu_32(ip->dst_addr);
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 83bc27b12..59cb9ded9 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -281,9 +281,14 @@  static inline int packet_hdr_has_eth(odp_packet_hdr_t *pkt_hdr)
 	return pkt_hdr->p.input_flags.eth;
 }
 
+static inline int packet_hdr_has_ipv4(odp_packet_hdr_t *pkt_hdr)
+{
+	return pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_IPV4;
+}
+
 static inline int packet_hdr_has_ipv6(odp_packet_hdr_t *pkt_hdr)
 {
-	return pkt_hdr->p.input_flags.ipv6;
+	return pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_IPV6;
 }
 
 static inline void packet_set_ts(odp_packet_hdr_t *pkt_hdr, odp_time_t *ts)
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index 36358ab4a..5147db137 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -1026,7 +1026,7 @@  static uint32_t packet_rss_hash(odp_packet_hdr_t *pkt_hdr,
 
 	tuple_len = 0;
 	hash = 0;
-	if (pkt_hdr->p.input_flags.ipv4) {
+	if (packet_hdr_has_ipv4(pkt_hdr)) {
 		if (hash_proto.ipv4) {
 			/* add ipv4 */
 			ipv4 = (const _odp_ipv4hdr_t *)(base +
@@ -1051,7 +1051,7 @@  static uint32_t packet_rss_hash(odp_packet_hdr_t *pkt_hdr,
 			tuple.v4.dport = udp->dst_port;
 			tuple_len += 1;
 		}
-	} else if (pkt_hdr->p.input_flags.ipv6) {
+	} else if (packet_hdr_has_ipv6(pkt_hdr)) {
 		if (hash_proto.ipv6) {
 			/* add ipv6 */
 			ipv6 = (const _odp_ipv6hdr_t *)(base +
@@ -1089,11 +1089,11 @@  cos_t *match_qos_l3_cos(pmr_l3_cos_t *l3_cos, const uint8_t *pkt_addr,
 	const _odp_ipv4hdr_t *ipv4;
 	const _odp_ipv6hdr_t *ipv6;
 
-	if (hdr->p.input_flags.l3 && hdr->p.input_flags.ipv4) {
+	if (hdr->p.input_flags.l3 && packet_hdr_has_ipv4(hdr)) {
 		ipv4 = (const _odp_ipv4hdr_t *)(pkt_addr + hdr->p.l3_offset);
 		dscp = _ODP_IPV4HDR_DSCP(ipv4->tos);
 		cos = l3_cos->cos[dscp];
-	} else if (hdr->p.input_flags.l3 && hdr->p.input_flags.ipv6) {
+	} else if (hdr->p.input_flags.l3 && packet_hdr_has_ipv6(hdr)) {
 		ipv6 = (const _odp_ipv6hdr_t *)(pkt_addr + hdr->p.l3_offset);
 		dscp = _ODP_IPV6HDR_DSCP(ipv6->ver_tc_flow);
 		cos = l3_cos->cos[dscp];
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 4b90e9f07..14ed13bca 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -2196,14 +2196,12 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 	/* Parse Layer 3 headers */
 	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);
@@ -2211,7 +2209,6 @@  int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr,
 		break;
 
 	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;
@@ -2562,9 +2559,6 @@  void odp_packet_l3_type_set(odp_packet_t pkt, odp_proto_l3_type_t val)
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 
 	pkt_hdr->p.input_flags.l3_type = val;
-	pkt_hdr->p.input_flags.arp = (val == ODP_PROTO_L3_TYPE_ARP);
-	pkt_hdr->p.input_flags.ipv4 = (val == ODP_PROTO_L3_TYPE_IPV4);
-	pkt_hdr->p.input_flags.ipv6 = (val == ODP_PROTO_L3_TYPE_IPV6);
 }
 
 odp_proto_l4_type_t odp_packet_l4_type(odp_packet_t pkt)
diff --git a/platform/linux-generic/odp_packet_flags.c b/platform/linux-generic/odp_packet_flags.c
index 0c33666eb..ab34d0950 100644
--- a/platform/linux-generic/odp_packet_flags.c
+++ b/platform/linux-generic/odp_packet_flags.c
@@ -83,17 +83,23 @@  int odp_packet_has_vlan_qinq(odp_packet_t pkt)
 
 int odp_packet_has_arp(odp_packet_t pkt)
 {
-	retflag(pkt, input_flags.arp);
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	return pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_ARP;
 }
 
 int odp_packet_has_ipv4(odp_packet_t pkt)
 {
-	retflag(pkt, input_flags.ipv4);
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	return pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_IPV4;
 }
 
 int odp_packet_has_ipv6(odp_packet_t pkt)
 {
-	retflag(pkt, input_flags.ipv6);
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	return pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_IPV6;
 }
 
 int odp_packet_has_ip_bcast(odp_packet_t pkt)
@@ -226,17 +232,32 @@  void odp_packet_has_vlan_qinq_set(odp_packet_t pkt, int val)
 
 void odp_packet_has_arp_set(odp_packet_t pkt, int val)
 {
-	setflag(pkt, input_flags.arp, val);
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	if (val)
+		odp_packet_l3_type_set(pkt, ODP_PROTO_L3_TYPE_ARP);
+	else if (pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_ARP)
+		odp_packet_l3_type_set(pkt, ODP_PROTO_L3_TYPE_NONE);
 }
 
 void odp_packet_has_ipv4_set(odp_packet_t pkt, int val)
 {
-	setflag(pkt, input_flags.ipv4, val);
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	if (val)
+		odp_packet_l3_type_set(pkt, ODP_PROTO_L3_TYPE_IPV4);
+	else if (pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_IPV4)
+		odp_packet_l3_type_set(pkt, ODP_PROTO_L3_TYPE_NONE);
 }
 
 void odp_packet_has_ipv6_set(odp_packet_t pkt, int val)
 {
-	setflag(pkt, input_flags.ipv6, val);
+	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+
+	if (val)
+		odp_packet_l3_type_set(pkt, ODP_PROTO_L3_TYPE_IPV6);
+	else if (pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_IPV6)
+		odp_packet_l3_type_set(pkt, ODP_PROTO_L3_TYPE_NONE);
 }
 
 void odp_packet_has_ip_bcast_set(odp_packet_t pkt, int val)