|
sk_buff append new
i have this query abt the sk_buff
im catching a packet at post_routing,
i need to append data to the stolen pkt and send it to the same dest.
i wrote following code but its not working.
i really need some help here.( any links abt this)
#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/icmp.h>
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/if_arp.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
static struct nf_hook_ops nfho;
/* IP address we want to drop packets from, in NB order */
static unsigned char *drop_ip = "some _ip_addr";
static int i=0;
/* This is the hook function itself */
unsigned int hook_func(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*dev_queue_xmit)(struct sk_buff *))
{
struct sk_buff *skbn,*sb = *skb;
char add_[]='HELLO';
char *add=add;
if (sb->nh.iph->saddr ==*(unsigned int *) drop_ip) {
printk("Dropped packet from... %d.%d.%d.%d\n",
*drop_ip, *(drop_ip + 1),
*(drop_ip + 2), *(drop_ip + 3));
i++; // MY way to avoid TCP connection set up pkts
skbn=skb_copy(sb,GFP_ATOMIC);
if(i==3)
{
char *c=skb_put(skbn,5);
memcpy((void *)c ,(void *)add,5);
/* problem
memcpy if working fine i am able to see the changes if i see the memory locations But i cant see the appended
data on the other side( ie receiver side) */
}
if(dev_queue_xmit(skbn)==0)
printk("success");
kfree_skb(sb);
return NF_STOLEN;
} else
{
return NF_ACCEPT;
}
}
/* Initialisation routine */
int init_module()
{
/* Fill in our hook structure */
nfho.hook = hook_func;
/* Handler function */
nfho.hooknum = NF_IP_POST_ROUTING; /* First for IPv4 */
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST; /* Make our func first */
nf_register_hook(&nfho);
return 0;
}
/* Cleanup routine */
void cleanup_module()
{
nf_unregister_hook(&nfho);
}
|