tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Enable to send packets on if_loop via bpf



Hi,

NetBSD can't send packets on a loopback interface
via bpf while FreeBSD and OpenBSD can.  Let's
make it available on NetBSD too.  The feature
is useful when you want to emulate incoming packets
easily on say testing.  Actually I found this issue when
I had been importing tests from FreeBSD.

NetBSD can't do this because a loopback interface
registers itself to bpf as DLT_NULL and bpf treats
packets being sent over the interface as AF_UNSPEC.
Packets of AF_UNSPEC are just dropped by loopback
interfaces.

FreeBSD and OpenBSD enable to do that by letting users
prepend a protocol family to a sending data.  bpf (or if_loop)
extracts it and handles the packet as an extracted protocol
family.  The following patch follows them (the implementation
is inspired by OpenBSD).

http://www.netbsd.org/~ozaki-r/loop-bpf.patch

The patch changes if_loop to register itself to bpf
as DLT_LOOP and bpf to handle a prepending protocol
family on bpf_write if a sender interface is DLT_LOOP.

There is a small thing to be decided.  Unfortunately,
the implementations of FreeBSD and OpenBSD are NOT
compatible.  FreeBSD prepends a protocol family in the
host byte order while OpenBSD prepends it in the
network byte order.  I picked FreeBSD's for no big reason
(or just because we know packets don't go outside).

Any thoughts or comments?

Thanks,
  ozaki-r


Home | Main Index | Thread Index | Old Index