pbuf_header fails in etharp_output

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

pbuf_header fails in etharp_output

Matthias Weisser
Hi

The ping problem I had yesterday disappears when I use a Linux system to ping my target. Now the ICMP packet from Linux arrives inside the lwIP stack and a valid reply message is created. This message is then passed to etharp_output which tries to make room for the ethernet header with the pbuf_header function. But this wont work. This

if ((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf))

is true and therefor the function fails. I don't have any idea how to fix this. Maybe its quite a simple problem (missing define?).


Regards,
Matthias



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: pbuf_header fails in etharp_output

Kieran Mansley
On Tue, 2007-05-22 at 11:50 +0200, Matthias Weisser wrote:

> Hi
>
> The ping problem I had yesterday disappears when I use a Linux system
> to ping my target. Now the ICMP packet from Linux arrives inside the
> lwIP stack and a valid reply message is created. This message is then
> passed to etharp_output which tries to make room for the ethernet
> header with the pbuf_header function. But this wont work. This
>
> if ((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf))
>
> is true and therefor the function fails. I don't have any idea how to
> fix this. Maybe its quite a simple problem (missing define?).

lwIP is a little bit cheeky and reuses the pbuf with the ICMP request to
form the ICMP reply.  It is therefore assuming that there is room at the
front for the necessary headers.  I suppose if your ethernet driver was
being very efficient and had stripped off the ethernet header before
creating the pbuf, this might not be the case.  Can you show how you're
creating the pbuf for the received ICMP packet?

The other thing to check is what the value is for the PBUF_LINK_HLEN,
and what the values in that "if" statement above are.

Kieran



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: pbuf_header fails in etharp_output

Goldschmidt Simon

> lwIP is a little bit cheeky and reuses the pbuf with the ICMP
> request to form the ICMP reply.  It is therefore assuming
> that there is room at the front for the necessary headers.  I
> suppose if your ethernet driver was being very efficient and
> had stripped off the ethernet header before creating the
> pbuf, this might not be the case.  Can you show how you're

If that's the case, it should be changed so that etharp can add
a PBUF_RAM in front. To me such a driver seems a good idea
for low memory targets (if you don't want to pass received IP
frames through etharp).

Simon


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Antw: RE: pbuf_header fails in etharp_output

Matthias Weisser


>>> "Goldschmidt Simon" <[hidden email]>
>> lwIP is a little bit cheeky and reuses the pbuf with the ICMP
>> request to form the ICMP reply.  It is therefore assuming
>> that there is room at the front for the necessary headers.  I
>> suppose if your ethernet driver was being very efficient and
>> had stripped off the ethernet header before creating the
>> pbuf, this might not be the case.  Can you show how you're

Yes, that's what I am doing. If a ethernet frame with type IP arrives I strip the 14 byte ethernet header. But not because I want to save memory (RAM is not the big problem in my system) but because I need the IP header aligned at a 4 byte boundary.

> If that's the case, it should be changed so that etharp can add
> a PBUF_RAM in front. To me such a driver seems a good idea
> for low memory targets (if you don't want to pass received IP
> frames through etharp).

Can you give me a little hint on how to do this or a advise how to put the ethernet packets into the pbufs to prevent alignment problems.


Matthias



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Antw: RE: pbuf_header fails in etharp_output

Kieran Mansley
On Tue, 2007-05-22 at 14:43 +0200, Matthias Weisser wrote:

>
> >>> "Goldschmidt Simon" <[hidden email]>
> >> lwIP is a little bit cheeky and reuses the pbuf with the ICMP
> >> request to form the ICMP reply.  It is therefore assuming
> >> that there is room at the front for the necessary headers.  I
> >> suppose if your ethernet driver was being very efficient and
> >> had stripped off the ethernet header before creating the
> >> pbuf, this might not be the case.  Can you show how you're
>
> Yes, that's what I am doing.

