Communicating Data from User Space to Kernel Space - Linux

This is a discussion on Communicating Data from User Space to Kernel Space - Linux ; struct rule{ int proto; char source[15]; }instance; I have written this structure into a file in user space ,say rule.txt . Say this file contains 10 records , i. e 10 instances of the above structure.Now I would like to ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Communicating Data from User Space to Kernel Space

  1. Communicating Data from User Space to Kernel Space

    struct rule{
    int proto;
    char source[15];
    }instance;

    I have written this structure into a file in user space ,say rule.txt .
    Say this file contains 10 records , i. e 10 instances of the above
    structure.Now I would like to read the same file in kernel space by a
    kernel module by reading 1 record at a time. How can i do this ?

    Is there any other way to do this without using files ? My objective
    is to read the 10 records from kernel space one record at a time and
    not the individual bytes.


  2. Re: Communicating Data from User Space to Kernel Space

    amit wrote:
    >
    > Is there any other way to do this without using files ? My objective
    > is to read the 10 records from kernel space one record at a time and
    > not the individual bytes.
    >


    hello

    For example, you can use netlink to communicate between user- and
    kernelspace, or you create an entry in the proc filesystem and use
    ioctl (but it isn't the prefered way). Or you use a device.

    Instead of using netlink, try out connector which is based on netlink
    but smarter to use.

    If you use netlink or connector you have to write a usermode helper
    application which sends all the data (packet for packet) to the kernel.

    hth

    Marco

  3. Re: Communicating Data from User Space to Kernel Space

    The best way is to use Netlink, as it is socket, it can be easily
    modified to adapt if your server is not resides in kernel (such as
    another machine).

    ABAI
    amit wrote:
    > struct rule{
    > int proto;
    > char source[15];
    > }instance;
    >
    > I have written this structure into a file in user space ,say rule.txt .
    > Say this file contains 10 records , i. e 10 instances of the above
    > structure.Now I would like to read the same file in kernel space by a
    > kernel module by reading 1 record at a time. How can i do this ?
    >
    > Is there any other way to do this without using files ? My objective
    > is to read the 10 records from kernel space one record at a time and
    > not the individual bytes.



  4. Re: Communicating Data from User Space to Kernel Space

    http://www.linuxjournal.com/article/7356

    Binary wrote:

    > The best way is to use Netlink, as it is socket, it can be easily
    > modified to adapt if your server is not resides in kernel (such as
    > another machine).
    >
    > ABAI
    > amit wrote:
    > > struct rule{
    > > int proto;
    > > char source[15];
    > > }instance;
    > >
    > > I have written this structure into a file in user space ,say rule.txt .
    > > Say this file contains 10 records , i. e 10 instances of the above
    > > structure.Now I would like to read the same file in kernel space by a
    > > kernel module by reading 1 record at a time. How can i do this ?
    > >
    > > Is there any other way to do this without using files ? My objective
    > > is to read the 10 records from kernel space one record at a time and
    > > not the individual bytes.



  5. Re: Communicating Data from User Space to Kernel Space

    miline wrote:
    > http://www.linuxjournal.com/article/7356


    hi

    One week ago, I've written a kernel module and an
    usermode helper application with netlink.

    The current netlink code implementation in kernel
    differs from the one described in the article above.

    As a result of this, use netfilter and iptables
    code as a reference to find out how to use netlink.


    hth

    Marco

+ Reply to Thread