Fedora Linux Support Community & Resources Center
  #1  
Old 23rd June 2008, 12:18 PM
hnshashi Offline
Registered User
 
Join Date: Jun 2008
Posts: 2
Arrow Sending netfilter message via netlink sockets(to User space module)

Hi,


I want send netfilter messages to user space program.

For this I have written a kernel and user space modules. They are successfully communicating (two way) using netlink sockets.

Then in same kernel module i have registered a hook to catch ICMP packets (which are coming when i ping machine).This also working.

I want send hooks received packets(ICMP/netfilter message) to user space module.

Please help me how can send netfilter message via netlink socket to User space Progarm.


kernel module is :


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Test");
MODULE_DESCRIPTION("Testing Netlink Socket");

static int debug=0;
module_param(debug,int,0);
MODULE_PARM_DESC(debug,"Debug Information");

static char *drop_if = "lo";

static struct sock *nl_sk=NULL;



static struct nf_hook_ops nfho;

static nl_data_ready(struct sock *sk,int len)
{
int err;
struct sk_buff *sk1=NULL;
struct nlmsghdr *nlh=NULL;
u32 pid;
printk("Netlink Socket Got Message\n");

sk1=skb_recv_datagram(nl_sk,0,0,&err);
nlh =(struct nlmsghdr*)(sk1->data);

printk("Kernel Received :%s\n",NLMSG_DATA(nlh));
strcpy(NLMSG_DATA(nlh), "This is ICMP Packet ");

pid = nlh->nlmsg_pid;
NETLINK_CB(sk1).pid =0;
NETLINK_CB(sk1).dst_group =0;
netlink_unicast(nl_sk,sk1,pid,MSG_DONTWAIT);


}
unsigned int hook_func(unsigned int hooknum,struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff*))
{

struct sk_buff *sb = *skb;
struct nlmsghdr *nlh=NULL;
static unsigned char *drop_ip = "x7fx00x00x01";

u32 pid;
if(strcmp(in->name,drop_if) == 0)
{
printk("ICMP Packet Receved on %s \n",drop_if);

nlh =(struct nlmsghdr*)(sb->data);

/*
pid = nlh->nlmsg_pid;
NETLINK_CB(sb).pid =0;
NETLINK_CB(sb).dst_group =0;
// netlink_unicast(nl_sk,sb,pid,MSG_DONTWAIT);
*/
return NF_ACCEPT;
}
else
{

return NF_ACCEPT;
}

}

static void netlink_test()
{
nl_sk=netlink_kernel_create(NETLINK_NETFILTER,0,nl _data_ready,NULL,NULL);
if(nl_sk==NULL)
printk("Netlink socket creation fails\n");
else
printk("Netlink socket created\n");
}
static int netkernel_init(void)
{
printk("Initialiaing netlink socket\n");
netlink_test();

printk("Registering Hook\n");
nfho.hook = hook_func;
nfho.hooknum = NF_IP_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);

return 0;
}
static int netkernel_exit(void)
{
printk("Good Bye!!!\n");
sock_release(nl_sk->sk_socket);
printk("Unregistering hook\n");
nf_unregister_hook(&nfho);

}
module_init(netkernel_init);
module_exit(netkernel_exit);



Thanks in Adavance
Shashidhara HN
Reply With Quote
Reply

Tags
message, module, netfilter, netlink, sending, socketsto, space, user

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sending out popup message ieuuk Servers & Networking 9 23rd January 2010 07:00 PM
where is the netfilter time module? sebnukem Security and Privacy 0 25th September 2007 03:08 AM
Sending message between WinXP and FC6 jdogzilla Using Fedora 1 26th October 2006 06:19 PM
Sendmail stop sending and Running low on space coyoteboy Using Fedora 3 20th September 2006 01:13 PM
Sending message from one sytem to another ramavtar Servers & Networking 4 6th December 2005 11:37 AM


Current GMT-time: 06:45 (Monday, 20-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat