LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Closed Thread
  Search this Thread
Old 03-10-2007, 09:30 PM   #1
linwenyuan
LQ Newbie
 
Registered: Sep 2006
Posts: 27

Rep: Reputation: 15
questions about register modules onto netfilter


hello,
i am trying to realize a firewall based on netfilter,so i need to write myself modules and register them onto some hook points of netfilter.I get a simple example from website named" linux magazine",the example is like this:
/* example.c*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/netfilter_ipv4.h>
#include <linux/ip.h>

MODULE_LICENSE("Dual BSD/GPL");
static unsigned int
linuxmag_hook(unsigned int hook, struct sk_buff **pskb,
const struct net_device *indev, const
struct net_device *outdev, int
(*okfn)(struct sk_buff *))
{
/* Get a handle to the packet data */
unsigned char *data = (void *)(*pskb)->nh.iph +
(*pskb)->nh.iph->ihl*4;

(*pskb)->nfcache |= NFC_UNKNOWN;
printk("hello\n");
switch ((*pskb)->len) {
case 100:
printk("linuxmag: corrupting packet\n");
data[99]++;
(*pskb)->nfcache |= NFC_ALTERED;
return NF_ACCEPT;

case 200:
printk("linuxmag: dropping packet\n");
return NF_DROP;

default:
return NF_ACCEPT;
}
}

static struct nf_hook_ops linuxmag_ops
= { { NULL, NULL }, linuxmag_hook,
PF_INET, NF_IP_LOCAL_OUT,
NF_IP_PRI_FILTER-1 };

int init_module(void) {
return nf_register_hook(&linuxmag_ops);
}
void cleanup_module(void)
{
nf_unregister_hook(&linuxmag_ops);
}
i have inserted the module (i found it is there when i use lsmod),but the following was my trail result:
[root@localhost example]# ping -c1 -s 72 210.45.119.241
PING 210.45.119.241 (210.45.119.241) 72(100) bytes of data.
80 bytes from 210.45.119.241: icmp_seq=0 ttl=64 time=0.056 ms

--- 210.45.119.241 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.056/0.056/0.056/0.000 ms, pipe 2

[root@localhost example]# ping -c1 -s 172 210.45.119.241
PING 210.45.119.241 (210.45.119.241) 172(200) bytes of data.
180 bytes from 210.45.119.241: icmp_seq=0 ttl=64 time=0.095 ms

--- 210.45.119.241 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 7ms
rtt min/avg/max/mdev = 0.095/0.095/0.095/0.000 ms, pipe 2

but according to the program ,the second time the packet should not be sent out.
so i used lsmod to check and found the value of "Used by" of "example" (this module name ) is 0, is the reason that i have not successfully registered the module onto the hook point of netfilter ?
any response will be appreciated very much.
 
Old 03-11-2007, 05:38 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate. While iptables provides a way to enhance security (access control and such), your question is not about Linux Security but about programming.
 
  


Closed Thread


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
questions about register myself module onto netfilter linwenyuan Linux - Kernel 1 03-12-2007 06:29 PM
Several questions about using netfilter zhubaining Linux - Networking 0 11-14-2006 04:01 AM
how-to register ndiswrapper with modules.pcimap esl537 Linux - Wireless Networking 1 09-06-2005 07:09 AM
How do I register my clarkconnect to make the administrative modules active? sunnyvic Linux - Security 1 08-01-2003 11:57 AM
Netfilter Questions jrmann1999 Linux - Networking 0 06-29-2001 07:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:40 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