new target - ebtables dynamic snat, kernel and userspace patch
Subsystems (3)
---- README ---ebt_dyn_snat - ebtable dynamic snat
Authors:
Shai Tahar <[email protected]>
Changes source mac address according to source ip address based on
local arp table
to be used when source ip address is snated
Copyright (C) 2009 Storwize
ebtables target for transparent bridge
[user]<--->[transparent bridge]<--->[server]
if the transparent bridge maskes user ip address towards the server,
the bridge normally would replace the source mac address with the bridge mac
till now, using arptables and ebtables snat and arpreply targets used for overcoming this scenario.
using the attached target will rewrite the packet source mac address based on local arp table (no need for arptables and arpreplay)
1. new ebtables target: dynamic snat target support depends on BRIDGE_NF_EBTABLES
This option adds the MAC DYN SNAT target, which allows altering
dynamicly the MAC
source address of frames based on local arp table.
2. ebtables userspace extension
use the following rules for a bridge (eth0,eth2)
ebtables -t nat -A POSTROUTING -p IPV4 -o eth0 -j dyn_snat --dyn-snat-target ACCEPT ebtables -t nat -A POSTROUTING -p IPV4 -o eth2 -j dyn_snat --dyn-snat-target ACCEPT
---- kernel 2.6.26 -- 2.6.30 ----
include/linux/netfilter_bridge/ebt_dyn_snat.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* ebtables dynamic snat +* +* Authors: +* Shai Tahar <[email protected]> +* +* Copyright (C) 2009 Storwize +*/ +#ifndef __LINUX_BRIDGE_EBT_DYN_SNAT_H +#define __LINUX_BRIDGE_EBT_DYN_SNAT_H + + +struct ebt_dyn_snat_info +{ +int target; +}; +#define EBT_DYN_SNAT_TARGET "dyn_snat" + +#endif
net/bridge/netfilter/ebt_dyn_snat.c new file +111 -0
111 lines not on this page · raw message
----- user space based on ebtables 2.0.6 -----
ebtables-2.0.6/extensions/Makefile +0 -0
@@ -1,6 +1,6 @@
#! /usr/bin/make
-EXT_FUNC+=802_3 nat arp arpreply ip standard log redirect vlan mark_m mark \
+EXT_FUNC+=802_3 dyn_snat nat arp arpreply ip standard log redirect vlan mark_m mark \
pkttype stp among limit
EXT_TABLES+=filter nat broute
EXT_OBJS+=$(foreach T,$(EXT_FUNC), extensions/ebt_$(T).o)
ebtables-2.0.6/extensions/ebt_dyn_snat.c new file +125 -0
125 lines not on this page · raw message
ebtables-2.0.6/include/linux/netfilter_bridge/ebt_dyn_snat.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* ebt_dyn_snat - ebtable dynamic snat +* +* Authors: +* Shai Tahar <[email protected]> +* +* changes source mac address according to source ip address based on local arp table +* to be used when source ip address is snated +* +* Copyright (C) 2009 Storwize +*/ + +#ifndef __LINUX_BRIDGE_EBT_DYN_SNAT_H +#define __LINUX_BRIDGE_EBT_DYN_SNAT_H + + +struct ebt_dyn_snat_info +{ +int target; +}; +#define EBT_DYN_SNAT_TARGET "dyn_snat" + +#endif
Quoted 9 lines · Shai Tahar
---- README ---
ebt_dyn_snat- ebtable dynamic snat
Authors:
Shai Tahar <[email protected]>Changes source mac address according to source ip address based on local
arp table
to be used when source ip address is snated
Quoted 7 lines
Copyright (C) 2009 Storwize
ebtables target for transparent bridge
[user]<--->[transparent bridge]<--->[server]if the transparent bridge maskes user ip address towards the server, the bridge normally would replace the source mac address
Well, if you want to have the client's original MAC address in the packet, do not SNAT it. It (seems) as simple as that.
in case you manipulate the data in the connection, such as in tproxy scenario (squid etc')
a new connection goes out (with the same tuple) but the mac address is diffrent (the source mac is the device interface)
assuming A,B,C are mac address and 1,2,3 are ip address
[user]<--->[transparent bridge]<--->[server]
A1 B2 C3
user initiates a connection A1--->C3
the connection is redirected into B2, the connection is terminated as a socket to a local application on the traparent bridge machine.
a new connection goes out from B2, masked as B1--->C3 (the target changes B1 into A1) in return, the server answers A1 C3--->A1, the connection is redirected into the localhost the data then forwarded to the user B3--->A1 (the target changes B3 int C3)
Shai Tahar
Storwize
Quoted 24 lines · Jan Engelhardt
Quoted 9 lines · Shai Tahar
---- README ---
ebt_dyn_snat- ebtable dynamic snat
Authors:
Shai Tahar <[email protected]>Changes source mac address according to source ip address based on local
arp table
to be used when source ip address is snatedQuoted 8 lines
Copyright (C) 2009 Storwize
ebtables target for transparent bridge
[user]<--->[transparent bridge]<--->[server]if the transparent bridge maskes user ip address towards the server, the bridge normally would replace the source mac address
Well, if you want to have the client's original MAC address in the packet, do not SNAT it. It (seems) as simple as that.
Quoted 8 lines · Shai Tahar
in case you manipulate the data in the connection, such as in tproxy scenario (squid etc')
a new connection goes out (with the same tuple) but the mac address is diffrent (the source mac is the device interface)assuming A,B,C are mac address and 1,2,3 are ip address
[user]<--->[transparent bridge]<--->[server]
A1 B2 C3
Your next steps misunderstand how MAC addresses work. MAC changes at each physical NIC card plugged into the cable.
Corrections follow...
Quoted 1 line
user initiates a connection A1--->C3
Correction:
user initiates query A1---->?3
network responds ===> go to 3 via B
user initiates connection A1--->B3
Quoted 1 line
the connection is redirected into B2,
Correction:
the connection succeeds.
packets get forwarded
NORMAL OPERATION:
B2 relays packets to C3...
server sends reply packets C3--->B1
B2 proceeds to shuffle packets like so
out A1-->B3::B1-->C3
and back C3-->B1::B3-->A1
Quoted 1 line
the connection is terminated as a socket to a local application on the traparent bridge machine.
YOUR SCENARIO OPERATION:
B2 relays packets to local app.
local app initiates query B1---->?3
network responds ===> go to 3 via C
local app initiates connection B1--->C3
B2 proceeds to shuffle packets like so
out A1-->B3:local-app:B1-->C3
and back C3-->B1:local-app:B3-->A1
As you can see there is no difference between normal correct MAC operation and the existing tproxy scenario as viewed by C3 and A1.
AYJ
Quoted 34 lines
a new connection goes out from B2, masked as B1--->C3 (the target changes B1 into A1) in return, the server answers A1 C3--->A1, the connection is redirected into the localhost the data then forwarded to the user B3--->A1 (the target changes B3 int C3)
Shai Tahar
StorwizeQuoted 25 lines · Jan Engelhardt
Quoted 10 lines · Shai Tahar
---- README ---
ebt_dyn_snat- ebtable dynamic snat
Authors:
Shai Tahar <[email protected]>Changes source mac address according to source ip address based on
local
arp table
to be used when source ip address is snatedQuoted 8 lines
Copyright (C) 2009 Storwize
ebtables target for transparent bridge
[user]<--->[transparent bridge]<--->[server]if the transparent bridge maskes user ip address towards the server, the bridge normally would replace the source mac address
Well, if you want to have the client's original MAC address in the packet, do not SNAT it. It (seems) as simple as that.
Even better, plug the client machine directly into the server NIC.
Amos
Signature · 3 lines
Please be using Current Stable Squid 2.7.STABLE7 or 3.0.STABLE19 Current Beta Squid 3.1.0.13
Shai Tahar schreef:
Quoted 9 lines
---- README ---
ebt_dyn_snat- ebtable dynamic snat
Authors:
Shai Tahar <[email protected]>Changes source mac address according to source ip address based on
local arp table
to be used when source ip address is snated
Hi,
A few comments/questions.
Why is the standard target DROP?
Please provide a man file entry (ebtables.8)
You didn't provide the configuration option for the kernel
Please provide the patches as attachments (separate files for kernel and userspace) that will patch correctly with 'patch -p1 < $file'
After a first glance the code looks ok.
Maybe the description of your target should be more general: it matches the ARP source address to the IP source address based on the local arp table. Your target is indeed useful to make a bridging firewall that does IP NAT more transparent.
cheers,
Bart
Quoted 6 lines · Amos Jeffries
Quoted 5 lines · Shai Tahar
in case you manipulate the data in the connection, such as in tproxy scenario (squid etc')
a new connection goes out (with the same tuple) but the mac address is diffrent (the source mac is the device interface)
Quoted 8 lines
Quoted 5 lines
assuming A,B,C are mac address and 1,2,3 are ip address
[user]<--->[transparent bridge]<--->[server]
A1 B2 C3Your next steps misunderstand how MAC addresses work. MAC changes at each physical NIC card plugged into the cable.
Not necessarily, and not for a bridge. That's why bridges put the NIC in promiscuous mode.
Quoted 8 lines
Corrections follow...
Quoted 1 line
user initiates a connection A1--->C3
Correction:
user initiates query A1---->?3
network responds ===> go to 3 via B
user initiates connection A1--->B3
That's how proxy arp works, not bridging. A bridge knows nothing about IP, it just forwards packets unmodified to the destination MAC address.