Browse Source

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
Daniel-Constantin Mierla 10 years ago
parent
commit
4700831fa0
4 changed files with 32 additions and 3 deletions
  1. 18 0
      main.c
  2. 8 1
      tls_hooks.c
  3. 5 2
      tls_hooks.h
  4. 1 0
      tls_hooks_init.h

+ 18 - 0
main.c

@@ -2445,6 +2445,24 @@ try_again:
 	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");

+ 8 - 1
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)

+ 5 - 2
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);
 };
 
 

+ 1 - 0
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