diff mbox

[v2,2/2] linux-generic: packet: don't look for L2 header if there isn't any

Message ID 1458321603-23979-3-git-send-email-zoltan.kiss@linaro.org
State Accepted
Commit c487453e599b0f2bba3e001061367eabb586f620
Headers show

Commit Message

Zoltan Kiss March 18, 2016, 5:20 p.m. UTC
The L2 offset functions should consider the L2 flag: return negative
answer if there isn't any, and implicitly set it when offset is set.
E.g. user created packets don't have L2 headers immediately.

Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
---
 platform/linux-generic/include/odp_packet_internal.h | 5 +++++
 platform/linux-generic/odp_packet.c                  | 5 +++++
 2 files changed, 10 insertions(+)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 7974a20..92b770f 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -272,6 +272,11 @@  static inline int packet_hdr_has_l2(odp_packet_hdr_t *pkt_hdr)
 	return pkt_hdr->input_flags.l2;
 }
 
+static inline void packet_hdr_has_l2_set(odp_packet_hdr_t *pkt_hdr, int val)
+{
+	pkt_hdr->input_flags.l2 = val;
+}
+
 static inline int packet_hdr_has_eth(odp_packet_hdr_t *pkt_hdr)
 {
 	return pkt_hdr->input_flags.eth;
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index aac42b6..2c44316 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -353,12 +353,16 @@  uint32_t odp_packet_user_area_size(odp_packet_t pkt)
 void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+	if (!packet_hdr_has_l2(pkt_hdr))
+		return NULL;
 	return packet_map(pkt_hdr, pkt_hdr->l2_offset, len);
 }
 
 uint32_t odp_packet_l2_offset(odp_packet_t pkt)
 {
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
+	if (!packet_hdr_has_l2(pkt_hdr))
+		return ODP_PACKET_OFFSET_INVALID;
 	return pkt_hdr->l2_offset;
 }
 
@@ -369,6 +373,7 @@  int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset)
 	if (offset >= pkt_hdr->frame_len)
 		return -1;
 
+	packet_hdr_has_l2_set(pkt_hdr, 1);
 	pkt_hdr->l2_offset = offset;
 	return 0;
 }