lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #20220] UDP PCB search in udp_input()


From: Magnus Berglund
Subject: [lwip-devel] [bug #20220] UDP PCB search in udp_input()
Date: Wed, 20 Jun 2007 13:12:47 +0000
User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

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

                 Summary: UDP PCB search in udp_input()
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: magnus_berglund
            Submitted on: onsdag 2007-06-20 den 13:12
                Category: UDP
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

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.






    _______________________________________________________

Reply to this item at:

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

_______________________________________________
  Meddelandet skickades via/av Savannah
  http://savannah.nongnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]