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 05-23-2006, 09:42 AM   #1
aashish.verma
LQ Newbie
 
Registered: Apr 2006
Posts: 11

Rep: Reputation: 0
packet filtering !!! need help


/*i have written this code to allow packets from IP 192.168.0.12 only */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/ip.h> /* For IP header */
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

/* This is the structure we shall use to register our function */
static struct nf_hook_ops nfhook;

/* IP address we want to drop packets from, in NB order */
static unsigned char *allow_ip = "\xco\xa8\x00\x0c"; /*192.168.0.12*/

/* 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 (*okfn)(struct sk_buff *))
{
struct sk_buff *sb = *skb;

if (sb->nh.iph->saddr == *(unsigned int*) allow_ip) {
/*here im printing srcaddr and total length just for my reference*/
printk("\n\nIP source address:%d",sb->nh.iph->saddr);
printk("\n\nTotal Length:%d",sb->nh.iph->tot_len);
printk("Allow packet from... %d.%d.%d.%d\n",
*allow_ip, *(allow_ip + 1),
*(allow_ip + 2), *(allow_ip + 3));
return NF_ACCEPT;

} else {
return NF_DROP;
}
}

/* Initialisation routine */
static int allow_init(void)
{
/* Fill in our hook structure */
nfhook.hook = hook_func;
/* Handler function */
nfhook.hooknum = NF_IP_PRE_ROUTING;/*First for IPv4 */
nfhook.pf = PF_INET;
nfhook.priority = NF_IP_PRI_FIRST; /* Make our func first */

nf_register_hook(&nfhook);

return 0;
}

/* Cleanup routine */
static void allow_exit(void)
{
nf_unregister_hook(&nfhook);
}



module_init(allow_init);
module_exit(allow_exit);

i am using SUSE10(kernel 2.6)..when i inserted the module using "INSMOD"..i got message "allow_ip module is not supported by Novell, some tainted message"..
from var/log/messages..

then i done PING 192.168.0.12
but there was no response... at the end it showing 100% packet loss...

is the code ok..or i have to make changes in the code?

plz help me out...
Thanks in advance
 
Old 05-23-2006, 10:10 AM   #2
b0nd
Senior Member
 
Registered: Jan 2005
Distribution: Slackware, BackTrack, Windows XP
Posts: 1,020

Rep: Reputation: 45
hi aashish,
plz. don't mind b'coz i'm not suggesting you any idea but would like to ask you that which books have you referred for learning such coding ? Means what knowledge is prerequisite.

regards
 
Old 05-24-2006, 10:29 AM   #3
aashish.verma
LQ Newbie
 
Registered: Apr 2006
Posts: 11

Original Poster
Rep: Reputation: 0
i taken a reference from "phrack.org" in this they have a article "Hacking the Linux Kernel Network Stack ".. what wrong with this? actually i am new to linux..plz tell in detail or give some links ...

thanks
 
  


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
Packet filtering firewall Maintech Slackware 3 10-30-2005 11:34 AM
ipv6 packet filtering reddy_pradeep Solaris / OpenSolaris 0 09-15-2005 11:27 PM
packet filtering majeztik Linux - Security 2 04-09-2005 01:34 AM
Packet Filtering empre55 Linux - Newbie 1 03-20-2005 09:10 AM
Packet Filtering simmid Linux - Networking 0 09-18-2001 02:05 AM


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