buglwIP - A Lightweight TCP/IP stack - Bugs: bug #57710, Unable to reinitialize the TCP...

 
 

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

bug #57710: Unable to reinitialize the TCP connection

Submitter:  Praveen Kumar <praveen_embedded>
Submitted:  Fri 31 Jan 2020 05:02:09 PM UTC
   
 
Category:  TCP Severity:  3 - Normal
Item Group:  Crash Error Status:  Duplicate
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  2.0.3

Mon 03 Feb 2020 07:01:47 PM UTC, comment #5: 

Sorry, I fail to follow those posts in detail, but let me just come back to what I think is the main question here:

> So, Is there any way like re initializing entire LWIP like fresh power cycle


No, currently there isn't.

However, there is bug #55598 to remind us that such a feature would be nice/wanted.

Being like that: closing this one as duplicate.

And for next time: if you just want to ask questions, please send a mail to the lwip-users list instead of starting a bug (unless you know it's a bug).

Simon Goldschmidt <goldsimon>
Group administrator
Mon 03 Feb 2020 12:29:11 PM UTC, comment #4: 

Hi Benjamin,

We are not using IPv6 but its default enabled in my LWIP.
I will disable it as we don't have any plans on working on IPv6.

I have added the change which you suggested in below function and need to test now.
err_t Etherdo_connected(void arg, struct tcp_pcb newpcb, err_t err) {
    // do something
    ip_set_option(newpcb, SOF_KEEPALIVE);

    pcb_tcp = pcb;
}

I am using the "newpcb" during tcp_write(). I amcopying the content of newpcb to my local pcb_tcb and using that for data transmission.

I will remove the IPv6 and check again now and will get back to you with results.


Regards,
PraveenKumar.

Praveen Kumar <praveen_embedded>
Mon 03 Feb 2020 11:13:25 AM UTC, comment #3: 

First of all I suppose you are using IPv6? Since mld6_tmr should only be part if IPv6 is active i.e. LWIP_IPV6_MLD and LWIP_IPV6 is set in lwipopts.h

Does your "Etherdo_connected" method set this KEEPALIVE flag for that particular connection?

I suppose you method look like:

err_t Etherdo_connected(void *arg, struct tcp_pcb *newpcb, err_t err) {
    // do something
    ip_set_option(newpcb, SOF_KEEPALIVE);
}

I don't know if this is the right way to set that flag but it seems so because the tcp_slowtmr periodically tests for that particular flag. Setting that flag in your listen pcb should also be possible since it gets inherited according to source code comments.

/* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
#define SOF_INHERITED   (SOF_REUSEADDR|SOF_KEEPALIVE)

The pcb_tcp you are using as argument in tcp_write() is that "newpcb" from your accept function I suppose? As I said, I usually uses the socket API for that purpose.

Benjamin K <bkausbk>
Mon 03 Feb 2020 10:35:05 AM UTC, comment #2: 

Hi Benjamin,
 Thanks for reply. I have tried whatever you suggested but after client stopped transmission, i control is stuck in function "void mld6_tmr(void)".

Do i need to do something to come out this function? like removing netif something like that.

I am adding following steps during lwip init.
TCPIP_STACK_INTERFACE_0_init(st_ETH_ConfigStruct.u8_SourceMacAddress, Src_IP, gw);          
netif_set_up(&TCPIP_STACK_INTERFACE_0_desc);

netif_set_default(&TCPIP_STACK_INTERFACE_0_desc);
mac_async_enable(&MACIF);

etharp_add_static_entry(&Dest_IP, (struct eth_addr *)&st_ETH_ConfigStruct.u8_DestMacAddress[0]);

pcb_tcp = tcp_new();

error = tcp_bind(pcb_tcp, &address, st_ETH_ConfigStruct.u16_SourcePortNum);

pcb_tcp = tcp_listen(pcb_tcp);

tcp_accept(pcb_tcp, Etherdo_connected);

After link established, below functions are used to do data transfer.

tcp_write(pcb_tcp,u8_DataBuff,u16_DataLen,TCP_WRITE_FLAG_MORE);
tcp_output(pcb_tcp));


This is how i initialized LWIP stack and transmitting data over ethernet. Here i have used static MAC address as we should connect to particular MAC address.

now if i try to re-initialize all the setting after tcp_close() or tcp_shutdown(pcb_tcp, 1, 1);  or tcp_abort(pcb_tcp); , i am stucking in same function "void mld6_tmr(void)".

Can you please suggest me what all the functions i should use to clear all old tcp_pcb details and create new tcp_pcb which work as bootup time initialization.

i have tried netif_set_down(), etharp_remove_static_entry() and some other functions to clear all the old pcb related data and tried creating new pcb but still i have the same issue.

Please suggest me something here.


Regards,
PraveenKumar.







Praveen Kumar <praveen_embedded>
Mon 03 Feb 2020 07:09:38 AM UTC, comment #1: 

I had a similar problem for a long time, and I think I have fixed it now. In my case the reason was insufficient resources, but my MCU was not going to sleep, but the connection was interrupted because the WLAN device lost it's connection. I had a web server running on my system that was processing many asynchronous requests from a client. Once the connection became unstable and was about to be terminated, some TCP/IP responses could no longer be sent to the client. As a result, the PCBs from the pool were used up very quickly. But since the connection was never explicitly closed, they were never released. Because of that, I was forced to activate TCP_KEEPALIVE. For this purpose I have included in the file lwipopts.h

#define LWIP_TCP_KEEPALIVE              1
#define TCP_KEEPIDLE_DEFAULT 5000
#define TCP_KEEPINTVL_DEFAULT 5000

#define LWIP_NETCONN_FULLDUPLEX 1

This ensures that any TCP/IP connection that may have been closed on the client side or is not answered by the client any more, will be closed after 5 seconds of inactivity. This frees up all internal resources. In my case, the problem that took me weeks to solve was solved immediately.

Please note, keep alive feature has to be explicitly activated per TCP/IP connection. If you are using sockets API this could be like so:

int ClientSocket = lwip_accept(ServerSocket, (struct sockaddr *) &ClientInfo, &AddrLen); // Blocking
if (ClientSocket > 0) {
int ParamOpt = 1;
lwip_setsockopt(ClientSocket, SOL_SOCKET, SO_KEEPALIVE, &ParamOpt, sizeof(int));
}

This is worth a try in your case.

Benjamin K <bkausbk>
Fri 31 Jan 2020 05:02:09 PM UTC, original submission:  

Hi ,

we are using LWIP 2.0.3 for one of our project to establish the TCP connection from ECU and Atmel micro.
We got the LWIP from atmel itself and i have modified little to support VLAN data receive and transmit.
But now we are seeing some issue during data transmission.
When the ECU goes to sleep, it cut down the Ethernet link and when it wakes up it will establish the Ethernet connection.
But here when the ECU wakes up the communication is not going well from our LWIP stack. We are seeing multiple re transmissions which are causing issues in data transmission.
So we planned to reinitialize the LWIP stack after ECU goes to sleep.
But when i do shut down the connection, the connection is not closing as there is no FIN request response from ECU and its getting stuck in tcp_slow timer.
Also i have seen new behavior like when i received new frame on TCP, i am trying to ACK back using ACK now function(tcp_ack_now(pcb);tcp_output(pcb);), but i am seeing the ACK packet after my data packet is been transferred.
This i didn't understand like why the ACK packet is transferred after data packet? this is also one of the reason for us to see communication failure.

So, Is there any way like re initializing entire LWIP like fresh power cycle(freeing all the PCB's and initializing as new power cycle).

Please let know how to do that, currently we are stuck here and our communication is not proper.

I am attaching the images for our communication issues.
Here LWIP_IP: 192.168.6.182
     ECU IP : 192.168.6.144
If you see LWIP_TCP_DataSentoutFirst.JPG, the data is send first and ACK is sent after that even though the ACK transmission is initiated first with priority level set to MAX.


Thanks & Regards,
PraveenKumar.

Praveen Kumar <praveen_embedded>

 

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

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by bkausbk (Posted a comment)
  • -email is unavailable- added by praveen_embedded (Submitted the item)
  • -email is unavailable- added by praveen_embedded
  •  

    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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-02-03 goldsimon StatusNone Duplicate
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2020-01-31 praveen_embedded Attached File- Added LWIP_TCP_DataSentoutFirst.JPG, #48314
        Attached File- Added LWIPCommunicationIssue.JPG, #48315
        Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code