[asterisk-commits] res hep {pjsip|rtcp}: Decline module loads if res hep had no... (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 8 17:17:38 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: res_hep_{pjsip|rtcp}: Decline module loads if res_hep had not loaded
......................................................................


res_hep_{pjsip|rtcp}: Decline module loads if res_hep had not loaded

A crash can occur in res_hep_pjsip or res_hep_rtcp if res_hep has not
loaded and does not have a configuration file. Previously when this
occurred, checks were put in to see if the configuration was loaded
successfully. While this is a good idea - and has been added to the
offending function in res_hep - the reality is res_hep_pjsip and
res_hep_rtcp have no business running if res_hep isn't also running.

As such, this patch also adds a function to res_hep that returns whether
or not it successfully loaded. Oddly enough, ast_module_check returns
"everything is peachy" even if a module declined its load - so it cannot
be solely relied on. res_hep_pjsip and res_hep_rtcp now also check this
function to see if they should continue to load; if it fails, they
decline their load as well.

ASTERISK-26096 #close

Change-Id: I007e535fcc2e51c2ca48534f48c5fc2ac38935ea
---
M include/asterisk/res_hep.h
M res/res_hep.c
M res/res_hep.exports.in
M res/res_hep_pjsip.c
M res/res_hep_rtcp.c
5 files changed, 30 insertions(+), 0 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Joshua Colp: Verified
  Matthew Fredrickson: Looks good to me, but someone else must approve



diff --git a/include/asterisk/res_hep.h b/include/asterisk/res_hep.h
index bd0129e..cfd213a 100644
--- a/include/asterisk/res_hep.h
+++ b/include/asterisk/res_hep.h
@@ -118,6 +118,14 @@
  */
 enum hep_uuid_type hepv3_get_uuid_type(void);
 
+/*!
+ * \brief Return whether or not we're currently loaded and active
+ *
+ * \retval 0 The module is not loaded
+ * \retval 1 The module is loaded
+ */
+int hepv3_is_loaded(void);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
diff --git a/res/res_hep.c b/res/res_hep.c
index 4520135..e79f2b6 100644
--- a/res/res_hep.c
+++ b/res/res_hep.c
@@ -409,9 +409,21 @@
 {
 	RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
 
+	if (!config) {
+		/* Well, that's unfortunate. Return something. */
+		return HEP_UUID_TYPE_CALL_ID;
+	}
+
 	return config->general->uuid_type;
 }
 
+int hepv3_is_loaded(void)
+{
+	RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
+
+	return (config != NULL) ? 1 : 0;
+}
+
 struct hepv3_capture_info *hepv3_create_capture_info(const void *payload, size_t len)
 {
 	struct hepv3_capture_info *info;
diff --git a/res/res_hep.exports.in b/res/res_hep.exports.in
index df0f2b4..e318ac9 100644
--- a/res/res_hep.exports.in
+++ b/res/res_hep.exports.in
@@ -3,6 +3,7 @@
 		LINKER_SYMBOL_PREFIX*hepv3_send_packet;
 		LINKER_SYMBOL_PREFIX*hepv3_create_capture_info;
 		LINKER_SYMBOL_PREFIX*hepv3_get_uuid_type;
+		LINKER_SYMBOL_PREFIX*hepv3_is_loaded;
 	local:
 		*;
 };
diff --git a/res/res_hep_pjsip.c b/res/res_hep_pjsip.c
index 0cc54c2..a3a93e9 100644
--- a/res/res_hep_pjsip.c
+++ b/res/res_hep_pjsip.c
@@ -210,6 +210,11 @@
 {
 	CHECK_PJSIP_MODULE_LOADED();
 
+	if (!ast_module_check("res_hep.so") || !hepv3_is_loaded()) {
+		ast_log(AST_LOG_WARNING, "res_hep is not loaded or running; declining module load\n");
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
 	ast_sip_register_service(&logging_module);
 	return AST_MODULE_LOAD_SUCCESS;
 }
diff --git a/res/res_hep_rtcp.c b/res/res_hep_rtcp.c
index 8643d4d..03db181 100644
--- a/res/res_hep_rtcp.c
+++ b/res/res_hep_rtcp.c
@@ -149,6 +149,10 @@
 
 static int load_module(void)
 {
+	if (!ast_module_check("res_hep.so") || !hepv3_is_loaded()) {
+		ast_log(AST_LOG_WARNING, "res_hep is not loaded or running; declining module load\n");
+		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	stasis_rtp_subscription = stasis_subscribe(ast_rtp_topic(),
 		rtp_topic_handler, NULL);

-- 
To view, visit https://gerrit.asterisk.org/2976
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I007e535fcc2e51c2ca48534f48c5fc2ac38935ea
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>



More information about the asterisk-commits mailing list