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()

Submitter:  Magnus Berglund <magnus_berglund>
Submitted:  Wed 20 Jun 2007 01:12:46 PM UTC
   
 
Category:  UDP Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Planned 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>
Group 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>
Group 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>
Group Member
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>
Group 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>
Group 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>

 

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

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Date Changed by Updated Field Previous Value => Replaced by
    2007-06-25 goldsimon StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2007-06-21 goldsimon StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code