buglwIP - A Lightweight TCP/IP stack - Bugs: bug #45829, ipX_to_ip() function does not work...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #45829: ipX_to_ip() function does not work when just one IP version supported

Submitter:  Erik Ekman <yarrick>
Submitted:  Wed 26 Aug 2015 09:05:48 AM UTC
   
 
Category:  IPv4 Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Works For Me
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Jump to the original submission

Thu 27 Aug 2015 07:43:29 PM UTC, comment #6: 

The question would be how can we ensure the 2nd argumen isn't used (like in your OP code)?

Anyway, I don't think it's a bug... -> closed

Simon Goldschmidt <goldsimon>
Group administrator
Wed 26 Aug 2015 08:31:21 PM UTC, comment #5: 

Ok, I see.

When I spotted the usage in udp.c it became more clear to me how to use it properly.

It was not for external usage, but for a new lwip module I hope to share some day.

Erik Ekman <yarrick>
Group Member
Wed 26 Aug 2015 06:43:22 PM UTC, comment #4: 

The real question is whether these macros/functions should be exported to applications. Portable applications should use ip_addr_t anyway, not ip4_addr_t, and I'd like to enforce this by not exporing ipX_2_ip() to application code. Only I haven't found a decent way to do this, yet.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 26 Aug 2015 06:41:16 PM UTC, comment #3: 

I don't think I get the point of this patch. The code you wrote in the OP is wrong. You should not ignore the return value. It should rather pass the return value of ipX_2_ip() to udp_sendto_if().

Simon Goldschmidt <goldsimon>
Group administrator
Wed 26 Aug 2015 12:18:57 PM UTC, comment #2: 

v3 of patch

Functions now return ptr to destination, to allow minimal changes to udp code.

(file #34737)

Erik Ekman <yarrick>
Group Member
Wed 26 Aug 2015 09:16:43 AM UTC, comment #1: 

v2 patch that uses the right copy macro.

I noticed that UDP code does not compile with this patch. If this seems like a good direction I can fix those errors.

This will lead to a copy of addresses in cases where it might not be needed, but it will be easier to write code handling all cases of IPv4/v6 support.

(file #34735)

Erik Ekman <yarrick>
Group Member
Wed 26 Aug 2015 09:05:48 AM UTC, original submission:  

When both IP versions are supported, ip4_to_ip()/ip6_to_ip() converts the IP version-specific first argument to an IP version-independent type given as the second argument.

To work the same way when only one IP version is supported the first argument needs to be copied to the second.

Consider the following code (choose destination address and pcb based on IP version of incoming packet):

#if LWIP_IPV4
ip4_addr_t v4addr = ..;
#endif
#if LWIP_IPV6
ip6_addr_t v6addr = ..;
#endif

struct {
#if LWIP_IPV4
  struct udp_pcb *v4pcb;
#endif
#if LWIP_IPV6
  struct udp_pcb *v6pcb;
#endif
} data;

....
{
    ip_addr_t tempaddr;
    struct udp_pcb *pcb = NULL;

    if (IP_IS_V6_VAL(source_addr)) {
#if LWIP_IPV6
      ip6_2_ip(&v6addr, &tempaddr);
      pcb = data.v6pcb;
#endif
    } else {
#if LWIP_IPV4
      ip4_2_ip(&v4addr, &tempaddr);
      pcb = data.v4pcb;
#endif
    }
    udp_sendto_if(pcb, pbuf, &tempaddr, port, netif);
}

This code works when both IP versions are enabled but break if only one is, since the ipX_to_ip() functions do different things.

Erik Ekman <yarrick>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by yarrick (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-08-27 goldsimon Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2015-08-26 goldsimon StatusNone Works For Me
    2015-08-26 yarrick Attached File- Added 0001-Make-ipX_to_ip-work-when-just-one-IP-version-v3.patch, #34737
    2015-08-26 yarrick Attached File- Added 0001-Make-ipX_to_ip-work-when-just-one-IP-version-v2.patch, #34735
    2015-08-26 yarrick Attached File- Added 0001-Make-ipX_to_ip-work-when-just-one-IP-version-support.patch, #34733

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code