LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2007, 01:53 AM   #1
simon_qwl
Member
 
Registered: Jul 2004
Posts: 34

Rep: Reputation: 15
How to send copied skb in netfilter hook?


Hi all,
I have encountered some issues regarding to netfilter hooks. My intention is to monitor the traffic and make a skb_copy() call on the specific packets. Because i need to modify the content. After modification process, i need to send this new skb out as usual. However,i couldn't do so by calling skb_queue_head(). is there any tutorials on this subject?

Thank you very much for your hints.
 
Old 10-05-2007, 12:59 PM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Check out http://people.nl.linux.org/ftp/pub/a...kernelapi.html

Seems like dev_queue_xmit is the function you want?
 
Old 10-05-2007, 01:20 PM   #3
simon_qwl
Member
 
Registered: Jul 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks for the link,orgcandman.
As i understand, dev_queue_xmit() will put the skb into queue of network card to wait for transmitting out. does it mean the skb will skip ANY other hook points?(NF_IP_LOCAL_IN,etc),because the hook is registered in NF_IP_PRE_ROUTING.
 
Old 10-06-2007, 05:51 AM   #4
simon_qwl
Member
 
Registered: Jul 2004
Posts: 34

Original Poster
Rep: Reputation: 15
i have tried using following code as testing:
Code:
new_skb = skb_copy(old_skb, GFP_ATOMIC);
if(new_skb){
     skb_unlink(new_skb);
     skb_queue_head(old_skb->list,new_skb);
     return NF_DROP;
}
     return NF_ACCEPT;
However, the system is hung immediately when the module is inserted. something wrong with the code or it's not the way to do it?
 
Old 10-06-2007, 11:18 PM   #5
simon_qwl
Member
 
Registered: Jul 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Great,problem has been solved as following:

Code:
new_skb = skb_copy(old_skb, GFP_ATOMIC);
.
.
modification process on the new_skb
.
.
if(new_skb){
     kfree_skb(*skb);
     *skb = new_skb
     return NF_ACCEPT;
}
Basically, the original *skb points to the new_skb and return NF_ACCEPT. I use another hook in NF_IP_LOACAL_IN to detect the modified packets, so it works.
However I hope there are further discussion on how to generate and insert more than one skb into list for delivery?
 
Old 04-18-2012, 05:24 AM   #6
amir_saniyan
LQ Newbie
 
Registered: Oct 2011
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by simon_qwl View Post
Great,problem has been solved as following:

Code:
new_skb = skb_copy(old_skb, GFP_ATOMIC);
.
.
modification process on the new_skb
.
.
if(new_skb){
     kfree_skb(*skb);
     *skb = new_skb
     return NF_ACCEPT;
}
Basically, the original *skb points to the new_skb and return NF_ACCEPT. I use another hook in NF_IP_LOACAL_IN to detect the modified packets, so it works.
However I hope there are further discussion on how to generate and insert more than one skb into list for delivery?
Yes it works, Thanks
But I should comment kfree_skb(*skb); when I uncomment kfree_skb(*skb); my OS hangs.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
netfilter hook problem mihirsevak Linux - Networking 2 10-21-2007 01:17 AM
group the outgoing skb's into single skb and then send grouped skb. venkatesh111 Linux - Networking 0 04-27-2006 01:05 AM
netfilter hook forward packets tim24 Linux - Networking 3 03-27-2006 03:14 PM
netfilter hook function error jinxcat Programming 1 09-23-2005 04:24 PM
Unable to process skb in my own handler imransadat Programming 4 03-04-2005 12:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration