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.k...@linaro.org>
---
 platform/linux-generic/include/odp_packet_internal.h | 5 +++++
 platform/linux-generic/odp_packet.c                  | 5 +++++
 2 files changed, 10 insertions(+)

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;
 }
-- 
1.9.1

_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to