summaryrefslogtreecommitdiff
path: root/res/res_pjsip
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2017-03-07 07:33:26 -0700
committerGeorge Joseph <gjoseph@digium.com>2017-03-16 09:49:07 -0600
commit5013d8f5d31153c243e4a426bd0720e08be3ddc4 (patch)
tree0054aa7e9620fd4cba35a0b599a430e510474096 /res/res_pjsip
parent84f0871cba30a9f3562f01fd347c6674d9058aad (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 'res/res_pjsip')
-rw-r--r--res/res_pjsip/config_transport.c22
-rw-r--r--res/res_pjsip/pjsip_message_ip_updater.c83
2 files changed, 98 insertions, 7 deletions
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 60b4507cd..3c41f175a 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -552,13 +552,20 @@ static int transport_apply(const struct ast_sorcery *sorcery, void *obj)
}
}
- if (res == PJ_SUCCESS && (transport->tos || transport->cos)) {
- pj_sock_t sock;
- pj_qos_params qos_params;
- sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
- pj_sock_get_qos_params(sock, &qos_params);
- set_qos(transport, &qos_params);
- pj_sock_set_qos_params(sock, &qos_params);
+ if (res == PJ_SUCCESS) {
+ temp_state->state->transport->info = pj_pool_alloc(temp_state->state->transport->pool,
+ (AST_SIP_X_AST_TXP_LEN + strlen(transport_id) + 2));
+
+ sprintf(temp_state->state->transport->info, "%s:%s", AST_SIP_X_AST_TXP, transport_id);
+
+ if (transport->tos || transport->cos) {
+ pj_sock_t sock;
+ pj_qos_params qos_params;
+ sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
+ pj_sock_get_qos_params(sock, &qos_params);
+ set_qos(transport, &qos_params);
+ pj_sock_set_qos_params(sock, &qos_params);
+ }
}
} else if (transport->type == AST_TRANSPORT_TCP) {
pjsip_tcp_transport_cfg cfg;
@@ -1375,6 +1382,7 @@ int ast_sip_initialize_sorcery_transport(void)
ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
ast_sorcery_object_field_register(sorcery, "transport", "websocket_write_timeout", AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_transport, write_timeout), 1, INT_MAX);
ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
+ ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
internal_sip_register_endpoint_formatter(&endpoint_transport_formatter);
diff --git a/res/res_pjsip/pjsip_message_ip_updater.c b/res/res_pjsip/pjsip_message_ip_updater.c
index 7671ad0a7..864d898b3 100644
--- a/res/res_pjsip/pjsip_message_ip_updater.c
+++ b/res/res_pjsip/pjsip_message_ip_updater.c
@@ -28,6 +28,7 @@
#define MOD_DATA_RESTRICTIONS "restrictions"
static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata);
+static pj_bool_t multihomed_on_rx_message(pjsip_rx_data *rdata);
/*! \brief Outgoing message modification restrictions */
struct multihomed_message_restrictions {
@@ -41,6 +42,7 @@ static pjsip_module multihomed_module = {
.priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 1,
.on_tx_request = multihomed_on_tx_message,
.on_tx_response = multihomed_on_tx_message,
+ .on_rx_request = multihomed_on_rx_message,
};
/*! \brief Helper function to get (or allocate if not already present) restrictions on a message */
@@ -151,6 +153,44 @@ static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp)
return 0;
}
+static void sanitize_tdata(pjsip_tx_data *tdata)
+{
+ static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN };
+ pjsip_param *x_transport;
+ pjsip_sip_uri *uri;
+ pjsip_fromto_hdr *fromto;
+ pjsip_contact_hdr *contact;
+ pjsip_hdr *hdr;
+
+ if (tdata->msg->type == PJSIP_REQUEST_MSG) {
+ uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
+ x_transport = pjsip_param_find(&uri->other_param, &x_name);
+ if (x_transport) {
+ pj_list_erase(x_transport);
+ }
+ }
+
+ for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
+ if (hdr->type == PJSIP_H_TO || hdr->type == PJSIP_H_FROM) {
+ fromto = (pjsip_fromto_hdr *) hdr;
+ uri = pjsip_uri_get_uri(fromto->uri);
+ x_transport = pjsip_param_find(&uri->other_param, &x_name);
+ if (x_transport) {
+ pj_list_erase(x_transport);
+ }
+ } else if (hdr->type == PJSIP_H_CONTACT) {
+ contact = (pjsip_contact_hdr *) hdr;
+ uri = pjsip_uri_get_uri(contact->uri);
+ x_transport = pjsip_param_find(&uri->other_param, &x_name);
+ if (x_transport) {
+ pj_list_erase(x_transport);
+ }
+ }
+ }
+
+ pjsip_tx_data_invalidate_msg(tdata);
+}
+
static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
{
struct multihomed_message_restrictions *restrictions = ast_sip_mod_data_get(tdata->mod_data, multihomed_module.id, MOD_DATA_RESTRICTIONS);
@@ -159,6 +199,8 @@ static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
pjsip_via_hdr *via;
pjsip_fromto_hdr *from;
+ sanitize_tdata(tdata);
+
/* Use the destination information to determine what local interface this message will go out on */
pjsip_tpmgr_fla2_param_default(&prm);
prm.tp_type = tdata->tp_info.transport->key.type;
@@ -273,6 +315,47 @@ static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
return PJ_SUCCESS;
}
+static pj_bool_t multihomed_on_rx_message(pjsip_rx_data *rdata)
+{
+ pjsip_contact_hdr *contact;
+ pjsip_sip_uri *uri;
+ const char *transport_id;
+ struct ast_sip_transport *transport;
+ pjsip_param *x_transport;
+
+ if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG) {
+ return PJ_FALSE;
+ }
+
+ contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
+ if (!(contact && contact->uri
+ && ast_begins_with(rdata->tp_info.transport->info, AST_SIP_X_AST_TXP ":"))) {
+ return PJ_FALSE;
+ }
+
+ uri = pjsip_uri_get_uri(contact->uri);
+
+ transport_id = rdata->tp_info.transport->info + AST_SIP_X_AST_TXP_LEN + 1;
+ transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_id);
+
+ if (!(transport && transport->symmetric_transport)) {
+ return PJ_FALSE;
+ }
+
+ x_transport = PJ_POOL_ALLOC_T(rdata->tp_info.pool, pjsip_param);
+ x_transport->name = pj_strdup3(rdata->tp_info.pool, AST_SIP_X_AST_TXP);
+ x_transport->value = pj_strdup3(rdata->tp_info.pool, transport_id);
+
+ pj_list_insert_before(&uri->other_param, x_transport);
+
+ ast_debug(1, "Set transport '%s' on %.*s from %.*s:%d\n", transport_id,
+ (int)rdata->msg_info.msg->line.req.method.name.slen,
+ rdata->msg_info.msg->line.req.method.name.ptr,
+ (int)uri->host.slen, uri->host.ptr, uri->port);
+
+ return PJ_FALSE;
+}
+
void ast_res_pjsip_cleanup_message_ip_updater(void)
{
ast_sip_unregister_service(&multihomed_module);