Re: Changing MAC address for forwarding a pacjet with ebtables
Bart De Schuymer <[email protected]>
| Newsgroups | gmane.linux.network.bridge.ebtables.devel |
|---|---|
| Message-ID | <[email protected]> |
Op vr, 19-10-2007 te 16:15 +0200, schreef Mark Ryden:
> Hello,
> I am writing a kernel module which changes the MAC address of a received UDP
> packet so that it will be of a different machine on the same LAN and
> so that the
> packet will be forwarded to that machine.
> Namely, I am trying to do fowarding in layer 2 using ebtables hook.
>
> I am catching the packet with NF_BR_PRE_ROUTING ebtable hook.
> In this hook, I am changing its MAC address to 00:11:2F:93:E0:52 ;
> this is the MAC
> address of another machine which is on the same LAN (my ARP table
> knows this MAC).
>
> The code is below; it is short; (only 100 lines). If someone can
> take a look at it and give some advice it will be more than welcomed.
>
> I saw a posting in this mailing list a few days ago in which
> somebody tried also to adjust a MAC address and it was suggested that
> he should follow ebt_snat.c; so this is what I did.
>
> see:
> http://sourceforge.net/mailarchive/forum.php?thread_name=6.1.2.0.2.20050218133252.04555610%40luna.tlmat.unican.es&forum_name=ebtables-devel
>
> More details:
> When running the module and sending UDP packets on port 5555, I
> see that I get the packets in the module;
> Moreover, I see that the following if statement is valid:
> if (skb_shared(*pskb) || skb_cloned(*pskb)) ..
>
> However, when I put a sniffer on that machine or the second machine I
> **don't** see that a packet is sent to the second machine,
> namely to 00:11:2F:93:E0:52.
>
> What is missing here ? should I add some ebtable forwarding hook?
>
> BTW, on my machine, there is a bridge defined thus (as far as I know,this
> should be ok):
> ifconfig eth0 0.0.0.0
> brctl addbr mybr
> brctl addif mybr eth0
> ifconfig mybr up
> ifconfig mybr 192.168.0.45 netmask 255.255.255.0
>
> if( (*pskb)->protocol == ethpip && (*pskb)->nh.iph->protocol == IPPROTO_UDP)
> {
> struct udphdr *udp_header = (struct udphdr *)((*pskb)->data +
> ((*pskb)->nh.iph->ihl *4));
You'll need to use skb_header_pointer() here, see ebt_ip.c.
For debugging purpose, try returning EBT_CONTINUE instead of NF_ACCEPT
and add an ebtables log rule after the rule containing your target.
cheers,
Bart
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/