buglwIP - A Lightweight TCP/IP stack - Bugs: bug #20220, UDP PCB search in udp_input()

 
 

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

bug #20220: UDP PCB search in udp_input()

Submitted by:  Magnus Berglund <magnus_berglund>
Submitted on:  Wed 20 Jun 2007 01:12:46 PM UTC  
 
Category: UDPSeverity: 3 - Normal
Item Group: Faulty BehaviourStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: ClosedPlanned Release: None
lwIP version: None

Mon 25 Jun 2007 05:25:44 PM UTC, comment #5:

I've changed the code to set local_match=0 for every loop.

Closing this as fixed. Thanks again for reporting.

Simon Goldschmidt <goldsimon>
Project Administrator
Mon 25 Jun 2007 01:28:16 PM UTC, comment #4:

Of course, I mixed up the meaning of local_match and uncon_pcb, sorry. Setting local_match indeed seems to solve the problem best :-)

Simon Goldschmidt <goldsimon>
Project Administrator
Mon 25 Jun 2007 12:38:23 PM UTC, comment #3:

The original posters suggestion of just setting local_match to zero inside the loop rather than outside the loop seems like a good one to me.

Kieran Mansley <kieranm>
Project Administrator
Fri 22 Jun 2007 08:52:15 PM UTC, comment #2:

> Can I have some comments from other developers on this?


What do you think? Is it a bug or am I seeing things?

Simon Goldschmidt <goldsimon>
Project Administrator
Thu 21 Jun 2007 08:34:13 PM UTC, comment #1:

Confirmed. Thanks for posting this.

I'd add a (pcb->local_port == dest) to what you describe as ' if (local_match != 0 && remote_end_matches())' (line 165 in udp.c v1.89, current CVS HEAD)

Can I have some comments from other developers on this?

Simon Goldschmidt <goldsimon>
Project Administrator
Wed 20 Jun 2007 01:12:46 PM UTC, original submission:

I have discovered what I think is a bug in udp_input().

The problem is the pcb search and the local_match variable.
The code does something similar to:

local_match = 0;
for (pcb in udp_pcbs) {
if (local_end_matches()) {
some_stuff()
local_match = 1;
}
if (local_match != 0 && remote_end_matches()) {
break;
}
}

This means that if some pcb matches on the local side, the loop
will continue to search for a better match. A "later" pcb that matches on the remote side only will be considered a "full match" and the execution will break out of the for loop. The local side of that pcb need not neccesarry match the packet though.

Setting local_match to zero for each loop solves the problem.

Does that break anything else?

The following app reproduces the problem:

#define BUFLEN 64
void Lwip_UDP_Echo_Thread(void)
{
struct netconn *inconn;
struct netconn *outconn;
struct netbuf *buf;
struct ip_addr *addr;
unsigned short port;
struct ip_addr someaddr;

outconn = netconn_new(NETCONN_UDP);
inconn = netconn_new(NETCONN_UDP);

/* Need this connect() to place this pcb last in the pcb list. */
IP4_ADDR(&someaddr, 192, 168, 255, 255);
netconn_connect(outconn, &someaddr, 1234);

netconn_bind(inconn, NULL, 1111);

while (1)
{
buf = netconn_recv(inconn);
if (buf != NULL)
{
addr = netbuf_fromaddr(buf);
port = netbuf_fromport(buf);

/* Echo packet back to sender */
netconn_connect(outconn, addr, port);
netconn_send(outconn, buf);

netbuf_delete(buf);
}
}
}

The first packet sent to this app will be echoed back correctly, but all later incoming packets will be forwarded to the outconn connection instead of inconn.

Magnus Berglund <magnus_berglund>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by kieranm (Posted a comment)
  • -unavailable- added by goldsimon (Posted a comment)
  • -unavailable- added by magnus_berglund (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 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 25 Jun 2007 05:25:44 PM UTCgoldsimonStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Thu 21 Jun 2007 08:34:13 PM UTCgoldsimonStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1