Skip to content

Commit

Permalink
Added new tcp_no_new_conn_rplflag to control TCP conns
Browse files Browse the repository at this point in the history
While tcp_no_new_conn_bflag controls the opening of TCP conns on the UAC branches side of the transaction, the new tcp_no_new_conn_rplflag does the some kind of controling but on the UAS side of transaction (sending back the replies)
  • Loading branch information
bogdan-iancu committed Feb 26, 2019
1 parent d3a0aaa commit 3ed5419
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cfg.lex
Expand Up @@ -304,6 +304,7 @@ TCP_CON_LIFETIME "tcp_connection_lifetime"
TCP_LISTEN_BACKLOG "tcp_listen_backlog"
TCP_MAX_CONNECTIONS "tcp_max_connections"
TCP_NO_NEW_CONN_BFLAG "tcp_no_new_conn_bflag"
TCP_NO_NEW_CONN_RPLFLAG "tcp_no_new_conn_rplflag"
TCP_KEEPALIVE "tcp_keepalive"
TCP_KEEPCOUNT "tcp_keepcount"
TCP_KEEPIDLE "tcp_keepidle"
Expand Down Expand Up @@ -572,6 +573,7 @@ SPACE [ ]
<INITIAL>{SIP_WARNING} { count(); yylval.strval=yytext; return SIP_WARNING; }
<INITIAL>{MHOMED} { count(); yylval.strval=yytext; return MHOMED; }
<INITIAL>{TCP_NO_NEW_CONN_BFLAG} { count(); yylval.strval=yytext; return TCP_NO_NEW_CONN_BFLAG; }
<INITIAL>{TCP_NO_NEW_CONN_RPLFLAG} { count(); yylval.strval=yytext; return TCP_NO_NEW_CONN_RPLFLAG; }
<INITIAL>{TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; }
<INITIAL>{TCP_WORKERS} { count(); yylval.strval=yytext; return TCP_WORKERS; }
<INITIAL>{TCP_ACCEPT_ALIASES} { count(); yylval.strval=yytext;
Expand Down
10 changes: 10 additions & 0 deletions cfg.y
Expand Up @@ -375,6 +375,7 @@ static struct multi_str *tmp_mod;
%token TCP_LISTEN_BACKLOG
%token TCP_MAX_CONNECTIONS
%token TCP_NO_NEW_CONN_BFLAG
%token TCP_NO_NEW_CONN_RPLFLAG
%token TCP_KEEPALIVE
%token TCP_KEEPCOUNT
%token TCP_KEEPIDLE
Expand Down Expand Up @@ -997,6 +998,15 @@ assign_stm: DEBUG EQUAL snumber
flag_idx2mask( &tcp_no_new_conn_bflag );
}
| TCP_NO_NEW_CONN_BFLAG EQUAL error { yyerror("number value expected"); }
| TCP_NO_NEW_CONN_RPLFLAG EQUAL ID {
tcp_no_new_conn_rplflag =
get_flag_id_by_name(FLAG_TYPE_MSG, $3);
if (!flag_in_range( (flag_t)tcp_no_new_conn_rplflag ) )
yyerror("invalid TCP no_new_conn RePLy Flag");
flag_idx2mask( &tcp_no_new_conn_rplflag );
}
| TCP_NO_NEW_CONN_RPLFLAG EQUAL error { yyerror("number value expected"); }

| TCP_KEEPALIVE EQUAL NUMBER {
tcp_keepalive=$3;
}
Expand Down
6 changes: 6 additions & 0 deletions forward.c
Expand Up @@ -540,10 +540,16 @@ int forward_reply(struct sip_msg* msg)
goto error;
}

if (msg->flags & tcp_no_new_conn_rplflag)
tcp_no_new_conn = 1;

if (msg_send(send_sock, proto, to, (int)id, new_buf, new_len, msg)<0) {
tcp_no_new_conn = 0;
update_stat( drp_rpls, 1);
goto error0;
}
tcp_no_new_conn = 0;

update_stat( fwd_rpls, 1);
/*
* If no port is specified in the second via, then this
Expand Down
1 change: 1 addition & 0 deletions globals.h
Expand Up @@ -70,6 +70,7 @@ extern int tcp_keepinterval;
extern int tcp_max_msg_time;
extern int tcp_no_new_conn;
extern int tcp_no_new_conn_bflag;
extern int tcp_no_new_conn_rplflag;

extern int no_daemon_mode;
extern int debug_mode;
Expand Down
17 changes: 17 additions & 0 deletions modules/tm/t_reply.c
Expand Up @@ -428,6 +428,9 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
LM_CRIT("send_sock is NULL\n");
}

if(trans->uas.request && trans->uas.request->flags&tcp_no_new_conn_rplflag)
tcp_no_new_conn = 1;

if ( SEND_PR_BUFFER( rb, buf, len )==0 ) {
LM_DBG("reply sent out. buf=%p: %.9s..., "
"shmem=%p: %.9s\n", buf, buf, rb->buffer.s, rb->buffer.s );
Expand All @@ -442,6 +445,8 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
stats_trans_rpl( code, 1 /*local*/ );
}

tcp_no_new_conn = 0;

/* run the POST send callbacks */
if (code>=200&&!is_local(trans)&&has_tran_tmcbs(trans,TMCB_RESPONSE_OUT)){
cb_s.s = buf;
Expand Down Expand Up @@ -1077,6 +1082,9 @@ int t_retransmit_reply( struct cell *t )
UNLOCK_REPLIES( t );

/* send the buffer out */
if (t->uas.request && t->uas.request->flags & tcp_no_new_conn_rplflag)
tcp_no_new_conn = 1;

if (SEND_PR_BUFFER( & t->uas.response, b, len )==0) {
/* success */
LM_DBG("buf=%p: %.9s..., shmem=%p: %.9s\n",b, b,
Expand All @@ -1089,6 +1097,9 @@ int t_retransmit_reply( struct cell *t )
NULL, FAKED_REPLY, t->uas.status);
}
}

tcp_no_new_conn = 0;

return 1;

error:
Expand Down Expand Up @@ -1330,6 +1341,10 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
run_trans_callbacks_locked(TMCB_RESPONSE_PRE_OUT,t,t->uas.request,
relayed_msg, relayed_code);
}

if (t->uas.request && t->uas.request->flags & tcp_no_new_conn_rplflag)
tcp_no_new_conn = 1;

/* send it out*/
if (SEND_PR_BUFFER( uas_rb, buf, res_len)==0) {
/* success */
Expand All @@ -1345,6 +1360,8 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
}
}

tcp_no_new_conn = 0;

/* run the POST sending out callback */
if (!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_OUT) ) {
cb_s.s = buf;
Expand Down
7 changes: 5 additions & 2 deletions net/net_tcp.c
Expand Up @@ -129,9 +129,12 @@ int tcp_keepcount = 0;
int tcp_keepidle = 0;
int tcp_keepinterval = 0;

/*!< should a new TCP conn be open if needed? - branch flag to be set in
* the SIP messages - configuration option */
/*!< should we allow opening a new TCP conn when sending data
* over UAC branches? - branch flag to be set in the SIP messages */
int tcp_no_new_conn_bflag = 0;
/*!< should we allow opening a new TCP conn when sending data
* back to UAS (replies)? - msg flag to be set in the SIP messages */
int tcp_no_new_conn_rplflag = 0;
/*!< should a new TCP conn be open if needed? - variable used to used for
* signalizing between SIP layer (branch flag) and TCP layer (tcp_send func)*/
int tcp_no_new_conn = 0;
Expand Down

0 comments on commit 3ed5419

Please sign in to comment.