Skip to content

Commit

Permalink
dialog: counters for keep alive tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 4, 2016
1 parent 6bb0bab commit 2ea8b13
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
37 changes: 20 additions & 17 deletions modules/dialog/dlg_hash.h
Expand Up @@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Expand Down Expand Up @@ -48,7 +48,7 @@
/* events for dialog processing */
#define DLG_EVENT_TDEL 1 /*!< transaction was destroyed */
#define DLG_EVENT_RPL1xx 2 /*!< 1xx request */
#define DLG_EVENT_RPL2xx 3 /*!< 2xx request */
#define DLG_EVENT_RPL2xx 3 /*!< 2xx request */
#define DLG_EVENT_RPL3xx 4 /*!< 3xx request */
#define DLG_EVENT_REQPRACK 5 /*!< PRACK request */
#define DLG_EVENT_REQACK 6 /*!< ACK request */
Expand Down Expand Up @@ -128,6 +128,8 @@ typedef struct dlg_cell
struct dlg_head_cbl cbs; /*!< dialog callbacks */
struct dlg_profile_link *profile_links; /*!< dialog profiles */
struct dlg_var *vars; /*!< dialog variables */
unsigned int ka_src_counter; /*!< keepalive src (caller) counter */
unsigned int ka_dst_counter; /*!< keepalive dst (callee) counter */
} dlg_cell_t;


Expand Down Expand Up @@ -322,9 +324,9 @@ dlg_cell_t* dlg_get_by_iuid(dlg_iuid_t *diuid);
* \brief Get dialog that correspond to CallId, From Tag and To Tag
*
* Get dialog that correspond to CallId, From Tag and To Tag.
* See RFC 3261, paragraph 4. Overview of Operation:
* "The combination of the To tag, From tag, and Call-ID completely
* defines a peer-to-peer SIP relationship between [two UAs] and is
* See RFC 3261, paragraph 4. Overview of Operation:
* "The combination of the To tag, From tag, and Call-ID completely
* defines a peer-to-peer SIP relationship between [two UAs] and is
* referred to as a dialog."
* Note that the caller is responsible for decrementing (or reusing)
* the reference counter by one again iff a dialog has been found.
Expand Down Expand Up @@ -458,9 +460,10 @@ struct mi_root * mi_terminate_dlgs(struct mi_root *cmd_tree, void *param );
* \return 1 if dialog structure and message content matches, 0 otherwise
*/
static inline int match_dialog(dlg_cell_t *dlg, str *callid,
str *ftag, str *ttag, unsigned int *dir) {
str *ftag, str *ttag, unsigned int *dir)
{
if (dlg->tag[DLG_CALLEE_LEG].len == 0) {
// dialog to tag is undetermined ATM.
// dialog to tag is undetermined ATM.
if (*dir==DLG_DIR_DOWNSTREAM) {
if (dlg->callid.len == callid->len &&
dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
Expand All @@ -485,9 +488,9 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,

*dir = DLG_DIR_UPSTREAM;
return 1;
} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
strncmp(dlg->callid.s, callid->s, callid->len)==0) {
} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len
&& strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0
&& strncmp(dlg->callid.s, callid->s, callid->len)==0) {

*dir = DLG_DIR_DOWNSTREAM;
return 1;
Expand Down Expand Up @@ -525,10 +528,10 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
*dir = DLG_DIR_UPSTREAM;
return 1;
} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0 &&
strncmp(dlg->callid.s, callid->s, callid->len)==0) {
dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0 &&
strncmp(dlg->callid.s, callid->s, callid->len)==0) {

*dir = DLG_DIR_DOWNSTREAM;
return 1;
Expand All @@ -537,8 +540,8 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
* runs on 200ok but with initial INVITE that has no to-tag */
if(ttag->len==0 && dlg->state==DLG_STATE_CONFIRMED_NA
&& dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
strncmp(dlg->callid.s, callid->s, callid->len)==0) {
strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
strncmp(dlg->callid.s, callid->s, callid->len)==0) {

*dir = DLG_DIR_DOWNSTREAM;
return 1;
Expand Down
18 changes: 15 additions & 3 deletions modules/dialog/dlg_req_within.c
Expand Up @@ -239,7 +239,8 @@ void bye_reply_cb(struct cell* t, int type, struct tmcb_params* ps){


/* callback function to handle responses to the keep-alive request */
void dlg_ka_cb(struct cell* t, int type, struct tmcb_params* ps){
void dlg_ka_cb_all(struct cell* t, int type, struct tmcb_params* ps, int dir)
{

dlg_cell_t* dlg;
dlg_iuid_t *iuid = NULL;
Expand Down Expand Up @@ -281,6 +282,17 @@ void dlg_ka_cb(struct cell* t, int type, struct tmcb_params* ps){
dlg_iuid_sfree(iuid);
}

/* callback function to handle responses to the keep-alive request to src */
void dlg_ka_cb_src(struct cell* t, int type, struct tmcb_params* ps)
{
dlg_ka_cb_all(t, type, ps, DLG_CALLER_LEG);
}

/* callback function to handle responses to the keep-alive request to dst */
void dlg_ka_cb_dst(struct cell* t, int type, struct tmcb_params* ps)
{
dlg_ka_cb_all(t, type, ps, DLG_CALLEE_LEG);
}

static inline int build_extra_hdr(struct dlg_cell * cell, str *extra_hdrs,
str *str_hdr)
Expand Down Expand Up @@ -440,10 +452,10 @@ int dlg_send_ka(dlg_cell_t *dlg, int dir)

if(dir==DLG_CALLEE_LEG && dlg_lreq_callee_headers.len>0) {
set_uac_req(&uac_r, &met, &dlg_lreq_callee_headers, NULL, di,
TMCB_LOCAL_COMPLETED, dlg_ka_cb, (void*)iuid);
TMCB_LOCAL_COMPLETED, dlg_ka_cb_dst, (void*)iuid);
} else {
set_uac_req(&uac_r, &met, NULL, NULL, di, TMCB_LOCAL_COMPLETED,
dlg_ka_cb, (void*)iuid);
(dir==DLG_CALLEE_LEG)?dlg_ka_cb_dst:dlg_ka_cb_src, (void*)iuid);
}
result = d_tmb.t_request_within(&uac_r);

Expand Down

0 comments on commit 2ea8b13

Please sign in to comment.