All of lore.kernel.org
 help / color / mirror / Atom feed
* L2 NAT
@ 2008-11-14 16:34 ivan
  2008-11-15  4:02 ` Grant Taylor
  0 siblings, 1 reply; 7+ messages in thread
From: ivan @ 2008-11-14 16:34 UTC (permalink / raw)
  To: netfilter

Hi All,

I need to connect three devices via ethernet, through a switch, to the
same tftp server. The problem is that these devices have the same IPs,
i.e. 192.168.0.181, and when I address to or get data from one of
them, I can't tell which device I'm actually talking to. The devices
are three items of the same product, and their IP cannot be changed.

I have implemented a perl script that changes the ARP table in tftp
server side, but I need a stronger solution.

I was thinking on developing a sort of L2 NAT which could change the
IP source address of a package according to its MAC address, and put
it in the middle of the tftp server and the devices.

Using the current iptables command can I set up this?? or  I need to
develop my own kernel module???

If you have any idea please let me know.


Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: L2 NAT
  2008-11-14 16:34 ivan
@ 2008-11-15  4:02 ` Grant Taylor
  0 siblings, 0 replies; 7+ messages in thread
From: Grant Taylor @ 2008-11-15  4:02 UTC (permalink / raw)
  To: Mail List - Netfilter

On 11/14/2008 10:34 AM, ivan wrote:
> I need to connect three devices via ethernet, through a switch, to 
> the same tftp server. The problem is that these devices have the same 
> IPs, i.e. 192.168.0.181, and when I address to or get data from one 
> of them, I can't tell which device I'm actually talking to. The 
> devices are three items of the same product, and their IP cannot be 
> changed.

Do the devices ever initiate connections to your server or just respond 
to connections that the server initiates?

If it is your server initiating connections, you might be able to 
statically set arp entries for each device on it's own bogus IP.  By 
doing this you should be able to talk to each bogus IP and have the 
ethernet frames go to the proper device.  If the IP stack / software on 
each device is simple enough, you can probably talk to it with the 
incorrect destination IP.  Though I'm not 100% sure what the returning 
packet would be like.  But it is a direction to look.

> I have implemented a perl script that changes the ARP table in tftp 
> server side, but I need a stronger solution.

*nod*

> I was thinking on developing a sort of L2 NAT which could change the 
> IP source address of a package according to its MAC address, and put 
> it in the middle of the tftp server and the devices.

You might be able to use Bridge NetFilter extensions on a box between 
the three devices and the server to be able to NAT the IPs of the traffic.

You could choose what source IP to SNAT traffic to based on the source 
MAC address.  If you send the new ethernet frame out with the original 
source MAC address your server will have the proper MAC address and a 
spoofed IP to know where the packet came from.

Your server will have to reply to a MAC address, probably the real MAC 
address of the device but with a spoofed IP.  So the bridge will have to 
DNAT the traffic based on the destination MAC address.

This should take care of packets leaving the devices going to the server.

You will need to watch for ARP queries from the network for the spoofed 
IPs of the devices and have the bridge send the ARP reply with the 
correct MAC addresses and the spoofed IPs.

> Using the current iptables command can I set up this?? or  I need to 
> develop my own kernel module???

I think you might be able to pull it off with a combination of IPTables 
and EBTables.

> If you have any idea please let me know.

See what you think of the above ideas.



Grant. . . .

^ permalink raw reply	[flat|nested] 7+ messages in thread

* L2 NAT
@ 2008-12-03 17:22 ivan
  2008-12-04  1:01 ` James King
  0 siblings, 1 reply; 7+ messages in thread
From: ivan @ 2008-12-03 17:22 UTC (permalink / raw)
  To: netfilter-devel

Hi,

After having a lot of help of Grant Taylor in order to analyze if I
was able to achieve my idea using the available iptables features, and
getting as result the fact that I had to develop my own kernel module.
I'm writing to this list because my question is related to the linux
kernel programing.

I would like to pass parameters to the kernel module in run time from
user space. These parameters could be IP address and MAC. Somebody
know how I can do this??

I was thinking about passing this parameters thorough a sysctl syscall
or using /proc filesystem, but I beleave that this is not the correct
way.

Also I was taking a look to iptables source code and analyzing the
source code of iptables and libiptc lib, but I could not find any clue
how to these ones change the kernel parameters.

Could you pleas help me???

thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: L2 NAT
  2008-12-03 17:22 L2 NAT ivan
@ 2008-12-04  1:01 ` James King
  2008-12-04 13:34   ` ivan
  0 siblings, 1 reply; 7+ messages in thread
From: James King @ 2008-12-04  1:01 UTC (permalink / raw)
  To: ivan; +Cc: netfilter-devel

On Wed, Dec 3, 2008 at 9:22 AM, ivan <lagigliaivan@gmail.com> wrote:
> I would like to pass parameters to the kernel module in run time from
> user space. These parameters could be IP address and MAC. Somebody
> know how I can do this??

Use the module_param functions (you probably want the string variant).
 See http://tldp.org/LDP/lkmpg/2.6/html/x323.html for examples.

> I was thinking about passing this parameters thorough a sysctl syscall
> or using /proc filesystem, but I beleave that this is not the correct
> way.

Depends on if you need to be able to modify it after the module has
already been loaded.  If not, a module parameter should suffice.


HTH,
James

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: L2 NAT
  2008-12-04  1:01 ` James King
