Help me ,Help me .
Hello:
I program the firewall used the iptable under linux ,The kernel is 2.4.18 ,
I see , the sys_open is call from userspace ,so i convert kernelspace to userspace ,
but failed (The source is atteched ).
I coun't call the system call ,example sys_open ,sys_close, The problem is i could't write file ,what can i do ,
mm_segment_t old_fs =get_fs() ;
set_fs(new_fs) ;
fd = sys_open(pathname,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR); printk("fd is [%d]",fd);
sys_write(fd,"Mail has develope sucesses , ",20) ; sys_close(fd);
set_fs(old_fs) ;
when the packet is accor ,the machine will panic , the error is :
error ....
kernel panic :Aiee,killing interrupt handler!
In interrupt handler - not syncing
Please help me ,Thank you .
yours zpeak
/*-----------------------------------------------------------------------------------------------------
*Atteched the source and the problem
----------------------------------------------------------------------------------------------------*/ #ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/config.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/spinlock.h>
#include <asm-i386/segment.h>
#include <asm-i386/uaccess.h>
#include <linux/netfilter_ipv4.h>
static unsigned int myfirewall(unsigned int hooknum,struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,int (*okfn)(struct sk_buff*))
{
mm_segment_t old_fs =get_fs() ;
mm_segment_t new_fs =get_ds();
printk("The old fs is [%lu]\n",old_fs.seg) ;
printk("The neww fs is [%lu]\n ",new_fs.seg) ;
/* I found the old_fs and new_fs is in the same address
* But in other module is different ,why,can you tell me
*/
int fd = 0;
char pathname[50] ="/test/log/8.mail" ;
set_fs(new_fs) ;
fd = sys_open(pathname,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR); printk("fd is [%d]",fd);
sys_write(fd,"Mail has develope sucesses , ",20) ; sys_close(fd);
set_fs(old_fs) ;
return NF_ACCEPT;
}
static struct nf_hook_ops iplimitfilter=
{
{NULL,NULL},
myfirewall,
PF_INET,
NF_IP_PRE_ROUTING,
NF_IP_PRI_FILTER
};
int init_module(void)
{
mm_segment_t old_fs =get_fs() ;
mm_segment_t new_fs =get_ds();
printk("The** old fs is [%lu]\n",old_fs.seg) ;
printk("The** neww fs is [%lu]\n ",new_fs.seg) ;
return nf_register_hook(&iplimitfilter);
}
void cleanup_module(void)
{
nf_unregister_hook(&iplimitfilter);
}
------------------------------------------------------------
gcc -D__KERNEL__ -WALL -I /usr/src/linux.2.4.18/include myfirewall.c
Hello, unnamed entity calling itself 'cyberyam' and 'zpeak',
Quoted 2 lines
I coun't call the system call ,example
sys_open,sys_close, The problem is i could't write file ,what can i do ,
You can learn that the kernel is not user mode. There's an awful lot to learn.
Iptables kernel modules do not run in process context, so you are not able to do any filesystem I/O from them.
If you do not understand the answer, see/ask http://www.kernelnewbies.org/
Quoted 1 line
From your example code, I gather that you want to send an email when
some condition happens. See the existing, well established 'ULOG' target for a working, proper approach to that task. No need for kernel programming, as far as I can tell. See http://gnumonks.org/projects/ulogd
regards
Patrick