From 85c15c4873d5b3b389f086e3919a912f87c8e5a1 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Tue, 14 Apr 2020 11:31:09 +0300 Subject: [PATCH 01/13] Add sctp multihoming support This is a follow up for https://opensips.org/pipermail/users/2019-March/040715.html --- cfg.lex | 2 ++ cfg.y | 9 +++++++++ globals.h | 2 ++ main.c | 1 + modules/proto_sctp/sctp_server.c | 11 +++++++++++ 5 files changed, 25 insertions(+) diff --git a/cfg.lex b/cfg.lex index 20979abe285..7a02dd5684f 100644 --- a/cfg.lex +++ b/cfg.lex @@ -212,6 +212,7 @@ LOGSTDERROR log_stderror LOGFACILITY log_facility LOGNAME log_name LISTEN listen +LISTEN_SCTP_SEC listen_sctp_sec MEMGROUP mem-group ALIAS alias AUTO_ALIASES auto_aliases @@ -417,6 +418,7 @@ SPACE [ ] {LOGFACILITY} { yylval.strval=yytext; return LOGFACILITY; } {LOGNAME} { yylval.strval=yytext; return LOGNAME; } {LISTEN} { count(); yylval.strval=yytext; return LISTEN; } +{LISTEN_SCTP_SEC} { count(); yylval.strval=yytext; return LISTEN_SCTP_SEC; } {MEMGROUP} { count(); yylval.strval=yytext; return MEMGROUP; } {ALIAS} { count(); yylval.strval=yytext; return ALIAS; } {AUTO_ALIASES} { count(); yylval.strval=yytext; return AUTO_ALIASES; } diff --git a/cfg.y b/cfg.y index e48baa808b5..6de06f19e24 100644 --- a/cfg.y +++ b/cfg.y @@ -341,6 +341,7 @@ extern int cfg_parse_only_routes; %token LOGNAME %token AVP_ALIASES %token LISTEN +%token LISTEN_SCTP_SEC %token MEMGROUP %token ALIAS %token AUTO_ALIASES @@ -1137,6 +1138,14 @@ assign_stm: DEBUG EQUAL snumber | LISTEN EQUAL error { yyerror("ip address or hostname " "expected (use quotes if the hostname includes" " config keywords)"); } + | LISTEN_SCTP_SEC EQUAL ip { + if (init_su(&sctp_sec_addr, $3, 0)!=0){ + LM_CRIT("cfg. parser: failed" + " to add secondary sctp address\n"); + break; + } + } + | LISTEN_SCTP_SEC EQUAL error { yyerror("ip address expected"); } | MEMGROUP EQUAL STRING COLON multi_string { IFOR(); /* convert STIRNG ($3) to an ID */ /* update the memstats type for each module */ diff --git a/globals.h b/globals.h index 118537c669d..ec259476676 100644 --- a/globals.h +++ b/globals.h @@ -150,4 +150,6 @@ extern int disable_503_translation; extern int enable_asserts; extern int abort_on_assert; + +extern union sockaddr_union sctp_sec_addr; #endif diff --git a/main.c b/main.c index 86d132789cf..ca15c9fa575 100644 --- a/main.c +++ b/main.c @@ -314,6 +314,7 @@ int is_main = 1; /* flag = is this the "main" process? */ char* pid_file = 0; /* filename as asked by user */ char* pgid_file = 0; +union sockaddr_union sctp_sec_addr = { .s.sa_family = 0 }; /** * Clean up on exit. This should be called before exiting. diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index f1a302dec8a..a20c768fb63 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -125,6 +125,17 @@ int proto_sctp_init_listener(struct socket_info* sock_info) " local address, try site local or global\n"); goto error; } + if (sctp_sec_addr.s.sa_family != 0) { + if (sctp_bindx(sock_info->socket, + (struct sockaddr *)&sctp_sec_addr, 1, + SCTP_BINDX_ADD_ADDR) == -1) + LM_ERR("bindx(%x, %p) : %s\n", + sock_info->socket, &sctp_sec_addr.s, + strerror(errno)); + else + LM_INFO("sctp bindx success to: %s\n", + inet_ntoa(((struct sockaddr_in *)&sctp_sec_addr)->sin_addr)); + } if(listen(sock_info->socket, LISTEN_BACKLOG)<0){ LM_ERR("listen(%x, %d) on %s: %s\n", sock_info->socket, From 7b1ef16fd2ab69fbb26ae35a44797eb3730457c8 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Tue, 14 Apr 2020 11:52:01 +0300 Subject: [PATCH 02/13] Add support for Generic Number parameter --- modules/sip_i/isup.c | 81 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/modules/sip_i/isup.c b/modules/sip_i/isup.c index e8e22ef8cd7..de49b3be145 100644 --- a/modules/sip_i/isup.c +++ b/modules/sip_i/isup.c @@ -152,6 +152,27 @@ static struct isup_subfield calling_party_num_subf[] = { {str_init("Address signal"), {0, {{0, 0}}, {0}}}, SUBF_INIT_EMPTY}; +static struct isup_subfield generic_num_subf[] = { + {str_init("Number qualifier indicator"), {3, + {str_init("additional called party num"), str_init("additional connected num"), + str_init("additional calling party num")}, {1,5,6}}}, + {str_init("Odd/even indicator"), {2, + {str_init("even"), str_init("odd")}, {0,1}}}, + {str_init("Nature of address indicator"), {4, + {str_init("subscriber"), str_init("unknown"), str_init("national"), + str_init("international")}, {1,2,3,4}}}, + {str_init("Number Incomplete indicator"), {2, + {str_init("complete"), str_init("incomplete")}, {0,1}}}, + {str_init("Numbering plan indicator"), {3, + {str_init("ISDN"), str_init("Data"), str_init("Telex")}, {1,3,4}}}, + {str_init("Address presentation restricted indicator"), {4, + {str_init("allowed"), str_init("restricted"), str_init("not available"), + str_init("reserved")}, {0,1,2,3}}}, + {str_init("Screening indicator"), {2, + {str_init("user"), str_init("network")}, {1,3}}}, + {str_init("Address signal"), {0, {{0, 0}}, {0}}}, + SUBF_INIT_EMPTY}; + static struct isup_subfield backward_call_ind_subf[] = { {str_init("Charge indicator"), {2, {str_init("no indication"), str_init("no charge")}, {0,1}}}, @@ -745,6 +766,64 @@ int calling_party_num_writef(int param_idx, int subfield_idx, unsigned char *par return 0; } +void generic_num_parsef(int subfield_idx, unsigned char *param_val, int len, + int *int_res, str *str_res) +{ + int idx[] = {0,1,1,2,2,2,2}; + int shift[] = {0,7,0,7,4,2,0}; + int mask[] = {0xff,1,0x7f,1,7,3,3}; + int oddeven = (param_val[1] >> 7) & 0x1; + + if (subfield_idx < 0 || subfield_idx > 7) { + LM_ERR("BUG - bad subfield\n"); + return; + } + + switch (subfield_idx) { + case 1: + *int_res = oddeven; + break; + case 7: + isup_get_number(str_res, param_val + 3, len - 3, oddeven); + break; + default: + *int_res = (param_val[idx[subfield_idx]] >> shift[subfield_idx]) & mask[subfield_idx]; + } +} + +int generic_num_writef(int param_idx, int subfield_idx, unsigned char *param_val, int *len, + pv_value_t *val) +{ + int new_val; + int num_len, oddeven; + str num; + int idx[] = {0,1,1,2,2,2,2}; + int mask[] = {0xff,0x80,0x7f,0x80,0x70,0xc,0x3}; + int shift[] = {0,7,0,7,4,2,0}; + + NUM_PARAM_GET_VAL_PV(7); + + if (subfield_idx < 0 || subfield_idx > 7) { + LM_ERR("BUG - bad subfield\n"); + return -1; + } + + if (subfield_idx == 7) { + isup_put_number(param_val + 2, num, &num_len, &oddeven); + /* also set oddeven, just in case it wasn't already */ + param_val[1] = SET_BITS(param_val[1], 0x80, 7, oddeven); + } else + param_val[idx[subfield_idx]] = SET_BITS(param_val[idx[subfield_idx]], + mask[subfield_idx], shift[subfield_idx], new_val); + + if (subfield_idx == 7) + *len = num_len + 2; + else if (*len == 0) + *len = 2; + + return 0; +} + void backward_call_ind_parsef(int subfield_idx, unsigned char *param_val, int len, int *int_res, str *str_res) { @@ -1171,7 +1250,7 @@ struct isup_param_data isup_params[NO_ISUP_PARAMS] = { {ISUP_PARM_REDIRECT_FORWARD_INFO, str_init("Redirect forward information"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_REDIRECT_BACKWARD_INFO, str_init("Redirect backward information"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_NUM_PORTABILITY_FORWARD_INFO, str_init("Number portability forward information"), NULL, NULL, NULL, NULL, 0}, - {ISUP_PARM_GENERIC_ADDR, str_init("Generic Number"), NULL, NULL, NULL, NULL, 0}, + {ISUP_PARM_GENERIC_ADDR, str_init("Generic Number"), generic_num_parsef, generic_num_writef, generic_num_subf, NULL, 0}, {ISUP_PARM_GENERIC_DIGITS, str_init("Generic Digits"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_EGRESS_SERV, str_init("Egress Service"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_JIP, str_init("Jurisdiction Information Parameter"), NULL, NULL, NULL, NULL, 0}, From fe56fe466bacff07ad27e2a6b21f423a8aeffb14 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Mon, 1 Jun 2020 09:36:54 +0300 Subject: [PATCH 03/13] Add logging for SCTP_ASSOC_CHANGE event --- modules/proto_sctp/sctp_server.c | 68 +++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index a20c768fb63..46091785125 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -89,6 +89,16 @@ int proto_sctp_init_listener(struct socket_info* sock_info) } #endif +#ifdef SCTP_EVENTS + struct sctp_event_subscribe ev_s = {0}; + ev_s.sctp_association_event = 1; + + if(setsockopt(sock_info->socket, IPPROTO_SCTP, SCTP_EVENTS, &ev_s, sizeof(ev_s)) == -1) { + LM_WARN("setsockopt SCTP_EVENTS: %s (%d)\n", + strerror(errno), errno); + } +#endif + /* this sockopt causes a kernel panic in some sctp implementations. * commenting it out. -gmarmon */ @@ -150,11 +160,37 @@ int proto_sctp_init_listener(struct socket_info* sock_info) return -1; } +static char *sctp_assoc_change_state2s(short int state) +{ + char *s; + + switch(state) { + case SCTP_COMM_UP: + s = "SCTP_COMM_UP"; + break; + case SCTP_COMM_LOST: + s = "SCTP_COMM_LOST"; + break; + case SCTP_RESTART: + s = "SCTP_RESTART"; + break; + case SCTP_SHUTDOWN_COMP: + s = "SCTP_SHUTDOWN_COMP"; + break; + case SCTP_CANT_STR_ASSOC: + s = "SCTP_CANT_STR_ASSOC"; + break; + default: + s = "UNKNOWN"; + break; + }; + return s; +} int proto_sctp_read(struct socket_info *si, int* bytes_read) { struct receive_info ri; - int len; + int len, msg_flags; static char buf [BUF_SIZE+1]; char *tmp; unsigned int fromlen; @@ -162,7 +198,7 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) fromlen=sockaddru_len(si->su); len = sctp_recvmsg(si->socket, buf, BUF_SIZE, &ri.src_su.s, &fromlen, - &sinfo, 0); + &sinfo, &msg_flags); if (len==-1){ if (errno==EAGAIN){ LM_DBG("packet with bad checksum received\n"); @@ -174,6 +210,34 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) return -2; } + if (msg_flags & MSG_NOTIFICATION) { + union sctp_notification *snp = (union sctp_notification *)buf; + + switch(snp->sn_header.sn_type) { + case SCTP_ASSOC_CHANGE: + su2ip_addr(&ri.src_ip, &ri.src_su); + if (snp->sn_assoc_change.sac_state == SCTP_COMM_UP) + LM_NOTICE("SCTP_ASSOC_CHANGE assoc_id: %d, peer ip:%s," + "peer port:%d, state: %s\n", + snp->sn_assoc_change.sac_assoc_id, + ip_addr2a(&ri.src_ip), + su_getport(&ri.src_su), + sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state)); + else + LM_ERR("SCTP_ASSOC_CHANGE assoc_id: %d, peer ip:%s, " + "peer port:%d, state: %s\n", + snp->sn_assoc_change.sac_assoc_id, + ip_addr2a(&ri.src_ip), + su_getport(&ri.src_su), + sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state)); + break; + default: + LM_INFO("unexpected sctp notification type: %d\n", + snp->sn_header.sn_type); + } + return 0; + } + /* we must 0-term the messages, receive_msg expects it */ buf[len]=0; /* no need to save the previous char */ From 390a1f6c536938b1caeef90aa4731048d3eeb779 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Mon, 1 Jun 2020 09:50:42 +0300 Subject: [PATCH 04/13] Uncomment and fix TOS applying for sctp socket --- modules/proto_sctp/sctp_server.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index 46091785125..b393e7e5fe3 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -102,13 +102,18 @@ int proto_sctp_init_listener(struct socket_info* sock_info) /* this sockopt causes a kernel panic in some sctp implementations. * commenting it out. -gmarmon */ - /* tos optval=tos; - if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, - sizeof(optval)) ==-1){ - LM_WARN("setsockopt tos: %s\n", strerror(errno)); + if (addr->s.sa_family == AF_INET) { + if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, + sizeof(optval)) ==-1){ + LM_WARN("setsockopt tos: %s\n", strerror(errno)); + } + } else if (addr->s.sa_family == AF_INET6) { + if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_TCLASS, (void*)&optval, + sizeof(optval)) ==-1){ + LM_WARN("setsockopt v6 tos: %s\n", strerror(errno)); + } } - */ #if defined (__linux__) && defined(SCTP_ERRORS) /* will SCTP_ERRORS ever be defined? -gmarmon */ From ae2002e39c6ad2d9012a01360e18313b9978a431 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Mon, 1 Jun 2020 09:59:03 +0300 Subject: [PATCH 05/13] Add SCTP_UNORDERED flag when sending over sctp --- modules/proto_sctp/sctp_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index b393e7e5fe3..5752b4537ba 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -277,7 +277,7 @@ int proto_sctp_send(struct socket_info *source, char *buf, unsigned len, tolen=sockaddru_len(*to); again: - n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, 0, 0, 0, 0); + n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, SCTP_UNORDERED, 0, 0, 0); #ifdef XL_DEBUG LM_INFO("send status: %d\n", n); #endif From 23f2c2c682ecf9404f9f133f9d7f9ce06cc4e7bf Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Mon, 1 Jun 2020 10:50:20 +0300 Subject: [PATCH 06/13] Add SCTP_SEND_TTL_MS param, default 0 --- cfg.lex | 2 ++ cfg.y | 4 ++++ globals.h | 1 + main.c | 1 + modules/proto_sctp/sctp_server.c | 11 ++++++++++- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cfg.lex b/cfg.lex index 7a02dd5684f..04058d789c1 100644 --- a/cfg.lex +++ b/cfg.lex @@ -213,6 +213,7 @@ LOGFACILITY log_facility LOGNAME log_name LISTEN listen LISTEN_SCTP_SEC listen_sctp_sec +SCTP_SEND_TTL_MS sctp_send_ttl_ms MEMGROUP mem-group ALIAS alias AUTO_ALIASES auto_aliases @@ -419,6 +420,7 @@ SPACE [ ] {LOGNAME} { yylval.strval=yytext; return LOGNAME; } {LISTEN} { count(); yylval.strval=yytext; return LISTEN; } {LISTEN_SCTP_SEC} { count(); yylval.strval=yytext; return LISTEN_SCTP_SEC; } +{SCTP_SEND_TTL_MS} { count(); yylval.strval=yytext; return SCTP_SEND_TTL_MS; } {MEMGROUP} { count(); yylval.strval=yytext; return MEMGROUP; } {ALIAS} { count(); yylval.strval=yytext; return ALIAS; } {AUTO_ALIASES} { count(); yylval.strval=yytext; return AUTO_ALIASES; } diff --git a/cfg.y b/cfg.y index 6de06f19e24..30cd80e1513 100644 --- a/cfg.y +++ b/cfg.y @@ -342,6 +342,7 @@ extern int cfg_parse_only_routes; %token AVP_ALIASES %token LISTEN %token LISTEN_SCTP_SEC +%token SCTP_SEND_TTL_MS %token MEMGROUP %token ALIAS %token AUTO_ALIASES @@ -1146,6 +1147,9 @@ assign_stm: DEBUG EQUAL snumber } } | LISTEN_SCTP_SEC EQUAL error { yyerror("ip address expected"); } + | SCTP_SEND_TTL_MS EQUAL NUMBER { IFOR(); + sctp_send_ttl_ms=$3; } + | SCTP_SEND_TTL_MS EQUAL error { yyerror("number expected"); } | MEMGROUP EQUAL STRING COLON multi_string { IFOR(); /* convert STIRNG ($3) to an ID */ /* update the memstats type for each module */ diff --git a/globals.h b/globals.h index ec259476676..c84690aa54e 100644 --- a/globals.h +++ b/globals.h @@ -152,4 +152,5 @@ extern int enable_asserts; extern int abort_on_assert; extern union sockaddr_union sctp_sec_addr; +extern uint32_t sctp_send_ttl_ms; #endif diff --git a/main.c b/main.c index ca15c9fa575..de1aed266d0 100644 --- a/main.c +++ b/main.c @@ -315,6 +315,7 @@ char* pid_file = 0; /* filename as asked by user */ char* pgid_file = 0; union sockaddr_union sctp_sec_addr = { .s.sa_family = 0 }; +uint32_t sctp_send_ttl_ms = 0; /** * Clean up on exit. This should be called before exiting. diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index 5752b4537ba..90424662037 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -92,6 +92,7 @@ int proto_sctp_init_listener(struct socket_info* sock_info) #ifdef SCTP_EVENTS struct sctp_event_subscribe ev_s = {0}; ev_s.sctp_association_event = 1; + ev_s.sctp_send_failure_event = 1; if(setsockopt(sock_info->socket, IPPROTO_SCTP, SCTP_EVENTS, &ev_s, sizeof(ev_s)) == -1) { LM_WARN("setsockopt SCTP_EVENTS: %s (%d)\n", @@ -236,6 +237,14 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) su_getport(&ri.src_su), sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state)); break; + case SCTP_SEND_FAILED: + LM_ERR("SCTP_SEND_FAILED assoc_id: %d, peer ip:%s, " + "peer port:%d, error: %d\n", + snp->sn_send_failed.ssf_assoc_id, + ip_addr2a(&ri.src_ip), + su_getport(&ri.src_su), + snp->sn_send_failed.ssf_error); + break; default: LM_INFO("unexpected sctp notification type: %d\n", snp->sn_header.sn_type); @@ -277,7 +286,7 @@ int proto_sctp_send(struct socket_info *source, char *buf, unsigned len, tolen=sockaddru_len(*to); again: - n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, SCTP_UNORDERED, 0, 0, 0); + n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, SCTP_UNORDERED, 0, sctp_send_ttl_ms, 0); #ifdef XL_DEBUG LM_INFO("send status: %d\n", n); #endif From 3dd7a4ca950b26e1a439eb007abf33a11a163e5f Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Mon, 1 Jun 2020 19:33:59 +0300 Subject: [PATCH 07/13] Fix SCTP_SEND_FAILED --- modules/proto_sctp/sctp_server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index 90424662037..e0239003f46 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -238,6 +238,7 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state)); break; case SCTP_SEND_FAILED: + su2ip_addr(&ri.src_ip, &ri.src_su); LM_ERR("SCTP_SEND_FAILED assoc_id: %d, peer ip:%s, " "peer port:%d, error: %d\n", snp->sn_send_failed.ssf_assoc_id, From b0822d9322935070773e50614be0d7b8b7079ee4 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Wed, 3 Jun 2020 14:35:51 +0300 Subject: [PATCH 08/13] Revert "Fix SCTP_SEND_FAILED" This reverts commit 3dd7a4ca950b26e1a439eb007abf33a11a163e5f. --- modules/proto_sctp/sctp_server.c | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index e0239003f46..90424662037 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -238,7 +238,6 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state)); break; case SCTP_SEND_FAILED: - su2ip_addr(&ri.src_ip, &ri.src_su); LM_ERR("SCTP_SEND_FAILED assoc_id: %d, peer ip:%s, " "peer port:%d, error: %d\n", snp->sn_send_failed.ssf_assoc_id, From b2df4602372874aa8fb185572bca4400a15c3347 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Wed, 3 Jun 2020 14:36:36 +0300 Subject: [PATCH 09/13] Revert "Add SCTP_SEND_TTL_MS param, default 0" This reverts commit 23f2c2c682ecf9404f9f133f9d7f9ce06cc4e7bf. --- cfg.lex | 2 -- cfg.y | 4 ---- globals.h | 1 - main.c | 1 - modules/proto_sctp/sctp_server.c | 11 +---------- 5 files changed, 1 insertion(+), 18 deletions(-) diff --git a/cfg.lex b/cfg.lex index 04058d789c1..7a02dd5684f 100644 --- a/cfg.lex +++ b/cfg.lex @@ -213,7 +213,6 @@ LOGFACILITY log_facility LOGNAME log_name LISTEN listen LISTEN_SCTP_SEC listen_sctp_sec -SCTP_SEND_TTL_MS sctp_send_ttl_ms MEMGROUP mem-group ALIAS alias AUTO_ALIASES auto_aliases @@ -420,7 +419,6 @@ SPACE [ ] {LOGNAME} { yylval.strval=yytext; return LOGNAME; } {LISTEN} { count(); yylval.strval=yytext; return LISTEN; } {LISTEN_SCTP_SEC} { count(); yylval.strval=yytext; return LISTEN_SCTP_SEC; } -{SCTP_SEND_TTL_MS} { count(); yylval.strval=yytext; return SCTP_SEND_TTL_MS; } {MEMGROUP} { count(); yylval.strval=yytext; return MEMGROUP; } {ALIAS} { count(); yylval.strval=yytext; return ALIAS; } {AUTO_ALIASES} { count(); yylval.strval=yytext; return AUTO_ALIASES; } diff --git a/cfg.y b/cfg.y index 30cd80e1513..6de06f19e24 100644 --- a/cfg.y +++ b/cfg.y @@ -342,7 +342,6 @@ extern int cfg_parse_only_routes; %token AVP_ALIASES %token LISTEN %token LISTEN_SCTP_SEC -%token SCTP_SEND_TTL_MS %token MEMGROUP %token ALIAS %token AUTO_ALIASES @@ -1147,9 +1146,6 @@ assign_stm: DEBUG EQUAL snumber } } | LISTEN_SCTP_SEC EQUAL error { yyerror("ip address expected"); } - | SCTP_SEND_TTL_MS EQUAL NUMBER { IFOR(); - sctp_send_ttl_ms=$3; } - | SCTP_SEND_TTL_MS EQUAL error { yyerror("number expected"); } | MEMGROUP EQUAL STRING COLON multi_string { IFOR(); /* convert STIRNG ($3) to an ID */ /* update the memstats type for each module */ diff --git a/globals.h b/globals.h index c84690aa54e..ec259476676 100644 --- a/globals.h +++ b/globals.h @@ -152,5 +152,4 @@ extern int enable_asserts; extern int abort_on_assert; extern union sockaddr_union sctp_sec_addr; -extern uint32_t sctp_send_ttl_ms; #endif diff --git a/main.c b/main.c index de1aed266d0..ca15c9fa575 100644 --- a/main.c +++ b/main.c @@ -315,7 +315,6 @@ char* pid_file = 0; /* filename as asked by user */ char* pgid_file = 0; union sockaddr_union sctp_sec_addr = { .s.sa_family = 0 }; -uint32_t sctp_send_ttl_ms = 0; /** * Clean up on exit. This should be called before exiting. diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index 90424662037..5752b4537ba 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -92,7 +92,6 @@ int proto_sctp_init_listener(struct socket_info* sock_info) #ifdef SCTP_EVENTS struct sctp_event_subscribe ev_s = {0}; ev_s.sctp_association_event = 1; - ev_s.sctp_send_failure_event = 1; if(setsockopt(sock_info->socket, IPPROTO_SCTP, SCTP_EVENTS, &ev_s, sizeof(ev_s)) == -1) { LM_WARN("setsockopt SCTP_EVENTS: %s (%d)\n", @@ -237,14 +236,6 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) su_getport(&ri.src_su), sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state)); break; - case SCTP_SEND_FAILED: - LM_ERR("SCTP_SEND_FAILED assoc_id: %d, peer ip:%s, " - "peer port:%d, error: %d\n", - snp->sn_send_failed.ssf_assoc_id, - ip_addr2a(&ri.src_ip), - su_getport(&ri.src_su), - snp->sn_send_failed.ssf_error); - break; default: LM_INFO("unexpected sctp notification type: %d\n", snp->sn_header.sn_type); @@ -286,7 +277,7 @@ int proto_sctp_send(struct socket_info *source, char *buf, unsigned len, tolen=sockaddru_len(*to); again: - n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, SCTP_UNORDERED, 0, sctp_send_ttl_ms, 0); + n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, SCTP_UNORDERED, 0, 0, 0); #ifdef XL_DEBUG LM_INFO("send status: %d\n", n); #endif From 46e5a9c7c475cddf35e8ea9fd790c2de8bdfee60 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Wed, 3 Jun 2020 14:41:39 +0300 Subject: [PATCH 10/13] Add SCTP_SEND_TTL_MS param, default 0 --- cfg.lex | 2 ++ cfg.y | 4 ++++ globals.h | 1 + main.c | 1 + modules/proto_sctp/sctp_server.c | 14 ++++++++++++-- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cfg.lex b/cfg.lex index 7a02dd5684f..04058d789c1 100644 --- a/cfg.lex +++ b/cfg.lex @@ -213,6 +213,7 @@ LOGFACILITY log_facility LOGNAME log_name LISTEN listen LISTEN_SCTP_SEC listen_sctp_sec +SCTP_SEND_TTL_MS sctp_send_ttl_ms MEMGROUP mem-group ALIAS alias AUTO_ALIASES auto_aliases @@ -419,6 +420,7 @@ SPACE [ ] {LOGNAME} { yylval.strval=yytext; return LOGNAME; } {LISTEN} { count(); yylval.strval=yytext; return LISTEN; } {LISTEN_SCTP_SEC} { count(); yylval.strval=yytext; return LISTEN_SCTP_SEC; } +{SCTP_SEND_TTL_MS} { count(); yylval.strval=yytext; return SCTP_SEND_TTL_MS; } {MEMGROUP} { count(); yylval.strval=yytext; return MEMGROUP; } {ALIAS} { count(); yylval.strval=yytext; return ALIAS; } {AUTO_ALIASES} { count(); yylval.strval=yytext; return AUTO_ALIASES; } diff --git a/cfg.y b/cfg.y index 6de06f19e24..30cd80e1513 100644 --- a/cfg.y +++ b/cfg.y @@ -342,6 +342,7 @@ extern int cfg_parse_only_routes; %token AVP_ALIASES %token LISTEN %token LISTEN_SCTP_SEC +%token SCTP_SEND_TTL_MS %token MEMGROUP %token ALIAS %token AUTO_ALIASES @@ -1146,6 +1147,9 @@ assign_stm: DEBUG EQUAL snumber } } | LISTEN_SCTP_SEC EQUAL error { yyerror("ip address expected"); } + | SCTP_SEND_TTL_MS EQUAL NUMBER { IFOR(); + sctp_send_ttl_ms=$3; } + | SCTP_SEND_TTL_MS EQUAL error { yyerror("number expected"); } | MEMGROUP EQUAL STRING COLON multi_string { IFOR(); /* convert STIRNG ($3) to an ID */ /* update the memstats type for each module */ diff --git a/globals.h b/globals.h index ec259476676..c84690aa54e 100644 --- a/globals.h +++ b/globals.h @@ -152,4 +152,5 @@ extern int enable_asserts; extern int abort_on_assert; extern union sockaddr_union sctp_sec_addr; +extern uint32_t sctp_send_ttl_ms; #endif diff --git a/main.c b/main.c index ca15c9fa575..de1aed266d0 100644 --- a/main.c +++ b/main.c @@ -315,6 +315,7 @@ char* pid_file = 0; /* filename as asked by user */ char* pgid_file = 0; union sockaddr_union sctp_sec_addr = { .s.sa_family = 0 }; +uint32_t sctp_send_ttl_ms = 0; /** * Clean up on exit. This should be called before exiting. diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index 5752b4537ba..1f4b7e3b4de 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -92,6 +92,7 @@ int proto_sctp_init_listener(struct socket_info* sock_info) #ifdef SCTP_EVENTS struct sctp_event_subscribe ev_s = {0}; ev_s.sctp_association_event = 1; + ev_s.sctp_send_failure_event = 1; if(setsockopt(sock_info->socket, IPPROTO_SCTP, SCTP_EVENTS, &ev_s, sizeof(ev_s)) == -1) { LM_WARN("setsockopt SCTP_EVENTS: %s (%d)\n", @@ -195,7 +196,7 @@ static char *sctp_assoc_change_state2s(short int state) int proto_sctp_read(struct socket_info *si, int* bytes_read) { struct receive_info ri; - int len, msg_flags; + int len, msg_flags = 0; static char buf [BUF_SIZE+1]; char *tmp; unsigned int fromlen; @@ -236,6 +237,15 @@ int proto_sctp_read(struct socket_info *si, int* bytes_read) su_getport(&ri.src_su), sctp_assoc_change_state2s(snp->sn_assoc_change.sac_state)); break; + case SCTP_SEND_FAILED: + su2ip_addr(&ri.src_ip, &ri.src_su); + LM_ERR("SCTP_SEND_FAILED assoc_id: %d, peer ip:%s, " + "peer port:%d, error: %d\n", + snp->sn_send_failed.ssf_assoc_id, + ip_addr2a(&ri.src_ip), + su_getport(&ri.src_su), + snp->sn_send_failed.ssf_error); + break; default: LM_INFO("unexpected sctp notification type: %d\n", snp->sn_header.sn_type); @@ -277,7 +287,7 @@ int proto_sctp_send(struct socket_info *source, char *buf, unsigned len, tolen=sockaddru_len(*to); again: - n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, SCTP_UNORDERED, 0, 0, 0); + n=sctp_sendmsg(source->socket, buf, len, &to->s, tolen, 0, SCTP_UNORDERED, 0, sctp_send_ttl_ms, 0); #ifdef XL_DEBUG LM_INFO("send status: %d\n", n); #endif From ff737b295032823a4492a5596e469005bbf28562 Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Wed, 3 Jun 2020 15:02:19 +0300 Subject: [PATCH 11/13] Make non-blocking sctp sending --- modules/proto_sctp/sctp_server.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/proto_sctp/sctp_server.c b/modules/proto_sctp/sctp_server.c index 1f4b7e3b4de..a4e20fc9da6 100644 --- a/modules/proto_sctp/sctp_server.c +++ b/modules/proto_sctp/sctp_server.c @@ -43,6 +43,7 @@ #include #include #endif +#include #include "../../mem/shm_mem.h" #include "../../sr_module.h" @@ -152,6 +153,19 @@ int proto_sctp_init_listener(struct socket_info* sock_info) LM_INFO("sctp bindx success to: %s\n", inet_ntoa(((struct sockaddr_in *)&sctp_sec_addr)->sin_addr)); } + + /* make non-blocking sending */ + optval=fcntl(sock_info->socket, F_GETFL); + if (optval==-1){ + LM_ERR("fnctl failed with %s [%d]\n", strerror(errno), errno); + goto error; + } + if (fcntl(sock_info->socket, F_SETFL, optval|O_NONBLOCK)==-1){ + LM_ERR("fcntl: set non-blocking failed with %s [%d]\n", + strerror(errno), errno); + goto error; + } + if(listen(sock_info->socket, LISTEN_BACKLOG)<0){ LM_ERR("listen(%x, %d) on %s: %s\n", sock_info->socket, @@ -292,14 +306,16 @@ int proto_sctp_send(struct socket_info *source, char *buf, unsigned len, LM_INFO("send status: %d\n", n); #endif if (n==-1){ - LM_ERR("sctp_sendmsg(sock,%p,%d,%p,%d,0,0,0,0,0): %s(%d)\n", - buf,len,&to->s,tolen, strerror(errno),errno); - if (errno==EINTR) goto again; if (errno==EINVAL) { LM_CRIT("invalid sendtoparameters\n" "one possible reason is the server is bound to localhost and\n" "attempts to send to the net\n"); + } else if(errno == EAGAIN || errno == EWOULDBLOCK) { + LM_ERR(L_ERR, "sctp_sendmsg failed, send buffer full\n"); + } else { + LM_ERR("sctp_sendmsg(sock,%p,%d,%p,%d...): %s(%d)\n", + buf,len,&to->s,tolen, strerror(errno),errno); } } return n; From f922001ad912fa4f41f84dc0a402ea4d8200d26e Mon Sep 17 00:00:00 2001 From: Rustam Safargalin Date: Mon, 17 Aug 2020 15:39:46 +0300 Subject: [PATCH 12/13] Add support for ISUP Called IN number parameter --- modules/sip_i/isup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sip_i/isup.c b/modules/sip_i/isup.c index de49b3be145..99e748b12d3 100644 --- a/modules/sip_i/isup.c +++ b/modules/sip_i/isup.c @@ -1223,7 +1223,7 @@ struct isup_param_data isup_params[NO_ISUP_PARAMS] = { {ISUP_PARM_CORRELATION_ID, str_init("Correlation id"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_SCF_ID, str_init("SCF id"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_CALL_DIVERSION_TREATMENT_IND, str_init("Call diversion treatment indicators"), NULL, NULL, NULL, NULL, 0}, - {ISUP_PARM_CALLED_IN_NUMBER, str_init("Called IN number"), NULL, NULL, NULL, NULL, 0}, + {ISUP_PARM_CALLED_IN_NUMBER, str_init("Called IN number"), original_called_num_parsef, original_called_num_writef, original_called_num_subf, NULL, 0}, {ISUP_PARM_CALL_OFFERING_TREATMENT_IND, str_init("Call offering treatment indicators"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_CHARGED_PARTY_IDENT, str_init("Charged party identification"), NULL, NULL, NULL, NULL, 0}, {ISUP_PARM_CONFERENCE_TREATMENT_IND, str_init("Conference treatment indicators"), NULL, NULL, NULL, NULL, 0}, From 6ceab7d6cf331d87cd9cc0db8735b89e36b5b684 Mon Sep 17 00:00:00 2001 From: Mikhail Kalashnikov Date: Wed, 26 Aug 2020 21:23:56 +0300 Subject: [PATCH 13/13] tm:retransmission_handler change log severity --- modules/tm/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/tm/timer.c b/modules/tm/timer.c index 1aa851c143d..d11b190aeee 100644 --- a/modules/tm/timer.c +++ b/modules/tm/timer.c @@ -286,7 +286,7 @@ inline static void retransmission_handler( struct timer_link *retr_tl ) /* re-transmission */ if ( r_buf->activ_type==TYPE_LOCAL_CANCEL || r_buf->activ_type==TYPE_REQUEST ) { - LM_DBG("retransmission_handler : request resending" + LM_INFO("retransmission_handler : request resending" " (t=%p, %.9s ... )\n", r_buf->my_T, r_buf->buffer.s); set_t(r_buf->my_T); if (SEND_BUFFER( r_buf )==0) {