Change destination MAC
George <[email protected]>
| Newsgroups | gmane.linux.network.bridge.ebtables.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello.
I'm developing a kernel module in order to change the MAC address to the
one I desired. For that I'm using the netfilter/ebtables hook. However I'm
facing a problem, I don't know the reason why it happens.
The module works fine and seems to do its job. However that depends on the
dest MAC address I put to the packet.
Let's explain it. If the dest MAC addr is under the control of the brigde
(brctl showmacs br0) there is no problem when changing it, I can put
whatever within this list.
However if I put another different from the ones in the list, the packet is
not sent. I'm sniffing the channel and no packet get out of the device.
When exiting the NF_BR_POST_ROUTING it seems that the mac has been changed,
but the packet never gets out.
Any reason for that.
Any help is more than welcome.
TA.
Here I post the code:
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/types.h>
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter_bridge.h>
#include <linux/socket.h>
struct nf_hook_ops hook_ex;
unsigned int function_hook( unsigned int hook, struct sk_buff **pskb, const
struct net_device *in,
const struct net_device *out, int (*okfn)(struct sk_buff *))
{
static int j = 0;
unsigned char *data;
int i;
char a[] = {0x00, 0x02, 0x2d, 0x21, 0xb4, 0x65};
struct sk_buff *nskb;
nskb = skb_copy(*pskb, GFP_ATOMIC);
if (!nskb)
return NF_DROP;
if ((*pskb)->sk)
skb_set_owner_w(nskb, (*pskb)->sk);
kfree_skb(*pskb);
*pskb = nskb;
memcpy(eth_hdr(*pskb)->h_dest, a, ETH_ALEN);
data = (*pskb)->mac.raw;
for (i=0;i<6;i++) {
printk("%02X ", data[i]);
}
printk(" %d\n", j);
printk("%s\n", out->name);
(*pskb)->nfcache |= NFC_UNKNOWN;
(*pskb)->nfcache |= NFC_ALTERED;
return NF_ACCEPT;
}
static int __init init(void)
{
// hook
hook_ex.list.next = NULL;
hook_ex.list.prev = NULL;
hook_ex.hook = function_hook;
// hook_ex.list.flush = NULL;
hook_ex.pf = PF_BRIDGE;
hook_ex.hooknum = NF_BR_POST_ROUTING;
return nf_register_hook(&hook_ex);
}
static void __exit fini(void)
{
nf_unregister_hook(&hook_ex);
}
module_init(init);
module_exit(fini);
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click