lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [lwip-users] DHCP issues....problem found; how do I solve it?


From: Tom C. Barker
Subject: RE: [lwip-users] DHCP issues....problem found; how do I solve it?
Date: Tue, 2 Dec 2003 13:02:39 -0800

Hi Leon,
Thanks.

I have found the issue. It will never arise with a 2-byte or 1-byte aligned
machine.

The issue is here in pbuf.c:

  p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf) +
offset));

This works fine if offset % 4 = 0 or you are on a 1- or 2-byte machine. For
ethernet,
((all headers) % 4 != 0) because the eth_hdr is 14 bytes. So forcing the
(data) payload to 
(payload % 4 = 0) _always_ forces the eventual eth_hdr (or final payload) to


    orig_payload - udp - ip - eth = orig_payload - 8 - 20 - 14

which is never (% 4 = 0). But on a 1-byte or 2-byte aligned machine, you are
ok.

So, 

//    p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf) +
offset));
    p->payload = (void *)((u8_t *)p + (sizeof(struct pbuf) + offset));

and 

//    LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
//           ((u32_t)p->payload % MEM_ALIGNMENT) == 0);

fixes it for now....
Note that even when PBUF_LINK_HLEN is changed from the default of 16 to the
actual of 14,
(and PBUF_LINK_HLEN has to be changed for the new code to work), the former
code still is 
not compensating for the eventual subtraction of 14 bytes.

Note that the LWIP_ASSERT would give me a false positive.

Please give me me your opinion on this.
Also, do I need to change the same for case PBUF_POOL:?

Tom







-----Original Message-----
From: Leon Woestenberg [mailto:address@hidden
Sent: Monday, December 01, 2003 2:49 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] DHCP issues....problem found; how do I solve
it?


Hello Tom,

> This has been set all the time. If I take out the
> memcpy, DHCP never gets a properly formed REQUEST out.
>
> #define MEM_ALIGNMENT           4
>
DHCP allocates memory for request packets in the following manner:

dhcp_create_request(struct netif *netif)
{
  ...
  dhcp->p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg),
PBUF_RAM);


This in turn results in the following piece of code being executed:

pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
{
  ...
  case PBUF_RAM:
    /* If pbuf is to be allocated in RAM, allocate memory for it. */
    p = mem_malloc(MEM_ALIGN_SIZE(sizeof(struct pbuf) + length + offset));
    ....
    /* Set up internal structure of the pbuf. */
    p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf) +
offset));
    ...
    LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
           ((u32_t)p->payload % MEM_ALIGNMENT) == 0);


There are MEM_ALIGN macro's and even an assertion to make sure the payload
is aligned
properly.

Please use any debugging means to see where your application fails aligning.

Regards,

Leon.



_______________________________________________
lwip-users mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/lwip-users




reply via email to

[Prev in Thread] Current Thread [Next in Thread]