lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] 8-byte memory alignment issues


From: Rishi Khan
Subject: Re: [lwip-users] 8-byte memory alignment issues
Date: Mon, 11 Aug 2008 14:47:32 -0400

Whoops, I copied the old code wrong in my solution (notice, the first line of the old code is different now):
Here is my solution:
in tcp_out.c:tcp_output line 976 (your line # may be different) it was:

    p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
    if (p == NULL) {
LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
      TCP_STATS_INC(tcp.err);
      return ERR_BUF;
    }

I changed it to:
    p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_RAM);
    if (p == NULL) {
LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
      TCP_STATS_INC(tcp.err);
      return ERR_BUF;
    }
    if (pbuf_header(p, TCP_HLEN)) {
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_out: (ACK) no room for TCP header in pbuf.\n"));
      TCP_STATS_INC(tcp.err);
      return ERR_MEM;
    }

On Aug 11, 2008, at 2:42 PM, Rishi Khan wrote:

I am trying to use MEM_ALIGNMENT = 8. However, I am having trouble sending TCP packets that are aligned. The problem is that I really need the DATA aligned. What happens is tcp_output calls:
pbuf_alloc(PBUF_IP,TCP_HLEN, PBUF_RAM)
where IP_HLEN = 20, TCP_HLEN=20. So, the pbuf is aligned such that the TCP header is aligned on an 8 byte boundary. However, when I subtract 20 (the IP header) and 16 (the ETH header with a 2 byte padding), I am no longer 8 byte aligned (only 4 byte aligned). In most cases, I'd like to see this:

----------8 byte alignment marker----------------
16 byte ETH header (2 byte padding in the front)
20 byte IP header
20 byte TCP header
DATA

So the data starts on byte 56, which is 8 byte aligned. However I get:

16 byte ETH header (2 byte padding in the front)
20 byte IP header
----------8 byte alignment marker----------------
20 byte TCP header
DATA

Now the data and the beginning of the packet are not 8 byte aligned. What would you suggest as a way to maintain 8 byte alignment?


Here is my solution:
in tcp_out.c:tcp_output line 976 (your line # may be different) it was:

    p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_RAM);
    if (p == NULL) {
LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
      TCP_STATS_INC(tcp.err);
      return ERR_BUF;
    }

I changed it to:
    p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_RAM);
    if (p == NULL) {
LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
      TCP_STATS_INC(tcp.err);
      return ERR_BUF;
    }
    if (pbuf_header(p, TCP_HLEN)) {
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_out: (ACK) no room for TCP header in pbuf.\n"));
      TCP_STATS_INC(tcp.err);
      return ERR_MEM;
    }

This works. Do you think this is the right solution?

If so, there are also places in tcp_rst, tcp_keepalive, tcp_zerowindow_probe, udp_sendto_if, ip_frag that are coded like this too.

Do you want a patch?

Rishi



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






reply via email to

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