[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What is wrong with this kernel module??? :((

From: Murtaza
Subject: What is wrong with this kernel module??? :((
Date: Mon, 31 Dec 2007 15:23:18 +0500

I am writing a module for getting the udp packets @ kernel level to optimize
an application i am building. I am running the following code by using
virtual Linux Kernel for debugging purpose(using some umlscript shell). But
I am not able to catch udp packets at the kernel level when the packets are
sent to it. Can anybody help please???


#include <linux/ip.h>
#include <linux/kernel.h>
#include <linux/signal.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/if_arp.h>
#include <linux/skbuff.h>
#include <linux/udp.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/tty.h>
#include <linux/version.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/workqueue.h>

#define E_INVALID_ARGS -1
#define E_OUT_OF_MEMORY -2

#define MAX_KEY_LEN 20
#define MAX_VALUE_LEN 20


static struct nf_hook_ops netfilter_ops;
unsigned char *port = "\x13\x8d";

struct udphdr *udp_header;
struct tty_struct *my_tty = NULL;
static int pkts = 0;
struct workqueue_struct *knfd_wq;
static char *interface = "lo";
struct sk_buff *sock_buff;

extern __sum16 skb_checksum_complete(struct sk_buff *skb);

unsigned int main_hook(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 *sock_buff = *skb;
//struct Tupple* t = ethernet_packet_parser(*skb);

printk(KERN_ALERT"i m in the start\n");

if(!sock_buff){ return NF_ACCEPT;}
//if(!(sock_buff->nh.iph)){ return NF_ACCEPT;}

printk(KERN_ALERT"i m out , protcol: %d \n",sock_buff->protocol);
return NF_ACCEPT;
///////////////// PROBLEM PROBLEM PROBLEM PROBLEM ///////////
///// I never reach there Even i send UDP packets
/////// to my machine... ///////////

printk(KERN_ALERT"\n\ni got it \r\n");

return 0;


int init_module()
printk(KERN_ALERT"init_module called\r\n");
netfilter_ops.hook = main_hook; = PF_INET;
netfilter_ops.hooknum = NF_IP_PRE_ROUTING;
netfilter_ops.priority = NF_IP_PRI_FIRST;

printk(KERN_ALERT"Module loaded\n\r");

return 0;

Ghulam Murtaza
Lahore University of Management Sciences

reply via email to

[Prev in Thread] Current Thread [Next in Thread]