LinuxQuestions.org
Visit Jeremy's Blog.
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 04-09-2011, 07:42 PM   #1
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Rep: Reputation: 0
socket identifier


I'm storing a list of 'struct socket' connections inside my kernel module and making associations from the BSD interface to the protocol interface in my kernel module. Is there a unique identifier of any sort about a BSD socket so that I can get that socket out of my linked list for later reuse?

Or maybe I'm thinking about them wrong. It seems that almost every socket call passes in 'struct socket' as an argument, so maybe I don't need to store them. But I do want to know which user-space interface socket points to which protocol endpoint (remote host).

Kind of confusing, still trying to wrap my head around all these layers and connections. Any clarification much appreciated.

Last edited by rrlangly; 05-03-2011 at 06:26 PM.
 
Old 04-10-2011, 03:43 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,681

Rep: Reputation: 218Reputation: 218Reputation: 218
The struct sockets are connected to their file descriptors. Is it the connection you want to have?
 
Old 04-10-2011, 04:53 PM   #3
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Original Poster
Rep: Reputation: 0
Yes, the file descriptor would work if I had access to it since it's the only unique thing about a socket that I know.

I create a socket and store it on a linked list in my kernel w/ other data. The proto_ops.connect callback gets called, so I search a list of remote hosts and the sockets to them.

My problem is I don't know how to compare the incoming 'struct socket *sock' with the struct socket's in my linked list, I don't have a file desriptor to check that I can tell. The socket ip and port can be the same on multiple sockets. The only unique thing I know about a socket is the file descriptor, but I can't find a good way to get access to it so I can match the userspace fd with the socket in my list.

Code:
static int my_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
{
    //...

    list_for_each(pos, &my_hosts.list) {
        // how to find socket in my_hosts linked list that is the same
        // as the 'struct socket *sock' passed into this func?
    }
}

Last edited by rrlangly; 04-30-2011 at 08:17 PM.
 
Old 04-30-2011, 08:17 PM   #4
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Original Poster
Rep: Reputation: 0
Shameless bump. Still stuck.
 
Old 05-01-2011, 07:48 AM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,681

Rep: Reputation: 218Reputation: 218Reputation: 218
OK, but what is exactly the problem you have now?
 
Old 05-02-2011, 07:01 PM   #6
rrlangly
Member
 
Registered: Dec 2009
Posts: 47

Original Poster
Rep: Reputation: 0
Code:
My problem is I don't know how to compare the incoming 'struct socket *sock' 
with the struct socket's in my linked list, I don't have a file desriptor to check
that I can tell. The socket ip and port can be the same on multiple sockets. The
only unique thing I know about a socket is the file descriptor, but I can't find a 
good way to get access to it so I can match the userspace fd with the socket in my 
list.
A simpler way to put it would be ... how do I get the file descriptor that matches a 'struct socket'? File descriptors are unique, so I just need to find a way to get the file descriptor for a particular socket. But file descriptors aren't passed beyond the socket systemcall's in socket.c.

(from socket.c syscall to connect)
err = sock->ops->connect(sock, (struct sockaddr *)&address, addrlen, sock->file->f_flags);

My proto_ops funcs won't receive file descriptor from this sock->ops->connect() call.

I can see that sockfd_lookup_light() (as shown in socket of net/socket.c) will get me a socket from a fd, but I basically want to get a fd from a socket.

Last edited by rrlangly; 05-02-2011 at 10:14 PM.
 
  


Reply


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
PC BSD, Open BSD, or Free BSD ? Alexvader *BSD 5 02-08-2010 01:40 AM
Using KDevelop for simple BSD Socket executable. snowman81 Programming 0 12-16-2007 12:32 PM
BSD socket filter problem DaveV *BSD 0 08-07-2003 03:09 AM
ERROR: not an identifier GEEXTER Linux - Newbie 0 12-16-2002 12:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration