Browse code

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 authored on 25/01/2015 09:57:00
Showing 4 changed files
... ...
@@ -2445,6 +2445,24 @@ try_again:
2445 2445
 	if (real_time&4)
2446 2446
 			set_rt_prio(rt_prio, rt_policy);
2447 2447
 
2448
+#ifdef USE_TCP
2449
+#ifdef USE_TLS
2450
+	if (!tls_disable){
2451
+		if (!tls_loaded()){
2452
+			LM_WARN("tls support enabled, but no tls engine "
2453
+						" available (forgot to load the tls module?)\n");
2454
+			LM_WARN("disabling tls...\n");
2455
+			tls_disable=1;
2456
+		} else {
2457
+			LM_DBG("=============================\n");
2458
+			if (pre_init_tls()<0){
2459
+				LM_CRIT("could not pre-initialize tls, exiting...\n");
2460
+				goto error;
2461
+			}
2462
+		}
2463
+	}
2464
+#endif /* USE_TLS */
2465
+#endif /* USE_TCP */
2448 2466
 	
2449 2467
 	if (init_modules() != 0) {
2450 2468
 		fprintf(stderr, "ERROR: error while initializing modules\n");
... ...
@@ -28,7 +28,7 @@
28 28
 
29 29
 #ifdef TLS_HOOKS
30 30
 
31
-struct tls_hooks tls_hook= {0, 0, 0, 0, 0 ,0 ,0};
31
+struct tls_hooks tls_hook= {0,0,0,0,0,0,0,0};
32 32
 
33 33
 static int tls_hooks_loaded=0;
34 34
 
... ...
@@ -62,6 +62,13 @@ int init_tls()
62 62
 	return 0;
63 63
 }
64 64
 
65
+int pre_init_tls()
66
+{
67
+	if (tls_hook.pre_init)
68
+		return tls_hook.pre_init();
69
+	return 0;
70
+}
71
+
65 72
 void destroy_tls()
66 73
 {
67 74
 	if (tls_hook.destroy)
... ...
@@ -64,15 +64,18 @@ struct tls_hooks{
64 64
 	void (*tcpconn_clean)(struct tcp_connection* c);
65 65
 	void (*tcpconn_close)(struct tcp_connection*c , int fd);
66 66
 	
67
-	/* per listening socket init, called on ser startup (after modules,
67
+	/* per listening socket init, called on kamailio startup (after modules,
68 68
 	 *  process table, init() and udp socket initialization)*/
69 69
 	int (*init_si)(struct socket_info* si);
70
-	/* generic init function (called at ser init, after module initialization
70
+	/* generic init function (called at kamailio init, after module initialization
71 71
 	 *  and process table creation)*/
72 72
 	int (*init)(void);
73 73
 	/* destroy function, called after the modules are destroyed, and 
74 74
 	 * after  destroy_tcp() */
75 75
 	void (*destroy)(void);
76
+	/* generic pre-init function (called at kamailio start, before module
77
+	 * initialization (after modparams) */
78
+	int (*pre_init)(void);
76 79
 };
77 80
 
78 81
 
... ...
@@ -44,6 +44,7 @@ int tls_has_init_si(void); /*returns true if a handle for tls_init is registered
44 44
 int tls_init(struct socket_info* si);
45 45
 int init_tls(void);
46 46
 void destroy_tls(void);
47
+int pre_init_tls(void);
47 48
 
48 49
 #endif /* TLS_HOOKS */
49 50
 #endif