Module: kamailio
Branch: master
Commit: 4700831fa0f2dc52e296ce647711b03d1406497a
URL:
https://github.com/kamailio/kamailio/commit/4700831fa0f2dc52e296ce647711b03…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-01-25T10:57:00+01:00
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
---
Modified: main.c
Modified: tls_hooks.c
Modified: tls_hooks.h
Modified: tls_hooks_init.h
---
Diff:
https://github.com/kamailio/kamailio/commit/4700831fa0f2dc52e296ce647711b03…
Patch:
https://github.com/kamailio/kamailio/commit/4700831fa0f2dc52e296ce647711b03…
---
diff --git a/main.c b/main.c
index 3899422..892ead0 100644
--- a/main.c
+++ b/main.c
@@ -2445,6 +2445,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 37ae42d..92e709f 100644
--- a/tls_hooks.c
+++ b/tls_hooks.c
@@ -28,7 +28,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;
@@ -62,6 +62,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 3f08f2f..3ac5bd2 100644
--- a/tls_hooks.h
+++ b/tls_hooks.h
@@ -64,15 +64,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 21d464c..3657769 100644
--- a/tls_hooks_init.h
+++ b/tls_hooks_init.h
@@ -44,6 +44,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