mirror of
https://github.com/asterisk/asterisk.git
synced 2026-06-09 03:45:27 +00:00
res_pjsip_maintenance: Add PJSIP endpoint maintenance mode
Introduces res_pjsip_maintenance, a loadable module that allows operators to place individual PJSIP endpoints into maintenance mode at runtime without unregistering or disabling them. While an endpoint is in maintenance mode: * New inbound INVITE and SUBSCRIBE dialogs are rejected with 503 Service Unavailable and a Retry-After: 300 header. * In-progress dialogs (re-INVITE, UPDATE, BYE, etc.) are unaffected and complete normally. * Outbound originations via Dial() or ARI originate are refused before any SIP session is created. State is held in-memory only and is cleared on module unload or Asterisk restart. This module was developed with AI assistance (Claude). All code has been reviewed and tested by the author, who takes full responsibility for the submission. CLI interface: pjsip set maintenance <on|off> <endpoint|all> pjsip show maintenance [endpoint] AMI interface: Action: PJSIPSetMaintenance Endpoint: <name>|all State: on|off Action: PJSIPShowMaintenance Endpoint: <name> (optional; omit to list all) Emits PJSIPMaintenanceStatus events per result, followed by PJSIPMaintenanceStatusComplete. State changes also emit an unsolicited PJSIPMaintenanceStatus event. To support outbound blocking, a new session_create callback is added to ast_sip_session_supplement. Supplements that set this callback are invoked at the start of ast_sip_session_create_outgoing() in res_pjsip_session, before any dialog or invite session resources are allocated. res_pjsip_maintenance registers itself as a session supplement and uses this callback to gate outbound session creation on a per-endpoint basis. MODULEINFO: <depend>pjproject</depend> <depend>res_pjsip</depend> <depend>res_pjsip_session</depend> UserNote: New module res_pjsip_maintenance adds runtime maintenance mode for PJSIP endpoints. Use "pjsip set maintenance <on|off> <endpoint|all>" to enable or disable, and "pjsip show maintenance" to list affected endpoints. AMI actions PJSIPSetMaintenance and PJSIPShowMaintenance provide programmatic access. No configuration file changes required. DeveloperNote: ast_sip_session_supplement gains a new optional callback - int (*session_create)(struct ast_sip_endpoint *endpoint, const char *destination). It is called from the global supplement list (not per-session) at the start of ast_sip_session_create_outgoing() via ast_sip_session_check_supplement_create(). Returning non-zero blocks the outgoing session. Modules that need to gate outbound SIP session creation should register a supplement with this callback set rather than hooking into chan_pjsip directly.
This commit is contained in:
committed by
github-actions[bot]
parent
ce9765032f
commit
b3728145b2
@@ -364,6 +364,31 @@ struct ast_sip_session_supplement {
|
||||
* Defaults to AST_SIP_SESSION_BEFORE_MEDIA
|
||||
*/
|
||||
enum ast_sip_session_response_priority response_priority;
|
||||
/*!
|
||||
* \brief Called before an outgoing session is created
|
||||
*
|
||||
* This is called before the session dialog is created and can be used to
|
||||
* block the creation of the session entirely. A non-zero return value
|
||||
* prevents the session from being created. The callback is called from
|
||||
* the global supplement list, not per-session, so the session does not
|
||||
* yet exist when this is called.
|
||||
*
|
||||
* \since 20.20.0
|
||||
* \since 22.10.0
|
||||
* \since 23.4.0
|
||||
*
|
||||
* \param endpoint The endpoint the outgoing session would be created for
|
||||
* \param contact The contact to use for the outgoing session, or NULL
|
||||
* \param location Name of the location to call, be it named location or explicit URI, or NULL
|
||||
* \param request_user Optional request user to place in the request URI, or NULL
|
||||
* \param req_topology The requested stream capabilities
|
||||
*
|
||||
* \retval non-zero Block session creation
|
||||
* \retval 0 Allow session creation
|
||||
*/
|
||||
int (*session_create)(struct ast_sip_endpoint *endpoint,
|
||||
struct ast_sip_contact *contact, const char *location,
|
||||
const char *request_user, struct ast_stream_topology *req_topology);
|
||||
};
|
||||
|
||||
enum ast_sip_session_sdp_stream_defer {
|
||||
@@ -625,6 +650,33 @@ void ast_sip_session_register_supplement_with_module(struct ast_module *module,
|
||||
*/
|
||||
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement);
|
||||
|
||||
/*!
|
||||
* \brief Check registered supplements for permission to create an outgoing session
|
||||
*
|
||||
* Iterates the global supplement list and calls any registered \c session_create
|
||||
* callbacks. The first callback to return a non-zero value stops the iteration
|
||||
* and causes this function to return -1, blocking the session creation.
|
||||
*
|
||||
* This is called at the beginning of ast_sip_session_create_outgoing() before
|
||||
* any dialog or invite session resources are allocated.
|
||||
*
|
||||
* \since 20.20.0
|
||||
* \since 22.10.0
|
||||
* \since 23.4.0
|
||||
*
|
||||
* \param endpoint The endpoint the outgoing session would be created for
|
||||
* \param contact The contact to use for the outgoing session, or NULL
|
||||
* \param location Name of the location to call, be it named location or explicit URI, or NULL
|
||||
* \param request_user Optional request user to place in the request URI, or NULL
|
||||
* \param req_topology The requested stream capabilities
|
||||
*
|
||||
* \retval 0 Session creation is allowed
|
||||
* \retval -1 Session creation is blocked by a supplement
|
||||
*/
|
||||
int ast_sip_session_check_supplement_create(struct ast_sip_endpoint *endpoint,
|
||||
struct ast_sip_contact *contact, const char *location,
|
||||
const char *request_user, struct ast_stream_topology *req_topology);
|
||||
|
||||
/*!
|
||||
* \brief Add supplements to a SIP session
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user