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

Submitted by:  Erik Ekman <yarrick>
Submitted on:  Wed 26 Aug 2015 09:05:48 AM UTC  
 
Category: IPv4Severity: 3 - Normal
Item Group: Faulty BehaviourStatus: Works For Me
Privacy: PublicAssigned to: Simon Goldschmidt <goldsimon>
Open/Closed: ClosedPlanned Release: None
lwIP version: git head

(Jump to the original submission 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>
Project AdministratorIn charge of this item.
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>
Project 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>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.
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>
Project 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>
Project 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>
Project Member

 

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 27 Aug 2015 07:43:29 PM UTCgoldsimonAssigned toNone=>goldsimon
      Open/ClosedOpen=>Closed
    Wed 26 Aug 2015 06:41:16 PM UTCgoldsimonStatusNone=>Works For Me
    Wed 26 Aug 2015 12:18:57 PM UTCyarrickAttached File-=>Added 0001-Make-ipX_to_ip-work-when-just-one-IP-version-v3.patch, #34737
    Wed 26 Aug 2015 09:16:43 AM UTCyarrickAttached File-=>Added 0001-Make-ipX_to_ip-work-when-just-one-IP-version-v2.patch, #34735
    Wed 26 Aug 2015 09:05:48 AM UTCyarrickAttached File-=>Added 0001-Make-ipX_to_ip-work-when-just-one-IP-version-support.patch, #34733

    Back to the top


    Powered by Savane 3.1-cleanup1