In that case it's technically the fault of lwIP and we should perhaps
change our ICMP to not do this (or at least check the pbuf to see if
it's OK before it does).  If you'd rather not work around it, please
file a bug so that it will eventually get fixed.

>  If a ethernet frame with type IP arrives I strip the 14 byte ethernet
> header. But not because I want to save memory (RAM is not the big
> problem in my system) but because I need the IP header aligned at a 4
> byte boundary.

The normal way to achieve the IP header aligned on a 4-byte boundary is
to get your MAC to deliver the packet to a 2-byte offset.  Then, if you
have a 14-byte ethernet header, the IP header should be aligned as you
require.  Not all MACs support this though I suppose, so your way should
also be supported.

An easy workaround would be in this case to call pbuf_header to reserve
16 bytes before you copy in the packet data.  This would ensure there is
space in the pbuf to put the outgoing ethernet header, but is really a
bit of a hack and the right thing to do is fix it in lwIP's ICMP code.

Kieran



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: Antw: RE: pbuf_header fails in etharp_output

Goldschmidt Simon

> > >> lwIP is a little bit cheeky and reuses the pbuf with the ICMP
> > >> request to form the ICMP reply.  It is therefore assuming that
> > >> there is room at the front for the necessary headers.  I suppose
if
> > >> your ethernet driver was being very efficient and had stripped
off
> > >> the ethernet header before creating the pbuf, this might not be
the
> > >> case.  Can you show how you're
> >
> > Yes, that's what I am doing.
>
> In that case it's technically the fault of lwIP and we should
> perhaps change our ICMP to not do this (or at least check the
> pbuf to see if it's OK before it does).  If you'd rather not
> work around it, please file a bug so that it will eventually
> get fixed.

Yes, please file a bug report!
I'd change etharp.c to allocate a temporary pbuf  for the MAC header
as do all other protocolsm but we can discuss that on lwip-devel.

> >  If a ethernet frame with type IP arrives I strip the 14 byte
ethernet
> > header. But not because I want to save memory (RAM is not the big
> > problem in my system) but because I need the IP header aligned at a
4
> > byte boundary.
>
> The normal way to achieve the IP header aligned on a 4-byte
> boundary is to get your MAC to deliver the packet to a 2-byte
> offset.  Then, if you have a 14-byte ethernet header, the IP
> header should be aligned as you require.  Not all MACs
> support this though I suppose, so your way should also be supported.

If your "MAC" supports copying only the IP data, I suppose you copy
it using memcpy(). Then you can copy to a 2-byte aligned pointer, too.
I think normal way to achieve the 2-byte alignment is shown in
ethernetif.c
(using ETH_PAD_SIZE).

> An easy workaround would be in this case to call pbuf_header
> to reserve
> 16 bytes before you copy in the packet data.  This would
> ensure there is space in the pbuf to put the outgoing
> ethernet header, but is really a bit of a hack and the right
> thing to do is fix it in lwIP's ICMP code.

That would make ICMP dependent of the link layer!


Simon


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: Antw: RE: pbuf_header fails in etharp_output

Kieran Mansley
On Tue, 2007-05-22 at 15:25 +0200, Goldschmidt Simon wrote:
> > An easy workaround would be in this case to call pbuf_header
> > to reserve
> > 16 bytes before you copy in the packet data.  This would
> > ensure there is space in the pbuf to put the outgoing
> > ethernet header, but is really a bit of a hack and the right
> > thing to do is fix it in lwIP's ICMP code.
>
> That would make ICMP dependent of the link layer!

No more so than TCP, UDP, etc.  It would (if there wasn't enough space
in the pbuf it already had) simply allocate a pbuf using the PBUF_IP
pbuf_layer flag, and so it would have enough space reserved for the IP
and link headers.

Kieran



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: pbuf_header fails in etharp_output

Goldschmidt Simon
> > That would make ICMP dependent of the link layer!
>
> No more so than TCP, UDP, etc.  It would (if there wasn't
> enough space in the pbuf it already had) simply allocate a
> pbuf using the PBUF_IP pbuf_layer flag, and so it would have
> enough space reserved for the IP and link headers.

But how does the ICMP code know how much space to reserve fo the
link layer? As far as I know, UDP does not make such an assumption,
i only checks if the UDP header fits in and allocates another pbuf
if not. But in ICMP, the packet fits in the pbuf (and also the IP
header). Only the MAC header does not fit in. I think it's a wrong
design of the etharp module that it can't allocate its own header.
On the other side, ip_output_if() does it the same way.
So the easiest modification would be to allocate a new pbuf for
ICMP?


Simon


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: pbuf_header fails in etharp_output

Kieran Mansley
On Tue, 2007-05-22 at 15:47 +0200, Goldschmidt Simon wrote:
> > > That would make ICMP dependent of the link layer!
> >
> > No more so than TCP, UDP, etc.  It would (if there wasn't
> > enough space in the pbuf it already had) simply allocate a
> > pbuf using the PBUF_IP pbuf_layer flag, and so it would have
> > enough space reserved for the IP and link headers.
>
> But how does the ICMP code know how much space to reserve fo the
> link layer?

Look at the start of pbuf_alloc().  It increases the required length
depending on what pbuf_layer is.  It uses the port-defined constants
PBUF_TRANSPORT_HLEN, PBUF_IP_HLEN and PBUF_LINK_HLEN to know how much it
needs to reserve for the headers of each layer.

Kieran



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: Antw: RE: pbuf_header fails in etharp_output

Matthias Weisser
In reply to this post by Goldschmidt Simon
>>>> that there is room at the front for the necessary headers.  I
>>>> suppose if your ethernet driver was being very efficient and
>>>> had stripped off the ethernet header before creating the
>>>> pbuf, this might not be the case.  Can you show how you're
>>>
>>> Yes, that's what I am doing.
>>>
>> In that case it's technically the fault of lwIP and we should
>> perhaps change our ICMP to not do this (or at least check the
>> pbuf to see if it's OK before it does).  If you'd rather not
>> work around it, please file a bug so that it will eventually
>> get fixed.
>
> Yes, please file a bug report!

About what? That ip_input fails if the IP header is not 4 byte aligned? Or that etharp_output fails if there is no room at the beginning of a p_buf to store the ethernet header?


Matthias



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

RE: Antw: RE: pbuf_header fails in etharp_output

Kieran Mansley
On Wed, 2007-05-23 at 08:19 +0200, Matthias Weisser wrote:

> >>>> that there is room at the front for the necessary headers.  I
> >>>> suppose if your ethernet driver was being very efficient and
> >>>> had stripped off the ethernet header before creating the
> >>>> pbuf, this might not be the case.  Can you show how you're
> >>>
> >>> Yes, that's what I am doing.
> >>>
> >> In that case it's technically the fault of lwIP and we should
> >> perhaps change our ICMP to not do this (or at least check the
> >> pbuf to see if it's OK before it does).  If you'd rather not
> >> work around it, please file a bug so that it will eventually
> >> get fixed.
> >
> > Yes, please file a bug report!
>
> About what? That ip_input fails if the IP header is not 4 byte
> aligned? Or that etharp_output fails if there is no room at the
> beginning of a p_buf to store the ethernet header?

That ICMP assumes the pbuf you give it has space for a ethernet header
at the front.

Kieran



_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users