@ 2008-12-04 13:34   ` ivan
  2008-12-04 14:38     ` John Haxby
  0 siblings, 1 reply; 7+ messages in thread
From: ivan @ 2008-12-04 13:34 UTC (permalink / raw)
  To: James King; +Cc: netfilter-devel

James,

Thanks for your soon reply!

I think that your answer is a good approach, but I would like to
pass/modify the module parameters while this one is running. I believe
this way allows to the user more flexibility to add/configure the
module behavior.

Please, let me know if you have any idea.

Thanks again.

ivan.




On Wed, Dec 3, 2008 at 11:01 PM, James King <t.james.king@gmail.com> wrote:
> On Wed, Dec 3, 2008 at 9:22 AM, ivan <lagigliaivan@gmail.com> wrote:
>> I would like to pass parameters to the kernel module in run time from
>> user space. These parameters could be IP address and MAC. Somebody
>> know how I can do this??
>
> Use the module_param functions (you probably want the string variant).
>  See http://tldp.org/LDP/lkmpg/2.6/html/x323.html for examples.
>
>> I was thinking about passing this parameters thorough a sysctl syscall
>> or using /proc filesystem, but I beleave that this is not the correct
>> way.
>
> Depends on if you need to be able to modify it after the module has
> already been loaded.  If not, a module parameter should suffice.
>
>
> HTH,
> James
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: L2 NAT
  2008-12-04 13:34   ` ivan
@ 2008-12-04 14:38     ` John Haxby
  2008-12-04 15:43       ` ivan
  0 siblings, 1 reply; 7+ messages in thread
From: John Haxby @ 2008-12-04 14:38 UTC (permalink / raw)
  To: ivan; +Cc: James King, netfilter-devel

ivan wrote:
> I think that your answer is a good approach, but I would like to
> pass/modify the module parameters while this one is running. I believe
> this way allows to the user more flexibility to add/configure the
> module behavior.
>   

You can do that with module parameters, they appears as files in 
/sys/module/<module-name>/parameters and, given the right permissions, 
you can modify them as you see fit.

jch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: L2 NAT
  2008-12-04 14:38     ` John Haxby
@ 2008-12-04 15:43       ` ivan
  0 siblings, 0 replies; 7+ messages in thread
From: ivan @ 2008-12-04 15:43 UTC (permalink / raw)
  To: John Haxby; +Cc: James King, netfilter-devel

Thanks jch,

I will try doing this!
My module works changing the IP address of a package according to its
MAC address, so I would like to add diferents <MAC-IP> couples while
the module is running.

Thanks!!

On Thu, Dec 4, 2008 at 12:38 PM, John Haxby <john.haxby@oracle.com> wrote:
> ivan wrote:
>>
>> I think that your answer is a good approach, but I would like to
>> pass/modify the module parameters while this one is running. I believe
>> this way allows to the user more flexibility to add/configure the
>> module behavior.
>>
>
> You can do that with module parameters, they appears as files in
> /sys/module/<module-name>/parameters and, given the right permissions, you
> can modify them as you see fit.
>
> jch
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-12-04 15:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-03 17:22 L2 NAT ivan
2008-12-04  1:01 ` James King
2008-12-04 13:34   ` ivan
2008-12-04 14:38     ` John Haxby
2008-12-04 15:43       ` ivan
  -- strict thread matches above, loose matches on Subject: below --
2008-11-14 16:34 ivan
2008-11-15  4:02 ` Grant Taylor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.