LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-20-2019, 01:32 AM   #1
Andy041292
LQ Newbie
 
Registered: Apr 2019
Posts: 3

Rep: Reputation: Disabled
Netfilter hook


I'm trying to write kernel module which will add two bytes to the end of any TCP packet and send it to the network interface. The IMPORTANT POINT is that network device will remove these bytes in hardware (simply throw them out without any modification of the packet), so there is no need to take these bytes into account in the TCP header (recalculate checksum and so). I'm doing it with help of NF_INET_POST_ROUTING netfilter hook. I just use skb_put() and then return NF_ACCEPT. Two bytes are added successfully but TCP checksum at the receiver end is wrong. What am I doing wrong? Is TCP checksum get recalculated after NF_INET_POST_ROUTING hook? Does packet go directly to the interface after this hook or it also goes through TCP stack? Is it really necessary in my case to create new skb buffer, consume old, and send new buffer out using dev_queue_xmit(). So how can I do my job properly? The entire code is below:

Code:
static struct nf_hook_ops *nfho3 = NULL;

static unsigned int ksz_prp_tx(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)
{

	u8 *trailer;

	trailer = skb_put(skb, 2);
	trailer[0] = 0x00;
	trailer[1] = 0x0C;

	return NF_ACCEPT;
}   

static int __init ipv4_prp_init(void)
{

nfho3 = (struct nf_hook_ops*)kcalloc(1, sizeof(struct nf_hook_ops), GFP_KERNEL);

/* Initialize netfilter tx hook for IPv4*/
nfho3->hook 	= (nf_hookfn*)ksz_prp_tx;	/* hook function */
nfho3->hooknum 	= NF_INET_POST_ROUTING;		/* received packets */ 
nfho3->pf 	= PF_INET;			/* IPv4 */
nfho3->priority = NF_IP_PRI_FIRST;	        /* max hook priority */

nf_register_net_hook(&init_net, nfho3);  

}

static void __exit ipv4_prp_exit(void)
{
	nf_unregister_net_hook(&init_net, nfho3);
	kfree(nfho3);
}

module_init(ipv4_prp_init);
module_exit(ipv4_prp_exit);
 
Old 11-24-2019, 01:06 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Welcome to the Programming forum!

As your question has not received any replies here, you might consider asking for help through the Netfilter site or in the Kernel forum here on LQ.

To ask that your question be moved to the Kernel forum please use the Report button at bottom of your original question.

Good luck!
 
  


Reply

Tags
kernel module, netfilter modules



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
Looking for idea on firewall project based on netfilter hook Kunsheng Programming 2 03-18-2009 04:59 PM
[SVN - post-commit hook] hook failed, did not exit cleanly G00fy Programming 0 01-21-2009 02:15 AM
netfilter hook problem mihirsevak Linux - Networking 2 10-21-2007 01:17 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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 06:54 AM.

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