Networking Forums

Networking Forums > Computer Networking > Linux Networking > Problem with netfilter in a kernel module

Reply
Thread Tools Display Modes

Problem with netfilter in a kernel module

 
 
Aashay Shringarpure
Guest
Posts: n/a

 
      03-01-2009, 06:44 AM
Hi,
i was trying to write a simple kernel module which would filter data
based on the tcp destination port. From, what I know, the netfilter
architecture was changed sometime between 2.4 and 2.6 and I'm getting
a lot of conflicting HOWTOs on the net.

Here is the code for my handler function:

unsigned int hook_func(unsigned int hooknum,
struct sk_buff* skb, // should this be
sk_buf** skb ?
const struct net_device *indev,
const struct net_device *outdev,
int (*okfn)(struct sk_buff *)) {

if(!skb) {
return NF_ACCEPT;
}
return drop_by_port(skb,2000);
}

In drop_by_port, I am getting the same address when I try to extract
the transport header using skb_transport_header and the network header
using skb_network_header which points me to believe that something is
wrong with the packet I am getting.

Also, If I change the sk_buf* to sk_buf**, I get *skb (which I pass to
skb_transport_header) to be a Null pointer which crashes the entire
system.

Thanks for any help

--Aashay

 
Reply With Quote
 
 
 
 
Aashay Shringarpure
Guest
Posts: n/a

 
      03-02-2009, 06:58 AM
On Mar 1, 2:44*am, Aashay Shringarpure <aash...@gmail.com> wrote:
> Hi,
> i was trying to write a simple kernel module which would filter data
> based on the tcp destination port. From, what I know, the netfilter
> architecture was changed sometime between 2.4 and 2.6 and I'm getting
> a lot of conflicting HOWTOs on the net.
>
> Here is the code for my handler function:
>
> unsigned int hook_func(unsigned int hooknum,
> * * * * * * * * * * * * struct sk_buff* skb, * * * * * * * * * * * * *// should this be
> sk_buf** skb ?
> * * * * * * * * * * * * const struct net_device *indev,
> * * * * * * * * * * * * const struct net_device *outdev,
> * * * * * * * * * * * * int (*okfn)(struct sk_buff *)) {
>
> * * * * if(!skb) {
> * * * * * * * * return NF_ACCEPT;
> * * * * }
> * * * * return drop_by_port(skb,2000);
>
> }
>
> In drop_by_port, I am getting the same address when I try to extract
> the transport header using skb_transport_header and the network header
> using skb_network_header which points me to believe that something is
> wrong with the packet I am getting.
>
> Also, If I change the sk_buf* to sk_buf**, I get *skb (which I pass to
> skb_transport_header) to be a Null pointer which crashes the entire
> system.
>
> Thanks for any help
>
> --Aashay


I solved it. I just add the IP header length to its start to get the
transport header's start.
 
Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
possible issues on SMP machine for Netfilter based kernel module Rohit Linux Networking 0 05-16-2007 09:55 AM
How to get data in kernel SEND buffer for a TCP socket from a netfilter based kernel module Rohit Linux Networking 0 05-10-2007 11:27 AM
How to detect TCP sequence number wrap around in a netfilter kernel module Rohit Linux Networking 0 05-10-2007 06:28 AM
killing a kernel thread ....... UDP server (kernel module)......... alex Linux Networking 0 09-20-2006 11:26 AM
help about nat and internet service provider problem!! (kernel module) Giacomo Linux Networking 2 08-26-2005 06:37 PM



1 2 3 4 5 6 7 8 9 10 11