diff options
author | George Joseph <gjoseph@digium.com> | 2017-03-07 07:33:26 -0700 |
---|---|---|
committer | George Joseph <gjoseph@digium.com> | 2017-03-16 09:49:07 -0600 |
commit | 5013d8f5d31153c243e4a426bd0720e08be3ddc4 (patch) | |
tree | 0054aa7e9620fd4cba35a0b599a430e510474096 /include/asterisk/res_pjsip.h | |
parent | 84f0871cba30a9f3562f01fd347c6674d9058aad (diff) |
res_pjsip: Symmetric transports
A new transport parameter 'symmetric_transport' has been added.
When a request from a dynamic contact comes in on a transport with
this option set to 'yes', the transport name will be saved and used
for subsequent outgoing requests like OPTIONS, NOTIFY and INVITE.
It's saved as a contact uri parameter named 'x-ast-txp' and will
display with the contact uri in CLI, AMI, and ARI output. On the
outgoing request, if a transport wasn't explicitly set on the
endpoint AND the request URI is not a hostname, the saved transport
will be used and the 'x-ast-txp' parameter stripped from the
outgoing packet.
* config_transport was modified to accept and store the new parameter.
* config_transport/transport_apply was updated to store the transport
name in the pjsip_transport->info field using the pjsip_transport->pool
on UDP transports.
* A 'multihomed_on_rx_message' function was added to
pjsip_message_ip_updater that, for incoming requests, retrieves the
transport name from pjsip_transport->info and retrieves the transport.
If transport->symmetric_transport is set, an 'x-ast-txp' uri parameter
containing the transport name is added to the incoming Contact header.
* An 'ast_sip_get_transport_name' function was added to res_pjsip.
It takes an ast_sip_endpoint and a pjsip_sip_uri and returns a
transport name if endpoint->transport is set or if there's an
'x-ast-txp' parameter on the uri and the uri host is an ipv4 or
ipv6 address. Otherwise it returns NULL.
* An 'ast_sip_dlg_set_transport' function was added to res_pjsip
which takes an ast_sip_endpoint, a pjsip_dialog, and an optional
pjsip_tpselector. It calls ast_sip_get_transport_name() and if
a non-NULL is returned, sets the selector and sets the transport
on the dialog. If a selector was passed in, it's updated.
* res_pjsip/ast_sip_create_dialog_uac and ast_sip_create_dialog_uas
were modified to call ast_sip_dlg_set_transport() instead of their
original logic.
* res_pjsip/create_out_of_dialog_request was modified to call
ast_sip_get_transport_name() and pjsip_tx_data_set_transport()
instead of its original logic.
* Existing transport logic was removed from endpt_send_request
since that can only be called after a create_out_of_dialog_request.
* res_pjsip/ast_sip_create_rdata was converted to a wrapper around
a new 'ast_sip_create_rdata_with_contact' function which allows
a contact_uri to be specified in addition to the existing
parameters. (See below)
* res_pjsip_pubsub/internal_pjsip_evsub_send_request was eliminated
since all it did was transport selection and that is now done in
ast_sip_create_dialog_uac and ast_sip_create_dialog_uas.
* 'contact_uri' was added to subscription_persistence. This was
necessary because although the parsed rdata contact header has the
x-ast-txp parameter added (if appropriate),
subscription_persistence_update stores the raw packet which
doesn't have it. subscription_persistence_recreate was then
updated to call ast_sip_create_rdata_with_contact with the
persisted contact_uri so the recreated subscription has the
correct transport info to send the NOTIFYs.
* res_pjsip_session/internal_pjsip_inv_send_msg was eliminated since
all it did was transport selection and that is now done in
ast_sip_create_dialog_uac.
* pjsip_message_ip_updater/multihomed_on_tx_message was updated
to remove all traces of the x-ast-txp parameter from the
outgoing headers.
NOTE: This change does NOT modify the behavior of permanent
contacts specified on an aor. To do so would require that the
permanent contact's contact uri be updated with the x-ast-txp
parameter and the aor sorcery object updated. If we need to
persue this, we need to think about cloning permanent contacts into
the same store as the dynamic ones on an aor load so they can be
updated without disturbing the originally configured value.
You CAN add the x-ast-txp parameter to a permanent contact's uri
but it would be much simpler to just set endpoint->transport.
Change-Id: I4ee1f51473da32ca54b877cd158523efcef9655f
Diffstat (limited to 'include/asterisk/res_pjsip.h')
-rw-r--r-- | include/asterisk/res_pjsip.h | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index fb0451307..c6c308bee 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -194,6 +194,8 @@ struct ast_sip_transport { int write_timeout; /*! Allow reload */ int allow_reload; + /*! Automatically send requests out the same transport requests have come in on */ + int symmetric_transport; }; #define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias" @@ -765,6 +767,10 @@ struct ast_sip_endpoint { unsigned int asymmetric_rtp_codec; }; +/*! URI parameter for symmetric transport */ +#define AST_SIP_X_AST_TXP "x-ast-txp" +#define AST_SIP_X_AST_TXP_LEN 9 + /*! * \brief Initialize an auth vector with the configured values. * @@ -1659,6 +1665,26 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, /*! * \brief General purpose method for creating an rdata structure using specific information + * \since 13.15.0 + * + * \param rdata[out] The rdata structure that will be populated + * \param packet A SIP message + * \param src_name The source IP address of the message + * \param src_port The source port of the message + * \param transport_type The type of transport the message was received on + * \param local_name The local IP address the message was received on + * \param local_port The local port the message was received on + * \param contact_uri The contact URI of the message + * + * \retval 0 success + * \retval -1 failure + */ +int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet, + const char *src_name, int src_port, char *transport_type, const char *local_name, + int local_port, const char *contact_uri); + +/*! + * \brief General purpose method for creating an rdata structure using specific information * * \param rdata[out] The rdata structure that will be populated * \param packet A SIP message @@ -1671,8 +1697,8 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, * \retval 0 success * \retval -1 failure */ -int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, char *transport_type, - const char *local_name, int local_port); +int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, + int src_port, char *transport_type, const char *local_name, int local_port); /*! * \brief General purpose method for creating a SIP request @@ -2709,4 +2735,54 @@ void ast_sip_modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr, void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period, unsigned int *prune_interval); +/*! + * \brief Get the transport name from an endpoint or request uri + * \since 13.15.0 + * + * \param endpoint + * \param sip_uri + * \param buf Buffer to receive transport name + * \param buf_len Buffer length + * + * \retval 0 Success + * \retval -1 Failure + * + * \note + * If endpoint->transport is not NULL, it is returned in buf. + * Otherwise if sip_uri has an 'x-ast-txp' parameter AND the sip_uri host is + * an ip4 or ip6 address, its value is returned, + */ +int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint, + pjsip_sip_uri *sip_uri, char *buf, size_t buf_len); + +/*! + * \brief Sets pjsip_tpselector from an endpoint or uri + * \since 13.15.0 + * + * \param endpoint If endpoint->transport is set, it's used + * \param sip_uri If sip_uri contains a x-ast-txp parameter, it's used + * \param selector The selector to be populated + * + * \retval 0 success + * \retval -1 failure + */ +int ast_sip_set_tpselector_from_ep_or_uri(const struct ast_sip_endpoint *endpoint, + pjsip_sip_uri *sip_uri, pjsip_tpselector *selector); + +/*! + * \brief Set the transport on a dialog + * \since 13.15.0 + * + * \param endpoint + * \param dlg + * \param selector (optional) + * + * \note + * This API calls ast_sip_get_transport_name(endpoint, dlg->target) and if the result is + * non-NULL, calls pjsip_dlg_set_transport. If 'selector' is non-NULL, it is updated with + * the selector used. + */ +int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg, + pjsip_tpselector *selector); + #endif /* _RES_PJSIP_H */ |