Re: how do I direct raw packages to a given socket?

Andi Kleen (ak@muc.de)
29 Sep 1999 13:32:32 +0200


schuldei@uni-bremen.de (Andreas Schuldei) writes:

>
> Right now I open a socket in userspace and bind it to the devive and
> give it the same protocol as I specified in the kernel-module.
> This way I can communicate with the devices on the bitbus.
> But I want to do so from several processes. Right now all sockets
> could receive all packages. Of cause I can open several raw sockets
> with different file descriptors. Can I direct a package to the userspace
> socket by specifing something like
>
> skb->sock=filedescriptor;

no, this does not work. sock is a pointer. filedescriptor is a index.

if you want to multiplex it you would need to write a kernel
protocol family that can supply multiple sockets.

If the problem is not very performance critical you can get around it
with a small user space library that binds a packet socket to
MCAT_PROTO and then does something like:

/* only receive header */
n = recv(packet_sk, buf, headerlen, MSG_PEEK);
if (n <= headerlen) error();

if (header is for me) {
n = recv(packet_sk, buf, buflen, 0);
....
}

Basically the MSG_PEEK avoids the full data copy if the packet
is not for you. But it would still eat a lot of context switches,
but for low speed networking (e.g. <= 64kbit/s) that should be no
problem for modern CPUs.



-Andi

-- 
This is like TV. I don't like TV.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/