Speno's Pythonic Avocado 5.6.2004

2004-06-05

Starting an Ethernet bridge in Python

I'm trying to write an ethernet bridge in Python on MacOS X. The idea is simple enough: take an ethernet frame from one interface and send it out a different interface skipping over those frames that are destined for the bridge itself (my iBook). It's probably not as hard as it sounds. At least I hope it won't be. Smiley

Getting packets off of an interface is easy using pcapy. Inspecting ethernet frames so that we don't forward ones that are addressed to the brige device is easy using Impacket. Alternativley, we can use a capture filter with pcapy to avoid getting our own frames. That part's already done, leaving just the hard parts to solve. However, there are a few problems to overcome first.

The major problem is that MacOS X will re-write the source of any ethernet frame such that it appears to come from the interface it was written to. Obviously, this will totally break our bridge. I have filed a bug report with Apple about this. In the meantime, you can build your own patched kernel to fix this problem.

Once I get my new kernel running, I'll need a way to write already formed ethernet frames to the network. The Python socket module doesn't support this on anything but Linux, where the AF_PACKET address family is implemented. I'll have to find an alternative such as using libnet, extending Python's own socketmodule.c or making a simple rawsocket module using Pyrex. Ideas and code are welcome, of course!

Take care.

This post references topics: python
posted at 09:52:00    #    comment []    trackback []
June 2004
MoTuWeThFrSaSu
  1 2 3 4 5 6
7 8 910111213
14151617181920
21222324252627
282930    
May
2004
 Aug
2004

One python programmer's search for understanding and avocados. This isn't personal, only pythonic.

XML-Image Letterimage

© 2004-2005, John P. Speno