LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-09-2006, 01:07 AM   #1
shrishailnk
Member
 
Registered: Mar 2006
Posts: 47

Rep: Reputation: 15
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);
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
checksum in sk_buff shrishailnk Linux - Networking 1 04-08-2006 03:41 AM
sk_buff questions? nocturna_gr Programming 1 01-14-2006 09:36 PM
Help with sk_buff cstrask Programming 0 11-23-2005 09:55 PM
how to use sk_buff wangjinyi Programming 0 10-27-2005 02:28 AM
Question about sk_buff auron Linux - Networking 0 10-06-2005 03:57 AM


All times are GMT -5. The time now is 09:12 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration