From 3ed54196a41823ba288b5dceac200dee33d47df7 Mon Sep 17 00:00:00 2001 From: Bogdan-Andrei Iancu Date: Tue, 26 Feb 2019 19:40:09 +0200 Subject: [PATCH] Added new tcp_no_new_conn_rplflag to control TCP conns 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) --- cfg.lex | 2 ++ cfg.y | 10 ++++++++++ forward.c | 6 ++++++ globals.h | 1 + modules/tm/t_reply.c | 17 +++++++++++++++++ net/net_tcp.c | 7 +++++-- 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/cfg.lex b/cfg.lex index 62739917e7..12b7324b24 100644 --- a/cfg.lex +++ b/cfg.lex @@ -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" @@ -572,6 +573,7 @@ SPACE [ ] {SIP_WARNING} { count(); yylval.strval=yytext; return SIP_WARNING; } {MHOMED} { count(); yylval.strval=yytext; return MHOMED; } {TCP_NO_NEW_CONN_BFLAG} { count(); yylval.strval=yytext; return TCP_NO_NEW_CONN_BFLAG; } +{TCP_NO_NEW_CONN_RPLFLAG} { count(); yylval.strval=yytext; return TCP_NO_NEW_CONN_RPLFLAG; } {TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; } {TCP_WORKERS} { count(); yylval.strval=yytext; return TCP_WORKERS; } {TCP_ACCEPT_ALIASES} { count(); yylval.strval=yytext; diff --git a/cfg.y b/cfg.y index 31818eea93..d3f85c2985 100644 --- a/cfg.y +++ b/cfg.y @@ -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 @@ -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; } diff --git a/forward.c b/forward.c index f19b5651eb..b1620ea145 100644 --- a/forward.c +++ b/forward.c @@ -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 diff --git a/globals.h b/globals.h index 25565d4a43..35d9651473 100644 --- a/globals.h +++ b/globals.h @@ -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; diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c index e1cbb377ad..17e2528ccf 100644 --- a/modules/tm/t_reply.c +++ b/modules/tm/t_reply.c @@ -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 ); @@ -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; @@ -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, @@ -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: @@ -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 */ @@ -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; diff --git a/net/net_tcp.c b/net/net_tcp.c index ae97b91bf4..d85f140bb3 100644 --- a/net/net_tcp.c +++ b/net/net_tcp.c @@ -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;