t_lookup.c File Reference

TM :: Transaction matching. More...

#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"

Include dependency graph for t_lookup.c:

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 cellget_cancelled_t (void)
struct cellget_e2eack_t (void)
struct cellget_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 cellt_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 cellcancelled_T
static struct celle2eack_T
int ruri_matching = 1
static struct cellT
int via1_matching = 1


Detailed Description

TM :: Transaction matching.

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.


Define Documentation

#define EQ_LEN ( _hf   )     (t_msg->_hf->body.len==p_msg->_hf->body.len)

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_STRS ( _s1,
_s2   )     ( (_s1).len==(_s2).len && memcmp((_s1).s,(_s2).s,(_s2).len)==0)

Definition at line 121 of file t_lookup.c.

Referenced by t_reply_matching().

#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)

Definition at line 125 of file t_lookup.c.

Referenced by init_new_t().


Function Documentation

static int ack_matching ( struct cell p_cell,
struct sip_msg p_msg 
) [inline, static]

ACK matching.

Parameters:
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().

static int dlg_matching ( struct cell p_cell,
struct sip_msg ack 
) [inline, static]

Dialog matching.

Dialog matching, are to-tags in ACK/200 same as those we sent out?

Parameters:
p_cell transaction with the TO tag
ack checked SIP message
Returns:
1 on success, zero on errors

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]

Definition at line 166 of file t_lookup.c.

Referenced by do_t_unref().

struct cell* get_e2eack_t ( void   )  [read]

Definition at line 169 of file t_lookup.c.

Referenced by do_t_unref().

struct cell* get_t ( void   )  [read]

static void init_new_t ( struct cell new_cell,
struct sip_msg p_msg 
) [inline, static]

Initialize a new transaction for a message.

Initialize a new transaction for a message in shared memory.

Parameters:
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().

int init_rb ( struct retr_buf rb,
struct sip_msg msg 
)

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

Parameters:
p_msg SIP message
trans transaction
skip_method SIP message method for skipping?
Returns:
2 if e2e ACK for a proxied transaction found, 1 if found (covers ACK for local UAS) 0 if not found (undefined transaction)

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.

Returns:
1 on success, negative on errors

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.

Parameters:
msg SIP message
Returns:
1 on success, 0 on errors

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().

static int partial_dlg_matching ( struct sip_msg t_msg,
struct sip_msg p_msg 
) [inline, static]

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?

Parameters:
t_msg first SIP message with INVITE
p_msg second SIP message with ACK
Returns:
1 on success, 0 on errors

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   ) 

Definition at line 167 of file t_lookup.c.

References T_UNDEFINED.

Referenced by script_init().

void reset_e2eack_t ( void   ) 

Definition at line 170 of file t_lookup.c.

References T_UNDEFINED.

Referenced by script_init().

void set_t ( struct cell t  ) 

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

Returns:
1 if transaction found, 0 if not found, -1 on errors (e.g. parsing)

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.

Returns:
1 on success, -1 if not found and on errors

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  ) 

Small wrapper around is_local.

Returns:
1 on success, -1 if transaction not found and on errors

Definition at line 1308 of file t_lookup.c.

References get_t(), is_local, LM_ERR, and t_check().

Referenced by load_tm().

int t_lookup_callid ( struct cell **  trans,
str  callid,
str  cseq 
)

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"

Parameters:
trans transaction
callid Call-Id value
cseq CSEQ value
Returns:
1 if transaction was found, -1 when not found and on errors

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.

Returns:
1 on success, -1 if not found, and on errors

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 
)

struct cell* t_lookupOriginalT ( struct sip_msg p_msg  )  [read]

Lookups transaction being canceled by CANCEL in p_msg.

Lookups transaction from hash table that is being canceled by the CANCEL in the message.

Parameters:
p_msg SIP message with CANCEL
Returns:
0 - transaction wasn't found, T - transaction found

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.

Returns:
negative on error, 1 if a request did not match a transaction
  • it that was an ack, the calling function shall forward statelessly
  • otherwise it means, a new transaction was introduced and the calling function shall reply/relay/whatever_appropriate 0 on retransmission

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 
)

int t_unref ( struct sip_msg p_msg  ) 

Unreference a transaction, release it if necessary.

Returns:
1 on success, -1 on errors

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().

static int via_matching ( struct via_body inv_via,
struct via_body ack_via 
) [inline, static]

Branch-based transaction matching.

Parameters:
inv_via VIA body
ack_via VIA from ACK
Returns:
1 on match, 0 for no match

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().


Variable Documentation

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.

struct cell* e2eack_T [static]

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().

struct cell* T [static]

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().


Generated on Thu May 24 20:00:44 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6