error in sending of packet using ip_finish_output

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

 



Hi,
   I wrote a kernel module for copy  nfs packetsto new packet and send the new packet to network. It works in small packet. But it failed in sending of bigger packets. the program is shown below. I don't know the problem..



/* generic module headers here */
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <linux/nfs.h>

/* scatterlist and page mask required for encrypt */
#include <asm/scatterlist.h>
#include <asm/page.h>

#include <linux/crypto.h>

#include <linux/version.h>
#include <linux/proc_fs.h>
#include <linux/errno.h>

/* network headers here */
#include <linux/byteorder/generic.h>
#include <linux/netdevice.h>

#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

#include <linux/ip.h>
#include <linux/in.h>
#include <net/checksum.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/skbuff.h>

#define IP_PROTO_NFS 105 


static
unsigned int
send_hook (unsigned int nfhook, struct sk_buff **skb,
	const struct net_device *in, const struct net_device *out,
	int (*okfn) (struct sk_buff *))

{
	struct sk_buff *skbuff = *skb;
	struct sk_buff *skcopy;
	struct udphdr *udp_hdr;
	int  proto, err=0;
	int hlen,totlen, troom;
	hlen = skbuff ->nh.iph->ihl * 4;
	udp_hdr = (struct udphdr *)(skbuff->nh.raw + hlen);

	if (udp_hdr -> dest == htons(NFS_PORT) || 
			udp_hdr->source == htons(NFS_PORT) &&
			skbuff->nh.iph->protocol == IPPROTO_UDP)
	{
		
		
		printk(KERN_ALERT"\n\n Send Hook\n" );
		
		
		skcopy = skb_copy(skbuff, GFP_ATOMIC);
			
						/*changes in skcopy*/	
		
		printk(KERN_INFO"\nsize of packet skbuff%d"
				"\nsize of packet skcopy%d",
				(skbuff->end - skbuff->head ),
				(skcopy->end - skcopy->head ));
		
		skcopy->nh.iph->protocol = IP_PROTO_NFS;
						/*sending packet*/		
		skcopy->nh.iph->check =0;
		ip_send_check(skcopy->nh.iph);
		ip_finish_output(skcopy);
		kfree_skb(skbuff);				
		return NF_STOLEN;
	}				
	return NF_ACCEPT;
}

;
static
unsigned int
recv_hook (unsigned int nfhook, struct sk_buff **skb,
	const struct net_device *in, const struct net_device *out,
	int (*okfn) (struct sk_buff *))

{
	struct sk_buff *skbuff = *skb;
	int  proto, err=0;
	int hlen,totlen, len;
	totlen = ntohs(skbuff->nh.iph->tot_len);
	proto = skbuff->nh.iph->protocol;
	if(proto == IP_PROTO_NFS) {

		printk(KERN_ALERT "\n\nIN RECV_HOOK FUNCTION");

		printk(KERN_ALERT"\nproto %d\ntotlen %d",
				skbuff->nh.iph->protocol,
				ntohs(skbuff->nh.iph->tot_len));
		skbuff->nh.iph->protocol = IPPROTO_UDP;

	}
	return NF_ACCEPT;
}	



static struct nf_hook_ops hook_send;
static struct nf_hook_ops hook_recv;

static 
int init_module (void)
{

/*encryption hook*/
	hook_send.hook = send_hook;
	hook_send.hooknum = NF_IP_LOCAL_OUT;
	hook_send.pf = PF_INET;
	hook_send.priority = NF_IP_PRI_FIRST;

	nf_register_hook (&hook_send);

	
	hook_recv.hook = recv_hook;
	hook_recv.hooknum = NF_IP_LOCAL_IN;
	hook_recv.pf = PF_INET;
	hook_recv.priority = NF_IP_PRI_FIRST;

	nf_register_hook (&hook_recv);
	
	printk (KERN_INFO "Module successfully loaded.\n");
	return 0;
}

static 
void cleanup_module(void)
{
	nf_unregister_hook(&hook_send);
	nf_unregister_hook(&hook_recv);

	printk (KERN_ALERT"Module successfully unloaded");

}


MODULE_LICENSE("GPL");



-- 
This message has been scanned for viruses and
dangerous content by Techfocuz Communicator 2.6  (http://www.focuzinfotech.com), and is
believed to be clean.

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux