Subject: Re: new EtherIP driver for 4.0
To: None <tech-net@NetBSD.org>
From: David Young <dyoung@pobox.com>
List: tech-net
Date: 10/31/2006 16:25:11
On Tue, Oct 31, 2006 at 03:36:01PM +0100, Hans Rosenfeld wrote:
> Hi,
>
> I wrote a new EtherIP driver for 4.0 based on tap(4) and gif(4).
>
> I did this because the current EtherIP implementation is buggy
> (kern/34268), quite unclean (it magically works by bridging a gif
> interface) and, as I have been told, its way of hijacking a random
> ethernet interfaces input routine to insert packets into the bridge is
> at least questionable. It is also not possible to use bridge features
> like STP with the current implementation.
Hans,
That's cool, thanks! I can adapt this code to work with gre, too.
***
It occurred to me this morning that instead of adding entries to the
protocol switch for gif or gre, maybe we can use raw sockets like so?
struct socket *so;
socreate(AF_xxx ..., &so, SOCK_RAW, IPPROTO_xxx, ...)
sobind(so, local_outer_address, ...);
soconnect(so, remote_outer_address, ...);
This has the advantage that it re-uses protocol demultiplexing code.
That is, we do not have to search the available tunnel interfaces as gre
does in gre_lookup(), but the socket demultiplexing code does this for us:
for (sc = LIST_FIRST(&gre_softc_list); sc != NULL;
sc = LIST_NEXT(sc, sc_list)) {
if ((sc->g_dst.s_addr == ip->ip_src.s_addr) &&
(sc->g_src.s_addr == ip->ip_dst.s_addr) &&
(sc->g_proto == proto) &&
((sc->sc_if.if_flags & IFF_UP) != 0))
return (sc);
}
Also, using raw sockets helps simplify gre, which already uses sockets
in UDP mode. GRE can dispense with IP encapsulation and demultiplexing,
and the kernel thread that does sosends and soreceives UDP datagrams can
sosend/soreceive IPv4- / IPv6-encapsulated packets, too. Many lines of
code will be saved. IPv6-enabling GRE will become very easy.
I believe the raw sockets approach will simplify etherip, too. I believe
virtually all of the code in sys/netinet{6,}/ can go away.
What do you think?
Dave
--
David Young OJC Technologies
dyoung@ojctech.com Urbana, IL * (217) 278-3933