Hooks in layer 2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi:

I compile and insert in kernel a simple netfilter module in order to intercept ethernet traffic and it seems to be ok (no error messages) but something is wrong 'cause not appears the printk messages.

Here is the code:

<p>
#define _KERNEL_

#include <linux/netfilter_ipv4.h>
#include <linux/netfilter_bridge.h>

static struct list_head list = {NULL, NULL};
static struct nf_hook_ops operations[1];

static unsigned int prerouting(unsigned int hook, struct sk_buff *skb, 					
const struct net_device *indev, const struct net_device *outdev, 					
int (*okfn) (struct sk_buff *))
{
unsigned char src[6], dst[6];
const struct ethhdr *eth = eth_hdr(skb);
	memcpy(src, eth->h_source, ETH_ALEN);
	memcpy(dst, eth->h_dest, ETH_ALEN);
	if ( eth->h_proto == htons(ETH_P_IP))
	{
		printk(KERN_ERR"(%d) src %s, dst %s, proto %d\n", ETH_ALEN, src, dst, eth->h_proto);
	}
	printk(KERN_ERR"prerouting\n");
	return NF_ACCEPT; 
}

static int __init init(void)
{
int ret; 
	operations[1].list = list;
	operations[1].hook = (nf_hookfn *)prerouting;
	operations[1].pf = PF_BRIDGE;
	operations[1].hooknum = NF_BR_PRE_ROUTING;
	operations[1].priority = NF_BR_PRI_BRNF;
	operations[1].owner = THIS_MODULE;
	ret = nf_register_hook(&operations[1]);
	if (ret < 0)
	{
		return ret;
	}
	printk(KERN_WARNING"simple up\n");
	return ret;
}


//Funcion para que el modulo termine lo que el mismo inicio
static void __exit exit(void)
{
	printk(KERN_WARNING"simple down\n");
	nf_unregister_hook(&operations[0]);
}


module_init(init);
module_exit(exit);
</p>

Only appears the simple up and down printk messages when i insert and remove my module respectively. I put others hooks in localin, localout, forward and postrouting and nothing happens. I use OpenSUSE 11.2 (with kernel 2.6.31.5-0.1-default).

Thanks,

Rigoberto
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux