Skip to contentSkip to conversation

Problem With Local in hook in 2.6 kernel

DISCUSSION Kanhu Rauta 1 participant 1 message Mar 9, 2007 netfilter

lore
Share & tools
lore
#0 lore raw

Hi list,

I am using kernel 2.6.20.1. I have written a module,which will register a function at local_in hook, i have found a strange behavior with the packets getting in my callback function i.e

[let say i am sending 1500 bytes to this machine from the network] ping -s 1500 <ip>

1>in case of fragmention i am getting only one packet at the hook,While analyzing the ip header it says this is the assembled packet(skb->len=1528,offset=0,MF=0).

While dumping the data(for 0 to 1528 print skb->data[i]) it shows that only 1472 bytes are valid data and rest 28 bytes are something garbage.
I verified this with ethereal.

2>I have dumped these packets in ip_local_deliver function after ip_defrag and before NF_HOOK,But the result is same.

But i have tested it with 2.4 kernel,its working fine.My hook gets a single assembled packet with correct data of 1500 bytes.

Can Anybody let me know why i am not getting the complete data in case of 2.6 kernel ?

Regards,
kanhu

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/ip.h>
#include <net/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/icmp.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/etherdevice.h>

MODULE_LICENSE("Dual BSD/GPL");

void print_packet( char *str,unsigned char *pak, int len ) {
    int i;   
    if( str != NULL ) {
        printk("%s: pktlen:%d\n",str,len);
    }        
    for( i = 0; i < (len-20); i++ ) {
        if (i%16 == 0) {
            printk("\n %4x:",i);
        }
        printk("%2x ", (unsigned char)pak[i+20] );
    }
    printk("\n");
}

static unsigned int print_local_in_packet(unsigned int hook, struct sk_buff **pskb,

                const struct net_device *indev, const struct net_device *outdev,
                int (*okfn)(struct sk_buff *) ) {
	int i;
	unsigned char *pdata;
	struct iphdr  *ip;
	struct sk_buff *skb = *pskb;
	if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET))
		printk("ip_conntrack_defrag: packet still fragmented after = defrag!\n"); 
	//skb = ip_defrag(skb, 0);
	pdata = skb->data;
        ip   =  (struct iphdr *)(pdata);
	if( ip->protocol == IPPROTO_ICMP ){
		printk("VER:%d hlen:%d tos:%d\n",ip->ihl,ip->version,ip->tos);
		printk("total-len:%d id:%d frag-offt:%d \n",ntohs(ip->tot_len),ntohs(ip->id),ntohs(ip->frag_off));
		printk("ttl:%d proto:%d cksum:%d \n",ip->ttl,ip->protocol,ip->check);
		printk("src=%u.%u.%u.%u  dst:%u.%u.%u.%u\n", NIPQUAD(ip->saddr), NIPQUAD(ip->daddr));
		print_packet("After successful decap",skb->data, skb->len);
	}
        return NF_ACCEPT;

}

static struct nf_hook_ops netfilter_ops = {

   .hook     = print_local_in_packet,
   .owner    = THIS_MODULE,
   .pf       = PF_INET,
   .hooknum  = NF_IP_LOCAL_IN,

.priority = NF_IP_PRI_FIRST, };

int rc;
static int hello_init(void)

{
	printk(KERN_ALERT "Hello, world\n");
   	rc=nf_register_hook(&netfilter_ops);
	if( rc<0 ){printk("Unable to regester the Hook rc:%d\n",rc);}
	else { printk("Successfully Added the hook-%d\n",rc);}
	return 0;
}

static void hello_exit(void)

{
	printk(KERN_ALERT "Goodbye, crueL world\n");
	nf_unregister_hook( &netfilter_ops);
	//if( rc<0 ){printk("Unable to unregester the Hook rc:%d\n",rc);}
}

module_init(hello_init);
module_exit(hello_exit);