diff mbox

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

Message ID 1456949141-32378-3-git-send-email-zoltan.kiss@linaro.org
State Superseded
Headers show

Commit Message

Zoltan Kiss March 2, 2016, 8:05 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(+)

Comments

Zoltan Kiss March 11, 2016, 7:03 a.m. UTC | #1
Ping

On 03/03/16 03:05, Zoltan Kiss wrote:
> 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 --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
> index d9fe544..1dc875e 100644
> --- a/platform/linux-generic/include/odp_packet_internal.h
> +++ b/platform/linux-generic/include/odp_packet_internal.h
> @@ -263,6 +263,11 @@ static inline int odp_packet_hdr_has_l2(odp_packet_hdr_t *pkt_hdr)
>   	return pkt_hdr->input_flags.l2;
>   }
>   
> +static inline void odp_packet_hdr_has_l2_set(odp_packet_hdr_t *pkt_hdr, int val)
> +{
> +	pkt_hdr->input_flags.l2 = val;
> +}
> +
>   static inline int odp_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 db85b5e..94d7f85 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 (!odp_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 (!odp_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;
>   
> +	odp_packet_hdr_has_l2_set(pkt_hdr, 1);
>   	pkt_hdr->l2_offset = offset;
>   	return 0;
>   }
Zoltan Kiss March 18, 2016, 11:39 a.m. UTC | #2
Ping, added Bill

On 11/03/16 07:03, Zoltan Kiss wrote:
> Ping
>
> On 03/03/16 03:05, Zoltan Kiss wrote:
>> 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 --git a/platform/linux-generic/include/odp_packet_internal.h
>> b/platform/linux-generic/include/odp_packet_internal.h
>> index d9fe544..1dc875e 100644
>> --- a/platform/linux-generic/include/odp_packet_internal.h
>> +++ b/platform/linux-generic/include/odp_packet_internal.h
>> @@ -263,6 +263,11 @@ static inline int
>> odp_packet_hdr_has_l2(odp_packet_hdr_t *pkt_hdr)
>>       return pkt_hdr->input_flags.l2;
>>   }
>> +static inline void odp_packet_hdr_has_l2_set(odp_packet_hdr_t
>> *pkt_hdr, int val)
>> +{
>> +    pkt_hdr->input_flags.l2 = val;
>> +}
>> +
>>   static inline int odp_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 db85b5e..94d7f85 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 (!odp_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 (!odp_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;
>> +    odp_packet_hdr_has_l2_set(pkt_hdr, 1);
>>       pkt_hdr->l2_offset = offset;
>>       return 0;
>>   }
>
Maxim Uvarov March 18, 2016, 12:07 p.m. UTC | #3
On 03/18/16 14:39, Zoltan Kiss wrote:
> Ping, added Bill
>

ping for what?  There are comments to rename functions.

Maxim.

> On 11/03/16 07:03, Zoltan Kiss wrote:
>> Ping
>>
>> On 03/03/16 03:05, Zoltan Kiss wrote:
>>> 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 --git a/platform/linux-generic/include/odp_packet_internal.h
>>> b/platform/linux-generic/include/odp_packet_internal.h
>>> index d9fe544..1dc875e 100644
>>> --- a/platform/linux-generic/include/odp_packet_internal.h
>>> +++ b/platform/linux-generic/include/odp_packet_internal.h
>>> @@ -263,6 +263,11 @@ static inline int
>>> odp_packet_hdr_has_l2(odp_packet_hdr_t *pkt_hdr)
>>>       return pkt_hdr->input_flags.l2;
>>>   }
>>> +static inline void odp_packet_hdr_has_l2_set(odp_packet_hdr_t
>>> *pkt_hdr, int val)
>>> +{
>>> +    pkt_hdr->input_flags.l2 = val;
>>> +}
>>> +
>>>   static inline int odp_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 db85b5e..94d7f85 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 (!odp_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 (!odp_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;
>>> +    odp_packet_hdr_has_l2_set(pkt_hdr, 1);
>>>       pkt_hdr->l2_offset = offset;
>>>       return 0;
>>>   }
>>
Zoltan Kiss March 18, 2016, 1 p.m. UTC | #4
My bad, I read those comments made for the other patch but I haven't 
applied them on this one.

On 18/03/16 12:07, Maxim Uvarov wrote:
> On 03/18/16 14:39, Zoltan Kiss wrote:
>> Ping, added Bill
>>
>
> ping for what?  There are comments to rename functions.
>
> Maxim.
>
>> On 11/03/16 07:03, Zoltan Kiss wrote:
>>> Ping
>>>
>>> On 03/03/16 03:05, Zoltan Kiss wrote:
>>>> 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 --git a/platform/linux-generic/include/odp_packet_internal.h
>>>> b/platform/linux-generic/include/odp_packet_internal.h
>>>> index d9fe544..1dc875e 100644
>>>> --- a/platform/linux-generic/include/odp_packet_internal.h
>>>> +++ b/platform/linux-generic/include/odp_packet_internal.h
>>>> @@ -263,6 +263,11 @@ static inline int
>>>> odp_packet_hdr_has_l2(odp_packet_hdr_t *pkt_hdr)
>>>>       return pkt_hdr->input_flags.l2;
>>>>   }
>>>> +static inline void odp_packet_hdr_has_l2_set(odp_packet_hdr_t
>>>> *pkt_hdr, int val)
>>>> +{
>>>> +    pkt_hdr->input_flags.l2 = val;
>>>> +}
>>>> +
>>>>   static inline int odp_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 db85b5e..94d7f85 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 (!odp_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 (!odp_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;
>>>> +    odp_packet_hdr_has_l2_set(pkt_hdr, 1);
>>>>       pkt_hdr->l2_offset = offset;
>>>>       return 0;
>>>>   }
>>>
>
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index d9fe544..1dc875e 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -263,6 +263,11 @@  static inline int odp_packet_hdr_has_l2(odp_packet_hdr_t *pkt_hdr)
 	return pkt_hdr->input_flags.l2;
 }
 
+static inline void odp_packet_hdr_has_l2_set(odp_packet_hdr_t *pkt_hdr, int val)
+{
+	pkt_hdr->input_flags.l2 = val;
+}
+
 static inline int odp_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 db85b5e..94d7f85 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 (!odp_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 (!odp_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;
 
+	odp_packet_hdr_has_l2_set(pkt_hdr, 1);
 	pkt_hdr->l2_offset = offset;
 	return 0;
 }