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

(cherry picked from commit 4700831fa0f2dc52e296ce647711b03d1406497a)

Daniel-Constantin Mierla authored on 25/01/2015 09:57:00
Showing 4 changed files
... ...
@@ -2498,6 +2498,24 @@ try_again:
2498 2498
 	if (real_time&4)
2499 2499
 			set_rt_prio(rt_prio, rt_policy);
2500 2500
 
2501
+#ifdef USE_TCP
2502
+#ifdef USE_TLS
2503
+	if (!tls_disable){
2504
+		if (!tls_loaded()){
2505
+			LM_WARN("tls support enabled, but no tls engine "
2506
+						" available (forgot to load the tls module?)\n");
2507
+			LM_WARN("disabling tls...\n");
2508
+			tls_disable=1;
2509
+		} else {
2510
+			LM_DBG("=============================\n");
2511
+			if (pre_init_tls()<0){
2512
+				LM_CRIT("could not pre-initialize tls, exiting...\n");
2513
+				goto error;
2514
+			}
2515
+		}
2516
+	}
2517
+#endif /* USE_TLS */
2518
+#endif /* USE_TCP */
2501 2519
 	
2502 2520
 	if (init_modules() != 0) {
2503 2521
 		fprintf(stderr, "ERROR: error while initializing modules\n");
... ...
@@ -37,7 +37,7 @@
37 37
 
38 38
 #ifdef TLS_HOOKS
39 39
 
40
-struct tls_hooks tls_hook= {0, 0, 0, 0, 0 ,0 ,0};
40
+struct tls_hooks tls_hook= {0,0,0,0,0,0,0,0};
41 41
 
42 42
 static int tls_hooks_loaded=0;
43 43
 
... ...
@@ -71,6 +71,13 @@ int init_tls()
71 71
 	return 0;
72 72
 }
73 73
 
74
+int pre_init_tls()
75
+{
76
+	if (tls_hook.pre_init)
77
+		return tls_hook.pre_init();
78
+	return 0;
79
+}
80
+
74 81
 void destroy_tls()
75 82
 {
76 83
 	if (tls_hook.destroy)
... ...
@@ -74,15 +74,18 @@ struct tls_hooks{
74 74
 	void (*tcpconn_clean)(struct tcp_connection* c);
75 75
 	void (*tcpconn_close)(struct tcp_connection*c , int fd);
76 76
 	
77
-	/* per listening socket init, called on ser startup (after modules,
77
+	/* per listening socket init, called on kamailio startup (after modules,
78 78
 	 *  process table, init() and udp socket initialization)*/
79 79
 	int (*init_si)(struct socket_info* si);
80
-	/* generic init function (called at ser init, after module initialization
80
+	/* generic init function (called at kamailio init, after module initialization
81 81
 	 *  and process table creation)*/
82 82
 	int (*init)(void);
83 83
 	/* destroy function, called after the modules are destroyed, and 
84 84
 	 * after  destroy_tcp() */
85 85
 	void (*destroy)(void);
86
+	/* generic pre-init function (called at kamailio start, before module
87
+	 * initialization (after modparams) */
88
+	int (*pre_init)(void);
86 89
 };
87 90
 
88 91
 
... ...
@@ -53,6 +53,7 @@ int tls_has_init_si(void); /*returns true if a handle for tls_init is registered
53 53
 int tls_init(struct socket_info* si);
54 54
 int init_tls(void);
55 55
 void destroy_tls(void);
56
+int pre_init_tls(void);
56 57
 
57 58
 #endif /* TLS_HOOKS */
58 59
 #endif