lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] Two tcp pcbs listening on same IP address and port


From: Dado Admir
Subject: [lwip-devel] Two tcp pcbs listening on same IP address and port
Date: Mon, 27 May 2019 08:37:21 +0200

Hi all,

We're using lwip on an embedded device with two Ethernet ports and two tcp server applications running on it. The applications are bound to specific Ethernet port, and this is done by using tcp_bind_netif function. They are also bound to local ip addresses (address assigned to netif at the moment) and local port by using tcp_bind function. This setup works fine in all cases except when we have two same ip addresses assigned to two netifs. In this case, we are getting ERR_USE when trying to bind the second tcp to <IP address, port> pair (SO_REUSE option is enabled).

We managed to get the code working by adding few lines to the lwip tcp code in parts where there are checks for address/port reuse (tcp_bind, tcp_listen and tcp_input functions). We added checks for assigned netif index for every tcp pcb.

For example, in function tcp_listen_with_backlog, the condition is changed from:

      if ((lpcb->local_port == pcb->local_port) &&
          ip_addr_cmp(&lpcb->local_ip, &pcb->local_ip)) {
        /* this address/port is already used */
to:
      if ((lpcb->local_port == pcb->local_port) &&
          ip_addr_cmp(&lpcb->local_ip, &pcb->local_ip) &&
          (lpcb->netif_idx == pcb->netif_idx)) {
        /* this address/port is already used */

Similar changes are in the other two functions. 

The idea is to make listening tcp defined by <IP address, port,  netif_idx> instead of only <IP address, port>.  This would be valid only for pcbs on which tcp_bind_netif was previously called. 

The questions are, would this change make sense for lwip and does it violate any TCP rules? Same questions for UDP. 

We're using lwip version 2.1.2.

Thank you

reply via email to

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