Re: Macnetworkprog Digest, Vol 3, Issue 221
Re: Macnetworkprog Digest, Vol 3, Issue 221
- Subject: Re: Macnetworkprog Digest, Vol 3, Issue 221
- From: Ryan McGann <email@hidden>
- Date: Mon, 01 Jan 2007 00:43:14 -0800
On Jan 1, 2007, at 12:19 AM, email@hidden wrote:
I'm writing a remote file system KEXT that uses the socket KPI, but
some of the work has to be done from user space via an app (e.g. the
authentication process, which requires user interaction).
What's the correct way to pass a socket from my app to the kernel for
use with the socket KPI?
There isn't a right way to do this.
One way to do this is register a socket filter. You can use a socket
option, I think it's SO_NKE to attach your filter to the socket from
user space. You absolutely must not call sock_close on this socket
from the kernel though. You need user space to be responsible for
opening and closing the socket. There are some tricky issues in the
handoff from user space to kernel and the pieces you would need to
accomplish this are not part of the KPI.
After seeing Josh's response, I don't know if we are doing this the "appropriate" way, but it works AFAIK. To perform something similar, we create the socket in userspace, and when it's time to "hand off" the socket we call a setsockopt on a kern_ctl socket. The socket "parameter" passed to setsockopt is the file descriptor for the socket we want to hand off. The setsockopt handler for the kern_ctl socket in the kernel calls file_socket (sys/file.h in the Kernel "framework"), which takes a file descriptor and turns it into a socket_t pointer. file_socket only works in the context of the process that owns the file descriptor obviously.
Of course Josh's caveat still applies. You cannot ever call sock_close on that socket in the kernel; the userspace application must take care of that. Weirdness certainly does ensue.
Ryan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden