The Lprogs Journal

Journal Of the Linux Programmers Group
Click here to join lprogs
Click to Subscribe

Previous Issues

  • Issue #1 - September 2006

    October 2006 (#2)

    From the editor's desk

    The second issue of the lprogs Journal is out. The first issue was accepted as a good initiative by some people. And that is enough to keep this going. Though the posts this month were less in number , but we had more "technical" posts and they have al been compiled together in this issue. ILUG-DELHI also celebrated its annual festival "FreeDel,2006" of which i was a part. I delivered a talk there . You will find the relevant link in this issue also. So you have the 2nd issue of the journal packed with GNU/LINUX and FLOSS Topics.

    To DO

  • More Contributions from the world of GNU / LINUX
  • Improve the "look and feel" of the journal

    Talk on IDS & IPS at FreeDel,2006

  • Download the talk
  • Visit FreeDel,2006

    Group Posts

  • Open Source Search Technology goes beyond keywords , By Amit Saha
  • Windows v Linux Security , By Divya Dutta
  • Linux Technology in IBM Development , By Divya Dutta
  • Can you trust your computer ? By Amit Saha
  • Reflections on Trusting Trust , Ken Thompson
  • Implementation of Host Based IDS & IPS Combining RBID & SBID By Amit Saha
  • Linux Adavanced Routing and traffic control , By rhle_freak
  • Linus Torvalds , read on , By Amit Saha
  • How to find PAGE SIZE in linux kernel , By Suman Adak
  • Linux kernel linked list implementation , By Suman Adak

  • Communicating from user space to kernel space

    The query

    amit saha 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.
    

    The replies:

  • I think the best way for you to proceed is to implement an ioctl in your kernel module, and call it from your user space program when you have each record ready and populated. Binand
  • Or use one of proc, sysfs or netlink interface but the simplest will be to implement write/ioctl.
  • 1) implementing a char device and ioctl() system call and creating /proc entry

    2) using kernel system call which has been exported by kernel

    3) create and use sysfs files within a kernel module.

    4) using netlink socket.

    But the question is that why we shouldn't read or write files in kernel space? And what is the efficient way to do that?does kernel actually reads or writes files?

    The only one reason that i could find , "where" and "how" files would be located and loaded . and it is policy decision in the linux community that we shouldn't do. The problem is , where this config file lives? Is there any particular location where all config file can stay and read by kernel. If i am correct, the various same config file location could be different in different distribution. So one my kernel module can run only one distribution. It is not guaranteed that it will run in different distribution.

    And yes how to load the config files. May today u r using very simple file but tomorrow you could use very complex database file and in that case kernel doesn't have more flexibility to handle such file.

    So many kernel hackers suggest not to read and write file in kernel space. But what is the solution? Yes as per my knowledge, We could do like

    1.implement file reading and writing in user space

    2. communicate vis /proc entry.

    I can give some example

    1.Mounting file system [ mount program reads config file /etc/fstab and issue mount system call]

    2.Netfilter filrewalls gets rule from user space application[iptables which read the configuration file and communication with kernel via socket]

  • "Driving Me Nuts - Things You Never Should Do in the Kernel" , By Greg Kroah-Hartman

    From Linux Journal

  • Roll your Own Firewall with Netfilter
  • The Linux Socket Filter: Sniffing Bytes over the Network
  • Inside the Linux Packet Filter - I
  • Inside the Linux Packet Filter - II

    Miscellaneous Resources & Good Readings

  • We can put an end to word attachments
  • Linux IP Networking
  • Kernel Resources
  • The Apache HTTP Server examined,modeled & documented
  • The Ping Page
  • Kernel Hacking Resources
  • Still More Linux Resources
  • Make Your Own Linux Distribution
  • Remote Control Your PC

    Kernel Status

    Journal Contributors

  • Amit Saha - (Web:http://amitsaha.in.googlepages.com )
  • Dibyendu Roy ( [email protected] )
  • Divya Dutta ( [email protected] )
  • Suman Adak (Web: http://sumanadak.blogspot.com)
  • Soumyadeep Banerjee ( [email protected] )

    Subscribe to Linux Programmers Group and Journal
    Powered by groups.yahoo.com

    Mail your contributions / comments / suggestions /queries to Amit Saha. He reads mail at [email protected]
    Get Firefox!
    Hosted by www.Geocities.ws

    1