#include "../../dprint.h"
#include "../../parser/parser_f.h"
#include "../../parser/parse_from.h"
#include "../../ut.h"
#include "../../timer.h"
#include "../../hash_func.h"
#include "../../forward.h"
#include "t_funcs.h"
#include "config.h"
#include "sip_msg.h"
#include "t_hooks.h"
#include "t_lookup.h"
#include "dlg.h"
#include "t_msgbuilder.h"
#include "t_fwd.h"

Go to the source code of this file.
Defines | |
| #define | EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len) |
| #define | EQ_REQ_URI_LEN (p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len) |
| #define | EQ_REQ_URI_STR |
| #define | EQ_STR(_hf) |
| #define | EQ_STRS(_s1, _s2) ( (_s1).len==(_s2).len && memcmp((_s1).s,(_s2).s,(_s2).len)==0) |
| #define | EQ_VIA_LEN(_via) |
| #define | EQ_VIA_STR(_via) |
| #define | HF_LEN(_hf) ((_hf)->len) |
Functions | |
| static int | ack_matching (struct cell *p_cell, struct sip_msg *p_msg) |
| ACK matching. | |
| static int | dlg_matching (struct cell *p_cell, struct sip_msg *ack) |
| Dialog matching. | |
| struct cell * | get_cancelled_t (void) |
| struct cell * | get_e2eack_t (void) |
| struct cell * | get_t (void) |
| static void | init_new_t (struct cell *new_cell, struct sip_msg *p_msg) |
| Initialize a new transaction for a message. | |
| int | init_rb (struct retr_buf *rb, struct sip_msg *msg) |
| void | init_t (void) |
| static int | matching_3261 (struct sip_msg *p_msg, struct cell **trans, enum request_method skip_method) |
| Transaction matching a-la RFC-3261 using transaction ID in branch. | |
| static int | new_t (struct sip_msg *p_msg) |
| Create a new transaction. | |
| static int | parse_dlg (struct sip_msg *msg) |
| Parse necessary dialog related headers in the SIP message. | |
| static int | partial_dlg_matching (struct sip_msg *t_msg, struct sip_msg *p_msg) |
| Partial dialog matching for two SIP messages. | |
| void | reset_cancelled_t (void) |
| void | reset_e2eack_t (void) |
| void | set_t (struct cell *t) |
| int | t_check (struct sip_msg *p_msg, int *param_branch) |
| Determine current transaction. | |
| int | t_get_trans_ident (struct sip_msg *p_msg, unsigned int *hash_index, unsigned int *label) |
| Get transaction identifier. | |
| int | t_is_local (struct sip_msg *p_msg) |
| Small wrapper around is_local. | |
| int | t_lookup_callid (struct cell **trans, str callid, str cseq) |
| Lookup a transaction by callid and cseq. | |
| int | t_lookup_ident (struct cell **trans, unsigned int hash_index, unsigned int label) |
| Lookup a transaction from a hash identifier. | |
| int | t_lookup_request (struct sip_msg *p_msg, int leave_new_locked) |
| Lookup request. | |
| struct cell * | t_lookupOriginalT (struct sip_msg *p_msg) |
| Lookups transaction being canceled by CANCEL in p_msg. | |
| int | t_newtran (struct sip_msg *p_msg) |
| Atomic "new_tran" construct. | |
| int | t_reply_matching (struct sip_msg *p_msg, int *p_branch) |
| Reply matching. | |
| int | t_unref (struct sip_msg *p_msg) |
| Unreference a transaction, release it if necessary. | |
| void | t_unref_cell (struct cell *c) |
| static int | via_matching (struct via_body *inv_via, struct via_body *ack_via) |
| Branch-based transaction matching. | |
Variables | |
| static struct cell * | cancelled_T |
| static struct cell * | e2eack_T |
| int | ruri_matching = 1 |
| static struct cell * | T |
| int | via1_matching = 1 |
This C-file takes care of matching requests and replies with existing transactions. Note that we do not do SIP-compliant request matching as asked by SIP spec. We do bitwise matching of all header fields in requests which form a transaction key. It is much faster and it works pretty well -- we haven't had any interop issue neither in lab nor in bake-offs. The reason is that retransmissions do look same as original requests (it would be really silly if they would be mangled). The only exception is we parse To as To in ACK is compared to To in reply and both of them are constructed by different software.
As for reply matching, we match based on branch value -- that is faster too. There are two versions .. with SYNONYMs define enabled, the branch includes ordinal number of a transaction in a synonym list in hash table and is somewhat faster but not reboot-resilient. SYNONYMs turned off are little slower but work across reboots as well.
The branch parameter is formed as follows: SYNONYMS on: hash.synonym.branch SYNONYMS off: hash.md5.branch
Definition in file t_lookup.c.
Definition at line 105 of file t_lookup.c.
Referenced by partial_dlg_matching(), t_lookup_request(), and t_lookupOriginalT().
| #define EQ_REQ_URI_LEN (p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len) |
Definition at line 106 of file t_lookup.c.
Referenced by t_lookup_request(), and t_lookupOriginalT().
| #define EQ_REQ_URI_STR |
Value:
( memcmp( t_msg->first_line.u.request.uri.s,\ p_msg->first_line.u.request.uri.s,\ p_msg->first_line.u.request.uri.len)==0)
Definition at line 112 of file t_lookup.c.
Referenced by t_lookup_request(), and t_lookupOriginalT().
| #define EQ_STR | ( | _hf | ) |
Value:
(memcmp(t_msg->_hf->body.s,\ p_msg->_hf->body.s, \ p_msg->_hf->body.len)==0)
Definition at line 109 of file t_lookup.c.
Referenced by partial_dlg_matching(), t_lookup_request(), and t_lookupOriginalT().
| #define EQ_VIA_LEN | ( | _via | ) |
Value:
( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
Definition at line 99 of file t_lookup.c.
Referenced by t_lookup_request(), and t_lookupOriginalT().
| #define EQ_VIA_STR | ( | _via | ) |
Value:
( memcmp( t_msg->_via->name.s,\
p_msg->_via->name.s,\
(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
)==0 )
Definition at line 116 of file t_lookup.c.
Referenced by t_lookup_request(), and t_lookupOriginalT().
| #define HF_LEN | ( | _hf | ) | ((_hf)->len) |
ACK matching.
| p_cell | transaction | |
| p_msg | checked SIP message |
Definition at line 257 of file t_lookup.c.
References dlg_matching(), partial_dlg_matching(), cell::relayed_reply_branch, ua_server::request, and cell::uas.
Referenced by matching_3261().
Dialog matching.
Dialog matching, are to-tags in ACK/200 same as those we sent out?
| p_cell | transaction with the TO tag | |
| ack | checked SIP message |
Definition at line 242 of file t_lookup.c.
References get_to, _str::len, ua_server::local_totag, _str::s, to_body::tag_value, and cell::uas.
Referenced by ack_matching(), and t_lookup_request().
| struct cell* get_cancelled_t | ( | void | ) | [read] |
| struct cell* get_e2eack_t | ( | void | ) | [read] |
| struct cell* get_t | ( | void | ) | [read] |
Definition at line 161 of file t_lookup.c.
Referenced by add_blind_uac(), faked_env(), load_tm(), pv_get_tm_reply_code(), pv_t_update_req(), pv_t_update_rpl(), register_tmcb(), reply_received(), run_reqin_callbacks(), run_trans_callbacks(), t_cancel_branches(), t_check_status(), t_check_trans(), t_flush_flags(), t_get_trans_ident(), t_is_local(), t_load_contacts(), t_local_replied(), t_next_contacts(), t_on_branch(), t_on_negative(), t_on_reply(), t_relay_to(), t_was_cancelled(), w_t_relay(), w_t_release(), and w_t_reply().
Initialize a new transaction for a message.
Initialize a new transaction for a message in shared memory.
| new_cell | new transaction | |
| p_msg | SIP message |
Definition at line 1020 of file t_lookup.c.
References sip_msg::callid, cell::callid, sip_msg::cseq, cell::cseq_n, sip_msg::first_line, cell::flags, sip_msg::from, cell::from, get_cseq, get_on_branch(), get_on_negative(), get_on_reply(), HF_LEN, _str::len, cell::method, METHOD_INVITE, hdr_field::name, cell::on_branch, cell::on_negative, cell::on_reply, msg_start::request, ua_server::request, _str::s, T_IS_INVITE_FLAG, sip_msg::to, cell::to, msg_start::u, and cell::uas.
Referenced by new_t().
Definition at line 986 of file t_lookup.c.
References receive_info::bind_address, retr_buf::dst, E_BAD_VIA, via_body::host, _str::len, LM_ERR, dest_info::proto, receive_info::proto, via_body::proto, receive_info::proto_reserved1, dest_info::proto_reserved1, sip_msg::rcv, reply_to_via, _str::s, dest_info::send_sock, ser_error, dest_info::to, update_sock_struct_from_ip, update_sock_struct_from_via(), and sip_msg::via1.
Referenced by t_newtran().
| void init_t | ( | void | ) |
Definition at line 164 of file t_lookup.c.
References set_t(), and T_UNDEFINED.
Referenced by mod_init().
| static int matching_3261 | ( | struct sip_msg * | p_msg, | |
| struct cell ** | trans, | |||
| enum request_method | skip_method | |||
| ) | [static] |
Transaction matching a-la RFC-3261 using transaction ID in branch.
Transaction matching a-la RFC-3261 using transaction ID in branch. The function assumes there is magic cookie in branch
| p_msg | SIP message | |
| trans | transaction | |
| skip_method | SIP message method for skipping? |
Definition at line 326 of file t_lookup.c.
References ack_matching(), via_body::branch, get_tm_table(), sip_msg::hash_index, _str::len, LM_DBG, LM_ERR, MCOOKIE_LEN, METHOD_ACK, cell::next_cell, parse_dlg(), ua_server::request, _str::s, ua_server::status, via_body::tid, cell::uas, via_param::value, sip_msg::via1, and via_matching().
Referenced by t_lookup_request(), and t_lookupOriginalT().
| static int new_t | ( | struct sip_msg * | p_msg | ) | [inline, static] |
Create a new transaction.
Definition at line 1048 of file t_lookup.c.
References build_cell(), E_BAD_REQ, E_OUT_OF_MEM, sip_msg::hash_index, init_new_t(), INIT_REF_UNSAFE, insert_into_hash_table_unsafe(), LM_ERR, METHOD_INVITE, parse_from_header(), parse_sip_msg_uri(), and set_t().
Referenced by t_newtran().
| static int parse_dlg | ( | struct sip_msg * | msg | ) | [inline, static] |
Parse necessary dialog related headers in the SIP message.
| msg | SIP message |
Definition at line 178 of file t_lookup.c.
References sip_msg::cseq, sip_msg::from, HDR_CSEQ_F, HDR_FROM_F, HDR_TO_F, LM_ERR, parse_from_header(), parse_headers(), and sip_msg::to.
Referenced by matching_3261().
Partial dialog matching for two SIP messages.
Partial dialog matching in two SIP messages. Is the ACK (p_msg) in p_msg dialog-wise equal to the INVITE (t_msg) except to-tags?
| t_msg | first SIP message with INVITE | |
| p_msg | second SIP message with ACK |
Definition at line 208 of file t_lookup.c.
References EQ_LEN, EQ_STR, get_cseq, get_from, _str::len, LM_ERR, _str::s, and to_body::tag_value.
Referenced by ack_matching().
| void reset_cancelled_t | ( | void | ) |
| void reset_e2eack_t | ( | void | ) |
| void set_t | ( | struct cell * | t | ) |
Definition at line 162 of file t_lookup.c.
Referenced by faked_env(), init_t(), new_t(), reply_received(), run_reqin_callbacks(), run_trans_callbacks(), script_init(), t_check_trans(), t_lookup_callid(), t_lookup_ident(), t_lookup_request(), t_reply_matching(), and t_unref().
| int t_check | ( | struct sip_msg * | p_msg, | |
| int * | param_branch | |||
| ) |
Determine current transaction.
Determine current transaction for SIP message. Set T to a ptr if the transaction could be found, to 0 if not found, and to T_UNDEFINED on errors: Found Not Found Error (e.g. parsing) Return Value 1 0 -1 T ptr 0 T_UNDEFINED
Definition at line 919 of file t_lookup.c.
References sip_msg::cseq, sip_msg::first_line, get_cseq, HDR_CSEQ_F, HDR_EOH_F, HDR_TO_F, HDR_VIA1_F, LM_DBG, LM_ERR, cseq_body::method_id, METHOD_INVITE, parse_from_header(), parse_headers(), SIP_REQUEST, t_lookup_request(), t_reply_matching(), T_UNDEFINED, sip_msg::to, msg_start::type, and sip_msg::via1.
Referenced by pv_get_tm_reply_code(), pv_t_update_req(), reply_received(), t_check_trans(), t_get_trans_ident(), and t_is_local().
| int t_get_trans_ident | ( | struct sip_msg * | p_msg, | |
| unsigned int * | hash_index, | |||
| unsigned int * | label | |||
| ) |
Get transaction identifier.
Definition at line 1244 of file t_lookup.c.
References get_t(), cell::hash_index, cell::label, LM_ERR, and t_check().
Referenced by assemble_msg(), and load_tm().
| int t_is_local | ( | struct sip_msg * | p_msg | ) |
Lookup a transaction by callid and cseq.
Lookup a transaction by callid and cseq, parameters are pure header field content only, e.g. "123@10.0.0.1" and "11"
| trans | transaction | |
| callid | Call-Id value | |
| cseq | CSEQ value |
Definition at line 1336 of file t_lookup.c.
References cell::callid, cell::cseq_n, s_table::entrys, entry::first_cell, get_tm_table(), cell::hash_index, INVITE, INVITE_LEN, _str::len, LM_DBG, LM_ERR, LOCK_HASH, MAX_HEADER, cell::next_cell, print_callid_mini(), print_cseq_mini(), REF_UNSAFE, _str::s, set_t(), tm_hash, TM_TABLE_ENTRIES, and UNLOCK_HASH.
Referenced by mi_tm_cancel().
| int t_lookup_ident | ( | struct cell ** | trans, | |
| unsigned int | hash_index, | |||
| unsigned int | label | |||
| ) |
Lookup a transaction from a hash identifier.
Definition at line 1269 of file t_lookup.c.
References get_tm_table(), cell::label, LM_DBG, LM_ERR, LOCK_HASH, cell::next_cell, REF_UNSAFE, set_t(), TM_TABLE_ENTRIES, and UNLOCK_HASH.
Referenced by load_tm(), mi_tm_reply(), and t_uac_cancel().
| int t_lookup_request | ( | struct sip_msg * | p_msg, | |
| int | leave_new_locked | |||
| ) |
Lookup request.
Definition at line 417 of file t_lookup.c.
References hdr_field::body, via_body::branch, cell::callid, sip_msg::callid, check_transaction_quadruple(), dlg_matching(), EQ_LEN, EQ_REQ_URI_LEN, EQ_REQ_URI_STR, EQ_STR, EQ_VIA_LEN, EQ_VIA_STR, cell::flags, cell::from, get_cseq, get_tm_table(), get_to, sip_msg::hash_index, _str::len, LM_DBG, LM_ERR, LOCK_HASH, matching_3261(), MCOOKIE, MCOOKIE_LEN, METHOD_ACK, METHOD_INVITE, cell::next_cell, cell::nr_of_outgoings, NULL, REF_UNSAFE, cell::relayed_reply_branch, REQ_EXIST, ua_server::request, ruri_matching, _str::s, set_kr(), set_t(), ua_server::status, T_BLIND_UAC, t_release_transaction(), T_UNDEFINED, tm_hash, cell::to, cell::uas, UNLOCK_HASH, via_param::value, sip_msg::via1, and via1_matching.
Referenced by pv_t_update_rpl(), t_check(), t_check_trans(), and t_newtran().
Lookups transaction being canceled by CANCEL in p_msg.
Lookups transaction from hash table that is being canceled by the CANCEL in the message.
| p_msg | SIP message with CANCEL |
Definition at line 628 of file t_lookup.c.
References via_body::branch, EQ_LEN, EQ_REQ_URI_LEN, EQ_REQ_URI_STR, EQ_STR, EQ_VIA_LEN, EQ_VIA_STR, get_cseq, get_tm_table(), get_to, sip_msg::hash_index, cell::hash_index, _str::len, LM_DBG, LM_ERR, LOCK_HASH, matching_3261(), MCOOKIE, MCOOKIE_LEN, METHOD_CANCEL, cell::next_cell, NULL, REF_UNSAFE, ua_server::request, ruri_matching, _str::s, T_UNDEFINED, cell::uas, UNLOCK_HASH, via_param::value, sip_msg::via1, and via1_matching.
Referenced by load_tm(), t_check_trans(), and t_forward_nonack().
| int t_newtran | ( | struct sip_msg * | p_msg | ) |
Atomic "new_tran" construct.
Definition at line 1088 of file t_lookup.c.
References sip_msg::add_to_branch_len, sip_msg::add_to_branch_s, check_hdrs_changes(), E_BAD_REQ, E_BAD_TUPEL, E_BAD_VIA, E_OUT_OF_MEM, E_SCRIPT, has_tran_tmcbs, sip_msg::hash_index, HDR_EOH_F, init_rb(), LM_DBG, LM_ERR, METHOD_ACK, new_t(), cell::nr_of_outgoings, parse_headers(), sip_msg::parsed_flag, put_on_wait(), ua_server::response, run_trans_callbacks(), t_calc_branch(), t_lookup_request(), t_release_transaction(), t_retransmit_reply(), T_UNDEFINED, t_unref(), TMCB_E2EACK_IN, cell::uas, UNLOCK_HASH, and unmatched_totag().
Referenced by load_tm(), t_relay_to(), and w_t_newtran().
| int t_reply_matching | ( | struct sip_msg * | p_msg, | |
| int * | p_branch | |||
| ) |
Reply matching.
Definition at line 753 of file t_lookup.c.
References via_body::branch, BRANCH_SEPARATOR, retr_buf::buffer, eat_token2_end(), eat_token_end(), EQ_STRS, get_cseq, get_tm_table(), has_tran_tmcbs, cell::hash_index, HDR_TO_F, is_invite, is_local, cell::label, _str::len, LM_DBG, LM_ERR, ua_client::local_cancel, LOCK_HASH, MAX_BRANCHES, MCOOKIE, MCOOKIE_LEN, cell::md5, MD5_LEN, cell::method, cseq_body::method, METHOD_CANCEL, cseq_body::method_id, METHOD_OTHER, cell::next_cell, cell::nr_of_outgoings, NULL, parse_headers(), REF_UNSAFE, REQ_LINE, ua_server::request, reverse_hex2int(), run_trans_callbacks(), _str::s, set_t(), syn_branch, TM_TABLE_ENTRIES, TMCB_E2EACK_IN, TMCB_LOCAL_COMPLETED, TMCB_RESPONSE_IN, TMCB_RESPONSE_OUT, TMCB_RESPONSE_PRE_OUT, cell::uac, cell::uas, UNLOCK_HASH, via_param::value, and sip_msg::via1.
Referenced by t_check().
| int t_unref | ( | struct sip_msg * | p_msg | ) |
Unreference a transaction, release it if necessary.
Definition at line 1212 of file t_lookup.c.
References sip_msg::first_line, get_kr(), kr, LM_WARN, METHOD_ACK, REQ_RLSD, set_t(), SIP_REQUEST, T_NULL_CELL, t_release_transaction(), T_UNDEFINED, msg_start::type, and UNREF.
Referenced by do_t_unref(), reply_received(), and t_newtran().
| void t_unref_cell | ( | struct cell * | c | ) |
Definition at line 1234 of file t_lookup.c.
References UNREF.
Referenced by do_t_unref(), and load_tm().
Branch-based transaction matching.
| inv_via | VIA body | |
| ack_via | VIA from ACK |
Definition at line 286 of file t_lookup.c.
References via_body::host, _str::len, via_body::port, _str::s, via_body::tid, and via_body::transport.
Referenced by matching_3261().
struct cell* cancelled_T [static] |
Simillar to T, but it is used for the cancelled invite transaction (when processing a CANCEL)
Definition at line 151 of file t_lookup.c.
Simillar to T, but it is used for the ack-ed invite transaction (when processing a end-to-end 200 ACK )
Definition at line 157 of file t_lookup.c.
| int ruri_matching = 1 |
Should be request-uri matching used as a part of pre-3261 transaction matching, as the standard wants us to do so (and is reasonable to do so, to be able to distinguish spirals)? Turn only off for better interaction with devices that are broken and send different r-uri in CANCEL/ACK than in original INVITE
Definition at line 135 of file t_lookup.c.
Referenced by t_lookup_request(), and t_lookupOriginalT().
This is a global variable which keeps a pointer to the transaction currently processed by a process; it is set by t_lookup_request or t_reply_matching; don't dare to change it anywhere else as it would break ref_counting
Definition at line 145 of file t_lookup.c.
| int via1_matching = 1 |
Definition at line 136 of file t_lookup.c.
Referenced by t_lookup_request(), and t_lookupOriginalT().
1.5.6