LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 11-03-2008, 04:54 PM   #1
ibaniski
LQ Newbie
 
Registered: Nov 2008
Posts: 10

Rep: Reputation: 0
Question close socket + kernel module


Hello,

I am working with/writing a kernel module which communicates with user processes using a custom socket family.

One of the features that I need in this module is "force shutdown", which will close the sockets and somehow notify the user process(es) that the communication has been broken.

I attempted to do the following in the module "shutdown" code:
PHP Code:
sock_orphan(sk);
sock_put(p->sock->sk);
sk NULL
for each open socket. However, the user process is not notified of this, and continues to listen on the socket; and when I try to terminate the process it attempts to close the socket (even though it has been closed in the kernel) and faults.

Any ides on how to properly close a socket from inside a kernel module? Perhaps I need to do something specific in sk_destruct?

Thanks,
ib

Last edited by ibaniski; 11-03-2008 at 05:05 PM.
 
Old 11-10-2008, 10:17 AM   #2
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,425

Rep: Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159
If the user opens a socket, then the user (or user-side process cleanup code) must close it.

When you determine that the communications represented by some particular socket are no longer possible, then you should signal the user-process (in some agreed-upon way), and also set a flag in your own internal data-structures to reflect the fact that this communication channel is now "dead."

If the user ignores the notification and attempts to communicate with a dead channel, the request is turned-away, returning an error indication to the user's socket-I/O request. If the user queries the status of the channel (in some way that you have provided), he will learn that it is "dead as a doornail."

Eventually, one way or the other, the user will close what he has opened. When he does so, the data-structures you have created must be expunged.
 
Old 11-11-2008, 03:45 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,539

Rep: Reputation: 149Reputation: 149
You must have some code that notifies the client when your socket becomes unusable (if it's connection-oriented, when the connection is broken; when the interface goes down etc). Copy that code. Don't deallocate socket structures - it's needed for the client to read()/write() and get an error and/or close() properly.
 
  


Reply

Tags
close, kernel, module, socket


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why can i not close socket with command /quit lrios Programming 11 05-09-2008 12:06 AM
Installing perl module IO::Socket::SSL [GOD]Anck Slackware 1 03-26-2008 08:07 AM
command to close tcp socket powah Linux - Networking 1 08-17-2007 01:22 PM
race condition in close socket?? jwstric2 Programming 3 03-18-2005 06:01 PM
Close socket/port THETEZ Linux - General 4 03-28-2004 09:05 PM


All times are GMT -5. The time now is 05:24 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration