mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-20 08:40:16 +00:00
pjsip: Update ACLs on named ACL changes.
This change extends the Sorcery API to allow a wizard to be told to explicitly reload objects or a specific object type even if the wizard believes that nothing has changed. This has been leveraged by res_pjsip and res_pjsip_acl to reload endpoints and PJSIP ACLs when a named ACL changes. ASTERISK-28697 Change-Id: Ib8fee9bd9dd490db635132c479127a4114c1ca0b
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
#include "asterisk/statsd.h"
|
||||
#include "asterisk/pbx.h"
|
||||
#include "asterisk/stream.h"
|
||||
#include "asterisk/stasis.h"
|
||||
#include "asterisk/security_events.h"
|
||||
|
||||
/*! \brief Number of buckets for persistent endpoint information */
|
||||
#define PERSISTENT_BUCKETS 53
|
||||
@@ -49,6 +51,8 @@ static struct ao2_container *persistent_endpoints;
|
||||
|
||||
static struct ast_sorcery *sip_sorcery;
|
||||
|
||||
static struct stasis_subscription *acl_change_sub;
|
||||
|
||||
/*! \brief Hashing function for persistent endpoint information */
|
||||
static int persistent_endpoint_hash(const void *obj, const int flags)
|
||||
{
|
||||
@@ -1787,6 +1791,16 @@ static void load_all_endpoints(void)
|
||||
ao2_cleanup(endpoints);
|
||||
}
|
||||
|
||||
static void acl_change_stasis_cb(void *data, struct stasis_subscription *sub,
|
||||
struct stasis_message *message)
|
||||
{
|
||||
if (stasis_message_type(message) != ast_named_acl_change_type()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ast_sorcery_force_reload_object(sip_sorcery, "endpoint");
|
||||
}
|
||||
|
||||
int ast_res_pjsip_initialize_configuration(void)
|
||||
{
|
||||
if (ast_manager_register_xml(AMI_SHOW_ENDPOINTS, EVENT_FLAG_SYSTEM, ami_show_endpoints) ||
|
||||
@@ -2007,6 +2021,10 @@ int ast_res_pjsip_initialize_configuration(void)
|
||||
|
||||
ast_sip_location_prune_boot_contacts();
|
||||
|
||||
acl_change_sub = stasis_subscribe(ast_security_topic(), acl_change_stasis_cb, NULL);
|
||||
stasis_subscription_accept_message_type(acl_change_sub, ast_named_acl_change_type());
|
||||
stasis_subscription_set_filter(acl_change_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2016,6 +2034,7 @@ void ast_res_pjsip_destroy_configuration(void)
|
||||
return;
|
||||
}
|
||||
|
||||
acl_change_sub = stasis_unsubscribe_and_join(acl_change_sub);
|
||||
ast_sip_destroy_sorcery_global();
|
||||
ast_sip_destroy_sorcery_location();
|
||||
ast_sip_destroy_sorcery_auth();
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include "asterisk/logger.h"
|
||||
#include "asterisk/sorcery.h"
|
||||
#include "asterisk/acl.h"
|
||||
#include "asterisk/stasis.h"
|
||||
#include "asterisk/security_events.h"
|
||||
|
||||
/*** DOCUMENTATION
|
||||
<configInfo name="res_pjsip_acl" language="en_US">
|
||||
@@ -114,6 +116,8 @@
|
||||
</configInfo>
|
||||
***/
|
||||
|
||||
static struct stasis_subscription *acl_change_sub;
|
||||
|
||||
static int apply_acl(pjsip_rx_data *rdata, struct ast_acl_list *acl)
|
||||
{
|
||||
struct ast_sockaddr addr;
|
||||
@@ -280,6 +284,16 @@ static void *acl_alloc(const char *name)
|
||||
return sip_acl;
|
||||
}
|
||||
|
||||
static void acl_change_stasis_cb(void *data, struct stasis_subscription *sub,
|
||||
struct stasis_message *message)
|
||||
{
|
||||
if (stasis_message_type(message) != ast_named_acl_change_type()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ast_sorcery_force_reload_object(ast_sip_get_sorcery(), SIP_SORCERY_ACL_TYPE);
|
||||
}
|
||||
|
||||
static int load_module(void)
|
||||
{
|
||||
ast_sorcery_apply_config(ast_sip_get_sorcery(), SIP_SORCERY_ACL_TYPE);
|
||||
@@ -304,12 +318,18 @@ static int load_module(void)
|
||||
|
||||
ast_sorcery_load_object(ast_sip_get_sorcery(), SIP_SORCERY_ACL_TYPE);
|
||||
|
||||
acl_change_sub = stasis_subscribe(ast_security_topic(), acl_change_stasis_cb, NULL);
|
||||
stasis_subscription_accept_message_type(acl_change_sub, ast_named_acl_change_type());
|
||||
stasis_subscription_set_filter(acl_change_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
|
||||
|
||||
ast_sip_register_service(&acl_module);
|
||||
|
||||
return AST_MODULE_LOAD_SUCCESS;
|
||||
}
|
||||
|
||||
static int unload_module(void)
|
||||
{
|
||||
acl_change_sub = stasis_unsubscribe_and_join(acl_change_sub);
|
||||
ast_sip_unregister_service(&acl_module);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ static struct ast_sorcery_wizard config_object_wizard = {
|
||||
.open = sorcery_config_open,
|
||||
.load = sorcery_config_load,
|
||||
.reload = sorcery_config_reload,
|
||||
.force_reload = sorcery_config_load,
|
||||
.retrieve_id = sorcery_config_retrieve_id,
|
||||
.retrieve_fields = sorcery_config_retrieve_fields,
|
||||
.retrieve_multiple = sorcery_config_retrieve_multiple,
|
||||
|
||||
Reference in New Issue
Block a user