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 07-28-2011, 10:08 PM   #1
Sekhar417
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Rep: Reputation: Disabled
Bridge Netfilter Example


Hi,

Can any one send example code for BRIDGE NETFILTER
implementation in kernel.

Example code should work to receive the ETHERNET Frames from another Machine.


Thanks
--Sekhar
 
Old 07-29-2011, 03:05 PM   #2
kmassare
LQ Newbie
 
Registered: Apr 2011
Location: California, US
Distribution: Fedora
Posts: 28

Rep: Reputation: 8
You really haven't said what you are trying to do or what distribution you are using but have you looked at ebtables and brctl? I am using them to bridge and filter two Ethernet segments.
 
Old 07-29-2011, 10:58 PM   #3
Sekhar417
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for your response, Actually I have two Linux machines which are in same LAN. I tried to send Ethernet packet from one Linux machine and tried to capture in another machine using BRIDGE NETFILTER kernel code. But I am not able to succeed, i couldn't see any packets received in my Kernel.

I used BRIDGE NETFilter Hook( PRE_ROUTING) in kernel to capture the packet, but i couldn't succeed.

Can you please give me idea,how to use to etables to capture ethernet Frames using kernel code. If you have any Kernel code related to etables, could you please share to me.

I have tried to understand the etables, but not able to implement the same in kernel.

=============
Example code:
=============
static unsigned int hook_entry_pre_routing(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;
static int i=0;

unsigned char haddr[6];
const struct ethhdr *eth = eth_hdr(sb);
memcpy(haddr, eth->h_source, ETH_ALEN);

printk(KERN_INFO "NFNL PRE : The Mac address is %s\n", haddr);

return NF_ACCEPT;
}


static int __init muni_nf_init(void)
{
int ret = 0;

printk(KERN_INFO "NFNL Loading BRIDGING NF Module\n");


my_hook_pre_routing.hooknum = NF_BR_PRE_ROUTING;
my_hook_pre_routing.pf = PF_BRIDGE;
my_hook_pre_routing.hook = hook_entry_pre_routing;
my_hook_pre_routing.priority = NF_BR_PRI_BRNF;
if((ret = nf_register_hook(&my_hook_pre_routing)) < 0)
{
printk(KERN_INFO "NFNL Can't regiter the hook (ERR=%d)\n",ret);
nf_unregister_hook(&my_hook_pre_routing);
return ret;
}

static void __exit muni_nf_exit(void)
{
printk(KERN_INFO "NFNL UnLoading MUNI NF Module\n");
nf_unregister_hook(&my_hook_pre_routing);

}

module_init(muni_nf_init);
module_exit(muni_nf_exit);

/* Comment goes here */
MODULE_LICENSE("Proprietary");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_VERSION("2.4.1.7");



Thanks
--sekhar

Last edited by Sekhar417; 07-29-2011 at 11:09 PM. Reason: Added sample code...
 
Old 07-30-2011, 12:44 AM   #4
kmassare
LQ Newbie
 
Registered: Apr 2011
Location: California, US
Distribution: Fedora
Posts: 28

Rep: Reputation: 8
Sorry, I don't have any kernel code that would help.
 
  


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
Linux bridge + netfilter sholah Linux - Server 4 01-15-2009 01:08 AM
Netfilter Help rajaashok Linux - Kernel 1 11-22-2007 12:41 AM
netfilter and dmesg MarcusMoeller Linux - Networking 6 01-20-2007 02:51 AM
Several questions about using netfilter zhubaining Linux - Networking 0 11-14-2006 04:01 AM
Netfilter and 2.6.16.2 krizzz Slackware 8 04-13-2006 10:17 PM

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

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