aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJonathan T. Looney <jtl@FreeBSD.org>2017-06-08 20:41:28 +0000
committerJonathan T. Looney <jtl@FreeBSD.org>2017-06-08 20:41:28 +0000
commitdc6a41b936668b4022d98d986f4db7dec8e94b90 (patch)
treebe74ecf011f53c4b9a56dc38093d3f0cdc4d00b7 /sys
parentc2aa86d19c5b52ce2a7383a088ddda959c23db58 (diff)
downloadsrc-dc6a41b936668b4022d98d986f4db7dec8e94b90.tar.gz
src-dc6a41b936668b4022d98d986f4db7dec8e94b90.zip
Add the infrastructure to support loading multiple versions of TCP
stack modules. It adds support for mangling symbols exported by a module by prepending a string to them. (This avoids overlapping symbols in the kernel linker.) It allows the use of a macro as the module name in the DECLARE_MACRO() and MACRO_VERSION() macros. It allows the code to register stack aliases (e.g. both a generic name ["default"] and version-specific name ["default_10_3p1"]). With these changes, it is trivial to compile TCP stack modules with the name defined in the Makefile and to load multiple versions of the same stack simultaneously. This functionality can be used to enable side-by-side testing of an old and new version of the same TCP stack. It also could support upgrading the TCP stack without a reboot. Reviewed by: gnn, sjg (makefiles only) Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D11086
Notes
Notes: svn path=/head/; revision=319719
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/kmod.mk4
-rw-r--r--sys/conf/kmod_syms_prefix.awk18
-rw-r--r--sys/netinet/tcp_subr.c142
-rw-r--r--sys/netinet/tcp_var.h9
-rw-r--r--sys/sys/module.h14
5 files changed, 152 insertions, 35 deletions
diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 635600759685..8469d4d9fefa 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -253,6 +253,10 @@ ${FULLPROG}: ${OBJS}
export_syms | xargs -J% ${OBJCOPY} % ${.TARGET}
.endif
.endif
+.if defined(PREFIX_SYMS)
+ ${AWK} -v prefix=${PREFIX_SYMS} -f ${SYSDIR}/conf/kmod_syms_prefix.awk \
+ ${.TARGET} /dev/null | xargs -J% ${OBJCOPY} % ${.TARGET}
+.endif
.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no
${OBJCOPY} --strip-debug ${.TARGET}
.endif
diff --git a/sys/conf/kmod_syms_prefix.awk b/sys/conf/kmod_syms_prefix.awk
new file mode 100644
index 000000000000..9962ddc60a05
--- /dev/null
+++ b/sys/conf/kmod_syms_prefix.awk
@@ -0,0 +1,18 @@
+# $FreeBSD$
+
+# Read global symbols from object file.
+BEGIN {
+ while ("${NM:='nm'} " ARGV[1] | getline) {
+ if (match($0, /^[^[:space:]]+ [^AU] (.*)$/)) {
+ syms[$3] = $2
+ }
+ }
+ delete ARGV[1]
+}
+
+# Strip commons, make everything else local.
+END {
+ for (member in syms) {
+ printf("--redefine-sym=%s=%s%s\n", member, prefix, member);
+ }
+}
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 39ebe70432fe..8cbfa1262209 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -275,7 +275,7 @@ find_tcp_functions_locked(struct tcp_function_set *fs)
struct tcp_function_block *blk=NULL;
TAILQ_FOREACH(f, &t_functions, tf_next) {
- if (strcmp(f->tf_fb->tfb_tcp_block_name, fs->function_set_name) == 0) {
+ if (strcmp(f->tf_name, fs->function_set_name) == 0) {
blk = f->tf_fb;
break;
}
@@ -376,6 +376,7 @@ sysctl_net_inet_list_available(SYSCTL_HANDLER_ARGS)
struct tcp_function *f;
char *buffer, *cp;
size_t bufsz, outsz;
+ bool alias;
cnt = 0;
rw_rlock(&tcp_function_lock);
@@ -384,22 +385,25 @@ sysctl_net_inet_list_available(SYSCTL_HANDLER_ARGS)
}
rw_runlock(&tcp_function_lock);
- bufsz = (cnt+2) * (TCP_FUNCTION_NAME_LEN_MAX + 12) + 1;
+ bufsz = (cnt+2) * ((TCP_FUNCTION_NAME_LEN_MAX * 2) + 13) + 1;
buffer = malloc(bufsz, M_TEMP, M_WAITOK);
error = 0;
cp = buffer;
- linesz = snprintf(cp, bufsz, "\n%-32s%c %s\n", "Stack", 'D', "PCB count");
+ linesz = snprintf(cp, bufsz, "\n%-32s%c %-32s %s\n", "Stack", 'D',
+ "Alias", "PCB count");
cp += linesz;
bufsz -= linesz;
outsz = linesz;
rw_rlock(&tcp_function_lock);
TAILQ_FOREACH(f, &t_functions, tf_next) {
- linesz = snprintf(cp, bufsz, "%-32s%c %u\n",
+ alias = (f->tf_name != f->tf_fb->tfb_tcp_block_name);
+ linesz = snprintf(cp, bufsz, "%-32s%c %-32s %u\n",
f->tf_fb->tfb_tcp_block_name,
(f->tf_fb == tcp_func_set_ptr) ? '*' : ' ',
+ alias ? f->tf_name : "-",
f->tf_fb->tfb_refcnt);
if (linesz >= bufsz) {
error = EOVERFLOW;
@@ -500,12 +504,31 @@ maketcp_hashsize(int size)
return (hashsize);
}
+/*
+ * Register a TCP function block with the name provided in the names
+ * array. (Note that this function does NOT automatically register
+ * blk->tfb_tcp_block_name as a stack name. Therefore, you should
+ * explicitly include blk->tfb_tcp_block_name in the list of names if
+ * you wish to register the stack with that name.)
+ *
+ * Either all name registrations will succeed or all will fail. If
+ * a name registration fails, the function will update the num_names
+ * argument to point to the array index of the name that encountered
+ * the failure.
+ *
+ * Returns 0 on success, or an error code on failure.
+ */
int
-register_tcp_functions(struct tcp_function_block *blk, int wait)
+register_tcp_functions_as_names(struct tcp_function_block *blk, int wait,
+ const char *names[], int *num_names)
{
- struct tcp_function_block *lblk;
struct tcp_function *n;
struct tcp_function_set fs;
+ int error, i;
+
+ KASSERT(names != NULL && *num_names > 0,
+ ("%s: Called with 0-length name list", __func__));
+ KASSERT(names != NULL, ("%s: Called with NULL name list", __func__));
if (t_functions_inited == 0) {
init_tcp_functions();
@@ -518,6 +541,7 @@ register_tcp_functions(struct tcp_function_block *blk, int wait)
* These functions are required and you
* need a name.
*/
+ *num_names = 0;
return (EINVAL);
}
if (blk->tfb_tcp_timer_stop_all ||
@@ -532,34 +556,99 @@ register_tcp_functions(struct tcp_function_block *blk, int wait)
(blk->tfb_tcp_timer_activate == NULL) ||
(blk->tfb_tcp_timer_active == NULL) ||
(blk->tfb_tcp_timer_stop == NULL)) {
- return (EINVAL);
+ *num_names = 0;
+ return (EINVAL);
}
- }
- n = malloc(sizeof(struct tcp_function), M_TCPFUNCTIONS, wait);
- if (n == NULL) {
- return (ENOMEM);
- }
- n->tf_fb = blk;
- strcpy(fs.function_set_name, blk->tfb_tcp_block_name);
- rw_wlock(&tcp_function_lock);
- lblk = find_tcp_functions_locked(&fs);
- if (lblk) {
- /* Duplicate name space not allowed */
- rw_wunlock(&tcp_function_lock);
- free(n, M_TCPFUNCTIONS);
- return (EALREADY);
}
+
refcount_init(&blk->tfb_refcnt, 0);
blk->tfb_flags = 0;
- TAILQ_INSERT_TAIL(&t_functions, n, tf_next);
- rw_wunlock(&tcp_function_lock);
+ for (i = 0; i < *num_names; i++) {
+ n = malloc(sizeof(struct tcp_function), M_TCPFUNCTIONS, wait);
+ if (n == NULL) {
+ error = ENOMEM;
+ goto cleanup;
+ }
+ n->tf_fb = blk;
+
+ (void)strncpy(fs.function_set_name, names[i],
+ TCP_FUNCTION_NAME_LEN_MAX);
+ fs.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
+ rw_wlock(&tcp_function_lock);
+ if (find_tcp_functions_locked(&fs) != NULL) {
+ /* Duplicate name space not allowed */
+ rw_wunlock(&tcp_function_lock);
+ free(n, M_TCPFUNCTIONS);
+ error = EALREADY;
+ goto cleanup;
+ }
+ (void)strncpy(n->tf_name, names[i], TCP_FUNCTION_NAME_LEN_MAX);
+ n->tf_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
+ TAILQ_INSERT_TAIL(&t_functions, n, tf_next);
+ rw_wunlock(&tcp_function_lock);
+ }
return(0);
-}
+
+cleanup:
+ /*
+ * Deregister the names we just added. Because registration failed
+ * for names[i], we don't need to deregister that name.
+ */
+ *num_names = i;
+ rw_wlock(&tcp_function_lock);
+ while (--i >= 0) {
+ TAILQ_FOREACH(n, &t_functions, tf_next) {
+ if (!strncmp(n->tf_name, names[i],
+ TCP_FUNCTION_NAME_LEN_MAX)) {
+ TAILQ_REMOVE(&t_functions, n, tf_next);
+ n->tf_fb = NULL;
+ free(n, M_TCPFUNCTIONS);
+ break;
+ }
+ }
+ }
+ rw_wunlock(&tcp_function_lock);
+ return (error);
+}
+
+/*
+ * Register a TCP function block using the name provided in the name
+ * argument.
+ *
+ * Returns 0 on success, or an error code on failure.
+ */
+int
+register_tcp_functions_as_name(struct tcp_function_block *blk, const char *name,
+ int wait)
+{
+ const char *name_list[1];
+ int num_names, rv;
+
+ num_names = 1;
+ if (name != NULL)
+ name_list[0] = name;
+ else
+ name_list[0] = blk->tfb_tcp_block_name;
+ rv = register_tcp_functions_as_names(blk, wait, name_list, &num_names);
+ return (rv);
+}
+
+/*
+ * Register a TCP function block using the name defined in
+ * blk->tfb_tcp_block_name.
+ *
+ * Returns 0 on success, or an error code on failure.
+ */
+int
+register_tcp_functions(struct tcp_function_block *blk, int wait)
+{
+
+ return (register_tcp_functions_as_name(blk, NULL, wait));
+}
int
deregister_tcp_functions(struct tcp_function_block *blk)
{
- struct tcp_function_block *lblk;
struct tcp_function *f;
int error=ENOENT;
@@ -579,8 +668,7 @@ deregister_tcp_functions(struct tcp_function_block *blk)
rw_wunlock(&tcp_function_lock);
return (EBUSY);
}
- lblk = find_tcp_fb_locked(blk, &f);
- if (lblk) {
+ while (find_tcp_fb_locked(blk, &f) != NULL) {
/* Found */
TAILQ_REMOVE(&t_functions, f, tf_next);
f->tf_fb = NULL;
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index d298c9dd6c61..2e2f88acbcbc 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -272,8 +272,9 @@ struct tcp_function_block {
};
struct tcp_function {
- TAILQ_ENTRY(tcp_function) tf_next;
- struct tcp_function_block *tf_fb;
+ TAILQ_ENTRY(tcp_function) tf_next;
+ char tf_name[TCP_FUNCTION_NAME_LEN_MAX];
+ struct tcp_function_block *tf_fb;
};
TAILQ_HEAD(tcp_funchead, tcp_function);
@@ -785,6 +786,10 @@ void tcp_do_segment(struct mbuf *, struct tcphdr *,
int);
int register_tcp_functions(struct tcp_function_block *blk, int wait);
+int register_tcp_functions_as_names(struct tcp_function_block *blk,
+ int wait, const char *names[], int *num_names);
+int register_tcp_functions_as_name(struct tcp_function_block *blk,
+ const char *name, int wait);
int deregister_tcp_functions(struct tcp_function_block *blk);
struct tcp_function_block *find_and_ref_tcp_functions(struct tcp_function_set *fs);
struct tcp_function_block *find_and_ref_tcp_fb(struct tcp_function_block *blk);
diff --git a/sys/sys/module.h b/sys/sys/module.h
index 71aa9954b210..5a268fc11d7e 100644
--- a/sys/sys/module.h
+++ b/sys/sys/module.h
@@ -106,14 +106,15 @@ struct mod_pnp_match_info
#include <sys/linker_set.h>
+#define MODULE_METADATA_CONCAT(uniquifier) _mod_metadata##uniquifier
#define MODULE_METADATA(uniquifier, type, data, cval) \
- static struct mod_metadata _mod_metadata##uniquifier = { \
+ static struct mod_metadata MODULE_METADATA_CONCAT(uniquifier) = { \
MDT_STRUCT_VERSION, \
type, \
data, \
cval \
}; \
- DATA_SET(modmetadata_set, _mod_metadata##uniquifier)
+ DATA_SET(modmetadata_set, MODULE_METADATA_CONCAT(uniquifier))
#define MODULE_DEPEND(module, mdepend, vmin, vpref, vmax) \
static struct mod_depend _##module##_depend_on_##mdepend \
@@ -139,7 +140,7 @@ struct mod_pnp_match_info
#define DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, maxver) \
MODULE_DEPEND(name, kernel, __FreeBSD_version, \
__FreeBSD_version, maxver); \
- MODULE_METADATA(_md_##name, MDT_MODULE, &data, #name); \
+ MODULE_METADATA(_md_##name, MDT_MODULE, &data, __XSTRING(name));\
SYSINIT(name##module, sub, order, module_register_init, &data); \
struct __hack
@@ -156,13 +157,14 @@ struct mod_pnp_match_info
#define DECLARE_MODULE_TIED(name, data, sub, order) \
DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, __FreeBSD_version)
+#define MODULE_VERSION_CONCAT(module, version) _##module##_version
#define MODULE_VERSION(module, version) \
- static struct mod_version _##module##_version \
+ static struct mod_version MODULE_VERSION_CONCAT(module, version)\
__section(".data") = { \
version \
}; \
- MODULE_METADATA(_##module##_version, MDT_VERSION, \
- &_##module##_version, #module)
+ MODULE_METADATA(MODULE_VERSION_CONCAT(module, version), MDT_VERSION,\
+ &MODULE_VERSION_CONCAT(module, version), __XSTRING(module))
/**
* Generic macros to create pnp info hints that modules may export