On Fri, Mar 21, 2014 at 10:01:09AM +0000, Anton Ivanov wrote:
> I am wondering how to re-organize these so that the code is not
> duplicated across 3-4 drivers as well as allow people to easily add more
> encaps in the future.
> One way will be to pull all common routines into a common file and have
> different option sets and different inits. Another will be to have
> "encaps" as a parameter to a common driver. This, however will make all
> params optional making option parsing ugly and prone to coding errors.

The user-visible command-line options will be different (e.g. L2TPv3 rx
cookie).  Therefore, I suggest having independent user-facing netdevs.

In other words, give each encapsulation its own NetdevFooOptions in
qapi-schema.json and a net_init_foo() function.

qemu -netdev gre,... -netdev l2tp,...

The actual implementation could be shared.  Maybe something like:
net/encap.c - common code for encapsulation/tunneling
net/encap.h - header used by L2TPv3 and GRE
net/l2tpv3.c - L2TPv3 specific code and net_init_l2tp()
net/gre.c - GRE specific code and net_init_gre()

How exactly the net/encap.h interface looks is something you need to
decide based on the details.  Does it make sense to have a common
NetdevEncap struct that can be embedded and has function pointers for
protocol-specific hooks?  Or is it better to just provide common
functions and let protocols use them as a library?  It's up to you.

Stefan

Reply via email to