Documentation / code sample wanted.

Documentation / code sample wanted.

Post by Jody Pearso » Tue, 03 Jun 2003 19:50:09



Hi All,

I am looking for some source code or a document which outlines how to open
a TCP connection within kernel space.

After many google searches, and a search of the archives, I cannot seem to
find an example which says "do this".

There are many references to sk_buff and friends, but nothing more
practical.

I have looked over khttpd, which has been some help, and I looked briefly
at the nfs code, but I don't want to use RPC.

Can anybody point me to a document/code/patch to help me out ?

For more information, I basically want to emulate a userland
gethostbyname() in kernel space.

Thanks

Jody

--
Chaos, Panic, Pandemonium...  my work here is done.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Documentation / code sample wanted.

Post by Richard B. Johnso » Tue, 03 Jun 2003 20:20:13



> Hi All,

> I am looking for some source code or a document which outlines how to open
> a TCP connection within kernel space.

> After many google searches, and a search of the archives, I cannot seem to
> find an example which says "do this".

> There are many references to sk_buff and friends, but nothing more
> practical.

> I have looked over khttpd, which has been some help, and I looked briefly
> at the nfs code, but I don't want to use RPC.

> Can anybody point me to a document/code/patch to help me out ?

> For more information, I basically want to emulate a userland
> gethostbyname() in kernel space.

> Thanks

> Jody

> --
> Chaos, Panic, Pandemonium...  my work here is done.

This has become a FAQ, probably because people
don't know what a kernel is. They think it's
just some 'C' code in which you can do anything
the 'C' compiler lets you do.

Important! The kernel is not a 'task' it doesn't
have a context. Everything it has been designed
to do, is to perform systematic tasks upon behalf
of the caller, calling from user-mode context.
When it is executing, it is executing upon behalf
of a user-mode task. It is doing what the user-mode
task doesn't know how, or isn't trusted, to do.

The only thing that can call the kernel and
successfully accomplish what it intended to do, is
a user-mode task. Therefore, if you want to call
the kernel, you do it from a user-mode program.
It's just that simple.

For some reason, you want to translate the name
of a host to its IP address or vice-versa from
inside the kernel. Notwithstanding that it is
patently absurd to require such text translation
inside the kernel, it certainly is possible.
The kernel code (a module) needs a user-mode
daemon to perform user-mode tasks on its behalf.

This is bas-ackwards because code should be written
the other way around, i.e., the kernel performs
tasks upon behalf of a calling task.

You do this, by creating a user-mode daemon that
sleeps in select() or poll() until the kernel code
wakes it, using wake_up_interruptible(), after
making information available (probably via ioctl())
about what the kernel code wants it to do. The user-
mode daemon, awakened from poll() will perform an
ioctl() and find out what the kernel code wants it
to do. It will then do it, and pass the information
to the kernel code via ioctl(), read() or write().
The kernel code will 'know" when the information
has been returned because the user-mode daemon will
then sleep in poll() or select() again.

You can also create a "kernel thread" to do something
like this. However, nothing in the kernel can use the
'C' runtime library, running the risk of the kernel
being called from that library. The interface to
socket() stuff is a single kernel function, socketcall,
function number 102. You don't want to have to do
all the socket stuff by hand, you really want to
use the 'C' runtime library, so you must use a user-
mode daemon instead of a kernel thread.

Cheers,
* Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://www.veryComputer.com/
Please read the FAQ at  http://www.veryComputer.com/

 
 
 

Documentation / code sample wanted.

Post by Alan Co » Tue, 03 Jun 2003 22:50:09



Quote:> I have looked over khttpd, which has been some help, and I looked briefly
> at the nfs code, but I don't want to use RPC.

> Can anybody point me to a document/code/patch to help me out ?

> For more information, I basically want to emulate a userland
> gethostbyname() in kernel space.

Thats basically impossible because gethostbyname will handle queries to
all kinds of things like LDAP or DNSSEC. Do your lookups in user space,
its a lot simpler.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Documentation / code sample wanted.

Post by Matt Mackal » Wed, 04 Jun 2003 06:20:06



> I am looking for some source code or a document which outlines how to open
> a TCP connection within kernel space.

Take a look at nbd or Cisco's iSCSI driver.

Quote:> For more information, I basically want to emulate a userland
> gethostbyname() in kernel space.

That gets ugly quickly. There are a lot of options and complexity
needed to handle even the simplest name resolution robustly. It almost
certainly makes more sense to do this in userspace and pass the result
down to the kernel.

--
Matt Mackall : http://www.selenic.com : of or relating to the moon
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Documentation / code sample wanted.

Post by Jody Pearso » Wed, 04 Jun 2003 12:50:10


Hi*, All,

Quote:

>This has become a FAQ, probably because people
>don't know what a kernel is. They think it's
>just some 'C' code in which you can do anything
>the 'C' compiler lets you do.

In this case, I was being stupid with the gethostbyname exmaple. But I
do know what a kernel is !

To fill in the blanks, I am writing a network based filesystem, and I
now realise that the place to do the gethostbyname() is in a mount helper.

Quote:>Important! The kernel is not a 'task' it doesn't
>have a context. Everything it has been designed
>to do, is to perform systematic tasks upon behalf
>of the caller, calling from user-mode context.
>When it is executing, it is executing upon behalf
>of a user-mode task. It is doing what the user-mode
>task doesn't know how, or isn't trusted, to do.

What I would like to achive is a self-contained module which implements
a filesystem. The user-space apps then interact with the fs as normal.

I am trying to avoid havng "helper daemons" for various reasons, too
long to go into here

Quote:

>The only thing that can call the kernel and
>successfully accomplish what it intended to do, is
>a user-mode task. Therefore, if you want to call
>the kernel, you do it from a user-mode program.
>It's just that simple.

And if your a filesystem ? Is it really recommended to do;

userspace->kernel->userspace->kernel->userspace ? That seems like a lot
of context switching to me.

Quote:

>You do this, by creating a user-mode daemon that
>sleeps in select() or poll() until the kernel code
>wakes it,

[snip]

As I said, for my own reasons I would like not to have a deamon like this.

Thanks for the help.

Jody

--
Chaos, Panic, Pandemonium...  my work here is done.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://www.veryComputer.com/
Please read the FAQ at  http://www.veryComputer.com/

 
 
 

1. wanted: sample code using BUTTONBOX X input extension device

i.e. not accessing /dev/bd directly like x_buttontest does.

As a modest offering in return, here's a utility that will exercise
XListInputDevices(3).  I don't understand why xdpyinfo doesn't
provide this information.

ftp://smarty.smart.net/pub/rlhamil/goodies/xlsidev.c

Followups to comp.windows.x.

--
ftp> get |fortune
377 I/O error: smart remark generator failed

Bogonics: the primary language inside the Beltway


2. Intel 740 chipset

3. Wanted: SVR4 Driver sample code, or references

4. HELP with Iptables!

5. Wanted: sample code for Voyager IR interface

6. Problem generating salt

7. Telnet protocol documentation or source code wanted

8. Magic Filter for Cannon BJ

9. Expect Documentation/Sample Scripts

10. Gated samples and documentation

11. Wanted: Sample sendmail.cf for SunOS

12. net-snmp sample source code...

13. sample code that sends raw Ethernet packets?