[sr-dev] git:4.2:93804b66: core: tls hooks can execute a callback before modules init function is executed

Daniel-Constantin Mierla miconda at gmail.com
Wed Jan 28 13:46:44 CET 2015


Module: kamailio
Branch: 4.2
Commit: 93804b66c5301af75cd6930f9c6653228cce8719
URL: https://github.com/kamailio/kamailio/commit/93804b66c5301af75cd6930f9c6653228cce8719

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-01-28T13:40:40+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

(cherry picked from commit 4700831fa0f2dc52e296ce647711b03d1406497a)

---

Modified: main.c
Modified: tls_hooks.c
Modified: tls_hooks.h
Modified: tls_hooks_init.h

---

Diff:  https://github.com/kamailio/kamailio/commit/93804b66c5301af75cd6930f9c6653228cce8719.diff
Patch: https://github.com/kamailio/kamailio/commit/93804b66c5301af75cd6930f9c6653228cce8719.patch

---

diff --git a/main.c b/main.c
index e285b49..d30e213 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 9b6dab6..29f82b6 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 c342e4a..d08c0bf 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 d494cba..458e22e 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




More information about the sr-dev mailing list