This patch enables the ability to load multiple versions of the same TCP stack.
It lets us write simple Makefiles like this:
#
# $FreeBSD$
#
STACKNAME= bbr_17q22
KMOD= tcp_${STACKNAME}
SRCS= bbr.c sack_filter.c
#
# Enable full debugging
#
#CFLAGS += -g
CFLAGS+= -DMODNAME=${KMOD}
CFLAGS+= -DSTACKNAME=${STACKNAME}
PREFIX_SYMS= ${KMOD}_
.include <bsd.kmod.mk>In the code, we can register non-conflicting module names like this:
MODULE_VERSION(MODNAME, 1); DECLARE_MODULE(MODNAME, tcp_bbr, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);
We can enable multiple stack names like this:
static const char *my_stack_names[] = {
__XSTRING(STACKNAME),
#ifdef STACKALIAS
__XSTRING(STACKALIAS),
#endif
};
...
num_stacks = nitems(my_stack_names);
err = register_tcp_functions_as_names(&__tcp_mystack, M_WAITOK,
my_stack_names, &num_stacks);To do this, it:
- Supports symbol mangling to avoid overlapping symbols between the multiple modules.
- Lets us use a macro as the module name in the DECLARE_MACRO() and MACRO_VERSION() macros.
- Lets us register stack aliases (e.g. both a generic name ["default"] and version-specific name ["default_v1"]).
We can then create a new version of the module just by changing the STACKNAME variable.