From 93804b66c5301af75cd6930f9c6653228cce8719 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 25 Jan 2015 10:57:00 +0100 Subject: [PATCH] core: tls hooks can execute a callback before modules init function is executed - useful to prepare tls environment before a module might access it - executed after modparam but before mod_init (cherry picked from commit 4700831fa0f2dc52e296ce647711b03d1406497a) --- main.c | 18 ++++++++++++++++++ tls_hooks.c | 9 ++++++++- tls_hooks.h | 7 +++++-- tls_hooks_init.h | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index e285b49092f..d30e2135558 100644 --- a/main.c +++ b/main.c @@ -2498,6 +2498,24 @@ int main(int argc, char** argv) if (real_time&4) set_rt_prio(rt_prio, rt_policy); +#ifdef USE_TCP +#ifdef USE_TLS + if (!tls_disable){ + if (!tls_loaded()){ + LM_WARN("tls support enabled, but no tls engine " + " available (forgot to load the tls module?)\n"); + LM_WARN("disabling tls...\n"); + tls_disable=1; + } else { + LM_DBG("=============================\n"); + if (pre_init_tls()<0){ + LM_CRIT("could not pre-initialize tls, exiting...\n"); + goto error; + } + } + } +#endif /* USE_TLS */ +#endif /* USE_TCP */ if (init_modules() != 0) { fprintf(stderr, "ERROR: error while initializing modules\n"); diff --git a/tls_hooks.c b/tls_hooks.c index 9b6dab653bd..29f82b64f49 100644 --- a/tls_hooks.c +++ b/tls_hooks.c @@ -37,7 +37,7 @@ #ifdef TLS_HOOKS -struct tls_hooks tls_hook= {0, 0, 0, 0, 0 ,0 ,0}; +struct tls_hooks tls_hook= {0,0,0,0,0,0,0,0}; static int tls_hooks_loaded=0; @@ -71,6 +71,13 @@ int init_tls() return 0; } +int pre_init_tls() +{ + if (tls_hook.pre_init) + return tls_hook.pre_init(); + return 0; +} + void destroy_tls() { if (tls_hook.destroy) diff --git a/tls_hooks.h b/tls_hooks.h index c342e4a65aa..d08c0bf7da9 100644 --- a/tls_hooks.h +++ b/tls_hooks.h @@ -74,15 +74,18 @@ struct tls_hooks{ void (*tcpconn_clean)(struct tcp_connection* c); void (*tcpconn_close)(struct tcp_connection*c , int fd); - /* per listening socket init, called on ser startup (after modules, + /* per listening socket init, called on kamailio startup (after modules, * process table, init() and udp socket initialization)*/ int (*init_si)(struct socket_info* si); - /* generic init function (called at ser init, after module initialization + /* generic init function (called at kamailio init, after module initialization * and process table creation)*/ int (*init)(void); /* destroy function, called after the modules are destroyed, and * after destroy_tcp() */ void (*destroy)(void); + /* generic pre-init function (called at kamailio start, before module + * initialization (after modparams) */ + int (*pre_init)(void); }; diff --git a/tls_hooks_init.h b/tls_hooks_init.h index d494cba282d..458e22eac34 100644 --- a/tls_hooks_init.h +++ b/tls_hooks_init.h @@ -53,6 +53,7 @@ int tls_has_init_si(void); /*returns true if a handle for tls_init is registered int tls_init(struct socket_info* si); int init_tls(void); void destroy_tls(void); +int pre_init_tls(void); #endif /* TLS_HOOKS */ #endif