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.
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.
|