[bug #27704] autoip starts with wrong address - ntohl

View: New views
7 Messages — Rating Filter:   Alert me  

[bug #27704] autoip starts with wrong address - ntohl

by Mario Castelán Castro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


URL:
  <http://savannah.nongnu.org/bugs/?27704>

                 Summary: autoip starts with wrong address - ntohl
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: tsomogyi
            Submitted on: Wed 14 Oct 2009 16:10:04 GMT
                Category: IPv4
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release:
            lwIP version: CVS Head

    _______________________________________________________

Details:

Current code in autoip.c:
static void
autoip_create_addr(...)
{
        ...
        u32_t addr = ntohl(LWIP_AUTOIP_CREATE_SEED_ADDR(netif));
        ...

Should be:
        u32_t addr = LWIP_AUTOIP_CREATE_SEED_ADDR(netif);

So ntohl() should be removed, otherwise it reverses the byte order on
little-endian platforms and makes the whole IP address calculation wrong.

I'm wondering if nobody noticed this e.g. on Windows so far...





    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27704>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel

[bug #27704] autoip starts with wrong address - ntohl

by Mario Castelán Castro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Follow-up Comment #1, bug #27704 (project lwip):

Whether this is a bug or not, I guess that depends on the defition of the
macro LWIP_AUTOIP_CREATE_SEED_ADDR() - whether it returns the address in host
or network byte order.

I'd vote for network byte order, but that doesn't seem to be defined. But
then, the default implementation is clearly wrong since it returns host byte
order.

Thus, on win32, I get the address 169.254.254.169, which is a correct autoip
address, but not what we want.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27704>

_______________________________________________
  Nachricht geschickt von/durch Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel

[bug #27704] autoip starts with wrong address - ntohl

by Mario Castelán Castro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Follow-up Comment #2, bug #27704 (project lwip):

goldsimon# yes, it always returns 169.254.254.169 on little-endian (e.g. our
TI DSP or Windows) platforms, because the wrong (mirrored) part is kept by the
mask "addr = AUTOIP_NET | (addr & 0xffff);"
This also means that having two or more devices on the network, they all
picks up the same address (169.254.254.169) causing IP address conflict! In
this case "addr += netif->autoip->tried_llipaddr;" doesn't help either,
because the wrong part is masked.
And as AUTOIP_NET is defined as a 32-bit number, the compiler will generate
the correct byte representation both on little and big endian platforms, thus
ntohl() to be removed.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27704>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel

[bug #27704] autoip starts with wrong address - ntohl

by Mario Castelán Castro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Update of bug #27704 (project lwip):

                  Status:                    None => In Progress            
             Assigned to:                    None => goldsimon              

    _______________________________________________________

Follow-up Comment #3:

But as I said in comment #1, in lwIP, addresses are stored in network byte
order, so the address loaded by LWIP_AUTOIP_CREATE_SEED_ADDR() will be network
byte order, too. Only the default implementation of
LWIP_AUTOIP_CREATE_SEED_ADDR() is wrong and returns host byte order. I'll fix
that.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27704>

_______________________________________________
  Nachricht geschickt von/durch Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel

[bug #27704] autoip starts with wrong address - ntohl

by Mario Castelán Castro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Update of bug #27704 (project lwip):

                  Status:             In Progress => Fixed                  
             Open/Closed:                    Open => Closed                

    _______________________________________________________

Follow-up Comment #4:

Fixed by adding htonl() to the default implementation of
LWIP_AUTOIP_CREATE_SEED_ADDR().

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27704>

_______________________________________________
  Nachricht geschickt von/durch Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel

[bug #27704] autoip starts with wrong address - ntohl

by Mario Castelán Castro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Follow-up Comment #5, bug #27704 (project lwip):

Right.
Just the doxygen comment for autoip_create_addr() should be updated as you
renamed IPAddr -> ipaddr.

Luca


    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27704>

_______________________________________________
  Messaggio inviato con/da Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel

[bug #27704] autoip starts with wrong address - ntohl

by Mario Castelán Castro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Follow-up Comment #6, bug #27704 (project lwip):

Thanks.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?27704>

_______________________________________________
  Nachricht geschickt von/durch Savannah
  http://savannah.nongnu.org/



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel