kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* broken network connection
@ 2014-11-06 21:07 Grzegorz Dwornicki
  2014-11-06 21:30 ` Jim Davis
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Grzegorz Dwornicki @ 2014-11-06 21:07 UTC (permalink / raw)
  To: kernelnewbies

Hi

I have a big interest in how kernel handles this situaction.

Lets assume that we have two hosts: host 1 and host 2 and on host 1 I
have started this command:
nc -l -p 4444
on host 2 I have started this command (2 means IP addres of second host here!):
nc 2 4444

Now i can send msgs betweem them. In time I have decided to end
connection. To do this I'm using ctrl+c on host 2. What functions are
called to clean broken socket on host 1? What functions are called to
clean up socket on host 2?

Grzegorz.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* broken network connection
  2014-11-06 21:07 broken network connection Grzegorz Dwornicki
@ 2014-11-06 21:30 ` Jim Davis
  2014-11-07  9:44   ` Silvan Jegen
  2014-11-07 11:10 ` Sreejith M M
  2014-11-07 11:47 ` Pranay Srivastava
  2 siblings, 1 reply; 5+ messages in thread
From: Jim Davis @ 2014-11-06 21:30 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Nov 6, 2014 at 2:07 PM, Grzegorz Dwornicki <gd1100@gmail.com> wrote:

> To do this I'm using ctrl+c on host 2. What functions are
> called to clean broken socket on host 1? What functions are called to
> clean up socket on host 2?

Have you tried running strace on the nc processes?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* broken network connection
  2014-11-06 21:30 ` Jim Davis
@ 2014-11-07  9:44   ` Silvan Jegen
  0 siblings, 0 replies; 5+ messages in thread
From: Silvan Jegen @ 2014-11-07  9:44 UTC (permalink / raw)
  To: kernelnewbies

Am 2014-11-06 22:30, schrieb Jim Davis:
> On Thu, Nov 6, 2014 at 2:07 PM, Grzegorz Dwornicki <gd1100@gmail.com> 
> wrote:
> 
>> To do this I'm using ctrl+c on host 2. What functions are
>> called to clean broken socket on host 1? What functions are called to
>> clean up socket on host 2?
> 
> Have you tried running strace on the nc processes?

Additionally you can use the Kernel's ftrace[0] functionality to figure 
out which functions are being called in the kernel (instead of getting 
only the system calls returned like with strace).


[0] https://www.kernel.org/doc/Documentation/trace/ftrace.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* broken network connection
  2014-11-06 21:07 broken network connection Grzegorz Dwornicki
  2014-11-06 21:30 ` Jim Davis
@ 2014-11-07 11:10 ` Sreejith M M
  2014-11-07 11:47 ` Pranay Srivastava
  2 siblings, 0 replies; 5+ messages in thread
From: Sreejith M M @ 2014-11-07 11:10 UTC (permalink / raw)
  To: kernelnewbies

When a socket is closed at one side of the communication, the other side
will not get to know this information.
In your case, when ctrl+c is performed, socket is terminated abruptly at
host1 end. Until, host2 tries to read from this broken connection, host 2
will not know that the connection is broken  and it will keep the same conn
alive. The moment, host2 tries to read from this socket, it will come to
know that the connection is broken and it will terminate the connection.
The logical flow of function(system calls) at host2 would be

read() -> Application would receive an error on read call
shutdown() ->depends on the application you are using
close()

Then depending on the application, if it decides to terminate, it will call
exit() as well.

you can see the man pages of these commands for more information.

On Fri, Nov 7, 2014 at 2:37 AM, Grzegorz Dwornicki <gd1100@gmail.com> wrote:

> Hi
>
> I have a big interest in how kernel handles this situaction.
>
> Lets assume that we have two hosts: host 1 and host 2 and on host 1 I
> have started this command:
> nc -l -p 4444
> on host 2 I have started this command (2 means IP addres of second host
> here!):
> nc 2 4444
>
> Now i can send msgs betweem them. In time I have decided to end
> connection. To do this I'm using ctrl+c on host 2. What functions are
> called to clean broken socket on host 1? What functions are called to
> clean up socket on host 2?
>
> Grzegorz.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
Regards,
Sreejith
--------------------------------------------------------------------------------------------------------
Aint no grave, can hold my body down!!!
"Obadiah 1:4"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20141107/3647eda9/attachment.html 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* broken network connection
  2014-11-06 21:07 broken network connection Grzegorz Dwornicki
  2014-11-06 21:30 ` Jim Davis
  2014-11-07 11:10 ` Sreejith M M
@ 2014-11-07 11:47 ` Pranay Srivastava
  2 siblings, 0 replies; 5+ messages in thread
From: Pranay Srivastava @ 2014-11-07 11:47 UTC (permalink / raw)
  To: kernelnewbies

Hi

On Fri, Nov 7, 2014 at 2:37 AM, Grzegorz Dwornicki <gd1100@gmail.com> wrote:
>
> Hi
>
> I have a big interest in how kernel handles this situaction.
>
> Lets assume that we have two hosts: host 1 and host 2 and on host 1 I
> have started this command:
> nc -l -p 4444
> on host 2 I have started this command (2 means IP addres of second host here!):
> nc 2 4444
>
> Now i can send msgs betweem them. In time I have decided to end
> connection. To do this I'm using ctrl+c on host 2. What functions are
> called to clean broken socket on host 1? What functions are called to
> clean up socket on host 2?
>

I'm not expert on this but from what your steps suggests at the kernel
level both machines know there's no communication
between them.

When you hit ctl+c or send your process signal which is not handled
then by default that process is killed.
When you open a socket, it's actually linked to a file via sockfs,
this is socket is on your opened file lists so assuming you didn't
forked and the refcount was still 1 for this sockfs inode the do_exit
would perform cleanup when it calls fput on these opened files.

That would terminate the socket by calling sock_release, see
net/socket.c. So the application at the other end doesn't yet know
about it but it'll when it attempts to go and read since the kernel at
the other end already knows that this connection has been terminated.

For specific functions you'll need to see net/ipv4[6]/. something like
sock_close/ sock_disconnect?

What would be interesting if you took the ether cable out or just
turned off power? It won't be a clean shutdown then :-p.


> Grzegorz.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




-- 
        ---P.K.S

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-11-07 11:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-06 21:07 broken network connection Grzegorz Dwornicki
2014-11-06 21:30 ` Jim Davis
2014-11-07  9:44   ` Silvan Jegen
2014-11-07 11:10 ` Sreejith M M
2014-11-07 11:47 ` Pranay Srivastava

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).