Network disconect behaviour

Hi! when i unplug cable from the board i see in log this messages. Does this mean that the socket is not closed gracefuly? in theory, the stack should stop when the cable is disconnected or not?

[14:15:12:850] < prvCloseDHCPSocket[41-43]: closed, user count 0
[14:15:15:847] < vIPSetDHCP_RATimerEnableState: Off
[14:15:15:847] < prvCloseDHCPSocket[41-43]: closed, user count 0
[14:15:18:845] < vIPSetDHCP_RATimerEnableState: Off
[14:15:18:845] < prvCloseDHCPSocket[41-43]: closed, user count 0
[14:15:21:847] < vIPSetDHCP_RATimerEnableState: Off
[14:15:21:847] < prvCloseDHCPSocket[41-43]: closed, user count 0
[14:15:24:848] < vIPSetDHCP_RATimerEnableState: Off
[14:15:24:848] < prvCloseDHCPSocket[41-43]: closed, user count 0

Not necessarily. A link down may be a temporary situation that should according to the ISO/OSI model be transparent to higher layers. In many TCP/IP implementations, an ifdown event is being considered a significant event that may indeed shut down all connections communicating over the interface, but that can also be an overkill if the link comes up again quick. In your dsl connection at home, for example, you may have short link interruptions without your active connections (video streams etc) never being aware of it.

In reverse, it is also possible for a physical link to be up but all communications broken, nevertheless, for example, if your device is connected to a switch with an uplink on the switch failing but the link with your device port still active.

This is a very shady area of networking which almost every networking component or software treats individually.

Frequently there is an ifdown()/ifup() callback pair that you can use to customize the behavior of your stack. I do not know offhand if that is supported by FreeRTOS+TCP, but even if, it is only an indicator for the very next hop.

EDIT: Since your logs reveal dhcp activity, it is worth mentioning that frequently, the ifup() event following an ifdown() is used to renegotiate a dhcp address. Needless to say, if your device obtains a different IP address the next time, all of your existing communications are worthless because your end point is gone. However, dhcp recommends that a dhcp server should reuse the same IP address for identical MAC addresses if possible, meaning that logically, your open connections can still be used after a dhcp renegotiation. But not all dhcp servers follow that recommendation, so the best reaction to a link down event can be installation dependent.

2 Likes

Hi @pistoletov1974 ,
When a network cable is plugged out, this just triggers a link down event.
The stack is still alive and so is the socket attached to the endpoint/condition. Just that that physical link is just marked as down.